]> git.proxmox.com Git - swtpm.git/blob - tests/_test_tpm2_wrongorder
tests: Support filenames with spaces in some functions
[swtpm.git] / tests / _test_tpm2_wrongorder
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 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 # Get the established bit before the TPM has been initialized
45 # This should not work
46
47 if [ ${SWTPM_INTERFACE} != "cuse" ]; then
48 run_swtpm_ioctl ${SWTPM_INTERFACE} --stop
49 if [ $? -ne 0 ]; then
50 echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM."
51 exit 1
52 fi
53 fi
54
55 ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -e 2>&1)"
56 if [ $? -eq 0 ]; then
57 echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
58 exit 1
59 fi
60 exp="TPM result from PTM_GET_TPMESTABLISHED: 0xa"
61 if [ "$ERR" != "$exp" ]; then
62 echo "Error: Unexpected error message"
63 echo "Received: $ERR"
64 echo "Expected: $exp"
65 exit 1
66 fi
67
68 kill_quiet -0 ${SWTPM_PID}
69 if [ $? -ne 0 ]; then
70 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
71 exit 1
72 fi
73
74 # Open access to the TPM
75 swtpm_open_cmddev ${SWTPM_INTERFACE} 100
76
77 # Read PCR 17
78 # length CC count hashalg sz
79 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')
80 exp=' 80 01 00 00 00 0a 00 00 01 01'
81 if [ "$RES" != "$exp" ]; then
82 echo "Error: Did not get expected result from TPM_PCRRead(17)"
83 echo "expected: $exp"
84 echo "received: $RES"
85 exit 1
86 fi
87
88 exec 100>&-
89
90 kill_quiet -0 ${SWTPM_PID}
91 if [ $? -ne 0 ]; then
92 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
93 exit 1
94 fi
95
96 # Init the TPM
97 run_swtpm_ioctl ${SWTPM_INTERFACE} -i
98 if [ $? -ne 0 ]; then
99 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
100 exit 1
101 fi
102
103 kill_quiet -0 ${SWTPM_PID} 2>/dev/null
104 if [ $? -ne 0 ]; then
105 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
106 exit 1
107 fi
108
109 run_swtpm_ioctl ${SWTPM_INTERFACE} -s
110 if [ $? -ne 0 ]; then
111 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
112 exit 1
113 fi
114
115 if wait_process_gone ${SWTPM_PID} 4; then
116 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
117 exit 1
118 fi
119
120 if [ ! -e $STATE_FILE ]; then
121 echo "Error: TPM state file $STATE_FILE does not exist."
122 exit 1
123 fi
124
125 echo "OK"
126
127 exit 0