Architecture¶
How the packages divide the work and what happens to a request on each side.
Packages¶
| Package | Role | Depends on |
|---|---|---|
pkicmp |
ASN.1 types for CMP and CRMF, message construction, parsing, MAC and signature protection, verification, proof of possession | golang.org/x/crypto, go-composite-mldsa, circl |
cms |
EnvelopedData and EncryptedValue for proof of possession by decryption | golang.org/x/crypto |
client |
Request flows over HTTP: protection, response verification, polling and confirmation | pkicmp, cms |
server |
An http.Handler with transactions, policy middleware and the CA interfaces |
pkicmp, cms |
pkicmp stands alone. Use it directly for custom tooling, a registration authority proxy or tests
that need to build or inspect messages. See Messages and protection.
Client¶
A Client holds an endpoint and configuration only. Each Send* or Get* call runs one complete
operation and keeps its transaction state, such as the transaction ID and nonces, for that call
alone. One Client can therefore serve many goroutines.
sequenceDiagram
participant App as Your code
participant C as client.Client
participant CA as CMP server
App->>C: SendIR(key, creds)
C->>CA: ir (protected with creds)
CA-->>C: ip, or pollRep while the CA decides
C->>C: verify protection, certReqId and issued key
C->>CA: certConf
CA-->>C: pkiConf
C-->>App: EnrollResult
The call returns only after the whole exchange, including polling and confirmation. A context deadline bounds it. Enrollment and Response verification describe each step.
Server¶
server.NewCAServer wraps your CA in a handler, applies the policy middleware and returns a
Server that implements http.Handler. server.New takes any Handler instead, for full control
such as custom routing or a registration authority proxy.
Every request passes these stages in order:
- HTTP checks. Only
POSTwithContent-Type: application/pkixcmpis accepted. Bodies are limited byserver.MaxRequestBodySize, 1 MiB by default. - Header checks. The protocol version must be 2 or 3 and a recipient the server does not answer to is refused.
- Protection. The MAC is checked with the secret from
SecretLookupor the signature with the certificate fromCertificateLookup. The result is aSenderIdentity. - Transaction checks. Nonces, the transaction ID and the transaction limits are checked against the state of the sender's transaction.
- Policy middleware.
LightweightPolicyand your own middleware accept or refuse the request. - Built-in request checks. The handler that
NewCAServerbuilds verifies proof of possession and decodes BasicConstraints for every certificate request, with or without a policy. - Your CA.
IssueCertificate,RevokeCertificate,CheckPendingor a support message provider decides the answer. - Response. The server protects the response with the MAC of a MAC-protected request or else
with the
WithSignerkey. It then records the transaction state.
flowchart LR
R[HTTP request] --> P[Verify protection]
P --> T[Transaction state]
T --> M[Policy middleware]
M --> B[Proof of possession]
B --> CA[Your CA]
CA --> S[Protect response]
A refusal at any stage becomes a CMP error message or the rejection in an ip, cp, kup or rp
where RFC 9810 asks for one. An error your code returns that is not a *server.Error becomes a bare
systemFailure, so internal detail never reaches the peer.
Transactions¶
The server keys each transaction by the sender's verified credential and the transaction ID. One client cannot continue or hijack another client's transaction even with the same transaction ID. Transactions live in memory:
CleanupExpiredremoves completed and stale transactions and must be called periodically.WithMaxTransactionsandWithMaxTransactionsPerCredentialcap the state a client can create.SnapshotTransactionsandRestoreTransactionsmove the state to durable storage or a new process.
Transactions and recovery describes each.
What your code supplies¶
| Concern | Library | Your code |
|---|---|---|
| Wire format, protection, nonces, transactions | Yes | No |
| Proof of possession | Yes | Decides on indirect methods through the options |
| Who may request which certificate | No | Middleware or IssueCertificate |
| Shared secrets and known certificates | Lookup interfaces | The store behind them |
| Certificate contents, serial numbers and validity | Template from the request | Every final decision before signing |
| Revocation, CRLs and CA certificates | Protocol handling | The data and the decision |
| TLS, rate limiting and audit logging | No | HTTP server and middleware |