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

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