
App. to encrypt/decrypt using TPM and IBM TSS
Goal and requirement: Avoid leaving files with sensitive information in clear text on the box. This should happen without any user intervention.
Proposed Solution: Create a random key and encrypt the files with sensitive information using this openssl key. So, now we need to secure this openssl key. This will be secured by the TPM chip on the router. This is done as key.bin is the most important info for the attacker. So, the key used for encryption is secured by the TPM. This key.bin is deleted from the filesystem after sealing it in the TPM. It is retrieved from the TPM on the fly as and when needed by other applications running on the router.
Details:
Steps below to create a random key (key.bin) and encrypt a file (secret.info) using openssl:
1. openssl rand -base64 32 > keys/key.bin
2. openssl enc -aes-256-cbc -salt -in ~/secret.info -out keys/secret.info.enc -pass file: ./keys/key.bin
What are we achieving?
Fast and secure encryption of large files using openssl. The key used for encryption is secured by the TPM using symmetric encryption. This key never leaves the TPM. So, we can say that the data (key.bin) which is protected by this is secure. Not relying on TPM to do encryption and decryption as this is time consuming and impacts performance.
Risk Analysis:
Without the proposed solution: Attacker can see sensitive info if on the system Attacker can scp out these files from the router and will get valuable info.
With the above solution: Scp’ing file out of the edge will be useless to the attacker as the files are encrypted. Attacker w/o root access to the box will NOT get any sensitive info. Attacker with root access cannot decrypt the file until the attacker can figure the password used at time if TPM2_Create() used to seal data to TPM.
Seal the data (openssl key – key.bin) to the TPM:
Steps using ibmtss
step # 1: Create a primary storage key k1. This never leaves the tpm
./createprimary -hi o -> Handle 80000000 TPM2_CreatePrimary()
step # 2: Create a key k2 which will be protected by the
primary key created above.
./create -hp 80000000 -bl -kt f -kt p -opr tmppriv.bin -opu tmppub.bin -if test/key.bin -pwdk password . TPM2_Create()
step # 3: Load key k2 in the tpm which wraps the sealed data (key.bin)
/load -hp 80000000 -ipr tmppriv.bin -ipu tmppub.bin TPM2_Load()
Now, To access the sealed data (openssl key key.bin):
Unseal to obtain the openssl key which will be used to decrypt the#ChatAndFeedback
sensitive info.
./unseal -ha 80000001 -pwd password -of <file_with_decrypted_info>
Then delete this file after using the key to decrypt/update/encrypt files on the file system.
👍
3❤️
👍
💡
👏
😂
Explore More Posts

Infineon lifts the veto on 9678 and I added back the information to our PQC Readiness page in our TPMdev tutorials - https://github.com/tpm2dev/tpm.dev.tutorials/blob/master/PQC/pqc-ready-tpm.md
#TPMDEV2026 Registration is now open. Online seats are limited (not a joke, streaming capacity). Secure your spot by registering today - https://events.zoom.us/ev/At5hYcw-lZoyOdB5W0MEy8olBvqgyR47DA3r7yptfWG5xHDZ2Y3V~AtG0Iepwg5qMqLJOT7QHCwcl7aai2M3qEMQYdmAof_9bJbjErQlhygjd5A
The latest tpm2-tools 5.8 release addresses three GitHub security advisories. One is a heap overflow in tpm2_getekcertificate, and the other is an out-of-bounds write that happens when too many sessions are in use. I don’t have information on the third advisory. Beyond the fixes, 5.8 extends EK certificate handling. It adds the option to read EK certificates from NV RAM, introduces new EK templates and supports a marshaled quote format. https://github.com/tpm2-software/tpm2-tools/releases/tag/5.8


Comments
Start the Conversation
If it is open-source I would encourage you to share that as well ;)
I've taken the commands of interest from the regtests under the tss. Ken has many such popular apps coded in scripts.
For the above one, I need to write the …more
ploop plooop Your steps looks incomplete. I don't see where you wrap your openssl key. It looks like you create two different keys. Or something is a miss. Also, I do not see where you seal/encrypt the data.
Regarding scripting - This is exactly what Ken Goldman explained veyr well in his IBM TSS how to use last month - https://developers.tpm.dev/posts/how-to-use-the-ibm-stack-with-tpm He recommends scripting first and then creating the app (C code or otherwise).
Chirag (ploop plooop), I added your post to Featured, so more people could be reached and you could receive more feedback. If it would be an app/source, I would be happy to do code review for you.
Looking forward to your next update :)
Dimitar Tomov: Thanks for going over this..
The ./create utility with the -bl and -if key.bin options and then the ./load utility together is helping seal the data key.bin to the TPM. The openssl key is wrapped by the …more
If this is the actual plan, you're writing key.bin to disk in the clear, so nothing after that will help. Even if you change to keeping the key.bin in memory, swapping is an issue …more
Yes. Anything written to disk is nearly impossible to erase. Of course, if the script is just a prototype and the real code does not use the disk, it's safer …more
Understood. Thank you. Will eventually not use the scripts and keep only in memory.