|
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 the search for objects in tokens will continue past the
|
|
Packit Service |
7f6fc8 |
# first token found.
|
|
Packit Service |
7f6fc8 |
#
|
|
Packit Service |
7f6fc8 |
# Generic PKCS#11 URIs are used to make the search to match more than one
|
|
Packit Service |
7f6fc8 |
# token. The search should be able to find the objects in each device, which are
|
|
Packit Service |
7f6fc8 |
# labeled differently per token.
|
|
Packit Service |
7f6fc8 |
#
|
|
Packit Service |
7f6fc8 |
# This test also contains a negative test to verify that the engine will not try
|
|
Packit Service |
7f6fc8 |
# to login to a token if more than one token matched the search. This is why it
|
|
Packit Service |
7f6fc8 |
# is required to have only one match to be able to use a private key.
|
|
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 |
PIN=1234
|
|
Packit Service |
7f6fc8 |
PUK=1234
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
NUM_DEVICES=5
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
# Initialize the SoftHSM DB
|
|
Packit Service |
7f6fc8 |
init_db
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
# Create some devices
|
|
Packit Service |
7f6fc8 |
create_devices $NUM_DEVICES $PIN $PUK "libp11-test" "label"
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
sed -e "s|@MODULE_PATH@|${MODULE}|g" -e "s|@ENGINE_PATH@|../src/.libs/pkcs11.so|g" <"${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 |
PRIVATE_KEY="pkcs11:token=libp11-test-3;object=label-3;type=private;pin-value=1234"
|
|
Packit Service |
7f6fc8 |
PRIVATE_KEY_WITHOUT_TOKEN="pkcs11:object=label-3;type=private;pin-value=1234"
|
|
Packit Service |
7f6fc8 |
PUBLIC_KEY_ANY="pkcs11:type=public"
|
|
Packit Service |
7f6fc8 |
CERTIFICATE="pkcs11:object=label-3;type=cert;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 |
# Verify that it doesn't try to login if more than one token matched the search
|
|
Packit Service |
7f6fc8 |
openssl pkeyutl -engine pkcs11 -keyform engine \
|
|
Packit Service |
7f6fc8 |
-inkey "${PRIVATE_KEY_WITHOUT_TOKEN}" \
|
|
Packit Service |
7f6fc8 |
-sign -out "${outdir}/signature.bin" -in "${outdir}/in.txt"
|
|
Packit Service |
7f6fc8 |
if test $? = 0;then
|
|
Packit Service |
7f6fc8 |
echo "Did not fail when the PKCS#11 URI matched multiple tokens"
|
|
Packit Service |
7f6fc8 |
exit 1;
|
|
Packit Service |
7f6fc8 |
fi
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
# Generate signature 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 sign file using PKCS#11 URI ${PRIVATE_KEY}"
|
|
Packit Service |
7f6fc8 |
exit 1;
|
|
Packit Service |
7f6fc8 |
fi
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
# Verify the signature using the public key from each token
|
|
Packit Service |
7f6fc8 |
i=0
|
|
Packit Service |
7f6fc8 |
while [ $i -le ${NUM_DEVICES} ]; do
|
|
Packit Service |
7f6fc8 |
pubkey="pkcs11:object=label-$i;type=public;pin-value=1234"
|
|
Packit Service |
7f6fc8 |
openssl pkeyutl -engine pkcs11 -keyform engine -pubin -inkey "${pubkey}" \
|
|
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 the signature using the PKCS#11 URI ${pubkey}"
|
|
Packit Service |
7f6fc8 |
exit 1;
|
|
Packit Service |
7f6fc8 |
fi
|
|
Packit Service |
7f6fc8 |
i=$(($i + 1))
|
|
Packit Service |
7f6fc8 |
done
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
# Verify the signature using a certificate without specifying the token
|
|
Packit Service |
7f6fc8 |
openssl pkeyutl -engine pkcs11 -keyform engine -pubin -inkey "${CERTIFICATE}" \
|
|
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 the signature using the PKCS#11 URI ${CERTIFICATE}"
|
|
Packit Service |
7f6fc8 |
exit 1;
|
|
Packit Service |
7f6fc8 |
fi
|
|
Packit Service |
7f6fc8 |
|
|
Packit Service |
7f6fc8 |
# Verify the signature using the first public key found
|
|
Packit Service |
7f6fc8 |
openssl pkeyutl -engine pkcs11 -keyform engine -pubin -inkey "${PUBLIC_KEY_ANY}" \
|
|
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 the signature using the PKCS#11 URI ${PUBLIC_KEY_ANY}."
|
|
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
|