Skip to content

Keys Stay Home

Small checks around an offline authority.

Part 41 of 41ofFamiliars
  1. 1Session Zero
  2. 2Rolling for a Name
  3. 3The Haunted Handler
  4. 4The Sparse Wheel
  5. 5The Fork in the Path
  6. 6The Planet as a Prefix
  7. 7The Long Division
  8. 8The Line You Usually Cancel
  9. 9Sixteen Bytes Too Far
  10. 10Packing a UUID
  11. 11Bytes You Can Type
  12. 12The Shunting Yard
  13. 13Interchangeable Parts
  14. 14One Loop Per Core
  15. 15The Seam
  16. 16Append Only
  17. 17Who Owns the Tree
  18. 18Down the Flume
  19. 19The Syscalls That Lie
  20. 20Asking the Machine
  21. 21The Earth Is Not a Ball
  22. 22Smith and Schmidt
  23. 23Many Ways to Be Similar
  24. 24Built to Disappear
  25. 25Sometimes a Mutex Is Right
  26. 26Work, Not Threads
  27. 27Before the Program Runs
  28. 28No Collisions, Ever
  29. 29The Names Enums Throw Away
  30. 30The Bag of Holding
  31. 31A Map of Blocks
  32. 32Certainly Absent
  33. 33A Tree Made of Types
  34. 34Everything but the Views
  35. 35Who Owns the Wheel
  36. 36A Guest on the Loop
  37. 37Acknowledged Means Durable
  38. 38Sorted as Bytes
  39. 39Store, Then Search
  40. 40When Power Leaves
  41. 41Keys Stay Home

Part of Familiars, my collection of standalone C++ building blocks. This one is pki.

An offline certificate authority has a simple rule: its signing key stays on the operator’s host. The nodes generate requests and receive certificates, but they never receive that key. The rule is easy to write on a diagram and easy to erode in practice. A directory is copied into a data root. A key is created with a permissive mode. A passphrase ends up in a command line or an environment variable. An expiring certificate is discovered only when a connection fails.

pki begins with the checks around that boundary. It is a C++20 library over OpenSSL 3 with one command entry point, pki::run, which a consumer can expose inside its own binary. It currently generates keys, checks authority directories and private files, prints fingerprints, validates identities, and reports certificate expiry. It does not issue certificates yet. Signing, an issuance index, rotation, and recovery are later steps. I would rather make the existing boundary honest than put a CA label on an unfinished signer.

The authority directory is opened once. On a POSIX filesystem with local ownership and modes, pki checks that the caller owns it and that its mode is 0700. It reaches children through openat on that directory descriptor, with no symlink following. It checks a private file after opening it: regular file, one link, correct owner, and the required mode. The CA key is 0600; a node key may be 0640 for the caller’s effective group. Creation uses exclusive open, sets the mode, syncs the file, and flushes the directory. The architecture names the checks and the filesystem contract.

Those details are not decoration. A path checked before opening can be swapped before use. A symlink can point outside the guarded directory. A second hard link can make a private file reachable through another name. The descriptor and post-open checks close those particular gaps, and a refusal names the reason instead of pretending the file is safe.

The toolkit also avoids common secret leaks: passphrases come from a terminal or a checked file, not from arguments or the environment; secret buffers are locked and wiped; core dumps are disabled. Generated CA keys use encrypted PKCS#8, with scrypt and AES-256-CBC. The format is readable with OpenSSL’s own pkcs8 command, so recovery does not require the pki binary.

Two SHA-256 fingerprints answer different questions. A certificate’s SPKI fingerprint hashes the public-key information, so it stays the same when that key receives a renewed certificate. Its DER fingerprint hashes the entire certificate, so a renewal changes it. The distinction prevents a pin meant to follow a key from accidentally pinning one issuance. pki prints both, as 64 lowercase hex digits.

Identities use SPIFFE URI form: spiffe://<cluster>/<consumer>/<node|client>/<name>. The library canonicalizes the allowed fields so the same identity has one byte representation. For a cluster protocol, that is more useful than accepting several spellings and hoping every peer normalizes them the same way.

Expiry is also a command check rather than a calendar reminder. A certificate is flagged once it has passed five sixths of its lifetime, or when it is within an explicit span such as --within 30d. The exit status separates an ordinary check (0), a finding (1), and a refusal to operate (2). That makes a cron job able to alert on approaching expiry without interpreting prose.

The intended consumers include Xapiand’s HTTPS API and Detent’s mutual-TLS peers. Neither integration is complete merely because the library can inspect a key or a certificate. The roadmap still has the issuance index and signing, rotation and backup, then the consumer commands and adoption.

Today I would use pki to generate and guard keys, inspect fingerprints, and check expiry. I would not use it as a certificate issuer. That clear edge is part of keeping the authority where it belongs.