Introduction
In this post, we’ll dig in and interact with your own local Trusted Platform Module.
Note: If you don’t have access to a TPM-enabled computer, or the right admin privileges, Google hosts a fantastic TPM simulator here that exercises Intel TPM2 Software Stack, IBM TPM Simulator, and Google BoringSSL to create a great virtual platform for learning.
TPM First Contact (Windows)
The Microsoft Windows operating system relies on TPM-based capabilities for security components including BitLocker™ drive encryption, the Virtual Smart Card features, and the Crypto Provider. Windows 10 and 11 actually require TPM 2.0 to be enabled in ALL desktop and server editions. Measured Boot, enabled by the system’s TPM paired with remote attestation, secures the system configuration against rootkits and similar attacks that would otherwise be undetectable.
We can quickly check some details of the TPM on our Windows system by heading into the Device Manager screen and looking for the Security Devices section.
Let’s interact with it. Open a terminal window, and let’s get some basic information out of the system. Windows provides several powershell cmdlets that can be used immediately.
Get-Tpm returns a set of info from the module like below:
We can also infer a bit about the system underneath using this information: For example, the manufacturer field here will read "Intel" if the platform is equipped and using Platform Trust Technologies (PTT). In this case it's using a TPM from the manufacturer STM.
Get-TpmEndorsementKeyInfo -Hash "Sha256" can be used to get info about the endorsement public key and certs:
If that was fun, explore some of the other user-space operations here. Notice that most of these are about TPM information or ownership.
To use the TPM from an application perspective, we need to interact with the Windows Core Security features, specifically the TPM Base Services software component and associated API. Microsoft provides wrappers and utilities to help speed the integration of these operations here
and we'll start exploring these next.
TPM First Contact (Linux)
Storing and loading keys using a TPM in Linux is enabled using a set of standardized commands and libraries that make it possible to work with keys securely across any TPM 2.0 compatible module.
Checking to see if a TPM is present in the system can be done at a high level by simply looking through the system log with: dmesg | grep -i tpm
Here's a step-by-step to some basic interactions on a Linux system:
- Prerequisites:
- Ensure you have a TPM 2.0 chip installed on the target system.
- Install the necessary TPM 2.0 software packages. These packages may vary depending on your Linux distribution. Common packages include tpm2-tools and tpm2-tss.
- Initialize the TPM:
- Before using the TPM, initialize it if it hasn't been done already. You can use the tpm2_startup command to initialize the TPM.
- Create an Application Key:
- Generate an application-specific key that you want to store in the TPM. You can use a software library like OpenSSL or a TPM library like tpm2-tools to generate this key.
- For example, you can generate an RSA keypair: openssl genpkey -algorithm RSA -out appkey.pem
- Load the Key into the TPM:
- Use the TPM 2.0 tools to load your application-specific key into the TPM. You will typically use the tpm2_load command for this purpose: tpm2_load -C context.out -u appkey.pub -r appkey.priv
- This command loads the key into the TPM and saves its context in the context.out file. You will need this context to use the key later.
- Use the TPM-Resident Key:
- When your application needs to use the key, you can use TPM commands or libraries like tpm2-tss to perform cryptographic operations with the TPM-resident key. For example, if you want to sign data with the TPM key: tpm2_sign -c context.out -g sha256 -m data.txt -s signature.bin
- This command signs the data using the TPM-resident key and saves the signature in signature.bin.
- Unload the Key (Optional):
- If you no longer need the TPM-resident key, you can unload it from the TPM using the tpm2_flushcontext command: tpm2_flushcontext -c context.out
- This frees up TPM resources associated with the key.
- Shutdown and Cleanup (Optional):
- After your application is done using the TPM, you can shut down the TPM using the tpm2_shutdown command.
Now we’re putting the TPM to work! Note that while the loaded key does benefit from the built-in protections that the TPM offers (see Table: TPM Feature Breakdown in the last blog here), it’s otherwise unguarded.
What's Next?
In the next article, we will be creating policies to seal, protect, and extend the root of trust.
Reach out to Intel's Health and Life Sciences team at health.lifesciences@intel.com or learn more about security features at https://www.intel.com/health.
About the Author
Andrew Lamkin is a Health Security-focused AI Solutions Architect at Intel Health & Life Sciences, where he applies his background in mission-critical computing from the defense and aerospace industries to build a foundation for trusted computing in healthcare.
Links and Resources
Google’s TPM simulator: Intel TPM2 Software Stack, IBM TPM Simulator, Google BoringSSL
Trusted Computing Group’s resources on TPM 2.0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.