Debian Codegraph @

tests/rsa-check-privkey.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) 2015 Nikos Mavrogiannopoulos
6 # Copyright (C) 2019 Anderson Toshiyuki Sasaki
7 # Copyright (C) 2019 Red Hat, Inc.
8 # Copyright (C) 2021 Uri Blumenthal, MIT
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22
23 outdir="output.$$"
24
25 PRIVATE_KEY="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=private;pin-value=1234"
26 CERTIFICATE_URL="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=cert;pin-value=1234"
27
28 # Load common test functions
29 . ${srcdir}/common.sh
30
31 # Do the token initialization
32 init_token "rsa" "1" "libp11" ${ID} "server-key" "privkey" "" "cert"
33
34 # Load openssl settings
35 . ${srcdir}/openssl-settings.sh
36
37 # Restore openssl settings
38 trap cleanup EXIT
39
40 ${OPENSSL} x509 -in ${srcdir}/rsa-cert.der -inform DER -outform PEM \
41 -out ${outdir}/rsa-cert.pem
42 CERTIFICATE="${outdir}/rsa-cert.pem"
43
44 # Run the test
45 ${WRAPPER} ./check-privkey ${CERTIFICATE} ${PRIVATE_KEY} ${MODULE} \
46 "${outdir}/engines.cnf"
47 rc=$?
48 if [[ $rc -eq 77 ]]; then
49 echo "RSA key test skipped."
50 rm -rf "$outdir"
51 exit 77
52 elif [[ $rc -ne 0 ]]; then
53 echo "The private key loading couldn't get the public key from the certificate."
54 exit 1
55 fi
56
57 ./check-privkey ${CERTIFICATE_URL} ${PRIVATE_KEY} ${MODULE} \
58 "${outdir}/engines.cnf"
59 if [[ $? -ne 0 ]]; then
60 echo "The private key loading couldn't get the public key from the certificate URL."
61 exit 1
62 fi
63
64 rm -rf "$outdir"
65
66 exit 0