]>
Commit | Line | Data |
---|---|---|
01aa2ed3 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")} | |
8 | ||
01aa2ed3 SB |
9 | VTPM_NAME="vtpm-test-hashing" |
10 | SWTPM_DEV_NAME="/dev/${VTPM_NAME}" | |
11 | export TPM_PATH=$(mktemp -d) | |
12 | STATE_FILE=$TPM_PATH/tpm-00.permall | |
13 | VOLATILE_STATE_FILE=$TPM_PATH/tpm-00.volatilestate | |
14 | SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock | |
15 | SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock | |
16 | SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse} | |
17 | ||
18 | function cleanup() | |
19 | { | |
20 | pid=${SWTPM_PID} | |
21 | if [ -n "$pid" ]; then | |
47c7ea77 | 22 | kill_quiet -9 $pid |
01aa2ed3 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 | |
01aa2ed3 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" |
01aa2ed3 | 37 | |
47c7ea77 | 38 | kill_quiet -0 ${SWTPM_PID} |
01aa2ed3 SB |
39 | if [ $? -ne 0 ]; then |
40 | echo "Error: ${SWTPM_INTERFACE} TPM did not start." | |
41 | exit 1 | |
42 | fi | |
43 | ||
44 | # Init the TPM | |
45 | run_swtpm_ioctl ${SWTPM_INTERFACE} -i | |
46 | if [ $? -ne 0 ]; then | |
47 | echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM." | |
48 | exit 1 | |
49 | fi | |
50 | ||
47c7ea77 | 51 | kill_quiet -0 ${SWTPM_PID} 2>/dev/null |
01aa2ed3 SB |
52 | if [ $? -ne 0 ]; then |
53 | echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT." | |
54 | exit 1 | |
55 | fi | |
56 | ||
57 | # Startup the TPM | |
58 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
59 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01') | |
60 | exp=' 00 c4 00 00 00 0a 00 00 00 00' | |
61 | if [ "$RES" != "$exp" ]; then | |
62 | echo "Error: Did not get expected result from TPM_Startup(ST_Clear)" | |
63 | echo "expected: $exp" | |
64 | echo "received: $RES" | |
65 | exit 1 | |
66 | fi | |
67 | ||
68 | # Check the TPM Established bit before the hashing | |
69 | RES=$(run_swtpm_ioctl ${SWTPM_INTERFACE} -e) | |
70 | if [ $? -ne 0 ]; then | |
71 | echo "Error: Could not get the TPM Established flag." | |
72 | exit 1 | |
73 | fi | |
74 | exp='tpmEstablished is 0' | |
75 | if [ "$RES" != "$exp" ]; then | |
76 | echo "Error (1): TPM Established flag has wrong value." | |
77 | echo "expected: $exp" | |
78 | echo "received: $RES" | |
79 | exit 1 | |
80 | fi | |
81 | ||
82 | run_swtpm_ioctl ${SWTPM_INTERFACE} -h 1234 | |
83 | if [ $? -ne 0 ]; then | |
84 | echo "Error: Hash command did not work." | |
85 | exit 1 | |
86 | fi | |
87 | ||
88 | # Read PCR 17 | |
89 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
90 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11') | |
91 | exp=' 00 c4 00 00 00 1e 00 00 00 00 97 e9 76 e4 f2 2c d6 d2 4a fd 21 20 85 ad 7a 86 64 7f 2a e5' | |
92 | if [ "$RES" != "$exp" ]; then | |
93 | echo "Error: (1) Did not get expected result from TPM_PCRRead(17)" | |
94 | echo "expected: $exp" | |
95 | echo "received: $RES" | |
96 | exit 1 | |
97 | fi | |
98 | ||
99 | # Check the TPM Established bit after the hashing | |
100 | RES=$(run_swtpm_ioctl ${SWTPM_INTERFACE} -e) | |
101 | if [ $? -ne 0 ]; then | |
102 | echo "Error: Could not get the TPM Established flag." | |
103 | exit 1 | |
104 | fi | |
105 | exp='tpmEstablished is 1' | |
106 | if [ "$RES" != "$exp" ]; then | |
107 | echo "Error (2): TPM Established flag has wrong value." | |
108 | echo "expected: $exp" | |
109 | echo "received: $RES" | |
110 | exit 1 | |
111 | fi | |
112 | ||
113 | # Reset the establishment bit via locality 3 | |
114 | run_swtpm_ioctl ${SWTPM_INTERFACE} -l 3 | |
115 | if [ $? -ne -0 ]; then | |
116 | echo "Error: Could not set locality 3" | |
117 | exit 1 | |
118 | fi | |
119 | ||
120 | # \x40 or \x0B seems to confuse 'normal' echo | |
121 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
122 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0A\x40\x00\x00\x0B') | |
123 | exp=' 00 c4 00 00 00 0a 00 00 00 00' | |
124 | if [ "$RES" != "$exp" ]; then | |
125 | echo "Error: Could not reset the establishment bit" | |
126 | echo "expected: $exp" | |
127 | echo "received: $RES" | |
128 | exit 1 | |
129 | fi | |
130 | ||
131 | # Check the TPM Established bit after the reset | |
132 | RES=$(run_swtpm_ioctl ${SWTPM_INTERFACE} -e) | |
133 | if [ $? -ne 0 ]; then | |
134 | echo "Error: Could not get the TPM Established flag." | |
135 | exit 1 | |
136 | fi | |
137 | exp='tpmEstablished is 0' | |
138 | if [ "$RES" != "$exp" ]; then | |
139 | echo "Error (3): TPM Established flag has wrong value." | |
140 | echo "expected: $exp" | |
141 | echo "received: $RES" | |
142 | exit 1 | |
143 | fi | |
144 | ||
145 | # back to locality 0 | |
146 | run_swtpm_ioctl ${SWTPM_INTERFACE} -l 0 | |
147 | if [ $? -ne 0 ]; then | |
148 | echo "Error: Could not set locality 0." | |
149 | exit 1 | |
150 | fi | |
151 | ||
152 | # Read from a file | |
153 | dd if=/dev/zero bs=1024 count=1024 2>/dev/null| \ | |
154 | run_swtpm_ioctl ${SWTPM_INTERFACE} -h - | |
155 | ||
156 | # Read PCR 17 | |
157 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
158 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11') | |
159 | exp=' 00 c4 00 00 00 1e 00 00 00 00 d8 0e 7a 7b 3c 37 88 7d b4 c2 88 08 1d a7 53 f6 4b 11 3a 9c' | |
160 | if [ "$RES" != "$exp" ]; then | |
161 | echo "Error: (2) Did not get expected result from TPM_PCRRead(17)" | |
162 | echo "expected: $exp" | |
163 | echo "received: $RES" | |
164 | exit 1 | |
165 | fi | |
166 | ||
167 | run_swtpm_ioctl ${SWTPM_INTERFACE} -s | |
168 | if [ $? -ne 0 ]; then | |
169 | echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM." | |
170 | exit 1 | |
171 | fi | |
172 | ||
45d2d092 | 173 | if wait_process_gone ${SWTPM_PID} 4; then |
01aa2ed3 SB |
174 | echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore." |
175 | exit 1 | |
176 | fi | |
177 | ||
178 | if [ ! -e $STATE_FILE ]; then | |
179 | echo "Error: TPM state file $STATE_FILE does not exist." | |
180 | exit 1 | |
181 | fi | |
182 | ||
183 | echo "OK" | |
184 | ||
185 | exit 0 |