Extend ciphersuite test coverage.
[openssl.git] / test / testssl
1 #!/bin/sh
2
3 if [ "$1" = "" ]; then
4   key=../apps/server.pem
5 else
6   key="$1"
7 fi
8 if [ "$2" = "" ]; then
9   cert=../apps/server.pem
10 else
11   cert="$2"
12 fi
13 ssltest="../util/shlib_wrap.sh ./ssltest -s_key $key -s_cert $cert -c_key $key -c_cert $cert"
14
15 if ../util/shlib_wrap.sh ../apps/openssl x509 -in $cert -text -noout | fgrep 'DSA Public Key' >/dev/null; then
16   dsa_cert=YES
17 else
18   dsa_cert=NO
19 fi
20
21 if [ "$3" = "" ]; then
22   CA="-CApath ../certs"
23 else
24   CA="-CAfile $3"
25 fi
26
27 if [ "$4" = "" ]; then
28   extra=""
29 else
30   extra="$4"
31 fi
32
33 serverinfo="./serverinfo.pem"
34
35 #############################################################################
36
37 echo test sslv3
38 $ssltest -ssl3 $extra || exit 1
39
40 echo test sslv3 with server authentication
41 $ssltest -ssl3 -server_auth $CA $extra || exit 1
42
43 echo test sslv3 with client authentication
44 $ssltest -ssl3 -client_auth $CA $extra || exit 1
45
46 echo test sslv3 with both client and server authentication
47 $ssltest -ssl3 -server_auth -client_auth $CA $extra || exit 1
48
49 echo test sslv2/sslv3
50 $ssltest $extra || exit 1
51
52 echo test sslv2/sslv3 with server authentication
53 $ssltest -server_auth $CA $extra || exit 1
54
55 echo test sslv2/sslv3 with client authentication
56 $ssltest -client_auth $CA $extra || exit 1
57
58 echo test sslv2/sslv3 with both client and server authentication
59 $ssltest -server_auth -client_auth $CA $extra || exit 1
60
61 echo test sslv3 via BIO pair
62 $ssltest -bio_pair -ssl3 $extra || exit 1
63
64 echo test sslv3 with server authentication via BIO pair
65 $ssltest -bio_pair -ssl3 -server_auth $CA $extra || exit 1
66
67 echo test sslv3 with client authentication via BIO pair
68 $ssltest -bio_pair -ssl3 -client_auth $CA $extra || exit 1
69
70 echo test sslv3 with both client and server authentication via BIO pair
71 $ssltest -bio_pair -ssl3 -server_auth -client_auth $CA $extra || exit 1
72
73 echo test sslv2/sslv3 via BIO pair
74 $ssltest $extra || exit 1
75
76 echo test dtlsv1
77 $ssltest -dtls1 $extra || exit 1
78
79 echo test dtlsv1 with server authentication
80 $ssltest -dtls1 -server_auth $CA $extra || exit 1
81
82 echo test dtlsv1 with client authentication
83 $ssltest -dtls1 -client_auth $CA $extra || exit 1
84
85 echo test dtlsv1 with both client and server authentication
86 $ssltest -dtls1 -server_auth -client_auth $CA $extra || exit 1
87
88 echo test dtlsv1.2
89 $ssltest -dtls12 $extra || exit 1
90
91 echo test dtlsv1.2 with server authentication
92 $ssltest -dtls12 -server_auth $CA $extra || exit 1
93
94 echo test dtlsv1.2 with client authentication
95 $ssltest -dtls12 -client_auth $CA $extra || exit 1
96
97 echo test dtlsv1.2 with both client and server authentication
98 $ssltest -dtls12 -server_auth -client_auth $CA $extra || exit 1
99
100 if [ $dsa_cert = NO ]; then
101   echo 'test sslv2/sslv3 w/o (EC)DHE via BIO pair'
102   $ssltest -bio_pair -no_dhe -no_ecdhe $extra || exit 1
103 fi
104
105 echo test sslv2/sslv3 with 1024bit DHE via BIO pair
106 $ssltest -bio_pair -dhe1024dsa -v $extra || exit 1
107
108 echo test sslv2/sslv3 with server authentication
109 $ssltest -bio_pair -server_auth $CA $extra || exit 1
110
111 echo test sslv2/sslv3 with client authentication via BIO pair
112 $ssltest -bio_pair -client_auth $CA $extra || exit 1
113
114 echo test sslv2/sslv3 with both client and server authentication via BIO pair
115 $ssltest -bio_pair -server_auth -client_auth $CA $extra || exit 1
116
117 echo test sslv2/sslv3 with both client and server authentication via BIO pair and app verify
118 $ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1
119
120 test_cipher() {
121     _cipher=$1
122     echo "Testing $_cipher"
123     prot=""
124     if [ $2 = "SSLv3" ] ; then
125       prot="-ssl3"
126     fi
127     _exarg=$3
128     $ssltest $_exarg -cipher $_cipher $prot
129     if [ $? -ne 0 ] ; then
130           echo "Failed $_cipher"
131           exit 1
132     fi
133 }
134
135 echo "Testing ciphersuites"
136 exkeys=""
137 ciphers="-EXP:-PSK:-SRP:-kDH:-kECDHe"
138 if ../util/shlib_wrap.sh ../apps/openssl no-dhparam >/dev/null; then
139   echo "skipping DHE tests"
140   ciphers="$ciphers:-kDHE"
141 fi
142 if ../util/shlib_wrap.sh ../apps/openssl no-dsa >/dev/null; then
143   echo "skipping DSA tests"
144   ciphers="$ciphers:-aDSA"
145 else
146   exkeys="$exkeys -s_cert certD.ss -s_key keyD.ss"
147 fi
148
149 if ../util/shlib_wrap.sh ../apps/openssl no-ec >/dev/null; then
150   echo "skipping EC tests"
151   ciphers="$ciphers:!aECDSA:!kECDH"
152 else
153   exkeys="$exkeys -s_cert certE.ss -s_key keyE.ss"
154 fi
155
156 for protocol in TLSv1.2 SSLv3; do
157   echo "Testing ciphersuites for $protocol"
158   for cipher in `../util/shlib_wrap.sh ../apps/openssl ciphers "$protocol:$ciphers" | tr ':' ' '`; do
159     test_cipher $cipher $protocol "$exkeys"
160   done
161     echo "testing connection with weak DH, expecting failure"
162     if [ $protocol = "SSLv3" ] ; then
163       $ssltest -s_cipher "EDH" -c_cipher "EDH:@SECLEVEL=1" -dhe512 -ssl3
164     else
165       $ssltest -s_cipher "EDH" -c_cipher "EDH:@SECLEVEL=1" -dhe512
166     fi
167     if [ $? -eq 0 ]; then
168       echo "FAIL: connection with weak DH succeeded"
169       exit 1
170     fi
171 done
172
173 #############################################################################
174
175 if ../util/shlib_wrap.sh ../apps/openssl no-dhparam; then
176   echo skipping anonymous DH tests
177 else
178   echo test tls1 with 1024bit anonymous DH, multiple handshakes
179   $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1
180 fi
181
182 if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
183   echo skipping RSA tests
184 else
185   echo 'test tls1 with 1024bit RSA, no (EC)DHE, multiple handshakes'
186   ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -s_cert ../apps/server2.pem -no_dhe -no_ecdhe -num 10 -f -time $extra || exit 1
187
188   if ../util/shlib_wrap.sh ../apps/openssl no-dhparam; then
189     echo skipping RSA+DHE tests
190   else
191     echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes
192     ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -s_cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1
193   fi
194 fi
195
196 echo test tls1 with PSK
197 $ssltest -tls1 -cipher PSK -psk abc123 $extra || exit 1
198
199 echo test tls1 with PSK via BIO pair
200 $ssltest -bio_pair -tls1 -cipher PSK -psk abc123 $extra || exit 1
201
202 #############################################################################
203 # Next Protocol Negotiation Tests
204
205 $ssltest -bio_pair -tls1 -npn_client || exit 1
206 $ssltest -bio_pair -tls1 -npn_server || exit 1
207 $ssltest -bio_pair -tls1 -npn_server_reject || exit 1
208 $ssltest -bio_pair -tls1 -npn_client -npn_server_reject || exit 1
209 $ssltest -bio_pair -tls1 -npn_client -npn_server || exit 1
210 $ssltest -bio_pair -tls1 -npn_client -npn_server -num 2 || exit 1
211 $ssltest -bio_pair -tls1 -npn_client -npn_server -num 2 -reuse || exit 1
212
213 #############################################################################
214 # Custom Extension tests
215
216 echo test tls1 with custom extensions
217 $ssltest -bio_pair -tls1 -custom_ext || exit 1
218
219 #############################################################################
220 # Serverinfo tests
221
222 echo test tls1 with serverinfo
223 $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo || exit 1
224 $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo -serverinfo_sct || exit 1
225 $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo -serverinfo_tack || exit 1
226 $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo -serverinfo_sct -serverinfo_tack || exit 1
227 $ssltest -bio_pair -tls1 -custom_ext -serverinfo_file $serverinfo -serverinfo_sct -serverinfo_tack || exit 1
228
229
230 #############################################################################
231 # ALPN tests
232
233 $ssltest -bio_pair -tls1 -alpn_client foo -alpn_server bar || exit 1
234 $ssltest -bio_pair -tls1 -alpn_client foo -alpn_server foo -alpn_expected foo || exit 1
235 $ssltest -bio_pair -tls1 -alpn_client foo,bar -alpn_server foo -alpn_expected foo || exit 1
236 $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server foo -alpn_expected foo || exit 1
237 $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server foo,bar -alpn_expected foo || exit 1
238 $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server bar,foo -alpn_expected bar || exit 1
239 $ssltest -bio_pair -tls1 -alpn_client foo,bar -alpn_server bar,foo -alpn_expected bar || exit 1
240 $ssltest -bio_pair -tls1 -alpn_client baz -alpn_server bar,foo || exit 1
241
242 if ../util/shlib_wrap.sh ../apps/openssl no-srp; then
243   echo skipping SRP tests
244 else
245   echo test tls1 with SRP
246   $ssltest -tls1 -cipher SRP -srpuser test -srppass abc123 || exit 1
247
248   echo test tls1 with SRP via BIO pair
249   $ssltest -bio_pair -tls1 -cipher SRP -srpuser test -srppass abc123 || exit 1
250
251   echo test tls1 with SRP auth
252   $ssltest -tls1 -cipher aSRP -srpuser test -srppass abc123 || exit 1
253
254   echo test tls1 with SRP auth via BIO pair
255   $ssltest -bio_pair -tls1 -cipher aSRP -srpuser test -srppass abc123 || exit 1
256 fi
257
258 #############################################################################
259 # Multi-buffer tests
260
261 if [ -z "$extra" -a `uname -m` = "x86_64" ]; then
262   $ssltest -cipher AES128-SHA    -bytes 8m      || exit 1
263   $ssltest -cipher AES128-SHA256 -bytes 8m      || exit 1
264 fi
265
266 exit 0