]>
Commit | Line | Data |
---|---|---|
3008874c SB |
1 | #!/bin/bash |
2 | ||
3 | # For the license, see the LICENSE file in the root directory. | |
4 | #set -x | |
5 | ||
313cf75c SB |
6 | ROOT=${abs_top_builddir:-$(pwd)/..} |
7 | TESTDIR=${abs_top_testdir:-$(dirname "$0")} | |
3008874c | 8 | |
3008874c SB |
9 | VTPM_NAME="vtpm-test-tpm-probe" |
10 | SWTPM_DEV_NAME="/dev/${VTPM_NAME}" | |
cce7503c | 11 | export TPM_PATH="$(mktemp -d)" || exit 1 |
3008874c SB |
12 | STATE_FILE=$TPM_PATH/tpm-00.permall |
13 | VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate | |
14 | SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse} | |
15 | SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock | |
16 | SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock | |
17 | ||
18 | function cleanup() | |
19 | { | |
20 | pid=${SWTPM_PID} | |
21 | if [ -n "$pid" ]; then | |
47c7ea77 | 22 | kill_quiet -9 $pid |
3008874c SB |
23 | fi |
24 | rm -rf $TPM_PATH | |
25 | } | |
26 | ||
27 | trap "cleanup" EXIT | |
28 | ||
313cf75c SB |
29 | [ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse |
30 | source ${TESTDIR}/common | |
3008874c SB |
31 | |
32 | rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null | |
33 | ||
34 | run_swtpm ${SWTPM_INTERFACE} | |
35 | ||
100317d5 | 36 | display_processes_by_name "$SWTPM" |
3008874c SB |
37 | |
38 | kill -0 ${SWTPM_PID} | |
39 | if [ $? -ne 0 ]; then | |
40 | echo "Error: ${SWTPM_INTERFACE} TPM did not start." | |
41 | exit 1 | |
42 | fi | |
43 | ||
3008874c SB |
44 | # Before TPM_INIT: Read PCR 17 -- this gives a TPM_FAIL |
45 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11') | |
46 | exp=' 00 c4 00 00 00 0a 00 00 00 09' | |
47 | if [ "$RES" != "$exp" ]; then | |
48 | echo "Error: Before TPM_INIT: Did not get expected result from TPM_PCRRead(17)" | |
49 | echo "expected: $exp" | |
50 | echo "received: $RES" | |
51 | exit 1 | |
52 | fi | |
53 | ||
54 | # Init the TPM | |
55 | run_swtpm_ioctl ${SWTPM_INTERFACE} -i | |
56 | ||
57 | # Read PCR 17 -- this should give TPM_INVALID_POSTINIT | |
3008874c SB |
58 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11') |
59 | exp=' 00 c4 00 00 00 0a 00 00 00 26' | |
60 | if [ "$RES" != "$exp" ]; then | |
61 | echo "Error: Did not get expected result from TPM_PCRRead(17)" | |
62 | echo "expected: $exp" | |
63 | echo "received: $RES" | |
64 | exit 1 | |
65 | fi | |
66 | ||
a3820b86 SB |
67 | check_seccomp_profile "${SWTPM_EXE}" "${SWTPM_PID}" 2 |
68 | if [ $? -ne 0 ]; then | |
69 | exit 1 | |
70 | fi | |
71 | ||
148010c0 SB |
72 | run_swtpm_ioctl ${SWTPM_INTERFACE} -s |
73 | if [ $? -ne 0 ]; then | |
74 | echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM." | |
75 | exit 1 | |
76 | fi | |
77 | ||
78 | if wait_process_gone ${SWTPM_PID} 4; then | |
79 | echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore." | |
80 | exit 1 | |
81 | fi | |
82 | ||
3008874c SB |
83 | echo "OK" |
84 | ||
85 | exit 0 |