]>
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 # read n bytes from fd 100 and write to stdout
29 python
-c "import os; os.write(1, os.read(100, $1))" | \
35 [ "${SWTPM_INTERFACE}" == "cuse" ] && source test_cuse
37 skip_test_no_tpm20
"${SWTPM_EXE}"
39 run_swtpm
${SWTPM_INTERFACE} --tpm2
41 kill_quiet
-0 ${SWTPM_PID}
43 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
48 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
50 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
54 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
56 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
60 # Prepare the TPM2_Startup
61 echo -en '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00' > "${CMD_PATH}"
63 swtpm_open_cmddev
${SWTPM_INTERFACE} 100
66 cat "${CMD_PATH}" >&100
68 # Read 4 and then 6 bytes of the response
69 res1
=$
(swtpm_read_n_bytes_fd100
4)
71 if [ "$res1" != "$exp1" ]; then
72 echo "1st Startup: Unexpected 1st response part"
73 echo "Expected: $exp1"
78 res2
=$
(swtpm_read_n_bytes_fd100
6)
79 exp2
=' 00 0a 00 00 00 00'
80 if [ "$res2" != "$exp2" ]; then
81 echo "1st Startup: Unexpected 2nd response part"
82 echo "Expected: $exp2"
87 # Startup the TPM2 again (will fail, but that's ok)
88 cat "${CMD_PATH}" >&100
90 # Read 4 and then only 4 bytes of the response
91 res1
=$
(swtpm_read_n_bytes_fd100
4)
93 if [ "$res1" != "$exp1" ]; then
94 echo "2nd Startup: Unexpected 1st response part"
95 echo "Expected: $exp1"
100 res2
=$
(swtpm_read_n_bytes_fd100
4)
102 if [ "$res2" != "$exp2" ]; then
103 echo "2nd Startup: Unexpected 2nd part"
104 echo "Expected: $exp2"
105 echo "Actual : $res2"
109 # Startup the TPM2 again (will fail, but that's ok)
110 cat "${CMD_PATH}" >&100
112 # Read 4 and then 6 bytes of the response
113 res1
=$
(swtpm_read_n_bytes_fd100
4)
115 if [ "$res1" != "$exp1" ]; then
116 echo "3rd Startup: Unexpected 1st response part"
117 echo "Expected: $exp1"
118 echo "Actual : $res1"
122 res2
=$
(swtpm_read_n_bytes_fd100
6)
123 exp2
=' 00 0a 00 00 01 00'
124 if [ "$res2" != "$exp2" ]; then
125 echo "3rd Startup: Unexpected 2nd part"
126 echo "Expected: $exp2"
127 echo "Actual : $res2"
132 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
133 if [ $?
-ne 0 ]; then
134 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
138 if wait_process_gone
${SWTPM_PID} 4; then
139 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
143 if [ ! -e $STATE_FILE ]; then
144 echo "Error: TPM state file $STATE_FILE does not exist."