Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for TPM 1.x #84

Open
petasis opened this issue Jan 8, 2019 · 21 comments · May be fixed by #462
Open

Support for TPM 1.x #84

petasis opened this issue Jan 8, 2019 · 21 comments · May be fixed by #462

Comments

@petasis
Copy link

petasis commented Jan 8, 2019

Hi all,

Is there any change of adding support for TPM 1.x, for those stacked with an old mainboard/bios that does not support TPM 2.0?

@martinezjavier
Copy link
Contributor

@petasis I don't know of anyone working on this in the short, but if someone is interested patches are welcomed!

The pin is called tpm2 and not tpm to make it clear that it only supports TPM 2.0. Since TPM 2.0 is not backward compatible with TPM 1.2 (both the programming model and software stack is different) a tpm1 pin has to be implemented for TPM 1.2 support.

Something that would make TPM 1.2 support more complicated is the fact that the TPM 1.2 software stack (trousers) requires a user-space daemon (tcsd) which would have to run in the initramfs.

That's not the case for TPM 2.0 since clevis is using the kernel-space resource manager (/dev/tpmrm?). But that's not available for TPM 1.2 chips.

@gastamper
Copy link

Not trying to plug my own work but @petasis, consider this project if it fits your needs. It's not clevis, but I did use clevis as the basis for the dracut hooks.

@martinezjavier
It's semi-tangential but you don't actually have to have trousers/tcsd running in order to just read from TPM 1.2, which is all we generally care about at boot time. See this binary for an example, which is what I used in the above-linked project.

@phoenix-frozen
Copy link

phoenix-frozen commented Mar 26, 2021

Can confirm, I used some tooling during my PhD that just talked to /dev/tpm0 without needing any of the usual TPM 1.2 TSS. No idea what happened to that tooling now, but I don't think it ships in Debian anymore. I think the core library those tools were based on was called "libtpm", but I can't find it now.

@oldium
Copy link
Contributor

oldium commented Jan 28, 2024

I have a working Clevis support for TPM 1.2 (currently modified directly in file system), so I plan to create a Pull Request this week. I am using tpm_sealdata and tpm_unsealdata with “well-known SRK password” (-z parameter to tpm_sealdata and tpm_unsealdata) to prevent any further password prompt during boot. The encryption and decryption can use PCR registers (-p parameter to tpm_sealdata). Currently it works inside normal initramfs, not with Dracut.

@oldium
Copy link
Contributor

oldium commented Feb 2, 2024

You can follow (work in progress) my development branch https://github.com/oldium/clevis/commits/feature/tpm1/.

The script uses tpm_sealdata and tpm_unsealdata tools to encrypt and decrypt secrets. It also uses “well-known” SRK password to prevent further password prompt during login (initially tpm_takeownership -z has to be used when taking TPM ownership to make this work).

What works:

  • Boot and unlock with TPM1.2:
    clevis luks bind -d /dev/<device> tpm1 '{"pcr_ids":"0,4,7"}'
  • Encrypt and decrypt:
    echo test | clevis encrypt tpm1 '{"pcr_ids":"0,4,7"}' | clevis decrypt

Status:

  • [✅ Done] Clevis encrypt, decrypt, bind support
  • [✅ Done] initramfs-tools support
  • [✅ Done] Systemd support
  • [✅ Done] Manual page for clevis-encrypt-tpm1
  • [✅ Done] Tests for tpm1 pin
  • [✅ Done] Dracut support

@oldium
Copy link
Contributor

oldium commented Feb 2, 2024

As this is work-in-progress, I plan to change the encryption algorithm tomorrow - currently the password is sealed directly with tpm_sealdata. I will do what TPM2 does (I understand more what it does and why now 😅) - it generates a cryptographically strong random encryption key (for encrypting the password) and encrypts the key with TPM afterwards. And during decrypting it decrypts the key first with TPM and afterwards decrypts the password with the decrypted key.

EDIT: it seems I do not get it fully yet, so investigating...

EDIT2: tpm2 really seals the encryption key (JWK) used to encrypt the password and unseals the JWK afterwards. This can be done with tpm_sealdata and tpm_unsealdata too.

@oldium
Copy link
Contributor

oldium commented Feb 3, 2024

Done. The code is now sealing JWK (which is used to encrypt the password) into TPM similar to what the tpm2 pin does.

@oldium
Copy link
Contributor

oldium commented Feb 3, 2024

TPM1 pin work is done, so now the Dracut and Systemd parts...

@oldium
Copy link
Contributor

oldium commented May 5, 2024

Updated systemd dependencies (so that tcsd is able to start before other services - same as clevis). I will play with Dracut now, I have a VM with sofware-emulated TPM 1.2, so it should be safe 😊

@oldium oldium linked a pull request May 5, 2024 that will close this issue
@Cavaler
Copy link

Cavaler commented Jun 4, 2024

Is there any progress on this? Is there any way we could help?

@oldium
Copy link
Contributor

oldium commented Jun 4, 2024

I have basic setup of VM already (dracut with simulated TPM1.2) for testing, so I just need to find some time to finish this.

@oldium
Copy link
Contributor

oldium commented Jun 17, 2024

Just wanted to give a small heads-up. Dracut with SystemD is locally working for me. Work is not yet committed; I need to test Dracut without SystemD and retest initramfs-tools with the latest changes. I would like to finish it this week.

@oldium
Copy link
Contributor

oldium commented Jun 18, 2024

Most of the work is done.

I also plan to fix how the non-SystemD Dracut unlocker introduced in v20 works before finishing the pull request. The unlocker currently ignores rd.luks variables completely. It currently runs in the initqueue/settled and initqueue/online Dracut hooks and calls clevis luks unlock, I plan to inject it into the Dracut cryptroot-ask flow, so that the script prepares a pipe in /tmp/luks.keys and when the cryptroot-ask tries to read the key file (a prepared pipe in this case), it will retrieve the stored clevis password.

This is like in the initramfs-tools unlocking flow, which uses analogous approach - it supplies the password instead of trying to unlock the disk directly.

@oldium

This comment was marked as outdated.

@oldium
Copy link
Contributor

oldium commented Jun 23, 2024

Done. Enjoy 😁

@oldium
Copy link
Contributor

oldium commented Jun 23, 2024

Release package for the latest v20 version with TPM 1.2 updates compiled for Debian 12 (bookworm) on amd64 arch can be found here. I just took Trixie v20 sources, updated them and compiled on Debian 12.

Edit: rebuilt packages with +tpm1 suffix.

@natterangell
Copy link

natterangell commented Sep 29, 2024

@oldium, confirmed working on a ThinkPad T420, with Debian 12. Coreboot/edk2 and self signed EFI unified kernel image booting with Secure Boot.

FYI, the only way I could make Clevis authenticate was by taking tpm ownership with the «well know secret», which requires this flag:

tpm_takeownership -z

it does not work if omitting the flag and pressing «Enter» to set an empty SRK password. Might be worth mentioning in Readme.

EDIT: I see now you mentioned that in an earlier comment already. Great work!

@oldium
Copy link
Contributor

oldium commented Sep 30, 2024

tpm_takeownership -z

it does not work if omitting the flag and pressing «Enter» to set an empty SRK password. Might be worth mentioning in Readme.

Done, enjoy 😁

@oldium
Copy link
Contributor

oldium commented Oct 2, 2024

The latest v21 release with TPM 1.2 support for Debian 12 (bookworm) on amd64 arch can be found here. It additionally contains untested pkcs11 pin package.

Enjoy 😁

@oldium
Copy link
Contributor

oldium commented Oct 6, 2024

Latest Debian 11 (bullseye), 12 (bookworm) and Fedora v39, v40 and v41 packages are available here https://github.com/oldium/clevis/releases/tag/v21_tpm1u2.

@oldium
Copy link
Contributor

oldium commented Oct 10, 2024

Latest Debian 11 (bullseye), 12 (bookworm) and Fedora v39, v40 and v41 packages are available here https://github.com/oldium/clevis/releases/tag/v21_tpm1u3.

Latest version fixes Dracut issue on RedHat systems with missing generic trousers data file (system.data.auth), which is used when generating generic initramfs image (hostonly=no).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants