Trusted Platform Module
Trusted Platform Module (TPM) is an international standard for a secure cryptoprocessor, which is a dedicated microprocessor designed to secure hardware by integrating cryptographic keys into devices.
In practice a TPM can be used for various different security applications such as secure boot, key storage and random number generation.
TPM is naturally supported only on devices that have TPM hardware support. If your hardware has TPM support but it is not showing up, it might need to be enabled in the BIOS settings.
Versions
There are two very different TPM specifications: 2.0 and 1.2, which also use different software stacks.
- TPM 2.0 allows direct access via
/dev/tpm0
(one client at a time), kernel-managed access via/dev/tpmrm0
, or managed access through the tpm2-abrmd resource manager daemon. According to a systemd project member, using tpm2-abrmd is no longer recommended. There are two choices of userspace tools, tpm2-tools by Intel and ibm-tssAUR by IBM. - TPM 1.2 uses the "TrouSerS" TSS (TCG software stack) by IBM, which is packaged as (tcsd) and (userspace). All software access the TPM through the tcsd daemon.
TPM 2.0 requires UEFI boot; BIOS or Legacy boot systems can only use TPM 1.2.
Some TPM chips can be switched between 2.0 and 1.2 through a firmware upgrade (which can be done only a limited number of times).
Using TPM 2.0
Many informative resources to learn how to configure and make use of TPM 2.0 services in daily applications are available from the tpm2-software community.
Checking support
A TPM 2.0 chip has been a requirement for computers certified to run Windows 10 since 2016-07-28. Linux has support for TPM 2.0 since version 3.20 and should not require any other steps to be enabled on a default Arch install.
Two ways to verify whether TPM 2.0 is setup without specific software:
Data-at-rest encryption with LUKS
There are two methods for unlocking a LUKS volume using a TPM. You can use Clevis or #systemd-cryptenroll.
Using either method, an encrypted volume or volumes may be unlocked using keys stored in a TPM, either automatically at boot or manually at a later time. Using a TPM for this purpose ensures that your drives will not unlock unless certain conditions are met, such as your firmware not having been modified and Secure Boot not having been disabled (see #Accessing PCR registers).
systemd-cryptenroll
has native support for enrolling LUKS keys in TPMs. It requires the following:
- must be installed,
- A LUKS2 device (currently the default type used by cryptsetup),
- If you intend to use this method on your root partition, some tweaks need to be made to the initramfs (see systemd-cryptsetup-generator for advanced configuration) :
To begin, run the following command to list your installed TPMs and the driver in use:
$ systemd-cryptenroll --tpm2-device=list
A key may be enrolled in both the TPM and the LUKS volume using only one command. The following example binds the key to PCRs 0 and 7 (the system firmware and Secure Boot state):
# systemd-cryptenroll --tpm2-device=/path/to/tpm2_device --tpm2-pcrs=0+7 /dev/sdX
where /dev/sdX
is the full path to the encrypted LUKS volume and /path/to/tpm2_device
is the full path to the TPM as given in the output of the first command.
To test that the key works, run the following command while the LUKS volume is closed:
# /usr/lib/systemd/systemd-cryptsetup attach mapping_name /dev/sdX - tpm2-device=/path/to/tpm2_device
where is your chosen name for the volume once opened. If the volume successfully unlocks, you are ready to add the required information to the crypttab so that can automatically unlock the device at boot.
If the volume you wish to unlock contains your root file system, you must take the following additional steps:
- Ensure you are using and in the array of
- Configure your initramfs to unlock the root volume with one of the following methods:
- Specifying the root volume using the configuration outlined above in (see tip at the top of dm-crypt/System configuration#Using systemd-cryptsetup-generator)
- Setting
rd.luks.options=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=tpm2-device=auto
in addition to or in the kernel command line
To remove a key enrolled using this method, run:
# systemd-cryptenroll /dev/sdX --wipe-slot=slot_number
where is the numeric LUKS slot number in which your TPM key is stored.
Alternatively, run:
# systemd-cryptenroll /dev/sdX --wipe-slot=tpm2
to remove all TPM-associated keys from your LUKS volume.
See and for more information and examples.
Other good examples of TPM 2.0 usage
- SSH: 's SSH configuration and Using a TPM for SSH authentication (2020-01)
- Configuring Secure Boot + TPM 2 (2018-06, Debian)
- Using the TPM - It's Not Rocket Science (Anymore) - Johannes Holland & Peter Huewe (2020-11, Youtube): examples for OpenSSL with
Using TPM 1.2
Drivers
TPM drivers are natively supported in modern kernels, but might need to be loaded:
# modprobe tpm
Depending on your chipset, you might also need to load one of the following:
# modprobe -a tpm_{atmel,infineon,nsc,tis,crb}
Usage
TPM 1.2 is managed by , a userspace daemon that manages Trusted Computing resources and should be (according to the TSS spec) the only portal to the TPM device driver. is part of the package, which was created and released by IBM, and can be configured via /etc/tcsd.conf
.
To start tcsd and watch the output, run:
# tcsd -f
Once is running you might also want to install which provides many of the command line tools for managing the TPM.
Some other tools of interest:
- opencryptoki — A PKCS#11 implementation for Linux. It includes drivers and libraries to enable IBM cryptographic hardware as well as a software token for testing.
Basics
Start off by getting basic version info:
$ tpm_version
and running a selftest:
Securing SSH keys
There are several methods to use TPM to secure keys, but here we show a simple method based on .
First, create a new directory and generate the key:
$ mkdir ~/.simple-tpm-pk11 $ stpm-keygen -o ~/.simple-tpm-pk11/my.key
Point the configuration to the key:
Now configure SSH to use the right PKCS11 provider:
It is now possible to generate keys with the PKCS11 provider:
$ ssh-keygen -D /usr/lib/libsimple-tpm-pk11.so
Accessing PCR registers
Platform Configuration Registers (PCR) contain hashes that can be read at any time but can only be written via the extend operation, which depends on the previous hash value, thus making a sort of blockchain. They are intended to be used for platform hardware and software integrity checking between boots (e.g. protection against Evil Maid attack). They can be used to unlock encryption keys and proving that the correct OS was booted.
The TCG PC Client Specific Platform Firmware Profile Specification defines the registers in use:
PCR | Use | Notes |
---|---|---|
PCR0 | Core System Firmware executable code (aka Firmware) | May change if you upgrade your UEFI |
PCR1 | Core System Firmware data (aka UEFI settings) | |
PCR2 | Extended or pluggable executable code | |
PCR3 | Extended or pluggable firmware data | Set during Boot Device Select UEFI boot phase |
PCR4 | Boot Manager Code and Boot Attempts | Measures the boot manager and the devices that the firmware tried to boot from |
PCR5 | Boot Manager Configuration and Data | Can measure configuration of boot loaders; includes the GPT Partition Table |
PCR6 | Resume from S4 and S5 Power State Events | |
PCR7 | Secure Boot State | Contains the full contents of PK/KEK/db, as well as the specific certificates used to validate each boot application |
PCR81 | Hash of the kernel command line | Supported by grub and systemd-boot |
PCR91 | Hash of the initrd | Kernel 6.1 might measure the kernel cmdline |
PCR101 | Reserved for Future Use | |
PCR111 | Hash of the Unified kernel image | see systemd-stub |
PCR121 | Overridden kernel command line, Credentials | see systemd-stub |
PCR131 | System Extensions | see systemd-stub |
PCR141 | Unused | |
PCR151 | Unused | |
PCR161 | Debug | May be used and reset at any time. May be absent from an official firmware release. |
PCR23 | Application Support | The OS can set and reset this PCR. |
- Use case defined by the OS and might change between various Linux distros and Windows devices.
On Windows, BitLocker uses PCR8-11 (Legacy) or PCR11-14 (UEFI) for its own purposes. Documentation from tianocore.
facilitates this check with a human observer and dedicated trusted device.
# cat /sys/kernel/security/tpm0/ascii_bios_measurements
Troubleshooting
tcsd.service failed to start
After installing trousersAUR, the service may not start correctly due to permission issues. It is possible to fix this either by rebooting or by triggering the udev rule that is included in the trousersAUR package:
# udevadm control --reload-rules # udevadm trigger
TPM2 LUKS2 unlocking still asking for password
If you followed the instruction described above for automatically unlocking luks2 devices with enrolled keys in a TPM2 hardware module, but still receive a prompt to input a password during the initramfs boot stage. You may need to early load the kernel module (you can obtain its name with ) that is responsible for handling your specific TPM2 module.