Debian Codegraph @

tests/provider-rsa-evp-sign.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 KEY_ID="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0"
25
26 printf ${PIN} > $outdir/pin.txt
27
28 # Do the token initialization
29 init_token "rsa" "1" "libp11" ${ID} "server-key" "privkey" "pubkey" "cert"
30
31 # Ensure the use of the locally built provider; applies after running 'pkcs11-tool'
32 unset OPENSSL_ENGINES
33 export OPENSSL_MODULES="../src/.libs/"
34 export PKCS11_MODULE_PATH=${MODULE}
35 echo "OPENSSL_MODULES=${OPENSSL_MODULES}"
36 echo "PKCS11_MODULE_PATH=${PKCS11_MODULE_PATH}"
37
38 # Load openssl settings
39 . ${srcdir}/openssl-settings.sh
40
41 # Restore openssl settings
42 trap cleanup EXIT
43
44 # Run the test
45 for PIN_ATTR in \
46 "pin-value=${PIN}" \
47 "pin-source=$outdir/pin.txt" \
48 "pin-source=file:$outdir/pin.txt"
49 do
50
51 PRIVATE_KEY="$KEY_ID;type=private;$PIN_ATTR"
52 PUBLIC_KEY="$KEY_ID;type=public"
53
54 echo $PRIVATE_KEY
55
56 ${WRAPPER} ./evp-sign-prov ctrl ${PRIVATE_KEY} ${PUBLIC_KEY}
57 rc=$?
58 if [[ $rc -eq 77 ]]; then
59 echo "Basic PKCS #11 test skipped."
60 rm -rf "$outdir"
61 exit 77
62 elif [[ $rc -ne 0 ]]; then
63 echo "Basic PKCS #11 test with pin-value, using ctrl failed."
64 exit 1
65 fi
66
67 ./evp-sign-prov default ${PRIVATE_KEY} ${PUBLIC_KEY}
68 if [[ $? -ne 0 ]]; then
69 echo "Basic PKCS #11 test with pin-value, using default failed."
70 exit 1
71 fi
72
73 done
74
75 export PKCS11_PIN=${PIN}
76 echo $PRIVATE_KEY
77
78 ./evp-sign-prov ctrl ${PRIVATE_KEY} ${PUBLIC_KEY}
79 if [[ $? -ne 0 ]]; then
80 echo "Basic PKCS #11 test with PKCS11_PIN environment variable, using ctrl failed."
81 exit 1
82 fi
83
84 ./evp-sign-prov default ${PRIVATE_KEY} ${PUBLIC_KEY}
85 if [[ $? -ne 0 ]]; then
86 echo "Basic PKCS #11 test with PKCS11_PIN environment variable, using default failed."
87 exit 1
88 fi
89
90 rm -rf "$outdir"
91
92 exit 0