summaryrefslogtreecommitdiff
path: root/tests/testKeys.sh
blob: 385caf376c8c2c9a19a36a07af161257608ae326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh

crypto=$1
topfolder=$2
xmlsec_app=$3
file_format=$4

pub_key_format=$file_format
cert_format=$file_format
priv_key_option="--pkcs12"
priv_key_format="p12"

if [ "z$TMPFOLDER" = "z" ] ; then
    TMPFOLDER=/tmp
fi

timestamp=`date +%Y%m%d_%H%M%S` 
tmpfile=$TMPFOLDER/testKeys.$timestamp-$$.tmp
logfile=$TMPFOLDER/testKeys.$timestamp-$$.log
script="$0"
nssdbfolder=$topfolder/nssdb

# prepate crypto config folder
crypto_config=$TMPFOLDER/xmlsec-crypto-config
keysfile=$crypto_config/keys.xml
mkdir -p $crypto_config
rm -rf $crypto_config/*

valgrind_suppression="--suppressions=$topfolder/openssl.supp --suppressions=$topfolder/nss.supp"
valgrind_options="--leak-check=yes --show-reachable=yes --num-callers=32 -v"


if [ "z$crypto" != "z" -a "z$crypto" != "zdefault" ] ; then
    xmlsec_params="$xmlsec_params --crypto $crypto"
fi
xmlsec_params="$xmlsec_params --crypto-config $crypto_config"

if [ -n "$DEBUG_MEMORY" ] ; then 
    export VALGRIND="valgrind $valgrind_options"
    export REPEAT=3
    xmlsec_params="$xmlsec_params --repeat $REPEAT"
fi

if [ -n "$PERF_TEST" ] ; then 
    export xmlsec_params="$xmlsec_params --repeat $PERF_TEST"
fi

printRes() {	
    if [ $1 = 0 ]; then
	echo "   OK"
    else 
        echo " Fail"
    fi
    if [ -f .memdump ] ; then 
	cat .memdump >> $logfile 
    fi
}

execKeysTest() {    
    req_key_data=$1
    key_name=$2
    alg_name=$3

    if [ -n "$req_key_data" ] ; then
	printf "    Checking $req_key_data key data presense                      "
        echo "$xmlsec_app check-key-data $req_key_data" >> $logfile
	$xmlsec_app check-key-data $req_key_data >> $logfile 2>> $logfile
	res=$?
	if [ $res = 0 ]; then
    	    echo "   OK"	    
	else
	    echo " Skip"
	    return
	fi
    fi

    printf "    Creating new key: $alg_name                           "

    params="--gen-key:$key_name $alg_name"
    if [ -f $keysfile ] ; then
	params="$params --keys-file $keysfile"	
    fi

    echo "$xmlsec_app keys $params $xmlsec_params $keysfile" >>  $logfile 
    $VALGRIND $xmlsec_app keys $params $xmlsec_params $keysfile >> $logfile 2>> $logfile
    printRes $?
}

echo "--- testKeys started for xmlsec-$crypto library ($timestamp) ---"
echo "--- LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
echo "--- log file is $logfile"
echo "--- testKeys started for xmlsec-$crypto library ($timestamp) ---" >> $logfile
echo "--- LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $logfile

# remove old keys file and copy NSS DB files if needed
rm -rf $keysfile
if [ "z$crypto" = "znss" ] ; then
    cp -f $nssdbfolder/*.db $crypto_config
fi

execKeysTest \
	"hmac" \
	"test-hmac-sha1" \
	"hmac-192"
execKeysTest \
	"rsa " \
	"test-rsa      " \
	"rsa-1024"
execKeysTest \
	"dsa " \
	"test-dsa      " \
	"dsa-1024"
execKeysTest \
	"des " \
	"test-des      " \
    	"des-192 "
execKeysTest \
	"aes " \
	"test-aes128   " \
	"aes-128 "
execKeysTest \
	"aes " \
	"test-aes192   " \
	"aes-192 "
execKeysTest \
	"aes " \
	"test-aes256   " \
	"aes-256 "

echo "--- testKeys finished ---" >> $logfile
echo "--- testKeys finished ---"
echo "--- detailed log is written to  $logfile ---"