mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-08-08 23:13:19 +00:00
tests: Check expected error output against expected error message
Some tests are expected to fail. Capture the error output and test it against epected error output. This also makes the test output less noisy. Also remove some other output noise. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
parent
148010c0b6
commit
f759520c02
@ -121,11 +121,18 @@ fi
|
||||
|
||||
for ((l = 0; l <= 2; l++)); do
|
||||
# Resetting via locality 2 must fail
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -r $l
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -r $l 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: Could reset the establishment bit via locality $l"
|
||||
exit 1
|
||||
fi
|
||||
exp="TPM result from PTM_RESET_TPMESTABLISHED: 0x3d"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# We expect the same results for the TPM_ResetEstablishment command
|
||||
|
||||
@ -220,11 +220,18 @@ fi
|
||||
# load the encrypted volatile state into it
|
||||
# This will not work; the TPM writes the data into the volatile state file
|
||||
# and validates it
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} --load volatile $volatilestatefile
|
||||
ERR=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --load volatile $volatilestatefile 2>&1)
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: Could load encrypted volatile state into TPM."
|
||||
exit 1
|
||||
fi
|
||||
exp="TPM result from PTM_SET_STATEBLOB: 0xd"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -s
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
@ -159,8 +159,8 @@ if [ ! -r $MY_VOLATILE_STATE_FILE ]; then
|
||||
fi
|
||||
echo "Saved volatile state."
|
||||
|
||||
ls -l $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
#ls -l $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
#sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
|
||||
# we will use our own volatile state
|
||||
rm -f $VOLATILE_STATE_FILE $STATE_FILE
|
||||
@ -300,7 +300,8 @@ echo "Test 1: Ok"
|
||||
# volatile state file does not exist
|
||||
sha1_volatile=$(get_sha1_file "${VOLATILE_STATE_FILE}")
|
||||
sha1_permanent=$(get_sha1_file "${STATE_FILE}")
|
||||
echo "sha1(volatile): $sha1_volatile sha1(permanent): $sha1_permanent"
|
||||
echo "sha1(volatile) : $sha1_volatile"
|
||||
echo "sha1(permanent): $sha1_permanent"
|
||||
|
||||
run_swtpm ${SWTPM_INTERFACE} \
|
||||
--key pwdfile=$keyfile \
|
||||
@ -317,13 +318,20 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
# Init the TPM
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -i
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -i 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: ${SWTPM_INTERFACE} TPM initialization should have failed."
|
||||
echo "TPM Logfile:"
|
||||
cat $logfile
|
||||
exit 1
|
||||
fi
|
||||
exp="TPM result from PTM_INIT: 0x21"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill_quiet -0 ${SWTPM_PID} 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -367,7 +375,8 @@ echo "Test 2: Ok"
|
||||
# volatile state file does not exist
|
||||
sha1_volatile=$(get_sha1_file "${VOLATILE_STATE_FILE}")
|
||||
sha1_permanent=$(get_sha1_file "${STATE_FILE}")
|
||||
echo "sha1(volatile): $sha1_volatile sha1(permanent): $sha1_permanent"
|
||||
echo "sha1(volatile) : $sha1_volatile"
|
||||
echo "sha1(permanent): $sha1_permanent"
|
||||
|
||||
# we need a 256bit key
|
||||
echo "${KEY}${KEY}" > $keyfile
|
||||
@ -387,14 +396,20 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
# Init the TPM
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -i
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -i 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: ${SWTPM_INTERFACE} TPM initialization should have failed."
|
||||
echo "TPM Logfile:"
|
||||
cat $logfile
|
||||
exit 1
|
||||
fi
|
||||
cat $logfile
|
||||
exp="TPM result from PTM_INIT: 0x28"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill_quiet -0 ${SWTPM_PID} 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
@ -74,12 +74,18 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
# Set the buffer size -- should fail
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exp="TPM result from PTM_SET_BUFFERSIZE: 0xa"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill_quiet -0 ${SWTPM_PID} 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
@ -34,7 +34,6 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
|
||||
run_swtpm ${SWTPM_INTERFACE} --tpm2
|
||||
|
||||
display_processes_by_name "$SWTPM"
|
||||
ls -l /dev/vtpm*
|
||||
|
||||
kill_quiet -0 ${SWTPM_PID}
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
@ -123,11 +123,18 @@ fi
|
||||
|
||||
for ((l = 0; l <= 2; l++)); do
|
||||
# Resetting via locality 2 must fail
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -r $l
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -r $l 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: Could reset the establishment bit via locality $l"
|
||||
exit 1
|
||||
fi
|
||||
exp="TPM result from PTM_RESET_TPMESTABLISHED: 0x3d"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Resetting via locality 3 must work
|
||||
|
||||
@ -211,21 +211,19 @@ run_swtpm_ioctl ${SWTPM_INTERFACE} --stop
|
||||
# load the encrypted volatile state into it
|
||||
# This will not work; the TPM writes the data into the volatile state file
|
||||
# and validates it
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} --load volatile $volatilestatefile
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} --load volatile $volatilestatefile 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: Could load encrypted volatile state into TPM."
|
||||
cat $logfile
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Now init the TPM; this must fail since the volatile state does not
|
||||
# match with the integrity hash it is expecting to find
|
||||
#run_swtpm_ioctl ${SWTPM_INTERFACE} -i
|
||||
#if [ $? -eq 0 ]; then
|
||||
# echo "Error: Initializing the ${SWTPM_INTERFACE} TPM should have failed."
|
||||
# cat $logfile
|
||||
# exit 1
|
||||
#fi
|
||||
exp="TPM result from PTM_SET_STATEBLOB: 0xd"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -s
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
@ -131,8 +131,8 @@ if [ ! -r $MY_VOLATILE_STATE_FILE ]; then
|
||||
fi
|
||||
echo "Saved volatile state."
|
||||
|
||||
ls -l $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
#ls -l $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
#sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
|
||||
# we will use our own volatile state
|
||||
rm -f $VOLATILE_STATE_FILE $STATE_FILE
|
||||
@ -266,7 +266,8 @@ echo "Test 1: Ok"
|
||||
# volatile state file does not exist
|
||||
sha1_volatile=$(get_sha1_file "${VOLATILE_STATE_FILE}")
|
||||
sha1_permanent=$(get_sha1_file "${STATE_FILE}")
|
||||
echo "sha1(volatile): $sha1_volatile sha1(permanent): $sha1_permanent"
|
||||
echo "sha1(volatile) : $sha1_volatile"
|
||||
echo "sha1(permanent): $sha1_permanent"
|
||||
|
||||
run_swtpm ${SWTPM_INTERFACE} \
|
||||
--key pwdfile=$keyfile \
|
||||
@ -284,13 +285,20 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
# Init the TPM
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -i
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -i 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: ${SWTPM_INTERFACE} TPM initialization should have failed."
|
||||
echo "TPM Logfile:"
|
||||
cat $logfile
|
||||
exit 1
|
||||
fi
|
||||
exp="TPM result from PTM_INIT: 0x101"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill_quiet -0 ${SWTPM_PID} 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -336,7 +344,8 @@ echo "Test 2: Ok"
|
||||
# volatile state file does not exist
|
||||
sha1_volatile=$(get_sha1_file "${VOLATILE_STATE_FILE}")
|
||||
sha1_permanent=$(get_sha1_file "${STATE_FILE}")
|
||||
echo "sha1(volatile): $sha1_volatile sha1(permanent): $sha1_permanent"
|
||||
echo "sha1(volatile) : $sha1_volatile"
|
||||
echo "sha1(permanent): $sha1_permanent"
|
||||
|
||||
# we need a 256bit key
|
||||
echo "${KEY}${KEY}" > $keyfile
|
||||
|
||||
@ -80,11 +80,18 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
# Set the buffer size -- should fail
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running."
|
||||
exit 1
|
||||
fi
|
||||
exp="TPM result from PTM_SET_BUFFERSIZE: 0xa"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Startup the TPM2
|
||||
swtpm_open_cmddev ${SWTPM_INTERFACE} 100
|
||||
|
||||
@ -52,11 +52,18 @@ if [ ${SWTPM_INTERFACE} != "cuse" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
run_swtpm_ioctl ${SWTPM_INTERFACE} -e
|
||||
ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -e 2>&1)"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
|
||||
exit 1
|
||||
fi
|
||||
exp="TPM result from PTM_GET_TPMESTABLISHED: 0xa"
|
||||
if [ "$ERR" != "$exp" ]; then
|
||||
echo "Error: Unexpected error message"
|
||||
echo "Received: $ERR"
|
||||
echo "Expected: $exp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill_quiet -0 ${SWTPM_PID}
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user