Skip to main content

Module certgen

Module certgen 

Expand description

Certificate generation for ZeroClaw’s mutual-TLS transport.

Produces a per-daemon CA and the server / client leaf certificates that chain to it, with correct X.509 profiles: the CA is CA:TRUE, pathlen:0 (keyCertSign + cRLSign); the server leaf carries serverAuth EKU; the client leaf carries clientAuth EKU. notBefore is backdated a few minutes for clock skew. This backs the secure-by-default auto-generation path (the daemon mints its own CA + server cert on first run) and client-cert issuance.

Structs§

IssuedLeaf
Metadata for a certificate issued from a client-submitted CSR. The private key is deliberately absent: it never leaves the requesting device (only the CSR is transmitted). This is what the daemon records in its issued-cert ledger and returns to the client over the enrollment channel.
Pem
A generated certificate + private key, PEM-encoded.
ServerMaterials
On-disk paths to the daemon’s mTLS server materials.

Enums§

CaKeyProtection
At-rest protection for the daemon CA private key.

Functions§

ensure_server_materials
Ensure mTLS server materials exist under dir.
ensure_server_materials_protected
Like ensure_server_materials, but applies protection to the CA private key at rest (threat A4). With CaKeyProtection::Passphrase, a freshly generated CA key is written as an encrypted envelope and an existing key is decrypted with the same passphrase on load. 0600 remains the floor in the CaKeyProtection::None case.
generate_client_csr
Generate a fresh client keypair (ECDSA P-256, hardware-keystore-backable) and a CSR for it. The CSR subject is only a hint; the daemon issuer overrides it with the device id it assigns (so a requester cannot choose its identity, A7). The private key is returned [Zeroizing] - the caller persists it locally and the in-memory copy is wiped on drop; it never leaves the device (only the CSR is transmitted). This is the client half of the sign_csr enrollment flow.
issue_client_cert
Issue a client certificate signed by the CA whose PEM cert + key are given. The returned key is generated fresh (server-side keygen path, e.g. the operator issue-client-cert CLI); the subject CN is the device identity.
load_ca_key_pem
Load the CA private-key PEM from disk, decrypting it when the file is an encrypted envelope. Returns a [Zeroizing] PEM so the crown-jewel key is wiped on drop. Used by the auto-gen path and by every issuance caller (the issue-client-cert CLI and the enrollment endpoint) before signing.
sign_csr
Sign a client-submitted CSR into a clientAuth-only leaf bound to device_id.
write_private_pem
Write a private-key PEM file, restricting permissions to 0600 on Unix before the bytes are written (no create-then-chmod world-readable window).