]> git.proxmox.com Git - swtpm.git/blob - tests/_test_tpm2_probe
packaging: track dbgsym package for swtpm-libs and swtpm-tools
[swtpm.git] / tests / _test_tpm2_probe
1 #!/bin/bash
2
3 # For the license, see the LICENSE file in the root directory.
4 #set -x
5
6 ROOT=${abs_top_builddir:-$(pwd)/..}
7 TESTDIR=${abs_top_testdir:-$(dirname "$0")}
8
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
17
18 function cleanup()
19 {
20 pid=${SWTPM_PID}
21 if [ -n "$pid" ]; then
22 kill_quiet -9 $pid
23 fi
24 rm -rf $TPM_PATH
25 }
26
27 trap "cleanup" EXIT
28
29 [ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
30 source ${TESTDIR}/common
31
32 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
33
34 run_swtpm ${SWTPM_INTERFACE} --tpm2
35
36 display_processes_by_name "$SWTPM"
37
38 kill_quiet -0 ${SWTPM_PID}
39 if [ $? -ne 0 ]; then
40 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
41 exit 1
42 fi
43
44 if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
45 run_swtpm_ioctl ${SWTPM_INTERFACE} --stop
46 if [ $? -ne 0 ]; then
47 echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM"
48 exit 1
49 fi
50 fi
51
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)"
58 echo "expected: $exp"
59 echo "received: $RES"
60 exit 1
61 fi
62
63 # Init the TPM
64 run_swtpm_ioctl ${SWTPM_INTERFACE} -i
65 if [ $? -ne 0 ]; then
66 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
67 exit 1
68 fi
69
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)"
75 echo "expected: $exp"
76 echo "received: $RES"
77 exit 1
78 fi
79
80 check_seccomp_profile "${SWTPM_EXE}" "${SWTPM_PID}" 2
81 if [ $? -ne 0 ]; then
82 exit 1
83 fi
84
85 run_swtpm_ioctl ${SWTPM_INTERFACE} -s
86 if [ $? -ne 0 ]; then
87 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
88 exit 1
89 fi
90
91 if wait_process_gone ${SWTPM_PID} 4; then
92 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
93 exit 1
94 fi
95
96 echo "OK"
97
98 exit 0