Skip to content

S09-06 - CA Keys

Purpose: How the key of each TLS inspection certificate authority is made, stored and restored, and when a CA is valid.

Each CA has its own P-256 key. wb-proxyd:

  1. generates it in the platform’s hardware key store (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.), non-exportable;
  2. self-signs the CA certificate with it;
  3. uses it to sign leaf certificates. Go’s certificate creation accepts any signer.

Only wb-proxyd writes, fetches, deletes or uses the key and its store item wraithbox/ca/<vm>/<ca> (S15-03-access-rulesS15-03-access-rules: Access RulesHow each host process gets only the credentials it needs, for only as long as it needs them, and which process may access which item., “Declared access”). wb-hostd gets the public certificate over local IPC, and hands it to wb-guestd.

The key store differs per host.

The key is a Secure Enclave key that isn’t stored in the Keychain. Its wrapped form, the token object ID, is the store item.

To sign, wb-proxyd fetches the item and passes it to Security.framework in kSecAttrTokenOID. That restores the same key in this or a later process, also after a rebuild (X09-keychain-unsignedX09-keychain-unsigned: Keychain access without a signing identityConfirm the fallback access-control model from S09-policy-credentials-audit and the Secure Enclave key creation for an ad-hoc signed binary.).

Only this Mac’s Secure Enclave can unwrap it. So a copied item is useless on another Mac. On this Mac, any process of the user that has the value can sign with the key. The store’s G2 is what keeps it to wb-proxyd (S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them.).

The same wrapped key is used in every build, on the Keychain backend and on the 1Password backend after V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. (S15-02-secret-storeS15-02-secret-store: The Secret StoreWhere credentials are held: the secret store, its backends, and the guarantees a backend must give.).

A permanent Secure Enclave key in the access group also works in a team-signed build (X29-dev-signingX29-dev-signing: Keychain access group for development buildsCan a developer's free personal team, an Apple ID signed in to Xcode without a paid membership, sign the helpers in Wraith Box.app (wb-proxyd, wb-hostd, wb-vmd) with a keychain-access-groups entitlement and a provisio…). Wraith Box doesn’t use one.

wb-proxyd takes any key the Secure Enclave token gives. On a Mac VM that token is the hypervisor’s virtual Secure Enclave, so a key there is only as strong as the hypervisor and its host. Wraith Box doesn’t support a Mac VM as its host (I509I509 (closed): platform: Secure Enclave CA key kept as its wrapped form, with the CA item round trip on the maintainer's MacPackage M3.9 of docs/implementation-plan.md, part 4 of 5 (M3.9d).), and no rule refuses one. CI’s macOS runners are such VMs, and give working keys to an unsigned test binary, so CI runs the shim’s round trip there (C02-streams-and-tlsC02-streams-and-tls: Streams, TLS, and the Inspection CAThe test cases for the streams wb-proxyd takes over: the hand-off from wb-netd, the first-byte and TLS checks, upstream addresses, the HTTP request form, and the inspection CA's leaves, rotation, and keys., “CA key”). A Mac without a Secure Enclave gets the error of Security.framework from generate and restore. No test covers that error path, because CI has no such Mac.

The key and its item have the attributes X09-keychain-unsignedX09-keychain-unsigned: Keychain access without a signing identityConfirm the fallback access-control model from S09-policy-credentials-audit and the Secure Enclave key creation for an ad-hoc signed binary. measured, and no others.

The key has:

  • kSecAttrIsPermanent false;
  • an access control with kSecAccessControlPrivateKeyUsage as its only flag, so no signature asks for user presence or biometry;
  • the protection kSecAttrAccessibleWhenUnlockedThisDeviceOnly.

kSecAttrIsPermanent is what the call asks for. A Secure Enclave key made with it false reads it back as true, so a check of the attribute can’t tell. The check is a search of the keychain for the key, which finds nothing. The maintainer’s run of 2026-11-10 measured both on a Secure Enclave key (I509I509 (closed): platform: Secure Enclave CA key kept as its wrapped form, with the CA item round trip on the maintainer's MacPackage M3.9 of docs/implementation-plan.md, part 4 of 5 (M3.9d).). A restored key has the same access control as the new one, with no flag passed at the restore.

The store item has kSecAttrSynchronizable false, so it never leaves the Mac.

Security.framework exports the symbol, but the SDK headers don’t declare it. So the cgo shim (S10-tech-stackS10-tech-stack: Technology ChoicesFix languages, libraries, packaging, and repository layout, with the reason for each choice.) declares it.

Passed without that attribute, the ID gives a new key without an error (X09-keychain-unsignedX09-keychain-unsigned: Keychain access without a signing identityConfirm the fallback access-control model from S09-policy-credentials-audit and the Secure Enclave key creation for an ad-hoc signed binary.). So each time wb-proxyd restores a key, it checks that the key’s public key equals the one in the CA certificate before it signs.

The public key a restored key reports comes from the token object ID’s own bytes (I509I509 (closed): platform: Secure Enclave CA key kept as its wrapped form, with the CA item round trip on the maintainer's MacPackage M3.9 of docs/implementation-plan.md, part 4 of 5 (M3.9d).), so it alone doesn’t show which key signs. To check that, the restore signs a fixed digest with the key and verifies the signature with that public key, and an error or a signature that doesn’t verify fails the restore. With that, the public key check is a check of the key that signs.

The key is a TPM key through the CNG platform crypto provider. wb-proxyd opens it by its name, the item name ca/<vm>/<ca>.

Windows 11 requires a TPM 2.0. wb setup refuses a host whose platform crypto provider isn’t available, with no software fallback.

wb setup decides once whether the host has a usable TPM 2.0. It records the choice in state.db, and says it.

  • With a TPM, the key’s wrapped blob is the store item. wb-proxyd loads it into the TPM to sign.
  • Without one, the fallback is a software key held in the secret store as the item. wb-proxyd fetches it and signs with it in its own memory. The audit record of each CA issue says so.

wb-proxyd probes for a TPM itself at start, and compares the result with the record. These fail each CA issue and restore, with the rule ca-key-store-mismatch:

  • a record of “software” on a host that has a TPM;
  • a record of “TPM” on a host that has none.

wb-proxyd never moves to the other kind on its own.

wb setup changes a recorded choice only with --ca-key-store tpm or --ca-key-store software. It refuses software on a host with a TPM. The change drops every CA from the record, as wb vm reset-ca does for each VM (“Recovery”).

So the recovery for a host that lost its TPM is wb setup --ca-key-store software.

A valid CA:

  • is in wb-hostd’s record;
  • hasn’t expired;
  • has an item that wb-proxyd has fetched, and restored to a key whose public key equals the certificate’s.

wb-proxyd signs only with a valid CA.

  1. wb-proxyd makes the key.
  2. It writes the item.
  3. It reads the item back.
  4. It restores the key from what it read.
  5. It compares the public key.

Only after that round trip does wb-hostd record the CA. A failed step deletes the item, leaves the record unchanged, and fails the issue with ca-key-restore.

Before step 1, an issue is refused with ca-issue-refused when its CA id is in use:

  • the id is in a VM’s last CA set, whether or not that set restored;
  • this wb-proxyd holds a key of the id, for either VM;
  • the store already holds the item, so a process before a restart may have issued it.

That last check fetches the item. A missing item lets the issue go on, and any other store error fails it as a failed step does. Only a failure after a successful write deletes the item, so an issue never overwrites or deletes the item of a CA in use.

Before it calls Security.framework, the restore parses the wrapped form against the fixed structure of a wrapped Secure Enclave P-256 key, as generate gives it, and refuses anything else as an error of the restore. Wraith Box only passes the Secure Enclave forms with the exact structure and encoding that generate gives. The reader takes only the exact encoding generate gives. Its lengths are definite and minimal, with no trailing bytes. Each field of rk is in its order with its exact length or value, and the ed element equals byte for byte the one generate gives. Generate checks its own new key’s form the same way, and fails when it differs.

The reader doesn’t check the bytes of the key fields bid, pub, wk, kid and rkm, only their lengths. A form with changed key-field bytes is deliberately not tested on hardware, because the tests don’t hand the Secure Enclave altered bytes.

In every build and on every backend, a read that fails because the store is locked waits for the unlock (S15-03-access-rulesS15-03-access-rules: Access RulesHow each host process gets only the credentials it needs, for only as long as it needs them, and which process may access which item., rule 7). That is -25308 on the Keychain, or a locked 1Password after V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there..

Any other failure is ca-key-restore:

  • a missing item;
  • a store error;
  • an error from the restore, including a wrapped form of another structure and a key whose signature doesn’t verify with its own public key;
  • a public key that differs.

Then wb-proxyd serves none of the VM’s streams, and the VM’s start or restore is refused with that rule.

In an ad-hoc signed build, the Keychain backend refuses every access with keychain-needs-team (S15-02-secret-storeS15-02-secret-store: The Secret StoreWhere credentials are held: the secret store, its backends, and the guarantees a backend must give.). An issue or a restore on that backend fails with that rule in place of ca-key-restore. So does the VM’s start or restore.

wb vm reset-ca <vm> (S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command.):

  1. drops the VM’s CAs from wb-hostd’s record;
  2. puts their items on the removal list (S15-03-access-rulesS15-03-access-rules: Access RulesHow each host process gets only the credentials it needs, for only as long as it needs them, and which process may access which item., “Declared access”);
  3. deletes the VM’s saved state.

The VM then cold boots. At that start the record has no CA, or every CA in it has expired. So wb-proxyd issues a new CA, and the install rewrites the guest’s trust files whole (S09-08-guest-trustS09-08-guest-trust: Guest TrustHow wb-guestd makes the guest's clients trust the VM's CAs.).

Only this command and wb setup --ca-key-store drop a CA that hasn’t expired. Each drop is a Device Config State Change (5019) event, with the command and the SHA-256 fingerprint of each dropped CA certificate.

Neither rotation nor a restart issues a new CA in place of one that failed.

One wrapped Secure Enclave key in every build

Section titled “One wrapped Secure Enclave key in every build”

The same wrapped key is used in every build, on the Keychain backend and on the 1Password backend after V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. (S15-02-secret-storeS15-02-secret-store: The Secret StoreWhere credentials are held: the secret store, its backends, and the guarantees a backend must give.).

A Mac VM’s virtual Secure Enclave is accepted and tested on CI

Section titled “A Mac VM’s virtual Secure Enclave is accepted and tested on CI”

wb-proxyd takes the key a Mac VM’s virtual Secure Enclave gives, and CI’s macOS runners run the shim’s round trip with it. This replaces decision 5 on I509I509 (closed): platform: Secure Enclave CA key kept as its wrapped form, with the CA item round trip on the maintainer's MacPackage M3.9 of docs/implementation-plan.md, part 4 of 5 (M3.9d)., which took a VM to have no Secure Enclave and expected generate and restore to fail there. CI’s runner (VirtualMac2,1) gave a working key.

The restore takes only the structure generate gives

Section titled “The restore takes only the structure generate gives”

The restore refuses a wrapped form whose structure or encoding differs from the one generate gives for a Secure Enclave P-256 key, before any call of Security.framework. The key fields bid, pub, wk, kid and rkm aren’t checked beyond their lengths.

Status: Draft