Blame tests/pkcs11-uri-without-token.softhsm

Packit Service 7f6fc8
#!/bin/sh
Packit Service 7f6fc8
Packit Service 7f6fc8
# Copyright (C) 2015 Nikos Mavrogiannopoulos
Packit Service 7f6fc8
#
Packit Service 7f6fc8
# GnuTLS is free software; you can redistribute it and/or modify it
Packit Service 7f6fc8
# under the terms of the GNU General Public License as published by the
Packit Service 7f6fc8
# Free Software Foundation; either version 3 of the License, or (at
Packit Service 7f6fc8
# your option) any later version.
Packit Service 7f6fc8
#
Packit Service 7f6fc8
# GnuTLS is distributed in the hope that it will be useful, but
Packit Service 7f6fc8
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 7f6fc8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 7f6fc8
# General Public License for more details.
Packit Service 7f6fc8
#
Packit Service 7f6fc8
# You should have received a copy of the GNU General Public License
Packit Service 7f6fc8
# along with GnuTLS; if not, write to the Free Software Foundation,
Packit Service 7f6fc8
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit Service 7f6fc8
Packit Service 7f6fc8
# This test checks if it is possible to use the keys without specifying the
Packit Service 7f6fc8
# token if there is only one initialized token available.
Packit Service 7f6fc8
Packit Service 7f6fc8
outdir="output.$$"
Packit Service 7f6fc8
Packit Service 7f6fc8
# Load common test functions
Packit Service 7f6fc8
. ${srcdir}/rsa-common.sh
Packit Service 7f6fc8
Packit Service 7f6fc8
# Do the common test initialization
Packit Service 7f6fc8
common_init
Packit Service 7f6fc8
Packit Service 7f6fc8
sed -e "s|@MODULE_PATH@|${MODULE}|g" -e \
Packit Service 7f6fc8
    "s|@ENGINE_PATH@|../src/.libs/pkcs11.so|g" \
Packit Service 7f6fc8
    <"${srcdir}/engines.cnf.in" >"${outdir}/engines.cnf"
Packit Service 7f6fc8
Packit Service 7f6fc8
export OPENSSL_ENGINES="../src/.libs/"
Packit Service 7f6fc8
export OPENSSL_CONF="${outdir}/engines.cnf"
Packit Service 7f6fc8
Packit Service 7f6fc8
# These URIs don't contain the token specification
Packit Service 7f6fc8
PRIVATE_KEY="pkcs11:object=server-key;type=private;pin-value=1234"
Packit Service 7f6fc8
PUBLIC_KEY="pkcs11:object=server-key;type=public;pin-value=1234"
Packit Service 7f6fc8
Packit Service 7f6fc8
# Create input file
Packit Service 7f6fc8
echo "secret" >"${outdir}/in.txt"
Packit Service 7f6fc8
Packit Service 7f6fc8
# Generate signature without specifying the token in the PKCS#11 URI
Packit Service 7f6fc8
openssl pkeyutl -engine pkcs11 -keyform engine -inkey "${PRIVATE_KEY}" \
Packit Service 7f6fc8
	-sign -out "${outdir}/signature.bin" -in "${outdir}/in.txt"
Packit Service 7f6fc8
if test $? != 0;then
Packit Service 7f6fc8
	echo "Failed to generate signature using PKCS#11 URI ${PRIVATE_KEY}"
Packit Service 7f6fc8
	exit 1;
Packit Service 7f6fc8
fi
Packit Service 7f6fc8
Packit Service 7f6fc8
# Verify the signature without specifying the token in the PKCS#11 URI
Packit Service 7f6fc8
openssl pkeyutl -engine pkcs11 -keyform engine -pubin -inkey "${PUBLIC_KEY}" \
Packit Service 7f6fc8
	-verify -sigfile "${outdir}/signature.bin" -in "${outdir}/in.txt"
Packit Service 7f6fc8
if test $? != 0;then
Packit Service 7f6fc8
	echo "Failed to verify signature using PKCS#11 URI ${PUBLIC_KEY}"
Packit Service 7f6fc8
	exit 1;
Packit Service 7f6fc8
fi
Packit Service 7f6fc8
Packit Service 7f6fc8
rm -rf "$outdir"
Packit Service 7f6fc8
Packit Service 7f6fc8
exit 0