Also known as TPM. A tamper-resistant cryptographic coprocessor on the motherboard. It serves as the hardware root of trust of a platform.
Hash functions and digital signatures provide the primitives used for measurements and attestation.
TPM Foundation
Components
- Cryptographic engines
Asymmetric encryption and signing, hashing, and a random number generator. - Non-volatile storage
Holds long-lived keys. Private keys never leave the chip in plain form. - Platform Configuration Registers (PCRs)
Secure registers that store measurements. They cannot be written directly, only extended. - Endorsement key
A unique key burned in by the manufacturer, identifying the TPM. - Storage root key
Wraps other keys, so keys can be stored outside the TPM while remaining protected by it.
Platform Configuration Registers
A PCR is a separate register, identified by its index. Each PCR holds 1 hash-sized value, 32 bytes with SHA-256.
The TPM 2.0 specification requires at least 24 PCRs, indexed 0 to 23. Many chips keep a separate bank for each hash algorithm, such as SHA-1 and SHA-256.
The index ranges are assigned as follows:
- PCRs 0 to 7
Reserved for firmware and boot components by the PC Client platform specification. PCR 0 holds firmware code, PCR 4 the boot manager, and PCR 7 the Secure Boot policy. - PCRs 8 to 15
Assigned by the bootloader and operating system, so the use of each register varies between systems. - PCRs 16 to 23
PCR 16 is for debugging, PCRs 17 to 22 for a dynamic root of trust, and PCR 23 for applications.
PCR Extend
A PCR can only be updated by combining its current value with a new measurement.
- hash function
- hash of the component being measured
- concatenation
The final value depends on every measurement and their order. A PCR cannot be set to an arbitrary value, so malware cannot erase an earlier measurement.
Boot Measurement
Establishing the Chain of Trust
Measured boot uses the TPM to record each link of the chain.
Each link extends the PCR of the component it measures. The numbers below assume a Linux system booted with GRUB. PCRs 0 and 4 follow the PC Client specification. PCRs 8 to 10 are conventions used by GRUB and IMA, and other bootloaders or operating systems may use different PCRs.
- UEFI firmware, measured by the Boot ROM, extends PCR 0.
- Bootloader, measured by UEFI firmware, extends PCR 4.
- Kernel and initramfs, measured by the bootloader, extend PCRs 8 and 9.
- Kernel modules and init, measured by the kernel through IMA, extend PCR 10.
- Applications, measured by the kernel, extend PCR 10.
Each component measures the next before executing it. A modified component produces a different PCR value.
The recorded PCR values are then used in 2 ways.
- Sealing
A secret, such as a disk encryption key, is encrypted by the TPM under a PCR policy. The TPM releases it only if the current PCR values match. A tampered boot chain never receives the key. - Remote attestation
The TPM signs the PCR values, together with a nonce from the verifier, using an attestation key. The verifier checks the signature and compares the PCRs against known-good values. The nonce prevents replay.
Secure boot and measured boot are complementary. Secure boot prevents unauthorized code from running. Measured boot produces evidence of what did run.
Runtime Measurement
Extension to the Operating System
The chain continues past the kernel through the OS.
- Linux Integrity Measurement Architecture (IMA)
The kernel hashes each executable, library, and configured file when it is loaded or opened. It appends the hash to a measurement log and extends PCR 10. - IMA appraisal
The kernel compares a file’s hash or signature against a value stored in the file’s extended attributes. The file is refused if it does not match. - Extended Verification Module (EVM)
Protects file metadata such as owner and permission bits. - Disk encryption
A disk key sealed to the boot PCRs is released only when the boot chain is intact.
Extension to User Applications
Application developers use the TPM through a software stack such as TPM2 Software Stack (TSS) or PKCS#11 rather than talking to the chip directly.
Developers should:
- Generate keys inside the TPM
Mark them non-exportable, so a compromised application cannot copy them. - Seal application secrets
Bind secrets such as API keys and data encryption keys to a PCR policy, so they are only released to an untampered platform. - Sign and verify code
Verify signatures on binaries, plugins, and updates before loading them. - Attest to remote servers
Send a signed quote with a fresh nonce before a server releases sensitive data. - Use monotonic counters
Prevent rollback to an older, vulnerable version of the application or its data. - Use the TPM random number generator
For keys and nonces. - Reseal after legitimate updates
A software update changes the PCR values and would otherwise lock the application out of its own secrets.