EQTY LabDocs

Notary Socket Protocol

The Unix socket protocol between a patched swtpm and the notary, its seven operations, and how an older peer on either side is handled.

View as Markdown

A patched swtpm reaches the notary over a dedicated Unix stream socket, <EQTY_VTPM_DIR>/notary.sock. One request per connection. Integers are big endian.

text
request   u32 length | u8 version (1) | u8 op | payload
response  u32 length | u8 version (1) | u8 status (0 = ok) | payload
          (on failure the payload is a UTF-8 reason, which swtpm logs)

Requests carry no vTPM ID. The notary identifies the vTPM by the peer’s PID, SO_PEERCRED on Linux and LOCAL_PEERPID on macOS, which must be an swtpm it launched and has not yet reaped. A child’s PID cannot be reused until it is waited for, so no pidfd is needed. The notary rate-limits each vTPM to 20 requests a second with a burst of 40, so one vTPM cannot starve the others or the notary’s own /v1/sign.

Operations

OpNameRequest payloadResponse payloadSince
0CAPSnonethe supported opsswtpm-notary 0.10.2-eqty.1, notary 0.0.8
1CHANGE_EPSnonenew seed, 64 bytesnotary 0.0.5
2EXTKEY_CREATEu32 hierarchy, u16 n, unique[n], u16 m, TPMT_PUBLIC[m]x[32], y[32], key_id[32]notary 0.0.5
3EXTKEY_SIGNkey_id[32], u16 hash_alg, u16 n, digest[n]r[32], s[32]notary 0.0.5
4EXTKEY_SIGN2as op 3, plus the key’s public pointr[32], s[32]notary 0.0.8
5GET_EPSu32 epochthe seed of that epoch, 64 bytesnotary 0.0.8
6EXTKEY_RELEASEu32 hierarchynonenotary 0.0.8

Capability negotiation

swtpm asks CAPS first. A notary that does not answer it, 0.0.5 to 0.0.7, fails the request, and swtpm keeps to ops 1 to 3 and behaves exactly as it did with those releases: the seed from the --eps descriptor, CHANGE_EPS for a new one, unbound EXTKEY_SIGN, and no key release. A notary that answers lists the ops it supports.

Seeds and epochs

The endorsement seed is derived, never stored: on Linux as HMAC(K_hw, "vtpm-eps" ‖ vTPM-ID ‖ epoch) with a fixedTPM keyed-hash key per vTPM in the host TPM, on macOS from a per-vTPM Secure Enclave key. The initial seed arrives on the --eps descriptor at start.

Without epochs, a reply to CHANGE_EPS lost between the two processes could leave the notary and the TPM on different seeds. With patch libtpms/0003, the state records which epoch it was written with, as a u32 in the otherwise zeroed seed field. A load asks GET_EPS for that epoch; TPM2_ChangeEPS asks for epoch plus one and commits only once it has the seed. The notary derives the same seed for the same epoch, re-derives past epochs, records epoch plus one as the new generation before replying, and refuses a larger jump. Manufacture fails rather than running on a zero seed when the seed is unavailable.

Bound signing

With op 3, a key ID alone obtains signatures, and the key ID sits in the state file. Op 4 carries the key’s public point with its ID, and the notary refuses a mismatch, so reading the state file is not enough to sign. On the libtpms side, TPM2_Load rejects a blob carrying the external-key marker unless it and its parent are fixedTPM, and CryptSign() forwards only fixedTPM objects.

Key creation

unique is present for primaries and derived objects, drawn from the object’s own DRBG, so the notary can re-create the same hardware key for the same template. Key IDs for primaries are HMAC(K_hw, "extkey-primary" ‖ hierarchy ‖ unique ‖ H(template)); ordinary keys get a random ID and a stored hardware blob. The top bit is cleared so an ID is a valid P-256 scalar. Declined deterministic keys consume no DRBG output, so primaries are identical with and without --extkey.

Key release

Op 6 names a hierarchy whose seed changed: after TPM2_ChangeEPS, TPM2_Clear, TPM2_ChangePPS and at TPM reset, which names the null hierarchy. The notary deletes the backing keys created in that hierarchy, whether they are soft keys, hardware TPM keys or Secure Enclave keychain items, so a key no longer reachable from the vTPM does not linger in the host.

Reference

The protocol reference is the header comment of swtpm/src/swtpm/eqty_notary.c in the repository. The notary side is notary_sock.rs in the notary-vtpm crate of vcomp-notary-desktop, with a protocol_tests module covering the new ops. tests/test_eps_epoch.py in swtpm-notary covers epochs, the fallback to a 0.0.7 notary and a missing seed; CI runs it.