]> git.proxmox.com Git - swtpm.git/blame - tests/_test_tpm2_wrongorder
tests: Set test-check local user.name and user.email before git am
[swtpm.git] / tests / _test_tpm2_wrongorder
CommitLineData
3008874c
SB
1#!/bin/bash
2
3# For the license, see the LICENSE file in the root directory.
4#set -x
5
313cf75c
SB
6ROOT=${abs_top_builddir:-$(pwd)/..}
7TESTDIR=${abs_top_testdir:-$(dirname "$0")}
8
3008874c
SB
9VTPM_NAME="vtpm-test-tpm2-wrongorder"
10SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
11export TPM_PATH=$(mktemp -d)
12STATE_FILE=$TPM_PATH/tpm2-00.permall
13VOLATILE_STATE_FILE=$TPM_PATH/tpm2-00.volatilestate
14SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse}
15SWTPM_CMD_UNIX_PATH=${TPM_PATH}/unix-cmd.sock
16SWTPM_CTRL_UNIX_PATH=${TPM_PATH}/unix-ctrl.sock
17
18function 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
27trap "cleanup" EXIT
28
313cf75c
SB
29[ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
30source ${TESTDIR}/common
3008874c
SB
31
32rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev/null
33
34run_swtpm ${SWTPM_INTERFACE} --tpm2
35
100317d5 36display_processes_by_name "$SWTPM"
3008874c 37
47c7ea77 38kill_quiet -0 ${SWTPM_PID}
3008874c
SB
39if [ $? -ne 0 ]; then
40 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
41 exit 1
42fi
43
44# Get the established bit before the TPM has been initialized
45# This should not work
46
47if [ ${SWTPM_INTERFACE} != "cuse" ]; then
48 run_swtpm_ioctl ${SWTPM_INTERFACE} --stop
49 if [ $? -ne 0 ]; then
50 echo "Error: Could not stop the ${SWTPM_INTERFACE} TPM."
51 exit 1
52 fi
53fi
54
f759520c 55ERR="$(run_swtpm_ioctl ${SWTPM_INTERFACE} -e 2>&1)"
3008874c
SB
56if [ $? -eq 0 ]; then
57 echo "Error: Could get established bit from ${SWTPM_INTERFACE} TPM before init."
58 exit 1
59fi
f759520c
SB
60exp="TPM result from PTM_GET_TPMESTABLISHED: 0xa"
61if [ "$ERR" != "$exp" ]; then
62 echo "Error: Unexpected error message"
63 echo "Received: $ERR"
64 echo "Expected: $exp"
65 exit 1
66fi
3008874c 67
47c7ea77 68kill_quiet -0 ${SWTPM_PID}
3008874c
SB
69if [ $? -ne 0 ]; then
70 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
71 exit 1
72fi
73
74# Open access to the TPM
75swtpm_open_cmddev ${SWTPM_INTERFACE} 100
76
77# Read PCR 17
78# length CC count hashalg sz
79RES=$(swtpm_cmd_tx ${SWTPM_INTERFACE} '\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b\x03\x00\x00\x02')
80exp=' 80 01 00 00 00 0a 00 00 01 01'
81if [ "$RES" != "$exp" ]; then
82 echo "Error: Did not get expected result from TPM_PCRRead(17)"
83 echo "expected: $exp"
84 echo "received: $RES"
85 exit 1
86fi
87
88exec 100>&-
89
47c7ea77 90kill_quiet -0 ${SWTPM_PID}
3008874c
SB
91if [ $? -ne 0 ]; then
92 echo "Error: ${SWTPM_INTERFACE} TPM must have crashed."
93 exit 1
94fi
95
96# Init the TPM
97run_swtpm_ioctl ${SWTPM_INTERFACE} -i
98if [ $? -ne 0 ]; then
99 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
100 exit 1
101fi
102
47c7ea77 103kill_quiet -0 ${SWTPM_PID} 2>/dev/null
3008874c
SB
104if [ $? -ne 0 ]; then
105 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
106 exit 1
107fi
108
109run_swtpm_ioctl ${SWTPM_INTERFACE} -s
110if [ $? -ne 0 ]; then
111 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
112 exit 1
113fi
114
45d2d092 115if wait_process_gone ${SWTPM_PID} 4; then
3008874c
SB
116 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
117 exit 1
118fi
119
120if [ ! -e $STATE_FILE ]; then
121 echo "Error: TPM state file $STATE_FILE does not exist."
122 exit 1
123fi
124
125echo "OK"
126
127exit 0