3 # For the license, see the LICENSE file in the root directory.
6 ROOT
=${abs_top_builddir:-$(pwd)/..}
7 TESTDIR
=${abs_top_testdir:-$(dirname "$0")}
9 VTPM_NAME
="vtpm-test-tpm2-savestate"
10 SWTPM_DEV_NAME
="/dev/${VTPM_NAME}"
11 export TPM_PATH
=$
(mktemp
-d)
12 STATE_FILE
=$TPM_PATH/tpm2-00.permall
13 VOLATILE_STATE_FILE
=$TPM_PATH/tpm2-00.volatilestate
14 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
15 SWTPM_CMD_UNIX_PATH
=${TPM_PATH}/unix-cmd.sock
16 SWTPM_CTRL_UNIX_PATH
=${TPM_PATH}/unix-ctrl.sock
21 if [ -n "$pid" ]; then
29 [ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
30 source ${TESTDIR}/common
32 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev
/null
34 run_swtpm
${SWTPM_INTERFACE} --tpm2
36 display_processes_by_name
"$SWTPM"
38 kill_quiet
-0 ${SWTPM_PID}
40 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
45 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
47 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
51 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
53 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
58 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
59 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00')
60 exp
=' 80 01 00 00 00 0a 00 00 00 00'
61 if [ "$RES" != "$exp" ]; then
62 echo "Error: Did not get expected result from TPM2_Startup(SU_Clear)"
69 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
70 req
='\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00'
71 req
+='\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00'
72 req
+='\x0b\x68\x65\x6c\x6c\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
73 req
+='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
75 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} $req)
76 exp
=' 80 02 00 00 00 13 00 00 00 00 00 00 00 00 00 00 01 00 00'
77 if [ "$RES" != "$exp" ]; then
78 echo "Error: Did not get expected result from TPM2_PCR_Extend(10)"
84 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
86 # length CC count hashalg sz
87 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b\x03\x00\x04\x00')
88 exp
=' 80 01 00 00 00 3e 00 00 00 00 00 00 00 15 00 00 00 01 00 0b 03 00 04 00 00 00 00 01 00 20 c3 ba a5 62 69 08 26 72 c3 db 3d 11 0a 10 74 a1 a7 a6 ea 43 e8 82 16 1a af 4b ea a6 83 17 e4 b8'
89 if [ "$RES" != "$exp" ]; then
90 echo "Error: (1) Did not get expected result from TPM2_PCRRead(10)"
96 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
98 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x45\x00\x01')
99 exp
=' 80 01 00 00 00 0a 00 00 00 00'
100 if [ "$RES" != "$exp" ]; then
101 echo "Error: (1) Did not get expected result from TPM2_Shutdown(SU_STATE)"
102 echo "expected: $exp"
103 echo "received: $RES"
108 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
109 if [ $?
-ne 0 ]; then
110 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
114 # Startup(SU_STATE) the TPM2
115 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
116 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x01')
117 exp
=' 80 01 00 00 00 0a 00 00 00 00'
118 if [ "$RES" != "$exp" ]; then
119 echo "Error: Did not get expected result from TPM2_Startup(SU_State)"
120 echo "expected: $exp"
121 echo "received: $RES"
125 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
127 # length CC count hashalg sz
128 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b\x03\x00\x04\x00')
129 exp
=' 80 01 00 00 00 3e 00 00 00 00 00 00 00 19 00 00 00 01 00 0b 03 00 04 00 00 00 00 01 00 20 c3 ba a5 62 69 08 26 72 c3 db 3d 11 0a 10 74 a1 a7 a6 ea 43 e8 82 16 1a af 4b ea a6 83 17 e4 b8'
130 if [ "$RES" != "$exp" ]; then
131 echo "Error: (2) Did not get expected result from TPM2_PCR_Read(10)"
132 echo "expected: $exp"
133 echo "received: $RES"
137 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
138 if [ $?
-ne 0 ]; then
139 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
143 if wait_process_gone
${SWTPM_PID} 4; then
144 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
148 if [ ! -e $STATE_FILE ]; then
149 echo "Error: TPM state file $STATE_FILE does not exist."