summaryrefslogtreecommitdiff
path: root/tests/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Makefile')
-rw-r--r--tests/Makefile58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..9d83a7e
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,58 @@
+# Required packages (Debian 9/stretch):
+# libengine-pkcs11-openssl: /usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so
+# softhsm2: /usr/bin/softhsm2-util
+# gnutls-bin: /usr/bin/p11tool
+# openssl: /usr/bin/openssl
+
+TEXT = "A foo is a bar"
+SOFTHSM = /usr/bin/softhsm2-util
+
+SOFTHSM_PROVIDER = /usr/lib/softhsm/libsofthsm2.so
+P11P_PROVIDER = /home/linus/usr/lib/pkcs11/p11-kit-client.so
+
+p11p-softhsm: testsig.hsm.p11p.pem
+ echo "$(TEXT)" |./do-verify.sh $< $(P11P_PROVIDER) ./openssl.p11p.cnf $(SOFTHSM_PROVIDER)
+
+direct-softhsm: testsig.hsm.pem
+ echo "$(TEXT)" | ./do-verify.sh $< $(SOFTHSM_PROVIDER) ./openssl.direct.cnf
+
+softhsm-token-setup: softhsm-token-setup.stamp
+softhsm-token-setup.stamp: softhsm/tokens testkey.pkcs8
+ test -x $(SOFTHSM)
+ ( \
+ BASEDIR=$$(pwd); \
+ export SOFTHSM2_CONF=$$BASEDIR/softhsm/softhsm2.conf; \
+ echo "directories.tokendir = $$BASEDIR/softhsm/tokens/" > $$SOFTHSM2_CONF; \
+ ${SOFTHSM} --init-token --free --label mytoken --so-pin ffffff --pin ffff; \
+ ${SOFTHSM} --import testkey.pkcs8 --token mytoken --label mykey --id 00 --pin ffff; \
+ )
+ touch $@
+
+softhsm/tokens:
+ mkdir -p $@
+
+testkey.pkcs8: testkey.pem
+ openssl pkey -in $< -outform pem -out $@
+
+testkey.pem:
+ openssl genrsa -out $@ 2048
+
+testsig.local.pem: testkey.pem
+ echo "$(TEXT)" | openssl dgst -sha256 -sign testkey.pem -out $@
+
+testsig.hsm.pem: softhsm-token-setup
+ echo "$(TEXT)" | ./do-sign.sh $@ $(SOFTHSM_PROVIDER) ./openssl.direct.cnf
+
+testsig.hsm.p11p.pem: softhsm-token-setup
+ echo "$(TEXT)" | ./do-sign.sh $@ $(P11P_PROVIDER) ./openssl.p11p.cnf $(SOFTHSM_PROVIDER)
+
+server-running:
+# FIXME: use env printed to do 'p11-kit server --kill', at some point
+
+clean:
+ -rm -r softhsm
+ -rm softhsm-token-setup.stamp
+ -rm testkey.pem testkey.pkcs8
+ -rm testsig.*.pem
+
+.PHONY: clean