Debian Codegraph @

tests/test_parameters

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # For the license, see the LICENSE file in the root directory.
4
5 ROOT=${abs_top_builddir:-$(dirname "$0")/..}
6 TESTDIR=${abs_top_testdir:=$(dirname "$0")}
7
8 PATH=$ROOT/src/swtpm:$PATH
9
10 PARAMETERS=(
11 ""
12 "--createek"
13 "--take-ownership"
14 "--createek --lock-nvram"
15 "--take-ownership --lock-nvram"
16 "--lock-nvram"
17 "--take-ownership --ownerpass OOO"
18 "--take-ownership --srkpass SSS"
19 "--take-ownership --ownerpass OO --srkpass SS"
20 "--take-ownership --lock-nvram --display"
21 "--display"
22 "--lock-nvram --display"
23 "--take-ownership --srk-well-known"
24 "--take-ownership --owner-well-known"
25 "--take-ownership --srk-well-known --owner-well-known"
26 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display"
27 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --keyfile ${TESTDIR}/data/keyfile.txt"
28 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --pwdfile ${TESTDIR}/data/pwdfile.txt"
29 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --keyfile ${TESTDIR}/data/keyfile256bit.txt --cipher aes-256-cbc"
30 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --pwdfile ${TESTDIR}/data/pwdfile.txt --cipher aes-256-cbc"
31 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --keyfile-fd 100 --cipher aes-256-cbc"
32 "--createek --create-ek-cert --create-platform-cert --lock-nvram --config ${TESTDIR}/swtpm_setup.conf --vmid test --display --pwdfile-fd 101 --cipher aes-256-cbc"
33 )
34
35 # Open read-only file descriptors referenced in test cases
36 exec 100<"${TESTDIR}/data/keyfile256bit.txt"
37 exec 101<"${TESTDIR}/data/pwdfile.txt"
38
39 FILESIZES=(
40 1185
41 1605
42 2066
43 1605
44 2066
45 1185
46 2066
47 2066
48 2066
49 2066
50 1185
51 1185
52 2066
53 2066
54 2066
55 1721
56 1788
57 1788
58 1820
59 1820
60 1820
61 1820
62 )
63
64 source "${TESTDIR}/common"
65 skip_test_no_tpm12 "${SWTPM_EXE}"
66
67 TPMDIR="$(mktemp -d)" || exit 1
68 # filesystem privileges require to run swtpm_setup as root during test
69 TPMAUTHORING="$SWTPM_SETUP --config ${SWTPM_SETUP_CONF}"
70 PATH=${ROOT}/src/swtpm_bios:${TESTDIR}:$PATH
71
72 trap "cleanup" SIGTERM EXIT
73
74 function cleanup()
75 {
76 rm -rf "$TPMDIR"
77 }
78
79 # swtpm_setup.conf points to the local create_certs.sh
80 # For create_certs.sh to be found (with out full path)
81 # add this directory to the PATH
82 PATH=$PATH:$PWD
83
84 for (( i=0; i<${#PARAMETERS[*]}; i++)); do
85 rm -rf "${TPMDIR:?}"/*
86 echo -n "Test $i: "
87 params=${PARAMETERS[$i]}
88 if ! $TPMAUTHORING \
89 --tpm-state "$TPMDIR" \
90 --tpm "$SWTPM_EXE socket ${SWTPM_TEST_SECCOMP_OPT}" \
91 ${params:+${params}} &>/dev/null;
92 then
93 echo "ERROR: Test with parameters '${params}' failed."
94 exit 1
95 elif [ ! -f "$TPMDIR/tpm-00.permall" ]; then
96 echo "ERROR: Test with parameters '${params}' did not
97 produce file $TPMDIR/tpm-00.permall."
98 exit 1
99 fi
100
101 FILESIZE=$(get_filesize "$TPMDIR/tpm-00.permall")
102 if [ "${FILESIZE}" -ne "${FILESIZES[$i]}" ]; then
103 echo "ERROR: Unexpected file size of $FILESIZE, "\
104 "expected ${FILESIZES[$i]}. Parameters: ${params}"
105 exit 1
106 fi
107
108 # Make sure the state is encrypted when a key was given.
109 # We expect sequences of 4 0-bytes in unencrypted state
110 # and no such sequences in encrypted state.
111 nullseq="$(od -t x1 -A n < "$TPMDIR/tpm-00.permall" | tr -d '\n' | tr -s ' ' |
112 grep "00 00 00 00")"
113 if [[ "$params}" =~ (keyfile|pwdfile) ]]; then
114 if [ -n "${nullseq}" ]; then
115 echo "ERROR: State file is not encrypted with" \
116 "parameters '${params}'"
117 fi
118 else
119 if [ -z "${nullseq}" ]; then
120 echo "ERROR: State must not be encrypted with" \
121 "parameters '${params}'"
122 fi
123 fi
124
125 echo "SUCCESS with parameters '${params}'."
126 done
127
128 exec 100>&-
129 exec 101>&-
130
131 exit 0