]>
Commit | Line | Data |
---|---|---|
e46a2b66 SB |
1 | #!/bin/bash |
2 | ||
3 | # For the license, see the LICENSE file in the root directory. | |
4 | ||
313cf75c SB |
5 | ROOT=${abs_top_builddir:-$(dirname "$0")/..} |
6 | TESTDIR=${abs_top_testdir:=$(dirname "$0")} | |
c51c07a0 | 7 | SRCDIR=${abs_top_srcdir:-$(dirname "$0")/..} |
e46a2b66 SB |
8 | |
9 | PARAMETERS=( | |
10 | "" | |
11 | "--createek" | |
12 | "--take-ownership" | |
13 | "--createek --lock-nvram" | |
14 | "--take-ownership --lock-nvram" | |
15 | "--lock-nvram" | |
16 | "--take-ownership --ownerpass OOO" | |
17 | "--take-ownership --srkpass SSS" | |
18 | "--take-ownership --ownerpass OO --srkpass SS" | |
19 | "--take-ownership --lock-nvram --display" | |
20 | "--display" | |
21 | "--lock-nvram --display" | |
22 | "--take-ownership --srk-well-known" | |
23 | "--take-ownership --owner-well-known" | |
24 | "--take-ownership --srk-well-known --owner-well-known" | |
313cf75c SB |
25 | "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display" |
26 | "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --keyfile ${TESTDIR}/data/keyfile.txt" | |
27 | "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --pwdfile ${TESTDIR}/data/pwdfile.txt" | |
e46a2b66 SB |
28 | ) |
29 | ||
30 | FILESIZES=( | |
27bf9db6 SB |
31 | 1185 |
32 | 1605 | |
33 | 2066 | |
34 | 1605 | |
35 | 2066 | |
36 | 1185 | |
37 | 2066 | |
38 | 2066 | |
39 | 2066 | |
40 | 2066 | |
41 | 1185 | |
42 | 1185 | |
43 | 2066 | |
44 | 2066 | |
45 | 2066 | |
46 | 1721 | |
638bd3ba SB |
47 | 1788 |
48 | 1788 | |
e46a2b66 SB |
49 | ) |
50 | ||
e150007d SB |
51 | if [ "$(id -u)" -ne 0 ]; then |
52 | echo "Need to be root to run this test." | |
53 | exit 77 | |
54 | fi | |
55 | ||
e46a2b66 | 56 | SWTPM=swtpm |
19e05751 | 57 | SWTPM_EXE=${SWTPM_EXE:-$ROOT/src/swtpm/$SWTPM} |
e2951df7 | 58 | SWTPM_IOCTL=${SWTPM_IOCTL:-$ROOT/src/swtpm_ioctl/swtpm_ioctl} |
e46a2b66 SB |
59 | TCSD=`type -P tcsd` |
60 | TPMDIR=`mktemp -d` | |
c51c07a0 | 61 | SWTPM_SETUP_CONF=$SRCDIR/etc/swtpm_setup.conf |
e46a2b66 SB |
62 | # filesystem privileges require to run swtpm_setup as root during test |
63 | TPMAUTHORING="$ROOT/src/swtpm_setup/swtpm_setup --config ${SWTPM_SETUP_CONF} --runas root" | |
c51c07a0 | 64 | PATH=${ROOT}/src/swtpm_bios:${TESTDIR}:$PATH |
e46a2b66 | 65 | |
313cf75c | 66 | source ${TESTDIR}/test_config |
6e7df39f | 67 | |
e46a2b66 SB |
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 | ||
6e7df39f | 80 | chown $TSS_USER:$TSS_GROUP $TPMDIR 2>/dev/null |
e46a2b66 | 81 | if [ $? -ne 0 ]; then |
6e7df39f | 82 | echo "Could not change ownership of $TPMDIR to $TSS_USER:$TSS_GROUP." \ |
e46a2b66 SB |
83 | "You need to be root." |
84 | exit 1 | |
85 | fi | |
86 | ||
84d2e89a SB |
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 | ||
e46a2b66 SB |
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" \ | |
e2951df7 | 98 | --swtpm_ioctl "$SWTPM_IOCTL" \ |
e46a2b66 SB |
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 |