]>
Commit | Line | Data |
---|---|---|
6852f6c8 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 | ||
6852f6c8 | 8 | TPMDIR=`mktemp -d` |
a19a8683 SB |
9 | SWTPM_CTRL_UNIX_PATH=$TPMDIR/sock |
10 | PID_FILE=$TPMDIR/swtpm.pid | |
11 | LOG_FILE=$TPMDIR/swtpm.log | |
6852f6c8 SB |
12 | CMD_PATH=$TPMDIR/cmd |
13 | RESP_PATH=$TPMDIR/resp | |
14 | ||
313cf75c | 15 | source ${TESTDIR}/test_common |
70f3e248 | 16 | |
6852f6c8 SB |
17 | trap "cleanup" SIGTERM EXIT |
18 | ||
19 | function cleanup() | |
20 | { | |
21 | rm -rf $TPMDIR | |
22 | if [ -n "$PID" ]; then | |
47c7ea77 | 23 | kill_quiet -SIGTERM $PID 2>/dev/null |
6852f6c8 SB |
24 | fi |
25 | } | |
26 | ||
a19a8683 SB |
27 | SWTPM_INTERFACE=socket+unix |
28 | SWTPM_SERVER_PORT=65430 | |
29 | SWTPM_SERVER_NAME=localhost | |
313cf75c | 30 | source ${TESTDIR}/common |
96066070 | 31 | |
1eef338e | 32 | # Test 1: test the control channel on the socket tpm |
6852f6c8 SB |
33 | |
34 | # use a pseudo terminal | |
76545232 SB |
35 | if [ -c /dev/ptmx ]; then |
36 | exec 100<>/dev/ptmx | |
37 | elif [ -c /dev/ptm ]; then | |
38 | exec 100<>/dev/ptm | |
39 | else | |
40 | echo "Could not find chardev for opening file descriptor." | |
41 | exit 1 | |
42 | fi | |
1eef338e | 43 | $SWTPM_EXE socket \ |
89d85f9a SB |
44 | --fd 100 \ |
45 | --tpmstate dir=$TPMDIR \ | |
46 | --pid file=$PID_FILE \ | |
a19a8683 | 47 | --ctrl type=unixio,path=$SWTPM_CTRL_UNIX_PATH \ |
89d85f9a | 48 | --log file=$LOG_FILE,level=20 & |
6852f6c8 | 49 | |
a19a8683 SB |
50 | exec 100>&- |
51 | ||
70f3e248 | 52 | if wait_for_file $PID_FILE 3; then |
1eef338e | 53 | echo "Error: Socket TPM did not write pidfile." |
6852f6c8 SB |
54 | exit 1 |
55 | fi | |
56 | ||
57 | PID="$(cat $PID_FILE)" | |
58 | ||
6852f6c8 | 59 | # Get the capability bits: CMD_GET_CAPABILITY = 0x00 00 00 01 |
a19a8683 | 60 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x01')" |
76545232 | 61 | if [[ "$(uname -s)" =~ (Linux|OpenBSD) ]]; then |
2b8a668d | 62 | exp=" 00 00 00 00 00 00 7f ff" |
1d92a4df | 63 | else |
2b8a668d | 64 | exp=" 00 00 00 00 00 00 6f ff" |
1d92a4df | 65 | fi |
6852f6c8 SB |
66 | if [ "$res" != "$exp" ]; then |
67 | echo "Error: Unexpected response from CMD_GET_CAPABILITY:" | |
68 | echo " actual : $res" | |
69 | echo " expected: $exp" | |
70 | exit 1 | |
71 | fi | |
72 | ||
804e7472 | 73 | # Send TPM_Init to the TPM: CMD_INIT = 0x00 00 00 02 + flags |
a19a8683 | 74 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')" |
804e7472 SB |
75 | exp=" 00 00 00 00" |
76 | if [ "$res" != "$exp" ]; then | |
77 | echo "Error: Unexpected response from CMD_INIT:" | |
78 | echo " actual : $res" | |
79 | echo " expected: $exp" | |
80 | exit 1 | |
81 | fi | |
82 | ||
83 | # Send unknown command to the TPM | |
a19a8683 | 84 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\xff\xff')" |
804e7472 SB |
85 | exp=" 00 00 00 0a" |
86 | if [ "$res" != "$exp" ]; then | |
87 | echo "Error: Unexpected response from sending unsupported command:" | |
88 | echo " actual : $res" | |
89 | echo " expected: $exp" | |
90 | exit 1 | |
91 | fi | |
92 | ||
03e00991 | 93 | # Save the volatile state: CMD_STORE_VOLATILE = 0x00 00 00 0a |
a19a8683 | 94 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0a')" |
03e00991 SB |
95 | exp=" 00 00 00 00" |
96 | if [ "$res" != "$exp" ]; then | |
97 | echo "Error: Unexpected response from CMD_STORE_VOLATILE:" | |
98 | echo " actual : $res" | |
99 | echo " expected: $exp" | |
100 | exit 1 | |
101 | fi | |
102 | ||
103 | if [ ! -r $TPMDIR/tpm-00.volatilestate ]; then | |
104 | echo "Error: Socket TPM: Did not write volatile state file" | |
105 | exit 1 | |
106 | fi | |
107 | ||
8f387d55 | 108 | # Send stop command to the TPM: CMD_STOP = 00 00 00 0e |
a19a8683 | 109 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')" |
f56a0cd2 SB |
110 | exp=" 00 00 00 00" |
111 | if [ "$res" != "$exp" ]; then | |
112 | echo "Error: Socket TPM: Unexpected response from CMD_STOP:" | |
113 | echo " actual : $res" | |
114 | echo " expected: $exp" | |
115 | exit 1 | |
116 | fi | |
117 | ||
8f387d55 | 118 | # Send get config command to the TPM: CMD_GET_CONFIG = 00 00 00 0f |
a19a8683 | 119 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0f')" |
f56a0cd2 SB |
120 | exp=" 00 00 00 00 00 00 00 00" |
121 | if [ "$res" != "$exp" ]; then | |
122 | echo "Error: Socket TPM: Unexpected response from CMD_GET_CONFIG:" | |
123 | echo " actual : $res" | |
124 | echo " expected: $exp" | |
125 | exit 1 | |
126 | fi | |
127 | ||
804e7472 | 128 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 |
a19a8683 | 129 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" |
804e7472 SB |
130 | exp=" 00 00 00 00" |
131 | if [ "$res" != "$exp" ]; then | |
132 | echo "Error: Unexpected response from CMD_SHUTDOWN:" | |
133 | echo " actual : $res" | |
134 | echo " expected: $exp" | |
135 | exit 1 | |
136 | fi | |
137 | ||
ead37845 SB |
138 | if wait_file_gone $PID_FILE 2; then |
139 | echo "Error: TPM should have removed PID file by now." | |
804e7472 SB |
140 | exit 1 |
141 | fi | |
142 | ||
36407c93 | 143 | if wait_process_gone $PID 1; then |
ead37845 | 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 | ||
36407c93 | 377 | if wait_process_gone $PID 1; then |
ead37845 | 378 | echo "Error: Socket TPM should not be running anymore." |
6a2dd35b SB |
379 | exit 1 |
380 | fi | |
381 | ||
89d85f9a SB |
382 | # Expecting to see an error message for the unknown command |
383 | check_logfile_patterns_level_1 $LOG_FILE 1 | |
384 | rm -f $LOG_FILE | |
385 | ||
6a2dd35b SB |
386 | echo "OK" |
387 | ||
6a2dd35b SB |
388 | # Test 3: test the control channel on the socket tpm: resume encrypted state |
389 | ||
390 | # copy all the state files | |
313cf75c | 391 | cp ${TESTDIR}/data/tpmstate2/* ${TPMDIR} |
6a2dd35b | 392 | |
a19a8683 | 393 | run_swtpm ${SWTPM_INTERFACE} \ |
6a2dd35b SB |
394 | --tpmstate dir=$TPMDIR \ |
395 | --pid file=$PID_FILE \ | |
313cf75c | 396 | --key pwdfile=${TESTDIR}/data/tpmstate2/pwdfile.txt \ |
63ab6c3c | 397 | --log file=$LOG_FILE,level=20 \ |
a19a8683 | 398 | --flags not-need-init |
6a2dd35b | 399 | |
70f3e248 | 400 | if wait_for_file $PID_FILE 3; then |
6a2dd35b SB |
401 | echo "Error: Socket TPM did not write pidfile." |
402 | exit 1 | |
403 | fi | |
404 | ||
405 | PID="$(cat $PID_FILE)" | |
406 | ||
6a2dd35b | 407 | # Read PCR 10 |
a19a8683 SB |
408 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
409 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x0a')" | |
6a2dd35b | 410 | 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 | 411 | if [ "$res" != "$exp" ]; then |
6a2dd35b SB |
412 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" |
413 | echo "expected: $exp" | |
a19a8683 | 414 | echo "received: $res" |
6a2dd35b SB |
415 | exit 1 |
416 | fi | |
417 | ||
aeee2dc8 | 418 | # Get the volatile state of the TPM: CMD_GET_STATEBLOB = 00 00 00 0c |
a19a8683 SB |
419 | # cmd | flags | type | offset | |
420 | vstate="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00')" | |
6a2dd35b | 421 | # result | flags | totlength | length | |
638bd3ba | 422 | exp=" 00 00 00 00 00 00 00 02 00 00 05 22 00 00 05 22" |
6a2dd35b | 423 | if [ "${vstate:0:48}" != "$exp" ]; then |
aeee2dc8 | 424 | echo "Error: Socket TPM: Unexpected response from CMD_GET_STATEBLOB:" |
6a2dd35b SB |
425 | echo " actual : ${vstate:0:48}" |
426 | echo " expected: $exp" | |
427 | exit 1 | |
428 | fi | |
429 | ||
430 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 | |
a19a8683 | 431 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" |
6a2dd35b SB |
432 | exp=" 00 00 00 00" |
433 | if [ "$res" != "$exp" ]; then | |
434 | echo "Error: Socket TPM: Unexpected response from CMD_SHUTDOWN:" | |
435 | echo " actual : $res" | |
436 | echo " expected: $exp" | |
437 | exit 1 | |
438 | fi | |
439 | ||
ead37845 SB |
440 | if wait_file_gone $PID_FILE 2; then |
441 | echo "Error: TPM should have removed PID file by now." | |
6a2dd35b SB |
442 | exit 1 |
443 | fi | |
444 | ||
36407c93 | 445 | if wait_process_gone $PID 1; then |
ead37845 | 446 | echo "Error: Socket TPM should not be running anymore." |
6a2dd35b SB |
447 | exit 1 |
448 | fi | |
449 | ||
89d85f9a SB |
450 | check_logfile_patterns_level_20 $LOG_FILE |
451 | rm -f $LOG_FILE | |
452 | ||
453 | echo "OK" | |
6a2dd35b SB |
454 | |
455 | # remove volatile state | |
456 | rm -f $TPMDIR/*.volatilestate | |
457 | ||
a19a8683 | 458 | run_swtpm ${SWTPM_INTERFACE} \ |
6a2dd35b SB |
459 | --tpmstate dir=$TPMDIR \ |
460 | --pid file=$PID_FILE \ | |
313cf75c | 461 | --key pwdfile=${TESTDIR}/data/tpmstate2/pwdfile.txt \ |
63ab6c3c | 462 | --log file=$LOG_FILE \ |
a19a8683 | 463 | --flags not-need-init |
6a2dd35b | 464 | |
70f3e248 | 465 | if wait_for_file $PID_FILE 3; then |
6a2dd35b SB |
466 | echo "Error: Socket TPM did not write pidfile." |
467 | exit 1 | |
468 | fi | |
469 | ||
470 | PID="$(cat $PID_FILE)" | |
471 | ||
6a2dd35b | 472 | # Read PCR 10 -- this should fail now |
a19a8683 SB |
473 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
474 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x0a')" | |
6a2dd35b | 475 | exp=' 00 c4 00 00 00 0a 00 00 00 26' |
a19a8683 | 476 | if [ "$res" != "$exp" ]; then |
6a2dd35b SB |
477 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" |
478 | echo "expected: $exp" | |
a19a8683 | 479 | echo "received: $res" |
6a2dd35b SB |
480 | exit 1 |
481 | fi | |
482 | ||
6a2dd35b | 483 | # Send stop command to the TPM: CMD_STOP = 00 00 00 0e |
a19a8683 | 484 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x0e')" |
6a2dd35b SB |
485 | exp=" 00 00 00 00" |
486 | if [ "$res" != "$exp" ]; then | |
487 | echo "Error: Socket TPM: Unexpected response from CMD_STOP:" | |
488 | echo " actual : $res" | |
489 | echo " expected: $exp" | |
490 | exit 1 | |
491 | fi | |
492 | ||
493 | # Send the volatile state to the TPM (while it is stopped) | |
494 | # | cmd | flags | type | | |
6a2dd35b SB |
495 | vstate=${vstate:48} |
496 | size=$((${#vstate} / 3)) | |
497 | size=$(printf "%08x" $size | sed 's/\([0-9a-f]\{2\}\)/\\x\1/g') | |
6a2dd35b | 498 | vstate=$(echo "${vstate}" | sed 's/ /\\x/g') |
a19a8683 | 499 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} "\x00\x00\x00\x0d\x00\x00\x00\x02\x00\x00\x00\x02${size}${vstate}")" |
6a2dd35b SB |
500 | exp=" 00 00 00 00" |
501 | if [ "$res" != "$exp" ]; then | |
aeee2dc8 | 502 | echo "Error: Socket TPM: Unexpected response from CMD_SET_STATEBLOB:" |
6a2dd35b SB |
503 | echo " actual : $res" |
504 | echo " expected: $exp" | |
505 | exit 1 | |
506 | fi | |
507 | ||
508 | # Send init command to the TPM: CMD_INIT = 00 00 00 02 | |
a19a8683 | 509 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x02\x00\x00\x00\x00')" |
6a2dd35b SB |
510 | exp=" 00 00 00 00" |
511 | if [ "$res" != "$exp" ]; then | |
512 | echo "Error: Socket TPM: Unexpected response from CMD_INIT:" | |
513 | echo " actual : $res" | |
514 | echo " expected: $exp" | |
515 | exit 1 | |
516 | fi | |
517 | ||
6a2dd35b | 518 | # Read PCR 10 -- has to return same result as before |
a19a8683 SB |
519 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
520 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x0a')" | |
6a2dd35b | 521 | 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 | 522 | if [ "$res" != "$exp" ]; then |
6a2dd35b SB |
523 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" |
524 | echo "expected: $exp" | |
a19a8683 | 525 | echo "received: $res" |
6a2dd35b SB |
526 | exit 1 |
527 | fi | |
528 | ||
492a635e | 529 | # Reset PCR 20 while in locality 0 -- should not work |
a19a8683 SB |
530 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
531 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0F\x00\x00\x00\xC8\x00\x03\x00\x00\x10')" | |
492a635e | 532 | exp=' 00 c4 00 00 00 0a 00 00 00 33' |
a19a8683 | 533 | if [ "$res" != "$exp" ]; then |
492a635e SB |
534 | echo "Error: Trying to reset PCR 20 in locality 0 returned unexpected result" |
535 | echo "expected: $exp" | |
a19a8683 | 536 | echo "received: $res" |
492a635e SB |
537 | exit 1 |
538 | fi | |
539 | ||
540 | # In locality 2 we can reset PCR 20 | |
541 | # Set the localoty on the TPM: CMD_SET_LOCALITY = 00 00 00 05 <locality> | |
a19a8683 | 542 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x05\x02')" |
492a635e SB |
543 | exp=" 00 00 00 00" |
544 | if [ "$res" != "$exp" ]; then | |
545 | echo "Error: Socket TPM: Unexpected response from CMD_SET_LOCALITY:" | |
546 | echo " actual : $res" | |
547 | echo " expected: $exp" | |
548 | exit 1 | |
549 | fi | |
550 | ||
551 | # Reset PCR 20 while in locality 2 -- has to work | |
a19a8683 SB |
552 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 |
553 | res="$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0F\x00\x00\x00\xC8\x00\x03\x00\x00\x10')" | |
492a635e | 554 | exp=' 00 c4 00 00 00 0a 00 00 00 00' |
a19a8683 | 555 | if [ "$res" != "$exp" ]; then |
492a635e SB |
556 | echo "Error: Could not reset PCR 20 in locality 2" |
557 | echo "expected: $exp" | |
a19a8683 | 558 | echo "received: $res" |
492a635e SB |
559 | exit 1 |
560 | fi | |
561 | ||
9ddc6998 | 562 | # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03 |
a19a8683 | 563 | res="$(swtpm_ctrl_tx ${SWTPM_INTERFACE} '\x00\x00\x00\x03')" |
9ddc6998 SB |
564 | exp=" 00 00 00 00" |
565 | if [ "$res" != "$exp" ]; then | |
566 | echo "Error: Socket TPM: Unexpected response from CMD_SHUTDOWN:" | |
567 | echo " actual : $res" | |
568 | echo " expected: $exp" | |
569 | exit 1 | |
570 | fi | |
571 | ||
ead37845 SB |
572 | if wait_file_gone $PID_FILE 2; then |
573 | echo "Error: TPM should have removed PID file by now." | |
9ddc6998 SB |
574 | exit 1 |
575 | fi | |
576 | ||
36407c93 | 577 | if wait_process_gone $PID 1; then |
ead37845 | 578 | echo "Error: Socket TPM should not be running anymore." |
9ddc6998 SB |
579 | exit 1 |
580 | fi | |
581 | ||
89d85f9a SB |
582 | # (Currently) expecting to see nothing in the log file |
583 | check_logfile_patterns_level_1 $LOG_FILE 0 | |
584 | rm -f $LOG_FILE | |
585 | ||
9ddc6998 SB |
586 | echo "OK" |
587 | ||
6852f6c8 | 588 | exit 0 |