Debian Codegraph @

tests/ec-evp-sign.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 #
7 # GnuTLS is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # GnuTLS is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GnuTLS; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 outdir="output.$$"
22
23 PRIVATE_KEY="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=private;pin-value=1234"
24 PUBLIC_KEY="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=public;pin-value=1234"
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" "pubkey" "cert"
31
32 # Load openssl settings
33 . ${srcdir}/openssl-settings.sh
34
35 # Restore openssl settings
36 trap cleanup EXIT
37
38 # Run the test
39 ${WRAPPER} ./evp-sign ctrl false "${outdir}/engines.cnf" \
40 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
41 rc=$?
42 if [[ $rc -eq 77 ]]; then
43 echo "Basic PKCS #11 test skipped."
44 rm -rf "$outdir"
45 exit 77
46 elif [[ $rc -ne 0 ]]; then
47 echo "Basic PKCS #11 test, using ctrl failed."
48 exit 1
49 fi
50
51 ./evp-sign default false "${outdir}/engines.cnf" \
52 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
53 if [[ $? -ne 0 ]]; then
54 echo "Basic PKCS #11 test, using default failed."
55 exit 1
56 fi
57
58 ./evp-sign ctrl ${PIN} "${outdir}/engines.cnf" \
59 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
60 if [[ $? -ne 0 ]]; then
61 echo "Basic PKCS #11 test without pin-value, using ctrl failed."
62 exit 1
63 fi
64
65 ./evp-sign default ${PIN} "${outdir}/engines.cnf" \
66 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
67 if [[ $? -ne 0 ]]; then
68 echo "Basic PKCS #11 test without pin-value, using default failed."
69 exit 1
70 fi
71
72 ./evp-sign ctrl ${PIN} "${outdir}/engines.cnf" \
73 "label_server-key-0" "label_server-key-0" ${MODULE}
74 if [[ $? -ne 0 ]]; then
75 echo "Basic PKCS #11 test with legacy name #1 failed."
76 exit 1
77 fi
78
79 ./evp-sign default ${PIN} "${outdir}/engines.cnf" \
80 "id_01020304" "id_01020304" ${MODULE}
81 if [[ $? -ne 0 ]]; then
82 echo "Basic PKCS #11 test with legacy name #2 failed."
83 exit 1
84 fi
85
86 rm -rf "$outdir"
87
88 exit 0