Debian Codegraph @

tests/_test_tpm2_wrongorder

raw symbols SCIP
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-wrongorder"
10 SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
11 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 source "${TESTDIR}/common"
30 [ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
31
32 rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null
33
34 TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --tpm2
35
36 display_processes_by_name "swtpm"
37
38 if ! kill_quiet -0 "${SWTPM_PID}"; then
39 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
40 exit 1
41 fi
42
43 # Get the established bit before the TPM has been initialized
44 # This should not work
45
46 if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
47 if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
48 echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM."
49 exit 1
50 fi
51 fi
52
53 if ERR="$(run_swtpm_ioctl "${SWTPM_INTERFACE}" -e 2>&1)"; then
54 echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
55 exit 1
56 fi
57 exp="TPM result from PTM_GET_TPMESTABLISHED: 0xa"
58 if [ "$ERR" != "$exp" ]; then
59 echo "Error: Unexpected error message"
60 echo "Received: $ERR"
61 echo "Expected: $exp"
62 exit 1
63 fi
64
65 if ! kill_quiet -0 "${SWTPM_PID}"; then
66 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
67 exit 1
68 fi
69
70 # Read PCR 17
71 # length CC count hashalg sz
72 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')
73 exp=' 80 01 00 00 00 0a 00 00 01 01'
74 if [ "$RES" != "$exp" ]; then
75 echo "Error: Did not get expected result from TPM_PCRRead(17)"
76 echo "expected: $exp"
77 echo "received: $RES"
78 exit 1
79 fi
80
81 if ! kill_quiet -0 "${SWTPM_PID}"; then
82 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
83 exit 1
84 fi
85
86 # Init the TPM
87 if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
88 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
89 exit 1
90 fi
91
92 if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
93 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
94 exit 1
95 fi
96
97 if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
98 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
99 exit 1
100 fi
101
102 if wait_process_gone "${SWTPM_PID}" 4; then
103 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
104 exit 1
105 fi
106
107 if [ ! -e "$STATE_FILE" ]; then
108 echo "Error: TPM state file $STATE_FILE does not exist."
109 exit 1
110 fi
111
112 echo "OK"
113
114 exit 0