Debian Codegraph @

tests/fork-change-slot.softhsm

raw
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) 2013 Nikos Mavrogiannopoulos
6 # Copyright (C) 2015 Red Hat, Inc.
7 #
8 # This is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the
10 # Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # GnuTLS is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GnuTLS; if not, write to the Free Software Foundation,
20 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 outdir="output.$$"
23
24 # Load common test functions
25 . ${srcdir}/common.sh
26
27 # Initialize SoftHSM DB
28 init_db
29
30 # Create 2 different tokens
31 init_card "token1"
32 init_card "token2"
33
34 # Generate an RSA key pair on the second token
35 generate_rsa_key_pair "pkey" "token2"
36
37 # Load openssl settings
38 . ${srcdir}/openssl-settings.sh
39
40 # Restore openssl settings
41 trap cleanup EXIT
42
43 # Run the test program which will stop and wait for a signal (SIGUSR1)
44 # Valgrind cannot be used because the test program waits indefinitely at the sigwait call
45 ./fork-change-slot "pkcs11:token=token2;object=pkey;type=private;pin-value=$PIN" \
46 "${outdir}/engines.cnf" ${MODULE} &
47 pid=$!
48
49 # Wait the test program to reach the sigwait
50 sleep 3
51
52 # Remove the first token to change the slotID associated with token2
53 remove_card "token1"
54
55 # Send the signal to the waiting process
56 kill -USR1 `pgrep -P $pid`
57
58 # Test the result
59 wait $pid
60 rc=$?
61 if [[ $rc -eq 77 ]]; then
62 echo "Fork test skipped."
63 rm -rf "$outdir"
64 exit 77
65 elif [[ $rc -ne 0 ]]; then
66 echo "Fork test failed."
67 exit 1
68 fi
69
70 rm -rf "$outdir"
71
72 exit 0