]>
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")} | |
8 | ||
3008874c SB |
9 | VTPM_NAME="vtpm-test-tpm2-setbuffersize" |
10 | SWTPM_DEV_NAME="/dev/${VTPM_NAME}" | |
11 | export TPM_PATH=$(mktemp -d) | |
12 | STATE_FILE=$TPM_PATH/tpm2-00.permall | |
13 | OUTFILE=$TPM_PATH/output | |
14 | VOLATILE_STATE_FILE=$TPM_PATH/tpm2-00.volatilestate | |
15 | SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock | |
16 | SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock | |
17 | SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse} | |
18 | ||
19 | function cleanup() | |
20 | { | |
21 | pid=${SWTPM_PID} | |
22 | if [ -n "$pid" ]; then | |
47c7ea77 | 23 | kill_quiet -9 $pid |
3008874c SB |
24 | fi |
25 | rm -rf $TPM_PATH | |
26 | } | |
27 | ||
28 | trap "cleanup" EXIT | |
29 | ||
313cf75c SB |
30 | [ "${SWTPM_INTERFACE}" == cuse ] && source ${TESTDIR}/test_cuse |
31 | source ${TESTDIR}/common | |
3008874c SB |
32 | |
33 | rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null | |
34 | ||
35 | run_swtpm ${SWTPM_INTERFACE} --tpm2 | |
36 | ||
47c7ea77 | 37 | kill_quiet -0 ${SWTPM_PID} |
3008874c SB |
38 | if [ $? -ne 0 ]; then |
39 | echo "Error: ${SWTPM_INTERFACE} TPM did not start." | |
40 | exit 1 | |
41 | fi | |
42 | ||
43 | # Check the buffer size | |
44 | run_swtpm_ioctl ${SWTPM_INTERFACE} -b 0 > ${OUTFILE} | |
45 | if [ $? -ne 0 ]; then | |
46 | echo "Error: Could not get the buffersize of the ${SWTPM_INTERFACE} TPM." | |
47 | exit 1 | |
48 | fi | |
49 | cat ${OUTFILE} | |
50 | ||
51 | if [ -z "$(grep "TPM buffersize" ${OUTFILE} | grep 4096)" ]; then | |
468f7e61 | 52 | echo "Error: The TPM buffersize of the ${SWTPM_INTERFACE} TPM is not 4096." |
3008874c SB |
53 | exit 1 |
54 | fi | |
55 | ||
56 | # set the buffer size -- it's not going to change but command must not fail | |
57 | run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4000 > ${OUTFILE} | |
58 | if [ $? -ne 0 ]; then | |
59 | echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM." | |
60 | exit 1 | |
61 | fi | |
62 | cat ${OUTFILE} | |
63 | ||
64 | if [ -z "$(grep "TPM buffersize" ${OUTFILE} | grep 4000)" ]; then | |
468f7e61 | 65 | echo "Error: Could not set the buffersize of the ${SWTPM_INTERFACE} TPM to 4000." |
3008874c SB |
66 | exit 1 |
67 | fi | |
68 | ||
69 | # Init the TPM | |
70 | run_swtpm_ioctl ${SWTPM_INTERFACE} -i | |
71 | if [ $? -ne 0 ]; then | |
72 | echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM." | |
73 | exit 1 | |
74 | fi | |
75 | ||
47c7ea77 | 76 | kill_quiet -0 ${SWTPM_PID} 2>/dev/null |
3008874c SB |
77 | if [ $? -ne 0 ]; then |
78 | echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT." | |
79 | exit 1 | |
80 | fi | |
81 | ||
82 | # Set the buffer size -- should fail | |
f759520c | 83 | ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -b 4096 2>&1)" |
3008874c SB |
84 | if [ $? -eq 0 ]; then |
85 | echo "Error: Could set the buffersize while the ${SWTPM_INTERFACE} TPM is running." | |
86 | exit 1 | |
87 | fi | |
f759520c SB |
88 | exp="TPM result from PTM_SET_BUFFERSIZE: 0xa" |
89 | if [ "$ERR" != "$exp" ]; then | |
90 | echo "Error: Unexpected error message" | |
91 | echo "Received: $ERR" | |
92 | echo "Expected: $exp" | |
93 | exit 1 | |
94 | fi | |
3008874c SB |
95 | |
96 | # Startup the TPM2 | |
97 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
98 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00') | |
99 | exp=' 80 01 00 00 00 0a 00 00 00 00' | |
100 | if [ "$RES" != "$exp" ]; then | |
101 | echo "Error: Did not get expected result from TPM2_Startup(SU_Clear)" | |
102 | echo "expected: $exp" | |
103 | echo "received: $RES" | |
104 | exit 1 | |
105 | fi | |
106 | ||
107 | # Read the Buffer sizes; we want to see '4000' (0xfa0) in the buffer sizes now | |
108 | swtpm_open_cmddev ${SWTPM_INTERFACE} 100 | |
109 | RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x16\x00\x00\x01\x7a\x00\x00\x00\x06\x00\x00\x01\x1e\x00\x00\x00\x02') | |
110 | exp=' 80 01 00 00 00 23 00 00 00 00 01 00 00 00 06 00 00 00 02 00 00 01 1e 00 00 0f a0 00 00 01 1f 00 00 0f a0' | |
111 | if [ "$RES" != "$exp" ]; then | |
112 | echo "Error: Did not get expected result from TPM2_GetCapability()" | |
113 | echo "expected: $exp" | |
114 | echo "received: $RES" | |
115 | exit 1 | |
116 | fi | |
117 | ||
118 | run_swtpm_ioctl ${SWTPM_INTERFACE} -s | |
119 | if [ $? -ne 0 ]; then | |
120 | echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM." | |
121 | exit 1 | |
122 | fi | |
123 | ||
45d2d092 | 124 | if wait_process_gone ${SWTPM_PID} 4; then |
3008874c SB |
125 | echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore." |
126 | exit 1 | |
127 | fi | |
128 | ||
129 | if [ ! -e $STATE_FILE ]; then | |
130 | echo "Error: TPM state file $STATE_FILE does not exist." | |
131 | exit 1 | |
132 | fi | |
133 | ||
134 | echo "OK" | |
135 | ||
136 | exit 0 |