Debian Codegraph @

tests/pkcs11-uri-pin-source.softhsm

raw
1 #!/bin/bash
2
3 # Copyright (C) 2025 Tobias Deiminger
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>
17
18 outdir="output.$$"
19
20 URL="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0"
21
22 # Load common test functions
23 . ${srcdir}/common.sh
24
25 # Generate test input files
26 printf ${PIN} > $outdir/pin.txt
27 printf "${PIN}\n" > $outdir/pin_with_trailing_newline.txt
28
29 # Do the token initialization
30 init_token "rsa" "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 for PIN_SOURCE_ATTR in \
40 "pin-source=$outdir/pin.txt" \
41 "pin-source=$outdir/pin_with_trailing_newline.txt" \
42 "pin-source=file:$outdir/pin.txt" \
43 "pin-source=file:$outdir/pin_with_trailing_newline.txt"
44 do
45
46 ${WRAPPER} ./check-privkey "${URL};type=cert" "${URL};type=private;${PIN_SOURCE_ATTR}" \
47 ${MODULE} "${outdir}/engines.cnf"
48 rc=$?
49 if [[ $rc -eq 77 ]]; then
50 echo "PIN source test skipped."
51 rm -rf "$outdir"
52 exit 77
53 elif [[ $rc -ne 0 ]]; then
54 echo "The private key loading couldn't get the public key from the certificate URL."
55 exit 1
56 fi
57
58
59 done
60
61 rm -rf "$outdir"
62
63 exit 0