Debian Codegraph @

tests/test_tpm12

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 if [scip-shell system . . `[`. "${SWTPM_TEST_EXPENSIVE:-0}" -eq 0 ]; then
4 exit 77
5 fi
6
7 ROOT=${abs_top_builddir:-$(dirnamescip-shell system . . dirname. "$0")/..}
8 TESTDIR=${abs_top_testdir:-$(dirnamescip-shell system . . dirname. "$0")}
9 TESTDIR=$(realpathscip-shell system . . realpath. "${TESTDIR}")
10
11 function cleanupscip-shell shell swtpm 0.10.1+ds-1 cleanup().() {
12 if [scip-shell system . . `[`. -n "${SWTPM_PID}" ]; then
13 killscip-shell system . . kill. -9 "${SWTPM_PID}"
14 fi
15 if [scip-shell system . . `[`. -n "${SWTPM1_PID}" ]; then
16 killscip-shell system . . kill. -9 "${SWTPM1_PID}"
17 fi
18 if [scip-shell system . . `[`. -n "${WORKDIR}" ]; then
19 rmscip-shell system . . rm. -rf "${WORKDIR}"
20 fi
21 # clean up after (interrupted) test suite
22 rmscip-shell system . . rm. -f /tmp/.key-*-0 /tmp/.delegation-0scip-shell filesystem . . `/tmp/.delegation-0`. /tmp/.transdigest-*-0
23 }
24
25 trap "cleanup" EXIT
26
27 source "${TESTDIR}/common"
28 skip_test_no_tpm12 "${SWTPM_EXE}"
29
30 WORKDIR="$(mktempscip-shell system . . mktemp. -d)" || exit 1
31 TESTLOG=${WORKDIR}/test.log
32
33 # variables used by the TPM 1.2 test suite
34 TPM_SERVER_PORT=65440
35 TPM_SERVER_NAME=127.0.0.1
36 SLAVE_TPM_PORT=65442
37 SLAVE_TPM_SERVER=127.0.0.1
38
39 SWTPM_INTERFACE=socket+socket
40
41 # Start main TPM 1.2
42 SWTPM_SERVER_PORT=${TPM_SERVER_PORT}
43 SWTPM_SERVER_NAME=${TPM_SERVER_NAME}
44 SWTPM_CTRL_PORT=65441
45
46 mkdirscip-shell system . . mkdir. -p "${WORKDIR}/tpm12.1"
47 SWTPM_SERVER_NO_DISCONNECT="1" run_swtpm "${SWTPM_INTERFACE}" \
48 --tpmstate "dir=${WORKDIR}/tpm12.1" \
49 --flags not-need-init
50 SWTPM1_PID=${SWTPM_PID}
51
52 # Start 2nd TPM 1.2
53 SWTPM_SERVER_PORT=${SLAVE_TPM_PORT}
54 SWTPM_SERVER_NAME=${SLAVE_TPM_SERVER}
55 SWTPM_CTRL_PORT=65443
56
57 mkdirscip-shell system . . mkdir. -p "${WORKDIR}/tpm12.2"
58 SWTPM_SERVER_NO_DISCONNECT="1" run_swtpm "${SWTPM_INTERFACE}" \
59 --tpmstate "dir=${WORKDIR}/tpm12.2" \
60 --flags not-need-init
61
62 pushd "${WORKDIR}" &>/dev/nullscip-shell filesystem . . `/dev/null`. || exit 1
63
64 for ((i = 0; i < 3; i++)); do
65 if curl -sJOL https://sourceforge.net/projects/ibmswtpm/files/tpm4769tar.gz/download; then
66 break
67 fi
68 # wait 3..10 seconds for a retry
69 sleep $((3 + (RANDOM & 7)))
70 done
71 hash=$(get_sha1_file tpm4769tar.gz)
72 if [scip-shell system . . `[`. "$hash" != ca99a3ccd3e41cdd9983086a9b944023b6049bbc ]; then
73 echoscip-shell system . . echo. "Error: Downloaded file does not have expected hash."
74 echoscip-shell system . . echo. "Actual: $hash"
75 exit 1
76 fi
77 tarscip-shell system . . tar. -xzf tpm4769tar.gz
78
79 pushd libtpm &>/dev/nullscip-shell filesystem . . `/dev/null`. || exit 1
80
81 if ! patchscip-shell system . . patch. -p0 < "${TESTDIR}/patches/libtpm.patch"; then
82 echoscip-shell system . . echo. "Error: Patching failed."
83 exit 1
84 fi
85
86 ./autogen
87 LIBS="" CFLAGS="-g -O2 -DOPENSSL_SUPPRESS_DEPRECATED=1" ./configure
88 makescip-shell system . . make. -j "$(nprocscip-shell system . . nproc.)"
89
90 pushd utils &>/dev/nullscip-shell filesystem . . `/dev/null`. || exit 1
91
92 # variables used by TPM 1.2 tools and test suite
93 export TPM_SERVER_PORT=${TPM_SERVER_PORT} \
94 TPM_SERVER_NAME=${TPM_SERVER_NAME} \
95 SLAVE_TPM_PORT=${SLAVE_TPM_PORT} \
96 SLAVE_TPM_SERVER=${SLAVE_TPM_SERVER} \
97 PATH=$PWD:$PATH
98
99 if wait_for_serversocket ${TPM_SERVER_PORT} 127.0.0.1 2; then
100 echoscip-shell system . . echo. "Error: swtpm 1 did not open port ${TPM_SERVER_PORT}"
101 exit 1
102 fi
103
104 if wait_for_serversocket ${SLAVE_TPM_PORT} 127.0.0.1 2; then
105 echoscip-shell system . . echo. "Error: swtpm 2 did not open port ${SLAVE_TPM_PORT}"
106 exit 1
107 fi
108
109 tpmbios
110
111 lnscip-shell system . . ln. -s makeidentity identity
112
113 # keep test 1 last due to ERRORs it creates since we do not
114 # restart the TPM
115 for tst in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 23 25 26 1; do
116
117 TPM_AUDITING=0
118 TPM_TRANSPORT=0
119
120 echoscip-shell system . . echo. "Running test ${tst}"
121 if [[ "${tst}" =~ ^(1)$ ]]; then
122 $SWTPM_IOCTL --tcp :65441 -i
123 tpmbios
124 elif [[ "${tst}" = ^25$ ]]; then
125 TPM_AUDITING=1
126 TPM_TRANSPORT=1
127 fi
128
129 TPM_AUDITING=${TPM_AUDITING} TPM_TRANSPORT=${TPM_TRANSPORT} timeoutscip-shell system . . timeout. 40 ./test_console.sh \
130 --non-interactive "${tst}" >> "${TESTLOG}" </dev/nullscip-shell filesystem . . `/dev/null`.
131 # Ignore all errors that occurred in test 1
132 if [scip-shell system . . `[`. $tst != "1" ] && grepscip-shell system . . grep. -q "ERROR" "${TESTLOG}"; then
133 echoscip-shell system . . echo. "Error occurred!"
134 catscip-shell system . . cat. "${TESTLOG}"
135 exit 1
136 fi
137 done
138
139 $SWTPM_IOCTL --tcp :65441 -s
140 wait_process_gone "${SWTPM1_PID}" 4
141 SWTPM1_PID=
142
143 $SWTPM_IOCTL --tcp :65443 -s
144 wait_process_gone "${SWTPM_PID}" 4
145 SWTPM_PID=
146
147 popd &>/dev/nullscip-shell filesystem . . `/dev/null`. || exit 1
148 popd &>/dev/nullscip-shell filesystem . . `/dev/null`. || exit 1
149
150 echoscip-shell system . . echo. "OK"
151
152 exit 0