init: add tpm2 unlock enhancements on top of upstream 35ab72d#370
init: add tpm2 unlock enhancements on top of upstream 35ab72d#370enihcam wants to merge 4 commits into
Conversation
anatol
left a comment
There was a problem hiding this comment.
Mixing multiple features in one commit makes it more difficult to inspect the git history in the future.
The commit needs to be split into 4 commits - one per fix/feature.
|
cc @pilotstew who also worked on tpm |
|
@enihcam also please provide more information in the git commit description - what exactly requires all the changes - why the timeout needs to be increated? why do you need to flatten the tpm structure? etc.. What exactly the reason for these changes? |
|
Couple of things standout. I can offer some comments here in a little bit. I'm deep into reworking how we handle fido messaging for quiet. The 2 pr's I submitted are steps toward that. As soon as I finish these I'll take a look. I know .13 is getting close and I'll try to get these in soon. |
|
Before I look at the rest. Master's Could you share how the token in your repro was created, |
- openTPM: fallback from /dev/tpmrm0 to /dev/tpm0 - tpmAwaitReady: extend timeout 3s -> 5s - flattenSystemdTPM2: handle nested systemd-tpm2 token structures - recoverTokenPassword: add tryVariants helper for multiple secret formats Unit tests: - TestFlattenSystemdTPM2 - TestTPM2PINAuthValueEmptyCases - TestPolicyHashParsing - TestPCRStringParsing
…ants Separates secret transformation (5 variants) from unsealing logic. Addresses review comment: password extraction should be separated from unsealing.
d213c81 to
d4955ce
Compare
|
@anatol Here's more detail on the changes: 1. Timeout 3s → 5s Some TPM devices/firmware take longer than 3 seconds to initialize on cold boot. The error "no tpm devices found after 3 seconds" was reported by users with slower TPM initialization. 5s gives buffer without significant boot time impact. 2. Nested token flattening systemd v255+ sometimes stores tokens with nested JSON structures: {"data": {"tpm2-blob": "...", "tpm2-pcrs": "10+13"}}instead of flat: {"tpm2-blob": "...", "tpm2-pcrs": "10+13"}Without flattening, booster couldn't read fields like tpm2-blob, tpm2-pcrs, etc. — resulting in "failed to recover systemd-tpm2 password". 3. /dev/tpm0 fallback The original code only tried /dev/tpmrm0 (resource manager interface). Some systems only have /dev/tpm0 (legacy interface). Adding fallback handles both. 4. Multiple secret format variants TPM unsealing produces raw 32 bytes, but different tools store these differently:
The tryVariants helper tries all common formats to maximize compatibility across systemd versions and tooling. |
recoverSystemdTPM2Password already returns base64-encoded password, so tryVariants was dead code for standard systemd-cryptenroll tokens. Simplify to use tryPassphraseAgainstSlots like upstream.
|
@pilotstew You're correct. Looking at The tryVariants helper was carried over from bb10root's implementation, but I don't have details on the specific token that required it. |
- TestFlattenSystemdTPM2: nested token flattening - TestPCRStringParsing: PCR list parsing (10+13, 0+7, etc) - TestPolicyHashParsing: hex/base64 policy hash parsing Also fix flattenSystemdTPM2 to recursively flatten nested wrappers.
|
Good call removing 3→5s timeout — no objection 👍 As far as I can tell the rest either describe a JSON shape systemd doesn't actually write, or re-do something upstream already handles:
Are these fixes for a broken token or boot? Do you have a |
thanks for helping me understand the details. it looks like the PR is redundant, so let's close it for now. |
|
Thanks for working on this @enihcam, and sorry for the confusion @bb10root's #304 was left hanging after I superseded it with #342. If you'd started from #304 before #342 landed, or were still on the v0.12 release, that overlap would have been easy to miss. TPM is a big part of the push to get v0.13 out. Unrelated to TPM but #372 is accepted and I have a small messaging patch ready to go. Once those are merged I suspect @anatol will push v.13 sortly after. The 3→5s timeout is still worthwhile on its own I may have coded that too tight. If you want to test the current state in the meantime, the AUR Thanks again for taking a look at it. Always welcome more reviewers. |
|
Thank you @enihcam for looking at booster improvements, we really appreciate your contributions. Let us know if you see any issues with the current HEAD. |
Summary
This PR adds additional TPM2 unlock enhancements on top of upstream commit 35ab72d.
Changes
Core fixes (built on upstream 35ab72d)
Unit tests
Upstream dedup
Upstream 35ab72d already covers:
This PR adds only the additional fixes not in upstream.
Fixes
Fixes #233