]>
git.proxmox.com Git - swtpm.git/blob - tests/test_tpm2_partial_reads
3 # For the license, see the LICENSE file in the root directory.
8 ROOT
=${abs_top_builddir:-$(pwd)/..}
10 export SWTPM_INTERFACE
=cuse
12 VTPM_NAME
="vtpm-test-tpm2-partial-reads"
13 SWTPM_DEV_NAME
="/dev/${VTPM_NAME}"
14 export TPM_PATH
="$(mktemp -d)" ||
exit 1
15 CMD_PATH
="${TPM_PATH}/cmd"
20 if [ -n "$pid" ]; then
26 function swtpm_read_n_bytes_fd100
()
28 dd bs
=1 count
=$1 if=/proc
/self
/fd
/100 2>/dev
/null | \
37 [ "${SWTPM_INTERFACE}" == "cuse" ] && source test_cuse
39 skip_test_no_tpm20
"${SWTPM_EXE}"
41 run_swtpm
${SWTPM_INTERFACE} --tpm2
43 kill_quiet
-0 ${SWTPM_PID}
45 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
50 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
52 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
56 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
58 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
62 # Prepare the TPM2_Startup
63 echo -en '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00' > "${CMD_PATH}"
65 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
68 cat "${CMD_PATH}" >&100
70 # Read 4 and then 6 bytes of the response
71 res1
=$
(swtpm_read_n_bytes_fd100
4)
73 if [ "$res1" != "$exp1" ]; then
74 echo "1st Startup: Unexpected 1st response part"
75 echo "Expected: $exp1"
80 res2
=$
(swtpm_read_n_bytes_fd100
6)
81 exp2
=' 00 0a 00 00 00 00'
82 if [ "$res2" != "$exp2" ]; then
83 echo "1st Startup: Unexpected 2nd response part"
84 echo "Expected: $exp2"
89 # Startup the TPM2 again (will fail, but that's ok)
90 cat "${CMD_PATH}" >&100
92 # Read 4 and then only 4 bytes of the response
93 res1
=$
(swtpm_read_n_bytes_fd100
4)
95 if [ "$res1" != "$exp1" ]; then
96 echo "2nd Startup: Unexpected 1st response part"
97 echo "Expected: $exp1"
102 res2
=$
(swtpm_read_n_bytes_fd100
4)
104 if [ "$res2" != "$exp2" ]; then
105 echo "2nd Startup: Unexpected 2nd part"
106 echo "Expected: $exp2"
107 echo "Actual : $res2"
111 # Startup the TPM2 again (will fail, but that's ok)
112 cat "${CMD_PATH}" >&100
114 # Read 4 and then 6 bytes of the response
115 res1
=$
(swtpm_read_n_bytes_fd100
4)
117 if [ "$res1" != "$exp1" ]; then
118 echo "3rd Startup: Unexpected 1st response part"
119 echo "Expected: $exp1"
120 echo "Actual : $res1"
124 res2
=$
(swtpm_read_n_bytes_fd100
6)
125 exp2
=' 00 0a 00 00 01 00'
126 if [ "$res2" != "$exp2" ]; then
127 echo "3rd Startup: Unexpected 2nd part"
128 echo "Expected: $exp2"
129 echo "Actual : $res2"
134 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
135 if [ $?
-ne 0 ]; then
136 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
140 if wait_process_gone
${SWTPM_PID} 4; then
141 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
145 if [ ! -e $STATE_FILE ]; then
146 echo "Error: TPM state file $STATE_FILE does not exist."