Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: always use json for http requests/responses #92

Merged
merged 11 commits into from
Sep 24, 2024
102 changes: 24 additions & 78 deletions .github/workflows/rock-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ jobs:
id: rockcraft
with:
rockcraft-channel: edge


- name: Install pre-requisites
run: |
sudo apt-get update
sudo apt-get install -y openssl jq
- name: Import the image to Docker registry
run: |
sudo rockcraft.skopeo --insecure-policy copy oci-archive:${{ steps.rockcraft.outputs.rock }} docker-daemon:notary:latest
Expand Down Expand Up @@ -43,84 +47,26 @@ jobs:
- name: Test if pebble notify fires correctly
id: test_notify
run : |
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
openssl req -new -key private_key.pem -out request.csr -subj "/C=CA/ST=Quebec/L=Montreal/O=Test Company/OU=IT Department/CN=test.example.com"
openssl req -x509 -new -nodes -key private_key.pem -sha256 -days 365 -out ca_certificate.pem -subj "/C=CA/ST=Quebec/L=Montreal/O=Test CA/OU=CA Department/CN=Test CA"
openssl x509 -req -in request.csr -CA ca_certificate.pem -CAkey private_key.pem -CAcreateserial -out certificate.pem -days 365 -sha256
CSR=$(cat request.csr | awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}')
CERTIFICATE=$(cat certificate.pem ca_certificate.pem | awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}')

curl -XPOST -k -d '{"username":"admin", "password": "Admin1234"}' https://localhost:3000/api/v1/accounts
export ADMIN_TOKEN=$(curl -XPOST -k -d '{"username":"admin", "password": "Admin1234"}' https://localhost:3000/login)
curl -XPOST -k -d '-----BEGIN CERTIFICATE REQUEST-----
MIICsTCCAZkCAQAwbDELMAkGA1UEBhMCQ0ExFDASBgNVBAgMC05vdmEgU2NvdGlh
MRAwDgYDVQQHDAdIYWxpZmF4MSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0
eSBMdGQxEjAQBgNVBAMMCWFwcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP
ADCCAQoCggEBAOhDSpNbeFiXMQzQcobExHqYMEGzqpX8N9+AR6/HPZWBybgx1hr3
ejqsKornzpVph/dO9UC7O9aBlG071O9VQGHt3OU3rkZIk2009vYwLuSrAlJtnUne
p7KKn2lZGvh7jVyZE5RkS0X27vlT0soANsmcVq/82VneHrF/nbDcK6DOjQpS5o5l
EiNk2CIpYGUkw3WnQF4pBk8t4bNOl3nfpaAOfnmNuBX3mWyfPnaKMCENMpDqL9FR
V/O5bIPLmyH30OHUEJUkWOmFt9GFi+QfMoM0fR34KmRbDz79hZZb/yVPZZJl7l6i
FWXkNR3gxdEnwCZkTgWk5OqS9dCJOtsDE8ECAwEAAaAAMA0GCSqGSIb3DQEBCwUA
A4IBAQCqBX5WaNv/HjkzAyNXYuCToCb8GjmiMqL54t+1nEI1QTm6axQXivEbQT3x
GIh7uQYC06wHE23K6Znc1/G+o3y6lID07rvhBNal1qoXUiq6CsAqk+DXYdd8MEh5
joerEedFqcW+WTUDcqddfIyDAGPqrM9j6/E+aFYyZjJ/xRuMf1zlWMljRiwj1NI9
NxqjsYYQ3zxfUjv8gxXm0hN8Up1O9saoEF+zbuWNdiUWd6Ih3/3u5VBNSxgVOrDQ
CeXyyzkMx1pWTx0rWa7NSa+DMKVVzv46pck/9kLB4gPL8zqvIOMQsf74N0VcbVfd
9jQR8mPXQYPUERl1ZhNrkzkyA0kd
-----END CERTIFICATE REQUEST-----' -H "Authorization: Bearer $ADMIN_TOKEN" 'https://localhost:3000/api/v1/certificate_requests'
curl -XPOST -k -d '-----BEGIN CERTIFICATE-----
MIIEVDCCAjwCFE8lmuBE85/RPw2M17Kzl93O+9IPMA0GCSqGSIb3DQEBCwUAMGEx
CzAJBgNVBAYTAlRSMQ4wDAYDVQQIDAVJem1pcjES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7VF0tyiE
j3eXaMAL8EAKxCUZbXcuwmK9qistAYXBFFEK9M08FwLH8HM4LoPjshMg3II9Ncs8
p3to8U99/ZeFbJRzEUF9poZ7VwxBEcgfWD1RV0+gNLC3Au2yuc4C3anknOv7Db/r
jdzVA8yTI8cZ/RtRohp5H/s+j2tcdfB3Zt+wfS4nLxqN/kf7qv2VSdPbXyTyz/ft
btZkbfdL5A==
-----END CERTIFICATE-----' -H "Authorization: Bearer $ADMIN_TOKEN" 'https://localhost:3000/api/v1/certificate_requests/1/certificate'
export ADMIN_TOKEN=$(curl -XPOST -k -d '{"username":"admin", "password": "Admin1234"}' https://localhost:3000/login | jq -r .result.token )

curl -k --location 'https://localhost:3000/api/v1/certificate_requests' \
--header "Authorization: Bearer $ADMIN_TOKEN" \
--header 'Content-Type: application/json' \
--data "{\"csr\":\"${CSR}\"}"

curl -k --location 'https://localhost:3000/api/v1/certificate_requests/1/certificate' \
--header "Authorization: Bearer $ADMIN_TOKEN" \
--header 'Content-Type: application/json' \
--data "{\"certificate\":\"${COMBINED_CERTIFICATE}\"}"

docker exec notary /usr/bin/pebble notices
docker exec notary /usr/bin/pebble notices | grep notary\\.com/certificate/update
docker exec notary /usr/bin/pebble notice 3
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.db
*.pem
*config.yaml

.DS_Store
Expand Down
172 changes: 0 additions & 172 deletions cmd/notary/main_test.go

This file was deleted.

14 changes: 7 additions & 7 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ type Database struct {
// A CertificateRequest struct represents an entry in the database.
// The object contains a Certificate Request, its matching Certificate if any, and the row ID.
type CertificateRequest struct {
ID int `json:"id"`
CSR string `json:"csr"`
Certificate string `json:"certificate"`
ID int
CSR string
Certificate string
}
type User struct {
ID int `json:"id"`
Username string `json:"username"`
Password string `json:"password,omitempty"`
Permissions int `json:"permissions"`
ID int
Username string
Password string
Permissions int
}

var ErrIdNotFound = errors.New("id not found")
Expand Down
Loading
Loading