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)" ||
exit 1
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 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01')
82 exp
=' 00 c4 00 00 00 0a 00 00 00 00'
83 if [ "$RES" != "$exp" ]; then
84 echo "Error: Did not get expected result from TPM_Startup(ST_Clear)"
90 run_swtpm_ioctl
${SWTPM_INTERFACE} -h 1234
92 echo "Error: Hash command did not work."
99 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
100 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'
101 if [ "$RES" != "$exp" ]; then
102 echo "Error: (1) Did not get expected result from TPM_PCRRead(17)"
103 echo "expected: $exp"
104 echo "received: $RES"
108 # Save the volatile state
109 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
110 if [ $?
-ne 0 ]; then
111 echo "Error: Saving the volatile state failed."
117 if [ ! -r $VOLATILE_STATE_FILE ]; then
118 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
124 tmp
=$
(run_swtpm_ioctl
${SWTPM_INTERFACE} -g | cut
-d":" -f2)
125 if [ $?
-ne 0 ]; then
126 echo "Error: Could not get the configration flags of the ${SWTPM_INTERFACE} TPM."
132 if [ "$tmp" != " 0x1" ]; then
133 echo "Error: Unexpected configuration flags: $tmp; expected 0x1."
140 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
141 if [ $?
-ne 0 ]; then
142 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
148 # Start the TPM again; have the keyfile removed
149 run_swtpm
${SWTPM_INTERFACE} \
150 --key file=$binkeyfile,mode
=aes-cbc
,format
=binary
,remove \
153 display_processes_by_name
"$SWTPM"
155 kill_quiet
-0 ${SWTPM_PID}
156 if [ $?
-ne 0 ]; then
157 echo "Error (2): ${SWTPM_INTERFACE} TPM did not start."
163 if wait_file_gone
${binkeyfile} 4; then
164 echo "Error: Keyfile $binkeyfile was not removed by ${SWTPM_INTERFACE} tpm."
171 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
172 if [ $?
-ne 0 ]; then
173 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
179 # Volatile state must have been removed by TPM now
180 if [ -r $VOLATILE_STATE_FILE ]; then
181 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
187 # Read the PCR again ...
188 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
189 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'
190 if [ "$RES" != "$exp" ]; then
191 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
192 echo "expected: $exp"
193 echo "received: $RES"
197 # Save the volatile state again
198 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
199 if [ $?
-ne 0 ]; then
200 echo "Error: Saving the volatile state failed."
206 if [ ! -r $VOLATILE_STATE_FILE ]; then
207 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
213 # Send a new TPM_Init
214 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
215 if [ $?
-ne 0 ]; then
216 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
222 # Volatile state must have been removed by TPM now
223 if [ -r $VOLATILE_STATE_FILE ]; then
224 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
230 # Read the PCR again ...
231 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
232 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'
233 if [ "$RES" != "$exp" ]; then
234 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
235 echo "expected: $exp"
236 echo "received: $RES"
242 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
243 if [ $?
-ne 0 ]; then
244 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
250 if wait_process_gone
${SWTPM_PID} 4; then
251 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
257 if [ ! -e $STATE_FILE ]; then
258 echo "Error: TPM state file $STATE_FILE does not exist."