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§
- Issued
Leaf - 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.
- Server
Materials - On-disk paths to the daemon’s mTLS server materials.
Enums§
- CaKey
Protection - 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 appliesprotectionto the CA private key at rest (threat A4). WithCaKeyProtection::Passphrase, a freshly generated CA key is written as an encrypted envelope and an existing key is decrypted with the same passphrase on load.0600remains the floor in theCaKeyProtection::Nonecase. - 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 thesign_csrenrollment 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-certCLI); 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 (theissue-client-certCLI and the enrollment endpoint) before signing. - sign_
csr - Sign a client-submitted CSR into a
clientAuth-only leaf bound todevice_id. - write_
private_ pem - Write a private-key PEM file, restricting permissions to
0600on Unix before the bytes are written (no create-then-chmod world-readable window).