Demystifying Trusted Platform Modules, Part 1

Trusted Platform Modules (aka TPM or TPM2.0), store digital keys in a secure way. When you generate a private key in a TPM, there is no way for anyone to read that key (not an attacker nor even the device owner). Instead, data is sent to the TPM for decrypting or signing. The TPM uses the private key internally and returns the decrypted or signed data back to you. To many tech-savvy people today, this high-level information is common knowledge.

But how does a developer actually use a TPM? How do they see the public keys in a specific TPM? How do they sign or decrypt a piece of data? Most public information regarding TPMs is either very high-level, or so low-level that it’s not helpful to learn from. This blog post will explain with mid-level technical depth & hands-on examples. We’ll be using Linux shell commands throughout, as that is the easiest way to experiment and get familiar. For a production application, there are libraries in C, Python, etc that can replace the shell commands.

Initial Setup

We recommend a $60 Infineon IRIDUIM SLB9670 eval board and a RaspberryPi to get started. We did this demo on a RaspberryPi4 that was already running a custom Yocto image. See below for how to integrate this TPM into a Yocto image. For enabling the TPM in the stock Raspbian image, Infineon already documented this thoroughly. Summit Embedded has also used this SLB9670 eval board on other devices besides just a Raspberry Pi.

You can play with the TPM in your main PC in leiu of buying a TPM eval board. But, if the operating system uses the TPM to store any Secure Boot or disk encryption keys, then you may end up causing your PC to be unbootable depending on what tpm2_* commands you run.

To make sure your embedded device’s TPM drivers are installed correctly, run two commands:

ls /dev/tpm*;

tpm2_getcap properties-fixed && tpm2_getcap properties-variable;

The former verifies the device tree & kernel configuration. The latter verifies SPI communication with the device and that you have the right tpm2_* tools installed. If these commands return errors, fix them before continuing.

Next, there are a few common use cases we can try out on the TPM. We’ll split them up into separate blog posts and link to each here:

Summit Embedded Blog: TPM Series

  1. TPM Set-up/Overview (this post)

  2. Inspect the Non-Private Contents of a TPM

  3. Store Non-Private Data (NVRAM)

  4. Encrypt & Decrypt Data

  5. Generate a Device Identity Certificate

  6. Sign Data With A Certificate

Appendix: Using TPM2 in Yocto

To use a TPM in yocto, you need to do two things:

1) Include all the tpm2_* binaries to work with the TPM. Add the following to your image recipe:

  • IMAGE_INSTALL:append = " packagegroup-security-tpm2 tpm2-tss-engine-dev opensc"

  • packagegroup-security-tpm2 installs the core tpm2 functionality, including tpm2-tools and various libtss2 packages
  • tpm2-tss-engine-dev is just a symlink to /usr/lib/engines-3/libtpm2tss.so from ./tpm2tss.so (openssl commands assume tpm2tss.so exists)
  • opensc adds pkcs11-tool for dealing with certs

2) Tell the kernel what SPI bus you’ve connected your TPM to. Do this via the device tree.

  • If using an Optiga SLB9670/SLM9670 (very common), you can adapt Toradex’s tpm node in their Mallow board dtsi file for your SPI bus pins.

  • For other TPM models, or help adapting the example device tree, Contact Us!

Next
Next

USB-Controlled Relays