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