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
|
|
|
|
|
|
|
TRACE "Under kexec-unseal-key"
|
|
|
|
|
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
|
|
|
|
read -s -p "Enter unlock password (blank to abort): " tpm_password
|
|
|
|
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
|
|
|
|
2023-03-07 19:00:57 +00:00
|
|
|
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" \
|
2023-03-07 19:00:57 +00:00
|
|
|
"$key_file" "$tpm_password"
|
2023-02-23 22:05:15 +00:00
|
|
|
|
2023-02-28 18:36:11 +00:00
|
|
|
if [ "$?" -eq 0 ]; then
|
2023-02-23 15:14:32 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2022-08-25 18:43:31 +00:00
|
|
|
|
2023-02-23 15:14:32 +00:00
|
|
|
pcrs
|
|
|
|
warn "Unable to unseal disk encryption key"
|
|
|
|
done
|
2017-07-12 04:17:45 +00:00
|
|
|
|
|
|
|
die "Retry count exceeded..."
|