Debian Codegraph @

tests/rsa-cert-store.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 # Do the token initialization
25 init_token "rsa" "1" "libp11" ${ID} "server-key" "privkey" "" "cert"
26
27 # Load openssl settings
28 . ${srcdir}/openssl-settings.sh
29
30 # Restore openssl settings
31 trap cleanup EXIT
32
33 # RSA certificate to store
34 ${OPENSSL} x509 -in ${srcdir}/rsa-cert.der -inform DER -outform PEM \
35 -out ${outdir}/rsa-cert.pem
36 CERTIFICATE="${outdir}/rsa-cert.pem"
37 CERTIFICATE_URL="pkcs11:token=libp11-0;id=04030201;object=stored-cert;pin-value=1234"
38
39 # Run the test
40 ${WRAPPER} ../examples/storecert ${CERTIFICATE} ${CERTIFICATE_URL} ${MODULE}
41 rc=$?
42 if [[ $rc -eq 77 ]]; then
43 echo "RSA certificate storing test skipped."
44 rm -rf "$outdir"
45 exit 77
46 elif [[ $rc -ne 0 ]]; then
47 echo "RSA certificate storing couldn't be performed."
48 exit 1
49 fi
50
51 list_objects && list_objects | grep -q stored-cert
52 if [[ $? -ne 0 ]]; then
53 echo "The RSA certificate was not properly stored."
54 exit 1
55 fi
56
57 rm -rf "$outdir"
58
59 exit 0