EQTY LabDocs

Patches

The three libtpms patches and four swtpm patches that make up swtpm-notary, what each changes, and what the state file still holds.

View as Markdown

The changes to upstream are kept as a git format-patch series against the v0.10.2 tags in patches/libtpms/ and patches/swtpm/, for review and upstreaming. scripts/verify-patches.sh checks that the vendored trees are exactly upstream plus the series. Each patched spot in libtpms is marked libtpms EQTY added or changed; the new swtpm code is one file, swtpm/src/swtpm/eqty_notary.c.

The hooks are no-ops unless registered. Without --eps or --extkey, the build behaves like upstream.

libtpms

PatchWhat it does
0001 seed hookTPMLIB_RegisterSeedCallbacks(). The endorsement primary seed is asked for at manufacture, at every state load and on TPM2_ChangeEPS, and marshalled as zeros. Such a state sets flag 0x8000 in its header’s min_version, so unpatched libtpms rejects it; the patched one refuses to mix the two kinds in either direction.
0002 extkey hookTPMLIB_RegisterExtKeyCallbacks(). New fixedTPM, sign-only, not decrypt ECC P-256 objects are offered to extkey_create. A backed object keeps a 32-byte key ID in place of its private scalar, marked in seedValue, and CryptSign() forwards ECDSA to extkey_sign. Backed objects cannot be duplicated, imported, loaded externally or used with TPM2_Commit. CryptCreateObject() takes the object’s hierarchy.
0003 hardeningSeed epochs: the state records which seed epoch it was written with; loads ask for that epoch and TPM2_ChangeEPS for the next, so a lost reply cannot leave the notary and the TPM on different seeds. Manufacture fails instead of running on a zero seed. TPM2_Load rejects a blob carrying the external-key marker unless it and its parent are fixedTPM, and CryptSign() forwards only fixedTPM objects, so a key ID alone cannot obtain signatures. extkey_sign gets the object’s public point. New optional extkey_release(hierarchy) after ChangeEPS, Clear, ChangePPS and at reset. Declined deterministic keys no longer consume DRBG output.

swtpm

PatchWhat it does
0001 --epsReads the seed from a descriptor, keeps it in locked memory, and registers the seed hook. TPM2_ChangeEPS asks the notary for the next seed.
0002 --extkeyRegisters the extkey hook and forwards key creation and signing to the notary. identity mode backs restricted endorsement-hierarchy keys, the IAK and AKs; all-signing every eligible key.
0003 macOSPortability of eqty_notary.c: memset_s, htonl, FD_CLOEXEC.
0004 protocolThe swtpm side of 0003 above: the CAPS probe, EXTKEY_SIGN2 with the public point, GET_EPS by epoch, and EXTKEY_RELEASE, with a fallback to ops 1 to 3 for a notary that does not answer CAPS. See Notary Socket Protocol.

Why forward inside libtpms

Every signing command, TPM2_Sign, Quote, Certify, CertifyCreation, GetTime and the rest, funnels through CryptSign() after libtpms has done all authorization, restriction and ticket checks. Forwarding there keeps TPM semantics exact: key names and qualified names are correct, because the vTPM object’s public area holds the hardware key’s point; response HMACs are computed over the real signature; and existing TPM software works unmodified.

The alternative, a command proxy in front of stock swtpm, would have to terminate the client’s sessions and re-implement TPM authorization, and a shadow software key gives the wrong key names and breaks response HMACs. Forwarding inside libtpms costs a fork, but a small and contained one.

What stays in software

Hardware backing moves the keys into silicon. These remain decisions libtpms makes in host memory:

  • Authorization. Sessions, HMACs, passwords and policies, including PolicyPCR on the vTPM’s own PCRs. The hardware only checks that the request came from the notary.
  • The restricted attribute. A restricted vTPM key is backed by an unrestricted hardware key. libtpms enforces the restriction, then hands the digest to the hardware. A hardware-restricted key could not serve: it would refuse to sign a quote over PCRs that are not the hardware’s.
  • What gets signed. Quote contents and NV data are software state. What is measured into the vTPM’s PCRs is the consumer’s concern: VM firmware and IMA, or the notary itself.

What the state file still holds

The endorsement seed is never in it. But an EK made persistent with TPM2_EvictControl, as tpm2_createek -c and most provisioning tools do, is stored in NV with its private scalar, like any persistent object. A copied state file then contains an EK that a patched libtpms with any seed would load. The notary-held key that encrypts the state file is what protects it; the “no EK in a copied state” property holds for the unencrypted content only while the EK is transient.

The EK is also still a software key: its seed is hardware-derived, but ECDH is not forwarded yet, so ActivateCredential and salted sessions run in software. That is the next phase.