]>
git.proxmox.com Git - swtpm.git/blob - tests/test_locality
3 # For the license, see the LICENSE file in the root directory.
9 SWTPM_EXE
=$ROOT/src
/swtpm
/$SWTPM
10 CUSE_TPM_IOCTL
=$ROOT/src
/swtpm_ioctl
/swtpm_ioctl
13 VTPM_NAME
=$
(printf "vtpm-%d-%d" $MAJOR $MINOR)
15 STATE_FILE
=$TPM_PATH/tpm-00.permall
16 VOLATILE_STATE_FILE
=$TPM_PATH/tpm-00.volatilestate
18 if [ "$(id -u)" -ne 0 ]; then
19 echo "Need to be root to run this test."
25 pid
=$
(ps aux |
grep $SWTPM |
grep $VTPM_NAME | gawk
'{print $2}')
26 if [ -n "$pid" ]; then
35 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev
/null
37 $SWTPM_EXE -n $VTPM_NAME
39 PID
=$
(ps aux |
grep $SWTPM |
grep $VTPM_NAME | gawk
'{print $2}')
41 ps aux |
grep $SWTPM |
grep -v grep
45 echo "Error: CUSE TPM did not start."
51 $CUSE_TPM_IOCTL -i /dev
/$VTPM_NAME
55 kill -0 $PID 2>/dev
/null
57 echo "Error: CUSE TPM not running anymore after INIT."
61 # Set locality 4 on the TPM
62 $CUSE_TPM_IOCTL -l 4 /dev
/$VTPM_NAME
64 echo "Error: CUSE TPM did not accept locality 4."
68 # Set illegal locality 5 on the TPM
69 $CUSE_TPM_IOCTL -l 5 /dev
/$VTPM_NAME
71 echo "Error: CUSE TPM accepted locality 5."
75 # Set locality 0 on the TPM
76 $CUSE_TPM_IOCTL -l 0 /dev
/$VTPM_NAME
78 echo "Error: CUSE TPM did not accept locality 0."
82 # In locality 2 we can reset PCR 20
83 $CUSE_TPM_IOCTL -l 2 /dev
/$VTPM_NAME
85 echo "Error: CUSE TPM did not accept locality 2."
89 exec 100<>/dev
/$VTPM_NAME
92 echo -en '\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01' >&100
93 RES
=$
(dd if=/proc
/self
/fd
/100 2>/dev
/null |
od -t x1
-A n
)
94 exp
=' 00 c4 00 00 00 0a 00 00 00 00'
95 if [ "$RES" != "$exp" ]; then
96 echo "Error: Did not get expected result from TPM_Startup(ST_Clear)"
103 echo -en '\x00\xC1\x00\x00\x00\x0F\x00\x00\x00\xC8\x00\x03\x00\x00\x10' >&100
104 RES
=$
(dd if=/proc
/self
/fd
/100 2>/dev
/null |
od -t x1
-A n
)
105 exp
=' 00 c4 00 00 00 0a 00 00 00 00'
106 if [ "$RES" != "$exp" ]; then
107 echo "Error: Could not reset PCR 20 in locality 2"
108 echo "expected: $exp"
109 echo "received: $RES"
114 $CUSE_TPM_IOCTL -s /dev
/$VTPM_NAME
118 kill -0 $PID 2>/dev
/null
119 if [ $?
-eq 0 ]; then
120 echo "Error: CUSE TPM should not be running anymore."
124 if [ ! -e $STATE_FILE ]; then
125 echo "Error: TPM state file $STATE_FILE does not exist."