]>
git.proxmox.com Git - swtpm.git/blob - tests/_test_encrypted_state
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 SWTPM_CMD_UNIX_PATH
=${TPM_PATH}/unix-cmd.sock
16 SWTPM_CTRL_UNIX_PATH
=${TPM_PATH}/unix-ctrl.sock
17 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
21 echo "$KEY" > $keyfile
26 if [ -n "$pid" ]; then
29 rm -f $keyfile $logfile
35 [ "${SWTPM_INTERFACE}" == cuse
] && source ${TESTDIR}/test_cuse
36 source ${TESTDIR}/common
38 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev
/null
40 run_swtpm
${SWTPM_INTERFACE} \
41 --key file=$keyfile,mode
=aes-cbc
,format
=hex \
44 ps aux |
grep $SWTPM |
grep -v grep
48 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
55 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
57 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
63 kill -0 ${SWTPM_PID} 2>/dev
/null
65 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
72 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
73 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01')
74 exp
=' 00 c4 00 00 00 0a 00 00 00 00'
75 if [ "$RES" != "$exp" ]; then
76 echo "Error: Did not get expected result from TPM_Startup(ST_Clear)"
82 run_swtpm_ioctl
${SWTPM_INTERFACE} -h 1234
84 echo "Error: Hash command did not work."
91 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
92 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
93 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'
94 if [ "$RES" != "$exp" ]; then
95 echo "Error: (1) Did not get expected result from TPM_PCRRead(17)"
101 # Save the volatile state
102 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
103 if [ $?
-ne 0 ]; then
104 echo "Error: Saving the volatile state failed."
110 if [ ! -r $VOLATILE_STATE_FILE ]; then
111 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
117 tmp
=$
(run_swtpm_ioctl
${SWTPM_INTERFACE} -g | cut
-d":" -f2)
118 if [ $?
-ne 0 ]; then
119 echo "Error: Could not get the configration flags of the ${SWTPM_INTERFACE} TPM."
125 if [ "$tmp" != " 0x1" ]; then
126 echo "Error: Unexpected configuration flags: $tmp; expected 0x1."
134 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
135 if [ $?
-ne 0 ]; then
136 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
142 # Start the TPM again; have the keyfile removed
143 run_swtpm
${SWTPM_INTERFACE} \
144 --key file=$keyfile,mode
=aes-cbc
,format
=hex
,remove \
147 ps aux |
grep $SWTPM |
grep -v grep
150 if [ $?
-ne 0 ]; then
151 echo "Error (2): ${SWTPM_INTERFACE} TPM did not start."
157 if [ -r $keyfile ]; then
158 echo "Error: Keyfile $keyfile was not removed by swtpm_cuse."
165 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
166 if [ $?
-ne 0 ]; then
167 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
173 # Volatile state must have been removed by TPM now
174 if [ -r $VOLATILE_STATE_FILE ]; then
175 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
181 # Read the PCR again ...
182 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
183 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
184 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'
185 if [ "$RES" != "$exp" ]; then
186 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
187 echo "expected: $exp"
188 echo "received: $RES"
192 # Save the volatile state again
193 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
194 if [ $?
-ne 0 ]; then
195 echo "Error: Saving the volatile state failed."
201 if [ ! -r $VOLATILE_STATE_FILE ]; then
202 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
208 # Send a new TPM_Init
209 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
210 if [ $?
-ne 0 ]; then
211 echo "Error: ${SWTPM_INTERFACE} TPM initialization failed."
217 # Volatile state must have been removed by TPM now
218 if [ -r $VOLATILE_STATE_FILE ]; then
219 echo "Error: Volatile state file $VOLATILE_STATE_FILE still exists."
225 # Read the PCR again ...
226 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
227 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
228 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'
229 if [ "$RES" != "$exp" ]; then
230 echo "Error: (2) Did not get expected result from TPM_PCRRead(17)"
231 echo "expected: $exp"
232 echo "received: $RES"
239 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
240 if [ $?
-ne 0 ]; then
241 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
247 if wait_process_gone
${SWTPM_PID} 1; then
248 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
254 if [ ! -e $STATE_FILE ]; then
255 echo "Error: TPM state file $STATE_FILE does not exist."