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-volatilestate"
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 SWTPM_CMD_UNIX_PATH
=${TPM_PATH}/unix-cmd.sock
15 SWTPM_CTRL_UNIX_PATH
=${TPM_PATH}/unix-ctrl.sock
16 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
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}
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 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01')
59 exp
=' 00 c4 00 00 00 0a 00 00 00 00'
60 if [ "$RES" != "$exp" ]; then
61 echo "Error: Did not get expected result from TPM_Startup(ST_Clear)"
67 run_swtpm_ioctl
${SWTPM_INTERFACE} -h 1234
69 echo "Error: Hash command did not work."
74 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
75 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'
76 if [ "$RES" != "$exp" ]; then
77 echo "Error: (1) Did not get expected result from TPM_PCRRead(17)"
83 # Check the TPM Established bit after the hashing
84 RES
=$
(run_swtpm_ioctl
${SWTPM_INTERFACE} -e)
85 exp
='tpmEstablished is 1'
86 if [ "$RES" != "$exp" ]; then
87 echo "Error (2): TPM Established flag has wrong value."
93 # Save the volatile state
94 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
96 echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
100 if [ ! -r $VOLATILE_STATE_FILE ]; then
101 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
106 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
107 if [ $?
-ne 0 ]; then
108 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
112 # Start the TPM again
113 run_swtpm
${SWTPM_INTERFACE}
115 display_processes_by_name
"$SWTPM"
117 kill_quiet
-0 ${SWTPM_PID}
118 if [ $?
-ne 0 ]; then
119 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
124 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
125 if [ $?
-ne 0 ]; then
126 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
130 # Volatile state must have been removed by TPM now
131 if [ -r $VOLATILE_STATE_FILE ]; then
132 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
136 # Read the PCR again ...
137 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
138 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'
139 if [ "$RES" != "$exp" ]; then
140 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
141 echo "expected: $exp"
142 echo "received: $RES"
146 # Check that the TPM Established bit is still set
147 RES
=$
(run_swtpm_ioctl
${SWTPM_INTERFACE} -e)
148 exp
='tpmEstablished is 1'
149 if [ "$RES" != "$exp" ]; then
150 echo "Error (2): TPM Established flag has wrong value."
151 echo "expected: $exp"
152 echo "received: $RES"
156 # Save the volatile state again
157 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
158 if [ $?
-ne 0 ]; then
159 echo "Error: Could not have the ${SWTPM_INTERFACE} TPM store the volatile state to a file."
163 if [ ! -r $VOLATILE_STATE_FILE ]; then
164 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
168 # Send a new TPM_Init
169 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
170 if [ $?
-ne 0 ]; then
171 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
175 # Volatile state must have been removed by TPM now
176 if [ -r $VOLATILE_STATE_FILE ]; then
177 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
181 # Read the PCR again ...
182 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
183 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'
184 if [ "$RES" != "$exp" ]; then
185 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
186 echo "expected: $exp"
187 echo "received: $RES"
191 # Check that the TPM Established bit is still set
192 RES
=$
(run_swtpm_ioctl
${SWTPM_INTERFACE} -e)
193 if [ $?
-ne 0 ]; then
194 echo "Error: Could not get the TPM Established flag from the ${SWTPM_INTERFACE} TPM."
197 exp
='tpmEstablished is 1'
198 if [ "$RES" != "$exp" ]; then
199 echo "Error (2): TPM Established flag has wrong value."
200 echo "expected: $exp"
201 echo "received: $RES"
206 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
207 if [ $?
-ne 0 ]; then
208 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
212 if wait_process_gone
${SWTPM_PID} 4; then
213 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
217 if [ ! -e $STATE_FILE ]; then
218 echo "Error: TPM state file $STATE_FILE does not exist."