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-probe"
10 SWTPM_DEV_NAME
="/dev/${VTPM_NAME}"
11 export TPM_PATH
="$(mktemp -d)" ||
exit 1
12 STATE_FILE
=$TPM_PATH/tpm2-00.permall
13 VOLATILE_STATE_FILE
=$TPM_PATH/tpm2-00.volatilestate
14 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
15 SWTPM_CMD_UNIX_PATH
=${TPM_PATH}/unix-cmd.sock
16 SWTPM_CTRL_UNIX_PATH
=${TPM_PATH}/unix-ctrl.sock
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} --tpm2
36 display_processes_by_name
"$SWTPM"
38 kill_quiet
-0 ${SWTPM_PID}
40 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
44 if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
45 run_swtpm_ioctl
${SWTPM_INTERFACE} --stop
47 echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM"
52 # Before TPM_INIT: Read PCR 17 -- this gives a fatal error
53 # length CC count hashalg sz
54 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b\x03\x00\x00\x02')
55 exp
=' 80 01 00 00 00 0a 00 00 01 01'
56 if [ "$RES" != "$exp" ]; then
57 echo "Error: Before TPM_INIT: Did not get expected result from TPM_PCRRead(17)"
64 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
66 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
70 # Read PCR 17 -- this should give TPM_INVALID_POSTINIT
71 RES
=$
(swtpm_cmd_tx
${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b\x03\x00\x00\x02')
72 exp
=' 80 01 00 00 00 0a 00 00 01 00'
73 if [ "$RES" != "$exp" ]; then
74 echo "Error: Did not get expected result from TPM_PCRRead(17)"
80 check_seccomp_profile
"${SWTPM_EXE}" "${SWTPM_PID}" 2
85 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
87 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
91 if wait_process_gone
${SWTPM_PID} 4; then
92 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."