mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-08-16 14:40:30 +00:00
tests: cleanup testcases
Cleanup the test cases: - remove unnecessary sleeps - check exit code of swtpm_ioctl Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
parent
a209a01816
commit
d7fc046934
@ -33,7 +33,7 @@ export TCSD_USE_TCP_DEVICE=1
|
||||
$SWTPM_EXE socket -p $PORT -i $TPMDIR &>/dev/null &
|
||||
PID=$!
|
||||
|
||||
sleep 5
|
||||
sleep 0.5
|
||||
|
||||
kill -0 $PID
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -71,7 +71,7 @@ TPMDIR=`mktemp -d`
|
||||
$SWTPM_EXE socket -p $PORT -i $TPMDIR -t &>/dev/null &
|
||||
PID=$!
|
||||
|
||||
sleep 5
|
||||
sleep 0.5
|
||||
|
||||
exec 20<&1-; exec 21<&2-
|
||||
kill -0 $PID
|
||||
|
||||
@ -45,8 +45,6 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
|
||||
|
||||
$SWTPM_EXE -n $VTPM_NAME --key file=$keyfile,mode=aes-cbc,format=hex \
|
||||
--log file=$logfile
|
||||
#sleep 20
|
||||
#echo "continuing"
|
||||
sleep 0.5
|
||||
PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME " | gawk '{print $2}')
|
||||
|
||||
@ -65,19 +63,12 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: CUSE TPM not running anymore after INIT."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
export TPM_DUMP_COMMANDS=1
|
||||
export TPM_DEVICE=/dev/$VTPM_NAME
|
||||
#tpmbios -o
|
||||
|
||||
# Startup the TPM
|
||||
exec 100<>/dev/$VTPM_NAME
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01' >&100
|
||||
@ -91,6 +82,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -h 1234 /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Hash command did not work."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read PCR 17
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11' >&100
|
||||
@ -105,6 +100,10 @@ fi
|
||||
|
||||
# Save the volatile state
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Saving the volatile state failed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
@ -125,6 +124,10 @@ fi
|
||||
# Shut the TPM down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start the TPM again; have the keyfile removed
|
||||
$SWTPM_EXE -n $VTPM_NAME --key file=$keyfile,mode=aes-cbc,format=hex,remove \
|
||||
@ -172,6 +175,10 @@ fi
|
||||
|
||||
# Save the volatile state again
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Saving the volatile state failed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
@ -207,6 +214,10 @@ fi
|
||||
# Final shut down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
@ -52,8 +52,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
|
||||
sleep 0.5
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -63,6 +65,10 @@ fi
|
||||
|
||||
# Get the capabilities flags from the TPM
|
||||
act=$($CUSE_TPM_IOCTL -c /dev/$VTPM_NAME)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not get the capability flags of the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -77,6 +83,10 @@ if ! [[ "$act" =~ ^${exp}$ ]]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
@ -50,8 +50,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
|
||||
sleep 0.5
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -59,11 +61,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
export TPM_DUMP_COMMANDS=1
|
||||
export TPM_DEVICE=/dev/$VTPM_NAME
|
||||
#tpmbios -o
|
||||
|
||||
# Startup the TPM
|
||||
exec 100<>/dev/$VTPM_NAME
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01' >&100
|
||||
@ -78,6 +75,10 @@ fi
|
||||
|
||||
# Check the TPM Established bit before the hashing
|
||||
RES=$($CUSE_TPM_IOCTL -e /dev/$VTPM_NAME)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not get the TPM Established flag."
|
||||
exit 1
|
||||
fi
|
||||
exp='tpmEstablished is 0'
|
||||
if [ "$RES" != "$exp" ]; then
|
||||
echo "Error (1): TPM Established flag has wrong value."
|
||||
@ -87,6 +88,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -h 1234 /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Hash command did not work."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read PCR 17
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11' >&100
|
||||
@ -101,6 +106,10 @@ fi
|
||||
|
||||
# Check the TPM Established bit after the hashing
|
||||
RES=$($CUSE_TPM_IOCTL -e /dev/$VTPM_NAME)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not get the TPM Established flag."
|
||||
exit 1
|
||||
fi
|
||||
exp='tpmEstablished is 1'
|
||||
if [ "$RES" != "$exp" ]; then
|
||||
echo "Error (2): TPM Established flag has wrong value."
|
||||
@ -134,6 +143,10 @@ fi
|
||||
|
||||
# Check the TPM Established bit after the reset
|
||||
RES=$($CUSE_TPM_IOCTL -e /dev/$VTPM_NAME)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not get the TPM Established flag."
|
||||
exit 1
|
||||
fi
|
||||
exp='tpmEstablished is 0'
|
||||
if [ "$RES" != "$exp" ]; then
|
||||
echo "Error (3): TPM Established flag has wrong value."
|
||||
@ -144,6 +157,10 @@ fi
|
||||
|
||||
# back to locality 0
|
||||
$CUSE_TPM_IOCTL -l 0 /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not set locality 0."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read from a file
|
||||
dd if=/dev/zero bs=1024 count=1024 2>/dev/null| \
|
||||
@ -161,6 +178,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
@ -50,6 +50,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: CUSE TPM initialization failed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
@ -59,11 +63,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
export TPM_DUMP_COMMANDS=1
|
||||
export TPM_DEVICE=/dev/$VTPM_NAME
|
||||
#tpmbios -o
|
||||
|
||||
# Startup the TPM
|
||||
exec 100<>/dev/$VTPM_NAME
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01' >&100
|
||||
@ -78,6 +77,10 @@ fi
|
||||
|
||||
# Check the TPM Established bit before the hashing
|
||||
RES=$($CUSE_TPM_IOCTL -e /dev/$VTPM_NAME)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not get the TPM Established flag from the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
exp='tpmEstablished is 0'
|
||||
if [ "$RES" != "$exp" ]; then
|
||||
echo "Error (1): TPM Established flag has wrong value."
|
||||
@ -87,6 +90,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -h 1234 /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Hash command did not work."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read PCR 17
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11' >&100
|
||||
@ -101,6 +108,10 @@ fi
|
||||
|
||||
# Check the TPM Established bit after the hashing
|
||||
RES=$($CUSE_TPM_IOCTL -e /dev/$VTPM_NAME)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not get the TPM Established flag from the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
exp='tpmEstablished is 1'
|
||||
if [ "$RES" != "$exp" ]; then
|
||||
echo "Error (2): TPM Established flag has wrong value."
|
||||
@ -195,6 +206,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
@ -48,9 +48,12 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
@ -61,6 +64,10 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
@ -48,11 +48,12 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
|
||||
sleep 0.5
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -114,7 +115,10 @@ fi
|
||||
|
||||
# Shut down TPM
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
sleep 0.5
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
|
||||
@ -76,8 +76,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: CUSE TPM not running anymore after INIT."
|
||||
@ -134,7 +132,10 @@ fi
|
||||
|
||||
# Save the volatile state into a file
|
||||
$CUSE_TPM_IOCTL --save volatile $volatilestatefile /dev/$VTPM_NAME
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not save the volatile state to ${volatilestatefile}."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -r $volatilestatefile ]; then
|
||||
echo "Error: Volatile state file $volatilestatefile does not exist."
|
||||
exit 1
|
||||
@ -204,7 +205,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
exec 100<>/dev/$VTPM_NAME
|
||||
|
||||
# Read PCR 10
|
||||
@ -218,10 +218,13 @@ if [ "$RES" != "$exp" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Shut the TPM down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Test 2: Ok"
|
||||
|
||||
@ -312,5 +315,9 @@ fi
|
||||
# Shut the TPM down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Test 4: Ok"
|
||||
|
||||
@ -56,8 +56,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
|
||||
sleep 0.5
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -86,7 +88,10 @@ fi
|
||||
|
||||
# Save the volatile state again
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not have the CUSE TPM write the volatile state to a file."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
exit 1
|
||||
@ -122,8 +127,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: CUSE TPM not running anymore after INIT."
|
||||
@ -145,7 +148,10 @@ fi
|
||||
|
||||
# Save the volatile state again
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not have the CUSE TPM write the volatile state to a file."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
exit 1
|
||||
@ -154,5 +160,9 @@ fi
|
||||
# Shut the TPM down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Test 2: Ok"
|
||||
|
||||
@ -52,8 +52,6 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
|
||||
|
||||
$SWTPM_EXE -n $VTPM_NAME --key file=$keyfile,mode=aes-cbc,format=hex \
|
||||
--log file=$logfile
|
||||
#sleep 20
|
||||
#echo "continuing"
|
||||
sleep 0.5
|
||||
PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME " | gawk '{print $2}')
|
||||
|
||||
@ -72,19 +70,12 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: CUSE TPM not running anymore after INIT."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
export TPM_DUMP_COMMANDS=1
|
||||
export TPM_DEVICE=/dev/$VTPM_NAME
|
||||
#tpmbios -o
|
||||
|
||||
# Startup the TPM
|
||||
exec 100<>/dev/$VTPM_NAME
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01' >&100
|
||||
@ -98,6 +89,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -h 1234 /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not hash the data."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read PCR 17
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11' >&100
|
||||
@ -151,6 +146,10 @@ fi
|
||||
echo "Saved permanent state."
|
||||
|
||||
$CUSE_TPM_IOCTL --save volatile $MY_VOLATILE_STATE_FILE /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not write volatile state file $MY_PERMANENT_STATE_FILE."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -r $MY_VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $MY_VOLATILE_STATE_FILE does not exist."
|
||||
exit 1
|
||||
@ -163,7 +162,6 @@ sha1sum $(dirname $MY_VOLATILE_STATE_FILE)/*
|
||||
# we will use our own volatile state
|
||||
rm -f $VOLATILE_STATE_FILE $STATE_FILE
|
||||
|
||||
sleep 2
|
||||
# Stop the TPM; this will not shut it down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL --stop /dev/$VTPM_NAME
|
||||
@ -219,7 +217,10 @@ fi
|
||||
|
||||
# Save the volatile state again
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not have the CUSE TPM write the volatile state to a file."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
exit 1
|
||||
@ -250,11 +251,13 @@ if [ "$RES" != "$exp" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Finale shut down
|
||||
# Final shut down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
sleep 0.5
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
|
||||
@ -49,8 +49,6 @@ rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
|
||||
|
||||
$SWTPM_EXE -n $VTPM_NAME \
|
||||
--log file=$logfile
|
||||
#sleep 20
|
||||
#echo "continuing"
|
||||
sleep 0.5
|
||||
PID=$(ps aux | grep $SWTPM | grep -E "$VTPM_NAME " | gawk '{print $2}')
|
||||
|
||||
@ -64,8 +62,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
|
||||
sleep 0.5
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -73,11 +73,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
export TPM_DUMP_COMMANDS=1
|
||||
export TPM_DEVICE=/dev/$VTPM_NAME
|
||||
#tpmbios -o
|
||||
|
||||
# Startup the TPM
|
||||
exec 100<>/dev/$VTPM_NAME
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01' >&100
|
||||
@ -91,6 +86,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -h 1234 /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Hash command did not work."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read PCR 17
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11' >&100
|
||||
@ -144,22 +143,29 @@ fi
|
||||
echo "Saved permanent state."
|
||||
|
||||
$CUSE_TPM_IOCTL --save volatile $MY_VOLATILE_STATE_FILE /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not write volatile state file $MY_VOLATILE_STATE_FILE."
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -r $MY_VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $MY_VOLATILE_STATE_FILE does not exist."
|
||||
exit 1
|
||||
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
|
||||
|
||||
sleep 2
|
||||
# Stop the TPM; this will not shut it down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL --stop /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not stop the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -212,6 +218,10 @@ fi
|
||||
|
||||
# Save the volatile state again
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not have the CUSE TPM store the volatile state to a file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
@ -220,6 +230,10 @@ fi
|
||||
|
||||
# Send a new TPM_Init
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Volatile state must have been removed by TPM now
|
||||
if [ -r $VOLATILE_STATE_FILE ]; then
|
||||
@ -239,10 +253,13 @@ if [ "$RES" != "$exp" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Finale shut down
|
||||
# Final shut down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
@ -25,6 +25,11 @@ ${SWTPM_CERT} \
|
||||
--pem \
|
||||
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: ${SWTPM_CERT} returned error code."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#expecting size to be constant
|
||||
size=$(stat -c%s ${cert} 2>/dev/null)
|
||||
exp=1224
|
||||
@ -48,6 +53,11 @@ ${SWTPM_CERT} \
|
||||
--pem \
|
||||
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: ${SWTPM_CERT} returned error code."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#expecting size to be constant
|
||||
size=$(stat -c%s ${cert} 2>/dev/null)
|
||||
exp=1302
|
||||
@ -71,6 +81,11 @@ ${SWTPM_CERT} \
|
||||
--pem \
|
||||
--tpm-manufacturer IBM --tpm-model swtpm-libtpms --tpm-version 1.2
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: ${SWTPM_CERT} returned error code."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#expecting size to be constant
|
||||
size=$(stat -c%s ${cert} 2>/dev/null)
|
||||
exp=1367
|
||||
@ -102,6 +117,11 @@ ${SWTPM_CERT} \
|
||||
--platform-model QEMU \
|
||||
--platform-version 2.1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: ${SWTPM_CERT} returned error code."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#expecting size to be constant
|
||||
size=$(stat -c%s ${cert} 2>/dev/null)
|
||||
exp=1411
|
||||
|
||||
@ -59,10 +59,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#ls -l ${workdir}
|
||||
#echo
|
||||
#cat ${workdir}/logfile
|
||||
|
||||
if [ ! -r "${SIGNINGKEY}" ]; then
|
||||
echo "Error: Signingkey file ${SIGNINGKEY} was not created."
|
||||
exit 1
|
||||
|
||||
@ -50,8 +50,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
|
||||
sleep 0.5
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -59,11 +61,6 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
export TPM_DUMP_COMMANDS=1
|
||||
export TPM_DEVICE=/dev/$VTPM_NAME
|
||||
#tpmbios -o
|
||||
|
||||
# Startup the TPM
|
||||
exec 100<>/dev/$VTPM_NAME
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01' >&100
|
||||
@ -77,6 +74,10 @@ if [ "$RES" != "$exp" ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -h 1234 /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Hash command did not work."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read PCR 17
|
||||
echo -en '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11' >&100
|
||||
@ -101,6 +102,10 @@ fi
|
||||
|
||||
# Save the volatile state
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not have the CUSE TPM store the volatile state to a file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
@ -110,6 +115,10 @@ fi
|
||||
# Shut the TPM down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start the TPM again
|
||||
$SWTPM_EXE -n $VTPM_NAME
|
||||
@ -126,6 +135,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Volatile state must have been removed by TPM now
|
||||
if [ -r $VOLATILE_STATE_FILE ]; then
|
||||
@ -157,6 +170,10 @@ fi
|
||||
|
||||
# Save the volatile state again
|
||||
$CUSE_TPM_IOCTL -v /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not have the CUSE TPM store the volatile state to a file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -r $VOLATILE_STATE_FILE ]; then
|
||||
echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
|
||||
@ -165,6 +182,10 @@ fi
|
||||
|
||||
# Send a new TPM_Init
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Volatile state must have been removed by TPM now
|
||||
if [ -r $VOLATILE_STATE_FILE ]; then
|
||||
@ -186,6 +207,10 @@ fi
|
||||
|
||||
# Check that the TPM Established bit is still set
|
||||
RES=$($CUSE_TPM_IOCTL -e /dev/$VTPM_NAME)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not get the TPM Established flag from the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
exp='tpmEstablished is 1'
|
||||
if [ "$RES" != "$exp" ]; then
|
||||
echo "Error (2): TPM Established flag has wrong value."
|
||||
@ -197,6 +222,10 @@ fi
|
||||
# Finale shut down
|
||||
exec 100>&-
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
@ -87,8 +87,10 @@ fi
|
||||
|
||||
# Init the TPM
|
||||
$CUSE_TPM_IOCTL -i /dev/$VTPM_NAME
|
||||
|
||||
sleep 0.5
|
||||
if [ $? -n 0 ]; then
|
||||
echo "Error: Could not initialize the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -0 $PID 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -97,6 +99,10 @@ if [ $? -ne 0 ]; then
|
||||
fi
|
||||
|
||||
$CUSE_TPM_IOCTL -s /dev/$VTPM_NAME
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: Could not shut down the CUSE TPM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user