]> git.proxmox.com Git - swtpm.git/blob - tests/test_parameters
swtpm_setup: Use swtpm_ioctl to get TPM specification info for EK cert
[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=${SWTPM_EXE:-$ROOT/src/swtpm/$SWTPM}
57 SWTPM_IOCTL=${SWTPM_IOCTL:-$ROOT/src/swtpm_ioctl/swtpm_ioctl}
58 TCSD=`type -P tcsd`
59 TPMDIR=`mktemp -d`
60 SWTPM_SETUP_CONF=$ROOT/etc/swtpm_setup.conf
61 # filesystem privileges require to run swtpm_setup as root during test
62 TPMAUTHORING="$ROOT/src/swtpm_setup/swtpm_setup --config ${SWTPM_SETUP_CONF} --runas root"
63 PATH=${PWD}/${ROOT}/src/swtpm_bios:$PATH
64 PATH=${PWD}/${ROOT}/src/swtpm_setup:$PATH
65
66 source ${DIR}/test_config
67
68 trap "cleanup" SIGTERM EXIT
69
70 if test "$TCSD" = ""; then
71 echo "TCSD executable 'tcsd' was not found in path."
72 exit 1
73 fi
74
75 function cleanup()
76 {
77 rm -rf $TPMDIR
78 }
79
80 chown $TSS_USER:$TSS_GROUP $TPMDIR 2>/dev/null
81 if [ $? -ne 0 ]; then
82 echo "Could not change ownership of $TPMDIR to $TSS_USER:$TSS_GROUP." \
83 "You need to be root."
84 exit 1
85 fi
86
87 # swtpm_setup.conf points to the local create_certs.sh
88 # For create_certs.sh to be found (with out full path)
89 # add this directory to the PATH
90 PATH=$PATH:$PWD
91
92 for (( i=0; i<${#PARAMETERS[*]}; i++)); do
93 rm -rf $TPMDIR/*
94 echo -n "Test $i: "
95 $TPMAUTHORING \
96 --tpm-state $TPMDIR \
97 --tpm "$SWTPM_EXE socket" \
98 --swtpm_ioctl "$SWTPM_IOCTL" \
99 ${PARAMETERS[$i]} 2>&1 >/dev/null
100
101 if [ $? -ne 0 ]; then
102 echo "ERROR: Test with parameters '${PARAMETERS[$i]}' failed."
103 exit 1
104 elif [ ! -f $TPMDIR/tpm-00.permall ]; then
105 echo "ERROR: Test with parameters '${PARAMETERS[$i]}' did not
106 produce file $TPMDIR/tpm-00.permall."
107 exit 1
108 fi
109
110 FILESIZE=`stat -c%s $TPMDIR/tpm-00.permall`
111 if [ ${FILESIZE} -ne ${FILESIZES[$i]} ]; then
112 echo "ERROR: Unexpected file size of $FILESIZE, "\
113 "expected ${FILESIZES[$i]}. Parameters: ${PARAMETERS[$i]}"
114 exit 1
115 fi
116
117 echo "SUCCESS with parameters '${PARAMETERS[$i]}'."
118 done