HTTP API¶
The client commands use a small JSON API over HTTPS. You can call it
directly, for example with curl. Everything under /v1/ stays compatible
within a major version.
Endpoints¶
| Endpoint | Authentication | What it does |
|---|---|---|
GET /health |
none | {"status":"ok"} when the server is up. |
POST /v1/x509/sign |
one-time token | Signs a TLS certificate. |
POST /v1/ssh/sign |
one-time token | Signs an SSH certificate. |
POST /v1/x509/renew |
renewal proof | Renews a TLS certificate. |
POST /v1/ssh/renew |
renewal proof | Renews an SSH host certificate. |
GET /v1/oidc/login |
(browser) | Starts a login with the identity provider. |
GET /v1/oidc/callback |
(browser) | The provider sends the browser back here. |
POST /v1/ldap/login |
username + password | Checks a directory login and answers with a one-time token. |
GET /v1/certificates/<serial> |
none | One issued TLS certificate, by serial number. |
/acme/directory and below |
ACME (JWS) | The ACME server (RFC 8555). |
/scep |
SCEP | The SCEP server (RFC 8894). |
/root.crt, /intermediate.crt, /ssh_user_ca.pub, /ssh_host_ca.pub, /crl, /ocsp |
none | Public information; see Public endpoints. |
Errors are JSON: {"error": "what went wrong"}.
POST /v1/x509/sign¶
Header: Authorization: Bearer <token>. Answers 201 Created.
| Request field | Meaning |
|---|---|
csr |
The certificate signing request, PEM. Required. |
validity |
How long the certificate should be valid, e.g. "24h". Optional; default: the profile's. |
| Response field | Meaning |
|---|---|
certificate |
The new certificate, PEM. |
chain |
The new certificate followed by the intermediate. |
jq -Rs '{csr: .}' web.csr |
curl --cacert root.crt -H "Authorization: Bearer $TOKEN" \
-d @- https://ca.example.com:8443/v1/x509/sign | jq -r .chain > web.crt
POST /v1/ssh/sign¶
Header: Authorization: Bearer <token>. Answers 201 Created.
| Request field | Meaning |
|---|---|
public_key |
The SSH public key, as in an id_ed25519.pub file. Required. |
principals |
Login names or host names. Optional; default: all names in the token. |
validity |
e.g. "8h". Optional. |
| Response field | Meaning |
|---|---|
certificate |
The SSH certificate, as in an id_ed25519-cert.pub file. |
jq -n --arg k "$(cat ~/.ssh/id_ed25519.pub)" '{public_key: $k}' |
curl --cacert root.crt -H "Authorization: Bearer $TOKEN" \
-d @- https://ca.example.com:8443/v1/ssh/sign | jq -r .certificate > ~/.ssh/id_ed25519-cert.pub
Status codes¶
| Status | When | Token used up? |
|---|---|---|
201 |
Issued. | yes |
400 |
The request is not sound: no CSR or key, weak key, validity above the maximum. | no |
401 |
The token is missing, invalid, expired or was already used. | – |
403 |
A name not in the token, or a token for another kind of certificate; renewal of a certificate the CA did not issue, or that was revoked, or obtained via ACME or SCEP. | no |
A request refused for its names, its CSR or its public key does not use up the token, so it can be corrected and sent again.
Renewal¶
POST /v1/x509/renew takes {"csr": "<PEM CSR for the new key>"} and
answers like /v1/x509/sign. POST /v1/ssh/renew takes {} and answers
like /v1/ssh/sign.
In place of a token, the Authorization: Bearer header carries a
renewal proof: a JWT signed with the private key of the certificate
being renewed, with the certificate in its header (x5c for TLS,
bastionxp-ca-ssh-cert for SSH). Its claims:
| Claim | Value |
|---|---|
aud |
bastionxp-ca:renew:x509 or bastionxp-ca:renew:ssh |
exp |
at most 5 minutes ahead |
jti |
a random ID, usable once |
body_sha256 |
SHA-256 of the request body, URL-safe base64 |
The names in the CSR are ignored; the new certificate gets the old one's. The CSR must be for a new key. Only certificates obtained through the API renew here.
Login addresses¶
GET /v1/oidc/login¶
Visited by a browser. The program that wants a certificate listens on a port of its own machine and opens this address with:
| Parameter | Meaning |
|---|---|
callback |
Where the result goes. Must be http://127.0.0.1:<port>/...; anything else is refused. |
state |
A random value, sent back with the result. |
profile |
tls-server, tls-client, ssh-user, ssh-host or one of the CA's own. |
kind |
ssh or x509, instead of profile: the certificate the login gives people for themselves, with the login's cert_profile. |
name |
A name for the certificate; repeat for more. Can be left out for an SSH user certificate for yourself. |
key |
Fingerprint of the public key. The token then works for that key only. |
subject |
Who the token is for. Optional, admins only. |
valid_for |
How long the token can be used, e.g. 10m. Optional; ignored when key is given. |
The CA sends the browser to the identity provider, which sends it back to
GET /v1/oidc/callback; the CA then sends it to callback with state
and either token or error. A token for a named key is valid for one
minute. Non-admins get an error for anything but their own certificates:
an SSH certificate of the login's ssh.cert_profile with their own
principals, or a TLS certificate of its x509.cert_profile for their own
name.
POST /v1/ldap/login¶
JSON with username, password and the same fields as above (profile, kind,
names, key, subject, valid_for). Answers:
| Status | Meaning |
|---|---|
201 |
{"token": "...", "expires": "..."} |
401 |
Wrong username or password. |
403 |
No rule names the person, or the rules do not allow the request. |
429 |
Too many failures. |
502 |
The directory cannot be reached. |