]>
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 | ||
1eef338e SB |
8 | TPMDIR=`mktemp -d` |
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 |
1eef338e SB |
27 | |
28 | # Test 1: test the control channel on the chardev tpm | |
29 | ||
30 | exec 100<>/dev/ptmx | |
31 | $SWTPM_EXE chardev \ | |
32 | --fd 100 \ | |
33 | --tpmstate dir=$TPMDIR \ | |
34 | --pid file=$PID_FILE \ | |
35 | --ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH \ | |
930c7ba1 SB |
36 | --log file=$LOG_FILE,level=20 \ |
37 | ${SWTPM_TEST_SECCOMP_OPT} & | |
1eef338e SB |
38 | |
39 | exec 100>&- | |
40 | ||
41 | if wait_for_file $PID_FILE 3; then | |
42 | echo "Error: Chardev TPM did not write pidfile." | |
43 | exit 1 | |
44 | fi | |
45 | ||
46 | PID="$(cat $PID_FILE)" | |
47 | ||
48 | # Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01 | |
49 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')" | |
2b8a668d | 50 | exp=" 00 00 00 00 00 00 7f ff" |
1eef338e SB |
51 | if [ "$res" != "$exp" ]; then |
52 | echo "Error: Unexpected response from CMD_GET_CAPABILITY:" | |
53 | echo " actual : $res" | |
54 | echo " expected: $exp" | |
55 | exit 1 | |
56 | fi | |
57 | ||
58 | # Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags | |
59 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')" | |
60 | exp=" 00 00 00 00" | |
61 | if [ "$res" != "$exp" ]; then | |
62 | echo "Error: Unexpected response from CMD_INIT:" | |
63 | echo " actual : $res" | |
64 | echo " expected: $exp" | |
65 | exit 1 | |
66 | fi | |
67 | ||
68 | # Send unknown command to the TPM | |
69 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')" | |
70 | exp=" 00 00 00 0a" | |
71 | if [ "$res" != "$exp" ]; then | |
72 | echo "Error: Unexpected response from sending unsupported command:" | |
73 | echo " actual : $res" | |
74 | echo " expected: $exp" | |
75 | exit 1 | |
76 | fi | |
77 | ||
78 | # Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a | |
79 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')" | |
80 | exp=" 00 00 00 00" | |
81 | if [ "$res" != "$exp" ]; then | |
82 | echo "Error: Unexpected response from CMD_STORE_VOLATILE:" | |
83 | echo " actual : $res" | |
84 | echo " expected: $exp" | |
85 | exit 1 | |
86 | fi | |
87 | ||
88 | if [ ! -r $TPMDIR/tpm-00.volatilestate ]; then | |
89 | echo "Error: Socket TPM: Did not write volatile state file" | |
90 | exit 1 | |
91 | fi | |
92 | ||
93 | # Send stop command to the TPM: CMD_STOP = 00 00 00 0e | |
94 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')" | |
95 | exp=" 00 00 00 00" | |
96 | if [ "$res" != "$exp" ]; then | |
97 | echo "Error: Socket TPM: Unexpected response from CMD_STOP:" | |
98 | echo " actual : $res" | |
99 | echo " expected: $exp" | |
100 | exit 1 | |
101 | fi | |
102 | ||
103 | # Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f | |
104 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')" | |
105 | exp=" 00 00 00 00 00 00 00 00" | |
106 | if [ "$res" != "$exp" ]; then | |
107 | echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:" | |
108 | echo " actual : $res" | |
109 | echo " expected: $exp" | |
110 | exit 1 | |
111 | fi | |
112 | ||
113 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 | |
114 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" | |
115 | exp=" 00 00 00 00" | |
116 | if [ "$res" != "$exp" ]; then | |
117 | echo "Error: Unexpected response from CMD_SHUTDOWN:" | |
118 | echo " actual : $res" | |
119 | echo " expected: $exp" | |
120 | exit 1 | |
121 | fi | |
122 | ||
45d2d092 | 123 | if wait_process_gone ${PID} 4; then |
1eef338e SB |
124 | echo "Error: TPM should not be running anymore." |
125 | exit 1 | |
126 | fi | |
127 | ||
ead37845 SB |
128 | if wait_file_gone $PID_FILE 2; then |
129 | echo "Error: TPM should have removed PID file by now." | |
1eef338e SB |
130 | exit 1 |
131 | fi | |
132 | ||
133 | check_logfile_patterns_level_20 $LOG_FILE | |
134 | rm -f $LOG_FILE | |
135 | ||
136 | echo "OK" |