[CRIT-3] CA private keys (Root/Sub CA, OCSP responder, JWT JWK) stored unencrypted as Erlang terms in Mnesia disc files #3

Open
opened 2026-11-14 18:28:39 +01:00 by amiryahaya · 2 comments
Owner

Finding

All key material is term_to_binary'd straight into Mnesia disc_copies files on the Docker volume. No encryption at rest, no HSM, no key wrapping, Root CA key kept online — and (see CRIT-4 / M-18) with no backup story, the material has exactly one fragile copy.

Evidence

  • lib/mdid_ws/cert_management/issuer_manager.ex:228-240 — raw keypair stored as private_key
  • lib/mdid_ws/cert_management/issuer.ex:44-72 — dirty_write of issuer record incl. private key
  • lib/mdid_ws/oauth/token.ex:146-154 — JWT signing JWK as term_to_binary

Impact

Read access to the volume, a backup, or the host filesystem = Root CA private key = 25 years of forgery (Sub CAs, leaf certs, OCSP responses).

Fix

  • Keep the Root CA offline (or in an HSM); never persist the Root signing key on the web host
  • Encrypt CA keys at rest under a master key injected at runtime (or KMS/HSM)
  • Document an emergency key-rotation runbook

Line numbers refer to the initial import commit 282cb11. Source: comprehensive audit, 2026-11-12 (first review of this codebase).

## Finding All key material is `term_to_binary`'d straight into Mnesia `disc_copies` files on the Docker volume. No encryption at rest, no HSM, no key wrapping, Root CA key kept online — and (see CRIT-4 / M-18) with no backup story, the material has exactly one fragile copy. ## Evidence - `lib/mdid_ws/cert_management/issuer_manager.ex:228-240` — raw `keypair` stored as `private_key` - `lib/mdid_ws/cert_management/issuer.ex:44-72` — `dirty_write` of issuer record incl. private key - `lib/mdid_ws/oauth/token.ex:146-154` — JWT signing JWK as `term_to_binary` ## Impact Read access to the volume, a backup, or the host filesystem = Root CA private key = 25 years of forgery (Sub CAs, leaf certs, OCSP responses). ## Fix - [ ] Keep the Root CA offline (or in an HSM); never persist the Root signing key on the web host - [ ] Encrypt CA keys at rest under a master key injected at runtime (or KMS/HSM) - [ ] Document an emergency key-rotation runbook _Line numbers refer to the initial import commit `282cb11`. Source: comprehensive audit, 2026-11-12 (first review of this codebase)._
Author
Owner

Closing the audit item with one gap accepted. Done: all stored private keys (Root, Sub CA, OCSP responder, JWT signing key) are AES-256-GCM encrypted under MDID_KEY_ENCRYPTION_KEY (A6); key rotation and the compromise runbook are in docs/key-management.md. Accepted gap: the Root CA key still sits on the host (it is used once, to sign the Sub CA at bootstrap), and anyone who can read the running process also has the master key. Reason: the Trustgate part of this service is going to be replaced by another CA system, and the local Root/Sub CA signing path will be reworked with it. Revisit then: keep Root offline or out of the store, and decide where the Sub CA signing key lives (HSM/KMS) as part of the new CA integration.

Closing the audit item with one gap accepted. Done: all stored private keys (Root, Sub CA, OCSP responder, JWT signing key) are AES-256-GCM encrypted under MDID_KEY_ENCRYPTION_KEY (A6); key rotation and the compromise runbook are in docs/key-management.md. Accepted gap: the Root CA key still sits on the host (it is used once, to sign the Sub CA at bootstrap), and anyone who can read the running process also has the master key. Reason: the Trustgate part of this service is going to be replaced by another CA system, and the local Root/Sub CA signing path will be reworked with it. Revisit then: keep Root offline or out of the store, and decide where the Sub CA signing key lives (HSM/KMS) as part of the new CA integration.
Author
Owner

Reopening: my closing comment gave the wrong reason. I said the Root key would be revisited as part of the new CA integration, but the integration is scoped to replacing Trustgate with emCA only; local signing, CRL and OCSP stay. So the local Root and Sub CA, and the accepted gap below, remain. Status: all stored private keys are AES-256-GCM encrypted under MDID_KEY_ENCRYPTION_KEY and the rotation/compromise runbook is in docs/key-management.md. Still open: the Root CA key sits on the host although it is used once, to sign the Sub CA at bootstrap, and an attacker who can read the running process also has the master key. Candidate next step: keep the Root key offline (export and wipe the key only, keep the Root certificate row; the boot guard refuses to start if the Root row is deleted while issued certificates exist), and decide separately whether the Sub CA key needs an HSM or KMS.

Reopening: my closing comment gave the wrong reason. I said the Root key would be revisited as part of the new CA integration, but the integration is scoped to replacing Trustgate with emCA only; local signing, CRL and OCSP stay. So the local Root and Sub CA, and the accepted gap below, remain. Status: all stored private keys are AES-256-GCM encrypted under MDID_KEY_ENCRYPTION_KEY and the rotation/compromise runbook is in docs/key-management.md. Still open: the Root CA key sits on the host although it is used once, to sign the Sub CA at bootstrap, and an attacker who can read the running process also has the master key. Candidate next step: keep the Root key offline (export and wipe the key only, keep the Root certificate row; the boot guard refuses to start if the Root row is deleted while issued certificates exist), and decide separately whether the Sub CA key needs an HSM or KMS.
Sign in to join this conversation.
No description provided.