Debian Codegraph @

tests/provider-fork-change-slot.softhsm

raw
1 #!/bin/bash
2
3 # Copyright © 2025 Mobi - Com Polska Sp. z o.o.
4 # Author: Małgorzata Olszówka <[email protected]>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>
18
19 outdir="output.$$"
20
21 # Load common test functions
22 . ${srcdir}/common.sh
23
24 # Initialize SoftHSM DB
25 init_db
26
27 # Create 2 different tokens
28 init_card "token1"
29 init_card "token2"
30
31 # Generate an RSA key pair on the second token
32 generate_rsa_key_pair "pkey" "token2"
33
34 # Ensure the use of the locally built provider; applies after running 'pkcs11-tool'
35 unset OPENSSL_ENGINES
36 export OPENSSL_MODULES="../src/.libs/"
37 export PKCS11_MODULE_PATH=${MODULE}
38 echo "OPENSSL_MODULES=${OPENSSL_MODULES}"
39 echo "PKCS11_MODULE_PATH=${PKCS11_MODULE_PATH}"
40
41 # Load openssl settings
42 . ${srcdir}/openssl-settings.sh
43
44 # Restore openssl settings
45 trap cleanup EXIT
46
47 # These URIs contains the token specification
48 PRIVATE_KEY="pkcs11:token=token2;object=pkey;type=private;pin-value=${PIN}"
49
50 # Run the test program which will stop and wait for a signal (SIGUSR1)
51 # Valgrind cannot be used because the test program waits indefinitely at the sigwait call
52 ./fork-change-slot-prov ${PRIVATE_KEY} &
53 pid=$!
54
55 # Wait the test program to reach the sigwait
56 sleep 3
57
58 # Remove the first token to change the slotID associated with token2
59 remove_card "token1"
60
61 # Send the signal to the waiting process
62 kill -USR1 `pgrep -P $pid`
63
64 # Test the result
65 wait $pid
66 rc=$?
67 if [[ $rc -eq 77 ]]; then
68 echo "Fork test skipped."
69 rm -rf "$outdir"
70 exit 77
71 elif [[ $rc -ne 0 ]]; then
72 echo "Fork test failed."
73 exit 1
74 fi
75
76 rm -rf "$outdir"
77
78 exit 0