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-resume-volatile:-VTPM_NAME}
10 SWTPM_DEV_NAME
="/dev/${VTPM_NAME}"
11 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
13 tpmstatedir
="$(mktemp -d)"
14 if [ -z "$tpmstatedir" ]; then
15 echo "Could not create temporary directory"
19 SWTPM_CMD_UNIX_PATH
=${tpmstatedir}/unix-cmd.sock
20 SWTPM_CTRL_UNIX_PATH
=${tpmstatedir}/unix-ctrl.sock
25 if [ -n "$pid" ]; then
33 [ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
34 source ${TESTDIR}/common
36 export TPM_PATH
=$tpmstatedir
38 # copy all the state files
39 cp ${TESTDIR}/data
/tpm2state
1/* ${TPM_PATH}
41 run_swtpm
${SWTPM_INTERFACE} --tpm2
43 display_processes_by_name
"$SWTPM"
45 kill_quiet
-0 ${SWTPM_PID}
47 echo "Error: CUSE TPM did not start."
52 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
54 echo "Error: Could not initialize the CUSE TPM."
58 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
60 echo "Error: CUSE TPM not running anymore after INIT."
64 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
66 # Read PCR 10 (from pcrextend -ha 10 -ic test)
67 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')
68 exp
=' 80 01 00 00 00 3e 00 00 00 00 00 00 00 16 00 00 00 01 00 0b 03 00 04 00 00 00 00 01 00 20 f6 85 98 e5 86 8d e6 8b 97 29 99 60 f2 71 7d 17 67 89 a4 2f 9a ae a8 c7 b7 aa 79 a8 62 56 c1 de'
69 if [ "$RES" != "$exp" ]; then
70 echo "Error: (1) Did not get expected result from TPM_PCRRead(10)"
76 # Save the volatile state again
77 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
79 echo "Error: Could not have the CUSE TPM write the volatile state to a file."
82 if [ ! -r $VOLATILE_STATE_FILE ]; then
83 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
89 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
93 # 2nd test: with encrypted state
94 # copy all the state files
95 cp ${TESTDIR}/data
/tpm2state
2/* ${TPM_PATH}
97 run_swtpm
${SWTPM_INTERFACE} \
99 --key pwdfile
=${TESTDIR}/data
/tpm2state
2/pwdfile.txt
,kdf
=sha512
101 display_processes_by_name
"$SWTPM"
103 kill_quiet
-0 ${SWTPM_PID}
104 if [ $?
-ne 0 ]; then
105 echo "Error: CUSE TPM did not start."
110 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
111 if [ $?
-ne 0 ]; then
112 echo "Error: CUSE TPM initialization failed."
116 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
117 if [ $?
-ne 0 ]; then
118 echo "Error: CUSE TPM not running anymore after INIT."
122 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
123 if [ $?
-ne 0 ]; then
124 echo "Error: Could not open command interface."
128 # Read PCR 10 (from pcrextend -ha 10 -ic test)
129 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')
130 exp
=' 80 01 00 00 00 3e 00 00 00 00 00 00 00 16 00 00 00 01 00 0b 03 00 04 00 00 00 00 01 00 20 f6 85 98 e5 86 8d e6 8b 97 29 99 60 f2 71 7d 17 67 89 a4 2f 9a ae a8 c7 b7 aa 79 a8 62 56 c1 de'
131 if [ "$RES" != "$exp" ]; then
132 echo "Error: (1) Did not get expected result from TPM_PCRRead(10)"
133 echo "expected: $exp"
134 echo "received: $RES"
138 # Save the volatile state again
139 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
140 if [ $?
-ne 0 ]; then
141 echo "Error: Could not have the CUSE TPM write the volatile state to a file."
144 if [ ! -r $VOLATILE_STATE_FILE ]; then
145 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
151 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
152 if [ $?
-ne 0 ]; then
153 echo "Error: Could not shut down the CUSE TPM."
159 # 3rd test: with encrypted state using aes-256-cbc
160 # copy all the state files
161 cp ${TESTDIR}/data
/tpm2state2b
/* ${TPM_PATH}
163 run_swtpm
${SWTPM_INTERFACE} \
165 --key pwdfile
=${TESTDIR}/data
/tpm2state2b
/pwdfile.txt
,mode
=aes-256-cbc
167 display_processes_by_name
"$SWTPM"
169 kill_quiet
-0 ${SWTPM_PID}
170 if [ $?
-ne 0 ]; then
171 echo "Error: CUSE TPM did not start."
176 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
177 if [ $?
-ne 0 ]; then
178 echo "Error: CUSE TPM initialization failed."
182 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
183 if [ $?
-ne 0 ]; then
184 echo "Error: CUSE TPM not running anymore after INIT."
188 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
189 if [ $?
-ne 0 ]; then
190 echo "Error: Could not open command interface."
194 # Read PCR 10 (from pcrextend -ha 10 -ic test)
195 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')
196 exp
=' 80 01 00 00 00 3e 00 00 00 00 00 00 00 16 00 00 00 01 00 0b 03 00 04 00 00 00 00 01 00 20 f6 85 98 e5 86 8d e6 8b 97 29 99 60 f2 71 7d 17 67 89 a4 2f 9a ae a8 c7 b7 aa 79 a8 62 56 c1 de'
197 if [ "$RES" != "$exp" ]; then
198 echo "Error: (1) Did not get expected result from TPM_PCRRead(10)"
199 echo "expected: $exp"
200 echo "received: $RES"
204 # Save the volatile state again
205 run_swtpm_ioctl
${SWTPM_INTERFACE} -v
206 if [ $?
-ne 0 ]; then
207 echo "Error: Could not have the CUSE TPM write the volatile state to a file."
210 if [ ! -r $VOLATILE_STATE_FILE ]; then
211 echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist."
217 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
218 if [ $?
-ne 0 ]; then
219 echo "Error: Could not shut down the CUSE TPM."