]>
Commit | Line | Data |
---|---|---|
3008874c SB |
1 | #!/bin/bash |
2 | ||
3 | # For the license, see the LICENSE file in the root directory. | |
4 | #set -x | |
5 | ||
313cf75c SB |
6 | ROOT=${abs_top_builddir:-$(pwd)/..} |
7 | TESTDIR=${abs_top_testdir:-$(dirname "$0")} | |
8 | ||
3008874c SB |
9 | VTPM_NAME="vtpm-test-tpm2-wrongorder" |
10 | SWTPM_DEV_NAME="/dev/${VTPM_NAME}" | |
11 | export TPM_PATH=$(mktemp -d) | |
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 | |
47c7ea77 | 22 | kill_quiet -9 $pid |
3008874c SB |
23 | fi |
24 | rm -rf $TPM_PATH | |
25 | } | |
26 | ||
27 | trap "cleanup" EXIT | |
28 | ||
313cf75c SB |
29 | [ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse |
30 | source ${TESTDIR}/common | |
3008874c SB |
31 | |
32 | rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null | |
33 | ||
34 | run_swtpm ${SWTPM_INTERFACE} --tpm2 | |
35 | ||
100317d5 | 36 | display_processes_by_name "$SWTPM" |
3008874c | 37 | |
47c7ea77 | 38 | kill_quiet -0 ${SWTPM_PID} |
3008874c SB |
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 | ||
f759520c | 55 | ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -e 2>&1)" |
3008874c SB |
56 | if [ $? -eq 0 ]; then |
57 | echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init." | |
58 | exit 1 | |
59 | fi | |
f759520c SB |
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 | |
3008874c | 67 | |
47c7ea77 | 68 | kill_quiet -0 ${SWTPM_PID} |
3008874c SB |
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 | ||
47c7ea77 | 90 | kill_quiet -0 ${SWTPM_PID} |
3008874c SB |
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 | ||
47c7ea77 | 103 | kill_quiet -0 ${SWTPM_PID} 2>/dev/null |
3008874c SB |
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 | ||
45d2d092 | 115 | if wait_process_gone ${SWTPM_PID} 4; then |
3008874c SB |
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 |