Git init
[external/xmlsec1.git] / tests / testKeys.sh
1 #!/bin/sh
2
3 crypto=$1
4 topfolder=$2
5 xmlsec_app=$3
6 file_format=$4
7
8 pub_key_format=$file_format
9 cert_format=$file_format
10 priv_key_option="--pkcs12"
11 priv_key_format="p12"
12
13 if [ "z$TMPFOLDER" = "z" ] ; then
14     TMPFOLDER=/tmp
15 fi
16
17 timestamp=`date +%Y%m%d_%H%M%S` 
18 tmpfile=$TMPFOLDER/testKeys.$timestamp-$$.tmp
19 logfile=$TMPFOLDER/testKeys.$timestamp-$$.log
20 script="$0"
21 nssdbfolder=$topfolder/nssdb
22
23 # prepate crypto config folder
24 crypto_config=$TMPFOLDER/xmlsec-crypto-config
25 keysfile=$crypto_config/keys.xml
26 mkdir -p $crypto_config
27 rm -rf $crypto_config/*
28
29 valgrind_suppression="--suppressions=$topfolder/openssl.supp --suppressions=$topfolder/nss.supp"
30 valgrind_options="--leak-check=yes --show-reachable=yes --num-callers=32 -v"
31
32
33 if [ "z$crypto" != "z" -a "z$crypto" != "zdefault" ] ; then
34     xmlsec_params="$xmlsec_params --crypto $crypto"
35 fi
36 xmlsec_params="$xmlsec_params --crypto-config $crypto_config"
37
38 if [ -n "$DEBUG_MEMORY" ] ; then 
39     export VALGRIND="valgrind $valgrind_options"
40     export REPEAT=3
41     xmlsec_params="$xmlsec_params --repeat $REPEAT"
42 fi
43
44 if [ -n "$PERF_TEST" ] ; then 
45     export xmlsec_params="$xmlsec_params --repeat $PERF_TEST"
46 fi
47
48 printRes() {    
49     if [ $1 = 0 ]; then
50         echo "   OK"
51     else 
52         echo " Fail"
53     fi
54     if [ -f .memdump ] ; then 
55         cat .memdump >> $logfile 
56     fi
57 }
58
59 execKeysTest() {    
60     req_key_data=$1
61     key_name=$2
62     alg_name=$3
63
64     if [ -n "$req_key_data" ] ; then
65         printf "    Checking $req_key_data key data presense                      "
66         echo "$xmlsec_app check-key-data $req_key_data" >> $logfile
67         $xmlsec_app check-key-data $req_key_data >> $logfile 2>> $logfile
68         res=$?
69         if [ $res = 0 ]; then
70             echo "   OK"            
71         else
72             echo " Skip"
73             return
74         fi
75     fi
76
77     printf "    Creating new key: $alg_name                           "
78
79     params="--gen-key:$key_name $alg_name"
80     if [ -f $keysfile ] ; then
81         params="$params --keys-file $keysfile"  
82     fi
83
84     echo "$xmlsec_app keys $params $xmlsec_params $keysfile" >>  $logfile 
85     $VALGRIND $xmlsec_app keys $params $xmlsec_params $keysfile >> $logfile 2>> $logfile
86     printRes $?
87 }
88
89 echo "--- testKeys started for xmlsec-$crypto library ($timestamp) ---"
90 echo "--- LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
91 echo "--- log file is $logfile"
92 echo "--- testKeys started for xmlsec-$crypto library ($timestamp) ---" >> $logfile
93 echo "--- LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $logfile
94
95 # remove old keys file and copy NSS DB files if needed
96 rm -rf $keysfile
97 if [ "z$crypto" = "znss" ] ; then
98     cp -f $nssdbfolder/*.db $crypto_config
99 fi
100
101 execKeysTest \
102         "hmac" \
103         "test-hmac-sha1" \
104         "hmac-192"
105 execKeysTest \
106         "rsa " \
107         "test-rsa      " \
108         "rsa-1024"
109 execKeysTest \
110         "dsa " \
111         "test-dsa      " \
112         "dsa-1024"
113 execKeysTest \
114         "des " \
115         "test-des      " \
116         "des-192 "
117 execKeysTest \
118         "aes " \
119         "test-aes128   " \
120         "aes-128 "
121 execKeysTest \
122         "aes " \
123         "test-aes192   " \
124         "aes-192 "
125 execKeysTest \
126         "aes " \
127         "test-aes256   " \
128         "aes-256 "
129
130 echo "--- testKeys finished ---" >> $logfile
131 echo "--- testKeys finished ---"
132 echo "--- detailed log is written to  $logfile ---" 
133