blob: f375b1b8e41d24598a37b8270148b40859359d43 [file] [log] [blame]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +01001#!/bin/sh
2
3# Test various options that are not covered by compat.sh
4#
5# Here the goal is not to cover every ciphersuite/version, but
6# rather specific options (max fragment length, truncated hmac, etc)
7# or procedures (session resumption from cache or ticket, renego, etc).
8#
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02009# Assumes a build with default options.
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010010
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010011set -u
12
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010013# default values, can be overriden by the environment
14: ${P_SRV:=../programs/ssl/ssl_server2}
15: ${P_CLI:=../programs/ssl/ssl_client2}
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +020016: ${P_PXY:=../programs/test/udp_proxy}
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010017: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020018: ${GNUTLS_CLI:=gnutls-cli}
19: ${GNUTLS_SERV:=gnutls-serv}
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010020
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +020021O_SRV="$OPENSSL_CMD s_server -cert data_files/server5.crt -key data_files/server5.key"
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010022O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020023G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
24G_CLI="$GNUTLS_CLI"
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010025
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010026TESTS=0
27FAILS=0
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020028SKIPS=0
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010029
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +020030CONFIG_H='../include/polarssl/config.h'
31
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010032MEMCHECK=0
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010033FILTER='.*'
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020034EXCLUDE='^$'
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010035
36print_usage() {
37 echo "Usage: $0 [options]"
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010038 echo -e " -h|--help\tPrint this help."
39 echo -e " -m|--memcheck\tCheck memory leaks and errors."
40 echo -e " -f|--filter\tOnly matching tests are executed (default: '$FILTER')"
41 echo -e " -e|--exclude\tMatching tests are excluded (default: '$EXCLUDE')"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010042}
43
44get_options() {
45 while [ $# -gt 0 ]; do
46 case "$1" in
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010047 -f|--filter)
48 shift; FILTER=$1
49 ;;
50 -e|--exclude)
51 shift; EXCLUDE=$1
52 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010053 -m|--memcheck)
54 MEMCHECK=1
55 ;;
56 -h|--help)
57 print_usage
58 exit 0
59 ;;
60 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +020061 echo "Unknown argument: '$1'"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010062 print_usage
63 exit 1
64 ;;
65 esac
66 shift
67 done
68}
69
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020070# skip next test if OpenSSL can't send SSLv2 ClientHello
71requires_openssl_with_sslv2() {
72 if [ -z "${OPENSSL_HAS_SSL2:-}" ]; then
Manuel Pégourié-Gonnarda4afadf2014-08-30 22:09:36 +020073 if $OPENSSL_CMD ciphers -ssl2 >/dev/null 2>&1; then
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020074 OPENSSL_HAS_SSL2="YES"
75 else
76 OPENSSL_HAS_SSL2="NO"
77 fi
78 fi
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +020079
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020080 if [ "$OPENSSL_HAS_SSL2" = "NO" ]; then
81 SKIP_NEXT="YES"
82 fi
83}
84
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020085# skip next test if GnuTLS isn't available
86requires_gnutls() {
87 if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
88 if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null; then
89 GNUTLS_AVAILABLE="YES"
90 else
91 GNUTLS_AVAILABLE="NO"
92 fi
93 fi
94 if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
95 SKIP_NEXT="YES"
96 fi
97}
98
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +020099# skip next test if IPv6 isn't available on this host
100requires_ipv6() {
101 if [ -z "${HAS_IPV6:-}" ]; then
102 $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
103 SRV_PID=$!
104 sleep 1
105 kill $SRV_PID >/dev/null 2>&1
106 if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
107 HAS_IPV6="NO"
108 else
109 HAS_IPV6="YES"
110 fi
111 rm -r $SRV_OUT
112 fi
113
114 if [ "$HAS_IPV6" = "NO" ]; then
115 SKIP_NEXT="YES"
116 fi
117}
118
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100119# print_name <name>
120print_name() {
121 echo -n "$1 "
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200122 LEN=$(( 72 - `echo "$1" | wc -c` ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100123 for i in `seq 1 $LEN`; do echo -n '.'; done
124 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100125
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200126 TESTS=$(( $TESTS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100127}
128
129# fail <message>
130fail() {
131 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +0100132 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100133
Manuel Pégourié-Gonnardc2b00922014-08-31 16:46:04 +0200134 mv $SRV_OUT o-srv-${TESTS}.log
135 mv $CLI_OUT o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200136 if [ -n "$PXY_CMD" ]; then
137 mv $PXY_OUT o-pxy-${TESTS}.log
138 fi
139 echo " ! outputs saved to o-XXX-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100140
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200141 if [ "X${USER:-}" = Xbuildbot -o "X${LOGNAME:-}" = Xbuildbot ]; then
142 echo " ! server output:"
143 cat o-srv-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200144 echo " ! ========================================================"
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200145 echo " ! client output:"
146 cat o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200147 if [ -n "$PXY_CMD" ]; then
148 echo " ! ========================================================"
149 echo " ! proxy output:"
150 cat o-pxy-${TESTS}.log
151 fi
152 echo ""
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200153 fi
154
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200155 FAILS=$(( $FAILS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100156}
157
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100158# is_polar <cmd_line>
159is_polar() {
160 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
161}
162
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100163# has_mem_err <log_file_name>
164has_mem_err() {
165 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
166 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
167 then
168 return 1 # false: does not have errors
169 else
170 return 0 # true: has errors
171 fi
172}
173
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200174# wait for server to start: two versions depending on lsof availability
175wait_server_start() {
176 if which lsof >/dev/null; then
177 # make sure we don't loop forever
178 ( sleep "$DOG_DELAY"; echo "SERVERSTART TIMEOUT"; kill $MAIN_PID ) &
179 WATCHDOG_PID=$!
180
181 # make a tight loop, server usually takes less than 1 sec to start
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200182 if [ "$DTLS" -eq 1 ]; then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200183 until lsof -nbi UDP:"$SRV_PORT" | grep UDP >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200184 else
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200185 until lsof -nbi TCP:"$SRV_PORT" | grep LISTEN >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200186 fi
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200187
188 kill $WATCHDOG_PID
189 wait $WATCHDOG_PID
190 else
191 sleep "$START_DELAY"
192 fi
193}
194
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200195# wait for client to terminate and set CLI_EXIT
196# must be called right after starting the client
197wait_client_done() {
198 CLI_PID=$!
199
200 ( sleep "$DOG_DELAY"; echo "TIMEOUT" >> $CLI_OUT; kill $CLI_PID ) &
201 WATCHDOG_PID=$!
202
203 wait $CLI_PID
204 CLI_EXIT=$?
205
206 kill $WATCHDOG_PID
207 wait $WATCHDOG_PID
208
209 echo "EXIT: $CLI_EXIT" >> $CLI_OUT
210}
211
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200212# check if the given command uses dtls and sets global variable DTLS
213detect_dtls() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200214 if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200215 DTLS=1
216 else
217 DTLS=0
218 fi
219}
220
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200221# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100222# Options: -s pattern pattern that must be present in server output
223# -c pattern pattern that must be present in client output
224# -S pattern pattern that must be absent in server output
225# -C pattern pattern that must be absent in client output
226run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100227 NAME="$1"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200228 shift 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100229
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100230 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
231 else
232 return
233 fi
234
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100235 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100236
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200237 # should we skip?
238 if [ "X$SKIP_NEXT" = "XYES" ]; then
239 SKIP_NEXT="NO"
240 echo "SKIP"
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200241 SKIPS=$(( $SKIPS + 1 ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200242 return
243 fi
244
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200245 # does this test use a proxy?
246 if [ "X$1" = "X-p" ]; then
247 PXY_CMD="$2"
248 shift 2
249 else
250 PXY_CMD=""
251 fi
252
253 # get commands and client output
254 SRV_CMD="$1"
255 CLI_CMD="$2"
256 CLI_EXPECT="$3"
257 shift 3
258
259 # fix client port
260 if [ -n "$PXY_CMD" ]; then
261 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
262 else
263 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
264 fi
265
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200266 # update DTLS variable
267 detect_dtls "$SRV_CMD"
268
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100269 # prepend valgrind to our commands if active
270 if [ "$MEMCHECK" -gt 0 ]; then
271 if is_polar "$SRV_CMD"; then
272 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
273 fi
274 if is_polar "$CLI_CMD"; then
275 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
276 fi
277 fi
278
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100279 # run the commands
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200280 if [ -n "$PXY_CMD" ]; then
281 echo "$PXY_CMD" > $PXY_OUT
282 eval "$PXY_CMD" >> $PXY_OUT 2>&1 &
283 PXY_PID=$!
284 # assume proxy starts faster than server
285 fi
286
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200287 echo "$SRV_CMD" > $SRV_OUT
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200288 # "yes" is for servers without -www (openssl with DTLS)
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +0200289 yes blabla | $SRV_CMD >> $SRV_OUT 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100290 SRV_PID=$!
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200291 wait_server_start
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200292
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200293 echo "$CLI_CMD" > $CLI_OUT
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200294 eval "$CLI_CMD" >> $CLI_OUT 2>&1 &
295 wait_client_done
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100296
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200297 # terminate the server (and the proxy)
Manuel Pégourié-Gonnard74b11702014-08-14 15:47:33 +0200298 kill $SRV_PID
299 wait $SRV_PID
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200300 if [ -n "$PXY_CMD" ]; then
301 kill $PXY_PID
302 wait $PXY_PID
303 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100304
305 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200306 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100307 # expected client exit to incorrectly succeed in case of catastrophic
308 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100309 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200310 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100311 else
312 fail "server failed to start"
313 return
314 fi
315 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100316 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200317 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100318 else
319 fail "client failed to start"
320 return
321 fi
322 fi
323
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100324 # check server exit code
325 if [ $? != 0 ]; then
326 fail "server fail"
327 return
328 fi
329
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100330 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100331 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
332 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100333 then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200334 fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100335 return
336 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100337
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100338 # check other assertions
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200339 # lines beginning with == are added by valgrind, ignore them
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100340 while [ $# -gt 0 ]
341 do
342 case $1 in
343 "-s")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200344 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100345 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100346 return
347 fi
348 ;;
349
350 "-c")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200351 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100352 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100353 return
354 fi
355 ;;
356
357 "-S")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200358 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100359 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100360 return
361 fi
362 ;;
363
364 "-C")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200365 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100366 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100367 return
368 fi
369 ;;
370
371 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200372 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100373 exit 1
374 esac
375 shift 2
376 done
377
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100378 # check valgrind's results
379 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200380 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100381 fail "Server has memory errors"
382 return
383 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200384 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100385 fail "Client has memory errors"
386 return
387 fi
388 fi
389
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100390 # if we're here, everything is ok
391 echo "PASS"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200392 rm -f $SRV_OUT $CLI_OUT $PXY_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100393}
394
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100395cleanup() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200396 rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200397 kill $SRV_PID >/dev/null 2>&1
398 kill $WATCHDOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200399 if [ -n "$PXY_CMD" ]; then
400 kill $PXY_PID >/dev/null 2>&1
401 fi
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100402 exit 1
403}
404
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100405#
406# MAIN
407#
408
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100409get_options "$@"
410
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100411# sanity checks, avoid an avalanche of errors
412if [ ! -x "$P_SRV" ]; then
413 echo "Command '$P_SRV' is not an executable file"
414 exit 1
415fi
416if [ ! -x "$P_CLI" ]; then
417 echo "Command '$P_CLI' is not an executable file"
418 exit 1
419fi
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200420if [ ! -x "$P_PXY" ]; then
421 echo "Command '$P_PXY' is not an executable file"
422 exit 1
423fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100424if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
425 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100426 exit 1
427fi
428
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200429# used by watchdog
430MAIN_PID="$$"
431
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200432# be more patient with valgrind
433if [ "$MEMCHECK" -gt 0 ]; then
434 START_DELAY=3
435 DOG_DELAY=30
436else
437 START_DELAY=1
438 DOG_DELAY=10
439fi
440
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200441# Pick a "unique" server port in the range 10000-19999, and a proxy port
442PORT_BASE="0000$$"
443PORT_BASE="$( echo -n $PORT_BASE | tail -c 4 )"
444SRV_PORT="1$PORT_BASE"
445PXY_PORT="2$PORT_BASE"
446unset PORT_BASE
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200447
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200448# fix commands to use this port, force IPv4 while at it
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200449P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
450P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
451P_PXY="$P_PXY server_addr=127.0.0.1 server_port=$SRV_PORT listen_addr=127.0.0.1 listen_port=$PXY_PORT"
452O_SRV="$O_SRV -accept $SRV_PORT"
453O_CLI="$O_CLI -connect localhost:+SRV_PORT"
454G_SRV="$G_SRV -p $SRV_PORT"
455G_CLI="$G_CLI -p +SRV_PORT"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200456
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200457# Also pick a unique name for intermediate files
458SRV_OUT="srv_out.$$"
459CLI_OUT="cli_out.$$"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200460PXY_OUT="pxy_out.$$"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200461SESSION="session.$$"
462
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200463SKIP_NEXT="NO"
464
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100465trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100466
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200467# Basic test
468
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200469# Checks that:
470# - things work with all ciphersuites active (used with config-full in all.sh)
471# - the expected (highest security) parameters are selected
472# ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200473run_test "Default" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200474 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200475 "$P_CLI" \
476 0 \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200477 -s "Protocol is TLSv1.2" \
478 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
479 -s "client hello v3, signature_algorithm ext: 6" \
480 -s "ECDHE curve: secp521r1" \
481 -S "error" \
482 -C "error"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200483
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100484# Test for SSLv2 ClientHello
485
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200486requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200487run_test "SSLv2 ClientHello: reference" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100488 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100489 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100490 0 \
491 -S "parse client hello v2" \
492 -S "ssl_handshake returned"
493
494# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200495requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200496run_test "SSLv2 ClientHello: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200497 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100498 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100499 0 \
500 -s "parse client hello v2" \
501 -S "ssl_handshake returned"
502
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100503# Tests for Truncated HMAC extension
504
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200505run_test "Truncated HMAC: reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200506 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100507 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100508 0 \
509 -s "dumping 'computed mac' (20 bytes)"
510
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200511run_test "Truncated HMAC: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200512 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100513 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100514 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100515 -s "dumping 'computed mac' (10 bytes)"
516
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100517# Tests for Session Tickets
518
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200519run_test "Session resume using tickets: basic" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200520 "$P_SRV debug_level=3 tickets=1" \
521 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100522 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100523 -c "client hello, adding session ticket extension" \
524 -s "found session ticket extension" \
525 -s "server hello, adding session ticket extension" \
526 -c "found session_ticket extension" \
527 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100528 -S "session successfully restored from cache" \
529 -s "session successfully restored from ticket" \
530 -s "a session has been resumed" \
531 -c "a session has been resumed"
532
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200533run_test "Session resume using tickets: cache disabled" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200534 "$P_SRV debug_level=3 tickets=1 cache_max=0" \
535 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100536 0 \
537 -c "client hello, adding session ticket extension" \
538 -s "found session ticket extension" \
539 -s "server hello, adding session ticket extension" \
540 -c "found session_ticket extension" \
541 -c "parse new session ticket" \
542 -S "session successfully restored from cache" \
543 -s "session successfully restored from ticket" \
544 -s "a session has been resumed" \
545 -c "a session has been resumed"
546
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200547run_test "Session resume using tickets: timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200548 "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
549 "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100550 0 \
551 -c "client hello, adding session ticket extension" \
552 -s "found session ticket extension" \
553 -s "server hello, adding session ticket extension" \
554 -c "found session_ticket extension" \
555 -c "parse new session ticket" \
556 -S "session successfully restored from cache" \
557 -S "session successfully restored from ticket" \
558 -S "a session has been resumed" \
559 -C "a session has been resumed"
560
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200561run_test "Session resume using tickets: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100562 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200563 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100564 0 \
565 -c "client hello, adding session ticket extension" \
566 -c "found session_ticket extension" \
567 -c "parse new session ticket" \
568 -c "a session has been resumed"
569
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200570run_test "Session resume using tickets: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200571 "$P_SRV debug_level=3 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200572 "( $O_CLI -sess_out $SESSION; \
573 $O_CLI -sess_in $SESSION; \
574 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100575 0 \
576 -s "found session ticket extension" \
577 -s "server hello, adding session ticket extension" \
578 -S "session successfully restored from cache" \
579 -s "session successfully restored from ticket" \
580 -s "a session has been resumed"
581
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100582# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100583
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200584run_test "Session resume using cache: tickets enabled on client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200585 "$P_SRV debug_level=3 tickets=0" \
586 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100587 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100588 -c "client hello, adding session ticket extension" \
589 -s "found session ticket extension" \
590 -S "server hello, adding session ticket extension" \
591 -C "found session_ticket extension" \
592 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100593 -s "session successfully restored from cache" \
594 -S "session successfully restored from ticket" \
595 -s "a session has been resumed" \
596 -c "a session has been resumed"
597
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200598run_test "Session resume using cache: tickets enabled on server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200599 "$P_SRV debug_level=3 tickets=1" \
600 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100601 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100602 -C "client hello, adding session ticket extension" \
603 -S "found session ticket extension" \
604 -S "server hello, adding session ticket extension" \
605 -C "found session_ticket extension" \
606 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100607 -s "session successfully restored from cache" \
608 -S "session successfully restored from ticket" \
609 -s "a session has been resumed" \
610 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100611
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200612run_test "Session resume using cache: cache_max=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200613 "$P_SRV debug_level=3 tickets=0 cache_max=0" \
614 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100615 0 \
616 -S "session successfully restored from cache" \
617 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100618 -S "a session has been resumed" \
619 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100620
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200621run_test "Session resume using cache: cache_max=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200622 "$P_SRV debug_level=3 tickets=0 cache_max=1" \
623 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100624 0 \
625 -s "session successfully restored from cache" \
626 -S "session successfully restored from ticket" \
627 -s "a session has been resumed" \
628 -c "a session has been resumed"
629
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200630run_test "Session resume using cache: timemout > delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200631 "$P_SRV debug_level=3 tickets=0" \
632 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100633 0 \
634 -s "session successfully restored from cache" \
635 -S "session successfully restored from ticket" \
636 -s "a session has been resumed" \
637 -c "a session has been resumed"
638
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200639run_test "Session resume using cache: timeout < delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200640 "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
641 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100642 0 \
643 -S "session successfully restored from cache" \
644 -S "session successfully restored from ticket" \
645 -S "a session has been resumed" \
646 -C "a session has been resumed"
647
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200648run_test "Session resume using cache: no timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200649 "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
650 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100651 0 \
652 -s "session successfully restored from cache" \
653 -S "session successfully restored from ticket" \
654 -s "a session has been resumed" \
655 -c "a session has been resumed"
656
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200657run_test "Session resume using cache: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200658 "$P_SRV debug_level=3 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200659 "( $O_CLI -sess_out $SESSION; \
660 $O_CLI -sess_in $SESSION; \
661 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100662 0 \
663 -s "found session ticket extension" \
664 -S "server hello, adding session ticket extension" \
665 -s "session successfully restored from cache" \
666 -S "session successfully restored from ticket" \
667 -s "a session has been resumed"
668
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200669run_test "Session resume using cache: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100670 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200671 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100672 0 \
673 -C "found session_ticket extension" \
674 -C "parse new session ticket" \
675 -c "a session has been resumed"
676
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100677# Tests for Max Fragment Length extension
678
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200679run_test "Max fragment length: not used, reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200680 "$P_SRV debug_level=3" \
681 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100682 0 \
683 -C "client hello, adding max_fragment_length extension" \
684 -S "found max fragment length extension" \
685 -S "server hello, max_fragment_length extension" \
686 -C "found max_fragment_length extension"
687
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200688run_test "Max fragment length: used by client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200689 "$P_SRV debug_level=3" \
690 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100691 0 \
692 -c "client hello, adding max_fragment_length extension" \
693 -s "found max fragment length extension" \
694 -s "server hello, max_fragment_length extension" \
695 -c "found max_fragment_length extension"
696
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200697run_test "Max fragment length: used by server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200698 "$P_SRV debug_level=3 max_frag_len=4096" \
699 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100700 0 \
701 -C "client hello, adding max_fragment_length extension" \
702 -S "found max fragment length extension" \
703 -S "server hello, max_fragment_length extension" \
704 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100705
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200706requires_gnutls
707run_test "Max fragment length: gnutls server" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200708 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200709 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200710 0 \
711 -c "client hello, adding max_fragment_length extension" \
712 -c "found max_fragment_length extension"
713
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100714# Tests for renegotiation
715
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200716run_test "Renegotiation: none, for reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200717 "$P_SRV debug_level=3 exchanges=2" \
718 "$P_CLI debug_level=3 exchanges=2" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100719 0 \
720 -C "client hello, adding renegotiation extension" \
721 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
722 -S "found renegotiation extension" \
723 -s "server hello, secure renegotiation extension" \
724 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100725 -C "=> renegotiate" \
726 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100727 -S "write hello request"
728
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200729run_test "Renegotiation: client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200730 "$P_SRV debug_level=3 exchanges=2 renegotiation=1" \
731 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100732 0 \
733 -c "client hello, adding renegotiation extension" \
734 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
735 -s "found renegotiation extension" \
736 -s "server hello, secure renegotiation extension" \
737 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100738 -c "=> renegotiate" \
739 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100740 -S "write hello request"
741
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200742run_test "Renegotiation: server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200743 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
744 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100745 0 \
746 -c "client hello, adding renegotiation extension" \
747 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
748 -s "found renegotiation extension" \
749 -s "server hello, secure renegotiation extension" \
750 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100751 -c "=> renegotiate" \
752 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100753 -s "write hello request"
754
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200755run_test "Renegotiation: double" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200756 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
757 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100758 0 \
759 -c "client hello, adding renegotiation extension" \
760 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
761 -s "found renegotiation extension" \
762 -s "server hello, secure renegotiation extension" \
763 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100764 -c "=> renegotiate" \
765 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100766 -s "write hello request"
767
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200768run_test "Renegotiation: client-initiated, server-rejected" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200769 "$P_SRV debug_level=3 exchanges=2 renegotiation=0" \
770 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100771 1 \
772 -c "client hello, adding renegotiation extension" \
773 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
774 -S "found renegotiation extension" \
775 -s "server hello, secure renegotiation extension" \
776 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100777 -c "=> renegotiate" \
778 -S "=> renegotiate" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200779 -S "write hello request" \
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +0200780 -c "SSL - Unexpected message at ServerHello in renegotiation" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200781 -c "failed"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100782
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200783run_test "Renegotiation: server-initiated, client-rejected, default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200784 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
785 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100786 0 \
787 -C "client hello, adding renegotiation extension" \
788 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
789 -S "found renegotiation extension" \
790 -s "server hello, secure renegotiation extension" \
791 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100792 -C "=> renegotiate" \
793 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100794 -s "write hello request" \
Manuel Pégourié-Gonnarda9964db2014-07-03 19:29:16 +0200795 -S "SSL - An unexpected message was received from our peer" \
796 -S "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100797
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200798run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200799 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200800 renego_delay=-1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200801 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200802 0 \
803 -C "client hello, adding renegotiation extension" \
804 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
805 -S "found renegotiation extension" \
806 -s "server hello, secure renegotiation extension" \
807 -c "found renegotiation extension" \
808 -C "=> renegotiate" \
809 -S "=> renegotiate" \
810 -s "write hello request" \
811 -S "SSL - An unexpected message was received from our peer" \
812 -S "failed"
813
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200814# delay 2 for 1 alert record + 1 application data record
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200815run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200816 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200817 renego_delay=2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200818 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200819 0 \
820 -C "client hello, adding renegotiation extension" \
821 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
822 -S "found renegotiation extension" \
823 -s "server hello, secure renegotiation extension" \
824 -c "found renegotiation extension" \
825 -C "=> renegotiate" \
826 -S "=> renegotiate" \
827 -s "write hello request" \
828 -S "SSL - An unexpected message was received from our peer" \
829 -S "failed"
830
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200831run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200832 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200833 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200834 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200835 0 \
836 -C "client hello, adding renegotiation extension" \
837 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
838 -S "found renegotiation extension" \
839 -s "server hello, secure renegotiation extension" \
840 -c "found renegotiation extension" \
841 -C "=> renegotiate" \
842 -S "=> renegotiate" \
843 -s "write hello request" \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200844 -s "SSL - An unexpected message was received from our peer"
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200845
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200846run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200847 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200848 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200849 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200850 0 \
851 -c "client hello, adding renegotiation extension" \
852 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
853 -s "found renegotiation extension" \
854 -s "server hello, secure renegotiation extension" \
855 -c "found renegotiation extension" \
856 -c "=> renegotiate" \
857 -s "=> renegotiate" \
858 -s "write hello request" \
859 -S "SSL - An unexpected message was received from our peer" \
860 -S "failed"
861
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200862run_test "Renegotiation: nbio, client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200863 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
864 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200865 0 \
866 -c "client hello, adding renegotiation extension" \
867 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
868 -s "found renegotiation extension" \
869 -s "server hello, secure renegotiation extension" \
870 -c "found renegotiation extension" \
871 -c "=> renegotiate" \
872 -s "=> renegotiate" \
873 -S "write hello request"
874
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200875run_test "Renegotiation: nbio, server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200876 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
877 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200878 0 \
879 -c "client hello, adding renegotiation extension" \
880 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
881 -s "found renegotiation extension" \
882 -s "server hello, secure renegotiation extension" \
883 -c "found renegotiation extension" \
884 -c "=> renegotiate" \
885 -s "=> renegotiate" \
886 -s "write hello request"
887
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200888run_test "Renegotiation: openssl server, client-initiated" \
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +0200889 "$O_SRV -www" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200890 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200891 0 \
892 -c "client hello, adding renegotiation extension" \
893 -c "found renegotiation extension" \
894 -c "=> renegotiate" \
895 -C "ssl_handshake returned" \
896 -C "error" \
897 -c "HTTP/1.0 200 [Oo][Kk]"
898
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200899run_test "Renegotiation: gnutls server, client-initiated" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200900 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200901 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200902 0 \
903 -c "client hello, adding renegotiation extension" \
904 -c "found renegotiation extension" \
905 -c "=> renegotiate" \
906 -C "ssl_handshake returned" \
907 -C "error" \
908 -c "HTTP/1.0 200 [Oo][Kk]"
909
Manuel Pégourié-Gonnard30d16eb2014-08-19 17:43:50 +0200910run_test "Renegotiation: DTLS, client-initiated" \
911 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
912 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
913 0 \
914 -c "client hello, adding renegotiation extension" \
915 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
916 -s "found renegotiation extension" \
917 -s "server hello, secure renegotiation extension" \
918 -c "found renegotiation extension" \
919 -c "=> renegotiate" \
920 -s "=> renegotiate" \
921 -S "write hello request"
922
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +0200923run_test "Renegotiation: DTLS, server-initiated" \
924 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
925 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
926 0 \
927 -c "client hello, adding renegotiation extension" \
928 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
929 -s "found renegotiation extension" \
930 -s "server hello, secure renegotiation extension" \
931 -c "found renegotiation extension" \
932 -c "=> renegotiate" \
933 -s "=> renegotiate" \
934 -s "write hello request"
935
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +0200936run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
937 "$G_SRV -u --mtu 4096" \
938 "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
939 0 \
940 -c "client hello, adding renegotiation extension" \
941 -c "found renegotiation extension" \
942 -c "=> renegotiate" \
943 -C "ssl_handshake returned" \
944 -C "error" \
945 -s "Extra-header:"
946
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100947# Tests for auth_mode
948
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200949run_test "Authentication: server badcert, client required" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100950 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100951 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200952 "$P_CLI debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100953 1 \
954 -c "x509_verify_cert() returned" \
955 -c "! self-signed or not signed by a trusted CA" \
956 -c "! ssl_handshake returned" \
957 -c "X509 - Certificate verification failed"
958
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200959run_test "Authentication: server badcert, client optional" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100960 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100961 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200962 "$P_CLI debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100963 0 \
964 -c "x509_verify_cert() returned" \
965 -c "! self-signed or not signed by a trusted CA" \
966 -C "! ssl_handshake returned" \
967 -C "X509 - Certificate verification failed"
968
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200969run_test "Authentication: server badcert, client none" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100970 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100971 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200972 "$P_CLI debug_level=1 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100973 0 \
974 -C "x509_verify_cert() returned" \
975 -C "! self-signed or not signed by a trusted CA" \
976 -C "! ssl_handshake returned" \
977 -C "X509 - Certificate verification failed"
978
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200979run_test "Authentication: client badcert, server required" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200980 "$P_SRV debug_level=3 auth_mode=required" \
981 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100982 key_file=data_files/server5.key" \
983 1 \
984 -S "skip write certificate request" \
985 -C "skip parse certificate request" \
986 -c "got a certificate request" \
987 -C "skip write certificate" \
988 -C "skip write certificate verify" \
989 -S "skip parse certificate verify" \
990 -s "x509_verify_cert() returned" \
991 -S "! self-signed or not signed by a trusted CA" \
992 -s "! ssl_handshake returned" \
993 -c "! ssl_handshake returned" \
994 -s "X509 - Certificate verification failed"
995
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200996run_test "Authentication: client badcert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200997 "$P_SRV debug_level=3 auth_mode=optional" \
998 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100999 key_file=data_files/server5.key" \
1000 0 \
1001 -S "skip write certificate request" \
1002 -C "skip parse certificate request" \
1003 -c "got a certificate request" \
1004 -C "skip write certificate" \
1005 -C "skip write certificate verify" \
1006 -S "skip parse certificate verify" \
1007 -s "x509_verify_cert() returned" \
1008 -s "! self-signed or not signed by a trusted CA" \
1009 -S "! ssl_handshake returned" \
1010 -C "! ssl_handshake returned" \
1011 -S "X509 - Certificate verification failed"
1012
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001013run_test "Authentication: client badcert, server none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001014 "$P_SRV debug_level=3 auth_mode=none" \
1015 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001016 key_file=data_files/server5.key" \
1017 0 \
1018 -s "skip write certificate request" \
1019 -C "skip parse certificate request" \
1020 -c "got no certificate request" \
1021 -c "skip write certificate" \
1022 -c "skip write certificate verify" \
1023 -s "skip parse certificate verify" \
1024 -S "x509_verify_cert() returned" \
1025 -S "! self-signed or not signed by a trusted CA" \
1026 -S "! ssl_handshake returned" \
1027 -C "! ssl_handshake returned" \
1028 -S "X509 - Certificate verification failed"
1029
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001030run_test "Authentication: client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001031 "$P_SRV debug_level=3 auth_mode=optional" \
1032 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001033 0 \
1034 -S "skip write certificate request" \
1035 -C "skip parse certificate request" \
1036 -c "got a certificate request" \
1037 -C "skip write certificate$" \
1038 -C "got no certificate to send" \
1039 -S "SSLv3 client has no certificate" \
1040 -c "skip write certificate verify" \
1041 -s "skip parse certificate verify" \
1042 -s "! no client certificate sent" \
1043 -S "! ssl_handshake returned" \
1044 -C "! ssl_handshake returned" \
1045 -S "X509 - Certificate verification failed"
1046
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001047run_test "Authentication: openssl client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001048 "$P_SRV debug_level=3 auth_mode=optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001049 "$O_CLI" \
1050 0 \
1051 -S "skip write certificate request" \
1052 -s "skip parse certificate verify" \
1053 -s "! no client certificate sent" \
1054 -S "! ssl_handshake returned" \
1055 -S "X509 - Certificate verification failed"
1056
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001057run_test "Authentication: client no cert, openssl server optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001058 "$O_SRV -verify 10" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001059 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001060 0 \
1061 -C "skip parse certificate request" \
1062 -c "got a certificate request" \
1063 -C "skip write certificate$" \
1064 -c "skip write certificate verify" \
1065 -C "! ssl_handshake returned"
1066
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001067run_test "Authentication: client no cert, ssl3" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001068 "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
1069 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001070 0 \
1071 -S "skip write certificate request" \
1072 -C "skip parse certificate request" \
1073 -c "got a certificate request" \
1074 -C "skip write certificate$" \
1075 -c "skip write certificate verify" \
1076 -c "got no certificate to send" \
1077 -s "SSLv3 client has no certificate" \
1078 -s "skip parse certificate verify" \
1079 -s "! no client certificate sent" \
1080 -S "! ssl_handshake returned" \
1081 -C "! ssl_handshake returned" \
1082 -S "X509 - Certificate verification failed"
1083
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001084# tests for SNI
1085
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001086run_test "SNI: no SNI callback" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001087 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001088 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001089 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001090 0 \
1091 -S "parse ServerName extension" \
1092 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
1093 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1094
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001095run_test "SNI: matching cert 1" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001096 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001097 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001098 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001099 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001100 0 \
1101 -s "parse ServerName extension" \
1102 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
1103 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1104
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001105run_test "SNI: matching cert 2" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001106 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001107 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001108 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001109 "$P_CLI server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001110 0 \
1111 -s "parse ServerName extension" \
1112 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001113 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001114
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001115run_test "SNI: no matching cert" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001116 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001117 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001118 sni=localhost,data_files/server2.crt,data_files/server2.key,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001119 "$P_CLI server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001120 1 \
1121 -s "parse ServerName extension" \
1122 -s "ssl_sni_wrapper() returned" \
1123 -s "ssl_handshake returned" \
1124 -c "ssl_handshake returned" \
1125 -c "SSL - A fatal alert message was received from our peer"
1126
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001127# Tests for non-blocking I/O: exercise a variety of handshake flows
1128
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001129run_test "Non-blocking I/O: basic handshake" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001130 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1131 "$P_CLI nbio=2 tickets=0" \
1132 0 \
1133 -S "ssl_handshake returned" \
1134 -C "ssl_handshake returned" \
1135 -c "Read from server: .* bytes read"
1136
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001137run_test "Non-blocking I/O: client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001138 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
1139 "$P_CLI nbio=2 tickets=0" \
1140 0 \
1141 -S "ssl_handshake returned" \
1142 -C "ssl_handshake returned" \
1143 -c "Read from server: .* bytes read"
1144
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001145run_test "Non-blocking I/O: ticket" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001146 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1147 "$P_CLI nbio=2 tickets=1" \
1148 0 \
1149 -S "ssl_handshake returned" \
1150 -C "ssl_handshake returned" \
1151 -c "Read from server: .* bytes read"
1152
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001153run_test "Non-blocking I/O: ticket + client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001154 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1155 "$P_CLI nbio=2 tickets=1" \
1156 0 \
1157 -S "ssl_handshake returned" \
1158 -C "ssl_handshake returned" \
1159 -c "Read from server: .* bytes read"
1160
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001161run_test "Non-blocking I/O: ticket + client auth + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001162 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1163 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1164 0 \
1165 -S "ssl_handshake returned" \
1166 -C "ssl_handshake returned" \
1167 -c "Read from server: .* bytes read"
1168
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001169run_test "Non-blocking I/O: ticket + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001170 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1171 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1172 0 \
1173 -S "ssl_handshake returned" \
1174 -C "ssl_handshake returned" \
1175 -c "Read from server: .* bytes read"
1176
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001177run_test "Non-blocking I/O: session-id resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001178 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1179 "$P_CLI nbio=2 tickets=0 reconnect=1" \
1180 0 \
1181 -S "ssl_handshake returned" \
1182 -C "ssl_handshake returned" \
1183 -c "Read from server: .* bytes read"
1184
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001185# Tests for version negotiation
1186
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001187run_test "Version check: all -> 1.2" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001188 "$P_SRV" \
1189 "$P_CLI" \
1190 0 \
1191 -S "ssl_handshake returned" \
1192 -C "ssl_handshake returned" \
1193 -s "Protocol is TLSv1.2" \
1194 -c "Protocol is TLSv1.2"
1195
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001196run_test "Version check: cli max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001197 "$P_SRV" \
1198 "$P_CLI max_version=tls1_1" \
1199 0 \
1200 -S "ssl_handshake returned" \
1201 -C "ssl_handshake returned" \
1202 -s "Protocol is TLSv1.1" \
1203 -c "Protocol is TLSv1.1"
1204
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001205run_test "Version check: srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001206 "$P_SRV max_version=tls1_1" \
1207 "$P_CLI" \
1208 0 \
1209 -S "ssl_handshake returned" \
1210 -C "ssl_handshake returned" \
1211 -s "Protocol is TLSv1.1" \
1212 -c "Protocol is TLSv1.1"
1213
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001214run_test "Version check: cli+srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001215 "$P_SRV max_version=tls1_1" \
1216 "$P_CLI max_version=tls1_1" \
1217 0 \
1218 -S "ssl_handshake returned" \
1219 -C "ssl_handshake returned" \
1220 -s "Protocol is TLSv1.1" \
1221 -c "Protocol is TLSv1.1"
1222
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001223run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001224 "$P_SRV min_version=tls1_1" \
1225 "$P_CLI max_version=tls1_1" \
1226 0 \
1227 -S "ssl_handshake returned" \
1228 -C "ssl_handshake returned" \
1229 -s "Protocol is TLSv1.1" \
1230 -c "Protocol is TLSv1.1"
1231
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001232run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001233 "$P_SRV max_version=tls1_1" \
1234 "$P_CLI min_version=tls1_1" \
1235 0 \
1236 -S "ssl_handshake returned" \
1237 -C "ssl_handshake returned" \
1238 -s "Protocol is TLSv1.1" \
1239 -c "Protocol is TLSv1.1"
1240
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001241run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001242 "$P_SRV max_version=tls1_1" \
1243 "$P_CLI min_version=tls1_2" \
1244 1 \
1245 -s "ssl_handshake returned" \
1246 -c "ssl_handshake returned" \
1247 -c "SSL - Handshake protocol not within min/max boundaries"
1248
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001249run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001250 "$P_SRV min_version=tls1_2" \
1251 "$P_CLI max_version=tls1_1" \
1252 1 \
1253 -s "ssl_handshake returned" \
1254 -c "ssl_handshake returned" \
1255 -s "SSL - Handshake protocol not within min/max boundaries"
1256
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001257# Tests for ALPN extension
1258
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001259if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
1260
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001261run_test "ALPN: none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001262 "$P_SRV debug_level=3" \
1263 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001264 0 \
1265 -C "client hello, adding alpn extension" \
1266 -S "found alpn extension" \
1267 -C "got an alert message, type: \\[2:120]" \
1268 -S "server hello, adding alpn extension" \
1269 -C "found alpn extension " \
1270 -C "Application Layer Protocol is" \
1271 -S "Application Layer Protocol is"
1272
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001273run_test "ALPN: client only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001274 "$P_SRV debug_level=3" \
1275 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001276 0 \
1277 -c "client hello, adding alpn extension" \
1278 -s "found alpn extension" \
1279 -C "got an alert message, type: \\[2:120]" \
1280 -S "server hello, adding alpn extension" \
1281 -C "found alpn extension " \
1282 -c "Application Layer Protocol is (none)" \
1283 -S "Application Layer Protocol is"
1284
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001285run_test "ALPN: server only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001286 "$P_SRV debug_level=3 alpn=abc,1234" \
1287 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001288 0 \
1289 -C "client hello, adding alpn extension" \
1290 -S "found alpn extension" \
1291 -C "got an alert message, type: \\[2:120]" \
1292 -S "server hello, adding alpn extension" \
1293 -C "found alpn extension " \
1294 -C "Application Layer Protocol is" \
1295 -s "Application Layer Protocol is (none)"
1296
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001297run_test "ALPN: both, common cli1-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001298 "$P_SRV debug_level=3 alpn=abc,1234" \
1299 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001300 0 \
1301 -c "client hello, adding alpn extension" \
1302 -s "found alpn extension" \
1303 -C "got an alert message, type: \\[2:120]" \
1304 -s "server hello, adding alpn extension" \
1305 -c "found alpn extension" \
1306 -c "Application Layer Protocol is abc" \
1307 -s "Application Layer Protocol is abc"
1308
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001309run_test "ALPN: both, common cli2-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001310 "$P_SRV debug_level=3 alpn=abc,1234" \
1311 "$P_CLI debug_level=3 alpn=1234,abc" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001312 0 \
1313 -c "client hello, adding alpn extension" \
1314 -s "found alpn extension" \
1315 -C "got an alert message, type: \\[2:120]" \
1316 -s "server hello, adding alpn extension" \
1317 -c "found alpn extension" \
1318 -c "Application Layer Protocol is abc" \
1319 -s "Application Layer Protocol is abc"
1320
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001321run_test "ALPN: both, common cli1-srv2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001322 "$P_SRV debug_level=3 alpn=abc,1234" \
1323 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001324 0 \
1325 -c "client hello, adding alpn extension" \
1326 -s "found alpn extension" \
1327 -C "got an alert message, type: \\[2:120]" \
1328 -s "server hello, adding alpn extension" \
1329 -c "found alpn extension" \
1330 -c "Application Layer Protocol is 1234" \
1331 -s "Application Layer Protocol is 1234"
1332
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001333run_test "ALPN: both, no common" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001334 "$P_SRV debug_level=3 alpn=abc,123" \
1335 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001336 1 \
1337 -c "client hello, adding alpn extension" \
1338 -s "found alpn extension" \
1339 -c "got an alert message, type: \\[2:120]" \
1340 -S "server hello, adding alpn extension" \
1341 -C "found alpn extension" \
1342 -C "Application Layer Protocol is 1234" \
1343 -S "Application Layer Protocol is 1234"
1344
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001345fi
1346
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001347# Tests for keyUsage in leaf certificates, part 1:
1348# server-side certificate/suite selection
1349
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001350run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001351 "$P_SRV key_file=data_files/server2.key \
1352 crt_file=data_files/server2.ku-ds.crt" \
1353 "$P_CLI" \
1354 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02001355 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001356
1357
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001358run_test "keyUsage srv: RSA, keyEncipherment -> RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001359 "$P_SRV key_file=data_files/server2.key \
1360 crt_file=data_files/server2.ku-ke.crt" \
1361 "$P_CLI" \
1362 0 \
1363 -c "Ciphersuite is TLS-RSA-WITH-"
1364
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001365run_test "keyUsage srv: RSA, keyAgreement -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001366 "$P_SRV key_file=data_files/server2.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001367 crt_file=data_files/server2.ku-ka.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001368 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001369 1 \
1370 -C "Ciphersuite is "
1371
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001372run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001373 "$P_SRV key_file=data_files/server5.key \
1374 crt_file=data_files/server5.ku-ds.crt" \
1375 "$P_CLI" \
1376 0 \
1377 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
1378
1379
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001380run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001381 "$P_SRV key_file=data_files/server5.key \
1382 crt_file=data_files/server5.ku-ka.crt" \
1383 "$P_CLI" \
1384 0 \
1385 -c "Ciphersuite is TLS-ECDH-"
1386
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001387run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001388 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001389 crt_file=data_files/server5.ku-ke.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001390 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001391 1 \
1392 -C "Ciphersuite is "
1393
1394# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001395# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001396
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001397run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001398 "$O_SRV -key data_files/server2.key \
1399 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001400 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001401 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1402 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001403 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001404 -C "Processing of the Certificate handshake message failed" \
1405 -c "Ciphersuite is TLS-"
1406
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001407run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001408 "$O_SRV -key data_files/server2.key \
1409 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001410 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001411 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1412 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001413 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001414 -C "Processing of the Certificate handshake message failed" \
1415 -c "Ciphersuite is TLS-"
1416
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001417run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001418 "$O_SRV -key data_files/server2.key \
1419 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001420 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001421 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1422 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001423 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001424 -C "Processing of the Certificate handshake message failed" \
1425 -c "Ciphersuite is TLS-"
1426
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001427run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001428 "$O_SRV -key data_files/server2.key \
1429 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001430 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001431 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1432 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001433 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001434 -c "Processing of the Certificate handshake message failed" \
1435 -C "Ciphersuite is TLS-"
1436
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001437run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001438 "$O_SRV -key data_files/server2.key \
1439 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001440 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001441 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1442 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001443 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001444 -C "Processing of the Certificate handshake message failed" \
1445 -c "Ciphersuite is TLS-"
1446
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001447run_test "keyUsage cli: DigitalSignature, RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001448 "$O_SRV -key data_files/server2.key \
1449 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001450 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001451 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1452 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001453 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001454 -c "Processing of the Certificate handshake message failed" \
1455 -C "Ciphersuite is TLS-"
1456
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001457# Tests for keyUsage in leaf certificates, part 3:
1458# server-side checking of client cert
1459
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001460run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001461 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001462 "$O_CLI -key data_files/server2.key \
1463 -cert data_files/server2.ku-ds.crt" \
1464 0 \
1465 -S "bad certificate (usage extensions)" \
1466 -S "Processing of the Certificate handshake message failed"
1467
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001468run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001469 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001470 "$O_CLI -key data_files/server2.key \
1471 -cert data_files/server2.ku-ke.crt" \
1472 0 \
1473 -s "bad certificate (usage extensions)" \
1474 -S "Processing of the Certificate handshake message failed"
1475
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001476run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001477 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001478 "$O_CLI -key data_files/server2.key \
1479 -cert data_files/server2.ku-ke.crt" \
1480 1 \
1481 -s "bad certificate (usage extensions)" \
1482 -s "Processing of the Certificate handshake message failed"
1483
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001484run_test "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001485 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001486 "$O_CLI -key data_files/server5.key \
1487 -cert data_files/server5.ku-ds.crt" \
1488 0 \
1489 -S "bad certificate (usage extensions)" \
1490 -S "Processing of the Certificate handshake message failed"
1491
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001492run_test "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001493 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001494 "$O_CLI -key data_files/server5.key \
1495 -cert data_files/server5.ku-ka.crt" \
1496 0 \
1497 -s "bad certificate (usage extensions)" \
1498 -S "Processing of the Certificate handshake message failed"
1499
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001500# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
1501
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001502run_test "extKeyUsage srv: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001503 "$P_SRV key_file=data_files/server5.key \
1504 crt_file=data_files/server5.eku-srv.crt" \
1505 "$P_CLI" \
1506 0
1507
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001508run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001509 "$P_SRV key_file=data_files/server5.key \
1510 crt_file=data_files/server5.eku-srv.crt" \
1511 "$P_CLI" \
1512 0
1513
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001514run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001515 "$P_SRV key_file=data_files/server5.key \
1516 crt_file=data_files/server5.eku-cs_any.crt" \
1517 "$P_CLI" \
1518 0
1519
1520# add psk to leave an option for client to send SERVERQUIT
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001521run_test "extKeyUsage srv: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001522 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1523 crt_file=data_files/server5.eku-cli.crt" \
1524 "$P_CLI psk=badbad" \
1525 1
1526
1527# Tests for extendedKeyUsage, part 2: client-side checking of server cert
1528
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001529run_test "extKeyUsage cli: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001530 "$O_SRV -key data_files/server5.key \
1531 -cert data_files/server5.eku-srv.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001532 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001533 0 \
1534 -C "bad certificate (usage extensions)" \
1535 -C "Processing of the Certificate handshake message failed" \
1536 -c "Ciphersuite is TLS-"
1537
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001538run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001539 "$O_SRV -key data_files/server5.key \
1540 -cert data_files/server5.eku-srv_cli.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001541 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001542 0 \
1543 -C "bad certificate (usage extensions)" \
1544 -C "Processing of the Certificate handshake message failed" \
1545 -c "Ciphersuite is TLS-"
1546
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001547run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001548 "$O_SRV -key data_files/server5.key \
1549 -cert data_files/server5.eku-cs_any.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001550 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001551 0 \
1552 -C "bad certificate (usage extensions)" \
1553 -C "Processing of the Certificate handshake message failed" \
1554 -c "Ciphersuite is TLS-"
1555
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001556run_test "extKeyUsage cli: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001557 "$O_SRV -key data_files/server5.key \
1558 -cert data_files/server5.eku-cs.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001559 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001560 1 \
1561 -c "bad certificate (usage extensions)" \
1562 -c "Processing of the Certificate handshake message failed" \
1563 -C "Ciphersuite is TLS-"
1564
1565# Tests for extendedKeyUsage, part 3: server-side checking of client cert
1566
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001567run_test "extKeyUsage cli-auth: clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001568 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001569 "$O_CLI -key data_files/server5.key \
1570 -cert data_files/server5.eku-cli.crt" \
1571 0 \
1572 -S "bad certificate (usage extensions)" \
1573 -S "Processing of the Certificate handshake message failed"
1574
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001575run_test "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001576 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001577 "$O_CLI -key data_files/server5.key \
1578 -cert data_files/server5.eku-srv_cli.crt" \
1579 0 \
1580 -S "bad certificate (usage extensions)" \
1581 -S "Processing of the Certificate handshake message failed"
1582
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001583run_test "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001584 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001585 "$O_CLI -key data_files/server5.key \
1586 -cert data_files/server5.eku-cs_any.crt" \
1587 0 \
1588 -S "bad certificate (usage extensions)" \
1589 -S "Processing of the Certificate handshake message failed"
1590
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001591run_test "extKeyUsage cli-auth: codeSign -> fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001592 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001593 "$O_CLI -key data_files/server5.key \
1594 -cert data_files/server5.eku-cs.crt" \
1595 0 \
1596 -s "bad certificate (usage extensions)" \
1597 -S "Processing of the Certificate handshake message failed"
1598
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001599run_test "extKeyUsage cli-auth: codeSign -> fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001600 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001601 "$O_CLI -key data_files/server5.key \
1602 -cert data_files/server5.eku-cs.crt" \
1603 1 \
1604 -s "bad certificate (usage extensions)" \
1605 -s "Processing of the Certificate handshake message failed"
1606
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001607# Tests for DHM parameters loading
1608
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001609run_test "DHM parameters: reference" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001610 "$P_SRV" \
1611 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1612 debug_level=3" \
1613 0 \
1614 -c "value of 'DHM: P ' (2048 bits)" \
1615 -c "value of 'DHM: G ' (2048 bits)"
1616
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001617run_test "DHM parameters: other parameters" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001618 "$P_SRV dhm_file=data_files/dhparams.pem" \
1619 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1620 debug_level=3" \
1621 0 \
1622 -c "value of 'DHM: P ' (1024 bits)" \
1623 -c "value of 'DHM: G ' (2 bits)"
1624
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001625# Tests for PSK callback
1626
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001627run_test "PSK callback: psk, no callback" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001628 "$P_SRV psk=abc123 psk_identity=foo" \
1629 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1630 psk_identity=foo psk=abc123" \
1631 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001632 -S "SSL - The server has no ciphersuites in common" \
1633 -S "SSL - Unknown identity received" \
1634 -S "SSL - Verification of the message MAC failed"
1635
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001636run_test "PSK callback: no psk, no callback" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001637 "$P_SRV" \
1638 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1639 psk_identity=foo psk=abc123" \
1640 1 \
1641 -s "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001642 -S "SSL - Unknown identity received" \
1643 -S "SSL - Verification of the message MAC failed"
1644
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001645run_test "PSK callback: callback overrides other settings" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001646 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
1647 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1648 psk_identity=foo psk=abc123" \
1649 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001650 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001651 -s "SSL - Unknown identity received" \
1652 -S "SSL - Verification of the message MAC failed"
1653
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001654run_test "PSK callback: first id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001655 "$P_SRV psk_list=abc,dead,def,beef" \
1656 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1657 psk_identity=abc psk=dead" \
1658 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001659 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001660 -S "SSL - Unknown identity received" \
1661 -S "SSL - Verification of the message MAC failed"
1662
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001663run_test "PSK callback: second id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001664 "$P_SRV psk_list=abc,dead,def,beef" \
1665 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1666 psk_identity=def psk=beef" \
1667 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001668 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001669 -S "SSL - Unknown identity received" \
1670 -S "SSL - Verification of the message MAC failed"
1671
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001672run_test "PSK callback: no match" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001673 "$P_SRV psk_list=abc,dead,def,beef" \
1674 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1675 psk_identity=ghi psk=beef" \
1676 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001677 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001678 -s "SSL - Unknown identity received" \
1679 -S "SSL - Verification of the message MAC failed"
1680
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001681run_test "PSK callback: wrong key" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001682 "$P_SRV psk_list=abc,dead,def,beef" \
1683 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1684 psk_identity=abc psk=beef" \
1685 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001686 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001687 -S "SSL - Unknown identity received" \
1688 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001689
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001690# Tests for ciphersuites per version
1691
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001692run_test "Per-version suites: SSL3" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001693 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1694 "$P_CLI force_version=ssl3" \
1695 0 \
1696 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
1697
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001698run_test "Per-version suites: TLS 1.0" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001699 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1700 "$P_CLI force_version=tls1" \
1701 0 \
1702 -c "Ciphersuite is TLS-RSA-WITH-RC4-128-SHA"
1703
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001704run_test "Per-version suites: TLS 1.1" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001705 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1706 "$P_CLI force_version=tls1_1" \
1707 0 \
1708 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
1709
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001710run_test "Per-version suites: TLS 1.2" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001711 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-RC4-128-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
1712 "$P_CLI force_version=tls1_2" \
1713 0 \
1714 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
1715
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001716# Tests for ssl_get_bytes_avail()
1717
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001718run_test "ssl_get_bytes_avail: no extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001719 "$P_SRV" \
1720 "$P_CLI request_size=100" \
1721 0 \
1722 -s "Read from client: 100 bytes read$"
1723
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001724run_test "ssl_get_bytes_avail: extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001725 "$P_SRV" \
1726 "$P_CLI request_size=500" \
1727 0 \
1728 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001729
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02001730# Tests for small packets
1731
1732run_test "Small packet SSLv3 BlockCipher" \
1733 "$P_SRV" \
1734 "$P_CLI request_size=1 force_version=ssl3 \
1735 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1736 0 \
1737 -s "Read from client: 1 bytes read"
1738
1739run_test "Small packet SSLv3 StreamCipher" \
1740 "$P_SRV" \
1741 "$P_CLI request_size=1 force_version=ssl3 \
1742 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1743 0 \
1744 -s "Read from client: 1 bytes read"
1745
1746run_test "Small packet TLS 1.0 BlockCipher" \
1747 "$P_SRV" \
1748 "$P_CLI request_size=1 force_version=tls1 \
1749 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1750 0 \
1751 -s "Read from client: 1 bytes read"
1752
1753run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
1754 "$P_SRV" \
1755 "$P_CLI request_size=1 force_version=tls1 \
1756 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1757 trunc_hmac=1" \
1758 0 \
1759 -s "Read from client: 1 bytes read"
1760
1761run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
1762 "$P_SRV" \
1763 "$P_CLI request_size=1 force_version=tls1 \
1764 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1765 trunc_hmac=1" \
1766 0 \
1767 -s "Read from client: 1 bytes read"
1768
1769run_test "Small packet TLS 1.1 BlockCipher" \
1770 "$P_SRV" \
1771 "$P_CLI request_size=1 force_version=tls1_1 \
1772 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1773 0 \
1774 -s "Read from client: 1 bytes read"
1775
1776run_test "Small packet TLS 1.1 StreamCipher" \
1777 "$P_SRV" \
1778 "$P_CLI request_size=1 force_version=tls1_1 \
1779 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1780 0 \
1781 -s "Read from client: 1 bytes read"
1782
1783run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
1784 "$P_SRV" \
1785 "$P_CLI request_size=1 force_version=tls1_1 \
1786 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1787 trunc_hmac=1" \
1788 0 \
1789 -s "Read from client: 1 bytes read"
1790
1791run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
1792 "$P_SRV" \
1793 "$P_CLI request_size=1 force_version=tls1_1 \
1794 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1795 trunc_hmac=1" \
1796 0 \
1797 -s "Read from client: 1 bytes read"
1798
1799run_test "Small packet TLS 1.2 BlockCipher" \
1800 "$P_SRV" \
1801 "$P_CLI request_size=1 force_version=tls1_2 \
1802 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1803 0 \
1804 -s "Read from client: 1 bytes read"
1805
1806run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
1807 "$P_SRV" \
1808 "$P_CLI request_size=1 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1809 0 \
1810 -s "Read from client: 1 bytes read"
1811
1812run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
1813 "$P_SRV" \
1814 "$P_CLI request_size=1 force_version=tls1_2 \
1815 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1816 trunc_hmac=1" \
1817 0 \
1818 -s "Read from client: 1 bytes read"
1819
1820run_test "Small packet TLS 1.2 StreamCipher" \
1821 "$P_SRV" \
1822 "$P_CLI request_size=1 force_version=tls1_2 \
1823 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1824 0 \
1825 -s "Read from client: 1 bytes read"
1826
1827run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
1828 "$P_SRV" \
1829 "$P_CLI request_size=1 force_version=tls1_2 \
1830 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1831 trunc_hmac=1" \
1832 0 \
1833 -s "Read from client: 1 bytes read"
1834
1835run_test "Small packet TLS 1.2 AEAD" \
1836 "$P_SRV" \
1837 "$P_CLI request_size=1 force_version=tls1_2 \
1838 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1839 0 \
1840 -s "Read from client: 1 bytes read"
1841
1842run_test "Small packet TLS 1.2 AEAD shorter tag" \
1843 "$P_SRV" \
1844 "$P_CLI request_size=1 force_version=tls1_2 \
1845 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1846 0 \
1847 -s "Read from client: 1 bytes read"
1848
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02001849# Test for large packets
1850
1851run_test "Large packet SSLv3 BlockCipher" \
1852 "$P_SRV" \
1853 "$P_CLI request_size=16384 force_version=ssl3 \
1854 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1855 0 \
1856 -s "Read from client: 16384 bytes read"
1857
1858run_test "Large packet SSLv3 StreamCipher" \
1859 "$P_SRV" \
1860 "$P_CLI request_size=16384 force_version=ssl3 \
1861 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1862 0 \
1863 -s "Read from client: 16384 bytes read"
1864
1865run_test "Large packet TLS 1.0 BlockCipher" \
1866 "$P_SRV" \
1867 "$P_CLI request_size=16384 force_version=tls1 \
1868 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1869 0 \
1870 -s "Read from client: 16384 bytes read"
1871
1872run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
1873 "$P_SRV" \
1874 "$P_CLI request_size=16384 force_version=tls1 \
1875 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1876 trunc_hmac=1" \
1877 0 \
1878 -s "Read from client: 16384 bytes read"
1879
1880run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
1881 "$P_SRV" \
1882 "$P_CLI request_size=16384 force_version=tls1 \
1883 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1884 trunc_hmac=1" \
1885 0 \
1886 -s "Read from client: 16384 bytes read"
1887
1888run_test "Large packet TLS 1.1 BlockCipher" \
1889 "$P_SRV" \
1890 "$P_CLI request_size=16384 force_version=tls1_1 \
1891 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1892 0 \
1893 -s "Read from client: 16384 bytes read"
1894
1895run_test "Large packet TLS 1.1 StreamCipher" \
1896 "$P_SRV" \
1897 "$P_CLI request_size=16384 force_version=tls1_1 \
1898 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1899 0 \
1900 -s "Read from client: 16384 bytes read"
1901
1902run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
1903 "$P_SRV" \
1904 "$P_CLI request_size=16384 force_version=tls1_1 \
1905 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1906 trunc_hmac=1" \
1907 0 \
1908 -s "Read from client: 16384 bytes read"
1909
1910run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
1911 "$P_SRV" \
1912 "$P_CLI request_size=16384 force_version=tls1_1 \
1913 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1914 trunc_hmac=1" \
1915 0 \
1916 -s "Read from client: 16384 bytes read"
1917
1918run_test "Large packet TLS 1.2 BlockCipher" \
1919 "$P_SRV" \
1920 "$P_CLI request_size=16384 force_version=tls1_2 \
1921 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1922 0 \
1923 -s "Read from client: 16384 bytes read"
1924
1925run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
1926 "$P_SRV" \
1927 "$P_CLI request_size=16384 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1928 0 \
1929 -s "Read from client: 16384 bytes read"
1930
1931run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
1932 "$P_SRV" \
1933 "$P_CLI request_size=16384 force_version=tls1_2 \
1934 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1935 trunc_hmac=1" \
1936 0 \
1937 -s "Read from client: 16384 bytes read"
1938
1939run_test "Large packet TLS 1.2 StreamCipher" \
1940 "$P_SRV" \
1941 "$P_CLI request_size=16384 force_version=tls1_2 \
1942 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1943 0 \
1944 -s "Read from client: 16384 bytes read"
1945
1946run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
1947 "$P_SRV" \
1948 "$P_CLI request_size=16384 force_version=tls1_2 \
1949 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1950 trunc_hmac=1" \
1951 0 \
1952 -s "Read from client: 16384 bytes read"
1953
1954run_test "Large packet TLS 1.2 AEAD" \
1955 "$P_SRV" \
1956 "$P_CLI request_size=16384 force_version=tls1_2 \
1957 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1958 0 \
1959 -s "Read from client: 16384 bytes read"
1960
1961run_test "Large packet TLS 1.2 AEAD shorter tag" \
1962 "$P_SRV" \
1963 "$P_CLI request_size=16384 force_version=tls1_2 \
1964 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1965 0 \
1966 -s "Read from client: 16384 bytes read"
1967
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001968# Tests for DTLS HelloVerifyRequest
1969
1970run_test "DTLS cookie: enabled" \
1971 "$P_SRV dtls=1 debug_level=2" \
1972 "$P_CLI dtls=1 debug_level=2" \
1973 0 \
1974 -s "cookie verification failed" \
1975 -s "cookie verification passed" \
1976 -S "cookie verification skipped" \
1977 -c "received hello verify request" \
1978 -S "SSL - The requested feature is not available"
1979
1980run_test "DTLS cookie: disabled" \
1981 "$P_SRV dtls=1 debug_level=2 cookies=0" \
1982 "$P_CLI dtls=1 debug_level=2" \
1983 0 \
1984 -S "cookie verification failed" \
1985 -S "cookie verification passed" \
1986 -s "cookie verification skipped" \
1987 -C "received hello verify request" \
1988 -S "SSL - The requested feature is not available"
1989
1990# wait for client having a timeout, or server sending an alert
1991#run_test "DTLS cookie: default (failing)" \
1992# "$P_SRV dtls=1 debug_level=2 cookies=-1" \
1993# "$P_CLI dtls=1 debug_level=2" \
1994# 0 \
1995# -S "cookie verification failed" \
1996# -S "cookie verification passed" \
1997# -S "cookie verification skipped" \
1998# -C "received hello verify request" \
1999# -s "SSL - The requested feature is not available"
2000
2001requires_ipv6
2002run_test "DTLS cookie: enabled, IPv6" \
2003 "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
2004 "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
2005 0 \
2006 -s "cookie verification failed" \
2007 -s "cookie verification passed" \
2008 -S "cookie verification skipped" \
2009 -c "received hello verify request" \
2010 -S "SSL - The requested feature is not available"
2011
Manuel Pégourié-Gonnard502bf302014-08-20 13:12:58 +02002012# Tests for receiving fragmented handshake messages with DTLS
2013
2014requires_gnutls
2015run_test "DTLS reassembly: no fragmentation (gnutls server)" \
2016 "$G_SRV -u --mtu 2048 -a" \
2017 "$P_CLI dtls=1 debug_level=2" \
2018 0 \
2019 -C "found fragmented DTLS handshake message" \
2020 -C "error"
2021
2022requires_gnutls
2023run_test "DTLS reassembly: some fragmentation (gnutls server)" \
2024 "$G_SRV -u --mtu 512" \
2025 "$P_CLI dtls=1 debug_level=2" \
2026 0 \
2027 -c "found fragmented DTLS handshake message" \
2028 -C "error"
2029
2030requires_gnutls
2031run_test "DTLS reassembly: more fragmentation (gnutls server)" \
2032 "$G_SRV -u --mtu 128" \
2033 "$P_CLI dtls=1 debug_level=2" \
2034 0 \
2035 -c "found fragmented DTLS handshake message" \
2036 -C "error"
2037
2038requires_gnutls
2039run_test "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
2040 "$G_SRV -u --mtu 128" \
2041 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2042 0 \
2043 -c "found fragmented DTLS handshake message" \
2044 -C "error"
2045
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002046requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002047run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
2048 "$G_SRV -u --mtu 256" \
2049 "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
2050 0 \
2051 -c "found fragmented DTLS handshake message" \
2052 -c "client hello, adding renegotiation extension" \
2053 -c "found renegotiation extension" \
2054 -c "=> renegotiate" \
2055 -C "ssl_handshake returned" \
2056 -C "error" \
2057 -s "Extra-header:"
2058
2059requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002060run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
2061 "$G_SRV -u --mtu 256" \
2062 "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
2063 0 \
2064 -c "found fragmented DTLS handshake message" \
2065 -c "client hello, adding renegotiation extension" \
2066 -c "found renegotiation extension" \
2067 -c "=> renegotiate" \
2068 -C "ssl_handshake returned" \
2069 -C "error" \
2070 -s "Extra-header:"
2071
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002072run_test "DTLS reassembly: no fragmentation (openssl server)" \
2073 "$O_SRV -dtls1 -mtu 2048" \
2074 "$P_CLI dtls=1 debug_level=2" \
2075 0 \
2076 -C "found fragmented DTLS handshake message" \
2077 -C "error"
2078
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02002079run_test "DTLS reassembly: fragmentation (openssl server)" \
2080 "$O_SRV -dtls1 -mtu 256" \
2081 "$P_CLI dtls=1 debug_level=2" \
2082 0 \
2083 -c "found fragmented DTLS handshake message" \
2084 -C "error"
2085
2086run_test "DTLS reassembly: fragmentation (openssl server)" \
2087 "$O_SRV -dtls1 -mtu 256" \
2088 "$P_CLI dtls=1 debug_level=2" \
2089 0 \
2090 -c "found fragmented DTLS handshake message" \
2091 -C "error"
2092
2093run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
2094 "$O_SRV -dtls1 -mtu 256" \
2095 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2096 0 \
2097 -c "found fragmented DTLS handshake message" \
2098 -C "error"
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002099
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002100# Tests with UDP proxy emulating unreliable transport
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002101
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002102run_test "DTLS proxy: reference" \
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002103 -p "$P_PXY" \
2104 "$P_SRV dtls=1" \
2105 "$P_CLI dtls=1" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002106 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002107 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002108 -c "HTTP/1.0 200 OK"
2109
2110run_test "DTLS proxy: some duplication" \
2111 -p "$P_PXY duplicate=3" \
2112 "$P_SRV dtls=1" \
2113 "$P_CLI dtls=1" \
2114 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002115 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002116 -c "HTTP/1.0 200 OK"
2117
2118run_test "DTLS proxy: lots of duplication" \
2119 -p "$P_PXY duplicate=1" \
2120 "$P_SRV dtls=1" \
2121 "$P_CLI dtls=1" \
2122 0 \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002123 -s "Extra-header:" \
2124 -c "HTTP/1.0 200 OK"
2125
2126run_test "DTLS proxy: inject invalid AD record" \
2127 -p "$P_PXY bad_ad=1" \
2128 "$P_SRV dtls=1" \
2129 "$P_CLI dtls=1" \
2130 0 \
2131 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002132 -c "HTTP/1.0 200 OK"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002133
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002134# Final report
2135
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002136echo "------------------------------------------------------------------------"
2137
2138if [ $FAILS = 0 ]; then
2139 echo -n "PASSED"
2140else
2141 echo -n "FAILED"
2142fi
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +02002143PASSES=$(( $TESTS - $FAILS ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +02002144echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002145
2146exit $FAILS