3 # For the license, see the LICENSE file in the root directory.
6 if [ "$(id -u)" -ne 0 ]; then
7 echo "Need to be root to run this test."
11 ROOT
=${abs_top_builddir:-$(dirname "$0")/..}
12 TESTDIR
=${abs_top_testdir:-$(dirname "$0")}
15 SWTPM_EXE
=${SWTPM_EXE:-$ROOT/src/swtpm/$SWTPM}
17 STATE_FILE
=$TPM_PATH/tpm-00.permall
18 VOLATILE_STATE_FILE
=$TPM_PATH/tpm-00.volatilestate
19 PID_FILE
=$TPM_PATH/${SWTPM}.pid
20 SOCK_PATH
=$TPM_PATH/sock
21 CMD_PATH
=$TPM_PATH/cmd
22 RESP_PATH
=$TPM_PATH/resp
23 LOGFILE
=$TPM_PATH/logfile
27 pid
=$
(ps aux |
grep $SWTPM |
grep -E " file=${PID_FILE}\$" | gawk
'{print $2}')
28 if [ -n "$pid" ]; then
36 source ${TESTDIR}/common
37 source ${TESTDIR}/load_vtpm_proxy
39 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev
/null
41 $SWTPM_EXE chardev
--vtpm-proxy \
42 --tpmstate dir
=$TPM_PATH \
43 --ctrl type=unixio
,path
=$SOCK_PATH \
44 ${SWTPM_TEST_SECCOMP_OPT} \
45 --pid file=$PID_FILE &>$LOGFILE &
47 PID
=$
(ps aux |
grep $SWTPM |
grep -E " file=${PID_FILE}\$" | gawk
'{print $2}')
49 display_processes_by_name
"$SWTPM"
53 echo "Error: Chardev TPM did not start."
57 if wait_for_file
$PID_FILE 3; then
58 echo "Error: Chardev TPM did not write pidfile."
62 # Wait for chardev to appear; TPM 1.2 may take a long time to self-test
64 for ((i
= 0; i
< 200; i
++)); do
65 if [ -z "${TPM_DEVICE}" ]; then
66 TPM_DEVICE
=$
(sed -n 's,.*\(/dev/tpm[0-9]\+\).*,\1,p' $LOGFILE)
67 if [ -n "${TPM_DEVICE}" ]; then
68 echo "Using ${TPM_DEVICE}."
71 if [ -n "${TPM_DEVICE}" ]; then
72 [ -c "${TPM_DEVICE}" ] && break
76 if ! [ -c "${TPM_DEVICE}" ]; then
77 echo "Error: Chardev ${TPM_DEVICE} did not appear"
81 # Open access to the TPM
84 echo "Error: Could not open $TPM_DEVICE"
88 # Read PCR 17 -- this should give a fatal error response
89 echo -en '\x00\xC1\x00\x00\x00\x0E\x00\x00\x00\x15\x00\x00\x00\x11' >&100
90 #RES=$(cat <&100 | od -t x1 -A n -w128)
91 RES
=$
(od -t x1
-A n
-w128 <&100)
92 exp
=' 00 c4 00 00 00 1e 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff'
93 if [ "$RES" != "$exp" ]; then
94 echo "Error: Did not get expected result from TPM_PCRRead(17)"
103 if [ $?
-ne 0 ]; then
104 echo "Error: Chardev TPM must have crashed."
108 if [ ! -e $STATE_FILE ]; then
109 echo "Error: TPM state file $STATE_FILE does not exist."
113 # Send shutdown command to the TPM: CMD_SHUTDOWN = 00 00 00 03
114 echo -en '\x00\x00\x00\x03' > $CMD_PATH
115 socat
-x -t10 FILE
:$CMD_PATH,rdonly UNIX-CONNECT
:$SOCK_PATH 2>&1 | \
117 tail -n1 > $RESP_PATH
118 res
="$(cat $RESP_PATH)"
120 if [ "$res" != "$exp" ]; then
121 echo "Error: Unexpected response from CMD_SHUTDOWN:"
122 echo " actual : $res"
123 echo " expected: $exp"
127 if wait_file_gone
$PID_FILE 2; then
128 echo "Error: TPM should have removed PID file by now."
132 if wait_process_gone
${PID} 4; then
133 echo "Error: TPM should not be running anymore."