| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
if [ "${SWTPM_TEST_EXPENSIVE:-0}" -eq 0 ]; then |
| 4 |
echo "SWTPM_TEST_EXPENSIVE must be set to run this test." |
| 5 |
exit 77 |
| 6 |
fi |
| 7 |
|
| 8 |
if [ -z "$(type openssl)" ]; then |
| 9 |
echo "Openssl command line tool is required." |
| 10 |
exit 1 |
| 11 |
fi |
| 12 |
|
| 13 |
ROOT=${abs_top_builddir:-$(pwd)/..} |
| 14 |
TESTDIR=${abs_top_testdir:-$(dirname "$0")} |
| 15 |
ABSTESTDIR=$(cd "${TESTDIR}" &>/dev/null || exit 1;echo "${PWD}") |
| 16 |
|
| 17 |
PATCHESDIR=${ABSTESTDIR}/patches |
| 18 |
|
| 19 |
SWTPM_SERVER_PORT=65426 |
| 20 |
SWTPM_SERVER_NAME=127.0.0.1 |
| 21 |
SWTPM_CTRL_PORT=65427 |
| 22 |
SWTPM_INTERFACE=socket+socket |
| 23 |
|
| 24 |
function cleanup() { |
| 25 |
pid=${SWTPM_PID} |
| 26 |
if [ -n "$pid" ]; then |
| 27 |
kill_quiet -9 "$pid" |
| 28 |
fi |
| 29 |
if [ -n "${WORKDIR}" ]; then |
| 30 |
rm -rf "${WORKDIR}" |
| 31 |
fi |
| 32 |
} |
| 33 |
|
| 34 |
trap "cleanup" EXIT |
| 35 |
|
| 36 |
source "${TESTDIR}/common" |
| 37 |
skip_test_no_tpm20 "${SWTPM_EXE}" |
| 38 |
|
| 39 |
WORKDIR="$(mktemp -d)" || exit 1 |
| 40 |
|
| 41 |
REGLOG=${WORKDIR}/reglog |
| 42 |
DEFAULT_PROFILE='{"Name":"default-v1"}' |
| 43 |
|
| 44 |
SWTPM_SERVER_NO_DISCONNECT="1" run_swtpm "${SWTPM_INTERFACE}" \ |
| 45 |
--tpm2 \ |
| 46 |
--tpmstate "dir=${WORKDIR}" \ |
| 47 |
--flags not-need-init \ |
| 48 |
--profile "profile=${SWTPM_TEST_PROFILE:-${DEFAULT_PROFILE}}" |
| 49 |
|
| 50 |
revision=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" --info 1 | |
| 51 |
sed 's/.*,"revision":\([^\}]*\).*/\1/') |
| 52 |
|
| 53 |
pushd "${WORKDIR}" &>/dev/null || exit 1 |
| 54 |
|
| 55 |
function build_ibmtss2() { |
| 56 |
git clone https://git.code.sf.net/p/ibmtpm20tss/tss ibmtpm20tss-tss |
| 57 |
|
| 58 |
pushd ibmtpm20tss-tss &>/dev/null || exit 1 |
| 59 |
|
| 60 |
if ! git checkout tags/v2.4.0; then |
| 61 |
echo "'Git checkout' failed." |
| 62 |
exit 1 |
| 63 |
fi |
| 64 |
|
| 65 |
# To be able to apply the patches we need to to set some variables |
| 66 |
# for user that don't have this set up properly |
| 67 |
git config --local user.name test |
| 68 |
git config --local user.email [email protected] |
| 69 |
|
| 70 |
# Nuvoton commands are not supported |
| 71 |
git am < "${PATCHESDIR}/0012-Disable-Nuvoton-commands.patch" |
| 72 |
|
| 73 |
# A v2.0.1 bug work-around: |
| 74 |
# We cannot run the EK certificate tests since rootcerts.txt points to |
| 75 |
# files we do not have |
| 76 |
git am < "${PATCHESDIR}/0001-Deactivate-test-cases-accessing-rootcerts.txt.patch" |
| 77 |
|
| 78 |
# Implement 'powerup' for swtpm |
| 79 |
git am < "${PATCHESDIR}/0002-Implement-powerup-for-swtpm.patch" |
| 80 |
|
| 81 |
# set CRYPTOLIBRARY=openssl |
| 82 |
git am < "${PATCHESDIR}/0003-Set-CRYPTOLIBRARY-to-openssl.patch" |
| 83 |
|
| 84 |
# Store and restore volatile state at every step |
| 85 |
git am < "${PATCHESDIR}/0004-Store-and-restore-volatile-state-at-every-step.patch" |
| 86 |
|
| 87 |
# Disable 'Events' test |
| 88 |
git am < "${PATCHESDIR}/0005-Disable-tests-related-to-events.patch" |
| 89 |
|
| 90 |
if openssl version | grep -q -E "^OpenSSL 3"; then |
| 91 |
git am < "${PATCHESDIR}/0010-Adjust-test-cases-for-OpenSSL-3.patch" |
| 92 |
fi |
| 93 |
|
| 94 |
autoreconf --force --install |
| 95 |
unset CFLAGS LDFLAGS LIBS |
| 96 |
./configure --disable-tpm-1.2 |
| 97 |
make -j4 |
| 98 |
|
| 99 |
popd &>/dev/null || exit 1 |
| 100 |
} |
| 101 |
|
| 102 |
export TPM_SERVER_NAME=127.0.0.1 |
| 103 |
export TPM_INTERFACE_TYPE=socsim |
| 104 |
export TPM_COMMAND_PORT=${SWTPM_SERVER_PORT} |
| 105 |
export TPM_PLATFORM_PORT=${SWTPM_CTRL_PORT} |
| 106 |
|
| 107 |
export SWTPM_IOCTL |
| 108 |
|
| 109 |
if [ -d "$SWTPM_TEST_IBMTSS" ]; then |
| 110 |
for opt in swtpm without-ecc without-nuvoton without-events; do |
| 111 |
if ! "$SWTPM_TEST_IBMTSS"/tssreg.sh -h | grep -q "${opt}"; then |
| 112 |
echo "Cannot run test with installed IBM TSS2 test suite since it does not support the --${opt} option." |
| 113 |
exit 1 |
| 114 |
fi |
| 115 |
done |
| 116 |
|
| 117 |
# assume tss is installed with the default prefix |
| 118 |
if ! tssstartup; then |
| 119 |
echo "Startup of TPM2 failed" |
| 120 |
exit 1 |
| 121 |
fi |
| 122 |
|
| 123 |
OPENSSL_ENABLE_SHA1_SIGNATURES=1 ./reg.sh -a 2>&1 | tee "${REGLOG}" |
| 124 |
"$SWTPM_TEST_IBMTSS"/tssreg.sh \ |
| 125 |
--swtpm \ |
| 126 |
--without-ecc \ |
| 127 |
--without-nuvoton \ |
| 128 |
--without-events \ |
| 129 |
--rev "$revision" \ |
| 130 |
-a 2>&1 | tee "${REGLOG}" |
| 131 |
else |
| 132 |
build_ibmtss2 |
| 133 |
pushd ibmtpm20tss-tss/utils || exit 1 |
| 134 |
if ! ./startup; then |
| 135 |
echo "Startup of TPM2 failed" |
| 136 |
exit 1 |
| 137 |
fi |
| 138 |
|
| 139 |
OPENSSL_ENABLE_SHA1_SIGNATURES=1 ./reg.sh -a 2>&1 | tee "${REGLOG}" |
| 140 |
popd &>/dev/null || exit 1 |
| 141 |
fi |
| 142 |
|
| 143 |
ret=0 |
| 144 |
|
| 145 |
if grep -q -E "^ ERROR:" "${REGLOG}"; then |
| 146 |
echo "There were test failures running the IBM TSS 2 tests" |
| 147 |
grep -E "^ ERROR:" "${REGLOG}" -B2 -A2 |
| 148 |
ret=1 |
| 149 |
fi |
| 150 |
|
| 151 |
# Shut down |
| 152 |
if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then |
| 153 |
echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM." |
| 154 |
ret=1 |
| 155 |
fi |
| 156 |
|
| 157 |
if wait_process_gone "${SWTPM_PID}" 4; then |
| 158 |
echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore." |
| 159 |
ret=1 |
| 160 |
fi |
| 161 |
|
| 162 |
popd &>/dev/null || exit 1 |
| 163 |
|
| 164 |
[ $ret -eq 0 ] && echo "OK" |
| 165 |
|
| 166 |
exit $ret |