Machine Enrollment Protocol v0 (Draft)
Machine Enrollment Protocol v0 #
Introduction #
When a new machine is added, a cryptographic binding must be established between it and the authorization server. Through that binding, symmetric key material is exchanged which can then be used to exchange further keys and secure communications between parties.
At the end of the process, both parties:
- Possess a Pairwise Storage Key, under which further keys can be exchanged, and
- Possess a KDF key, through which software keys can be derived (via HKDF-Expand). This may, among other things, be used to derive TLS PSKs
Terminology #
- Enroller: An administrator or provisioning system with permission to enroll machines.
- EK: a TPM2 Endorsement Key. EKs are typically certified by manufacturers, and are capable of performing limited decryption operations via
TPM2_ActivateCredential. - AK: a TPM2 Attestation Key. Attestation keys are typically provisioned by applications, and are capable of signing TPM-generated attestations.
Security Considerations #
This protocol targets machines with a TPM 2.0 compliant TPM. For machines without a TPM, one can be emulated in software, with a corresponding decrease in achieved security guarantees. Machines with non-TPM hardware security modules are currently considered out of scope.
The precise mechanism used for key control within the IDP is left unspecified. If it is not also a TPM 2.0 compliant TPM, it must be capable of interoperating with TPM 2.0 data structures.
The security policies in this document are stated assuming use of a HSM at the IDP end, and a TPM at the machine end. In the case that software encryption is used, guarantees about non-exposure to software on either machine are obviously void.
At the time of writing, no hardware is available containing a TPM with support for post-quantum key encapsulation algorithms (e.g. ML-KEM). Even when such hardware becomes available, it will take a long time for hardware with older TPMs to be phased out.
Our security posture is therefore:
- The whole protocol is executed within a TLSv1.3 tunnel, whereby the Key Encapsulation Method must be post-quantum secure.
- The Pairwise Storage Key is, for transport, encrypted directly from the IDP's HSM to a Machine Wrapping Key that is restricted to the machine's TPM. At no point is this key's key material exposed to software on either the IDP or Machine.
- The TPM "Inner Encryption Key" for the key transport procedure is derived via a TLS Keying Material Exporter from the secrets established for the TLS connection.
As a result, "Harvest Now, Decrypt Later" attacks on the connection between machine and IDP are prevented. To recover the Pairwise Storage Key, an adversary with a quantum computer must first observe the exchange between either the machine or the IDP and its corresponding HSM, and extract the TLS Exporter Master Secret from an endpoint.
Protocol layering #
The machine establishes a TLS 1.3 protected WebSocket connection to the path /api/internal/machine/v0/enrollment on the IDP.
The machine offers only PQ secure key exchange methods (either hybrid or pure PQ), optionally combined with session resumption, and does not offer 0-RTT data. The machine also validates the IDP's WebPKI certificate as a first identity check.
The TLS connection must be terminated directly by the IDP itself, or exported values will mismatch between both connection endpoints.
The IDP validates that the connection was established with a post-quantum-secure key exchange mode. If Session Resumption was performed, it must have been performed in psk_dhe_ke mode, and without 0-RTT data. If any of these conditions fail, the IDP rejects websocket establishment with a 400 Bad Request error and further details expressed in RFC 9457 Problem Detail format.
Protocol messages are CBOR encoded and transmitted within WebSocket binary frames. Errors are RFC 9457 Problem Details, encoded in JSON, and transmitted within text frames.
Some common types are reused in the CDDL specifications within this document:
; UUID as encoded per RFC 4122
uuid = bstr .size 16
; X.509 certificate carried as a byte string
x509-cert = bstr
; TPM 2.0 structures carried in their normal encoding
tpm-public = bstr ; TPMT_PUBLIC
tpm-attest = bstr ; TPMS_ATTEST
tpm-signature = bstr ; TPMT_SIGNATURE
tpm-creation = bstr ; TPMS_CREATION_DATA
; Shared data structure for carrying child keys
child-key = {
0: tpm-public, ; Key public area
1: bstr, ; Key private area, encrypted under the parent key
}
Every TPM structure received MUST unmarshal completely with no trailing bytes. The receiver MUST re-marshal it and compare it with the received bytes before computing any Name or digest over it. On any validation failure the verifier MUST abort, send a generic Problem Detail that does not identify which check failed, and close the connection. The reason SHOULD be logged locally.
Appropriate Algorithms #
Throughout this specification, references are made to "Appropriate Algorithms". At the time of writing, these are considered to be:
- Hash algorithms (including TPM naming algorithms): SHA-256 or any larger SHA-2 variant, any SHA-3 variant, SHAKE-128 or larger
- MAC algorithms: HMAC with any permitted hash algorithm, KMAC or KMACXOF, CMAC with any permitted block cipher
- Block ciphers: AES-128, 192 or 256
- Block cipher modes of operation: CTR, OFB, CBC, CFB, CCM, GCM, EAX
- Public key key enacpsulation: ML-KEM-768 or larger, ECDH with NIST P-256 or larger NIST prime curves, Curves 25519 or 448, RSA-2048 or larger (with RSAES-OAEP)
- Public key signature: ML-DSA-44 or larger, ECDSA with NIST P-256 or larger NIST prime curves, EdDSA with curves 25519 or 448, RSA-2048 or larger (with RSASSA-PSS or RSASSA-PKCS1v1.5)
Other algorithms MAY be permitted by the IDP after appropriate cryptographic review. SHA-1 and TripleDES MUST NOT be accepted. Algorithms from the above list MUST NOT be accepted with key sizes smaller than specified.
Implementations MUST implement:
- SHA-256 as a hash algorithm, HMAC-SHA-256 as a MAC algorithm
- AES-128 in CFB mode as a block cipher algorithm
- RSA-2048 with RSAES-OAEP for key encapsulation and with RSASSA-PSS or RSASSA-PKC1v1.5 for signing; ECDH and ECDSA with the P-256 curve for key encapsulation and signatures respectively
These requirements are aligned with the TCG PC Client Platform TPM Profile (PTP) Specification
Protocol Flow #
Preparation #
If the machine is in possession of an Endorsement Certificate from the TPM manufacturer, the enroller may pre-enter it into the IDP. If it is not in possession of an Endorsement Certificate, the enroller may instead create an Endorsement Key (if necessary) and enter said Endorsement Key.
Whether either step is required is a matter for local policy.
The IDP then provisions the enroller with an Enrollment Token. This is a base64url encoded CBOR structure:
enrollment-token = {
0: uuid, ; Machine's UUID
1: bstr, ; the enrollment secret, minimum 256-bits
2: str, ; IDP hostname
}
To execute the protocol, the enroller must provide the token to the machine in question.
The IDP stores SHA-256(machine_uuid || secret) as a verifier in the machine record.
The machine UUID is incorporated to prevent the verifier being swapped to another record.
A SHA-256 hash is stored to prevent a person with access to the IDP's database from enrolling a machine.
Step 1: Machine Initial #
The machine establishes a parameter-encryption enabled session with the TPM. Parameter encryption MUST be used for the TPM2_Import and TPM2_ActivateCredential commands in later protocol steps.
The machine computes the Masked Enrollment Secret by computing
secret_verifier = SHA-256(machine_uuid || secret)
mask = TLS-Export("EXPORTER: falke machinev0 enrollment secret mask", secret_verifier, len(secret))
masked_secret = secret XOR mask
It creates an Attestation Key, and then transmits the machine initial message:
enrollment-machine-initial = {
0: uuid, ; UUID of machine being enrolled
1: bstr, ; Masked enrollment secret
? 2: x509-cert, ; EK certificate, DER X.509 (only when the TPM has one)
3: tpm-public, ; EK public area
4: tpm-public, ; AK public area
}
Step 2: Attestation Challenge #
The IDP MUST implement rate limiting for attempts by a given source.
The IDP recovers the secret
mask = TLS-Export("EXPORTER: falke machinev0 enrollment secret mask", secret_verifier, len(masked_secret))
secret = masked_secret XOR mask
It then recomputes the verifier and checks it against the stored value to ensure the correct value was sent. This comparison MUST be performed in constant time. Through this process, the IDP has established that (a) the machine is in possession of the correct secret, and (b) that the TLS connection is secured end-to-end between itself and the machine in possession of the secret.
The IDP MUST return identical failures for (a) submissions of an unknown machine UUID, and (b) submissions of an incorrect masked secret. The IDP SHOULD ensure it performs identical computations whether or not the machine is known (e.g. by running the unmasking process with a dummy context), to thwart timing attacks.
At this point, the IDP must prevent concurrent enrollment sessions from being established for the same machine. (If the machine disconnects at any point before completing this process, the lock must be released.)
The IDP then validates that
- The EK public area specifies appropriate algorithms with
restricted,decrypt,fixedTPM,fixedParentandsensitiveDataOriginset andsignclear. - If an EK certificate is present, the public key matches the EK Public Key
- If the record has a pre-registered EK certificate or public key, they match against the presented values
- If an EK certificate is present, it validates it against known chains (if such validation is enabled)
- The AK public area specifies appropriate algorithms with
restricted,sign,fixedTPM,fixedParentandsensitiveDataOriginset, anddecryptclear - The AK name must differ from the EK name
It computes a secret confirmation:
confirmation = TLS-Export("EXPORTER: falke machinev0 enrollment secret confirmation", secret, len(secret))
It computes a challenge (per TPM2_MakeCredential). The challenge is encrypted to the EK, and references the AK. The credential value is a randomly generated 32 byte challenge.
The outputs are transmitted inside the IDP Attestation Challenge message:
enrollment-idp-attestation-challenge = {
0: bstr, ; enrollment secret confirmation
1: bstr, ; credential challenge blob (idObject)
2: bstr, ; credential challenge secret (encapsulated seed)
}
Step 3: Attestation Response & Machine Wrapping Key Exchange #
The machine recomputes the secret confirmation and validates that the IDP produced the same value. In doing so, it confirms that the TLS connection is secured end-to-end between itself and the IDP. The machine MUST verify the secret confirmation, in constant time, before issuing any TPM command that uses the challenge. On mismatch it MUST abort the connection.
The machine uses TPM2_ActivateCredential to recover the challenge.
The TPM2_ActivateCredential command MUST use an HMAC session salted to the EK, with the session attribute encrypt set so the returned certInfo is encrypted on the bus.
(This protects against passive bus snooping. It does not authenticate the salt key against an active interposer.)
By its ability to do so, it demonstrates that the AK is indeed an AK resident in the same TPM.
The machine constructs the Machine Wrapping Key, with the following options:
type,curve,symDefandnameAlgset to Appropriate Algorithms- Restricted, Decrypt, FixedTPM, FixedParent and SensitiveDataOrigin set, and Sign clear
outsideInfoset toSHA-256(challenge_value).- an authPolicy or authValue that restricts use of the key to the enrolled software (SHOULD)
- a parent that is a primary key in the owner hierarchy (the SRK or equivalent). It MUST NOT be a null-hierarchy or platform-hierarchy key.
The machine computes the Attestation Extra Data:
extra_data = TLS-Export(
"EXPORTER: falke machinev0 enrollment wrapping key attestation",
machine_uuid || wrapping_key_public, 32)
It attests the Machine Wrapping Key (using TPM2_CertifyCreation).
It removes the extra data from the attestation structure (leaving a zero-length TPM2B structure), and then passes the public key, creation information, attestation and signature to the IDP in the Machine Attestation Response message.
enrollment-machine-attestation-response = {
0: tpm-public, ; machine wrapping key public area
1: tpm-creation, ; machine wrapping key creation data
2: tpm-attest, ; TPM2_CertifyCreation attestation over field 0
3: tpm-signature, ; attestation signature under the step 1 AK
}
Step 4: Pairwise Storage Key Transfer #
The IDP MUST verify the Machine Wrapping Key:
- The public area matches the constraints outlined above:
type,curveandsize,symDef,nameAlg,attributes, and aschemeof null. - The attestation has
magic=TPM_GENERATED_VALUEandtype=TPM_ST_ATTEST_CREATION. objectNameequals the Name computed from field 0, andcreationHashequals the hash, under the key'snameAlg, of the creation data.- The
restricted,decrypt,fixedTPM,fixedParentandsensitiveDataOriginflags must be set. Thesignflag must be unset. - The creation data's
outsideInfoequalsSHA-256(challenge). - The creation data's
parentQualifiedNameequalsH(TPM_RH_OWNER || parentName), computed with the algorithm named inparentNameAlg. This shows that the parent is a primary key in the owner hierarchy. - The signature algorithm of the attestation matches that of the AK.
- After reinserting the recomputed
extraData, the signature verifies under the challenged AK.
The IdP SHOULD record creationPCR if present. Boot state is otherwise a non-goal for this revision of the specification. The private data required to load the Machine Wrapping Key must be protected with OS-level access control mechanisms.
The machine IDP constructs the Pairwise Storage Key and duplicates it to the Machine Wrapping Key in the IDP Key Transfer message.
The key is created using the AES-128-CFB, SHA-256 algorithm combination that is considered mandatory to implement in the PC TPM profile.
When creating the key, the IDP sets the encryptedDuplication flag on the key and attaches appropriate policies.
In particular, it prohibits duplication to any key except the Machine Wrapping Key.
When duplicating the key, it generates an inner encryption key:
inner_key = TLS-Export(
"EXPORTER: falke machinev0 enrollment pairwise key inner encryption",
machine_uuid || pairwise_key_public, (innerAlg.symDef.keyBits + 7) / 8)
This is used as the encryptionKeyIn parameter to TPM2_Duplicate. The algorithm used for the inner wrap matches that used for the outer wrap.
enrollment-idp-key-transfer = {
0: tpm-public, ; pairwise storage key public area (IdP-authored)
1: bstr, ; TPM2_Duplicate duplicate (TPM2B_PRIVATE body bytes)
2: bstr, ; TPM2_Duplicate outSymSeed (TPM2B_ENCRYPTED_SECRET body bytes)
}
Once the IDP Key Transfer message has been transmitted, the duplicate and outSymSeed values from the duplication process MUST be erased.
Step 5: KDF Key Transfer #
The machine validates the Pairwise Key's public area:
restricted,decrypt,encryptedDuplication,userWithAuthMUST be set, andfixedTPM,fixedParentandsignMUST be clear.authPolicyequal to the digest ofPolicyCommandCode(TPM2_CC_Duplicate)followed byPolicyDuplicationSelect(newParentName = TPM2_Name(Machine Wrapping Key))
The machine MUST compute that digest itself rather than trust any value supplied by the IdP.
The machine MUST derive innerKey in the same manner as done by the IDP in step 4. It MUST pass it as encryptionKey to TPM2_Import, together with the correct symmetricAlg. TPM2_Import MUST use a session with the decrypt attribute set. If TPM2_Import fails, the machine MUST abort the session.
During the import process, TPM rewraps it using the Machine Wrapping Key's symmetric seed value. The machine MUST then erase the duplication data. (From this point forth, for the purposes of this protocol, the asymmetric algorithm associated with the Machine Wrapping Key is immaterial)
The machine then constructs the KDF Key using TPM2_Create:
- Algorithm set to
KEYEDHASHwith HMAC-SHA-256, nameAlg SHA-256,sign,fixedParentandsensitiveDataOriginset, anddecryptandfixedTPMclear. sensitivemust be empty so that the key material is generated inside the TPM.
The KDF Key will be used to deterministically derive software keys, via HKDF-Expand.
USAGE_KEY_CONFIRMATION = 0x0000
KDF-Derive(key, usage: u16, context: bytes, L int) = HKDF-Expand(key, usage || context, L)
It computes a confirmation value to prove possession of the key
confirmation_context = TLS-Export("EXPORTER: falke machinev0 kdf confirmation", 0x00 || kdf_key_public, kdf_key.hash_len)
confirmation = KDF-Derive(kdf_key, USAGE_KEY_CONFIRMATION, 0x00 || confirmation_context, kdf_key.hash_len)
enrollment-machine-completion = {
0: child-key, ; Primary KDF key
1: bstr, ; KDF key confirmation (client to server)
}
Step 6: IDP Confirmation #
The IDP validates that the KDF key's public area indicates that it's a HMAC/SHA-256 key, that SensitiveDataOrigin and FixedParent are set and that Sign is set and Decrypt is clear.
The IDP then loads the KDF key using TPM2_Load.
It recomputes the client's confirmation context in order to validate it.
It then computes its own confirmation, in a similar manner except with the direction bytes altered:
confirmation_context = TLS-Export("EXPORTER: falke machinev0 kdf confirmation", 0x01 || kdf_key_public, kdf_key.hash_len)
confirmation = KDF-Derive(kdf_key, USAGE_KEY_CONFIRMATION, 0x01 || confirmation_context, kdf_key.hash_len)
It then transmits a completion message:
enrollment-idp-completion = {
0: bstr, ; KDF key confirmation (server to client)
}
Connection Closure #
The machine recomputes the IDP's confirmation and validates that it matches the transmitted value. Following validation, it saves the exchanged keys to persistent storage.
At this point, the protocol is successful. The machine orderly closes the connection (with Status Code 1000, Normal Closure). The IDP then
- Records any EK Certificate and the EK Public Key against the machine's record, and the trust mode of the EK
- Records the AK Public Key
- Records the Machine Wrapping Key
- Records the machine's Pairwise Storage Key and KDF keys against the machine's record, and
- Removes the enrollment secret (invalidating it)
The IDP considers the machine provisioned.
If the connection is closed for any other reason, the IDP discards all received and generated keys. The machine may re-attempt enrollment with the same secret.