]> git.proxmox.com Git - swtpm.git/blob - tests/test_parameters
swtpm: integrity protect the encrypt TPM state
[swtpm.git] / tests / test_parameters
1 #!/bin/bash
2
3 # For the license, see the LICENSE file in the root directory.
4
5 DIR=$(dirname "$0")
6 ROOT=${DIR}/..
7
8 PARAMETERS=(
9 ""
10 "--createek"
11 "--take-ownership"
12 "--createek --lock-nvram"
13 "--take-ownership --lock-nvram"
14 "--lock-nvram"
15 "--take-ownership --ownerpass OOO"
16 "--take-ownership --srkpass SSS"
17 "--take-ownership --ownerpass OO --srkpass SS"
18 "--take-ownership --lock-nvram --display"
19 "--display"
20 "--lock-nvram --display"
21 "--take-ownership --srk-well-known"
22 "--take-ownership --owner-well-known"
23 "--take-ownership --srk-well-known --owner-well-known"
24 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${DIR}/swtpm_setup.conf --vmid test --display"
25 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${DIR}/swtpm_setup.conf --vmid test --display --keyfile ${DIR}/data/keyfile.txt"
26 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${DIR}/swtpm_setup.conf --vmid test --display --pwdfile ${DIR}/data/pwdfile.txt"
27 )
28
29 FILESIZES=(
30 1169
31 1589
32 2050
33 1589
34 2050
35 1169
36 2050
37 2050
38 2050
39 2050
40 1169
41 1169
42 2050
43 2050
44 2050
45 1705
46 1744
47 1744
48 )
49
50 if [ "$(id -u)" -ne 0 ]; then
51 echo "Need to be root to run this test."
52 exit 77
53 fi
54
55 SWTPM=swtpm
56 SWTPM_EXE=$ROOT/src/swtpm/$SWTPM
57 TCSD=`type -P tcsd`
58 TPMDIR=`mktemp -d`
59 SWTPM_SETUP_CONF=$ROOT/etc/swtpm_setup.conf
60 # filesystem privileges require to run swtpm_setup as root during test
61 TPMAUTHORING="$ROOT/src/swtpm_setup/swtpm_setup --config ${SWTPM_SETUP_CONF} --runas root"
62 PATH=${PWD}/${ROOT}/src/swtpm_bios:$PATH
63 PATH=${PWD}/${ROOT}/src/swtpm_setup:$PATH
64
65 trap "cleanup" SIGTERM EXIT
66
67 if test "$TCSD" = ""; then
68 echo "TCSD executable 'tcsd' was not found in path."
69 exit 1
70 fi
71
72 function cleanup()
73 {
74 rm -rf $TPMDIR
75 }
76
77 chown tss:tss $TPMDIR 2>/dev/null
78 if [ $? -ne 0 ]; then
79 echo "Could not change ownership of $TPMDIR to tss:tss." \
80 "You need to be root."
81 exit 1
82 fi
83
84 for (( i=0; i<${#PARAMETERS[*]}; i++)); do
85 rm -rf $TPMDIR/*
86 echo -n "Test $i: "
87 $TPMAUTHORING \
88 --tpm-state $TPMDIR \
89 --tpm "$SWTPM_EXE socket" \
90 ${PARAMETERS[$i]} 2>&1 >/dev/null
91
92 if [ $? -ne 0 ]; then
93 echo "ERROR: Test with parameters '${PARAMETERS[$i]}' failed."
94 exit 1
95 elif [ ! -f $TPMDIR/tpm-00.permall ]; then
96 echo "ERROR: Test with parameters '${PARAMETERS[$i]}' did not
97 produce file $TPMDIR/tpm-00.permall."
98 exit 1
99 fi
100
101 FILESIZE=`stat -c%s $TPMDIR/tpm-00.permall`
102 if [ ${FILESIZE} -ne ${FILESIZES[$i]} ]; then
103 echo "ERROR: Unexpected file size of $FILESIZE, "\
104 "expected ${FILESIZES[$i]}. Parameters: ${PARAMETERS[$i]}"
105 exit 1
106 fi
107
108 echo "SUCCESS with parameters '${PARAMETERS[$i]}'."
109 done