]>
Commit | Line | Data |
---|---|---|
01aa2ed3 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 | ||
01aa2ed3 SB |
9 | VTPM_NAME="vtpm-test-wrongorder" |
10 | SWTPM_DEV_NAME="/dev/${VTPM_NAME}" | |
cce7503c | 11 | export TPM_PATH="$(mktemp -d)" || exit 1 |
01aa2ed3 SB |
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 | |
47c7ea77 | 23 | kill_quiet -9 $pid |
01aa2ed3 SB |
24 | fi |
25 | rm -rf $TPM_PATH | |
26 | } | |
27 | ||
28 | trap "cleanup" EXIT | |
29 | ||
313cf75c SB |
30 | [ "${SWTPM_INTERFACE}" == cuse ] && source ${TESTDIR}/test_cuse |
31 | source ${TESTDIR}/common | |
32 | source ${TESTDIR}/test_common | |
01aa2ed3 SB |
33 | |
34 | rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null | |
35 | ||
36 | run_swtpm ${SWTPM_INTERFACE} --log file=$LOG_FILE,level=20 | |
37 | ||
100317d5 | 38 | display_processes_by_name "$SWTPM" |
01aa2ed3 | 39 | |
47c7ea77 | 40 | kill_quiet -0 ${SWTPM_PID} |
01aa2ed3 SB |
41 | if [ $? -ne 0 ]; then |
42 | echo "Error: ${SWTPM_INTERFACE} TPM did not start." | |
43 | exit 1 | |
44 | fi | |
45 | ||
46 | if [ "${SWTPM_INTERFACE}" != "cuse" ]; then | |
47 | run_swtpm_ioctl ${SWTPM_INTERFACE} --stop | |
48 | if [ $? -ne 0 ]; then | |
49 | echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM" | |
50 | exit 1 | |
51 | fi | |
52 | fi | |
53 | ||
54 | # Get the established bit before the TPM has been initialized | |
55 | # This should not work | |
56 | ||
57 | run_swtpm_ioctl ${SWTPM_INTERFACE} -e | |
58 | if [ $? -eq 0 ]; then | |
59 | echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init." | |
60 | exit 1 | |
61 | fi | |
62 | ||
47c7ea77 | 63 | kill_quiet -0 ${SWTPM_PID} |
01aa2ed3 SB |
64 | if [ $? -ne 0 ]; then |
65 | echo "Error: ${SWTPM_INTERFACE} TPM must have crashed." | |
66 | exit 1 | |
67 | fi | |
68 | ||
69 | ||
70 | # Read PCR 17 -- this should give a fatal error response | |
71 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
72 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11') | |
73 | exp=' 00 c4 00 00 00 0a 00 00 00 09' | |
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 | exec 100>&- | |
82 | ||
47c7ea77 | 83 | kill_quiet -0 ${SWTPM_PID} |
01aa2ed3 SB |
84 | if [ $? -ne 0 ]; then |
85 | echo "Error: ${SWTPM_INTERFACE} TPM must have crashed." | |
86 | exit 1 | |
87 | fi | |
88 | ||
89 | # Init the TPM | |
90 | run_swtpm_ioctl ${SWTPM_INTERFACE} -i | |
91 | if [ $? -ne 0 ]; then | |
92 | echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM." | |
93 | exit 1 | |
94 | fi | |
95 | ||
47c7ea77 | 96 | kill_quiet -0 ${SWTPM_PID} 2>/dev/null |
01aa2ed3 SB |
97 | if [ $? -ne 0 ]; then |
98 | echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT." | |
99 | exit 1 | |
100 | fi | |
101 | ||
102 | run_swtpm_ioctl ${SWTPM_INTERFACE} -s | |
103 | if [ $? -ne 0 ]; then | |
104 | echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM." | |
105 | exit 1 | |
106 | fi | |
107 | ||
45d2d092 | 108 | if wait_process_gone ${SWTPM_PID} 4; then |
01aa2ed3 SB |
109 | echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore." |
110 | exit 1 | |
111 | fi | |
112 | ||
113 | if [ ! -e $STATE_FILE ]; then | |
114 | echo "Error: TPM state file $STATE_FILE does not exist." | |
115 | exit 1 | |
116 | fi | |
117 | ||
118 | check_logfile_patterns_level_20 $LOG_FILE | |
119 | rm -f $LOG_FILE | |
120 | ||
121 | echo "OK" | |
122 | ||
123 | exit 0 |