Debian Codegraph @

tests/_test_wrongorder

raw
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-wrongorder"
10 SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
11 TPM_PATH="$(mktemp -d)" || exit 1
12 STATE_FILE=$TPM_PATH/tpm-00.permall
13 LOG_FILE=$TPM_PATH/tpm-00.log
14 VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate
15 SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock
16 SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock
17 SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse}
18
19 function cleanup()
20 {
21 pid=${SWTPM_PID}
22 if [ -n "$pid" ]; then
23 kill_quiet -9 "$pid"
24 fi
25 rm -rf "$TPM_PATH"
26 }
27
28 trap "cleanup" EXIT
29
30 source "${TESTDIR}/common"
31 source "${TESTDIR}/test_common"
32 [ "${SWTPM_INTERFACE}" == cuse ] && source "${TESTDIR}/test_cuse"
33
34 rm -f "$STATE_FILE" "$VOLATILE_STATE_FILE" 2>/dev/null
35
36 TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --log "file=$LOG_FILE,level=20"
37
38 display_processes_by_name "swtpm"
39
40 if ! kill_quiet -0 "${SWTPM_PID}"; then
41 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
42 exit 1
43 fi
44
45 if [ "${SWTPM_INTERFACE}" != "cuse" ]; then
46 if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" --stop; then
47 echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM"
48 exit 1
49 fi
50 fi
51
52 # Get the established bit before the TPM has been initialized
53 # This should not work
54
55 if run_swtpm_ioctl "${SWTPM_INTERFACE}" -e; then
56 echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
57 exit 1
58 fi
59
60 if ! kill_quiet -0 "${SWTPM_PID}"; then
61 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
62 exit 1
63 fi
64
65 # Read PCR 17 -- this should give a fatal error response
66 RES=$(swtpm_cmd_tx "${SWTPM_INTERFACE}" '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')
67 exp=' 00 c4 00 00 00 0a 00 00 00 09'
68 if [ "$RES" != "$exp" ]; then
69 echo "Error: Did not get expected result from TPM_PCRRead(17)"
70 echo "expected: $exp"
71 echo "received: $RES"
72 exit 1
73 fi
74
75 if ! kill_quiet -0 "${SWTPM_PID}"; then
76 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
77 exit 1
78 fi
79
80 # Init the TPM
81 if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
82 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
83 exit 1
84 fi
85
86 if ! kill_quiet -0 "${SWTPM_PID}" 2>/dev/null; then
87 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
88 exit 1
89 fi
90
91 if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
92 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
93 exit 1
94 fi
95
96 if wait_process_gone "${SWTPM_PID}" 4; then
97 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
98 exit 1
99 fi
100
101 if [ ! -e "$STATE_FILE" ]; then
102 echo "Error: TPM state file $STATE_FILE does not exist."
103 exit 1
104 fi
105
106 check_logfile_patterns_level_20 "$LOG_FILE"
107 rm -f "$LOG_FILE"
108
109 echo "OK"
110
111 exit 0