blob: 60fb5e73c2a8a76534c07239edc41babd84f7b92 [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é-Gonnardfa60f122014-09-26 16:07:29 +020021O_SRV="$OPENSSL_CMD s_server -www -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é-Gonnard76fe9e42014-09-24 15:17:31 +0200119# skip the next test if valgrind is in use
120not_with_valgrind() {
121 if [ "$MEMCHECK" -gt 0 ]; then
122 SKIP_NEXT="YES"
123 fi
124}
125
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200126# multiply the client timeout delay by the given factor for the next test
127needs_more_time() {
128 CLI_DELAY_FACTOR=$1
129}
130
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100131# print_name <name>
132print_name() {
133 echo -n "$1 "
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200134 LEN=$(( 72 - `echo "$1" | wc -c` ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100135 for i in `seq 1 $LEN`; do echo -n '.'; done
136 echo -n ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100137
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200138 TESTS=$(( $TESTS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100139}
140
141# fail <message>
142fail() {
143 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +0100144 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100145
Manuel Pégourié-Gonnardc2b00922014-08-31 16:46:04 +0200146 mv $SRV_OUT o-srv-${TESTS}.log
147 mv $CLI_OUT o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200148 if [ -n "$PXY_CMD" ]; then
149 mv $PXY_OUT o-pxy-${TESTS}.log
150 fi
151 echo " ! outputs saved to o-XXX-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100152
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200153 if [ "X${USER:-}" = Xbuildbot -o "X${LOGNAME:-}" = Xbuildbot ]; then
154 echo " ! server output:"
155 cat o-srv-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200156 echo " ! ========================================================"
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200157 echo " ! client output:"
158 cat o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200159 if [ -n "$PXY_CMD" ]; then
160 echo " ! ========================================================"
161 echo " ! proxy output:"
162 cat o-pxy-${TESTS}.log
163 fi
164 echo ""
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200165 fi
166
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200167 FAILS=$(( $FAILS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100168}
169
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100170# is_polar <cmd_line>
171is_polar() {
172 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
173}
174
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +0200175# openssl s_server doesn't have -www with DTLS
176check_osrv_dtls() {
177 if echo "$SRV_CMD" | grep 's_server.*-dtls' >/dev/null; then
178 NEEDS_INPUT=1
179 SRV_CMD="$( echo $SRV_CMD | sed s/-www// )"
180 else
181 NEEDS_INPUT=0
182 fi
183}
184
185# provide input to commands that need it
186provide_input() {
187 if [ $NEEDS_INPUT -eq 0 ]; then
188 return
189 fi
190
191 while true; do
192 echo "HTTP/1.0 200 OK"
193 sleep 1
194 done
195}
196
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100197# has_mem_err <log_file_name>
198has_mem_err() {
199 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
200 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
201 then
202 return 1 # false: does not have errors
203 else
204 return 0 # true: has errors
205 fi
206}
207
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200208# wait for server to start: two versions depending on lsof availability
209wait_server_start() {
210 if which lsof >/dev/null; then
211 # make sure we don't loop forever
212 ( sleep "$DOG_DELAY"; echo "SERVERSTART TIMEOUT"; kill $MAIN_PID ) &
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200213 DOG_PID=$!
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200214
215 # make a tight loop, server usually takes less than 1 sec to start
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200216 if [ "$DTLS" -eq 1 ]; then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200217 until lsof -nbi UDP:"$SRV_PORT" | grep UDP >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200218 else
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200219 until lsof -nbi TCP:"$SRV_PORT" | grep LISTEN >/dev/null; do :; done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200220 fi
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200221
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200222 kill $DOG_PID >/dev/null 2>&1
223 wait $DOG_PID
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200224 else
225 sleep "$START_DELAY"
226 fi
227}
228
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200229# wait for client to terminate and set CLI_EXIT
230# must be called right after starting the client
231wait_client_done() {
232 CLI_PID=$!
233
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200234 CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
235 CLI_DELAY_FACTOR=1
236
237 ( sleep $CLI_DELAY; echo "TIMEOUT" >> $CLI_OUT; kill $CLI_PID ) &
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200238 DOG_PID=$!
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200239
240 wait $CLI_PID
241 CLI_EXIT=$?
242
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200243 kill $DOG_PID >/dev/null 2>&1
244 wait $DOG_PID
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200245
246 echo "EXIT: $CLI_EXIT" >> $CLI_OUT
247}
248
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200249# check if the given command uses dtls and sets global variable DTLS
250detect_dtls() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200251 if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200252 DTLS=1
253 else
254 DTLS=0
255 fi
256}
257
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200258# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100259# Options: -s pattern pattern that must be present in server output
260# -c pattern pattern that must be present in client output
261# -S pattern pattern that must be absent in server output
262# -C pattern pattern that must be absent in client output
263run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100264 NAME="$1"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200265 shift 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100266
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100267 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
268 else
269 return
270 fi
271
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100272 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100273
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200274 # should we skip?
275 if [ "X$SKIP_NEXT" = "XYES" ]; then
276 SKIP_NEXT="NO"
277 echo "SKIP"
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200278 SKIPS=$(( $SKIPS + 1 ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200279 return
280 fi
281
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200282 # does this test use a proxy?
283 if [ "X$1" = "X-p" ]; then
284 PXY_CMD="$2"
285 shift 2
286 else
287 PXY_CMD=""
288 fi
289
290 # get commands and client output
291 SRV_CMD="$1"
292 CLI_CMD="$2"
293 CLI_EXPECT="$3"
294 shift 3
295
296 # fix client port
297 if [ -n "$PXY_CMD" ]; then
298 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
299 else
300 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
301 fi
302
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200303 # update DTLS variable
304 detect_dtls "$SRV_CMD"
305
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100306 # prepend valgrind to our commands if active
307 if [ "$MEMCHECK" -gt 0 ]; then
308 if is_polar "$SRV_CMD"; then
309 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
310 fi
311 if is_polar "$CLI_CMD"; then
312 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
313 fi
314 fi
315
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100316 # run the commands
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200317 if [ -n "$PXY_CMD" ]; then
318 echo "$PXY_CMD" > $PXY_OUT
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200319 $PXY_CMD >> $PXY_OUT 2>&1 &
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200320 PXY_PID=$!
321 # assume proxy starts faster than server
322 fi
323
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +0200324 check_osrv_dtls
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200325 echo "$SRV_CMD" > $SRV_OUT
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +0200326 provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100327 SRV_PID=$!
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200328 wait_server_start
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200329
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200330 echo "$CLI_CMD" > $CLI_OUT
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200331 eval "$CLI_CMD" >> $CLI_OUT 2>&1 &
332 wait_client_done
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100333
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200334 # terminate the server (and the proxy)
Manuel Pégourié-Gonnard74b11702014-08-14 15:47:33 +0200335 kill $SRV_PID
336 wait $SRV_PID
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200337 if [ -n "$PXY_CMD" ]; then
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200338 kill $PXY_PID >/dev/null 2>&1
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200339 wait $PXY_PID
340 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100341
342 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200343 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100344 # expected client exit to incorrectly succeed in case of catastrophic
345 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100346 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200347 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100348 else
349 fail "server failed to start"
350 return
351 fi
352 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100353 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200354 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100355 else
356 fail "client failed to start"
357 return
358 fi
359 fi
360
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100361 # check server exit code
362 if [ $? != 0 ]; then
363 fail "server fail"
364 return
365 fi
366
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100367 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100368 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
369 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100370 then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200371 fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100372 return
373 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100374
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100375 # check other assertions
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200376 # lines beginning with == are added by valgrind, ignore them
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100377 while [ $# -gt 0 ]
378 do
379 case $1 in
380 "-s")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200381 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100382 fail "-s $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100383 return
384 fi
385 ;;
386
387 "-c")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200388 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then :; else
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100389 fail "-c $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100390 return
391 fi
392 ;;
393
394 "-S")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200395 if grep -v '^==' $SRV_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100396 fail "-S $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100397 return
398 fi
399 ;;
400
401 "-C")
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200402 if grep -v '^==' $CLI_OUT | grep "$2" >/dev/null; then
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100403 fail "-C $2"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100404 return
405 fi
406 ;;
407
408 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200409 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100410 exit 1
411 esac
412 shift 2
413 done
414
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100415 # check valgrind's results
416 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200417 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100418 fail "Server has memory errors"
419 return
420 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200421 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100422 fail "Client has memory errors"
423 return
424 fi
425 fi
426
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100427 # if we're here, everything is ok
428 echo "PASS"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200429 rm -f $SRV_OUT $CLI_OUT $PXY_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100430}
431
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100432cleanup() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200433 rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200434 test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
435 test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
436 test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
437 test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100438 exit 1
439}
440
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100441#
442# MAIN
443#
444
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100445get_options "$@"
446
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100447# sanity checks, avoid an avalanche of errors
448if [ ! -x "$P_SRV" ]; then
449 echo "Command '$P_SRV' is not an executable file"
450 exit 1
451fi
452if [ ! -x "$P_CLI" ]; then
453 echo "Command '$P_CLI' is not an executable file"
454 exit 1
455fi
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200456if [ ! -x "$P_PXY" ]; then
457 echo "Command '$P_PXY' is not an executable file"
458 exit 1
459fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100460if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
461 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100462 exit 1
463fi
464
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200465# used by watchdog
466MAIN_PID="$$"
467
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200468# be more patient with valgrind
469if [ "$MEMCHECK" -gt 0 ]; then
470 START_DELAY=3
471 DOG_DELAY=30
472else
473 START_DELAY=1
474 DOG_DELAY=10
475fi
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200476CLI_DELAY_FACTOR=1
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200477
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200478# Pick a "unique" server port in the range 10000-19999, and a proxy port
479PORT_BASE="0000$$"
480PORT_BASE="$( echo -n $PORT_BASE | tail -c 4 )"
481SRV_PORT="1$PORT_BASE"
482PXY_PORT="2$PORT_BASE"
483unset PORT_BASE
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200484
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200485# fix commands to use this port, force IPv4 while at it
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200486P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
487P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
488P_PXY="$P_PXY server_addr=127.0.0.1 server_port=$SRV_PORT listen_addr=127.0.0.1 listen_port=$PXY_PORT"
489O_SRV="$O_SRV -accept $SRV_PORT"
490O_CLI="$O_CLI -connect localhost:+SRV_PORT"
491G_SRV="$G_SRV -p $SRV_PORT"
492G_CLI="$G_CLI -p +SRV_PORT"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200493
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200494# Also pick a unique name for intermediate files
495SRV_OUT="srv_out.$$"
496CLI_OUT="cli_out.$$"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200497PXY_OUT="pxy_out.$$"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200498SESSION="session.$$"
499
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200500SKIP_NEXT="NO"
501
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100502trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100503
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200504# Basic test
505
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200506# Checks that:
507# - things work with all ciphersuites active (used with config-full in all.sh)
508# - the expected (highest security) parameters are selected
509# ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200510run_test "Default" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200511 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200512 "$P_CLI" \
513 0 \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200514 -s "Protocol is TLSv1.2" \
515 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
516 -s "client hello v3, signature_algorithm ext: 6" \
517 -s "ECDHE curve: secp521r1" \
518 -S "error" \
519 -C "error"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200520
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100521# Test for SSLv2 ClientHello
522
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200523requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200524run_test "SSLv2 ClientHello: reference" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100525 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +0100526 "$O_CLI -no_ssl2" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100527 0 \
528 -S "parse client hello v2" \
529 -S "ssl_handshake returned"
530
531# Adding a SSL2-only suite makes OpenSSL client send SSLv2 ClientHello
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200532requires_openssl_with_sslv2
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200533run_test "SSLv2 ClientHello: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200534 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100535 "$O_CLI -cipher 'DES-CBC-MD5:ALL'" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100536 0 \
537 -s "parse client hello v2" \
538 -S "ssl_handshake returned"
539
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100540# Tests for Truncated HMAC extension
541
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200542run_test "Truncated HMAC: reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200543 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100544 "$P_CLI trunc_hmac=0 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100545 0 \
546 -s "dumping 'computed mac' (20 bytes)"
547
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200548run_test "Truncated HMAC: actual test" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200549 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100550 "$P_CLI trunc_hmac=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100551 0 \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100552 -s "dumping 'computed mac' (10 bytes)"
553
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100554# Tests for Session Tickets
555
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200556run_test "Session resume using tickets: basic" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200557 "$P_SRV debug_level=3 tickets=1" \
558 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100559 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100560 -c "client hello, adding session ticket extension" \
561 -s "found session ticket extension" \
562 -s "server hello, adding session ticket extension" \
563 -c "found session_ticket extension" \
564 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100565 -S "session successfully restored from cache" \
566 -s "session successfully restored from ticket" \
567 -s "a session has been resumed" \
568 -c "a session has been resumed"
569
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200570run_test "Session resume using tickets: cache disabled" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200571 "$P_SRV debug_level=3 tickets=1 cache_max=0" \
572 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100573 0 \
574 -c "client hello, adding session ticket extension" \
575 -s "found session ticket extension" \
576 -s "server hello, adding session ticket extension" \
577 -c "found session_ticket extension" \
578 -c "parse new session ticket" \
579 -S "session successfully restored from cache" \
580 -s "session successfully restored from ticket" \
581 -s "a session has been resumed" \
582 -c "a session has been resumed"
583
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200584run_test "Session resume using tickets: timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200585 "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
586 "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +0100587 0 \
588 -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" \
593 -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 tickets: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100599 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200600 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100601 0 \
602 -c "client hello, adding session ticket extension" \
603 -c "found session_ticket extension" \
604 -c "parse new session ticket" \
605 -c "a session has been resumed"
606
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200607run_test "Session resume using tickets: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200608 "$P_SRV debug_level=3 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200609 "( $O_CLI -sess_out $SESSION; \
610 $O_CLI -sess_in $SESSION; \
611 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100612 0 \
613 -s "found session ticket extension" \
614 -s "server hello, adding session ticket extension" \
615 -S "session successfully restored from cache" \
616 -s "session successfully restored from ticket" \
617 -s "a session has been resumed"
618
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100619# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100620
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200621run_test "Session resume using cache: tickets enabled on client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200622 "$P_SRV debug_level=3 tickets=0" \
623 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100624 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100625 -c "client hello, adding session ticket extension" \
626 -s "found session ticket extension" \
627 -S "server hello, adding session ticket extension" \
628 -C "found session_ticket extension" \
629 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100630 -s "session successfully restored from cache" \
631 -S "session successfully restored from ticket" \
632 -s "a session has been resumed" \
633 -c "a session has been resumed"
634
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200635run_test "Session resume using cache: tickets enabled on server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200636 "$P_SRV debug_level=3 tickets=1" \
637 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100638 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100639 -C "client hello, adding session ticket extension" \
640 -S "found session ticket extension" \
641 -S "server hello, adding session ticket extension" \
642 -C "found session_ticket extension" \
643 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100644 -s "session successfully restored from cache" \
645 -S "session successfully restored from ticket" \
646 -s "a session has been resumed" \
647 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100648
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200649run_test "Session resume using cache: cache_max=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200650 "$P_SRV debug_level=3 tickets=0 cache_max=0" \
651 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100652 0 \
653 -S "session successfully restored from cache" \
654 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100655 -S "a session has been resumed" \
656 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100657
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200658run_test "Session resume using cache: cache_max=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200659 "$P_SRV debug_level=3 tickets=0 cache_max=1" \
660 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100661 0 \
662 -s "session successfully restored from cache" \
663 -S "session successfully restored from ticket" \
664 -s "a session has been resumed" \
665 -c "a session has been resumed"
666
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200667run_test "Session resume using cache: timemout > delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200668 "$P_SRV debug_level=3 tickets=0" \
669 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100670 0 \
671 -s "session successfully restored from cache" \
672 -S "session successfully restored from ticket" \
673 -s "a session has been resumed" \
674 -c "a session has been resumed"
675
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200676run_test "Session resume using cache: timeout < delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200677 "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
678 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +0100679 0 \
680 -S "session successfully restored from cache" \
681 -S "session successfully restored from ticket" \
682 -S "a session has been resumed" \
683 -C "a session has been resumed"
684
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200685run_test "Session resume using cache: no timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200686 "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
687 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +0100688 0 \
689 -s "session successfully restored from cache" \
690 -S "session successfully restored from ticket" \
691 -s "a session has been resumed" \
692 -c "a session has been resumed"
693
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200694run_test "Session resume using cache: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200695 "$P_SRV debug_level=3 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200696 "( $O_CLI -sess_out $SESSION; \
697 $O_CLI -sess_in $SESSION; \
698 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100699 0 \
700 -s "found session ticket extension" \
701 -S "server hello, adding session ticket extension" \
702 -s "session successfully restored from cache" \
703 -S "session successfully restored from ticket" \
704 -s "a session has been resumed"
705
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200706run_test "Session resume using cache: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100707 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200708 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +0100709 0 \
710 -C "found session_ticket extension" \
711 -C "parse new session ticket" \
712 -c "a session has been resumed"
713
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100714# Tests for Max Fragment Length extension
715
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200716run_test "Max fragment length: not used, reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200717 "$P_SRV debug_level=3" \
718 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100719 0 \
720 -C "client hello, adding max_fragment_length extension" \
721 -S "found max fragment length extension" \
722 -S "server hello, max_fragment_length extension" \
723 -C "found max_fragment_length extension"
724
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200725run_test "Max fragment length: used by client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200726 "$P_SRV debug_level=3" \
727 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100728 0 \
729 -c "client hello, adding max_fragment_length extension" \
730 -s "found max fragment length extension" \
731 -s "server hello, max_fragment_length extension" \
732 -c "found max_fragment_length extension"
733
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200734run_test "Max fragment length: used by server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200735 "$P_SRV debug_level=3 max_frag_len=4096" \
736 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +0100737 0 \
738 -C "client hello, adding max_fragment_length extension" \
739 -S "found max fragment length extension" \
740 -S "server hello, max_fragment_length extension" \
741 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100742
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200743requires_gnutls
744run_test "Max fragment length: gnutls server" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200745 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200746 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200747 0 \
748 -c "client hello, adding max_fragment_length extension" \
749 -c "found max_fragment_length extension"
750
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100751# Tests for renegotiation
752
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200753run_test "Renegotiation: none, for reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200754 "$P_SRV debug_level=3 exchanges=2" \
755 "$P_CLI debug_level=3 exchanges=2" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100756 0 \
757 -C "client hello, adding renegotiation extension" \
758 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
759 -S "found renegotiation extension" \
760 -s "server hello, secure renegotiation extension" \
761 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100762 -C "=> renegotiate" \
763 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100764 -S "write hello request"
765
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200766run_test "Renegotiation: client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200767 "$P_SRV debug_level=3 exchanges=2 renegotiation=1" \
768 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100769 0 \
770 -c "client hello, adding renegotiation extension" \
771 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
772 -s "found renegotiation extension" \
773 -s "server hello, secure renegotiation extension" \
774 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100775 -c "=> renegotiate" \
776 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100777 -S "write hello request"
778
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200779run_test "Renegotiation: server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200780 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
781 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100782 0 \
783 -c "client hello, adding renegotiation extension" \
784 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
785 -s "found renegotiation extension" \
786 -s "server hello, secure renegotiation extension" \
787 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100788 -c "=> renegotiate" \
789 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100790 -s "write hello request"
791
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200792run_test "Renegotiation: double" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200793 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
794 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100795 0 \
796 -c "client hello, adding renegotiation extension" \
797 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
798 -s "found renegotiation extension" \
799 -s "server hello, secure renegotiation extension" \
800 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100801 -c "=> renegotiate" \
802 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100803 -s "write hello request"
804
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200805run_test "Renegotiation: client-initiated, server-rejected" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200806 "$P_SRV debug_level=3 exchanges=2 renegotiation=0" \
807 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100808 1 \
809 -c "client hello, adding renegotiation extension" \
810 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
811 -S "found renegotiation extension" \
812 -s "server hello, secure renegotiation extension" \
813 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100814 -c "=> renegotiate" \
815 -S "=> renegotiate" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200816 -S "write hello request" \
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +0200817 -c "SSL - Unexpected message at ServerHello in renegotiation" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200818 -c "failed"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100819
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200820run_test "Renegotiation: server-initiated, client-rejected, default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200821 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
822 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100823 0 \
824 -C "client hello, adding renegotiation extension" \
825 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
826 -S "found renegotiation extension" \
827 -s "server hello, secure renegotiation extension" \
828 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100829 -C "=> renegotiate" \
830 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100831 -s "write hello request" \
Manuel Pégourié-Gonnarda9964db2014-07-03 19:29:16 +0200832 -S "SSL - An unexpected message was received from our peer" \
833 -S "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100834
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200835run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200836 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200837 renego_delay=-1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200838 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200839 0 \
840 -C "client hello, adding renegotiation extension" \
841 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
842 -S "found renegotiation extension" \
843 -s "server hello, secure renegotiation extension" \
844 -c "found renegotiation extension" \
845 -C "=> renegotiate" \
846 -S "=> renegotiate" \
847 -s "write hello request" \
848 -S "SSL - An unexpected message was received from our peer" \
849 -S "failed"
850
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200851# delay 2 for 1 alert record + 1 application data record
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200852run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200853 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200854 renego_delay=2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200855 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200856 0 \
857 -C "client hello, adding renegotiation extension" \
858 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
859 -S "found renegotiation extension" \
860 -s "server hello, secure renegotiation extension" \
861 -c "found renegotiation extension" \
862 -C "=> renegotiate" \
863 -S "=> renegotiate" \
864 -s "write hello request" \
865 -S "SSL - An unexpected message was received from our peer" \
866 -S "failed"
867
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200868run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200869 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200870 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200871 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200872 0 \
873 -C "client hello, adding renegotiation extension" \
874 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
875 -S "found renegotiation extension" \
876 -s "server hello, secure renegotiation extension" \
877 -c "found renegotiation extension" \
878 -C "=> renegotiate" \
879 -S "=> renegotiate" \
880 -s "write hello request" \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +0200881 -s "SSL - An unexpected message was received from our peer"
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200882
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200883run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200884 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200885 renego_delay=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200886 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +0200887 0 \
888 -c "client hello, adding renegotiation extension" \
889 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
890 -s "found renegotiation extension" \
891 -s "server hello, secure renegotiation extension" \
892 -c "found renegotiation extension" \
893 -c "=> renegotiate" \
894 -s "=> renegotiate" \
895 -s "write hello request" \
896 -S "SSL - An unexpected message was received from our peer" \
897 -S "failed"
898
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200899run_test "Renegotiation: nbio, client-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200900 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
901 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200902 0 \
903 -c "client hello, adding renegotiation extension" \
904 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
905 -s "found renegotiation extension" \
906 -s "server hello, secure renegotiation extension" \
907 -c "found renegotiation extension" \
908 -c "=> renegotiate" \
909 -s "=> renegotiate" \
910 -S "write hello request"
911
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200912run_test "Renegotiation: nbio, server-initiated" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200913 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
914 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +0200915 0 \
916 -c "client hello, adding renegotiation extension" \
917 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
918 -s "found renegotiation extension" \
919 -s "server hello, secure renegotiation extension" \
920 -c "found renegotiation extension" \
921 -c "=> renegotiate" \
922 -s "=> renegotiate" \
923 -s "write hello request"
924
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200925run_test "Renegotiation: openssl server, client-initiated" \
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +0200926 "$O_SRV -www" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200927 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200928 0 \
929 -c "client hello, adding renegotiation extension" \
930 -c "found renegotiation extension" \
931 -c "=> renegotiate" \
932 -C "ssl_handshake returned" \
933 -C "error" \
934 -c "HTTP/1.0 200 [Oo][Kk]"
935
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200936run_test "Renegotiation: gnutls server, client-initiated" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200937 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200938 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +0200939 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 -c "HTTP/1.0 200 [Oo][Kk]"
946
Manuel Pégourié-Gonnard30d16eb2014-08-19 17:43:50 +0200947run_test "Renegotiation: DTLS, client-initiated" \
948 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
949 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
950 0 \
951 -c "client hello, adding renegotiation extension" \
952 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
953 -s "found renegotiation extension" \
954 -s "server hello, secure renegotiation extension" \
955 -c "found renegotiation extension" \
956 -c "=> renegotiate" \
957 -s "=> renegotiate" \
958 -S "write hello request"
959
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +0200960run_test "Renegotiation: DTLS, server-initiated" \
961 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnarddf9a0a82014-10-02 14:17:18 +0200962 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
963 read_timeout=1000 max_resend=2" \
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +0200964 0 \
965 -c "client hello, adding renegotiation extension" \
966 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
967 -s "found renegotiation extension" \
968 -s "server hello, secure renegotiation extension" \
969 -c "found renegotiation extension" \
970 -c "=> renegotiate" \
971 -s "=> renegotiate" \
972 -s "write hello request"
973
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +0200974run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
975 "$G_SRV -u --mtu 4096" \
976 "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
977 0 \
978 -c "client hello, adding renegotiation extension" \
979 -c "found renegotiation extension" \
980 -c "=> renegotiate" \
981 -C "ssl_handshake returned" \
982 -C "error" \
983 -s "Extra-header:"
984
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100985# Tests for auth_mode
986
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200987run_test "Authentication: server badcert, client required" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100988 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100989 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200990 "$P_CLI debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100991 1 \
992 -c "x509_verify_cert() returned" \
993 -c "! self-signed or not signed by a trusted CA" \
994 -c "! ssl_handshake returned" \
995 -c "X509 - Certificate verification failed"
996
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +0200997run_test "Authentication: server badcert, client optional" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +0100998 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +0100999 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001000 "$P_CLI debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001001 0 \
1002 -c "x509_verify_cert() returned" \
1003 -c "! self-signed or not signed by a trusted CA" \
1004 -C "! ssl_handshake returned" \
1005 -C "X509 - Certificate verification failed"
1006
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001007run_test "Authentication: server badcert, client none" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +01001008 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001009 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001010 "$P_CLI debug_level=1 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001011 0 \
1012 -C "x509_verify_cert() returned" \
1013 -C "! self-signed or not signed by a trusted CA" \
1014 -C "! ssl_handshake returned" \
1015 -C "X509 - Certificate verification failed"
1016
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001017run_test "Authentication: client badcert, server required" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001018 "$P_SRV debug_level=3 auth_mode=required" \
1019 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001020 key_file=data_files/server5.key" \
1021 1 \
1022 -S "skip write certificate request" \
1023 -C "skip parse certificate request" \
1024 -c "got a certificate request" \
1025 -C "skip write certificate" \
1026 -C "skip write certificate verify" \
1027 -S "skip parse certificate verify" \
1028 -s "x509_verify_cert() returned" \
1029 -S "! self-signed or not signed by a trusted CA" \
1030 -s "! ssl_handshake returned" \
1031 -c "! ssl_handshake returned" \
1032 -s "X509 - Certificate verification failed"
1033
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001034run_test "Authentication: client badcert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001035 "$P_SRV debug_level=3 auth_mode=optional" \
1036 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001037 key_file=data_files/server5.key" \
1038 0 \
1039 -S "skip write certificate request" \
1040 -C "skip parse certificate request" \
1041 -c "got a certificate request" \
1042 -C "skip write certificate" \
1043 -C "skip write certificate verify" \
1044 -S "skip parse certificate verify" \
1045 -s "x509_verify_cert() returned" \
1046 -s "! self-signed or not signed by a trusted CA" \
1047 -S "! ssl_handshake returned" \
1048 -C "! ssl_handshake returned" \
1049 -S "X509 - Certificate verification failed"
1050
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001051run_test "Authentication: client badcert, server none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001052 "$P_SRV debug_level=3 auth_mode=none" \
1053 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001054 key_file=data_files/server5.key" \
1055 0 \
1056 -s "skip write certificate request" \
1057 -C "skip parse certificate request" \
1058 -c "got no certificate request" \
1059 -c "skip write certificate" \
1060 -c "skip write certificate verify" \
1061 -s "skip parse certificate verify" \
1062 -S "x509_verify_cert() returned" \
1063 -S "! self-signed or not signed by a trusted CA" \
1064 -S "! ssl_handshake returned" \
1065 -C "! ssl_handshake returned" \
1066 -S "X509 - Certificate verification failed"
1067
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001068run_test "Authentication: client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001069 "$P_SRV debug_level=3 auth_mode=optional" \
1070 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001071 0 \
1072 -S "skip write certificate request" \
1073 -C "skip parse certificate request" \
1074 -c "got a certificate request" \
1075 -C "skip write certificate$" \
1076 -C "got no certificate to send" \
1077 -S "SSLv3 client has no certificate" \
1078 -c "skip write certificate verify" \
1079 -s "skip parse certificate verify" \
1080 -s "! no client certificate sent" \
1081 -S "! ssl_handshake returned" \
1082 -C "! ssl_handshake returned" \
1083 -S "X509 - Certificate verification failed"
1084
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001085run_test "Authentication: openssl client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001086 "$P_SRV debug_level=3 auth_mode=optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001087 "$O_CLI" \
1088 0 \
1089 -S "skip write certificate request" \
1090 -s "skip parse certificate verify" \
1091 -s "! no client certificate sent" \
1092 -S "! ssl_handshake returned" \
1093 -S "X509 - Certificate verification failed"
1094
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001095run_test "Authentication: client no cert, openssl server optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001096 "$O_SRV -verify 10" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001097 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001098 0 \
1099 -C "skip parse certificate request" \
1100 -c "got a certificate request" \
1101 -C "skip write certificate$" \
1102 -c "skip write certificate verify" \
1103 -C "! ssl_handshake returned"
1104
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001105run_test "Authentication: client no cert, ssl3" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001106 "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
1107 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01001108 0 \
1109 -S "skip write certificate request" \
1110 -C "skip parse certificate request" \
1111 -c "got a certificate request" \
1112 -C "skip write certificate$" \
1113 -c "skip write certificate verify" \
1114 -c "got no certificate to send" \
1115 -s "SSLv3 client has no certificate" \
1116 -s "skip parse certificate verify" \
1117 -s "! no client certificate sent" \
1118 -S "! ssl_handshake returned" \
1119 -C "! ssl_handshake returned" \
1120 -S "X509 - Certificate verification failed"
1121
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001122# tests for SNI
1123
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001124run_test "SNI: no SNI callback" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001125 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001126 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001127 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001128 0 \
1129 -S "parse ServerName extension" \
1130 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
1131 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1132
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001133run_test "SNI: matching cert 1" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001134 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001135 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001136 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 +02001137 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001138 0 \
1139 -s "parse ServerName extension" \
1140 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
1141 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
1142
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001143run_test "SNI: matching cert 2" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001144 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001145 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001146 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 +02001147 "$P_CLI server_name=polarssl.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001148 0 \
1149 -s "parse ServerName extension" \
1150 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001151 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001152
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001153run_test "SNI: no matching cert" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02001154 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001155 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard76b8ab72014-03-26 09:31:35 +01001156 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 +02001157 "$P_CLI server_name=nonesuch.example" \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01001158 1 \
1159 -s "parse ServerName extension" \
1160 -s "ssl_sni_wrapper() returned" \
1161 -s "ssl_handshake returned" \
1162 -c "ssl_handshake returned" \
1163 -c "SSL - A fatal alert message was received from our peer"
1164
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001165# Tests for non-blocking I/O: exercise a variety of handshake flows
1166
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001167run_test "Non-blocking I/O: basic handshake" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001168 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1169 "$P_CLI nbio=2 tickets=0" \
1170 0 \
1171 -S "ssl_handshake returned" \
1172 -C "ssl_handshake returned" \
1173 -c "Read from server: .* bytes read"
1174
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001175run_test "Non-blocking I/O: client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001176 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
1177 "$P_CLI nbio=2 tickets=0" \
1178 0 \
1179 -S "ssl_handshake returned" \
1180 -C "ssl_handshake returned" \
1181 -c "Read from server: .* bytes read"
1182
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001183run_test "Non-blocking I/O: ticket" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001184 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1185 "$P_CLI nbio=2 tickets=1" \
1186 0 \
1187 -S "ssl_handshake returned" \
1188 -C "ssl_handshake returned" \
1189 -c "Read from server: .* bytes read"
1190
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001191run_test "Non-blocking I/O: ticket + client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001192 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1193 "$P_CLI nbio=2 tickets=1" \
1194 0 \
1195 -S "ssl_handshake returned" \
1196 -C "ssl_handshake returned" \
1197 -c "Read from server: .* bytes read"
1198
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001199run_test "Non-blocking I/O: ticket + client auth + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001200 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
1201 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1202 0 \
1203 -S "ssl_handshake returned" \
1204 -C "ssl_handshake returned" \
1205 -c "Read from server: .* bytes read"
1206
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001207run_test "Non-blocking I/O: ticket + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001208 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
1209 "$P_CLI nbio=2 tickets=1 reconnect=1" \
1210 0 \
1211 -S "ssl_handshake returned" \
1212 -C "ssl_handshake returned" \
1213 -c "Read from server: .* bytes read"
1214
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001215run_test "Non-blocking I/O: session-id resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01001216 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
1217 "$P_CLI nbio=2 tickets=0 reconnect=1" \
1218 0 \
1219 -S "ssl_handshake returned" \
1220 -C "ssl_handshake returned" \
1221 -c "Read from server: .* bytes read"
1222
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001223# Tests for version negotiation
1224
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001225run_test "Version check: all -> 1.2" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001226 "$P_SRV" \
1227 "$P_CLI" \
1228 0 \
1229 -S "ssl_handshake returned" \
1230 -C "ssl_handshake returned" \
1231 -s "Protocol is TLSv1.2" \
1232 -c "Protocol is TLSv1.2"
1233
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001234run_test "Version check: cli max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001235 "$P_SRV" \
1236 "$P_CLI max_version=tls1_1" \
1237 0 \
1238 -S "ssl_handshake returned" \
1239 -C "ssl_handshake returned" \
1240 -s "Protocol is TLSv1.1" \
1241 -c "Protocol is TLSv1.1"
1242
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001243run_test "Version check: srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001244 "$P_SRV max_version=tls1_1" \
1245 "$P_CLI" \
1246 0 \
1247 -S "ssl_handshake returned" \
1248 -C "ssl_handshake returned" \
1249 -s "Protocol is TLSv1.1" \
1250 -c "Protocol is TLSv1.1"
1251
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001252run_test "Version check: cli+srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001253 "$P_SRV max_version=tls1_1" \
1254 "$P_CLI max_version=tls1_1" \
1255 0 \
1256 -S "ssl_handshake returned" \
1257 -C "ssl_handshake returned" \
1258 -s "Protocol is TLSv1.1" \
1259 -c "Protocol is TLSv1.1"
1260
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001261run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001262 "$P_SRV min_version=tls1_1" \
1263 "$P_CLI max_version=tls1_1" \
1264 0 \
1265 -S "ssl_handshake returned" \
1266 -C "ssl_handshake returned" \
1267 -s "Protocol is TLSv1.1" \
1268 -c "Protocol is TLSv1.1"
1269
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001270run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001271 "$P_SRV max_version=tls1_1" \
1272 "$P_CLI min_version=tls1_1" \
1273 0 \
1274 -S "ssl_handshake returned" \
1275 -C "ssl_handshake returned" \
1276 -s "Protocol is TLSv1.1" \
1277 -c "Protocol is TLSv1.1"
1278
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001279run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001280 "$P_SRV max_version=tls1_1" \
1281 "$P_CLI min_version=tls1_2" \
1282 1 \
1283 -s "ssl_handshake returned" \
1284 -c "ssl_handshake returned" \
1285 -c "SSL - Handshake protocol not within min/max boundaries"
1286
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001287run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01001288 "$P_SRV min_version=tls1_2" \
1289 "$P_CLI max_version=tls1_1" \
1290 1 \
1291 -s "ssl_handshake returned" \
1292 -c "ssl_handshake returned" \
1293 -s "SSL - Handshake protocol not within min/max boundaries"
1294
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001295# Tests for ALPN extension
1296
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001297if grep '^#define POLARSSL_SSL_ALPN' $CONFIG_H >/dev/null; then
1298
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001299run_test "ALPN: none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001300 "$P_SRV debug_level=3" \
1301 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001302 0 \
1303 -C "client hello, adding alpn extension" \
1304 -S "found alpn extension" \
1305 -C "got an alert message, type: \\[2:120]" \
1306 -S "server hello, adding alpn extension" \
1307 -C "found alpn extension " \
1308 -C "Application Layer Protocol is" \
1309 -S "Application Layer Protocol is"
1310
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001311run_test "ALPN: client only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001312 "$P_SRV debug_level=3" \
1313 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001314 0 \
1315 -c "client hello, adding alpn extension" \
1316 -s "found alpn extension" \
1317 -C "got an alert message, type: \\[2:120]" \
1318 -S "server hello, adding alpn extension" \
1319 -C "found alpn extension " \
1320 -c "Application Layer Protocol is (none)" \
1321 -S "Application Layer Protocol is"
1322
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001323run_test "ALPN: server only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001324 "$P_SRV debug_level=3 alpn=abc,1234" \
1325 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001326 0 \
1327 -C "client hello, adding alpn extension" \
1328 -S "found alpn extension" \
1329 -C "got an alert message, type: \\[2:120]" \
1330 -S "server hello, adding alpn extension" \
1331 -C "found alpn extension " \
1332 -C "Application Layer Protocol is" \
1333 -s "Application Layer Protocol is (none)"
1334
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001335run_test "ALPN: both, common cli1-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001336 "$P_SRV debug_level=3 alpn=abc,1234" \
1337 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001338 0 \
1339 -c "client hello, adding alpn extension" \
1340 -s "found alpn extension" \
1341 -C "got an alert message, type: \\[2:120]" \
1342 -s "server hello, adding alpn extension" \
1343 -c "found alpn extension" \
1344 -c "Application Layer Protocol is abc" \
1345 -s "Application Layer Protocol is abc"
1346
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001347run_test "ALPN: both, common cli2-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001348 "$P_SRV debug_level=3 alpn=abc,1234" \
1349 "$P_CLI debug_level=3 alpn=1234,abc" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001350 0 \
1351 -c "client hello, adding alpn extension" \
1352 -s "found alpn extension" \
1353 -C "got an alert message, type: \\[2:120]" \
1354 -s "server hello, adding alpn extension" \
1355 -c "found alpn extension" \
1356 -c "Application Layer Protocol is abc" \
1357 -s "Application Layer Protocol is abc"
1358
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001359run_test "ALPN: both, common cli1-srv2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001360 "$P_SRV debug_level=3 alpn=abc,1234" \
1361 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001362 0 \
1363 -c "client hello, adding alpn extension" \
1364 -s "found alpn extension" \
1365 -C "got an alert message, type: \\[2:120]" \
1366 -s "server hello, adding alpn extension" \
1367 -c "found alpn extension" \
1368 -c "Application Layer Protocol is 1234" \
1369 -s "Application Layer Protocol is 1234"
1370
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001371run_test "ALPN: both, no common" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001372 "$P_SRV debug_level=3 alpn=abc,123" \
1373 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02001374 1 \
1375 -c "client hello, adding alpn extension" \
1376 -s "found alpn extension" \
1377 -c "got an alert message, type: \\[2:120]" \
1378 -S "server hello, adding alpn extension" \
1379 -C "found alpn extension" \
1380 -C "Application Layer Protocol is 1234" \
1381 -S "Application Layer Protocol is 1234"
1382
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02001383fi
1384
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001385# Tests for keyUsage in leaf certificates, part 1:
1386# server-side certificate/suite selection
1387
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001388run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001389 "$P_SRV key_file=data_files/server2.key \
1390 crt_file=data_files/server2.ku-ds.crt" \
1391 "$P_CLI" \
1392 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02001393 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001394
1395
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001396run_test "keyUsage srv: RSA, keyEncipherment -> RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001397 "$P_SRV key_file=data_files/server2.key \
1398 crt_file=data_files/server2.ku-ke.crt" \
1399 "$P_CLI" \
1400 0 \
1401 -c "Ciphersuite is TLS-RSA-WITH-"
1402
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001403run_test "keyUsage srv: RSA, keyAgreement -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001404 "$P_SRV key_file=data_files/server2.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001405 crt_file=data_files/server2.ku-ka.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001406 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001407 1 \
1408 -C "Ciphersuite is "
1409
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001410run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001411 "$P_SRV key_file=data_files/server5.key \
1412 crt_file=data_files/server5.ku-ds.crt" \
1413 "$P_CLI" \
1414 0 \
1415 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
1416
1417
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001418run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001419 "$P_SRV key_file=data_files/server5.key \
1420 crt_file=data_files/server5.ku-ka.crt" \
1421 "$P_CLI" \
1422 0 \
1423 -c "Ciphersuite is TLS-ECDH-"
1424
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001425run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001426 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001427 crt_file=data_files/server5.ku-ke.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02001428 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001429 1 \
1430 -C "Ciphersuite is "
1431
1432# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001433# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001434
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001435run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001436 "$O_SRV -key data_files/server2.key \
1437 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001438 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001439 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1440 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001441 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001442 -C "Processing of the Certificate handshake message failed" \
1443 -c "Ciphersuite is TLS-"
1444
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001445run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001446 "$O_SRV -key data_files/server2.key \
1447 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001448 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001449 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1450 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001451 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001452 -C "Processing of the Certificate handshake message failed" \
1453 -c "Ciphersuite is TLS-"
1454
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001455run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001456 "$O_SRV -key data_files/server2.key \
1457 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001458 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001459 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1460 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001461 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001462 -C "Processing of the Certificate handshake message failed" \
1463 -c "Ciphersuite is TLS-"
1464
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001465run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001466 "$O_SRV -key data_files/server2.key \
1467 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001468 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001469 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1470 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001471 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001472 -c "Processing of the Certificate handshake message failed" \
1473 -C "Ciphersuite is TLS-"
1474
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001475run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001476 "$O_SRV -key data_files/server2.key \
1477 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001478 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001479 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
1480 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001481 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001482 -C "Processing of the Certificate handshake message failed" \
1483 -c "Ciphersuite is TLS-"
1484
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001485run_test "keyUsage cli: DigitalSignature, RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001486 "$O_SRV -key data_files/server2.key \
1487 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001488 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001489 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
1490 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001491 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02001492 -c "Processing of the Certificate handshake message failed" \
1493 -C "Ciphersuite is TLS-"
1494
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001495# Tests for keyUsage in leaf certificates, part 3:
1496# server-side checking of client cert
1497
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001498run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001499 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001500 "$O_CLI -key data_files/server2.key \
1501 -cert data_files/server2.ku-ds.crt" \
1502 0 \
1503 -S "bad certificate (usage extensions)" \
1504 -S "Processing of the Certificate handshake message failed"
1505
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001506run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001507 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001508 "$O_CLI -key data_files/server2.key \
1509 -cert data_files/server2.ku-ke.crt" \
1510 0 \
1511 -s "bad certificate (usage extensions)" \
1512 -S "Processing of the Certificate handshake message failed"
1513
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001514run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001515 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001516 "$O_CLI -key data_files/server2.key \
1517 -cert data_files/server2.ku-ke.crt" \
1518 1 \
1519 -s "bad certificate (usage extensions)" \
1520 -s "Processing of the Certificate handshake message failed"
1521
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001522run_test "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001523 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001524 "$O_CLI -key data_files/server5.key \
1525 -cert data_files/server5.ku-ds.crt" \
1526 0 \
1527 -S "bad certificate (usage extensions)" \
1528 -S "Processing of the Certificate handshake message failed"
1529
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001530run_test "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001531 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02001532 "$O_CLI -key data_files/server5.key \
1533 -cert data_files/server5.ku-ka.crt" \
1534 0 \
1535 -s "bad certificate (usage extensions)" \
1536 -S "Processing of the Certificate handshake message failed"
1537
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001538# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
1539
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001540run_test "extKeyUsage srv: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001541 "$P_SRV key_file=data_files/server5.key \
1542 crt_file=data_files/server5.eku-srv.crt" \
1543 "$P_CLI" \
1544 0
1545
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001546run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001547 "$P_SRV key_file=data_files/server5.key \
1548 crt_file=data_files/server5.eku-srv.crt" \
1549 "$P_CLI" \
1550 0
1551
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001552run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001553 "$P_SRV key_file=data_files/server5.key \
1554 crt_file=data_files/server5.eku-cs_any.crt" \
1555 "$P_CLI" \
1556 0
1557
1558# add psk to leave an option for client to send SERVERQUIT
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001559run_test "extKeyUsage srv: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001560 "$P_SRV psk=abc123 key_file=data_files/server5.key \
1561 crt_file=data_files/server5.eku-cli.crt" \
1562 "$P_CLI psk=badbad" \
1563 1
1564
1565# Tests for extendedKeyUsage, part 2: client-side checking of server cert
1566
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001567run_test "extKeyUsage cli: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001568 "$O_SRV -key data_files/server5.key \
1569 -cert data_files/server5.eku-srv.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001570 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001571 0 \
1572 -C "bad certificate (usage extensions)" \
1573 -C "Processing of the Certificate handshake message failed" \
1574 -c "Ciphersuite is TLS-"
1575
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001576run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001577 "$O_SRV -key data_files/server5.key \
1578 -cert data_files/server5.eku-srv_cli.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001579 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001580 0 \
1581 -C "bad certificate (usage extensions)" \
1582 -C "Processing of the Certificate handshake message failed" \
1583 -c "Ciphersuite is TLS-"
1584
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001585run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001586 "$O_SRV -key data_files/server5.key \
1587 -cert data_files/server5.eku-cs_any.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001588 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001589 0 \
1590 -C "bad certificate (usage extensions)" \
1591 -C "Processing of the Certificate handshake message failed" \
1592 -c "Ciphersuite is TLS-"
1593
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001594run_test "extKeyUsage cli: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001595 "$O_SRV -key data_files/server5.key \
1596 -cert data_files/server5.eku-cs.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001597 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001598 1 \
1599 -c "bad certificate (usage extensions)" \
1600 -c "Processing of the Certificate handshake message failed" \
1601 -C "Ciphersuite is TLS-"
1602
1603# Tests for extendedKeyUsage, part 3: server-side checking of client cert
1604
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001605run_test "extKeyUsage cli-auth: clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001606 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001607 "$O_CLI -key data_files/server5.key \
1608 -cert data_files/server5.eku-cli.crt" \
1609 0 \
1610 -S "bad certificate (usage extensions)" \
1611 -S "Processing of the Certificate handshake message failed"
1612
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001613run_test "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001614 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001615 "$O_CLI -key data_files/server5.key \
1616 -cert data_files/server5.eku-srv_cli.crt" \
1617 0 \
1618 -S "bad certificate (usage extensions)" \
1619 -S "Processing of the Certificate handshake message failed"
1620
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001621run_test "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001622 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001623 "$O_CLI -key data_files/server5.key \
1624 -cert data_files/server5.eku-cs_any.crt" \
1625 0 \
1626 -S "bad certificate (usage extensions)" \
1627 -S "Processing of the Certificate handshake message failed"
1628
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001629run_test "extKeyUsage cli-auth: codeSign -> fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001630 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001631 "$O_CLI -key data_files/server5.key \
1632 -cert data_files/server5.eku-cs.crt" \
1633 0 \
1634 -s "bad certificate (usage extensions)" \
1635 -S "Processing of the Certificate handshake message failed"
1636
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001637run_test "extKeyUsage cli-auth: codeSign -> fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001638 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02001639 "$O_CLI -key data_files/server5.key \
1640 -cert data_files/server5.eku-cs.crt" \
1641 1 \
1642 -s "bad certificate (usage extensions)" \
1643 -s "Processing of the Certificate handshake message failed"
1644
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001645# Tests for DHM parameters loading
1646
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001647run_test "DHM parameters: reference" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001648 "$P_SRV" \
1649 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1650 debug_level=3" \
1651 0 \
1652 -c "value of 'DHM: P ' (2048 bits)" \
1653 -c "value of 'DHM: G ' (2048 bits)"
1654
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001655run_test "DHM parameters: other parameters" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001656 "$P_SRV dhm_file=data_files/dhparams.pem" \
1657 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1658 debug_level=3" \
1659 0 \
1660 -c "value of 'DHM: P ' (1024 bits)" \
1661 -c "value of 'DHM: G ' (2 bits)"
1662
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001663# Tests for PSK callback
1664
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001665run_test "PSK callback: psk, no callback" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001666 "$P_SRV psk=abc123 psk_identity=foo" \
1667 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1668 psk_identity=foo psk=abc123" \
1669 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001670 -S "SSL - The server has no ciphersuites in common" \
1671 -S "SSL - Unknown identity received" \
1672 -S "SSL - Verification of the message MAC failed"
1673
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001674run_test "PSK callback: no psk, no callback" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001675 "$P_SRV" \
1676 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1677 psk_identity=foo psk=abc123" \
1678 1 \
1679 -s "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001680 -S "SSL - Unknown identity received" \
1681 -S "SSL - Verification of the message MAC failed"
1682
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001683run_test "PSK callback: callback overrides other settings" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001684 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
1685 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1686 psk_identity=foo psk=abc123" \
1687 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001688 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001689 -s "SSL - Unknown identity received" \
1690 -S "SSL - Verification of the message MAC failed"
1691
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001692run_test "PSK callback: first id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001693 "$P_SRV psk_list=abc,dead,def,beef" \
1694 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1695 psk_identity=abc psk=dead" \
1696 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001697 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001698 -S "SSL - Unknown identity received" \
1699 -S "SSL - Verification of the message MAC failed"
1700
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001701run_test "PSK callback: second id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001702 "$P_SRV psk_list=abc,dead,def,beef" \
1703 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1704 psk_identity=def psk=beef" \
1705 0 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001706 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001707 -S "SSL - Unknown identity received" \
1708 -S "SSL - Verification of the message MAC failed"
1709
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001710run_test "PSK callback: no match" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001711 "$P_SRV psk_list=abc,dead,def,beef" \
1712 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1713 psk_identity=ghi psk=beef" \
1714 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001715 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001716 -s "SSL - Unknown identity received" \
1717 -S "SSL - Verification of the message MAC failed"
1718
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001719run_test "PSK callback: wrong key" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001720 "$P_SRV psk_list=abc,dead,def,beef" \
1721 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
1722 psk_identity=abc psk=beef" \
1723 1 \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02001724 -S "SSL - The server has no ciphersuites in common" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02001725 -S "SSL - Unknown identity received" \
1726 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02001727
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001728# Tests for ciphersuites per version
1729
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001730run_test "Per-version suites: SSL3" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001731 "$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" \
1732 "$P_CLI force_version=ssl3" \
1733 0 \
1734 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
1735
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001736run_test "Per-version suites: TLS 1.0" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001737 "$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" \
1738 "$P_CLI force_version=tls1" \
1739 0 \
1740 -c "Ciphersuite is TLS-RSA-WITH-RC4-128-SHA"
1741
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001742run_test "Per-version suites: TLS 1.1" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001743 "$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" \
1744 "$P_CLI force_version=tls1_1" \
1745 0 \
1746 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
1747
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001748run_test "Per-version suites: TLS 1.2" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001749 "$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" \
1750 "$P_CLI force_version=tls1_2" \
1751 0 \
1752 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
1753
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001754# Tests for ssl_get_bytes_avail()
1755
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001756run_test "ssl_get_bytes_avail: no extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001757 "$P_SRV" \
1758 "$P_CLI request_size=100" \
1759 0 \
1760 -s "Read from client: 100 bytes read$"
1761
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001762run_test "ssl_get_bytes_avail: extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02001763 "$P_SRV" \
1764 "$P_CLI request_size=500" \
1765 0 \
1766 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02001767
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02001768# Tests for small packets
1769
1770run_test "Small packet SSLv3 BlockCipher" \
1771 "$P_SRV" \
1772 "$P_CLI request_size=1 force_version=ssl3 \
1773 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1774 0 \
1775 -s "Read from client: 1 bytes read"
1776
1777run_test "Small packet SSLv3 StreamCipher" \
1778 "$P_SRV" \
1779 "$P_CLI request_size=1 force_version=ssl3 \
1780 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1781 0 \
1782 -s "Read from client: 1 bytes read"
1783
1784run_test "Small packet TLS 1.0 BlockCipher" \
1785 "$P_SRV" \
1786 "$P_CLI request_size=1 force_version=tls1 \
1787 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1788 0 \
1789 -s "Read from client: 1 bytes read"
1790
1791run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
1792 "$P_SRV" \
1793 "$P_CLI request_size=1 force_version=tls1 \
1794 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1795 trunc_hmac=1" \
1796 0 \
1797 -s "Read from client: 1 bytes read"
1798
1799run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
1800 "$P_SRV" \
1801 "$P_CLI request_size=1 force_version=tls1 \
1802 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1803 trunc_hmac=1" \
1804 0 \
1805 -s "Read from client: 1 bytes read"
1806
1807run_test "Small packet TLS 1.1 BlockCipher" \
1808 "$P_SRV" \
1809 "$P_CLI request_size=1 force_version=tls1_1 \
1810 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1811 0 \
1812 -s "Read from client: 1 bytes read"
1813
1814run_test "Small packet TLS 1.1 StreamCipher" \
1815 "$P_SRV" \
1816 "$P_CLI request_size=1 force_version=tls1_1 \
1817 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1818 0 \
1819 -s "Read from client: 1 bytes read"
1820
1821run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
1822 "$P_SRV" \
1823 "$P_CLI request_size=1 force_version=tls1_1 \
1824 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1825 trunc_hmac=1" \
1826 0 \
1827 -s "Read from client: 1 bytes read"
1828
1829run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
1830 "$P_SRV" \
1831 "$P_CLI request_size=1 force_version=tls1_1 \
1832 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1833 trunc_hmac=1" \
1834 0 \
1835 -s "Read from client: 1 bytes read"
1836
1837run_test "Small packet TLS 1.2 BlockCipher" \
1838 "$P_SRV" \
1839 "$P_CLI request_size=1 force_version=tls1_2 \
1840 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1841 0 \
1842 -s "Read from client: 1 bytes read"
1843
1844run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
1845 "$P_SRV" \
1846 "$P_CLI request_size=1 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1847 0 \
1848 -s "Read from client: 1 bytes read"
1849
1850run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
1851 "$P_SRV" \
1852 "$P_CLI request_size=1 force_version=tls1_2 \
1853 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1854 trunc_hmac=1" \
1855 0 \
1856 -s "Read from client: 1 bytes read"
1857
1858run_test "Small packet TLS 1.2 StreamCipher" \
1859 "$P_SRV" \
1860 "$P_CLI request_size=1 force_version=tls1_2 \
1861 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1862 0 \
1863 -s "Read from client: 1 bytes read"
1864
1865run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
1866 "$P_SRV" \
1867 "$P_CLI request_size=1 force_version=tls1_2 \
1868 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1869 trunc_hmac=1" \
1870 0 \
1871 -s "Read from client: 1 bytes read"
1872
1873run_test "Small packet TLS 1.2 AEAD" \
1874 "$P_SRV" \
1875 "$P_CLI request_size=1 force_version=tls1_2 \
1876 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1877 0 \
1878 -s "Read from client: 1 bytes read"
1879
1880run_test "Small packet TLS 1.2 AEAD shorter tag" \
1881 "$P_SRV" \
1882 "$P_CLI request_size=1 force_version=tls1_2 \
1883 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
1884 0 \
1885 -s "Read from client: 1 bytes read"
1886
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02001887# Test for large packets
1888
1889run_test "Large packet SSLv3 BlockCipher" \
1890 "$P_SRV" \
1891 "$P_CLI request_size=16384 force_version=ssl3 \
1892 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1893 0 \
1894 -s "Read from client: 16384 bytes read"
1895
1896run_test "Large packet SSLv3 StreamCipher" \
1897 "$P_SRV" \
1898 "$P_CLI request_size=16384 force_version=ssl3 \
1899 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1900 0 \
1901 -s "Read from client: 16384 bytes read"
1902
1903run_test "Large packet TLS 1.0 BlockCipher" \
1904 "$P_SRV" \
1905 "$P_CLI request_size=16384 force_version=tls1 \
1906 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1907 0 \
1908 -s "Read from client: 16384 bytes read"
1909
1910run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
1911 "$P_SRV" \
1912 "$P_CLI request_size=16384 force_version=tls1 \
1913 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1914 trunc_hmac=1" \
1915 0 \
1916 -s "Read from client: 16384 bytes read"
1917
1918run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
1919 "$P_SRV" \
1920 "$P_CLI request_size=16384 force_version=tls1 \
1921 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1922 trunc_hmac=1" \
1923 0 \
1924 -s "Read from client: 16384 bytes read"
1925
1926run_test "Large packet TLS 1.1 BlockCipher" \
1927 "$P_SRV" \
1928 "$P_CLI request_size=16384 force_version=tls1_1 \
1929 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1930 0 \
1931 -s "Read from client: 16384 bytes read"
1932
1933run_test "Large packet TLS 1.1 StreamCipher" \
1934 "$P_SRV" \
1935 "$P_CLI request_size=16384 force_version=tls1_1 \
1936 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1937 0 \
1938 -s "Read from client: 16384 bytes read"
1939
1940run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
1941 "$P_SRV" \
1942 "$P_CLI request_size=16384 force_version=tls1_1 \
1943 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1944 trunc_hmac=1" \
1945 0 \
1946 -s "Read from client: 16384 bytes read"
1947
1948run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
1949 "$P_SRV" \
1950 "$P_CLI request_size=16384 force_version=tls1_1 \
1951 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1952 trunc_hmac=1" \
1953 0 \
1954 -s "Read from client: 16384 bytes read"
1955
1956run_test "Large packet TLS 1.2 BlockCipher" \
1957 "$P_SRV" \
1958 "$P_CLI request_size=16384 force_version=tls1_2 \
1959 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
1960 0 \
1961 -s "Read from client: 16384 bytes read"
1962
1963run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
1964 "$P_SRV" \
1965 "$P_CLI request_size=16384 force_version=tls1_2 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
1966 0 \
1967 -s "Read from client: 16384 bytes read"
1968
1969run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
1970 "$P_SRV" \
1971 "$P_CLI request_size=16384 force_version=tls1_2 \
1972 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
1973 trunc_hmac=1" \
1974 0 \
1975 -s "Read from client: 16384 bytes read"
1976
1977run_test "Large packet TLS 1.2 StreamCipher" \
1978 "$P_SRV" \
1979 "$P_CLI request_size=16384 force_version=tls1_2 \
1980 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
1981 0 \
1982 -s "Read from client: 16384 bytes read"
1983
1984run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
1985 "$P_SRV" \
1986 "$P_CLI request_size=16384 force_version=tls1_2 \
1987 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1988 trunc_hmac=1" \
1989 0 \
1990 -s "Read from client: 16384 bytes read"
1991
1992run_test "Large packet TLS 1.2 AEAD" \
1993 "$P_SRV" \
1994 "$P_CLI request_size=16384 force_version=tls1_2 \
1995 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
1996 0 \
1997 -s "Read from client: 16384 bytes read"
1998
1999run_test "Large packet TLS 1.2 AEAD shorter tag" \
2000 "$P_SRV" \
2001 "$P_CLI request_size=16384 force_version=tls1_2 \
2002 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
2003 0 \
2004 -s "Read from client: 16384 bytes read"
2005
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002006# Tests for DTLS HelloVerifyRequest
2007
2008run_test "DTLS cookie: enabled" \
2009 "$P_SRV dtls=1 debug_level=2" \
2010 "$P_CLI dtls=1 debug_level=2" \
2011 0 \
2012 -s "cookie verification failed" \
2013 -s "cookie verification passed" \
2014 -S "cookie verification skipped" \
2015 -c "received hello verify request" \
2016 -S "SSL - The requested feature is not available"
2017
2018run_test "DTLS cookie: disabled" \
2019 "$P_SRV dtls=1 debug_level=2 cookies=0" \
2020 "$P_CLI dtls=1 debug_level=2" \
2021 0 \
2022 -S "cookie verification failed" \
2023 -S "cookie verification passed" \
2024 -s "cookie verification skipped" \
2025 -C "received hello verify request" \
2026 -S "SSL - The requested feature is not available"
2027
2028# wait for client having a timeout, or server sending an alert
2029#run_test "DTLS cookie: default (failing)" \
2030# "$P_SRV dtls=1 debug_level=2 cookies=-1" \
2031# "$P_CLI dtls=1 debug_level=2" \
2032# 0 \
2033# -S "cookie verification failed" \
2034# -S "cookie verification passed" \
2035# -S "cookie verification skipped" \
2036# -C "received hello verify request" \
2037# -s "SSL - The requested feature is not available"
2038
2039requires_ipv6
2040run_test "DTLS cookie: enabled, IPv6" \
2041 "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
2042 "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
2043 0 \
2044 -s "cookie verification failed" \
2045 -s "cookie verification passed" \
2046 -S "cookie verification skipped" \
2047 -c "received hello verify request" \
2048 -S "SSL - The requested feature is not available"
2049
Manuel Pégourié-Gonnard579950c2014-09-29 17:47:33 +02002050run_test "DTLS cookie: enabled, nbio" \
2051 "$P_SRV dtls=1 nbio=2 debug_level=2" \
2052 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2053 0 \
2054 -s "cookie verification failed" \
2055 -s "cookie verification passed" \
2056 -S "cookie verification skipped" \
2057 -c "received hello verify request" \
2058 -S "SSL - The requested feature is not available"
2059
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02002060# Tests for various cases of client authentication with DTLS
2061# (focused on handshake flows and message parsing)
2062
2063run_test "DTLS client auth: required" \
2064 "$P_SRV dtls=1 auth_mode=required" \
2065 "$P_CLI dtls=1" \
2066 0 \
2067 -s "Verifying peer X.509 certificate... ok"
2068
2069run_test "DTLS client auth: optional, client has no cert" \
2070 "$P_SRV dtls=1 auth_mode=optional" \
2071 "$P_CLI dtls=1 crt_file=none key_file=none" \
2072 0 \
2073 -s "! no client certificate sent"
2074
2075run_test "DTLS client auth: optional, client has no cert" \
2076 "$P_SRV dtls=1 auth_mode=none" \
2077 "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
2078 0 \
2079 -c "skip write certificate$" \
2080 -s "! no client certificate sent"
2081
Manuel Pégourié-Gonnard502bf302014-08-20 13:12:58 +02002082# Tests for receiving fragmented handshake messages with DTLS
2083
2084requires_gnutls
2085run_test "DTLS reassembly: no fragmentation (gnutls server)" \
2086 "$G_SRV -u --mtu 2048 -a" \
2087 "$P_CLI dtls=1 debug_level=2" \
2088 0 \
2089 -C "found fragmented DTLS handshake message" \
2090 -C "error"
2091
2092requires_gnutls
2093run_test "DTLS reassembly: some fragmentation (gnutls server)" \
2094 "$G_SRV -u --mtu 512" \
2095 "$P_CLI dtls=1 debug_level=2" \
2096 0 \
2097 -c "found fragmented DTLS handshake message" \
2098 -C "error"
2099
2100requires_gnutls
2101run_test "DTLS reassembly: more fragmentation (gnutls server)" \
2102 "$G_SRV -u --mtu 128" \
2103 "$P_CLI dtls=1 debug_level=2" \
2104 0 \
2105 -c "found fragmented DTLS handshake message" \
2106 -C "error"
2107
2108requires_gnutls
2109run_test "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
2110 "$G_SRV -u --mtu 128" \
2111 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2112 0 \
2113 -c "found fragmented DTLS handshake message" \
2114 -C "error"
2115
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002116requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002117run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
2118 "$G_SRV -u --mtu 256" \
2119 "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
2120 0 \
2121 -c "found fragmented DTLS handshake message" \
2122 -c "client hello, adding renegotiation extension" \
2123 -c "found renegotiation extension" \
2124 -c "=> renegotiate" \
2125 -C "ssl_handshake returned" \
2126 -C "error" \
2127 -s "Extra-header:"
2128
2129requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02002130run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
2131 "$G_SRV -u --mtu 256" \
2132 "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
2133 0 \
2134 -c "found fragmented DTLS handshake message" \
2135 -c "client hello, adding renegotiation extension" \
2136 -c "found renegotiation extension" \
2137 -c "=> renegotiate" \
2138 -C "ssl_handshake returned" \
2139 -C "error" \
2140 -s "Extra-header:"
2141
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002142run_test "DTLS reassembly: no fragmentation (openssl server)" \
2143 "$O_SRV -dtls1 -mtu 2048" \
2144 "$P_CLI dtls=1 debug_level=2" \
2145 0 \
2146 -C "found fragmented DTLS handshake message" \
2147 -C "error"
2148
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002149run_test "DTLS reassembly: some fragmentation (openssl server)" \
2150 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02002151 "$P_CLI dtls=1 debug_level=2" \
2152 0 \
2153 -c "found fragmented DTLS handshake message" \
2154 -C "error"
2155
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002156run_test "DTLS reassembly: more fragmentation (openssl server)" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02002157 "$O_SRV -dtls1 -mtu 256" \
2158 "$P_CLI dtls=1 debug_level=2" \
2159 0 \
2160 -c "found fragmented DTLS handshake message" \
2161 -C "error"
2162
2163run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
2164 "$O_SRV -dtls1 -mtu 256" \
2165 "$P_CLI dtls=1 nbio=2 debug_level=2" \
2166 0 \
2167 -c "found fragmented DTLS handshake message" \
2168 -C "error"
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02002169
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02002170# Tests for specific things with "unreliable" UDP connection
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002171
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002172not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002173run_test "DTLS proxy: reference" \
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02002174 -p "$P_PXY" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002175 "$P_SRV dtls=1 debug_level=2" \
2176 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002177 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02002178 -C "replayed record" \
2179 -S "replayed record" \
2180 -C "record from another epoch" \
2181 -S "record from another epoch" \
2182 -C "discarding invalid record" \
2183 -S "discarding invalid record" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002184 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002185 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002186 -c "HTTP/1.0 200 OK"
2187
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002188not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02002189run_test "DTLS proxy: duplicate every packet" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002190 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002191 "$P_SRV dtls=1 debug_level=2" \
2192 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02002193 0 \
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02002194 -c "replayed record" \
2195 -s "replayed record" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02002196 -c "discarding invalid record" \
2197 -s "discarding invalid record" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002198 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002199 -s "Extra-header:" \
2200 -c "HTTP/1.0 200 OK"
2201
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02002202run_test "DTLS proxy: duplicate every packet, server anti-replay off" \
2203 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002204 "$P_SRV dtls=1 debug_level=2 anti_replay=0" \
2205 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02002206 0 \
2207 -c "replayed record" \
2208 -S "replayed record" \
2209 -c "discarding invalid record" \
2210 -s "discarding invalid record" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02002211 -c "resend" \
2212 -s "resend" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02002213 -s "Extra-header:" \
2214 -c "HTTP/1.0 200 OK"
2215
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02002216run_test "DTLS proxy: inject invalid AD record" \
2217 -p "$P_PXY bad_ad=1" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02002218 "$P_SRV dtls=1 debug_level=1" \
2219 "$P_CLI dtls=1 debug_level=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002220 0 \
2221 -c "discarding invalid record" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02002222 -s "discarding invalid record" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002223 -s "Extra-header:" \
2224 -c "HTTP/1.0 200 OK"
2225
2226run_test "DTLS proxy: delay ChangeCipherSpec" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02002227 -p "$P_PXY delay_ccs=1" \
2228 "$P_SRV dtls=1 debug_level=1" \
2229 "$P_CLI dtls=1 debug_level=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002230 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02002231 -c "record from another epoch" \
2232 -s "record from another epoch" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002233 -c "discarding invalid record" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02002234 -s "discarding invalid record" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002235 -s "Extra-header:" \
2236 -c "HTTP/1.0 200 OK"
2237
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02002238# Tests for "randomly unreliable connection": try a variety of flows and peers
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02002239
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002240needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02002241run_test "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002242 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002243 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
2244 psk=abc123" \
2245 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02002246 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
2247 0 \
2248 -s "Extra-header:" \
2249 -c "HTTP/1.0 200 OK"
2250
2251needs_more_time 2
2252run_test "DTLS proxy: 3d, \"short\" RSA handshake" \
2253 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002254 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
2255 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02002256 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2257 0 \
2258 -s "Extra-header:" \
2259 -c "HTTP/1.0 200 OK"
2260
2261needs_more_time 2
2262run_test "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
2263 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002264 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
2265 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02002266 0 \
2267 -s "Extra-header:" \
2268 -c "HTTP/1.0 200 OK"
2269
2270needs_more_time 2
2271run_test "DTLS proxy: 3d, FS, client auth" \
2272 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002273 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=required" \
2274 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02002275 0 \
2276 -s "Extra-header:" \
2277 -c "HTTP/1.0 200 OK"
2278
2279needs_more_time 2
2280run_test "DTLS proxy: 3d, FS, ticket" \
2281 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002282 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=none" \
2283 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02002284 0 \
2285 -s "Extra-header:" \
2286 -c "HTTP/1.0 200 OK"
2287
2288needs_more_time 2
2289run_test "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
2290 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002291 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=required" \
2292 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02002293 0 \
2294 -s "Extra-header:" \
2295 -c "HTTP/1.0 200 OK"
2296
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002297needs_more_time 2
2298run_test "DTLS proxy: 3d, max handshake, nbio" \
2299 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002300 "$P_SRV dtls=1 hs_timeout=250-10000 nbio=2 tickets=1 \
2301 auth_mode=required" \
2302 "$P_CLI dtls=1 hs_timeout=250-10000 nbio=2 tickets=1" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002303 0 \
2304 -s "Extra-header:" \
2305 -c "HTTP/1.0 200 OK"
2306
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02002307needs_more_time 4
Manuel Pégourié-Gonnard7a26d732014-10-02 14:50:46 +02002308run_test "DTLS proxy: 3d, min handshake, resumption" \
2309 -p "$P_PXY drop=5 delay=5 duplicate=5" \
2310 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
2311 psk=abc123 debug_level=3" \
2312 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
2313 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
2314 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
2315 0 \
2316 -s "a session has been resumed" \
2317 -c "a session has been resumed" \
2318 -s "Extra-header:" \
2319 -c "HTTP/1.0 200 OK"
2320
2321needs_more_time 4
Manuel Pégourié-Gonnard85beb302014-10-02 17:59:19 +02002322run_test "DTLS proxy: 3d, min handshake, resumption, nbio" \
2323 -p "$P_PXY drop=5 delay=5 duplicate=5" \
2324 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
2325 psk=abc123 debug_level=3 nbio=2" \
2326 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
2327 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
2328 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
2329 0 \
2330 -s "a session has been resumed" \
2331 -c "a session has been resumed" \
2332 -s "Extra-header:" \
2333 -c "HTTP/1.0 200 OK"
2334
2335needs_more_time 4
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002336run_test "DTLS proxy: 3d, min handshake, client-initiated renego" \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02002337 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002338 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
2339 psk=abc123 renegotiation=1 debug_level=2" \
2340 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
2341 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02002342 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
2343 0 \
2344 -c "=> renegotiate" \
2345 -s "=> renegotiate" \
2346 -s "Extra-header:" \
2347 -c "HTTP/1.0 200 OK"
2348
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002349needs_more_time 4
2350run_test "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
2351 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002352 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
2353 psk=abc123 renegotiation=1 debug_level=2" \
2354 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
2355 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002356 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
2357 0 \
2358 -c "=> renegotiate" \
2359 -s "=> renegotiate" \
2360 -s "Extra-header:" \
2361 -c "HTTP/1.0 200 OK"
2362
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02002363needs_more_time 4
2364run_test "DTLS proxy: 3d, min handshake, server-initiated renego" \
2365 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_len=41" \
2366 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
2367 psk=abc123 renegotiate=1 renegotiation=1 exchanges=2 \
2368 debug_level=2" \
2369 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
2370 renegotiation=1 exchanges=2 debug_level=2 \
2371 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
2372 0 \
2373 -c "=> renegotiate" \
2374 -s "=> renegotiate" \
2375 -s "Extra-header:" \
2376 -c "HTTP/1.0 200 OK"
2377
2378needs_more_time 4
2379run_test "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
2380 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_len=41" \
2381 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
2382 psk=abc123 renegotiate=1 renegotiation=1 exchanges=2 \
2383 debug_level=2 nbio=2" \
2384 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
2385 renegotiation=1 exchanges=2 debug_level=2 nbio=2 \
2386 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
2387 0 \
2388 -c "=> renegotiate" \
2389 -s "=> renegotiate" \
2390 -s "Extra-header:" \
2391 -c "HTTP/1.0 200 OK"
2392
Manuel Pégourié-Gonnarda59af052014-10-02 17:07:09 +02002393needs_more_time 3
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02002394run_test "DTLS proxy: 3d, openssl server" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02002395 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
2396 "$O_SRV -dtls1 -mtu 2048" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002397 "$P_CLI dtls=1 hs_timeout=250-10000" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02002398 0 \
2399 -s "Extra-header:" \
2400 -c "HTTP/1.0 200 OK"
2401
Manuel Pégourié-Gonnarda59af052014-10-02 17:07:09 +02002402needs_more_time 4
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02002403run_test "DTLS proxy: 3d, openssl server, fragmentation" \
2404 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
2405 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002406 "$P_CLI dtls=1 hs_timeout=250-10000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02002407 0 \
2408 -s "Extra-header:" \
2409 -c "HTTP/1.0 200 OK"
2410
Manuel Pégourié-Gonnarda59af052014-10-02 17:07:09 +02002411needs_more_time 4
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002412run_test "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
2413 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
2414 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002415 "$P_CLI dtls=1 hs_timeout=250-10000 nbio=2" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002416 0 \
2417 -s "Extra-header:" \
2418 -c "HTTP/1.0 200 OK"
2419
Manuel Pégourié-Gonnarda59af052014-10-02 17:07:09 +02002420needs_more_time 3
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02002421run_test "DTLS proxy: 3d, gnutls server" \
2422 -p "$P_PXY drop=5 delay=5 duplicate=5" \
2423 "$G_SRV -u --mtu 2048 -a" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002424 "$P_CLI dtls=1 hs_timeout=250-10000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02002425 0 \
2426 -s "Extra-header:" \
2427 -c "Extra-header:"
2428
Manuel Pégourié-Gonnarda59af052014-10-02 17:07:09 +02002429needs_more_time 4
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02002430run_test "DTLS proxy: 3d, gnutls server, fragmentation" \
2431 -p "$P_PXY drop=5 delay=5 duplicate=5" \
2432 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002433 "$P_CLI dtls=1 hs_timeout=250-10000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02002434 0 \
2435 -s "Extra-header:" \
2436 -c "Extra-header:"
2437
Manuel Pégourié-Gonnarda59af052014-10-02 17:07:09 +02002438needs_more_time 4
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002439run_test "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
2440 -p "$P_PXY drop=5 delay=5 duplicate=5" \
2441 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02002442 "$P_CLI dtls=1 hs_timeout=250-10000 nbio=2" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02002443 0 \
2444 -s "Extra-header:" \
2445 -c "Extra-header:"
2446
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002447# Final report
2448
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002449echo "------------------------------------------------------------------------"
2450
2451if [ $FAILS = 0 ]; then
2452 echo -n "PASSED"
2453else
2454 echo -n "FAILED"
2455fi
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +02002456PASSES=$(( $TESTS - $FAILS ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +02002457echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01002458
2459exit $FAILS