]>
Commit | Line | Data |
---|---|---|
8f0f381f | 1 | #!/usr/bin/env bash |
1eef338e SB |
2 | |
3 | # For the license, see the LICENSE file in the root directory. | |
4 | ||
313cf75c SB |
5 | ROOT=${abs_top_builddir:-$(dirname "$0")/..} |
6 | TESTDIR=${abs_top_testdir:-$(dirname "$0")} | |
7 | ||
cce7503c | 8 | TPMDIR="$(mktemp -d)" || exit 1 |
1eef338e SB |
9 | SWTPM_CTRL_UNIX_PATH=$TPMDIR/sock |
10 | PID_FILE=$TPMDIR/swtpm.pid | |
11 | LOG_FILE=$TPMDIR/swtpm.log | |
12 | ||
313cf75c | 13 | source ${TESTDIR}/test_common |
1eef338e SB |
14 | |
15 | trap "cleanup" SIGTERM EXIT | |
16 | ||
17 | function cleanup() | |
18 | { | |
19 | rm -rf $TPMDIR | |
20 | if [ -n "$PID" ]; then | |
47c7ea77 | 21 | kill_quiet -SIGTERM $PID 2>/dev/null |
1eef338e SB |
22 | fi |
23 | } | |
24 | ||
25 | SWTPM_INTERFACE=socket+unix | |
313cf75c | 26 | source ${TESTDIR}/common |
346dc3d5 | 27 | skip_test_no_chardev "${SWTPM_EXE}" |
f1adde9f | 28 | skip_test_no_tpm12 "${SWTPM_EXE}" |
1eef338e SB |
29 | |
30 | # Test 1: test the control channel on the chardev tpm | |
31 | ||
32 | exec 100<>/dev/ptmx | |
33 | $SWTPM_EXE chardev \ | |
34 | --fd 100 \ | |
35 | --tpmstate dir=$TPMDIR \ | |
36 | --pid file=$PID_FILE \ | |
37 | --ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH \ | |
930c7ba1 SB |
38 | --log file=$LOG_FILE,level=20 \ |
39 | ${SWTPM_TEST_SECCOMP_OPT} & | |
1eef338e SB |
40 | |
41 | exec 100>&- | |
42 | ||
43 | if wait_for_file $PID_FILE 3; then | |
44 | echo "Error: Chardev TPM did not write pidfile." | |
45 | exit 1 | |
46 | fi | |
47 | ||
48 | PID="$(cat $PID_FILE)" | |
49 | ||
50 | # Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01 | |
51 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')" | |
2b8a668d | 52 | exp=" 00 00 00 00 00 00 7f ff" |
1eef338e SB |
53 | if [ "$res" != "$exp" ]; then |
54 | echo "Error: Unexpected response from CMD_GET_CAPABILITY:" | |
55 | echo " actual : $res" | |
56 | echo " expected: $exp" | |
57 | exit 1 | |
58 | fi | |
59 | ||
60 | # Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags | |
61 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')" | |
62 | exp=" 00 00 00 00" | |
63 | if [ "$res" != "$exp" ]; then | |
64 | echo "Error: Unexpected response from CMD_INIT:" | |
65 | echo " actual : $res" | |
66 | echo " expected: $exp" | |
67 | exit 1 | |
68 | fi | |
69 | ||
70 | # Send unknown command to the TPM | |
71 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')" | |
72 | exp=" 00 00 00 0a" | |
73 | if [ "$res" != "$exp" ]; then | |
74 | echo "Error: Unexpected response from sending unsupported command:" | |
75 | echo " actual : $res" | |
76 | echo " expected: $exp" | |
77 | exit 1 | |
78 | fi | |
79 | ||
80 | # Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a | |
81 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')" | |
82 | exp=" 00 00 00 00" | |
83 | if [ "$res" != "$exp" ]; then | |
84 | echo "Error: Unexpected response from CMD_STORE_VOLATILE:" | |
85 | echo " actual : $res" | |
86 | echo " expected: $exp" | |
87 | exit 1 | |
88 | fi | |
89 | ||
90 | if [ ! -r $TPMDIR/tpm-00.volatilestate ]; then | |
91 | echo "Error: Socket TPM: Did not write volatile state file" | |
92 | exit 1 | |
93 | fi | |
94 | ||
95 | # Send stop command to the TPM: CMD_STOP = 00 00 00 0e | |
96 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')" | |
97 | exp=" 00 00 00 00" | |
98 | if [ "$res" != "$exp" ]; then | |
99 | echo "Error: Socket TPM: Unexpected response from CMD_STOP:" | |
100 | echo " actual : $res" | |
101 | echo " expected: $exp" | |
102 | exit 1 | |
103 | fi | |
104 | ||
105 | # Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f | |
106 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')" | |
107 | exp=" 00 00 00 00 00 00 00 00" | |
108 | if [ "$res" != "$exp" ]; then | |
109 | echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:" | |
110 | echo " actual : $res" | |
111 | echo " expected: $exp" | |
112 | exit 1 | |
113 | fi | |
114 | ||
115 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 | |
116 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" | |
117 | exp=" 00 00 00 00" | |
118 | if [ "$res" != "$exp" ]; then | |
119 | echo "Error: Unexpected response from CMD_SHUTDOWN:" | |
120 | echo " actual : $res" | |
121 | echo " expected: $exp" | |
122 | exit 1 | |
123 | fi | |
124 | ||
45d2d092 | 125 | if wait_process_gone ${PID} 4; then |
1eef338e SB |
126 | echo "Error: TPM should not be running anymore." |
127 | exit 1 | |
128 | fi | |
129 | ||
ead37845 SB |
130 | if wait_file_gone $PID_FILE 2; then |
131 | echo "Error: TPM should have removed PID file by now." | |
1eef338e SB |
132 | exit 1 |
133 | fi | |
134 | ||
135 | check_logfile_patterns_level_20 $LOG_FILE | |
136 | rm -f $LOG_FILE | |
137 | ||
138 | echo "OK" |