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-encrypted-state"
10 SWTPM_DEV_NAME
="/dev/${VTPM_NAME}"
11 export TPM_PATH
=$
(mktemp
-d)
12 STATE_FILE
=$TPM_PATH/tpm-00.permall
13 VOLATILE_STATE_FILE
=$TPM_PATH/tpm-00.volatilestate
14 KEY
=1234567890abcdef1234567890abcdef
15 BINKEY
='\x12\x34\x56\x78\x90\xab\xcd\xef\x12\x34\x56\x78\x90\xab\xcd\xef'
16 SWTPM_CMD_UNIX_PATH
=${TPM_PATH}/unix-cmd.sock
17 SWTPM_CTRL_UNIX_PATH
=${TPM_PATH}/unix-ctrl.sock
18 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
20 keyfile
=${TPM_PATH}/keyfile
21 logfile
=${TPM_PATH}/logfile
22 binkeyfile
=${TPM_PATH}/binkeyfile
23 echo "$KEY" > ${keyfile}
24 echo -en "$BINKEY" > ${binkeyfile}
29 if [ -n "$pid" ]; then
37 [ "${SWTPM_INTERFACE}" == cuse
] && source ${TESTDIR}/test_cuse
38 source ${TESTDIR}/common
40 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev
/null
42 run_swtpm
${SWTPM_INTERFACE} \
43 --key file=$keyfile,mode
=aes-cbc
,format
=hex
,remove \
46 display_processes_by_name
"$SWTPM"
48 kill_quiet
-0 ${SWTPM_PID}
50 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
56 if wait_file_gone
${keyfile} 4; then
57 echo "Error: Keyfile $keyfile was not removed by ${SWTPM_INTERFACE} tpm."
64 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
66 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
72 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
74 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
81 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
82 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01')
83 exp
=' 00 c4 00 00 00 0a 00 00 00 00'
84 if [ "$RES" != "$exp" ]; then
85 echo "Error: Did not get expected result from TPM_Startup(ST_Clear)"
91 run_swtpm_ioctl
${SWTPM_INTERFACE} -h 1234
93 echo "Error: Hash command did not work."
100 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
101 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
102 exp
=' 00 c4 00 00 00 1e 00 00 00 00 97 e9 76 e4 f2 2c d6 d2 4a fd 21 20 85 ad 7a 86 64 7f 2a e5'
103 if [ "$RES" != "$exp" ]; then
104 echo "Error: (1) Did not get expected result from TPM_PCRRead(17)"
105 echo "expected: $exp"
106 echo "received: $RES"
110 # Save the volatile state
111 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
112 if [ $?
-ne 0 ]; then
113 echo "Error: Saving the volatile state failed."
119 if [ ! -r $VOLATILE_STATE_FILE ]; then
120 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
126 tmp
=$
(run_swtpm_ioctl
${SWTPM_INTERFACE} -g | cut
-d":" -f2)
127 if [ $?
-ne 0 ]; then
128 echo "Error: Could not get the configration flags of the ${SWTPM_INTERFACE} TPM."
134 if [ "$tmp" != " 0x1" ]; then
135 echo "Error: Unexpected configuration flags: $tmp; expected 0x1."
143 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
144 if [ $?
-ne 0 ]; then
145 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
151 # Start the TPM again; have the keyfile removed
152 run_swtpm
${SWTPM_INTERFACE} \
153 --key file=$binkeyfile,mode
=aes-cbc
,format
=binary
,remove \
156 display_processes_by_name
"$SWTPM"
158 kill_quiet
-0 ${SWTPM_PID}
159 if [ $?
-ne 0 ]; then
160 echo "Error (2): ${SWTPM_INTERFACE} TPM did not start."
166 if wait_file_gone
${binkeyfile} 4; then
167 echo "Error: Keyfile $binkeyfile was not removed by ${SWTPM_INTERFACE} tpm."
174 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
175 if [ $?
-ne 0 ]; then
176 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
182 # Volatile state must have been removed by TPM now
183 if [ -r $VOLATILE_STATE_FILE ]; then
184 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
190 # Read the PCR again ...
191 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
192 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
193 exp
=' 00 c4 00 00 00 1e 00 00 00 00 97 e9 76 e4 f2 2c d6 d2 4a fd 21 20 85 ad 7a 86 64 7f 2a e5'
194 if [ "$RES" != "$exp" ]; then
195 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
196 echo "expected: $exp"
197 echo "received: $RES"
201 # Save the volatile state again
202 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
203 if [ $?
-ne 0 ]; then
204 echo "Error: Saving the volatile state failed."
210 if [ ! -r $VOLATILE_STATE_FILE ]; then
211 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
217 # Send a new TPM_Init
218 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
219 if [ $?
-ne 0 ]; then
220 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
226 # Volatile state must have been removed by TPM now
227 if [ -r $VOLATILE_STATE_FILE ]; then
228 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
234 # Read the PCR again ...
235 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
236 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
237 exp
=' 00 c4 00 00 00 1e 00 00 00 00 97 e9 76 e4 f2 2c d6 d2 4a fd 21 20 85 ad 7a 86 64 7f 2a e5'
238 if [ "$RES" != "$exp" ]; then
239 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
240 echo "expected: $exp"
241 echo "received: $RES"
248 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
249 if [ $?
-ne 0 ]; then
250 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
256 if wait_process_gone
${SWTPM_PID} 4; then
257 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
263 if [ ! -e $STATE_FILE ]; then
264 echo "Error: TPM state file $STATE_FILE does not exist."