Blame tests/testpkcs11.softhsm

Packit Service 4684c1
#!/bin/sh
Packit Service 4684c1
Packit Service 4684c1
# Copyright (C) 2013 Nikos Mavrogiannopoulos
Packit Service 4684c1
#
Packit Service 4684c1
# This file is part of GnuTLS.
Packit Service 4684c1
#
Packit Service 4684c1
# GnuTLS is free software; you can redistribute it and/or modify it
Packit Service 4684c1
# under the terms of the GNU General Public License as published by the
Packit Service 4684c1
# Free Software Foundation; either version 3 of the License, or (at
Packit Service 4684c1
# your option) any later version.
Packit Service 4684c1
#
Packit Service 4684c1
# GnuTLS is distributed in the hope that it will be useful, but
Packit Service 4684c1
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 4684c1
# General Public License for more details.
Packit Service 4684c1
#
Packit Service 4684c1
# You should have received a copy of the GNU General Public License
Packit Service 4684c1
# along with GnuTLS; if not, write to the Free Software Foundation,
Packit Service 4684c1
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit Service 4684c1
Packit Service 4684c1
for i in /usr/lib64/pkcs11 /usr/lib/softhsm /usr/lib/x86_64-linux-gnu/softhsm /usr/lib /usr/lib64/softhsm;do
Packit Service 4684c1
	if test -f "$i/libsofthsm2.so"; then
Packit Service 4684c1
		ADDITIONAL_PARAM="--provider $i/libsofthsm2.so"
Packit Service 4684c1
		break
Packit Service 4684c1
	else
Packit Service 4684c1
		if test -f "$i/libsofthsm.so";then
Packit Service 4684c1
			ADDITIONAL_PARAM="--provider $i/libsofthsm.so"
Packit Service 4684c1
			break
Packit Service 4684c1
		fi
Packit Service 4684c1
	fi
Packit Service 4684c1
done
Packit Service 4684c1
Packit Service 4684c1
init_card () {
Packit Service 4684c1
	PIN="$1"
Packit Service 4684c1
	PUK="$2"
Packit Service 4684c1
Packit Service 4684c1
	if test -x "/usr/bin/softhsm2-util"; then
Packit Service 4684c1
		export SOFTHSM2_CONF="softhsm-testpkcs11.$$.config.tmp"
Packit Service 4684c1
		SOFTHSM_TOOL="/usr/bin/softhsm2-util"
Packit Service 4684c1
		${SOFTHSM_TOOL} --version|grep "2.0.0" >/dev/null 2>&1
Packit Service 4684c1
		if test $? = 0; then
Packit Service 4684c1
			echo "softhsm2-util 2.0.0 is broken"
Packit Service 4684c1
			export BROKEN_SOFTHSM2=1
Packit Service 4684c1
		fi
Packit Service 4684c1
	fi
Packit Service 4684c1
Packit Service 4684c1
	if test -x "/usr/bin/softhsm"; then
Packit Service 4684c1
		export SOFTHSM_CONF="softhsm-testpkcs11.$$.config.tmp"
Packit Service 4684c1
		SOFTHSM_TOOL="/usr/bin/softhsm"
Packit Service 4684c1
	fi
Packit Service 4684c1
Packit Service 4684c1
	if test -z "${SOFTHSM_TOOL}"; then
Packit Service 4684c1
		echo "Could not find softhsm(2) tool"
Packit Service 4684c1
		exit 77
Packit Service 4684c1
	fi
Packit Service 4684c1
Packit Service 4684c1
	if test -z "${SOFTHSM_CONF}"; then
Packit Service 4684c1
		rm -rf ./softhsm-testpkcs11.$$.tmp
Packit Service 4684c1
		mkdir -p ./softhsm-testpkcs11.$$.tmp
Packit Service 4684c1
		echo "objectstore.backend = file" > "${SOFTHSM2_CONF}"
Packit Service 4684c1
		echo "directories.tokendir = ./softhsm-testpkcs11.$$.tmp" >> "${SOFTHSM2_CONF}"
Packit Service 4684c1
Packit Service 4684c1
	else
Packit Service 4684c1
		rm -rf ./softhsm-testpkcs11.$$.tmp
Packit Service 4684c1
		echo "0:./softhsm-testpkcs11.$$.tmp" > "${SOFTHSM_CONF}"
Packit Service 4684c1
	fi
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
	echo -n "* Initializing smart card... "
Packit Service 4684c1
	${SOFTHSM_TOOL} --init-token --slot 0 --label "GnuTLS-Test" --so-pin "${PUK}" --pin "${PIN}" >/dev/null #2>&1
Packit Service 4684c1
	if test $? = 0; then
Packit Service 4684c1
		echo ok
Packit Service 4684c1
	else
Packit Service 4684c1
		echo failed
Packit Service 4684c1
		exit_error
Packit Service 4684c1
	fi
Packit Service 4684c1
}