Debian Codegraph @

tests/rsa-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 KEY_ID="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0"
24
25 # Load common test functions
26 . ${srcdir}/common.sh
27
28 printf ${PIN} > $outdir/pin.txt
29
30 # Do the token initialization
31 init_token "rsa" "1" "libp11" ${ID} "server-key" "privkey" "pubkey" "cert"
32
33 # Load openssl settings
34 . ${srcdir}/openssl-settings.sh
35
36 # Restore openssl settings
37 trap cleanup EXIT
38
39 # Run the test
40 for PIN_ATTR in \
41 "pin-value=${PIN}" \
42 "pin-source=$outdir/pin.txt" \
43 "pin-source=file:$outdir/pin.txt"
44 do
45
46 PRIVATE_KEY="$KEY_ID;type=private;$PIN_ATTR"
47 PUBLIC_KEY="$KEY_ID;type=public;$PIN_ATTR"
48
49 echo $PRIVATE_KEY
50
51 ${WRAPPER} ./evp-sign ctrl false "${outdir}/engines.cnf" \
52 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
53 rc=$?
54 if [[ $rc -eq 77 ]]; then
55 echo "Basic PKCS #11 test skipped."
56 rm -rf "$outdir"
57 exit 77
58 elif [[ $rc -ne 0 ]]; then
59 echo "Basic PKCS #11 test, using ctrl failed."
60 exit 1
61 fi
62
63 ./evp-sign default false "${outdir}/engines.cnf" \
64 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
65 if [[ $? -ne 0 ]]; then
66 echo "Basic PKCS #11 test, using default failed."
67 exit 1
68 fi
69
70 ./evp-sign ctrl ${PIN} "${outdir}/engines.cnf" \
71 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
72 if [[ $? -ne 0 ]]; then
73 echo "Basic PKCS #11 test without pin-value, using ctrl failed."
74 exit 1
75 fi
76
77 ./evp-sign default ${PIN} "${outdir}/engines.cnf" \
78 ${PRIVATE_KEY} ${PUBLIC_KEY} ${MODULE}
79 if [[ $? -ne 0 ]]; then
80 echo "Basic PKCS #11 test without pin-value, using default failed."
81 exit 1
82 fi
83
84 done
85
86 ./evp-sign ctrl ${PIN} "${outdir}/engines.cnf" \
87 "label_server-key-0" "label_server-key-0" ${MODULE}
88 if [[ $? -ne 0 ]]; then
89 echo "Basic PKCS #11 test with legacy name #1 failed."
90 exit 1
91 fi
92
93 ./evp-sign default ${PIN} "${outdir}/engines.cnf" \
94 "id_01020304" "id_01020304" ${MODULE}
95 if [[ $? -ne 0 ]]; then
96 echo "Basic PKCS #11 test with legacy name #2 failed."
97 exit 1
98 fi
99
100 rm -rf "$outdir"
101
102 exit 0