Debian Codegraph @

tests/provider-ec-check-privkey.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 PRIVATE_KEY="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=private;pin-value=${PIN}"
25 CERTIFICATE_URL="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=cert"
26
27 # Do the token initialization
28 init_token "ec" "1" "libp11" ${ID} "server-key" "privkey" "" "cert"
29
30 # Ensure the use of the locally built provider; applies after running 'pkcs11-tool'
31 unset OPENSSL_ENGINES
32 export OPENSSL_MODULES="../src/.libs/"
33 export PKCS11_MODULE_PATH=${MODULE}
34 echo "OPENSSL_MODULES=${OPENSSL_MODULES}"
35 echo "PKCS11_MODULE_PATH=${PKCS11_MODULE_PATH}"
36
37 # Load openssl settings
38 . ${srcdir}/openssl-settings.sh
39
40 # Restore openssl settings
41 trap cleanup EXIT
42
43 ${OPENSSL} x509 -in ${srcdir}/ec-cert.der -inform DER -outform PEM \
44 -out ${outdir}/ec-cert.pem
45 CERTIFICATE="${outdir}/ec-cert.pem"
46
47 # Run the test
48 ${WRAPPER} ./check-privkey-prov ${CERTIFICATE} ${PRIVATE_KEY} \
49 "${outdir}/engines.cnf"
50 rc=$?
51 if [[ $rc -eq 77 ]]; then
52 echo "EC key test skipped."
53 rm -rf "$outdir"
54 exit 77
55 elif [[ $rc -ne 0 ]]; then
56 echo "The private key loading couldn't get the public key from the certificate."
57 exit 1
58 fi
59
60 ./check-privkey-prov ${CERTIFICATE_URL} ${PRIVATE_KEY} \
61 "${outdir}/engines.cnf"
62 if [[ $? -ne 0 ]]; then
63 echo "The private key loading couldn't get the public key from the certificate URL."
64 exit 1
65 fi
66
67 rm -rf "$outdir"
68
69 exit 0