2023-02-08 21:01:48 +00:00
|
|
|
#!/bin/bash
|
2017-07-12 04:17:45 +00:00
|
|
|
# This will unseal and unecncrypt the drive encryption key from the TPM
|
|
|
|
# The TOTP secret will be shown to the user on each encryption attempt.
|
|
|
|
# It will then need to be bundled into initrd that is booted with Qubes.
|
|
|
|
set -e -o pipefail
|
2023-02-18 17:58:43 +00:00
|
|
|
. /etc/functions
|
2017-07-12 04:17:45 +00:00
|
|
|
|
|
|
|
TPM_INDEX=3
|
|
|
|
TPM_SIZE=312
|
|
|
|
|
|
|
|
. /etc/functions
|
2023-02-23 22:05:15 +00:00
|
|
|
|
2024-02-01 19:30:31 +00:00
|
|
|
TRACE_FUNC
|
2023-02-23 22:05:15 +00:00
|
|
|
|
2017-07-12 04:17:45 +00:00
|
|
|
mkdir -p /tmp/secret
|
|
|
|
|
|
|
|
key_file="$1"
|
|
|
|
|
|
|
|
if [ -z "$key_file" ]; then
|
|
|
|
key_file="/tmp/secret/secret.key"
|
|
|
|
fi
|
|
|
|
|
2023-03-10 20:39:54 +00:00
|
|
|
DEBUG "CONFIG_TPM: $CONFIG_TPM"
|
|
|
|
DEBUG "CONFIG_TPM2_TOOLS: $CONFIG_TPM2_TOOLS"
|
|
|
|
DEBUG "Show PCRs"
|
|
|
|
DEBUG "$(pcrs)"
|
2022-08-25 18:43:31 +00:00
|
|
|
|
2023-02-23 15:14:32 +00:00
|
|
|
for tries in 1 2 3; do
|
2024-01-19 16:51:20 +00:00
|
|
|
read -s -p "Enter LUKS TPM Disk Unlock Key passphrase (blank to abort): " tpm_password
|
2023-02-23 15:14:32 +00:00
|
|
|
echo
|
|
|
|
if [ -z "$tpm_password" ]; then
|
|
|
|
die "Aborting unseal disk encryption key"
|
tpm2-tools: Change sense of CONFIG_TPM to mean any TPM, not just TPM1.
Most logic throughout Heads doesn't need to know TPM1 versus TPM2 (and
shouldn't, the differences should be localized). Some checks were
incorrect and are fixed by this change. Most checks are now unchanged
relative to master.
There are not that many places outside of tpmr that need to
differentiate TPM1 and TPM2. Some of those are duplicate code that
should be consolidated (seal-hotpkey, unseal-totp, unseal-hotp), and
some more are probably good candidates for abstracting in tpmr so the
business logic doesn't have to know TPM1 vs. TPM2.
Previously, CONFIG_TPM could be variously 'y', 'n', or empty. Now it
is always 'y' or 'n', and 'y' means "any TPM". Board configs are
unchanged, setting CONFIG_TPM2_TOOLS=y implies CONFIG_TPM=y so this
doesn't have to be duplicated and can't be mistakenly mismatched.
There were a few checks for CONFIG_TPM = n that only coincidentally
worked for TPM2 because CONFIG_TPM was empty (not 'n'). This test is
now OK, but the checks were also cleaned up to '!= "y"' for robustness.
Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
2023-02-22 21:30:07 +00:00
|
|
|
fi
|
2022-08-25 18:43:31 +00:00
|
|
|
|
2024-01-19 16:51:20 +00:00
|
|
|
if DO_WITH_DEBUG --mask-position 6 \
|
2023-03-08 17:39:06 +00:00
|
|
|
tpmr unseal "$TPM_INDEX" "0,1,2,3,4,5,6,7" "$TPM_SIZE" \
|
2024-01-19 16:51:20 +00:00
|
|
|
"$key_file" "$tpm_password"; then
|
2023-02-23 15:14:32 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2022-08-25 18:43:31 +00:00
|
|
|
|
2024-03-27 14:04:10 +00:00
|
|
|
warn "Unable to unseal LUKS Disk Unlock Key from TPM"
|
2023-02-23 15:14:32 +00:00
|
|
|
done
|
2017-07-12 04:17:45 +00:00
|
|
|
|
|
|
|
die "Retry count exceeded..."
|