]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Add tests for TPMv2 with both swtpm and hardware
authorDavid Woodhouse <dwmw2@infradead.org>
Tue, 11 May 2021 12:45:18 +0000 (13:45 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Thu, 13 May 2021 13:15:30 +0000 (14:15 +0100)
For normal builds, the auth-swtpm test runs a new swtpm with a temporary
state directory, imports a pregenerated TPM state which matches the
keys that are also pregenerated and committed to git.

As with the normal keys/certs and SoftHSM state, there are also rules
for *generating* all this, to ensure that what's committed is entirely
reproducible and serve as documentation. But those rules are mostly
dormant from this point onwards (hence my not caring about parallel
builds being broken for the swtpm startup).

There's an attempt at supporting *real* TPM testing, with a 'hwtpm'
variant. In that case the rules for generating the key/cert and for
importing the existing EC cert into the TPM are *not* dormant. But
this isn't quite working yet and is going to need to be an explicit
invocation by those who care about such things.

There are three keys tested here. Firstly the original EC key used
by all our certificate tests, imported into the TPM with the
create_tpm2_key tool from James's openssl_tpm2_engine. We cannot
import our original RSA key as it deliberately had a strange key
size, and the TPM can't cope.

Then we *generate* EC and RSA keys in the TPM too, using the
tpm2tss-genkey tool from the Intel engine. That one isn't capable
of importing existing keys yet but *is* more widely available in
distro packages.

For swtpm we use both since it's only necessary for the tools to be
present at the time we add all this. For hwtpm where users will want
to do this at build/test time, they get a subset of the keys depending
on which tools they have available.

We preserve the existing nomenclature for matching keys/certs, where
NAME-key-STORAGETYPE.pem matches with NAME-cert.pem. So the *imported*
version of our existing EC key ends up being ec-key-swtpm.pem and
ec-key-hwtpm.pem to match the existing ec-cert.pem

For the *generated* keys, we need a new 'NAME' since they are actually
new keys. So 'swtpm-ec' 'swtpm-rsa' 'hwtpm-ec' 'hwtpm-rsa' are the names
of those keys, and since they were generated in the TPM and never
existed as a file, we need a new pattern-match rule to generate the
corresponding CSR and then certificate, using the ENGINE to do so.

But we want this pattern rule *not* to match the imported keys like
ec-key-swtpm.pem, because we don't want to trigger a generation of
ec-cert.pem from the TPM when it's already right there in a file.

So we *don't* want to use 'swtpm' and 'hwtpm' as the STORAGETYPE part of
the filenames of the generated keys; we just use 'tpm' instead, and then
the pattern rule matches 'swtpm-%-key-tpm.pem' and 'hwtpm-%-key-tpm.pem'.

This doesn't yet test NV-parented keys or any kind of passwords, but
it's a start.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
12 files changed:
.gitlab-ci.yml
configure.ac
openconnect.spec.in
tests/Makefile.am
tests/auth-hwtpm [new file with mode: 0755]
tests/auth-swtpm [new file with mode: 0755]
tests/certs/ec-key-swtpm.pem [new file with mode: 0644]
tests/certs/swtpm-ec-cert.pem [new file with mode: 0644]
tests/certs/swtpm-ec-key-tpm.pem [new file with mode: 0644]
tests/certs/swtpm-rsa-cert.pem [new file with mode: 0644]
tests/certs/swtpm-rsa-key-tpm.pem [new file with mode: 0644]
tests/swtpm-perm.state [new file with mode: 0644]

index 0ea3c5cd0e4ed68703c2a725aef5e6c82cdf6cd1..909097550d5c7723b6069d4a317bbc0cb5ecb23f 100644 (file)
@@ -248,6 +248,7 @@ asan/OpenSSL/Fedora:
 
 Fedora/GnuTLS:
   script:
+  - dnf -y install swtpm swtpm-tools
   - ./autogen.sh
   - ./configure --with-java --disable-dsa-tests --without-gnutls-version-check --enable-ppp-tests CFLAGS=-g
   - make tmp-distdir
@@ -273,6 +274,7 @@ Fedora/GnuTLS:
 
 Fedora/GnuTLS/ibmtss:
   script:
+  - dnf -y install swtpm swtpm-tools
   - ./autogen.sh
   - ./configure --with-java --disable-dsa-tests --without-gnutls-version-check --enable-ppp-tests CFLAGS=-g
   - make tmp-distdir
index a41fd834d72e35f644d7e822bdb2217df8602a08..bd9dde5092062515fae0c4c2928b5c828b65d7b6 100644 (file)
@@ -704,6 +704,30 @@ esac
 AM_CONDITIONAL(OPENCONNECT_TSS2_ESYS, [ test "$tss2lib" = "tss2-esys" ])
 AM_CONDITIONAL(OPENCONNECT_TSS2_IBM, [ test "$tss2lib" = "ibmtss" -o "$tss2lib" = "tss" ])
 
+AC_PATH_PROG(SWTPM, swtpm)
+SWTPM_IOCTL=""
+if test "$SWTPM" != ""; then
+    AC_PATH_PROG(SWTPM_IOCTL, swtpm_ioctl)
+fi
+
+# The Intel/TCG TSS can only *create* keys
+AC_PATH_PROG(TPM2TSS_GENKEY, tpm2tss-genkey)
+# James's one can import them too.
+AC_PATH_PROG(CREATE_TPM2_KEY, create_tpm2_key)
+
+AC_ARG_ENABLE([hwtpm-test],
+       AS_HELP_STRING([--enable-hwtpm-test], [Test TPM support using real TPMv2 [default=no]]),
+       [test_hwtpm=$enableval], [test_hwtpm=no])
+
+if test "$test_hwtpm" = "yes" -a "$TPM2TSS_GENKEY$CREATE_TPM2_KEY" = ""; then
+   AC_MSG_ERROR([Hardware TPM test requires tpm2tss-genkey and/or create_tpm2_key tools])
+fi
+
+AM_CONDITIONAL(TEST_HWTPM, [ test "$test_hwtpm" = "yes" ])
+AM_CONDITIONAL(TEST_SWTPM, [ test "$SWTPM_IOCTL" != "" ])
+AM_CONDITIONAL(TEST_TPM2_IMPORT, [ test "$TPM2TSS_GENKEY" != "" ])
+AM_CONDITIONAL(TEST_TPM2_CREATE, [ test "$CREATE_TPM2_KEY" != "" ])
+
 test_pkcs11=
 if test "$pkcs11_support" != ""; then
    AC_CHECK_PROG(test_pkcs11, softhsm2-util, yes)
index 1b654aa5facef16ae5760f64c332378410755cba..8264dcd8d5369400b89d4b30eb10ba8220c74c83 100644 (file)
@@ -81,7 +81,7 @@ BuildRequires:  pkgconfig(stoken) pkgconfig(libpskc)
 %endif
 %if %{use_tss2_esys}
 # https://bugzilla.redhat.com/show_bug.cgi?id=1638961
-BuildRequires: pkgconfig(tss2-esys) libgcrypt-devel
+BuildRequires: pkgconfig(tss2-esys) pkgconfig(tss2-tctildr) pkgconfig(tss2-mu) libgcrypt-devel swtpm
 %endif
 
 %description
index 52dcc1256abc834b8a72410ab7790aaaf45a2d14..ec9b515108e271512965d34c54e206f6d2554b78 100644 (file)
@@ -35,11 +35,29 @@ USER_KEYS += $(certsdir)/ec-key-pkcs1.pem $(certsdir)/ec-key-pkcs1.der \
        $(certsdir)/ec-key-pkcs8-pbes2-sha1.pem $(certsdir)/ec-key-pkcs8-pbes2-sha1.der \
        $(certsdir)/ec-key-aes256-cbc-sha256.p12
 
+SWTPM_KEYS = $(certsdir)/ec-key-swtpm.pem $(certsdir)/swtpm-ec-key-tpm.pem $(certsdir)/swtpm-rsa-key-tpm.pem
+SWTPM_CERTS = $(certsdir)/swtpm-ec-cert.pem $(certsdir)/swtpm-rsa-cert.pem
+
+HWTPM_KEYS =
+HWTPM_CERTS =
+
+# Importing the existing EC key (not DSA since it's ancient and not RSA because
+# the TPM probably can't cope with 2432-bit keys).
+if TEST_TPM2_IMPORT
+HWTPM_KEYS += ec-key-hwtpm.pem
+endif
+
+# Creating new keys in TPM.
+if TEST_TPM2_CREATE
+HWTPM_KEYS += hwtpm-ec-key-tpm.pem hwtpm-rsa-key-tpm.pem
+HWTPM_CERTS += hwtpm-ec-cert.pem hwtpm-rsa-cert.pem
+endif
+
 USER_CERTS = $(certsdir)/user-cert.pem $(certsdir)/dsa-cert.pem $(certsdir)/ec-cert.pem
 
 EXTRA_DIST = certs/ca.pem certs/ca-key.pem certs/user-cert.pem $(USER_KEYS) $(USER_CERTS) \
        $(OSSL_KEYS) $(DSA_KEYS) $(certsdir)/user-key-nonascii-password.p12 \
-       pass-UTF-8 pass-ISO8859-2 \
+       pass-UTF-8 pass-ISO8859-2 $(SWTPM_KEYS) $(SWTPM_CERTS) swtpm-perm.state \
        certs/server-cert.pem certs/server-key.pem configs/test1.passwd \
        common.sh configs/test-user-cert.config configs/test-user-pass.config \
        configs/test-obsolete-server-crypto.config \
@@ -50,28 +68,46 @@ EXTRA_DIST = certs/ca.pem certs/ca-key.pem certs/user-cert.pem $(USER_KEYS) $(US
        fake-juniper-sso-server.py fake-tncc.py fake-gp-server.py
 
 dist_check_SCRIPTS = autocompletion
+TESTS = autocompletion
 
-if HAVE_NETNS
 dist_check_SCRIPTS += dtls-psk sigterm
+if HAVE_NETNS
+TESTS += dtls-psk sigterm
 endif
 
-if TEST_PPP
 dist_check_SCRIPTS += ppp-over-tls
+if TEST_PPP
+TESTS += ppp-over-tls
 endif
 
+dist_check_SCRIPTS += auth-username-pass auth-certificate auth-nonascii cert-fingerprint \
+       id-test obsolete-server-crypto pfs auth-swtpm auth-hwtpm fortinet-auth-and-config \
+       f5-auth-and-config juniper-auth juniper-sso-auth gp-auth-and-config auth-pkcs11
+
 if HAVE_CWRAP
-dist_check_SCRIPTS += auth-username-pass auth-certificate auth-nonascii cert-fingerprint id-test obsolete-server-crypto pfs
+TESTS += auth-username-pass auth-certificate auth-nonascii cert-fingerprint id-test \
+       obsolete-server-crypto pfs
+
+if TEST_SWTPM
+TESTS += auth-swtpm
+# The rules for swtpm-perm.state are not invoked during normal builds since
+# the files are already present in git.
+auth-swtpm: swtpm-perm.state
+endif
+
+if TEST_HWTPM
+# This is only invoked *manually* with 'make TESTS=auth-hwtpm check'.
+TESTS += auth-hwtpm
+# These files are generated locally against the real TPM.
+auth-hwtpm: $(HWTPM_CERTS) $(HWTPM_KEYS)
+endif
 
 if HAVE_PYTHON36_FLASK
-dist_check_SCRIPTS += fortinet-auth-and-config
-dist_check_SCRIPTS += f5-auth-and-config
-dist_check_SCRIPTS += juniper-auth
-dist_check_SCRIPTS += juniper-sso-auth
-dist_check_SCRIPTS += gp-auth-and-config
+TESTS += fortinet-auth-and-config f5-auth-and-config juniper-auth juniper-sso-auth gp-auth-and-config
 endif
 
 if TEST_PKCS11
-dist_check_SCRIPTS += auth-pkcs11
+TESTS += auth-pkcs11
 
 PKCS11_TOKENS = openconnect-test openconnect-test1
 
@@ -95,6 +131,10 @@ endif # HAVE_CWRAP
 TESTS_ENVIRONMENT = srcdir="$(srcdir)" \
        top_builddir="$(top_builddir)" \
        key_list="$(USER_KEYS)" \
+       swtpm_list="$(SWTPM_KEYS)" \
+       hwtpm_list="$(HWTPM_KEYS)" \
+       SWTPM="$(SWTPM)" \
+       SWTPM_IOCTL="$(SWTPM_IOCTL)" \
        pkcs11_keys="$(PKCS11_KEYS)" \
        pkcs11_tokens="$(PKCS11_TOKENS)" \
        EXEEXT=$(EXEEXT) \
@@ -117,7 +157,7 @@ XFAIL_TESTS = bad_dtls_test
 endif
 endif
 
-TESTS = $(dist_check_SCRIPTS) $(C_TESTS)
+TESTS += $(C_TESTS)
 
 noinst_PROGRAMS = $(C_TESTS) serverhash
 
@@ -130,7 +170,6 @@ serverhash_LDADD = ../libopenconnect.la $(SSL_LIBS)
 
 keyfiles: $(USER_KEYS) $(USER_CERTS) $(certsdir)/server-cert.pem
 
-
 OPENSSL = openssl
 OSSLARGS = -in $< -out $@ -passout pass:password
 OSSLARGSP12 = -inkey $< -out $@ -in $${KEYFILE%-key-pkcs8.pem}-cert.pem -passout pass:$${PASSWORD%-password}
@@ -210,6 +249,84 @@ $(certsdir)/server-cert.pem:
                -extfile $(srcdir)/configs/server-cert.prm -extensions req_EXT \
                -set_serial $(shell date +%s) -req -out $@ -in $@.csr
 
+# Like most of the rules to generate keys/certs, the swtpm rules are
+# dormant for most builds; they were used once to generate the state
+# which is committed to git and used thereafter (just like the cert
+# files and the SoftHSM state). The rules here are to ensure that
+# what gets committed was reproducible, and to document how it was
+# created. So for swtpm, we need to:
+#
+#   • Start a new swtpm
+#   • Import/create the keys
+#   • Generate CSRs from the created keys
+#   • Extract the swtpm state to 'swtpm-perm.state'
+#   • Shut down the swtpm
+#
+# These rules attempt to do that, keeping variants of the existing
+# CSR/cert generation rules for the middle parts.
+
+SWTPM_TMPDIR := $(shell echo swtpm.$$$$.tmp)
+SWTPM_PRELOAD := LD_PRELOAD=libsocket_wrapper.so SOCKET_WRAPPER_DIR=$(SWTPM_TMPDIR) \
+       TPM_INTERFACE_TYPE=socsim TPM2TSSENGINE_TCTI=swtpm
+
+SWTPM_IOCTL_RUN = $(SWTPM_PRELOAD) $(SWTPM_IOCTL) --tcp 127.0.0.1:2322
+
+# This isn't safe for parallel builds, as it is invoked in mulltiple
+# places and has an obvious race condition.  However, this is only for
+# the one-time setup of the persistent swtpm state, and I can remember
+# not to use 'make -j' that one time. Fixing it to be a proper
+# separate 'tpm-started' phony rule without *always* having that rule
+# executed even when the certs/keys already exist is beyond me today.
+START_SWTPM := \
+       mkdir -p $(SWTPM_TMPDIR); \
+       if ! $(SWTPM_IOCTL_RUN) -g; then \
+               $(SWTPM_PRELOAD) $(SWTPM) socket --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 \
+                       --tpmstate dir=`pwd`/$(SWTPM_TMPDIR) --flags not-need-init,startup-clear -d; \
+       fi
+
+swtpm-perm.state: $(SWTPM_KEYS) $(SWTPM_CERTS)
+       $(SWTPM_IOCTL_RUN) --save permanent $@
+       $(SWTPM_IOCTL_RUN) -s
+       rm -rf $(SWTPM_TMPDIR)
+
+# This is an *import* of the normal ec key, hence having same prefix 'ec-'.
+# Separate fileames for swtpm (which is shipped with OpenConnect sources)
+# vs local real TPM. Like many of the key/cert rules here, the swtpm rule
+# is dormant and should never really be invoked for normal users once the
+# files are committed to git. Which is why it doesn't matter that it needs
+# the swtpm to have been started manually.
+
+$(certsdir)/ec-key-swtpm.pem: certs/ec-key-pkcs8.pem
+       $(START_SWTPM)
+       $(SWTPM_PRELOAD) $(CREATE_TPM2_KEY) -w $< $@
+
+ec-key-hwtpm.pem: certs/ec-key-pkcs8.pem
+       TPM_INTERFACE_TYPE=dev $(CREATE_TPM2_KEY) -w $< $@
+
+# These are *different* keys generated inside the TPM, hence a different prefix.
+$(certsdir)/swtpm-ec-key-tpm.pem:
+       $(START_SWTPM)
+       $(SWTPM_PRELOAD) $(TPM2TSS_GENKEY) -t swtpm -a ecdsa $@
+
+hwtpm-ec-key-tpm.pem:
+       $(TPM2TSS_GENKEY) -t device -a ecdsa $@
+
+$(certsdir)/swtpm-rsa-key-tpm.pem:
+       $(START_SWTPM)
+       $(SWTPM_PRELOAD) $(TPM2TSS_GENKEY) -t swtpm -a rsa -s 2048 $@
+
+hwtpm-rsa-key-tpm.pem:
+       $(TPM2TSS_GENKEY) -t device -a rsa -s 2048 $@
+
+$(certsdir)/swtpm-%-cert.csr: $(certsdir)/swtpm-%-key-tpm.pem
+       $(SWTPM_PRELOAD) $(OPENSSL) req -new -config $(srcdir)/configs/user-cert.prm -engine tpm2tss -keyform ENGINE -key $< -out $@
+
+hwtpm-%-cert.csr: hwtpm-%-key-tpm.pem
+       TPM2TSSENGINE_TCTI=device $(OPENSSL) req -new -config $(srcdir)/configs/user-cert.prm -engine tpm2tss -keyform ENGINE -key $< -out $@
+
+%-cert.csr: %-key-hwtpm.pem
+       TPM2TSSENGINE_TCTI=device $(OPENSSL) req -new -config $(srcdir)/configs/user-cert.prm -engine tpm2tss -keyform ENGINE -key $< -out $@
+
 %-cert.csr: %-key-pkcs8.pem
        $(OPENSSL) req -new -config $(srcdir)/configs/user-cert.prm -key $< -out $@
 
diff --git a/tests/auth-hwtpm b/tests/auth-hwtpm
new file mode 100755 (executable)
index 0000000..bc30b60
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Copyright (C) 2016 Red Hat, Inc.
+#
+# This file is part of openconnect.
+#
+# This is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>
+
+# This test uses LD_PRELOAD
+PRELOAD=1
+SERV="${SERV:-../src/ocserv}"
+srcdir=${srcdir:-.}
+top_builddir=${top_builddir:-..}
+
+. `dirname $0`/common.sh
+
+hwtpm_list=${hwtpm_list:-`echo ${certdir}/swtpm*-key-tpm.pem`}
+
+echo "Testing TPMv2 auth with hwtpm... "
+
+launch_simple_sr_server -d 1 -f -c configs/test-user-cert.config
+PID=$!
+wait_server $PID
+
+export TPM_INTERFACE_TYPE=dev
+
+for KEY in ${hwtpm_list}; do
+    echo -n "Connecting to obtain cookie (with key ${KEY##*/})... "
+    if [ "${KEY%%.p12}" != "${KEY}" ]; then
+       CERTARGS="-c ${KEY} --key-password password"
+    else
+       CERT="${KEY%-key-*.pem}-cert.pem"
+       if [ ! -r "$CERT" ]; then CERT="${certdir}/$CERT"; fi
+       CERTARGS="--sslkey ${KEY} -c ${CERT}"
+    fi
+    if ! echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test $CERTARGS --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly -vvvvv --passwd-on-stdin; then
+       fail $PID "Could not connect with key ${KEY##*/}!"
+    fi
+done
+
+echo ok
+
+cleanup
+
+exit 0
diff --git a/tests/auth-swtpm b/tests/auth-swtpm
new file mode 100755 (executable)
index 0000000..5508cd3
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/sh
+#
+# Copyright (C) 2016 Red Hat, Inc.
+#
+# This file is part of openconnect.
+#
+# This is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>
+
+# This test uses LD_PRELOAD
+PRELOAD=1
+SERV="${SERV:-../src/ocserv}"
+srcdir=${srcdir:-.}
+top_builddir=${top_builddir:-..}
+
+. `dirname $0`/common.sh
+
+swtpm_list=${swtpm_list:-`echo ${certdir}/swtpm*-key-tpm.pem`}
+
+echo "Testing TPMv2 auth with swtpm... "
+
+launch_simple_sr_server -d 1 -f -c configs/test-user-cert.config
+PID=$!
+wait_server $PID
+
+${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s || :
+# Kill the existing swtpm if it was started to create keys.
+${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s || :
+
+set -x
+mkdir -p ${SOCKDIR}/swtpm
+LD_PRELOAD=libsocket_wrapper.so ${SWTPM} socket --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --tpmstate dir=`pwd`/${SOCKDIR}/swtpm --log file=swtpm-log -d
+
+sleep 0.5
+LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 --load permanent ${srcdir}/swtpm-perm.state
+LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -i
+
+export TPM_INTERFACE_TYPE=socsim
+
+# We don't actually *require* either of the startup tools
+# to be present; we can fall back to killing swtpm and then
+# restarting it with the startup-clear option. Sadly, there
+# isn't a way for swtpm_ioctl to start it once swtpm is
+# running.
+#
+# We are also inconsistent: the Esys build will automatically
+# start the TPM while the IBM TSS build won't. I'd "fix" that
+# to make the tests work, but I actually think *not* doing so
+# is probably correct.
+if ! tsstartup && ! tpm2_startup -T swtpm -c; then
+    LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s
+    LD_PRELOAD=libsocket_wrapper.so ${SWTPM} socket --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --tpmstate dir=`pwd`/${SOCKDIR}/swtpm --log file=swtpm-log --flags not-need-init,startup-clear -d
+fi
+
+for KEY in ${swtpm_list}; do
+    echo -n "Connecting to obtain cookie (with key ${KEY##*/})... "
+    if [ "${KEY%%.p12}" != "${KEY}" ]; then
+       CERTARGS="-c ${KEY} --key-password password"
+    else
+       CERT="${KEY%-key-*.pem}-cert.pem"
+       if [ ! -r "$CERT" ]; then CERT="${certdir}/$CERT"; fi
+       CERTARGS="--sslkey ${KEY} -c ${CERT}"
+    fi
+    if ! echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test $CERTARGS --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly -vvvvv --passwd-on-stdin; then
+       LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s
+       fail $PID "Could not connect with key ${KEY##*/}!"
+    fi
+done
+
+echo ok
+
+LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s
+cleanup
+
+exit 0
diff --git a/tests/certs/ec-key-swtpm.pem b/tests/certs/ec-key-swtpm.pem
new file mode 100644 (file)
index 0000000..23db88c
--- /dev/null
@@ -0,0 +1,8 @@
+-----BEGIN TSS2 PRIVATE KEY-----
+MIHwBgZngQUKAQOgAwEBAQIEQAAAAQRYAFYAIwALAAYEQAAAABAAEAADABAAIE9y
+KoT7BbaJWUAVNwFMWirti5lwdNXhIB3GfBJjMWJjACAXccQXp5uGkTzg9kHgHE3g
+iqjmg5iCRKUbnSxLhsGlVASBgAB+ACBDbqTReH27klFD/gporN7JWZZi4ykoyGP8
+peloe3h60QAQFLD7X7y6Bl+njwjNYaAMje1tnAsnxe5fyeZaVnbn1nda+l9IjqdH
+vbXnnsc/R2GyKGVt7YDueE+5VbLm2LSrlcCzR2Ufdhg4Z/7YISZxsWOgWH5cEwwc
+n2Dz
+-----END TSS2 PRIVATE KEY-----
diff --git a/tests/certs/swtpm-ec-cert.pem b/tests/certs/swtpm-ec-cert.pem
new file mode 100644 (file)
index 0000000..1cdbdd5
--- /dev/null
@@ -0,0 +1,14 @@
+-----BEGIN CERTIFICATE-----
+MIICDzCByAIEYJztrjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQDEwJDQTAeFw0y
+MTA1MTMwOTEzMThaFw0zMTA1MTEwOTEzMThaMCcxDzANBgNVBAMMBkEgdXNlcjEU
+MBIGCgmSJomT8ixkAQEMBHRlc3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASP
+6eEgMFsfnhlAnYU1ANhL5at43wNxNipinJAkOJQWGdlNDUSmS3dpT/qqloGyMYZQ
+UFWwpKyl5IsQuPsb04DMMA0GCSqGSIb3DQEBCwUAA4IBMQA2eJkcGHu1VWWX1I9g
+gcHeNEXf23OhRMvVlG7VBz5bFZocPT/82tp8qpQO62k/nJ7j2yAi+nC1s/dk4X7S
+ajqixNrznprf91ymV1XHZgUKE9OkSn4sav7WnERA2UMoFapqhHw6uuPYMRkMLHoa
+Yjz+CWGtqASqn5+xd0k9GDQ0yaxAIM5sFmlhfwu5QdQOhIu1XzW/2WTh2X/GVHhs
+7g5/e7PvXmKc16KQWECS59gN+T+xP3YbCSPIgB5A1KtIaR+LvPXPhZI73CBHBNjY
+cYzU7/P5tCf87gla98CxKgy6uEwNd7f08/ZbKRAxtTY+SQbFKr3s1IS7fmA7rSEy
+VmPq/XDdKncUQf5G5rj/auYYk7BaFyT7uwH6j8YIxkhES9gSkno6BBBe6+0UcbMF
+ir7O
+-----END CERTIFICATE-----
diff --git a/tests/certs/swtpm-ec-key-tpm.pem b/tests/certs/swtpm-ec-key-tpm.pem
new file mode 100644 (file)
index 0000000..88e001e
--- /dev/null
@@ -0,0 +1,8 @@
+-----BEGIN TSS2 PRIVATE KEY-----
+MIHwBgZngQUKAQOgAwEBAQIEQAAAAQRYAFYAIwALAAQEcgAAABAAEAADABAAII/p
+4SAwWx+eGUCdhTUA2Evlq3jfA3E2KmKckCQ4lBYZACDZTQ1Epkt3aU/6qpaBsjGG
+UFBVsKSspeSLELj7G9OAzASBgAB+ACBs2ddMRL2ubUQ9AU+7eEDc1NqhRla3cN1T
+HdZ6OuXPWAAQVkmj9i+7SbwNXUEucdN8W7+2jBhFRbMuZbgrPLBWqp9rYaXMkoZx
+FFfvTI27aM6jrs3OILqmpzDJDmi1xLDF5jjIsL+mpY96RWqFQFG32X5CyRTqFno/
+T6LU
+-----END TSS2 PRIVATE KEY-----
diff --git a/tests/certs/swtpm-rsa-cert.pem b/tests/certs/swtpm-rsa-cert.pem
new file mode 100644 (file)
index 0000000..b6b2f4d
--- /dev/null
@@ -0,0 +1,18 @@
+-----BEGIN CERTIFICATE-----
+MIIC2zCCAZMCBGCc7a4wDQYJKoZIhvcNAQELBQAwDTELMAkGA1UEAxMCQ0EwHhcN
+MjEwNTEzMDkxMzE4WhcNMzEwNTExMDkxMzE4WjAnMQ8wDQYDVQQDDAZBIHVzZXIx
+FDASBgoJkiaJk/IsZAEBDAR0ZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEApUmzK/M0T5YwryIcmAT4ImqdCc4e1Pa8nViGPaT47VakpAqryCYawQrz
+mDXMsHeKP8+4mRCfNaAGdl6xdZcWVZLhTuDtJepk8p8WsHl4BwXqMH9gzLoKmSr+
+JvSvi7gUnOsG2DBPFAfbfNiBrpMbkplz09VSjq/goyLOm/qV9KFPQ7+eJXixkDyA
+0EndVULujOK/a+EaemXNiH+Ya99ezVg4OBRTFy/z1afhJqRU+XL4kTlHJ8CTmSET
+gT+b/IP1PU7kj58+InL8YUEdE9Ec6zIiuAUTfmQtQFKuFUGmalnXJ+/h17oc3QOx
+/5P3lFmzIOCZyG6jCCYuanl/q/XFiwIDAQABMA0GCSqGSIb3DQEBCwUAA4IBMQA+
+ocITQqinZT4txBGfoV88jwyuwC6+w/FaKB15XxiJPLn85HG31ImRiTxAyCHFr6fh
+p8nHHQ/gj3Sj2WNaY1aQGRGYpj662Vpmyu+zvfOVh+4WpwGssRE7dvW9xmlWbZac
+JS9PMUoArD4J3wOTomREzpKmeUBOwhUjuXGbhYGEGnU7Y5L3Q3p0d2aUTDD0ivQF
+JpxQ5WRhthTg0MG7W8alPrSStMEfDqY1Zqc2gFmTmJMwCtT26PeSvrLOQ7LanZyH
+k6Zwrjl2niSXLQLDCxRlKvGnJbeIxQgjt7MWmVS/uFjPdxBqrfd/meHDWLQ034xP
+xYODVB65GR124mnmXSAQ1ZDbtmdiGCAPknxZMEEJOIG4MZMWHv8s+GhjIEL0sdls
+yT6FGwsnS86mEKqWSakQ
+-----END CERTIFICATE-----
diff --git a/tests/certs/swtpm-rsa-key-tpm.pem b/tests/certs/swtpm-rsa-key-tpm.pem
new file mode 100644 (file)
index 0000000..f98f415
--- /dev/null
@@ -0,0 +1,14 @@
+-----BEGIN TSS2 PRIVATE KEY-----
+MIICEgYGZ4EFCgEDoAMBAQECBEAAAAEEggEYARYAAQALAAYEcgAAABAAEAgAAAEA
+AQEApUmzK/M0T5YwryIcmAT4ImqdCc4e1Pa8nViGPaT47VakpAqryCYawQrzmDXM
+sHeKP8+4mRCfNaAGdl6xdZcWVZLhTuDtJepk8p8WsHl4BwXqMH9gzLoKmSr+JvSv
+i7gUnOsG2DBPFAfbfNiBrpMbkplz09VSjq/goyLOm/qV9KFPQ7+eJXixkDyA0End
+VULujOK/a+EaemXNiH+Ya99ezVg4OBRTFy/z1afhJqRU+XL4kTlHJ8CTmSETgT+b
+/IP1PU7kj58+InL8YUEdE9Ec6zIiuAUTfmQtQFKuFUGmalnXJ+/h17oc3QOx/5P3
+lFmzIOCZyG6jCCYuanl/q/XFiwSB4ADeACAO56q5UqHwIYgX3NmlwrBg+fR6rmMX
+Qgtm6sZELotUWAAQGdacZ62VnbNH9ZCruwpqB4103/4mktXfzXRYRrZVScvAIRWa
+g13qIeiYvTvNkWyiV9XFtboICznnq+9GUi7XI+OXYdYdd2q/D2KbwuR1Gh5apWid
+0ZGSaZb7bkur3puCODhYODW44s70BpZBR+RgaxUsEiCFrcap4jhCWnEjBFCr923Q
+QTGWmLG9NkQb7+Uz7o68CIpXcU6EHKhAOmg3EP3rfaf/kMZE1U71/jHj6qwiTfvh
+vsVC8p3d
+-----END TSS2 PRIVATE KEY-----
diff --git a/tests/swtpm-perm.state b/tests/swtpm-perm.state
new file mode 100644 (file)
index 0000000..b2104d2
Binary files /dev/null and b/tests/swtpm-perm.state differ