Debian Codegraph @

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