Skip to content

Commit df27306

Browse files
committed
initrd/bin/kexec-unseal-key: make TPM Disk Unlock Key actually retry (pipefail prevented retries) + cleanup.
Apply workaround stating that capslock might be on, TPM might be in locked state: poweroff/poweron to retry cleanly. Output pcrs only in debug mode, otherwise disclosing unauthenticated final PCRs values to possible attacker. Should be available from authenticated Recovery console and from Debug only. Unify LUKS/TPM Disk Unlock Key output to end user for clarity Signed-off-by: Thierry Laurion <[email protected]>
1 parent 37a250d commit df27306

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

initrd/bin/kexec-seal-key

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,18 @@ for dev in $(cat "$KEY_DEVICES" | cut -d\ -f1); do
111111

112112
# Remove all the old keys from slot 1
113113
for dev in $(cat "$KEY_DEVICES" | cut -d\ -f1); do
114-
echo "++++++ $dev: Removing old key slot 1"
114+
echo "++++++ $dev: Removing old TPM Disk Unlock Key in LUKS slot 1"
115115
cryptsetup luksKillSlot \
116116
--key-file "$RECOVERY_KEY" \
117117
$dev 1 ||
118-
warn "$dev: removal of key in slot 1 failed: might not exist. Continuing"
118+
warn "$dev: removal of TPM Disk Unlock Key in LUKS slot 1 failed: might not exist. Continuing"
119119

120-
echo "++++++ $dev: Adding key to slot 1"
120+
echo "++++++ $dev: Adding TPM DISK Unlock Key to LUKS slot 1"
121121
cryptsetup luksAddKey \
122122
--key-file "$RECOVERY_KEY" \
123123
--key-slot 1 \
124124
$dev "$KEY_FILE" ||
125-
die "$dev: Unable to add key to slot 1"
125+
die "$dev: Unable to add TPM Disk Unlock Key to LUKS slot 1"
126126
done
127127

128128
# Now that we have setup the new keys, measure the PCRs

initrd/bin/kexec-unseal-key

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@ DEBUG "CONFIG_TPM2_TOOLS: $CONFIG_TPM2_TOOLS"
2525
DEBUG "Show PCRs"
2626
DEBUG "$(pcrs)"
2727

28+
failed=0
2829
for tries in 1 2 3; do
29-
read -s -p "Enter LUKS Disk Unlock Key passphrase (blank to abort): " tpm_password
30+
read -s -p "Enter LUKS TPM Disk Unlock Key passphrase (blank to abort): " tpm_password
3031
echo
3132
if [ -z "$tpm_password" ]; then
3233
die "Aborting unseal disk encryption key"
3334
fi
3435

3536
DO_WITH_DEBUG --mask-position 6 \
3637
tpmr unseal "$TPM_INDEX" "0,1,2,3,4,5,6,7" "$TPM_SIZE" \
37-
"$key_file" "$tpm_password"
38+
"$key_file" "$tpm_password" || failed=1
3839

39-
if [ "$?" -eq 0 ]; then
40+
if [ "$failed" -eq 0 ]; then
4041
exit 0
4142
fi
4243

43-
pcrs
44-
warn "Unable to unseal disk encryption key"
44+
DEBUG pcrs # Show PCRs final state only in debug mode. TCPA/TPM Event log should only be visible in debug mode/from authenticated Recovery console
45+
warn "Unable to unseal TPM Disk Unlock Key with provided passphrase. retry count: $tries/3."
46+
warn "Caps Lock mode on? (All letters typed might have been uppercased)"
4547
done
4648

47-
die "Retry count exceeded..."
49+
die "Retry count exceeded: TPM might be in a locked state until machine is cold rebooted (Power off, wait 30 seconds, power on)"

0 commit comments

Comments
 (0)