[pkg-opensc-commit] [libp11] 204/239: Added minimal test suite
Eric Dorland
eric at moszumanska.debian.org
Sat Oct 17 06:21:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit c9e923977305e80c2870daeabde6856ca5cb2ab6
Author: Nikos Mavrogiannopoulos <nmav at redhat.com>
Date: Thu Jul 2 12:27:30 2015 +0200
Added minimal test suite
That is based on the presence of pkcs11-tool (opensc) and softhsm.
---
Makefile.am | 6 +--
configure.ac | 4 +-
examples/Makefile | 7 ----
examples/Makefile.am | 9 ++++
tests/Makefile.am | 23 ++++++++++
tests/cert.der | Bin 0 -> 805 bytes
tests/key.der | Bin 0 -> 1191 bytes
tests/testpkcs11.softhsm | 107 +++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 145 insertions(+), 11 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index c1b7a5a..d264e5b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,11 +14,11 @@ MAINTAINERCLEANFILES = \
$(srcdir)/packaged
EXTRA_DIST = .gitignore Makefile.mak winconfig.h
-dist_noinst_DATA = COPYING bootstrap \
- $(srcdir)/examples/Makefile $(srcdir)/examples/*.c $(srcdir)/examples/README
+dist_noinst_DATA = COPYING bootstrap
+
dist_doc_DATA = NEWS
-SUBDIRS = src doc
+SUBDIRS = src doc tests examples
# Allow detection of packaged tarball
dist-hook:
diff --git a/configure.ac b/configure.ac
index 00b068f..7a0a2e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,7 @@ AC_INIT([libp11],[PACKAGE_VERSION_MAJOR.PACKAGE_VERSION_MINOR.PACKAGE_VERSION_FI
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
-AM_INIT_AUTOMAKE
+AM_INIT_AUTOMAKE([subdir-objects])
LIBP11_VERSION_MAJOR="PACKAGE_VERSION_MAJOR"
LIBP11_VERSION_MINOR="PACKAGE_VERSION_MINOR"
@@ -191,6 +191,8 @@ AC_CONFIG_FILES([
src/versioninfo.rc
doc/Makefile
doc/doxygen.conf
+ examples/Makefile
+ tests/Makefile
])
AC_OUTPUT
diff --git a/examples/Makefile b/examples/Makefile
deleted file mode 100644
index a412990..0000000
--- a/examples/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-CFLAGS=-O2 -g $(shell pkg-config --cflags libp11) $(shell pkg-config --cflags libcrypto)
-LDFLAGS=$(shell pkg-config --libs libp11) $(shell pkg-config --libs libcrypto)
-
-all: auth decrypt getrandom
-
-clean:
- rm auth decrypt getrandom
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..ae87454
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,9 @@
+AM_CFLAGS = $(OPENSSL_CFLAGS)
+AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir)/src \
+ -I$(top_builddir)/
+
+EXTRA_DIST = README
+
+noinst_PROGRAMS = auth decrypt getrandom
+
+LDADD = ../src/libp11.la
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..376907e
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,23 @@
+EXTRA_DIST = cert.der key.der
+
+AM_CFLAGS = $(OPENSSL_CFLAGS)
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/ \
+ -I$(top_builddir)/
+
+AM_LDFLAGS = -no-install
+LDADD = ../src/libp11.la $(OPENSSL_LIBS)
+
+auth_SOURCES = ../examples/auth.c
+
+check_PROGRAMS = auth
+dist_check_SCRIPTS = testpkcs11.softhsm
+
+TESTS = $(dist_check_SCRIPTS)
+
+TESTS_ENVIRONMENT = \
+ LC_ALL="C" \
+ EXEEXT=$(EXEEXT) \
+ top_builddir="$(top_builddir)" \
+ srcdir="$(srcdir)"
+
diff --git a/tests/cert.der b/tests/cert.der
new file mode 100644
index 0000000..dee34e1
Binary files /dev/null and b/tests/cert.der differ
diff --git a/tests/key.der b/tests/key.der
new file mode 100644
index 0000000..b96d3f8
Binary files /dev/null and b/tests/key.der differ
diff --git a/tests/testpkcs11.softhsm b/tests/testpkcs11.softhsm
new file mode 100755
index 0000000..45e1174
--- /dev/null
+++ b/tests/testpkcs11.softhsm
@@ -0,0 +1,107 @@
+#!/bin/sh
+
+# Copyright (C) 2013 Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# GnuTLS is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GnuTLS 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GnuTLS; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+outdir="${top_builddir:-./output}"
+file_dir="${srcdir:-./}"
+
+mkdir -p $outdir
+
+if test -f /usr/lib64/pkcs11/libsofthsm2.so; then
+ ADDITIONAL_PARAM="/usr/lib64/pkcs11/libsofthsm2.so"
+else
+ if test -f /usr/lib/softhsm/libsofthsm.so; then
+ ADDITIONAL_PARAM="/usr/lib/softhsm/libsofthsm.so"
+ else
+ ADDITIONAL_PARAM="/usr/lib64/softhsm/libsofthsm.so"
+ fi
+fi
+
+if ! test -x /usr/bin/pkcs11-tool;then
+ exit 77
+fi
+
+init_card () {
+ PIN="$1"
+ PUK="$2"
+
+ if test -x "/usr/bin/softhsm2-util"; then
+ export SOFTHSM2_CONF="$outdir/softhsm-testpkcs11.config"
+ SOFTHSM_TOOL="/usr/bin/softhsm2-util"
+ fi
+
+ if test -x "/usr/bin/softhsm"; then
+ export SOFTHSM_CONF="$outdir/softhsm-testpkcs11.config"
+ SOFTHSM_TOOL="/usr/bin/softhsm"
+ fi
+
+ if test -z "${SOFTHSM_TOOL}"; then
+ echo "Could not find softhsm(2) tool"
+ exit 77
+ fi
+
+ if test -z "${SOFTHSM_CONF}"; then
+ rm -rf $outdir/softhsm-testpkcs11.db
+ mkdir -p $outdir/softhsm-testpkcs11.db
+ echo "objectstore.backend = file" > "${SOFTHSM2_CONF}"
+ echo "directories.tokendir = $outdir/softhsm-testpkcs11.db" >> "${SOFTHSM2_CONF}"
+ else
+ rm -rf $outdir/softhsm-testpkcs11.db
+ echo "0:$outdir/softhsm-testpkcs11.db" > "${SOFTHSM_CONF}"
+ fi
+
+
+ echo -n "* Initializing smart card... "
+ ${SOFTHSM_TOOL} --init-token --slot 0 --label "libp11-test" --so-pin "${PUK}" --pin "${PIN}" >/dev/null
+ if test $? = 0; then
+ echo ok
+ else
+ echo failed
+ exit 1
+ fi
+}
+
+PIN=1234
+PUK=1234
+init_card $PIN $PUK
+
+# generate key in token
+pkcs11-tool -p $PIN --module $ADDITIONAL_PARAM -d 00010203 -a server-key -l -w ${file_dir}/key.der -y privkey >/dev/null
+if test $? != 0;then
+ exit 1;
+fi
+
+pkcs11-tool -p $PIN --module $ADDITIONAL_PARAM -d 00010203 -a server-key -l -w ${file_dir}/cert.der -y cert >/dev/null
+if test $? != 0;then
+ exit 1;
+fi
+
+echo "***************"
+echo "Listing objects"
+echo "***************"
+pkcs11-tool -p $PIN --module $ADDITIONAL_PARAM -l -O
+
+./auth $ADDITIONAL_PARAM $PIN
+if test $? != 0;then
+ exit 1;
+fi
+
+rm -rf $outdir
+
+exit 0
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list