aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2020-05-10 09:32:38 -0700
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2020-05-10 09:32:38 -0700
commit012ddc496ca6731af0a4018ca6ec9e18d670a4aa (patch)
tree00d0566081ff5bfe260a1849ae957ee627f8cc61
parent8cbccaf4088b6883601fa87164cb2fff78a1f24f (diff)
downloadopenssl_tpm2_engine-012ddc496ca6731af0a4018ca6ec9e18d670a4aa.tar.gz
Allow use of swtpm for testing
In addition to tpm_server there's another tpm emulator called swtpm. Avoid forcing distributions to support both by adjusting the test suite to run with either emulator and detecting in configure which can be used. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--configure.ac17
-rw-r--r--tests/Makefile.am14
-rwxr-xr-xtests/start_sw_tpm.sh19
3 files changed, 37 insertions, 13 deletions
diff --git a/configure.ac b/configure.ac
index f40b68f..5520de5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,22 +103,35 @@ AC_CHECK_HEADER([tss2/tss.h],[AC_DEFINE(TSS_INCLUDE,tss2)],
AC_MSG_ERROR([No TSS2 include directory found])))
AC_PATH_PROG(TPMSERVER, tpm_server,,/bin:/usr/bin:/usr/lib/ibmtss:/usr/libexec/ibmtss)
+AC_PATH_PROG(SWTPM, swtpm,,/bin:/usr/bin:/usr/lib/ibmtss:/usr/libexec/ibmtss)
+AC_PATH_PROG(SWTPM_IOCTL, swtpm_ioctl,,/bin:/usr/bin:/usr/lib/ibmtss:/usr/libexec/ibmtss)
CFLAGS="$CFLAGS -Wall"
SHREXT=$shrext_cmds
AC_SUBST(CFLAGS)
AC_SUBST(TSS_INCLUDE)
AC_SUBST(SHREXT)
+if test -x "${SWTPM}" -a -x "${SWTPM_IOCTL}"; then
+ testtpm=swtpm
+ unset TPMSERVER
+elif test -x "${TPMSERVER}"; then
+ testtpm=tpm_server
+else
+ testtpm=
+fi
+
+AC_SUBST(testtpm)
+
AC_OUTPUT([Makefile tests/Makefile])
cat <<EOF
CFLAGS: ${CFLAGS}
openssl engines directory: ${enginesdir}
-swtpm for testing: ${TPMSERVER}
+swtpm for testing: ${testtpm}
EOF
-if test -z "${TPMSERVER}"; then
+if test -z "${testtpm}"; then
AC_MSG_WARN([Software TPM not found, engine will build but can't be tested])
fi
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9e4bf05..23f2b57 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,13 +29,15 @@ TESTS = fail_connect.sh \
fail_connect.sh: tpm_server_found
tpm_server_found:
- @if [ -z "$(TPMSERVER)" ]; then echo "ERROR: Can't run tests, no tpm server is found"; exit 1; fi
+ @if [ -z "$(testtpm)" ]; then echo "ERROR: Can't run tests, no tpm server is found"; exit 1; fi
+
+AM_TESTS_ENVIRONMENT = TPM_INTERFACE_TYPE=socsim; export TPM_INTERFACE_TYPE; \
+ srcdir=$(abs_srcdir); export srcdir; \
+ OPENSSL_CONF=$(abs_srcdir)/openssl.cnf; export OPENSSL_CONF; \
+ TPMSERVER=$(TPMSERVER); export TPMSERVER; \
+ SWTPM=$(SWTPM); export SWTPM; \
+ SWTPM_IOCTL=$(SWTPM_IOCTL); export SWTPM_IOCTL;
-AM_TESTS_ENVIRONMENT = TPM_INTERFACE_TYPE=socsim; \
- srcdir=$(abs_srcdir); \
- OPENSSL_CONF=$(abs_srcdir)/openssl.cnf; \
- TPMSERVER=$(TPMSERVER); \
- export TPM_INTERFACE_TYPE OPENSSL_CONF srcdir TPMSERVER;
TEST_EXTENSIONS = .sh
CLEANFILES = key*.tpm key*.pub key*.priv tmp.* NVChip h*.bin key*.der seal.*
diff --git a/tests/start_sw_tpm.sh b/tests/start_sw_tpm.sh
index 93b669c..c968418 100755
--- a/tests/start_sw_tpm.sh
+++ b/tests/start_sw_tpm.sh
@@ -1,9 +1,13 @@
-if [ -z "${TPMSERVER}" -o ! -x ${TPMSERVER} ]; then
- exit 1;
-fi
+#!/bin/bash
+set -x
+
# remove any prior TPM contents
-rm -f NVChip h*.bin
+rm -f NVChip h*.bin *.permall
+if [ -x "${SWTPM}" ]; then
+${SWTPM} socket --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --tpmstate dir=`pwd` &
+else
${TPMSERVER} > /dev/null 2>&1 &
+fi
pid=$!
echo ${pid} > tpm_server.pid
##
@@ -12,11 +16,16 @@ echo ${pid} > tpm_server.pid
# store it permanently at handle 81000001 and flush the transient
##
a=0; while [ $a -lt 10 ]; do
- tsspowerup
+ if [ -x "${SWTPM_IOCTL}" ]; then
+ ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -i
+ else
+ tsspowerup
+ fi
if [ $? -eq 0 ]; then
break;
fi
sleep 1
+ a=$[$a+1]
done
if [ $a -eq 10 ]; then
echo "Waited 10s for tpm_server to come up; exiting"