| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Copyright © 2024 Mobi - Com Polska Sp. z o.o. |
| 4 |
# Author: Małgorzata Olszówka <[email protected]> |
| 5 |
# Copyright (C) 2015 Nikos Mavrogiannopoulos |
| 6 |
# |
| 7 |
# GnuTLS is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by the |
| 9 |
# Free Software Foundation; either version 3 of the License, or (at |
| 10 |
# your option) any later version. |
| 11 |
# |
| 12 |
# GnuTLS is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
# General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with GnuTLS; if not, write to the Free Software Foundation, |
| 19 |
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 |
|
| 21 |
# This test checks if it is possible to use the keys without specifying the |
| 22 |
# token if there is only one initialized token available. |
| 23 |
|
| 24 |
outdir="output.$$" |
| 25 |
|
| 26 |
# These URIs don't contain the token specification |
| 27 |
PRIVATE_KEY="pkcs11:object=server-key-0;type=private;pin-value=1234" |
| 28 |
PUBLIC_KEY="pkcs11:object=server-key-0;type=public;pin-value=1234" |
| 29 |
|
| 30 |
# Load common test functions |
| 31 |
. ${srcdir}/common.sh |
| 32 |
|
| 33 |
export OPENSSL_CONF="${outdir}/engines.cnf" |
| 34 |
echo "OPENSSL_CONF=${OPENSSL_CONF}" |
| 35 |
|
| 36 |
# Do the token initialization |
| 37 |
init_token "rsa" "1" "libp11" ${ID} "server-key" "privkey" "pubkey" "cert" |
| 38 |
|
| 39 |
# Create input file |
| 40 |
echo "secret" >"${outdir}/in.txt" |
| 41 |
|
| 42 |
# Load openssl settings |
| 43 |
. ${srcdir}/openssl-settings.sh |
| 44 |
|
| 45 |
if ! "${OPENSSL}" engine >/dev/null 2>&1; then |
| 46 |
echo "Skipping engine tests: ENGINE support not available" |
| 47 |
rm -rf "$outdir" |
| 48 |
exit 77 |
| 49 |
fi |
| 50 |
|
| 51 |
# Restore openssl settings |
| 52 |
trap cleanup EXIT |
| 53 |
|
| 54 |
# Run the test |
| 55 |
# Generate signature without specifying the token in the PKCS#11 URI |
| 56 |
${WRAPPER} ${OPENSSL} pkeyutl -engine pkcs11 -keyform engine \ |
| 57 |
-inkey ${PRIVATE_KEY} -sign -out "${outdir}/signature.bin" \ |
| 58 |
-in "${outdir}/in.txt" |
| 59 |
if [[ $? -ne 0 ]]; then |
| 60 |
echo "Failed to generate signature using PKCS#11 URI ${PRIVATE_KEY}" |
| 61 |
exit 1 |
| 62 |
fi |
| 63 |
|
| 64 |
# Verify the signature without specifying the token in the PKCS#11 URI |
| 65 |
${OPENSSL} pkeyutl -engine pkcs11 -keyform engine -pubin \ |
| 66 |
-inkey ${PUBLIC_KEY} -verify -sigfile "${outdir}/signature.bin" \ |
| 67 |
-in "${outdir}/in.txt" |
| 68 |
if [[ $? -ne 0 ]]; then |
| 69 |
echo "Failed to verify signature using PKCS#11 URI ${PUBLIC_KEY}" |
| 70 |
exit 1 |
| 71 |
fi |
| 72 |
|
| 73 |
rm -rf "$outdir" |
| 74 |
|
| 75 |
exit 0 |