test: add tests for systemd-cryptenroll --tpm2-seal-key-handle

In TEST-70-TPM2, test systemd-cryptenroll --tpm2-seal-key-handle using the
default (0) as well as the SRK handle (0x81000001), and test using a non-SRK
handle index after creating and persisting a primary key.

In test/test-tpm2, test tpm2_seal() and tpm2_unseal() using default (0), the SRK
handle, and a transient handle.
This commit is contained in:
Dan Streetman
2023-10-10 05:56:45 -04:00
parent 382bfd90c3
commit adcd3266ec
5 changed files with 211 additions and 49 deletions
+5 -2
View File
@@ -11,7 +11,7 @@ TEST_REQUIRE_INSTALL_TESTS=0
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
test_require_bin swtpm tpm2_pcrextend tpm2_dictionarylockout
test_require_bin openssl swtpm tpm2_createprimary tpm2_dictionarylockout tpm2_evictcontrol tpm2_flushcontext tpm2_pcrextend tpm2_pcrread
test_append_files() {
local workspace="${1:?}"
@@ -24,10 +24,13 @@ test_append_files() {
fi
install_dmevent
generate_module_dependencies
inst_binary openssl
inst_binary tpm2_createprimary
inst_binary tpm2_dictionarylockout
inst_binary tpm2_evictcontrol
inst_binary tpm2_flushcontext
inst_binary tpm2_pcrextend
inst_binary tpm2_pcrread
inst_binary openssl
}
do_test "$@"
+62
View File
@@ -8,6 +8,15 @@ SD_PCREXTEND="/usr/lib/systemd/systemd-pcrextend"
SD_TPM2SETUP="/usr/lib/systemd/systemd-tpm2-setup"
export SYSTEMD_LOG_LEVEL=debug
trap cleanup ERR
cleanup() {
# Evict the TPM primary key that we persisted
if [[ -n $persistent ]]; then
tpm2_evictcontrol -c "$persistent"
fi
}
persistent=""
cryptsetup_has_token_plugin_support() {
local plugin_path
@@ -131,6 +140,57 @@ if tpm_has_pcr sha256 12; then
rm -f /tmp/pcr.dat
fi
# Use default (0) seal key handle
systemd-cryptenroll --wipe-slot=tpm2 "$img"
PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=0 "$img"
systemd-cryptsetup attach test-volume "$img" - tpm2-device=auto,headless=1
systemd-cryptsetup detach test-volume
systemd-cryptenroll --wipe-slot=tpm2 "$img"
PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=0x0 "$img"
systemd-cryptsetup attach test-volume "$img" - tpm2-device=auto,headless=1
systemd-cryptsetup detach test-volume
# Use SRK seal key handle
systemd-cryptenroll --wipe-slot=tpm2 "$img"
PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=81000001 "$img"
systemd-cryptsetup attach test-volume "$img" - tpm2-device=auto,headless=1
systemd-cryptsetup detach test-volume
systemd-cryptenroll --wipe-slot=tpm2 "$img"
PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=0x81000001 "$img"
systemd-cryptsetup attach test-volume "$img" - tpm2-device=auto,headless=1
systemd-cryptsetup detach test-volume
# Test invalid ranges: pcr, nv, session, permanent
systemd-cryptenroll --wipe-slot=tpm2 "$img"
(! PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=7 "$img") # PCR
(! PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=0x01000001 "$img") # NV index
(! PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=0x02000001 "$img") # HMAC/loaded session
(! PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=0x03000001 "$img") # Policy/saved session
(! PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle=0x40000001 "$img") # Permanent
# Use non-SRK persistent seal key handle (by creating/persisting new key)
primary=/tmp/primary.ctx
tpm2_createprimary -c "$primary"
persistent_line=$(tpm2_evictcontrol -c "$primary" | grep persistent-handle)
persistent="0x${persistent_line##*0x}"
tpm2_flushcontext -t
systemd-cryptenroll --wipe-slot=tpm2 "$img"
PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle="${persistent#0x}" "$img"
systemd-cryptsetup attach test-volume "$img" - tpm2-device=auto,headless=1
systemd-cryptsetup detach test-volume
systemd-cryptenroll --wipe-slot=tpm2 "$img"
PASSWORD=passphrase systemd-cryptenroll --tpm2-device=auto --tpm2-seal-key-handle="$persistent" "$img"
systemd-cryptsetup attach test-volume "$img" - tpm2-device=auto,headless=1
systemd-cryptsetup detach test-volume
tpm2_evictcontrol -c "$persistent"
persistent=""
rm -f "$primary"
rm -f "${img:?}"
if [[ -x "$SD_MEASURE" ]]; then
@@ -390,4 +450,6 @@ if [[ -x "$SD_TPM2SETUP" ]]; then
"$SD_TPM2SETUP" --early=no
fi
cleanup
touch /testok