]>
Commit | Line | Data |
---|---|---|
c88b36f0 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 | ||
c88b36f0 SB |
9 | VTPM_NAME=${vtpm-test-tpm2-resume-volatile:-VTPM_NAME} |
10 | SWTPM_DEV_NAME="/dev/${VTPM_NAME}" | |
11 | SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse} | |
12 | ||
13 | tpmstatedir="$(mktemp -d)" | |
14 | if [ -z "$tpmstatedir" ]; then | |
15 | echo "Could not create temporary directory" | |
16 | exit 1 | |
17 | fi | |
18 | ||
19 | SWTPM_CMD_UNIX_PATH=${tpmstatedir}/unix-cmd.sock | |
20 | SWTPM_CTRL_UNIX_PATH=${tpmstatedir}/unix-ctrl.sock | |
21 | ||
22 | function cleanup() | |
23 | { | |
24 | pid=${SWTPM_PID} | |
25 | if [ -n "$pid" ]; then | |
26 | kill -9 $pid | |
27 | fi | |
28 | rm -rf $tpmstatedir | |
29 | } | |
30 | ||
31 | trap "cleanup" EXIT | |
32 | ||
313cf75c SB |
33 | [ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse |
34 | source ${TESTDIR}/common | |
c88b36f0 SB |
35 | |
36 | export TPM_PATH=$tpmstatedir | |
37 | ||
38 | # copy all the state files | |
313cf75c | 39 | cp ${TESTDIR}/data/tpm2state1/* ${TPM_PATH} |
c88b36f0 SB |
40 | |
41 | run_swtpm ${SWTPM_INTERFACE} --tpm2 | |
42 | ||
43 | ps aux | grep $SWTPM | grep -v grep | |
44 | ||
45 | kill -0 ${SWTPM_PID} | |
46 | if [ $? -ne 0 ]; then | |
47 | echo "Error: CUSE TPM did not start." | |
48 | exit 1 | |
49 | fi | |
50 | ||
51 | # Init the TPM | |
52 | run_swtpm_ioctl ${SWTPM_INTERFACE} -i | |
53 | if [ $? -ne 0 ]; then | |
54 | echo "Error: Could not initialize the CUSE TPM." | |
55 | exit 1 | |
56 | fi | |
57 | ||
58 | kill -0 ${SWTPM_PID} 2>/dev/null | |
59 | if [ $? -ne 0 ]; then | |
60 | echo "Error: CUSE TPM not running anymore after INIT." | |
61 | exit 1 | |
62 | fi | |
63 | ||
64 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
65 | ||
66 | # Read PCR 10 (from pcrextend -ha 10 -ic test) | |
67 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b\x03\x00\x04\x00') | |
68 | exp=' 80 01 00 00 00 3e 00 00 00 00 00 00 00 16 00 00 00 01 00 0b 03 00 04 00 00 00 00 01 00 20 f6 85 98 e5 86 8d e6 8b 97 29 99 60 f2 71 7d 17 67 89 a4 2f 9a ae a8 c7 b7 aa 79 a8 62 56 c1 de' | |
69 | if [ "$RES" != "$exp" ]; then | |
70 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" | |
71 | echo "expected: $exp" | |
72 | echo "received: $RES" | |
73 | exit 1 | |
74 | fi | |
75 | ||
76 | # Save the volatile state again | |
77 | run_swtpm_ioctl ${SWTPM_INTERFACE} -v | |
78 | if [ $? -ne 0 ]; then | |
79 | echo "Error: Could not have the CUSE TPM write the volatile state to a file." | |
80 | exit 1 | |
81 | fi | |
82 | if [ ! -r $VOLATILE_STATE_FILE ]; then | |
83 | echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist." | |
84 | exit 1 | |
85 | fi | |
86 | ||
87 | # Shut the TPM down | |
88 | exec 100>&- | |
89 | run_swtpm_ioctl ${SWTPM_INTERFACE} -s | |
90 | ||
91 | echo "Test 1: Ok" | |
92 | ||
93 | # 2nd test: with encrypted state | |
94 | # copy all the state files | |
313cf75c | 95 | cp ${TESTDIR}/data/tpm2state2/* ${TPM_PATH} |
c88b36f0 SB |
96 | |
97 | run_swtpm ${SWTPM_INTERFACE} \ | |
98 | --tpm2 \ | |
313cf75c | 99 | --key pwdfile=${TESTDIR}/data/tpm2state2/pwdfile.txt |
c88b36f0 SB |
100 | |
101 | ps aux | grep $SWTPM | grep -v grep | |
102 | ||
103 | kill -0 ${SWTPM_PID} | |
104 | if [ $? -ne 0 ]; then | |
105 | echo "Error: CUSE TPM did not start." | |
106 | exit 1 | |
107 | fi | |
108 | ||
109 | # Init the TPM | |
110 | run_swtpm_ioctl ${SWTPM_INTERFACE} -i | |
111 | if [ $? -ne 0 ]; then | |
112 | echo "Error: CUSE TPM initialization failed." | |
113 | exit 1 | |
114 | fi | |
115 | ||
116 | kill -0 ${SWTPM_PID} 2>/dev/null | |
117 | if [ $? -ne 0 ]; then | |
118 | echo "Error: CUSE TPM not running anymore after INIT." | |
119 | exit 1 | |
120 | fi | |
121 | ||
122 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
123 | if [ $? -ne 0 ]; then | |
124 | echo "Error: Could not open command interface." | |
125 | ext 1 | |
126 | fi | |
127 | ||
128 | # Read PCR 10 (from pcrextend -ha 10 -ic test) | |
129 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b\x03\x00\x04\x00') | |
130 | exp=' 80 01 00 00 00 3e 00 00 00 00 00 00 00 16 00 00 00 01 00 0b 03 00 04 00 00 00 00 01 00 20 f6 85 98 e5 86 8d e6 8b 97 29 99 60 f2 71 7d 17 67 89 a4 2f 9a ae a8 c7 b7 aa 79 a8 62 56 c1 de' | |
131 | if [ "$RES" != "$exp" ]; then | |
132 | echo "Error: (1) Did not get expected result from TPM_PCRRead(10)" | |
133 | echo "expected: $exp" | |
134 | echo "received: $RES" | |
135 | exit 1 | |
136 | fi | |
137 | ||
138 | # Save the volatile state again | |
139 | run_swtpm_ioctl ${SWTPM_INTERFACE} -v | |
140 | if [ $? -ne 0 ]; then | |
141 | echo "Error: Could not have the CUSE TPM write the volatile state to a file." | |
142 | exit 1 | |
143 | fi | |
144 | if [ ! -r $VOLATILE_STATE_FILE ]; then | |
145 | echo "Error: Volatile state file $VOLATILE_STATE_FILE does not exist." | |
146 | exit 1 | |
147 | fi | |
148 | ||
149 | # Shut the TPM down | |
150 | exec 100>&- | |
151 | run_swtpm_ioctl ${SWTPM_INTERFACE} -s | |
152 | if [ $? -ne 0 ]; then | |
153 | echo "Error: Could not shut down the CUSE TPM." | |
154 | exit 1 | |
155 | fi | |
156 | ||
157 | echo "Test 2: Ok" |