Debian Codegraph @

tests/rsa-testlistkeys_ext.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) 2023 Koninklijke Philips N.V.
6 #
7 # This 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 # Load common test functions
24 . ${srcdir}/common.sh
25
26 # Do the token initialization
27 init_token "rsa" "1" "libp11" ${ID} "server-key" "privkey" "pubkey" "cert"
28
29 # Write more objects with different labels to the token
30 import_objects "rsa" "libp11-0" "01020314" "server-key-1" "privkey" "pubkey" "cert"
31 import_objects "rsa" "libp11-0" "01020324" "server-key-2" "privkey" "pubkey" "cert"
32 import_objects "rsa" "libp11-0" "01020334" "server-key-3" "privkey" "pubkey" "cert"
33 import_objects "rsa" "libp11-0" "01020344" "server-key-4" "privkey" "pubkey" "cert"
34
35 list_objects "libp11-0"
36
37 # Load openssl settings
38 . ${srcdir}/openssl-settings.sh
39
40 # Restore openssl settings
41 trap cleanup EXIT
42
43 # Run the test
44 ${WRAPPER} ../examples/listkeys_ext -m ${MODULE} -p ${PIN} | grep -q 'nkeys:5'
45 rc=$?
46 if [[ $rc -eq 77 ]]; then
47 echo "List keys test skipped."
48 rm -rf "$outdir"
49 exit 77
50 elif [[ $rc -ne 0 ]]; then
51 echo "Failed when no search parameters were given. 5 Keys should have been found."
52 exit 1
53 fi
54
55 ../examples/listkeys_ext -m ${MODULE} -p ${PIN} -i "01020314" | grep -q 'nkeys:1'
56 if [[ $? -ne 0 ]]; then
57 echo "Failed when searching with id. Only 1 key should have been found."
58 exit 1
59 fi
60
61 ../examples/listkeys_ext -m ${MODULE} -p ${PIN} -i "1020314" | grep -q 'nkeys:1'
62 if [[ $? -ne 0 ]]; then
63 echo "Failed when searching with id. Only 1 key should have been found."
64 exit 1
65 fi
66
67 ../examples/listkeys_ext -m ${MODULE} -p ${PIN} -l server-key-3 | grep -q 'nkeys:1'
68 if [[ $? -ne 0 ]]; then
69 echo "Failed when searching with label. Only 1 key should have been found."
70 exit 1
71 fi
72
73 ../examples/listkeys_ext -m ${MODULE} -p ${PIN} -i "01020334" -l server-key-3 | grep -q 'nkeys:1'
74 if [[ $? -ne 0 ]]; then
75 echo "Failed when searching with id and label. Only 1 key should have been found."
76 exit 1
77 fi
78
79 ../examples/listkeys_ext -m ${MODULE} -p ${PIN} -i "01020334" -l server-key-1
80 if [[ $? -eq 0 ]]; then
81 echo "Did not fail when no keys should have been found."
82 exit 1
83 fi
84
85 rm -rf "$outdir"
86
87 exit 0