]>
Commit | Line | Data |
---|---|---|
6852f6c8 SB |
1 | #!/bin/bash |
2 | ||
3 | # For the license, see the LICENSE file in the root directory. | |
4 | ||
5 | DIR=$(dirname "$0") | |
6 | ROOT=${DIR}/.. | |
6852f6c8 | 7 | TPMDIR=`mktemp -d` |
a19a8683 SB |
8 | SWTPM_CTRL_UNIX_PATH=$TPMDIR/sock |
9 | PID_FILE=$TPMDIR/swtpm.pid | |
10 | LOG_FILE=$TPMDIR/swtpm.log | |
6852f6c8 SB |
11 | CMD_PATH=$TPMDIR/cmd |
12 | RESP_PATH=$TPMDIR/resp | |
13 | ||
70f3e248 SB |
14 | source ${DIR}/test_common |
15 | ||
6852f6c8 SB |
16 | trap "cleanup" SIGTERM EXIT |
17 | ||
18 | function cleanup() | |
19 | { | |
20 | rm -rf $TPMDIR | |
21 | if [ -n "$PID" ]; then | |
22 | kill -SIGTERM $PID 2>/dev/null | |
23 | fi | |
24 | } | |
25 | ||
a19a8683 SB |
26 | SWTPM_INTERFACE=socket+unix |
27 | SWTPM_SERVER_PORT=65430 | |
28 | SWTPM_SERVER_NAME=localhost | |
29 | source ${DIR}/common | |
96066070 | 30 | |
1eef338e | 31 | # Test 1: test the control channel on the socket tpm |
6852f6c8 SB |
32 | |
33 | # use a pseudo terminal | |
76545232 SB |
34 | if [ -c /dev/ptmx ]; then |
35 | exec 100<>/dev/ptmx | |
36 | elif [ -c /dev/ptm ]; then | |
37 | exec 100<>/dev/ptm | |
38 | else | |
39 | echo "Could not find chardev for opening file descriptor." | |
40 | exit 1 | |
41 | fi | |
1eef338e | 42 | $SWTPM_EXE socket \ |
89d85f9a SB |
43 | --fd 100 \ |
44 | --tpmstate dir=$TPMDIR \ | |
45 | --pid file=$PID_FILE \ | |
a19a8683 | 46 | --ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH \ |
89d85f9a | 47 | --log file=$LOG_FILE,level=20 & |
6852f6c8 | 48 | |
a19a8683 SB |
49 | exec 100>&- |
50 | ||
70f3e248 | 51 | if wait_for_file $PID_FILE 3; then |
1eef338e | 52 | echo "Error: Socket TPM did not write pidfile." |
6852f6c8 SB |
53 | exit 1 |
54 | fi | |
55 | ||
56 | PID="$(cat $PID_FILE)" | |
57 | ||
6852f6c8 | 58 | # Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01 |
a19a8683 | 59 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')" |
76545232 | 60 | if [[ "$(uname -s)" =~ (Linux|OpenBSD) ]]; then |
2b8a668d | 61 | exp=" 00 00 00 00 00 00 7f ff" |
1d92a4df | 62 | else |
2b8a668d | 63 | exp=" 00 00 00 00 00 00 6f ff" |
1d92a4df | 64 | fi |
6852f6c8 SB |
65 | if [ "$res" != "$exp" ]; then |
66 | echo "Error: Unexpected response from CMD_GET_CAPABILITY:" | |
67 | echo " actual : $res" | |
68 | echo " expected: $exp" | |
69 | exit 1 | |
70 | fi | |
71 | ||
804e7472 | 72 | # Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags |
a19a8683 | 73 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')" |
804e7472 SB |
74 | exp=" 00 00 00 00" |
75 | if [ "$res" != "$exp" ]; then | |
76 | echo "Error: Unexpected response from CMD_INIT:" | |
77 | echo " actual : $res" | |
78 | echo " expected: $exp" | |
79 | exit 1 | |
80 | fi | |
81 | ||
82 | # Send unknown command to the TPM | |
a19a8683 | 83 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')" |
804e7472 SB |
84 | exp=" 00 00 00 0a" |
85 | if [ "$res" != "$exp" ]; then | |
86 | echo "Error: Unexpected response from sending unsupported command:" | |
87 | echo " actual : $res" | |
88 | echo " expected: $exp" | |
89 | exit 1 | |
90 | fi | |
91 | ||
03e00991 | 92 | # Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a |
a19a8683 | 93 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')" |
03e00991 SB |
94 | exp=" 00 00 00 00" |
95 | if [ "$res" != "$exp" ]; then | |
96 | echo "Error: Unexpected response from CMD_STORE_VOLATILE:" | |
97 | echo " actual : $res" | |
98 | echo " expected: $exp" | |
99 | exit 1 | |
100 | fi | |
101 | ||
102 | if [ ! -r $TPMDIR/tpm-00.volatilestate ]; then | |
103 | echo "Error: Socket TPM: Did not write volatile state file" | |
104 | exit 1 | |
105 | fi | |
106 | ||
8f387d55 | 107 | # Send stop command to the TPM: CMD_STOP = 00 00 00 0e |
a19a8683 | 108 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')" |
f56a0cd2 SB |
109 | exp=" 00 00 00 00" |
110 | if [ "$res" != "$exp" ]; then | |
111 | echo "Error: Socket TPM: Unexpected response from CMD_STOP:" | |
112 | echo " actual : $res" | |
113 | echo " expected: $exp" | |
114 | exit 1 | |
115 | fi | |
116 | ||
8f387d55 | 117 | # Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f |
a19a8683 | 118 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')" |
f56a0cd2 SB |
119 | exp=" 00 00 00 00 00 00 00 00" |
120 | if [ "$res" != "$exp" ]; then | |
121 | echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:" | |
122 | echo " actual : $res" | |
123 | echo " expected: $exp" | |
124 | exit 1 | |
125 | fi | |
126 | ||
804e7472 | 127 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 |
a19a8683 | 128 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" |
804e7472 SB |
129 | exp=" 00 00 00 00" |
130 | if [ "$res" != "$exp" ]; then | |
131 | echo "Error: Unexpected response from CMD_SHUTDOWN:" | |
132 | echo " actual : $res" | |
133 | echo " expected: $exp" | |
134 | exit 1 | |
135 | fi | |
136 | ||
ead37845 SB |
137 | if wait_file_gone $PID_FILE 2; then |
138 | echo "Error: TPM should have removed PID file by now." | |
804e7472 SB |
139 | exit 1 |
140 | fi | |
141 | ||
ead37845 SB |
142 | kill -0 $PID 2>/dev/null |
143 | if [ $? -eq 0 ]; then | |
144 | echo "Error: TPM should not be running anymore." | |
804e7472 SB |
145 | exit 1 |
146 | fi | |
147 | ||
89d85f9a SB |
148 | check_logfile_patterns_level_20 $LOG_FILE |
149 | rm -f $LOG_FILE | |
150 | ||
6852f6c8 SB |
151 | echo "OK" |
152 | ||
9ddc6998 SB |
153 | # Test 2: test the control channel on the socket tpm |
154 | ||
f56a0cd2 SB |
155 | # There are a few more tests here that require sending commands to the TPM |
156 | ||
9ddc6998 | 157 | # use a pseudo terminal |
a19a8683 | 158 | run_swtpm ${SWTPM_INTERFACE} \ |
89d85f9a SB |
159 | --tpmstate dir=$TPMDIR \ |
160 | --pid file=$PID_FILE \ | |
a19a8683 | 161 | --log file=$LOG_FILE |
9ddc6998 | 162 | |
70f3e248 | 163 | if wait_for_file $PID_FILE 3; then |
9ddc6998 | 164 | echo "Error: Socket TPM did not write pidfile." |
a19a8683 | 165 | cat $LOG_FILE |
9ddc6998 SB |
166 | exit 1 |
167 | fi | |
168 | ||
169 | PID="$(cat $PID_FILE)" | |
170 | ||
a19a8683 | 171 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
9ddc6998 SB |
172 | |
173 | # Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01 | |
a19a8683 | 174 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')" |
76545232 | 175 | if [[ "$(uname -s)" =~ (Linux|OpenBSD) ]]; then |
2b8a668d | 176 | exp=" 00 00 00 00 00 00 7f ff" |
1d92a4df | 177 | else |
2b8a668d | 178 | exp=" 00 00 00 00 00 00 6f ff" |
1d92a4df | 179 | fi |
9ddc6998 SB |
180 | if [ "$res" != "$exp" ]; then |
181 | echo "Error: Socket TPM: Unexpected response from CMD_GET_CAPABILITY:" | |
182 | echo " actual : $res" | |
183 | echo " expected: $exp" | |
184 | exit 1 | |
185 | fi | |
186 | ||
187 | # Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags | |
a19a8683 | 188 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')" |
9ddc6998 SB |
189 | exp=" 00 00 00 00" |
190 | if [ "$res" != "$exp" ]; then | |
191 | echo "Error: Socket TPM: Unexpected response from CMD_INIT:" | |
192 | echo " actual : $res" | |
193 | echo " expected: $exp" | |
194 | exit 1 | |
195 | fi | |
196 | ||
197 | # Send unknown command to the TPM | |
a19a8683 | 198 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')" |
9ddc6998 SB |
199 | exp=" 00 00 00 0a" |
200 | if [ "$res" != "$exp" ]; then | |
201 | echo "Error: Socket TPM: Unexpected response from sending unsupported command:" | |
202 | echo " actual : $res" | |
203 | echo " expected: $exp" | |
204 | exit 1 | |
205 | fi | |
206 | ||
f56a0cd2 | 207 | # Startup the TPM |
a19a8683 | 208 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01')" |
f56a0cd2 | 209 | exp=' 00 c4 00 00 00 0a 00 00 00 00' |
a19a8683 | 210 | if [ "$res" != "$exp" ]; then |
f56a0cd2 SB |
211 | echo "Error: Did not get expected result from TPM_Startup(ST_Clear)" |
212 | echo "expected: $exp" | |
a19a8683 | 213 | echo "received: $res" |
f56a0cd2 SB |
214 | exit 1 |
215 | fi | |
216 | ||
03e00991 | 217 | # Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a |
a19a8683 | 218 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')" |
03e00991 SB |
219 | exp=" 00 00 00 00" |
220 | if [ "$res" != "$exp" ]; then | |
221 | echo "Error: Socket TPM: Unexpected response from CMD_STORE_VOLATILE:" | |
222 | echo " actual : $res" | |
223 | echo " expected: $exp" | |
224 | exit 1 | |
225 | fi | |
226 | ||
227 | if [ ! -r $TPMDIR/tpm-00.volatilestate ]; then | |
228 | echo "Error: Socket TPM: Did not write volatile state file" | |
229 | exit 1 | |
230 | fi | |
231 | ||
f56a0cd2 | 232 | # 1. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04 |
a19a8683 | 233 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x04')" |
f56a0cd2 SB |
234 | exp=" 00 00 00 00 00 00 00 00" |
235 | if [ "$res" != "$exp" ]; then | |
236 | echo "Error: Socket TPM: Unexpected response from sending CMD_GET_TPMESTABLISHED command:" | |
237 | echo " actual : $res" | |
238 | echo " expected: $exp" | |
239 | exit 1 | |
240 | fi | |
241 | ||
242 | # 2. Send command to start HASH : CMD_HASH_START = 00 00 00 06 | |
a19a8683 | 243 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x06')" |
f56a0cd2 SB |
244 | exp=" 00 00 00 00" |
245 | if [ "$res" != "$exp" ]; then | |
246 | echo "Error: Socket TPM: Unexpected response from sending CMD_HASH_START command:" | |
247 | echo " actual : $res" | |
248 | echo " expected: $exp" | |
249 | exit 1 | |
250 | fi | |
251 | ||
03e00991 SB |
252 | # 2.1. Send command to hash data : CMD_HASH_DATA = 00 00 00 07 uint32(length) data |
253 | # We send 0x100 null bytes | |
254 | echo -en '\x00\x00\x00\x07\x00\x00\x20\x00' > $CMD_PATH | |
255 | dd if=/dev/zero count=$((0x2000)) bs=1 >> $CMD_PATH 2>/dev/null | |
a19a8683 | 256 | socat -x -t10 FILE:$CMD_PATH,rdonly UNIX-CONNECT:$SWTPM_CTRL_UNIX_PATH 2>&1 | \ |
03e00991 SB |
257 | sed -n '/^ /p' | \ |
258 | tail -n1 > $RESP_PATH | |
259 | res="$(cat $RESP_PATH)" | |
260 | exp=" 00 00 00 00" | |
261 | if [ "$res" != "$exp" ]; then | |
262 | echo "Error: Socket TPM: Unexpected response from sending CMD_HASH_DATA command:" | |
263 | echo " actual : $res" | |
264 | echo " expected: $exp" | |
265 | exit 1 | |
266 | fi | |
267 | ||
f56a0cd2 | 268 | # 3. Send command to end HASH : CMD_HASH_END = 00 00 00 08 |
a19a8683 | 269 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x08')" |
f56a0cd2 SB |
270 | exp=" 00 00 00 00" |
271 | if [ "$res" != "$exp" ]; then | |
272 | echo "Error: Socket TPM: Unexpected response from sending CMD_HASH_END command:" | |
273 | echo " actual : $res" | |
274 | echo " expected: $exp" | |
275 | exit 1 | |
276 | fi | |
277 | ||
278 | # 4. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04 | |
a19a8683 | 279 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x04')" |
f56a0cd2 SB |
280 | exp=" 00 00 00 00 01 00 00 00" |
281 | if [ "$res" != "$exp" ]; then | |
282 | echo "Error: Socket TPM: Unexpected response from sending CMD_GET_TPMESTABLISHED command:" | |
283 | echo " actual : $res" | |
284 | echo " expected: $exp" | |
285 | exit 1 | |
286 | fi | |
287 | ||
288 | # 5. Send command to reset TPM established flag: CMD_RESET_TPMESTABLISHED = 00 00 00 0b 03 | |
a19a8683 | 289 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0b\x03')" |
3488d25f SB |
290 | exp=" 00 00 00 00" |
291 | if [ "$res" != "$exp" ]; then | |
292 | echo "Error: Socket TPM: Unexpected response from sending CMD_GET_TPMESTABLISHED command:" | |
293 | echo " actual : $res" | |
294 | echo " expected: $exp" | |
295 | exit 1 | |
296 | fi | |
f56a0cd2 SB |
297 | |
298 | # 6. Send command to get TPM established flag: CMD_GET_TPMESTABLISHED = 00 00 00 04 | |
a19a8683 | 299 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x04')" |
3488d25f SB |
300 | exp=" 00 00 00 00 00 00 00 00" |
301 | if [ "$res" != "$exp" ]; then | |
302 | echo "Error: Socket TPM: Unexpected response from sending CMD_GET_TPMESTABLISHED command:" | |
303 | echo " actual : $res" | |
304 | echo " expected: $exp" | |
305 | exit 1 | |
306 | fi | |
f56a0cd2 SB |
307 | |
308 | # Read PCR 17 | |
a19a8683 SB |
309 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
310 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')" | |
03e00991 | 311 | exp=' 00 c4 00 00 00 1e 00 00 00 00 c4 e1 e1 c9 81 c0 cd b1 e0 43 df 97 20 72 f9 5d a9 ff 06 ff' |
a19a8683 | 312 | if [ "$res" != "$exp" ]; then |
f56a0cd2 SB |
313 | echo "Error: (1) Did not get expected result from TPM_PCRRead(17)" |
314 | echo "expected: $exp" | |
a19a8683 | 315 | echo "received: $res" |
f56a0cd2 SB |
316 | exit 1 |
317 | fi | |
318 | ||
aeee2dc8 | 319 | # Get the volatile state of the TPM: CMD_GET_STATEBLOB = 00 00 00 0c |
a19a8683 SB |
320 | # cmd | flags | type | offset | |
321 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00')" | |
8f387d55 | 322 | # result | flags | totlength | length | |
27bf9db6 | 323 | exp=" 00 00 00 00 00 00 00 00 00 00 04 e5 00 00 04 e5" |
8f387d55 | 324 | if [ "${res:0:48}" != "$exp" ]; then |
aeee2dc8 | 325 | echo "Error: Socket TPM: Unexpected response from CMD_GET_STATEBLOB:" |
8f387d55 SB |
326 | echo " actual : $res" |
327 | echo " expected: $exp" | |
328 | exit 1 | |
329 | fi | |
f56a0cd2 | 330 | |
8f387d55 | 331 | # Send stop command to the TPM: CMD_STOP = 00 00 00 0e |
a19a8683 | 332 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')" |
f56a0cd2 SB |
333 | exp=" 00 00 00 00" |
334 | if [ "$res" != "$exp" ]; then | |
335 | echo "Error: Socket TPM: Unexpected response from CMD_STOP:" | |
336 | echo " actual : $res" | |
337 | echo " expected: $exp" | |
338 | exit 1 | |
339 | fi | |
340 | ||
341 | # Read PCR 17 -- should fail now | |
a19a8683 SB |
342 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
343 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11')" | |
f56a0cd2 | 344 | exp=' 00 c4 00 00 00 0a 00 00 00 09' |
a19a8683 | 345 | if [ "$res" != "$exp" ]; then |
f56a0cd2 SB |
346 | echo "Error: (1) Did not get expected result from TPM_PCRRead(17)" |
347 | echo "expected: $exp" | |
a19a8683 | 348 | echo "received: $res" |
f56a0cd2 SB |
349 | exit 1 |
350 | fi | |
351 | ||
8f387d55 | 352 | # Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f |
a19a8683 | 353 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')" |
f56a0cd2 SB |
354 | exp=" 00 00 00 00 00 00 00 00" |
355 | if [ "$res" != "$exp" ]; then | |
356 | echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:" | |
357 | echo " actual : $res" | |
358 | echo " expected: $exp" | |
359 | exit 1 | |
360 | fi | |
361 | ||
6a2dd35b | 362 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 |
a19a8683 | 363 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" |
6a2dd35b SB |
364 | exp=" 00 00 00 00" |
365 | if [ "$res" != "$exp" ]; then | |
366 | echo "Error: Socket TPM: Unexpected response from CMD_SHUTDOWN:" | |
367 | echo " actual : $res" | |
368 | echo " expected: $exp" | |
369 | exit 1 | |
370 | fi | |
371 | ||
ead37845 SB |
372 | if wait_file_gone $PID_FILE 2; then |
373 | echo "Error: TPM should have removed PID file by now." | |
6a2dd35b SB |
374 | exit 1 |
375 | fi | |
376 | ||
ead37845 SB |
377 | kill -0 $PID 2>/dev/null |
378 | if [ $? -eq 0 ]; then | |
379 | echo "Error: Socket TPM should not be running anymore." | |
6a2dd35b SB |
380 | exit 1 |
381 | fi | |
382 | ||
89d85f9a SB |
383 | # Expecting to see an error message for the unknown command |
384 | check_logfile_patterns_level_1 $LOG_FILE 1 | |
385 | rm -f $LOG_FILE | |
386 | ||
6a2dd35b SB |
387 | echo "OK" |
388 | ||
6a2dd35b SB |
389 | # Test 3: test the control channel on the socket tpm: resume encrypted state |
390 | ||
391 | # copy all the state files | |
392 | cp ${PWD}/${DIR}/data/tpmstate2/* ${TPMDIR} | |
393 | ||
a19a8683 | 394 | run_swtpm ${SWTPM_INTERFACE} \ |
6a2dd35b SB |
395 | --tpmstate dir=$TPMDIR \ |
396 | --pid file=$PID_FILE \ | |
89d85f9a | 397 | --key pwdfile=${PWD}/${DIR}/data/tpmstate2/pwdfile.txt \ |
63ab6c3c | 398 | --log file=$LOG_FILE,level=20 \ |
a19a8683 | 399 | --flags not-need-init |
6a2dd35b | 400 | |
70f3e248 | 401 | if wait_for_file $PID_FILE 3; then |
6a2dd35b SB |
402 | echo "Error: Socket TPM did not write pidfile." |
403 | exit 1 | |
404 | fi | |
405 | ||
406 | PID="$(cat $PID_FILE)" | |
407 | ||
6a2dd35b | 408 | # Read PCR 10 |
a19a8683 SB |
409 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
410 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x0a')" | |
6a2dd35b | 411 | exp=' 00 c4 00 00 00 1e 00 00 00 00 c7 8a 6e 94 c7 3c 4d 7f c3 05 c8 a6 6b bf 15 45 f4 ed b7 a5' |
a19a8683 | 412 | if [ "$res" != "$exp" ]; then |
6a2dd35b SB |
413 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" |
414 | echo "expected: $exp" | |
a19a8683 | 415 | echo "received: $res" |
6a2dd35b SB |
416 | exit 1 |
417 | fi | |
418 | ||
aeee2dc8 | 419 | # Get the volatile state of the TPM: CMD_GET_STATEBLOB = 00 00 00 0c |
a19a8683 SB |
420 | # cmd | flags | type | offset | |
421 | vstate="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00')" | |
6a2dd35b | 422 | # result | flags | totlength | length | |
27bf9db6 | 423 | exp=" 00 00 00 00 00 00 00 02 00 00 05 0c 00 00 05 0c" |
6a2dd35b | 424 | if [ "${vstate:0:48}" != "$exp" ]; then |
aeee2dc8 | 425 | echo "Error: Socket TPM: Unexpected response from CMD_GET_STATEBLOB:" |
6a2dd35b SB |
426 | echo " actual : ${vstate:0:48}" |
427 | echo " expected: $exp" | |
428 | exit 1 | |
429 | fi | |
430 | ||
431 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 | |
a19a8683 | 432 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" |
6a2dd35b SB |
433 | exp=" 00 00 00 00" |
434 | if [ "$res" != "$exp" ]; then | |
435 | echo "Error: Socket TPM: Unexpected response from CMD_SHUTDOWN:" | |
436 | echo " actual : $res" | |
437 | echo " expected: $exp" | |
438 | exit 1 | |
439 | fi | |
440 | ||
ead37845 SB |
441 | if wait_file_gone $PID_FILE 2; then |
442 | echo "Error: TPM should have removed PID file by now." | |
6a2dd35b SB |
443 | exit 1 |
444 | fi | |
445 | ||
ead37845 SB |
446 | kill -0 $PID 2>/dev/null |
447 | if [ $? -eq 0 ]; then | |
448 | echo "Error: Socket TPM should not be running anymore." | |
6a2dd35b SB |
449 | exit 1 |
450 | fi | |
451 | ||
89d85f9a SB |
452 | check_logfile_patterns_level_20 $LOG_FILE |
453 | rm -f $LOG_FILE | |
454 | ||
455 | echo "OK" | |
6a2dd35b SB |
456 | |
457 | # remove volatile state | |
458 | rm -f $TPMDIR/*.volatilestate | |
459 | ||
a19a8683 | 460 | run_swtpm ${SWTPM_INTERFACE} \ |
6a2dd35b SB |
461 | --tpmstate dir=$TPMDIR \ |
462 | --pid file=$PID_FILE \ | |
89d85f9a | 463 | --key pwdfile=${PWD}/${DIR}/data/tpmstate2/pwdfile.txt \ |
63ab6c3c | 464 | --log file=$LOG_FILE \ |
a19a8683 | 465 | --flags not-need-init |
6a2dd35b | 466 | |
70f3e248 | 467 | if wait_for_file $PID_FILE 3; then |
6a2dd35b SB |
468 | echo "Error: Socket TPM did not write pidfile." |
469 | exit 1 | |
470 | fi | |
471 | ||
472 | PID="$(cat $PID_FILE)" | |
473 | ||
6a2dd35b | 474 | # Read PCR 10 -- this should fail now |
a19a8683 SB |
475 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
476 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x0a')" | |
6a2dd35b | 477 | exp=' 00 c4 00 00 00 0a 00 00 00 26' |
a19a8683 | 478 | if [ "$res" != "$exp" ]; then |
6a2dd35b SB |
479 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" |
480 | echo "expected: $exp" | |
a19a8683 | 481 | echo "received: $res" |
6a2dd35b SB |
482 | exit 1 |
483 | fi | |
484 | ||
6a2dd35b | 485 | # Send stop command to the TPM: CMD_STOP = 00 00 00 0e |
a19a8683 | 486 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')" |
6a2dd35b SB |
487 | exp=" 00 00 00 00" |
488 | if [ "$res" != "$exp" ]; then | |
489 | echo "Error: Socket TPM: Unexpected response from CMD_STOP:" | |
490 | echo " actual : $res" | |
491 | echo " expected: $exp" | |
492 | exit 1 | |
493 | fi | |
494 | ||
495 | # Send the volatile state to the TPM (while it is stopped) | |
496 | # | cmd | flags | type | | |
6a2dd35b SB |
497 | vstate=${vstate:48} |
498 | size=$((${#vstate} / 3)) | |
499 | size=$(printf "%08x" $size | sed 's/\([0-9a-f]\{2\}\)/\\x\1/g') | |
6a2dd35b | 500 | vstate=$(echo "${vstate}" | sed 's/ /\\x/g') |
a19a8683 | 501 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} "\x00\x00\x00\x0d\x00\x00\x00\x02\x00\x00\x00\x02${size}${vstate}")" |
6a2dd35b SB |
502 | exp=" 00 00 00 00" |
503 | if [ "$res" != "$exp" ]; then | |
aeee2dc8 | 504 | echo "Error: Socket TPM: Unexpected response from CMD_SET_STATEBLOB:" |
6a2dd35b SB |
505 | echo " actual : $res" |
506 | echo " expected: $exp" | |
507 | exit 1 | |
508 | fi | |
509 | ||
510 | # Send init command to the TPM: CMD_INIT = 00 00 00 02 | |
a19a8683 | 511 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')" |
6a2dd35b SB |
512 | exp=" 00 00 00 00" |
513 | if [ "$res" != "$exp" ]; then | |
514 | echo "Error: Socket TPM: Unexpected response from CMD_INIT:" | |
515 | echo " actual : $res" | |
516 | echo " expected: $exp" | |
517 | exit 1 | |
518 | fi | |
519 | ||
6a2dd35b | 520 | # Read PCR 10 -- has to return same result as before |
a19a8683 SB |
521 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
522 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x0a')" | |
6a2dd35b | 523 | exp=' 00 c4 00 00 00 1e 00 00 00 00 c7 8a 6e 94 c7 3c 4d 7f c3 05 c8 a6 6b bf 15 45 f4 ed b7 a5' |
a19a8683 | 524 | if [ "$res" != "$exp" ]; then |
6a2dd35b SB |
525 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" |
526 | echo "expected: $exp" | |
a19a8683 | 527 | echo "received: $res" |
6a2dd35b SB |
528 | exit 1 |
529 | fi | |
530 | ||
492a635e | 531 | # Reset PCR 20 while in locality 0 -- should not work |
a19a8683 SB |
532 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
533 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0F\x00\x00\x00\xC8\x00\x03\x00\x00\x10')" | |
492a635e | 534 | exp=' 00 c4 00 00 00 0a 00 00 00 33' |
a19a8683 | 535 | if [ "$res" != "$exp" ]; then |
492a635e SB |
536 | echo "Error: Trying to reset PCR 20 in locality 0 returned unexpected result" |
537 | echo "expected: $exp" | |
a19a8683 | 538 | echo "received: $res" |
492a635e SB |
539 | exit 1 |
540 | fi | |
541 | ||
542 | # In locality 2 we can reset PCR 20 | |
543 | # Set the localoty on the TPM: CMD_SET_LOCALITY = 00 00 00 05 <locality> | |
a19a8683 | 544 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x05\x02')" |
492a635e SB |
545 | exp=" 00 00 00 00" |
546 | if [ "$res" != "$exp" ]; then | |
547 | echo "Error: Socket TPM: Unexpected response from CMD_SET_LOCALITY:" | |
548 | echo " actual : $res" | |
549 | echo " expected: $exp" | |
550 | exit 1 | |
551 | fi | |
552 | ||
553 | # Reset PCR 20 while in locality 2 -- has to work | |
a19a8683 SB |
554 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
555 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0F\x00\x00\x00\xC8\x00\x03\x00\x00\x10')" | |
492a635e | 556 | exp=' 00 c4 00 00 00 0a 00 00 00 00' |
a19a8683 | 557 | if [ "$res" != "$exp" ]; then |
492a635e SB |
558 | echo "Error: Could not reset PCR 20 in locality 2" |
559 | echo "expected: $exp" | |
a19a8683 | 560 | echo "received: $res" |
492a635e SB |
561 | exit 1 |
562 | fi | |
563 | ||
9ddc6998 | 564 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 |
a19a8683 | 565 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" |
9ddc6998 SB |
566 | exp=" 00 00 00 00" |
567 | if [ "$res" != "$exp" ]; then | |
568 | echo "Error: Socket TPM: Unexpected response from CMD_SHUTDOWN:" | |
569 | echo " actual : $res" | |
570 | echo " expected: $exp" | |
571 | exit 1 | |
572 | fi | |
573 | ||
ead37845 SB |
574 | if wait_file_gone $PID_FILE 2; then |
575 | echo "Error: TPM should have removed PID file by now." | |
9ddc6998 SB |
576 | exit 1 |
577 | fi | |
578 | ||
ead37845 SB |
579 | kill -0 $PID 2>/dev/null |
580 | if [ $? -eq 0 ]; then | |
581 | echo "Error: Socket TPM should not be running anymore." | |
9ddc6998 SB |
582 | exit 1 |
583 | fi | |
584 | ||
89d85f9a SB |
585 | # (Currently) expecting to see nothing in the log file |
586 | check_logfile_patterns_level_1 $LOG_FILE 0 | |
587 | rm -f $LOG_FILE | |
588 | ||
9ddc6998 SB |
589 | echo "OK" |
590 | ||
6852f6c8 | 591 | exit 0 |