testpkcs11: modified to support both softhsmv1 and v2
[gnutls:gnutls.git] / tests / suite / testpkcs11.softhsm
1 #!/bin/sh
2
3 # Copyright (C) 2013 Nikos Mavrogiannopoulos
4 #
5 # This file is part of GnuTLS.
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 if test -f /usr/lib64/pkcs11/libsofthsm2.so;then
22         ADDITIONAL_PARAM="--provider /usr/lib64/pkcs11/libsofthsm2.so"
23 else
24         if test -f /usr/lib/softhsm/libsofthsm.so;then
25                 ADDITIONAL_PARAM="--provider /usr/lib/softhsm/libsofthsm.so"
26         else
27                 ADDITIONAL_PARAM="--provider /usr/lib64/softhsm/libsofthsm.so"
28         fi
29 fi
30
31 init_card () {
32         PIN=$1
33         PUK=$2
34
35         if test -x "/usr/bin/softhsm2-util";then
36                 export SOFTHSM2_CONF="softhsm-testpkcs11.config"
37                 SOFTHSM_TOOL="/usr/bin/softhsm2-util"
38         fi
39
40         if test -x "/usr/bin/softhsm";then
41                 export SOFTHSM_CONF="softhsm-testpkcs11.config"
42                 SOFTHSM_TOOL="/usr/bin/softhsm"
43         fi
44
45         if test -z "$SOFTHSM_TOOL";then
46                 echo "Could not find softhsm(2) tool"
47                 exit 77
48         fi
49
50         if test -z "$SOFTHSM_CONF";then
51                 rm -rf ./softhsm-testpkcs11.db
52                 mkdir -p ./softhsm-testpkcs11.db
53                 echo "objectstore.backend = file" > $SOFTHSM2_CONF
54                 echo "directories.tokendir = ./softhsm-testpkcs11.db" >> $SOFTHSM2_CONF
55         else
56                 rm -rf ./softhsm-testpkcs11.db
57                 echo "0:./softhsm-testpkcs11.db" > $SOFTHSM_CONF
58         fi
59
60
61         echo -n "* Initializing smart card... "
62         $SOFTHSM_TOOL --init-token --slot 0 --label "GnuTLS-Test" --so-pin $PUK --pin $PIN >/dev/null #2>&1
63         if test $? = 0;then
64                 echo ok
65         else
66                 echo failed
67                 exit_error
68         fi
69 }
70