Blame tests/fork-change-slot.softhsm

Packit 6b81fa
#!/bin/sh
Packit 6b81fa
Packit 6b81fa
# Copyright (C) 2013 Nikos Mavrogiannopoulos
Packit 6b81fa
# Copyright (C) 2015 Red Hat, Inc.
Packit 6b81fa
#
Packit 6b81fa
# This is free software; you can redistribute it and/or modify it
Packit 6b81fa
# under the terms of the GNU General Public License as published by the
Packit 6b81fa
# Free Software Foundation; either version 3 of the License, or (at
Packit 6b81fa
# your option) any later version.
Packit 6b81fa
#
Packit 6b81fa
# GnuTLS is distributed in the hope that it will be useful, but
Packit 6b81fa
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6b81fa
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6b81fa
# General Public License for more details.
Packit 6b81fa
#
Packit 6b81fa
# You should have received a copy of the GNU General Public License
Packit 6b81fa
# along with GnuTLS; if not, write to the Free Software Foundation,
Packit 6b81fa
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 6b81fa
Packit 6b81fa
outdir="output.$$"
Packit 6b81fa
Packit 6b81fa
# Load common test functions
Packit 6b81fa
. ${srcdir}/rsa-common.sh
Packit 6b81fa
Packit 6b81fa
sed -e "s|@MODULE_PATH@|${MODULE}|g" -e \
Packit 6b81fa
	"s|@ENGINE_PATH@|../src/.libs/pkcs11.so|g" \
Packit 6b81fa
	<"${srcdir}/engines.cnf.in" >"${outdir}/engines.cnf"
Packit 6b81fa
Packit 6b81fa
# Set the used PIN and PUK
Packit 6b81fa
PIN=1234
Packit 6b81fa
PUK=1234
Packit 6b81fa
Packit 6b81fa
# Initialize SoftHSM DB
Packit 6b81fa
init_db
Packit 6b81fa
Packit 6b81fa
# Create 2 different tokens
Packit 6b81fa
init_card $PIN $PUK "token1"
Packit 6b81fa
init_card $PIN $PUK "token2"
Packit 6b81fa
Packit 6b81fa
# Force the use of the local built engine
Packit 6b81fa
export OPENSSL_ENGINES="../src/.libs/"
Packit 6b81fa
Packit 6b81fa
# Generate a key pair in the second token
Packit 6b81fa
pkcs11-tool --module ${MODULE} -l --pin $PIN --keypairgen --key-type \
Packit 6b81fa
	rsa:1024 --id 01020304 --label pkey --token-label token2
Packit 6b81fa
if test $? != 0;then
Packit 6b81fa
	exit 1;
Packit 6b81fa
fi
Packit 6b81fa
Packit 6b81fa
# Run the test program which will stop and wait for a signal (SIGUSR1)
Packit 6b81fa
./fork-change-slot \
Packit 6b81fa
	"pkcs11:token=token2;object=pkey;type=private;pin-value=$PIN" \
Packit 6b81fa
	"${outdir}/engines.cnf" ${MODULE} &
Packit 6b81fa
pid=$!
Packit 6b81fa
Packit 6b81fa
# Wait the test program to reach the sigwait
Packit 6b81fa
sleep 3
Packit 6b81fa
Packit 6b81fa
# Remove the first token to change the slotID associated with token2
Packit 6b81fa
${SOFTHSM_TOOL} --delete-token --token token1
Packit 6b81fa
Packit 6b81fa
# Send the signal to the waiting process
Packit 6b81fa
kill -USR1 `pgrep -P $pid`
Packit 6b81fa
Packit 6b81fa
# Test the result
Packit 6b81fa
wait $pid
Packit 6b81fa
if test $? != 0;then
Packit 6b81fa
	exit 1;
Packit 6b81fa
fi
Packit 6b81fa
Packit 6b81fa
# Cleanup
Packit 6b81fa
rm -rf "$outdir"
Packit 6b81fa
Packit 6b81fa
exit 0
Packit 6b81fa