Debian Codegraph @

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