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