blob: bc07a197fd92cb09b2357f9f12af9f25b59e6c68 [file] [log] [blame]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +01001#!/bin/sh
2
Simon Butcher58eddef2016-05-19 23:43:11 +01003# ssl-opt.sh
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +01004#
Simon Butcher58eddef2016-05-19 23:43:11 +01005# This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +01006#
Simon Butcher58eddef2016-05-19 23:43:11 +01007# Copyright (c) 2016, ARM Limited, All Rights Reserved
8#
9# Purpose
10#
11# Executes tests to prove various TLS/SSL options and extensions.
12#
13# The goal is not to cover every ciphersuite/version, but instead to cover
14# specific options (max fragment length, truncated hmac, etc) or procedures
15# (session resumption from cache or ticket, renego, etc).
16#
17# The tests assume a build with default options, with exceptions expressed
18# with a dependency. The tests focus on functionality and do not consider
19# performance.
20#
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010021
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010022set -u
23
Angus Grattonc4dd0732018-04-11 16:28:39 +100024if cd $( dirname $0 ); then :; else
25 echo "cd $( dirname $0 ) failed" >&2
26 exit 1
27fi
28
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010029# default values, can be overriden by the environment
30: ${P_SRV:=../programs/ssl/ssl_server2}
31: ${P_CLI:=../programs/ssl/ssl_client2}
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +020032: ${P_PXY:=../programs/test/udp_proxy}
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010033: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020034: ${GNUTLS_CLI:=gnutls-cli}
35: ${GNUTLS_SERV:=gnutls-serv}
Gilles Peskined50177f2017-05-16 17:53:03 +020036: ${PERL:=perl}
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010037
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +020038O_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 +010039O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020040G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +010041G_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_CLI --x509cafile data_files/test-ca_cat12.crt"
Gilles Peskined50177f2017-05-16 17:53:03 +020042TCP_CLIENT="$PERL scripts/tcp_client.pl"
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010043
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +020044# alternative versions of OpenSSL and GnuTLS (no default path)
45
46if [ -n "${OPENSSL_LEGACY:-}" ]; then
47 O_LEGACY_SRV="$OPENSSL_LEGACY s_server -www -cert data_files/server5.crt -key data_files/server5.key"
48 O_LEGACY_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_LEGACY s_client"
49else
50 O_LEGACY_SRV=false
51 O_LEGACY_CLI=false
52fi
53
Hanno Becker58e9dc32018-08-17 15:53:21 +010054if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +020055 G_NEXT_SRV="$GNUTLS_NEXT_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
56else
57 G_NEXT_SRV=false
58fi
59
Hanno Becker58e9dc32018-08-17 15:53:21 +010060if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +020061 G_NEXT_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_NEXT_CLI --x509cafile data_files/test-ca_cat12.crt"
62else
63 G_NEXT_CLI=false
64fi
65
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010066TESTS=0
67FAILS=0
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020068SKIPS=0
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010069
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000070CONFIG_H='../include/mbedtls/config.h'
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +020071
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010072MEMCHECK=0
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010073FILTER='.*'
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020074EXCLUDE='^$'
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010075
Paul Bakkere20310a2016-05-10 11:18:17 +010076SHOW_TEST_NUMBER=0
Paul Bakkerb7584a52016-05-10 10:50:43 +010077RUN_TEST_NUMBER=''
78
Paul Bakkeracaac852016-05-10 11:47:13 +010079PRESERVE_LOGS=0
80
Gilles Peskinef93c7d32017-04-14 17:55:28 +020081# Pick a "unique" server port in the range 10000-19999, and a proxy
82# port which is this plus 10000. Each port number may be independently
83# overridden by a command line option.
84SRV_PORT=$(($$ % 10000 + 10000))
85PXY_PORT=$((SRV_PORT + 10000))
86
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010087print_usage() {
88 echo "Usage: $0 [options]"
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +010089 printf " -h|--help\tPrint this help.\n"
90 printf " -m|--memcheck\tCheck memory leaks and errors.\n"
Gilles Peskinef93c7d32017-04-14 17:55:28 +020091 printf " -f|--filter\tOnly matching tests are executed (BRE; default: '$FILTER')\n"
92 printf " -e|--exclude\tMatching tests are excluded (BRE; default: '$EXCLUDE')\n"
Paul Bakkerb7584a52016-05-10 10:50:43 +010093 printf " -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
Paul Bakkere20310a2016-05-10 11:18:17 +010094 printf " -s|--show-numbers\tShow test numbers in front of test names\n"
Paul Bakkeracaac852016-05-10 11:47:13 +010095 printf " -p|--preserve-logs\tPreserve logs of successful tests as well\n"
Gilles Peskinef93c7d32017-04-14 17:55:28 +020096 printf " --port\tTCP/UDP port (default: randomish 1xxxx)\n"
97 printf " --proxy-port\tTCP/UDP proxy port (default: randomish 2xxxx)\n"
Andres AGf04f54d2016-10-10 15:46:20 +010098 printf " --seed\tInteger seed value to use for this test run\n"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010099}
100
101get_options() {
102 while [ $# -gt 0 ]; do
103 case "$1" in
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100104 -f|--filter)
105 shift; FILTER=$1
106 ;;
107 -e|--exclude)
108 shift; EXCLUDE=$1
109 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100110 -m|--memcheck)
111 MEMCHECK=1
112 ;;
Paul Bakkerb7584a52016-05-10 10:50:43 +0100113 -n|--number)
114 shift; RUN_TEST_NUMBER=$1
115 ;;
Paul Bakkere20310a2016-05-10 11:18:17 +0100116 -s|--show-numbers)
117 SHOW_TEST_NUMBER=1
118 ;;
Paul Bakkeracaac852016-05-10 11:47:13 +0100119 -p|--preserve-logs)
120 PRESERVE_LOGS=1
121 ;;
Gilles Peskinef93c7d32017-04-14 17:55:28 +0200122 --port)
123 shift; SRV_PORT=$1
124 ;;
125 --proxy-port)
126 shift; PXY_PORT=$1
127 ;;
Andres AGf04f54d2016-10-10 15:46:20 +0100128 --seed)
129 shift; SEED="$1"
130 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100131 -h|--help)
132 print_usage
133 exit 0
134 ;;
135 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200136 echo "Unknown argument: '$1'"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100137 print_usage
138 exit 1
139 ;;
140 esac
141 shift
142 done
143}
144
Manuel Pégourié-Gonnard988209f2015-03-24 10:43:55 +0100145# skip next test if the flag is not enabled in config.h
146requires_config_enabled() {
147 if grep "^#define $1" $CONFIG_H > /dev/null; then :; else
148 SKIP_NEXT="YES"
149 fi
150}
151
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200152# skip next test if the flag is enabled in config.h
153requires_config_disabled() {
154 if grep "^#define $1" $CONFIG_H > /dev/null; then
155 SKIP_NEXT="YES"
156 fi
157}
158
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200159# skip next test if OpenSSL doesn't support FALLBACK_SCSV
160requires_openssl_with_fallback_scsv() {
161 if [ -z "${OPENSSL_HAS_FBSCSV:-}" ]; then
162 if $OPENSSL_CMD s_client -help 2>&1 | grep fallback_scsv >/dev/null
163 then
164 OPENSSL_HAS_FBSCSV="YES"
165 else
166 OPENSSL_HAS_FBSCSV="NO"
167 fi
168 fi
169 if [ "$OPENSSL_HAS_FBSCSV" = "NO" ]; then
170 SKIP_NEXT="YES"
171 fi
172}
173
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200174# skip next test if GnuTLS isn't available
175requires_gnutls() {
176 if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
Manuel Pégourié-Gonnard03db6b02015-06-26 15:45:30 +0200177 if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null 2>&1; then
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200178 GNUTLS_AVAILABLE="YES"
179 else
180 GNUTLS_AVAILABLE="NO"
181 fi
182 fi
183 if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
184 SKIP_NEXT="YES"
185 fi
186}
187
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +0200188# skip next test if GnuTLS-next isn't available
189requires_gnutls_next() {
190 if [ -z "${GNUTLS_NEXT_AVAILABLE:-}" ]; then
191 if ( which "${GNUTLS_NEXT_CLI:-}" && which "${GNUTLS_NEXT_SERV:-}" ) >/dev/null 2>&1; then
192 GNUTLS_NEXT_AVAILABLE="YES"
193 else
194 GNUTLS_NEXT_AVAILABLE="NO"
195 fi
196 fi
197 if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
198 SKIP_NEXT="YES"
199 fi
200}
201
202# skip next test if OpenSSL-legacy isn't available
203requires_openssl_legacy() {
204 if [ -z "${OPENSSL_LEGACY_AVAILABLE:-}" ]; then
205 if which "${OPENSSL_LEGACY:-}" >/dev/null 2>&1; then
206 OPENSSL_LEGACY_AVAILABLE="YES"
207 else
208 OPENSSL_LEGACY_AVAILABLE="NO"
209 fi
210 fi
211 if [ "$OPENSSL_LEGACY_AVAILABLE" = "NO" ]; then
212 SKIP_NEXT="YES"
213 fi
214}
215
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200216# skip next test if IPv6 isn't available on this host
217requires_ipv6() {
218 if [ -z "${HAS_IPV6:-}" ]; then
219 $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
220 SRV_PID=$!
221 sleep 1
222 kill $SRV_PID >/dev/null 2>&1
223 if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
224 HAS_IPV6="NO"
225 else
226 HAS_IPV6="YES"
227 fi
228 rm -r $SRV_OUT
229 fi
230
231 if [ "$HAS_IPV6" = "NO" ]; then
232 SKIP_NEXT="YES"
233 fi
234}
235
Angus Grattonc4dd0732018-04-11 16:28:39 +1000236# Calculate the input & output maximum content lengths set in the config
237MAX_CONTENT_LEN=$( ../scripts/config.pl get MBEDTLS_SSL_MAX_CONTENT_LEN || echo "16384")
238MAX_IN_LEN=$( ../scripts/config.pl get MBEDTLS_SSL_IN_CONTENT_LEN || echo "$MAX_CONTENT_LEN")
239MAX_OUT_LEN=$( ../scripts/config.pl get MBEDTLS_SSL_OUT_CONTENT_LEN || echo "$MAX_CONTENT_LEN")
240
241if [ "$MAX_IN_LEN" -lt "$MAX_CONTENT_LEN" ]; then
242 MAX_CONTENT_LEN="$MAX_IN_LEN"
243fi
244if [ "$MAX_OUT_LEN" -lt "$MAX_CONTENT_LEN" ]; then
245 MAX_CONTENT_LEN="$MAX_OUT_LEN"
246fi
247
248# skip the next test if the SSL output buffer is less than 16KB
249requires_full_size_output_buffer() {
250 if [ "$MAX_OUT_LEN" -ne 16384 ]; then
251 SKIP_NEXT="YES"
252 fi
253}
254
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +0200255# skip the next test if valgrind is in use
256not_with_valgrind() {
257 if [ "$MEMCHECK" -gt 0 ]; then
258 SKIP_NEXT="YES"
259 fi
260}
261
Paul Bakker362689d2016-05-13 10:33:25 +0100262# skip the next test if valgrind is NOT in use
263only_with_valgrind() {
264 if [ "$MEMCHECK" -eq 0 ]; then
265 SKIP_NEXT="YES"
266 fi
267}
268
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200269# multiply the client timeout delay by the given factor for the next test
Janos Follath74537a62016-09-02 13:45:28 +0100270client_needs_more_time() {
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200271 CLI_DELAY_FACTOR=$1
272}
273
Janos Follath74537a62016-09-02 13:45:28 +0100274# wait for the given seconds after the client finished in the next test
275server_needs_more_time() {
276 SRV_DELAY_SECONDS=$1
277}
278
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100279# print_name <name>
280print_name() {
Paul Bakkere20310a2016-05-10 11:18:17 +0100281 TESTS=$(( $TESTS + 1 ))
282 LINE=""
283
284 if [ "$SHOW_TEST_NUMBER" -gt 0 ]; then
285 LINE="$TESTS "
286 fi
287
288 LINE="$LINE$1"
289 printf "$LINE "
290 LEN=$(( 72 - `echo "$LINE" | wc -c` ))
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +0100291 for i in `seq 1 $LEN`; do printf '.'; done
292 printf ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100293
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100294}
295
296# fail <message>
297fail() {
298 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +0100299 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100300
Manuel Pégourié-Gonnardc2b00922014-08-31 16:46:04 +0200301 mv $SRV_OUT o-srv-${TESTS}.log
302 mv $CLI_OUT o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200303 if [ -n "$PXY_CMD" ]; then
304 mv $PXY_OUT o-pxy-${TESTS}.log
305 fi
306 echo " ! outputs saved to o-XXX-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100307
Azim Khan19d13732018-03-29 11:04:20 +0100308 if [ "X${USER:-}" = Xbuildbot -o "X${LOGNAME:-}" = Xbuildbot -o "${LOG_FAILURE_ON_STDOUT:-0}" != 0 ]; then
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200309 echo " ! server output:"
310 cat o-srv-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200311 echo " ! ========================================================"
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200312 echo " ! client output:"
313 cat o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200314 if [ -n "$PXY_CMD" ]; then
315 echo " ! ========================================================"
316 echo " ! proxy output:"
317 cat o-pxy-${TESTS}.log
318 fi
319 echo ""
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200320 fi
321
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200322 FAILS=$(( $FAILS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100323}
324
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100325# is_polar <cmd_line>
326is_polar() {
327 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
328}
329
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +0200330# openssl s_server doesn't have -www with DTLS
331check_osrv_dtls() {
332 if echo "$SRV_CMD" | grep 's_server.*-dtls' >/dev/null; then
333 NEEDS_INPUT=1
334 SRV_CMD="$( echo $SRV_CMD | sed s/-www// )"
335 else
336 NEEDS_INPUT=0
337 fi
338}
339
340# provide input to commands that need it
341provide_input() {
342 if [ $NEEDS_INPUT -eq 0 ]; then
343 return
344 fi
345
346 while true; do
347 echo "HTTP/1.0 200 OK"
348 sleep 1
349 done
350}
351
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100352# has_mem_err <log_file_name>
353has_mem_err() {
354 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
355 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
356 then
357 return 1 # false: does not have errors
358 else
359 return 0 # true: has errors
360 fi
361}
362
Gilles Peskine418b5362017-12-14 18:58:42 +0100363# Wait for process $2 to be listening on port $1
364if type lsof >/dev/null 2>/dev/null; then
365 wait_server_start() {
366 START_TIME=$(date +%s)
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200367 if [ "$DTLS" -eq 1 ]; then
Gilles Peskine418b5362017-12-14 18:58:42 +0100368 proto=UDP
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200369 else
Gilles Peskine418b5362017-12-14 18:58:42 +0100370 proto=TCP
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200371 fi
Gilles Peskine418b5362017-12-14 18:58:42 +0100372 # Make a tight loop, server normally takes less than 1s to start.
373 while ! lsof -a -n -b -i "$proto:$1" -p "$2" >/dev/null 2>/dev/null; do
374 if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then
375 echo "SERVERSTART TIMEOUT"
376 echo "SERVERSTART TIMEOUT" >> $SRV_OUT
377 break
378 fi
379 # Linux and *BSD support decimal arguments to sleep. On other
380 # OSes this may be a tight loop.
381 sleep 0.1 2>/dev/null || true
382 done
383 }
384else
Gilles Peskinea9312652018-06-29 15:48:13 +0200385 echo "Warning: lsof not available, wait_server_start = sleep"
Gilles Peskine418b5362017-12-14 18:58:42 +0100386 wait_server_start() {
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200387 sleep "$START_DELAY"
Gilles Peskine418b5362017-12-14 18:58:42 +0100388 }
389fi
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200390
Andres Amaya Garciab84c40b2017-09-06 15:44:01 +0100391# Given the client or server debug output, parse the unix timestamp that is
Andres Amaya Garcia3b1bdff2017-09-14 12:41:29 +0100392# included in the first 4 bytes of the random bytes and check that it's within
Andres Amaya Garciab84c40b2017-09-06 15:44:01 +0100393# acceptable bounds
394check_server_hello_time() {
395 # Extract the time from the debug (lvl 3) output of the client
Andres Amaya Garcia67d8da52017-09-15 15:49:24 +0100396 SERVER_HELLO_TIME="$(sed -n 's/.*server hello, current time: //p' < "$1")"
Andres Amaya Garciab84c40b2017-09-06 15:44:01 +0100397 # Get the Unix timestamp for now
398 CUR_TIME=$(date +'%s')
399 THRESHOLD_IN_SECS=300
400
401 # Check if the ServerHello time was printed
402 if [ -z "$SERVER_HELLO_TIME" ]; then
403 return 1
404 fi
405
406 # Check the time in ServerHello is within acceptable bounds
407 if [ $SERVER_HELLO_TIME -lt $(( $CUR_TIME - $THRESHOLD_IN_SECS )) ]; then
408 # The time in ServerHello is at least 5 minutes before now
409 return 1
410 elif [ $SERVER_HELLO_TIME -gt $(( $CUR_TIME + $THRESHOLD_IN_SECS )) ]; then
Andres Amaya Garcia3b1bdff2017-09-14 12:41:29 +0100411 # The time in ServerHello is at least 5 minutes later than now
Andres Amaya Garciab84c40b2017-09-06 15:44:01 +0100412 return 1
413 else
414 return 0
415 fi
416}
417
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200418# wait for client to terminate and set CLI_EXIT
419# must be called right after starting the client
420wait_client_done() {
421 CLI_PID=$!
422
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200423 CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
424 CLI_DELAY_FACTOR=1
425
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200426 ( sleep $CLI_DELAY; echo "===CLIENT_TIMEOUT===" >> $CLI_OUT; kill $CLI_PID ) &
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200427 DOG_PID=$!
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200428
429 wait $CLI_PID
430 CLI_EXIT=$?
431
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200432 kill $DOG_PID >/dev/null 2>&1
433 wait $DOG_PID
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200434
435 echo "EXIT: $CLI_EXIT" >> $CLI_OUT
Janos Follath74537a62016-09-02 13:45:28 +0100436
437 sleep $SRV_DELAY_SECONDS
438 SRV_DELAY_SECONDS=0
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200439}
440
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200441# check if the given command uses dtls and sets global variable DTLS
442detect_dtls() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200443 if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200444 DTLS=1
445 else
446 DTLS=0
447 fi
448}
449
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200450# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100451# Options: -s pattern pattern that must be present in server output
452# -c pattern pattern that must be present in client output
Simon Butcher8e004102016-10-14 00:48:33 +0100453# -u pattern lines after pattern must be unique in client output
Andres Amaya Garcia93993de2017-09-06 15:38:07 +0100454# -f call shell function on client output
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100455# -S pattern pattern that must be absent in server output
456# -C pattern pattern that must be absent in client output
Simon Butcher8e004102016-10-14 00:48:33 +0100457# -U pattern lines after pattern must be unique in server output
Andres Amaya Garcia93993de2017-09-06 15:38:07 +0100458# -F call shell function on server output
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100459run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100460 NAME="$1"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200461 shift 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100462
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100463 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
464 else
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +0200465 SKIP_NEXT="NO"
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100466 return
467 fi
468
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100469 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100470
Paul Bakkerb7584a52016-05-10 10:50:43 +0100471 # Do we only run numbered tests?
472 if [ "X$RUN_TEST_NUMBER" = "X" ]; then :
473 elif echo ",$RUN_TEST_NUMBER," | grep ",$TESTS," >/dev/null; then :
474 else
475 SKIP_NEXT="YES"
476 fi
477
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200478 # should we skip?
479 if [ "X$SKIP_NEXT" = "XYES" ]; then
480 SKIP_NEXT="NO"
481 echo "SKIP"
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200482 SKIPS=$(( $SKIPS + 1 ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200483 return
484 fi
485
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200486 # does this test use a proxy?
487 if [ "X$1" = "X-p" ]; then
488 PXY_CMD="$2"
489 shift 2
490 else
491 PXY_CMD=""
492 fi
493
494 # get commands and client output
495 SRV_CMD="$1"
496 CLI_CMD="$2"
497 CLI_EXPECT="$3"
498 shift 3
499
500 # fix client port
501 if [ -n "$PXY_CMD" ]; then
502 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
503 else
504 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
505 fi
506
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200507 # update DTLS variable
508 detect_dtls "$SRV_CMD"
509
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100510 # prepend valgrind to our commands if active
511 if [ "$MEMCHECK" -gt 0 ]; then
512 if is_polar "$SRV_CMD"; then
513 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
514 fi
515 if is_polar "$CLI_CMD"; then
516 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
517 fi
518 fi
519
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200520 TIMES_LEFT=2
521 while [ $TIMES_LEFT -gt 0 ]; do
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200522 TIMES_LEFT=$(( $TIMES_LEFT - 1 ))
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200523
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200524 # run the commands
525 if [ -n "$PXY_CMD" ]; then
526 echo "$PXY_CMD" > $PXY_OUT
527 $PXY_CMD >> $PXY_OUT 2>&1 &
528 PXY_PID=$!
529 # assume proxy starts faster than server
530 fi
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200531
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200532 check_osrv_dtls
533 echo "$SRV_CMD" > $SRV_OUT
534 provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
535 SRV_PID=$!
Gilles Peskine418b5362017-12-14 18:58:42 +0100536 wait_server_start "$SRV_PORT" "$SRV_PID"
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200537
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200538 echo "$CLI_CMD" > $CLI_OUT
539 eval "$CLI_CMD" >> $CLI_OUT 2>&1 &
540 wait_client_done
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100541
Hanno Beckercadb5bb2017-05-26 13:56:10 +0100542 sleep 0.05
543
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200544 # terminate the server (and the proxy)
545 kill $SRV_PID
546 wait $SRV_PID
Hanno Beckerd82d8462017-05-29 21:37:46 +0100547
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200548 if [ -n "$PXY_CMD" ]; then
549 kill $PXY_PID >/dev/null 2>&1
550 wait $PXY_PID
551 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100552
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200553 # retry only on timeouts
554 if grep '===CLIENT_TIMEOUT===' $CLI_OUT >/dev/null; then
555 printf "RETRY "
556 else
557 TIMES_LEFT=0
558 fi
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200559 done
560
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100561 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200562 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100563 # expected client exit to incorrectly succeed in case of catastrophic
564 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100565 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200566 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100567 else
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100568 fail "server or client failed to reach handshake stage"
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100569 return
570 fi
571 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100572 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200573 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100574 else
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100575 fail "server or client failed to reach handshake stage"
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100576 return
577 fi
578 fi
579
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100580 # check server exit code
581 if [ $? != 0 ]; then
582 fail "server fail"
583 return
584 fi
585
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100586 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100587 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
588 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100589 then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200590 fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100591 return
592 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100593
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100594 # check other assertions
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200595 # lines beginning with == are added by valgrind, ignore them
Paul Bakker1f650922016-05-13 10:16:46 +0100596 # lines with 'Serious error when reading debug info', are valgrind issues as well
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100597 while [ $# -gt 0 ]
598 do
599 case $1 in
600 "-s")
Paul Bakker1f650922016-05-13 10:16:46 +0100601 if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
Simon Butcher8e004102016-10-14 00:48:33 +0100602 fail "pattern '$2' MUST be present in the Server output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100603 return
604 fi
605 ;;
606
607 "-c")
Paul Bakker1f650922016-05-13 10:16:46 +0100608 if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
Simon Butcher8e004102016-10-14 00:48:33 +0100609 fail "pattern '$2' MUST be present in the Client output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100610 return
611 fi
612 ;;
613
614 "-S")
Paul Bakker1f650922016-05-13 10:16:46 +0100615 if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
Simon Butcher8e004102016-10-14 00:48:33 +0100616 fail "pattern '$2' MUST NOT be present in the Server output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100617 return
618 fi
619 ;;
620
621 "-C")
Paul Bakker1f650922016-05-13 10:16:46 +0100622 if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
Simon Butcher8e004102016-10-14 00:48:33 +0100623 fail "pattern '$2' MUST NOT be present in the Client output"
624 return
625 fi
626 ;;
627
628 # The filtering in the following two options (-u and -U) do the following
629 # - ignore valgrind output
630 # - filter out everything but lines right after the pattern occurances
631 # - keep one of each non-unique line
632 # - count how many lines remain
633 # A line with '--' will remain in the result from previous outputs, so the number of lines in the result will be 1
634 # if there were no duplicates.
635 "-U")
636 if [ $(grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep -A1 "$2" | grep -v "$2" | sort | uniq -d | wc -l) -gt 1 ]; then
637 fail "lines following pattern '$2' must be unique in Server output"
638 return
639 fi
640 ;;
641
642 "-u")
643 if [ $(grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep -A1 "$2" | grep -v "$2" | sort | uniq -d | wc -l) -gt 1 ]; then
644 fail "lines following pattern '$2' must be unique in Client output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100645 return
646 fi
647 ;;
Andres Amaya Garcia93993de2017-09-06 15:38:07 +0100648 "-F")
649 if ! $2 "$SRV_OUT"; then
650 fail "function call to '$2' failed on Server output"
651 return
652 fi
653 ;;
654 "-f")
655 if ! $2 "$CLI_OUT"; then
656 fail "function call to '$2' failed on Client output"
657 return
658 fi
659 ;;
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100660
661 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200662 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100663 exit 1
664 esac
665 shift 2
666 done
667
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100668 # check valgrind's results
669 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200670 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100671 fail "Server has memory errors"
672 return
673 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200674 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100675 fail "Client has memory errors"
676 return
677 fi
678 fi
679
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100680 # if we're here, everything is ok
681 echo "PASS"
Paul Bakkeracaac852016-05-10 11:47:13 +0100682 if [ "$PRESERVE_LOGS" -gt 0 ]; then
683 mv $SRV_OUT o-srv-${TESTS}.log
684 mv $CLI_OUT o-cli-${TESTS}.log
685 fi
686
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200687 rm -f $SRV_OUT $CLI_OUT $PXY_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100688}
689
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100690cleanup() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200691 rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200692 test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
693 test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
694 test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
695 test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100696 exit 1
697}
698
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100699#
700# MAIN
701#
702
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100703get_options "$@"
704
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100705# sanity checks, avoid an avalanche of errors
Hanno Becker4ac73e72017-10-23 15:27:37 +0100706P_SRV_BIN="${P_SRV%%[ ]*}"
707P_CLI_BIN="${P_CLI%%[ ]*}"
708P_PXY_BIN="${P_PXY%%[ ]*}"
Hanno Becker17c04932017-10-10 14:44:53 +0100709if [ ! -x "$P_SRV_BIN" ]; then
710 echo "Command '$P_SRV_BIN' is not an executable file"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100711 exit 1
712fi
Hanno Becker17c04932017-10-10 14:44:53 +0100713if [ ! -x "$P_CLI_BIN" ]; then
714 echo "Command '$P_CLI_BIN' is not an executable file"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100715 exit 1
716fi
Hanno Becker17c04932017-10-10 14:44:53 +0100717if [ ! -x "$P_PXY_BIN" ]; then
718 echo "Command '$P_PXY_BIN' is not an executable file"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200719 exit 1
720fi
Simon Butcher3c0d7b82016-05-23 11:13:17 +0100721if [ "$MEMCHECK" -gt 0 ]; then
722 if which valgrind >/dev/null 2>&1; then :; else
723 echo "Memcheck not possible. Valgrind not found"
724 exit 1
725 fi
726fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100727if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
728 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100729 exit 1
730fi
731
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200732# used by watchdog
733MAIN_PID="$$"
734
Manuel Pégourié-Gonnard0d225da2018-01-22 10:22:09 +0100735# We use somewhat arbitrary delays for tests:
736# - how long do we wait for the server to start (when lsof not available)?
737# - how long do we allow for the client to finish?
738# (not to check performance, just to avoid waiting indefinitely)
739# Things are slower with valgrind, so give extra time here.
740#
741# Note: without lsof, there is a trade-off between the running time of this
742# script and the risk of spurious errors because we didn't wait long enough.
743# The watchdog delay on the other hand doesn't affect normal running time of
744# the script, only the case where a client or server gets stuck.
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200745if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnard0d225da2018-01-22 10:22:09 +0100746 START_DELAY=6
747 DOG_DELAY=60
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200748else
Manuel Pégourié-Gonnard0d225da2018-01-22 10:22:09 +0100749 START_DELAY=2
750 DOG_DELAY=20
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200751fi
Manuel Pégourié-Gonnard0d225da2018-01-22 10:22:09 +0100752
753# some particular tests need more time:
754# - for the client, we multiply the usual watchdog limit by a factor
755# - for the server, we sleep for a number of seconds after the client exits
756# see client_need_more_time() and server_needs_more_time()
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200757CLI_DELAY_FACTOR=1
Janos Follath74537a62016-09-02 13:45:28 +0100758SRV_DELAY_SECONDS=0
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200759
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200760# fix commands to use this port, force IPv4 while at it
Manuel Pégourié-Gonnard0af1ba32015-01-21 11:44:33 +0000761# +SRV_PORT will be replaced by either $SRV_PORT or $PXY_PORT later
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200762P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
763P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
Andres AGf04f54d2016-10-10 15:46:20 +0100764P_PXY="$P_PXY server_addr=127.0.0.1 server_port=$SRV_PORT listen_addr=127.0.0.1 listen_port=$PXY_PORT ${SEED:+"seed=$SEED"}"
Manuel Pégourié-Gonnard61957672015-06-18 17:54:58 +0200765O_SRV="$O_SRV -accept $SRV_PORT -dhparam data_files/dhparams.pem"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200766O_CLI="$O_CLI -connect localhost:+SRV_PORT"
767G_SRV="$G_SRV -p $SRV_PORT"
Manuel Pégourié-Gonnard0af1ba32015-01-21 11:44:33 +0000768G_CLI="$G_CLI -p +SRV_PORT localhost"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200769
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +0200770if [ -n "${OPENSSL_LEGACY:-}" ]; then
771 O_LEGACY_SRV="$O_LEGACY_SRV -accept $SRV_PORT -dhparam data_files/dhparams.pem"
772 O_LEGACY_CLI="$O_LEGACY_CLI -connect localhost:+SRV_PORT"
773fi
774
Hanno Becker58e9dc32018-08-17 15:53:21 +0100775if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +0200776 G_NEXT_SRV="$G_NEXT_SRV -p $SRV_PORT"
777fi
778
Hanno Becker58e9dc32018-08-17 15:53:21 +0100779if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +0200780 G_NEXT_CLI="$G_NEXT_CLI -p +SRV_PORT localhost"
781fi
782
Gilles Peskine62469d92017-05-10 10:13:59 +0200783# Allow SHA-1, because many of our test certificates use it
784P_SRV="$P_SRV allow_sha1=1"
785P_CLI="$P_CLI allow_sha1=1"
786
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200787# Also pick a unique name for intermediate files
788SRV_OUT="srv_out.$$"
789CLI_OUT="cli_out.$$"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200790PXY_OUT="pxy_out.$$"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200791SESSION="session.$$"
792
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200793SKIP_NEXT="NO"
794
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100795trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100796
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200797# Basic test
798
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200799# Checks that:
800# - things work with all ciphersuites active (used with config-full in all.sh)
801# - the expected (highest security) parameters are selected
802# ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200803run_test "Default" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200804 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200805 "$P_CLI" \
806 0 \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200807 -s "Protocol is TLSv1.2" \
Manuel Pégourié-Gonnardce66d5e2018-06-14 11:11:15 +0200808 -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200809 -s "client hello v3, signature_algorithm ext: 6" \
810 -s "ECDHE curve: secp521r1" \
811 -S "error" \
812 -C "error"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200813
Manuel Pégourié-Gonnard3bb08012015-01-22 13:34:21 +0000814run_test "Default, DTLS" \
815 "$P_SRV dtls=1" \
816 "$P_CLI dtls=1" \
817 0 \
818 -s "Protocol is DTLSv1.2" \
Manuel Pégourié-Gonnardce66d5e2018-06-14 11:11:15 +0200819 -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256"
Manuel Pégourié-Gonnard3bb08012015-01-22 13:34:21 +0000820
Andres Amaya Garciab84c40b2017-09-06 15:44:01 +0100821# Test current time in ServerHello
822requires_config_enabled MBEDTLS_HAVE_TIME
Manuel Pégourié-Gonnardce66d5e2018-06-14 11:11:15 +0200823run_test "ServerHello contains gmt_unix_time" \
Andres Amaya Garciab84c40b2017-09-06 15:44:01 +0100824 "$P_SRV debug_level=3" \
825 "$P_CLI debug_level=3" \
826 0 \
Andres Amaya Garciab84c40b2017-09-06 15:44:01 +0100827 -f "check_server_hello_time" \
828 -F "check_server_hello_time"
829
Simon Butcher8e004102016-10-14 00:48:33 +0100830# Test for uniqueness of IVs in AEAD ciphersuites
831run_test "Unique IV in GCM" \
832 "$P_SRV exchanges=20 debug_level=4" \
833 "$P_CLI exchanges=20 debug_level=4 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
834 0 \
835 -u "IV used" \
836 -U "IV used"
837
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100838# Tests for rc4 option
839
Simon Butchera410af52016-05-19 22:12:18 +0100840requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100841run_test "RC4: server disabled, client enabled" \
842 "$P_SRV" \
843 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
844 1 \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100845 -s "SSL - The server has no ciphersuites in common"
846
Simon Butchera410af52016-05-19 22:12:18 +0100847requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100848run_test "RC4: server half, client enabled" \
849 "$P_SRV arc4=1" \
850 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
851 1 \
852 -s "SSL - The server has no ciphersuites in common"
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100853
854run_test "RC4: server enabled, client disabled" \
855 "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
856 "$P_CLI" \
857 1 \
858 -s "SSL - The server has no ciphersuites in common"
859
860run_test "RC4: both enabled" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100861 "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100862 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
863 0 \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100864 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100865 -S "SSL - The server has no ciphersuites in common"
866
Gilles Peskinebc70a182017-05-09 15:59:24 +0200867# Tests for SHA-1 support
868
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200869requires_config_disabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinebc70a182017-05-09 15:59:24 +0200870run_test "SHA-1 forbidden by default in server certificate" \
871 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
872 "$P_CLI debug_level=2 allow_sha1=0" \
873 1 \
874 -c "The certificate is signed with an unacceptable hash"
875
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200876requires_config_enabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
877run_test "SHA-1 forbidden by default in server certificate" \
878 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
879 "$P_CLI debug_level=2 allow_sha1=0" \
880 0
881
Gilles Peskinebc70a182017-05-09 15:59:24 +0200882run_test "SHA-1 explicitly allowed in server certificate" \
883 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
884 "$P_CLI allow_sha1=1" \
885 0
886
887run_test "SHA-256 allowed by default in server certificate" \
888 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2-sha256.crt" \
889 "$P_CLI allow_sha1=0" \
890 0
891
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200892requires_config_disabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinebc70a182017-05-09 15:59:24 +0200893run_test "SHA-1 forbidden by default in client certificate" \
894 "$P_SRV auth_mode=required allow_sha1=0" \
895 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
896 1 \
897 -s "The certificate is signed with an unacceptable hash"
898
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200899requires_config_enabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
900run_test "SHA-1 forbidden by default in client certificate" \
901 "$P_SRV auth_mode=required allow_sha1=0" \
902 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
903 0
904
Gilles Peskinebc70a182017-05-09 15:59:24 +0200905run_test "SHA-1 explicitly allowed in client certificate" \
906 "$P_SRV auth_mode=required allow_sha1=1" \
907 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
908 0
909
910run_test "SHA-256 allowed by default in client certificate" \
911 "$P_SRV auth_mode=required allow_sha1=0" \
912 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha256.crt" \
913 0
914
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100915# Tests for Truncated HMAC extension
916
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100917run_test "Truncated HMAC: client default, server default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200918 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100919 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100920 0 \
Hanno Becker992b6872017-11-09 18:57:39 +0000921 -s "dumping 'expected mac' (20 bytes)" \
922 -S "dumping 'expected mac' (10 bytes)"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100923
Hanno Becker32c55012017-11-10 08:42:54 +0000924requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100925run_test "Truncated HMAC: client disabled, server default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200926 "$P_SRV debug_level=4" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000927 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=0" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100928 0 \
Hanno Becker992b6872017-11-09 18:57:39 +0000929 -s "dumping 'expected mac' (20 bytes)" \
930 -S "dumping 'expected mac' (10 bytes)"
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100931
Hanno Becker32c55012017-11-10 08:42:54 +0000932requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100933run_test "Truncated HMAC: client enabled, server default" \
934 "$P_SRV debug_level=4" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000935 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100936 0 \
Hanno Becker992b6872017-11-09 18:57:39 +0000937 -s "dumping 'expected mac' (20 bytes)" \
938 -S "dumping 'expected mac' (10 bytes)"
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100939
Hanno Becker32c55012017-11-10 08:42:54 +0000940requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100941run_test "Truncated HMAC: client enabled, server disabled" \
942 "$P_SRV debug_level=4 trunc_hmac=0" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000943 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100944 0 \
Hanno Becker992b6872017-11-09 18:57:39 +0000945 -s "dumping 'expected mac' (20 bytes)" \
946 -S "dumping 'expected mac' (10 bytes)"
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100947
Hanno Becker32c55012017-11-10 08:42:54 +0000948requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker34d0c3f2017-11-17 15:46:24 +0000949run_test "Truncated HMAC: client disabled, server enabled" \
950 "$P_SRV debug_level=4 trunc_hmac=1" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000951 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=0" \
Hanno Becker34d0c3f2017-11-17 15:46:24 +0000952 0 \
953 -s "dumping 'expected mac' (20 bytes)" \
954 -S "dumping 'expected mac' (10 bytes)"
955
956requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100957run_test "Truncated HMAC: client enabled, server enabled" \
958 "$P_SRV debug_level=4 trunc_hmac=1" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000959 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100960 0 \
Hanno Becker992b6872017-11-09 18:57:39 +0000961 -S "dumping 'expected mac' (20 bytes)" \
962 -s "dumping 'expected mac' (10 bytes)"
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100963
Hanno Becker4c4f4102017-11-10 09:16:05 +0000964run_test "Truncated HMAC, DTLS: client default, server default" \
965 "$P_SRV dtls=1 debug_level=4" \
966 "$P_CLI dtls=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
967 0 \
968 -s "dumping 'expected mac' (20 bytes)" \
969 -S "dumping 'expected mac' (10 bytes)"
970
971requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
972run_test "Truncated HMAC, DTLS: client disabled, server default" \
973 "$P_SRV dtls=1 debug_level=4" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000974 "$P_CLI dtls=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=0" \
Hanno Becker4c4f4102017-11-10 09:16:05 +0000975 0 \
976 -s "dumping 'expected mac' (20 bytes)" \
977 -S "dumping 'expected mac' (10 bytes)"
978
979requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
980run_test "Truncated HMAC, DTLS: client enabled, server default" \
981 "$P_SRV dtls=1 debug_level=4" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000982 "$P_CLI dtls=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=1" \
Hanno Becker4c4f4102017-11-10 09:16:05 +0000983 0 \
984 -s "dumping 'expected mac' (20 bytes)" \
985 -S "dumping 'expected mac' (10 bytes)"
986
987requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
988run_test "Truncated HMAC, DTLS: client enabled, server disabled" \
989 "$P_SRV dtls=1 debug_level=4 trunc_hmac=0" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000990 "$P_CLI dtls=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=1" \
Hanno Becker4c4f4102017-11-10 09:16:05 +0000991 0 \
992 -s "dumping 'expected mac' (20 bytes)" \
993 -S "dumping 'expected mac' (10 bytes)"
994
995requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
996run_test "Truncated HMAC, DTLS: client disabled, server enabled" \
997 "$P_SRV dtls=1 debug_level=4 trunc_hmac=1" \
Hanno Becker909f9a32017-11-21 17:10:12 +0000998 "$P_CLI dtls=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=0" \
Hanno Becker4c4f4102017-11-10 09:16:05 +0000999 0 \
1000 -s "dumping 'expected mac' (20 bytes)" \
1001 -S "dumping 'expected mac' (10 bytes)"
1002
1003requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
1004run_test "Truncated HMAC, DTLS: client enabled, server enabled" \
1005 "$P_SRV dtls=1 debug_level=4 trunc_hmac=1" \
Hanno Becker909f9a32017-11-21 17:10:12 +00001006 "$P_CLI dtls=1 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +01001007 0 \
1008 -S "dumping 'expected mac' (20 bytes)" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001009 -s "dumping 'expected mac' (10 bytes)"
1010
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001011# Tests for Encrypt-then-MAC extension
1012
1013run_test "Encrypt then MAC: default" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +01001014 "$P_SRV debug_level=3 \
1015 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001016 "$P_CLI debug_level=3" \
1017 0 \
1018 -c "client hello, adding encrypt_then_mac extension" \
1019 -s "found encrypt then mac extension" \
1020 -s "server hello, adding encrypt then mac extension" \
1021 -c "found encrypt_then_mac extension" \
1022 -c "using encrypt then mac" \
1023 -s "using encrypt then mac"
1024
1025run_test "Encrypt then MAC: client enabled, server disabled" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +01001026 "$P_SRV debug_level=3 etm=0 \
1027 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001028 "$P_CLI debug_level=3 etm=1" \
1029 0 \
1030 -c "client hello, adding encrypt_then_mac extension" \
1031 -s "found encrypt then mac extension" \
1032 -S "server hello, adding encrypt then mac extension" \
1033 -C "found encrypt_then_mac extension" \
1034 -C "using encrypt then mac" \
1035 -S "using encrypt then mac"
1036
Manuel Pégourié-Gonnard78e745f2014-11-04 15:44:06 +01001037run_test "Encrypt then MAC: client enabled, aead cipher" \
1038 "$P_SRV debug_level=3 etm=1 \
1039 force_ciphersuite=TLS-RSA-WITH-AES-128-GCM-SHA256" \
1040 "$P_CLI debug_level=3 etm=1" \
1041 0 \
1042 -c "client hello, adding encrypt_then_mac extension" \
1043 -s "found encrypt then mac extension" \
1044 -S "server hello, adding encrypt then mac extension" \
1045 -C "found encrypt_then_mac extension" \
1046 -C "using encrypt then mac" \
1047 -S "using encrypt then mac"
1048
1049run_test "Encrypt then MAC: client enabled, stream cipher" \
1050 "$P_SRV debug_level=3 etm=1 \
1051 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01001052 "$P_CLI debug_level=3 etm=1 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard78e745f2014-11-04 15:44:06 +01001053 0 \
1054 -c "client hello, adding encrypt_then_mac extension" \
1055 -s "found encrypt then mac extension" \
1056 -S "server hello, adding encrypt then mac extension" \
1057 -C "found encrypt_then_mac extension" \
1058 -C "using encrypt then mac" \
1059 -S "using encrypt then mac"
1060
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001061run_test "Encrypt then MAC: client disabled, server enabled" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +01001062 "$P_SRV debug_level=3 etm=1 \
1063 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001064 "$P_CLI debug_level=3 etm=0" \
1065 0 \
1066 -C "client hello, adding encrypt_then_mac extension" \
1067 -S "found encrypt then mac extension" \
1068 -S "server hello, adding encrypt then mac extension" \
1069 -C "found encrypt_then_mac extension" \
1070 -C "using encrypt then mac" \
1071 -S "using encrypt then mac"
1072
Janos Follathe2681a42016-03-07 15:57:05 +00001073requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001074run_test "Encrypt then MAC: client SSLv3, server enabled" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +01001075 "$P_SRV debug_level=3 min_version=ssl3 \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +01001076 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001077 "$P_CLI debug_level=3 force_version=ssl3" \
1078 0 \
1079 -C "client hello, adding encrypt_then_mac extension" \
1080 -S "found encrypt then mac extension" \
1081 -S "server hello, adding encrypt then mac extension" \
1082 -C "found encrypt_then_mac extension" \
1083 -C "using encrypt then mac" \
1084 -S "using encrypt then mac"
1085
Janos Follathe2681a42016-03-07 15:57:05 +00001086requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001087run_test "Encrypt then MAC: client enabled, server SSLv3" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +01001088 "$P_SRV debug_level=3 force_version=ssl3 \
1089 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +01001090 "$P_CLI debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001091 0 \
1092 -c "client hello, adding encrypt_then_mac extension" \
Janos Follath00efff72016-05-06 13:48:23 +01001093 -S "found encrypt then mac extension" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +01001094 -S "server hello, adding encrypt then mac extension" \
1095 -C "found encrypt_then_mac extension" \
1096 -C "using encrypt then mac" \
1097 -S "using encrypt then mac"
1098
Manuel Pégourié-Gonnard367381f2014-10-20 18:40:56 +02001099# Tests for Extended Master Secret extension
1100
1101run_test "Extended Master Secret: default" \
1102 "$P_SRV debug_level=3" \
1103 "$P_CLI debug_level=3" \
1104 0 \
1105 -c "client hello, adding extended_master_secret extension" \
1106 -s "found extended master secret extension" \
1107 -s "server hello, adding extended master secret extension" \
1108 -c "found extended_master_secret extension" \
1109 -c "using extended master secret" \
1110 -s "using extended master secret"
1111
1112run_test "Extended Master Secret: client enabled, server disabled" \
1113 "$P_SRV debug_level=3 extended_ms=0" \
1114 "$P_CLI debug_level=3 extended_ms=1" \
1115 0 \
1116 -c "client hello, adding extended_master_secret extension" \
1117 -s "found extended master secret extension" \
1118 -S "server hello, adding extended master secret extension" \
1119 -C "found extended_master_secret extension" \
1120 -C "using extended master secret" \
1121 -S "using extended master secret"
1122
1123run_test "Extended Master Secret: client disabled, server enabled" \
1124 "$P_SRV debug_level=3 extended_ms=1" \
1125 "$P_CLI debug_level=3 extended_ms=0" \
1126 0 \
1127 -C "client hello, adding extended_master_secret extension" \
1128 -S "found extended master secret extension" \
1129 -S "server hello, adding extended master secret extension" \
1130 -C "found extended_master_secret extension" \
1131 -C "using extended master secret" \
1132 -S "using extended master secret"
1133
Janos Follathe2681a42016-03-07 15:57:05 +00001134requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +02001135run_test "Extended Master Secret: client SSLv3, server enabled" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +01001136 "$P_SRV debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +02001137 "$P_CLI debug_level=3 force_version=ssl3" \
1138 0 \
1139 -C "client hello, adding extended_master_secret extension" \
1140 -S "found extended master secret extension" \
1141 -S "server hello, adding extended master secret extension" \
1142 -C "found extended_master_secret extension" \
1143 -C "using extended master secret" \
1144 -S "using extended master secret"
1145
Janos Follathe2681a42016-03-07 15:57:05 +00001146requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +02001147run_test "Extended Master Secret: client enabled, server SSLv3" \
1148 "$P_SRV debug_level=3 force_version=ssl3" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +01001149 "$P_CLI debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +02001150 0 \
1151 -c "client hello, adding extended_master_secret extension" \
Janos Follath00efff72016-05-06 13:48:23 +01001152 -S "found extended master secret extension" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +02001153 -S "server hello, adding extended master secret extension" \
1154 -C "found extended_master_secret extension" \
1155 -C "using extended master secret" \
1156 -S "using extended master secret"
1157
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001158# Tests for FALLBACK_SCSV
1159
1160run_test "Fallback SCSV: default" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001161 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001162 "$P_CLI debug_level=3 force_version=tls1_1" \
1163 0 \
1164 -C "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001165 -S "received FALLBACK_SCSV" \
1166 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001167 -C "is a fatal alert message (msg 86)"
1168
1169run_test "Fallback SCSV: explicitly disabled" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001170 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001171 "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
1172 0 \
1173 -C "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001174 -S "received FALLBACK_SCSV" \
1175 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001176 -C "is a fatal alert message (msg 86)"
1177
1178run_test "Fallback SCSV: enabled" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001179 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001180 "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001181 1 \
1182 -c "adding FALLBACK_SCSV" \
1183 -s "received FALLBACK_SCSV" \
1184 -s "inapropriate fallback" \
1185 -c "is a fatal alert message (msg 86)"
1186
1187run_test "Fallback SCSV: enabled, max version" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001188 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001189 "$P_CLI debug_level=3 fallback=1" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001190 0 \
1191 -c "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001192 -s "received FALLBACK_SCSV" \
1193 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001194 -C "is a fatal alert message (msg 86)"
1195
1196requires_openssl_with_fallback_scsv
1197run_test "Fallback SCSV: default, openssl server" \
1198 "$O_SRV" \
1199 "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
1200 0 \
1201 -C "adding FALLBACK_SCSV" \
1202 -C "is a fatal alert message (msg 86)"
1203
1204requires_openssl_with_fallback_scsv
1205run_test "Fallback SCSV: enabled, openssl server" \
1206 "$O_SRV" \
1207 "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
1208 1 \
1209 -c "adding FALLBACK_SCSV" \
1210 -c "is a fatal alert message (msg 86)"
1211
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001212requires_openssl_with_fallback_scsv
1213run_test "Fallback SCSV: disabled, openssl client" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001214 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001215 "$O_CLI -tls1_1" \
1216 0 \
1217 -S "received FALLBACK_SCSV" \
1218 -S "inapropriate fallback"
1219
1220requires_openssl_with_fallback_scsv
1221run_test "Fallback SCSV: enabled, openssl client" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001222 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001223 "$O_CLI -tls1_1 -fallback_scsv" \
1224 1 \
1225 -s "received FALLBACK_SCSV" \
1226 -s "inapropriate fallback"
1227
1228requires_openssl_with_fallback_scsv
1229run_test "Fallback SCSV: enabled, max version, openssl client" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001230 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001231 "$O_CLI -fallback_scsv" \
1232 0 \
1233 -s "received FALLBACK_SCSV" \
1234 -S "inapropriate fallback"
1235
Andres Amaya Garcia4c761fa2018-07-10 20:08:04 +01001236# Test sending and receiving empty application data records
1237
1238run_test "Encrypt then MAC: empty application data record" \
1239 "$P_SRV auth_mode=none debug_level=4 etm=1" \
1240 "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA" \
1241 0 \
1242 -S "0000: 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
1243 -s "dumping 'input payload after decrypt' (0 bytes)" \
1244 -c "0 bytes written in 1 fragments"
1245
1246run_test "Default, no Encrypt then MAC: empty application data record" \
1247 "$P_SRV auth_mode=none debug_level=4 etm=0" \
1248 "$P_CLI auth_mode=none etm=0 request_size=0" \
1249 0 \
1250 -s "dumping 'input payload after decrypt' (0 bytes)" \
1251 -c "0 bytes written in 1 fragments"
1252
1253run_test "Encrypt then MAC, DTLS: empty application data record" \
1254 "$P_SRV auth_mode=none debug_level=4 etm=1 dtls=1" \
1255 "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA dtls=1" \
1256 0 \
1257 -S "0000: 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
1258 -s "dumping 'input payload after decrypt' (0 bytes)" \
1259 -c "0 bytes written in 1 fragments"
1260
1261run_test "Default, no Encrypt then MAC, DTLS: empty application data record" \
1262 "$P_SRV auth_mode=none debug_level=4 etm=0 dtls=1" \
1263 "$P_CLI auth_mode=none etm=0 request_size=0 dtls=1" \
1264 0 \
1265 -s "dumping 'input payload after decrypt' (0 bytes)" \
1266 -c "0 bytes written in 1 fragments"
1267
Gilles Peskined50177f2017-05-16 17:53:03 +02001268## ClientHello generated with
1269## "openssl s_client -CAfile tests/data_files/test-ca.crt -tls1_1 -connect localhost:4433 -cipher ..."
1270## then manually twiddling the ciphersuite list.
1271## The ClientHello content is spelled out below as a hex string as
1272## "prefix ciphersuite1 ciphersuite2 ciphersuite3 ciphersuite4 suffix".
1273## The expected response is an inappropriate_fallback alert.
1274requires_openssl_with_fallback_scsv
1275run_test "Fallback SCSV: beginning of list" \
1276 "$P_SRV debug_level=2" \
1277 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 5600 0031 0032 0033 0100000900230000000f000101' '15030200020256'" \
1278 0 \
1279 -s "received FALLBACK_SCSV" \
1280 -s "inapropriate fallback"
1281
1282requires_openssl_with_fallback_scsv
1283run_test "Fallback SCSV: end of list" \
1284 "$P_SRV debug_level=2" \
1285 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 0031 0032 0033 5600 0100000900230000000f000101' '15030200020256'" \
1286 0 \
1287 -s "received FALLBACK_SCSV" \
1288 -s "inapropriate fallback"
1289
1290## Here the expected response is a valid ServerHello prefix, up to the random.
1291requires_openssl_with_fallback_scsv
1292run_test "Fallback SCSV: not in list" \
1293 "$P_SRV debug_level=2" \
1294 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 0056 0031 0032 0033 0100000900230000000f000101' '16030200300200002c0302'" \
1295 0 \
1296 -S "received FALLBACK_SCSV" \
1297 -S "inapropriate fallback"
1298
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001299# Tests for CBC 1/n-1 record splitting
1300
1301run_test "CBC Record splitting: TLS 1.2, no splitting" \
1302 "$P_SRV" \
1303 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1304 request_size=123 force_version=tls1_2" \
1305 0 \
1306 -s "Read from client: 123 bytes read" \
1307 -S "Read from client: 1 bytes read" \
1308 -S "122 bytes read"
1309
1310run_test "CBC Record splitting: TLS 1.1, no splitting" \
1311 "$P_SRV" \
1312 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1313 request_size=123 force_version=tls1_1" \
1314 0 \
1315 -s "Read from client: 123 bytes read" \
1316 -S "Read from client: 1 bytes read" \
1317 -S "122 bytes read"
1318
1319run_test "CBC Record splitting: TLS 1.0, splitting" \
1320 "$P_SRV" \
1321 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1322 request_size=123 force_version=tls1" \
1323 0 \
1324 -S "Read from client: 123 bytes read" \
1325 -s "Read from client: 1 bytes read" \
1326 -s "122 bytes read"
1327
Janos Follathe2681a42016-03-07 15:57:05 +00001328requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001329run_test "CBC Record splitting: SSLv3, splitting" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +01001330 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001331 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1332 request_size=123 force_version=ssl3" \
1333 0 \
1334 -S "Read from client: 123 bytes read" \
1335 -s "Read from client: 1 bytes read" \
1336 -s "122 bytes read"
1337
1338run_test "CBC Record splitting: TLS 1.0 RC4, no splitting" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01001339 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001340 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1341 request_size=123 force_version=tls1" \
1342 0 \
1343 -s "Read from client: 123 bytes read" \
1344 -S "Read from client: 1 bytes read" \
1345 -S "122 bytes read"
1346
1347run_test "CBC Record splitting: TLS 1.0, splitting disabled" \
1348 "$P_SRV" \
1349 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1350 request_size=123 force_version=tls1 recsplit=0" \
1351 0 \
1352 -s "Read from client: 123 bytes read" \
1353 -S "Read from client: 1 bytes read" \
1354 -S "122 bytes read"
1355
Manuel Pégourié-Gonnarda852cf42015-01-13 20:56:15 +01001356run_test "CBC Record splitting: TLS 1.0, splitting, nbio" \
1357 "$P_SRV nbio=2" \
1358 "$P_CLI nbio=2 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1359 request_size=123 force_version=tls1" \
1360 0 \
1361 -S "Read from client: 123 bytes read" \
1362 -s "Read from client: 1 bytes read" \
1363 -s "122 bytes read"
1364
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001365# Tests for Session Tickets
1366
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001367run_test "Session resume using tickets: basic" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001368 "$P_SRV debug_level=3 tickets=1" \
1369 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001370 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001371 -c "client hello, adding session ticket extension" \
1372 -s "found session ticket extension" \
1373 -s "server hello, adding session ticket extension" \
1374 -c "found session_ticket extension" \
1375 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001376 -S "session successfully restored from cache" \
1377 -s "session successfully restored from ticket" \
1378 -s "a session has been resumed" \
1379 -c "a session has been resumed"
1380
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001381run_test "Session resume using tickets: cache disabled" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001382 "$P_SRV debug_level=3 tickets=1 cache_max=0" \
1383 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +01001384 0 \
1385 -c "client hello, adding session ticket extension" \
1386 -s "found session ticket extension" \
1387 -s "server hello, adding session ticket extension" \
1388 -c "found session_ticket extension" \
1389 -c "parse new session ticket" \
1390 -S "session successfully restored from cache" \
1391 -s "session successfully restored from ticket" \
1392 -s "a session has been resumed" \
1393 -c "a session has been resumed"
1394
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001395run_test "Session resume using tickets: timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001396 "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
1397 "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +01001398 0 \
1399 -c "client hello, adding session ticket extension" \
1400 -s "found session ticket extension" \
1401 -s "server hello, adding session ticket extension" \
1402 -c "found session_ticket extension" \
1403 -c "parse new session ticket" \
1404 -S "session successfully restored from cache" \
1405 -S "session successfully restored from ticket" \
1406 -S "a session has been resumed" \
1407 -C "a session has been resumed"
1408
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001409run_test "Session resume using tickets: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +01001410 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001411 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +01001412 0 \
1413 -c "client hello, adding session ticket extension" \
1414 -c "found session_ticket extension" \
1415 -c "parse new session ticket" \
1416 -c "a session has been resumed"
1417
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001418run_test "Session resume using tickets: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001419 "$P_SRV debug_level=3 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +02001420 "( $O_CLI -sess_out $SESSION; \
1421 $O_CLI -sess_in $SESSION; \
1422 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +01001423 0 \
1424 -s "found session ticket extension" \
1425 -s "server hello, adding session ticket extension" \
1426 -S "session successfully restored from cache" \
1427 -s "session successfully restored from ticket" \
1428 -s "a session has been resumed"
1429
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001430# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001431
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001432run_test "Session resume using cache: tickets enabled on client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001433 "$P_SRV debug_level=3 tickets=0" \
1434 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001435 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001436 -c "client hello, adding session ticket extension" \
1437 -s "found session ticket extension" \
1438 -S "server hello, adding session ticket extension" \
1439 -C "found session_ticket extension" \
1440 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001441 -s "session successfully restored from cache" \
1442 -S "session successfully restored from ticket" \
1443 -s "a session has been resumed" \
1444 -c "a session has been resumed"
1445
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001446run_test "Session resume using cache: tickets enabled on server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001447 "$P_SRV debug_level=3 tickets=1" \
1448 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001449 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001450 -C "client hello, adding session ticket extension" \
1451 -S "found session ticket extension" \
1452 -S "server hello, adding session ticket extension" \
1453 -C "found session_ticket extension" \
1454 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001455 -s "session successfully restored from cache" \
1456 -S "session successfully restored from ticket" \
1457 -s "a session has been resumed" \
1458 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001459
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001460run_test "Session resume using cache: cache_max=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001461 "$P_SRV debug_level=3 tickets=0 cache_max=0" \
1462 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001463 0 \
1464 -S "session successfully restored from cache" \
1465 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001466 -S "a session has been resumed" \
1467 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001468
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001469run_test "Session resume using cache: cache_max=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001470 "$P_SRV debug_level=3 tickets=0 cache_max=1" \
1471 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001472 0 \
1473 -s "session successfully restored from cache" \
1474 -S "session successfully restored from ticket" \
1475 -s "a session has been resumed" \
1476 -c "a session has been resumed"
1477
Manuel Pégourié-Gonnard6df31962015-05-04 10:55:47 +02001478run_test "Session resume using cache: timeout > delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001479 "$P_SRV debug_level=3 tickets=0" \
1480 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001481 0 \
1482 -s "session successfully restored from cache" \
1483 -S "session successfully restored from ticket" \
1484 -s "a session has been resumed" \
1485 -c "a session has been resumed"
1486
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001487run_test "Session resume using cache: timeout < delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001488 "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
1489 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001490 0 \
1491 -S "session successfully restored from cache" \
1492 -S "session successfully restored from ticket" \
1493 -S "a session has been resumed" \
1494 -C "a session has been resumed"
1495
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001496run_test "Session resume using cache: no timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001497 "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
1498 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001499 0 \
1500 -s "session successfully restored from cache" \
1501 -S "session successfully restored from ticket" \
1502 -s "a session has been resumed" \
1503 -c "a session has been resumed"
1504
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001505run_test "Session resume using cache: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001506 "$P_SRV debug_level=3 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +02001507 "( $O_CLI -sess_out $SESSION; \
1508 $O_CLI -sess_in $SESSION; \
1509 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +01001510 0 \
1511 -s "found session ticket extension" \
1512 -S "server hello, adding session ticket extension" \
1513 -s "session successfully restored from cache" \
1514 -S "session successfully restored from ticket" \
1515 -s "a session has been resumed"
1516
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001517run_test "Session resume using cache: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +01001518 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001519 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +01001520 0 \
1521 -C "found session_ticket extension" \
1522 -C "parse new session ticket" \
1523 -c "a session has been resumed"
1524
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001525# Tests for Max Fragment Length extension
1526
Angus Grattonc4dd0732018-04-11 16:28:39 +10001527if [ "$MAX_CONTENT_LEN" -lt "4096" ]; then
1528 printf "${CONFIG_H} defines MBEDTLS_SSL_MAX_CONTENT_LEN to be less than 4096. Fragment length tests will fail.\n"
Hanno Becker6428f8d2017-09-22 16:58:50 +01001529 exit 1
1530fi
1531
Angus Grattonc4dd0732018-04-11 16:28:39 +10001532if [ $MAX_CONTENT_LEN -ne 16384 ]; then
1533 printf "Using non-default maximum content length $MAX_CONTENT_LEN\n"
1534fi
1535
Hanno Becker4aed27e2017-09-18 15:00:34 +01001536requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Hanno Beckerc5266962017-09-18 15:01:50 +01001537run_test "Max fragment length: enabled, default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001538 "$P_SRV debug_level=3" \
1539 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001540 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001541 -c "Maximum fragment length is $MAX_CONTENT_LEN" \
1542 -s "Maximum fragment length is $MAX_CONTENT_LEN" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001543 -C "client hello, adding max_fragment_length extension" \
1544 -S "found max fragment length extension" \
1545 -S "server hello, max_fragment_length extension" \
1546 -C "found max_fragment_length extension"
1547
Hanno Becker4aed27e2017-09-18 15:00:34 +01001548requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Hanno Beckerc5266962017-09-18 15:01:50 +01001549run_test "Max fragment length: enabled, default, larger message" \
1550 "$P_SRV debug_level=3" \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001551 "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
Hanno Beckerc5266962017-09-18 15:01:50 +01001552 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001553 -c "Maximum fragment length is $MAX_CONTENT_LEN" \
1554 -s "Maximum fragment length is $MAX_CONTENT_LEN" \
Hanno Beckerc5266962017-09-18 15:01:50 +01001555 -C "client hello, adding max_fragment_length extension" \
1556 -S "found max fragment length extension" \
1557 -S "server hello, max_fragment_length extension" \
1558 -C "found max_fragment_length extension" \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001559 -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
1560 -s "$MAX_CONTENT_LEN bytes read" \
Hanno Becker9cfabe32017-10-18 14:42:01 +01001561 -s "1 bytes read"
Hanno Beckerc5266962017-09-18 15:01:50 +01001562
1563requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1564run_test "Max fragment length, DTLS: enabled, default, larger message" \
1565 "$P_SRV debug_level=3 dtls=1" \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001566 "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
Hanno Beckerc5266962017-09-18 15:01:50 +01001567 1 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001568 -c "Maximum fragment length is $MAX_CONTENT_LEN" \
1569 -s "Maximum fragment length is $MAX_CONTENT_LEN" \
Hanno Beckerc5266962017-09-18 15:01:50 +01001570 -C "client hello, adding max_fragment_length extension" \
1571 -S "found max fragment length extension" \
1572 -S "server hello, max_fragment_length extension" \
1573 -C "found max_fragment_length extension" \
1574 -c "fragment larger than.*maximum "
1575
Angus Grattonc4dd0732018-04-11 16:28:39 +10001576# Run some tests with MBEDTLS_SSL_MAX_FRAGMENT_LENGTH disabled
1577# (session fragment length will be 16384 regardless of mbedtls
1578# content length configuration.)
1579
Hanno Beckerc5266962017-09-18 15:01:50 +01001580requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1581run_test "Max fragment length: disabled, larger message" \
1582 "$P_SRV debug_level=3" \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001583 "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
Hanno Beckerc5266962017-09-18 15:01:50 +01001584 0 \
1585 -C "Maximum fragment length is 16384" \
1586 -S "Maximum fragment length is 16384" \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001587 -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
1588 -s "$MAX_CONTENT_LEN bytes read" \
Hanno Becker9cfabe32017-10-18 14:42:01 +01001589 -s "1 bytes read"
Hanno Beckerc5266962017-09-18 15:01:50 +01001590
1591requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1592run_test "Max fragment length DTLS: disabled, larger message" \
1593 "$P_SRV debug_level=3 dtls=1" \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001594 "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
Hanno Beckerc5266962017-09-18 15:01:50 +01001595 1 \
1596 -C "Maximum fragment length is 16384" \
1597 -S "Maximum fragment length is 16384" \
1598 -c "fragment larger than.*maximum "
1599
1600requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001601run_test "Max fragment length: used by client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001602 "$P_SRV debug_level=3" \
1603 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001604 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001605 -c "Maximum fragment length is 4096" \
1606 -s "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001607 -c "client hello, adding max_fragment_length extension" \
1608 -s "found max fragment length extension" \
1609 -s "server hello, max_fragment_length extension" \
1610 -c "found max_fragment_length extension"
1611
Hanno Becker4aed27e2017-09-18 15:00:34 +01001612requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001613run_test "Max fragment length: used by server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001614 "$P_SRV debug_level=3 max_frag_len=4096" \
1615 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001616 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10001617 -c "Maximum fragment length is $MAX_CONTENT_LEN" \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001618 -s "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001619 -C "client hello, adding max_fragment_length extension" \
1620 -S "found max fragment length extension" \
1621 -S "server hello, max_fragment_length extension" \
1622 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001623
Hanno Becker4aed27e2017-09-18 15:00:34 +01001624requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001625requires_gnutls
1626run_test "Max fragment length: gnutls server" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001627 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001628 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001629 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001630 -c "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001631 -c "client hello, adding max_fragment_length extension" \
1632 -c "found max_fragment_length extension"
1633
Hanno Becker4aed27e2017-09-18 15:00:34 +01001634requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001635run_test "Max fragment length: client, message just fits" \
1636 "$P_SRV debug_level=3" \
1637 "$P_CLI debug_level=3 max_frag_len=2048 request_size=2048" \
1638 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001639 -c "Maximum fragment length is 2048" \
1640 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001641 -c "client hello, adding max_fragment_length extension" \
1642 -s "found max fragment length extension" \
1643 -s "server hello, max_fragment_length extension" \
1644 -c "found max_fragment_length extension" \
1645 -c "2048 bytes written in 1 fragments" \
1646 -s "2048 bytes read"
1647
Hanno Becker4aed27e2017-09-18 15:00:34 +01001648requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001649run_test "Max fragment length: client, larger message" \
1650 "$P_SRV debug_level=3" \
1651 "$P_CLI debug_level=3 max_frag_len=2048 request_size=2345" \
1652 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001653 -c "Maximum fragment length is 2048" \
1654 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001655 -c "client hello, adding max_fragment_length extension" \
1656 -s "found max fragment length extension" \
1657 -s "server hello, max_fragment_length extension" \
1658 -c "found max_fragment_length extension" \
1659 -c "2345 bytes written in 2 fragments" \
1660 -s "2048 bytes read" \
1661 -s "297 bytes read"
1662
Hanno Becker4aed27e2017-09-18 15:00:34 +01001663requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnard23eb74d2015-01-21 14:37:13 +00001664run_test "Max fragment length: DTLS client, larger message" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001665 "$P_SRV debug_level=3 dtls=1" \
1666 "$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
1667 1 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001668 -c "Maximum fragment length is 2048" \
1669 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001670 -c "client hello, adding max_fragment_length extension" \
1671 -s "found max fragment length extension" \
1672 -s "server hello, max_fragment_length extension" \
1673 -c "found max_fragment_length extension" \
1674 -c "fragment larger than.*maximum"
1675
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001676# Tests for renegotiation
1677
Hanno Becker6a243642017-10-12 15:18:45 +01001678# Renegotiation SCSV always added, regardless of SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001679run_test "Renegotiation: none, for reference" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001680 "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001681 "$P_CLI debug_level=3 exchanges=2" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001682 0 \
1683 -C "client hello, adding renegotiation extension" \
1684 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1685 -S "found renegotiation extension" \
1686 -s "server hello, secure renegotiation extension" \
1687 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001688 -C "=> renegotiate" \
1689 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001690 -S "write hello request"
1691
Hanno Becker6a243642017-10-12 15:18:45 +01001692requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001693run_test "Renegotiation: client-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001694 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001695 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001696 0 \
1697 -c "client hello, adding renegotiation extension" \
1698 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1699 -s "found renegotiation extension" \
1700 -s "server hello, secure renegotiation extension" \
1701 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001702 -c "=> renegotiate" \
1703 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001704 -S "write hello request"
1705
Hanno Becker6a243642017-10-12 15:18:45 +01001706requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001707run_test "Renegotiation: server-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001708 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001709 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001710 0 \
1711 -c "client hello, adding renegotiation extension" \
1712 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1713 -s "found renegotiation extension" \
1714 -s "server hello, secure renegotiation extension" \
1715 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001716 -c "=> renegotiate" \
1717 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001718 -s "write hello request"
1719
Janos Follathb0f148c2017-10-05 12:29:42 +01001720# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
1721# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
1722# algorithm stronger than SHA-1 is enabled in config.h
Hanno Becker6a243642017-10-12 15:18:45 +01001723requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Janos Follathb0f148c2017-10-05 12:29:42 +01001724run_test "Renegotiation: Signature Algorithms parsing, client-initiated" \
1725 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
1726 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
1727 0 \
1728 -c "client hello, adding renegotiation extension" \
1729 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1730 -s "found renegotiation extension" \
1731 -s "server hello, secure renegotiation extension" \
1732 -c "found renegotiation extension" \
1733 -c "=> renegotiate" \
1734 -s "=> renegotiate" \
1735 -S "write hello request" \
1736 -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
1737
1738# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
1739# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
1740# algorithm stronger than SHA-1 is enabled in config.h
Hanno Becker6a243642017-10-12 15:18:45 +01001741requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Janos Follathb0f148c2017-10-05 12:29:42 +01001742run_test "Renegotiation: Signature Algorithms parsing, server-initiated" \
1743 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
1744 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
1745 0 \
1746 -c "client hello, adding renegotiation extension" \
1747 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1748 -s "found renegotiation extension" \
1749 -s "server hello, secure renegotiation extension" \
1750 -c "found renegotiation extension" \
1751 -c "=> renegotiate" \
1752 -s "=> renegotiate" \
1753 -s "write hello request" \
1754 -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
1755
Hanno Becker6a243642017-10-12 15:18:45 +01001756requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001757run_test "Renegotiation: double" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001758 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001759 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001760 0 \
1761 -c "client hello, adding renegotiation extension" \
1762 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1763 -s "found renegotiation extension" \
1764 -s "server hello, secure renegotiation extension" \
1765 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001766 -c "=> renegotiate" \
1767 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001768 -s "write hello request"
1769
Hanno Becker6a243642017-10-12 15:18:45 +01001770requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001771run_test "Renegotiation: client-initiated, server-rejected" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001772 "$P_SRV debug_level=3 exchanges=2 renegotiation=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001773 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001774 1 \
1775 -c "client hello, adding renegotiation extension" \
1776 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1777 -S "found renegotiation extension" \
1778 -s "server hello, secure renegotiation extension" \
1779 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001780 -c "=> renegotiate" \
1781 -S "=> renegotiate" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001782 -S "write hello request" \
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +02001783 -c "SSL - Unexpected message at ServerHello in renegotiation" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001784 -c "failed"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001785
Hanno Becker6a243642017-10-12 15:18:45 +01001786requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001787run_test "Renegotiation: server-initiated, client-rejected, default" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001788 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001789 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001790 0 \
1791 -C "client hello, adding renegotiation extension" \
1792 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1793 -S "found renegotiation extension" \
1794 -s "server hello, secure renegotiation extension" \
1795 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001796 -C "=> renegotiate" \
1797 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001798 -s "write hello request" \
Manuel Pégourié-Gonnarda9964db2014-07-03 19:29:16 +02001799 -S "SSL - An unexpected message was received from our peer" \
1800 -S "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001801
Hanno Becker6a243642017-10-12 15:18:45 +01001802requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001803run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001804 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001805 renego_delay=-1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001806 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001807 0 \
1808 -C "client hello, adding renegotiation extension" \
1809 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1810 -S "found renegotiation extension" \
1811 -s "server hello, secure renegotiation extension" \
1812 -c "found renegotiation extension" \
1813 -C "=> renegotiate" \
1814 -S "=> renegotiate" \
1815 -s "write hello request" \
1816 -S "SSL - An unexpected message was received from our peer" \
1817 -S "failed"
1818
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +02001819# delay 2 for 1 alert record + 1 application data record
Hanno Becker6a243642017-10-12 15:18:45 +01001820requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001821run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001822 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001823 renego_delay=2 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001824 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001825 0 \
1826 -C "client hello, adding renegotiation extension" \
1827 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1828 -S "found renegotiation extension" \
1829 -s "server hello, secure renegotiation extension" \
1830 -c "found renegotiation extension" \
1831 -C "=> renegotiate" \
1832 -S "=> renegotiate" \
1833 -s "write hello request" \
1834 -S "SSL - An unexpected message was received from our peer" \
1835 -S "failed"
1836
Hanno Becker6a243642017-10-12 15:18:45 +01001837requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001838run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001839 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001840 renego_delay=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001841 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001842 0 \
1843 -C "client hello, adding renegotiation extension" \
1844 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1845 -S "found renegotiation extension" \
1846 -s "server hello, secure renegotiation extension" \
1847 -c "found renegotiation extension" \
1848 -C "=> renegotiate" \
1849 -S "=> renegotiate" \
1850 -s "write hello request" \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +02001851 -s "SSL - An unexpected message was received from our peer"
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001852
Hanno Becker6a243642017-10-12 15:18:45 +01001853requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001854run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001855 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001856 renego_delay=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001857 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001858 0 \
1859 -c "client hello, adding renegotiation extension" \
1860 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1861 -s "found renegotiation extension" \
1862 -s "server hello, secure renegotiation extension" \
1863 -c "found renegotiation extension" \
1864 -c "=> renegotiate" \
1865 -s "=> renegotiate" \
1866 -s "write hello request" \
1867 -S "SSL - An unexpected message was received from our peer" \
1868 -S "failed"
1869
Hanno Becker6a243642017-10-12 15:18:45 +01001870requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001871run_test "Renegotiation: periodic, just below period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001872 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001873 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
1874 0 \
1875 -C "client hello, adding renegotiation extension" \
1876 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1877 -S "found renegotiation extension" \
1878 -s "server hello, secure renegotiation extension" \
1879 -c "found renegotiation extension" \
1880 -S "record counter limit reached: renegotiate" \
1881 -C "=> renegotiate" \
1882 -S "=> renegotiate" \
1883 -S "write hello request" \
1884 -S "SSL - An unexpected message was received from our peer" \
1885 -S "failed"
1886
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001887# one extra exchange to be able to complete renego
Hanno Becker6a243642017-10-12 15:18:45 +01001888requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001889run_test "Renegotiation: periodic, just above period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001890 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001891 "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001892 0 \
1893 -c "client hello, adding renegotiation extension" \
1894 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1895 -s "found renegotiation extension" \
1896 -s "server hello, secure renegotiation extension" \
1897 -c "found renegotiation extension" \
1898 -s "record counter limit reached: renegotiate" \
1899 -c "=> renegotiate" \
1900 -s "=> renegotiate" \
1901 -s "write hello request" \
1902 -S "SSL - An unexpected message was received from our peer" \
1903 -S "failed"
1904
Hanno Becker6a243642017-10-12 15:18:45 +01001905requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001906run_test "Renegotiation: periodic, two times period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001907 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001908 "$P_CLI debug_level=3 exchanges=7 renegotiation=1" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001909 0 \
1910 -c "client hello, adding renegotiation extension" \
1911 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1912 -s "found renegotiation extension" \
1913 -s "server hello, secure renegotiation extension" \
1914 -c "found renegotiation extension" \
1915 -s "record counter limit reached: renegotiate" \
1916 -c "=> renegotiate" \
1917 -s "=> renegotiate" \
1918 -s "write hello request" \
1919 -S "SSL - An unexpected message was received from our peer" \
1920 -S "failed"
1921
Hanno Becker6a243642017-10-12 15:18:45 +01001922requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001923run_test "Renegotiation: periodic, above period, disabled" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001924 "$P_SRV debug_level=3 exchanges=9 renegotiation=0 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001925 "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
1926 0 \
1927 -C "client hello, adding renegotiation extension" \
1928 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1929 -S "found renegotiation extension" \
1930 -s "server hello, secure renegotiation extension" \
1931 -c "found renegotiation extension" \
1932 -S "record counter limit reached: renegotiate" \
1933 -C "=> renegotiate" \
1934 -S "=> renegotiate" \
1935 -S "write hello request" \
1936 -S "SSL - An unexpected message was received from our peer" \
1937 -S "failed"
1938
Hanno Becker6a243642017-10-12 15:18:45 +01001939requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001940run_test "Renegotiation: nbio, client-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001941 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001942 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +02001943 0 \
1944 -c "client hello, adding renegotiation extension" \
1945 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1946 -s "found renegotiation extension" \
1947 -s "server hello, secure renegotiation extension" \
1948 -c "found renegotiation extension" \
1949 -c "=> renegotiate" \
1950 -s "=> renegotiate" \
1951 -S "write hello request"
1952
Hanno Becker6a243642017-10-12 15:18:45 +01001953requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001954run_test "Renegotiation: nbio, server-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001955 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001956 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +02001957 0 \
1958 -c "client hello, adding renegotiation extension" \
1959 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1960 -s "found renegotiation extension" \
1961 -s "server hello, secure renegotiation extension" \
1962 -c "found renegotiation extension" \
1963 -c "=> renegotiate" \
1964 -s "=> renegotiate" \
1965 -s "write hello request"
1966
Hanno Becker6a243642017-10-12 15:18:45 +01001967requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001968run_test "Renegotiation: openssl server, client-initiated" \
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02001969 "$O_SRV -www" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001970 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001971 0 \
1972 -c "client hello, adding renegotiation extension" \
1973 -c "found renegotiation extension" \
1974 -c "=> renegotiate" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001975 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001976 -C "error" \
1977 -c "HTTP/1.0 200 [Oo][Kk]"
1978
Paul Bakker539d9722015-02-08 16:18:35 +01001979requires_gnutls
Hanno Becker6a243642017-10-12 15:18:45 +01001980requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001981run_test "Renegotiation: gnutls server strict, client-initiated" \
1982 "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001983 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001984 0 \
1985 -c "client hello, adding renegotiation extension" \
1986 -c "found renegotiation extension" \
1987 -c "=> renegotiate" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001988 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001989 -C "error" \
1990 -c "HTTP/1.0 200 [Oo][Kk]"
1991
Paul Bakker539d9722015-02-08 16:18:35 +01001992requires_gnutls
Hanno Becker6a243642017-10-12 15:18:45 +01001993requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001994run_test "Renegotiation: gnutls server unsafe, client-initiated default" \
1995 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1996 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
1997 1 \
1998 -c "client hello, adding renegotiation extension" \
1999 -C "found renegotiation extension" \
2000 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002001 -c "mbedtls_ssl_handshake() returned" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002002 -c "error" \
2003 -C "HTTP/1.0 200 [Oo][Kk]"
2004
Paul Bakker539d9722015-02-08 16:18:35 +01002005requires_gnutls
Hanno Becker6a243642017-10-12 15:18:45 +01002006requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002007run_test "Renegotiation: gnutls server unsafe, client-inititated no legacy" \
2008 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
2009 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
2010 allow_legacy=0" \
2011 1 \
2012 -c "client hello, adding renegotiation extension" \
2013 -C "found renegotiation extension" \
2014 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002015 -c "mbedtls_ssl_handshake() returned" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002016 -c "error" \
2017 -C "HTTP/1.0 200 [Oo][Kk]"
2018
Paul Bakker539d9722015-02-08 16:18:35 +01002019requires_gnutls
Hanno Becker6a243642017-10-12 15:18:45 +01002020requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002021run_test "Renegotiation: gnutls server unsafe, client-inititated legacy" \
2022 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
2023 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
2024 allow_legacy=1" \
2025 0 \
2026 -c "client hello, adding renegotiation extension" \
2027 -C "found renegotiation extension" \
2028 -c "=> renegotiate" \
2029 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002030 -C "error" \
2031 -c "HTTP/1.0 200 [Oo][Kk]"
2032
Hanno Becker6a243642017-10-12 15:18:45 +01002033requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard30d16eb2014-08-19 17:43:50 +02002034run_test "Renegotiation: DTLS, client-initiated" \
2035 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
2036 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
2037 0 \
2038 -c "client hello, adding renegotiation extension" \
2039 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
2040 -s "found renegotiation extension" \
2041 -s "server hello, secure renegotiation extension" \
2042 -c "found renegotiation extension" \
2043 -c "=> renegotiate" \
2044 -s "=> renegotiate" \
2045 -S "write hello request"
2046
Hanno Becker6a243642017-10-12 15:18:45 +01002047requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +02002048run_test "Renegotiation: DTLS, server-initiated" \
2049 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnarddf9a0a82014-10-02 14:17:18 +02002050 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
2051 read_timeout=1000 max_resend=2" \
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +02002052 0 \
2053 -c "client hello, adding renegotiation extension" \
2054 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
2055 -s "found renegotiation extension" \
2056 -s "server hello, secure renegotiation extension" \
2057 -c "found renegotiation extension" \
2058 -c "=> renegotiate" \
2059 -s "=> renegotiate" \
2060 -s "write hello request"
2061
Hanno Becker6a243642017-10-12 15:18:45 +01002062requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Andres AG692ad842017-01-19 16:30:57 +00002063run_test "Renegotiation: DTLS, renego_period overflow" \
2064 "$P_SRV debug_level=3 dtls=1 exchanges=4 renegotiation=1 renego_period=18446462598732840962 auth_mode=optional" \
2065 "$P_CLI debug_level=3 dtls=1 exchanges=4 renegotiation=1" \
2066 0 \
2067 -c "client hello, adding renegotiation extension" \
2068 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
2069 -s "found renegotiation extension" \
2070 -s "server hello, secure renegotiation extension" \
2071 -s "record counter limit reached: renegotiate" \
2072 -c "=> renegotiate" \
2073 -s "=> renegotiate" \
Hanno Becker6a243642017-10-12 15:18:45 +01002074 -s "write hello request"
Andres AG692ad842017-01-19 16:30:57 +00002075
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00002076requires_gnutls
Hanno Becker6a243642017-10-12 15:18:45 +01002077requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +02002078run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
2079 "$G_SRV -u --mtu 4096" \
2080 "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
2081 0 \
2082 -c "client hello, adding renegotiation extension" \
2083 -c "found renegotiation extension" \
2084 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002085 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +02002086 -C "error" \
2087 -s "Extra-header:"
2088
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002089# Test for the "secure renegotation" extension only (no actual renegotiation)
2090
Paul Bakker539d9722015-02-08 16:18:35 +01002091requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002092run_test "Renego ext: gnutls server strict, client default" \
2093 "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
2094 "$P_CLI debug_level=3" \
2095 0 \
2096 -c "found renegotiation extension" \
2097 -C "error" \
2098 -c "HTTP/1.0 200 [Oo][Kk]"
2099
Paul Bakker539d9722015-02-08 16:18:35 +01002100requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002101run_test "Renego ext: gnutls server unsafe, client default" \
2102 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
2103 "$P_CLI debug_level=3" \
2104 0 \
2105 -C "found renegotiation extension" \
2106 -C "error" \
2107 -c "HTTP/1.0 200 [Oo][Kk]"
2108
Paul Bakker539d9722015-02-08 16:18:35 +01002109requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002110run_test "Renego ext: gnutls server unsafe, client break legacy" \
2111 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
2112 "$P_CLI debug_level=3 allow_legacy=-1" \
2113 1 \
2114 -C "found renegotiation extension" \
2115 -c "error" \
2116 -C "HTTP/1.0 200 [Oo][Kk]"
2117
Paul Bakker539d9722015-02-08 16:18:35 +01002118requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002119run_test "Renego ext: gnutls client strict, server default" \
2120 "$P_SRV debug_level=3" \
2121 "$G_CLI --priority=NORMAL:%SAFE_RENEGOTIATION" \
2122 0 \
2123 -s "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
2124 -s "server hello, secure renegotiation extension"
2125
Paul Bakker539d9722015-02-08 16:18:35 +01002126requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002127run_test "Renego ext: gnutls client unsafe, server default" \
2128 "$P_SRV debug_level=3" \
2129 "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
2130 0 \
2131 -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
2132 -S "server hello, secure renegotiation extension"
2133
Paul Bakker539d9722015-02-08 16:18:35 +01002134requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01002135run_test "Renego ext: gnutls client unsafe, server break legacy" \
2136 "$P_SRV debug_level=3 allow_legacy=-1" \
2137 "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
2138 1 \
2139 -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
2140 -S "server hello, secure renegotiation extension"
2141
Janos Follath0b242342016-02-17 10:11:21 +00002142# Tests for silently dropping trailing extra bytes in .der certificates
2143
2144requires_gnutls
2145run_test "DER format: no trailing bytes" \
2146 "$P_SRV crt_file=data_files/server5-der0.crt \
2147 key_file=data_files/server5.key" \
2148 "$G_CLI " \
2149 0 \
2150 -c "Handshake was completed" \
2151
2152requires_gnutls
2153run_test "DER format: with a trailing zero byte" \
2154 "$P_SRV crt_file=data_files/server5-der1a.crt \
2155 key_file=data_files/server5.key" \
2156 "$G_CLI " \
2157 0 \
2158 -c "Handshake was completed" \
2159
2160requires_gnutls
2161run_test "DER format: with a trailing random byte" \
2162 "$P_SRV crt_file=data_files/server5-der1b.crt \
2163 key_file=data_files/server5.key" \
2164 "$G_CLI " \
2165 0 \
2166 -c "Handshake was completed" \
2167
2168requires_gnutls
2169run_test "DER format: with 2 trailing random bytes" \
2170 "$P_SRV crt_file=data_files/server5-der2.crt \
2171 key_file=data_files/server5.key" \
2172 "$G_CLI " \
2173 0 \
2174 -c "Handshake was completed" \
2175
2176requires_gnutls
2177run_test "DER format: with 4 trailing random bytes" \
2178 "$P_SRV crt_file=data_files/server5-der4.crt \
2179 key_file=data_files/server5.key" \
2180 "$G_CLI " \
2181 0 \
2182 -c "Handshake was completed" \
2183
2184requires_gnutls
2185run_test "DER format: with 8 trailing random bytes" \
2186 "$P_SRV crt_file=data_files/server5-der8.crt \
2187 key_file=data_files/server5.key" \
2188 "$G_CLI " \
2189 0 \
2190 -c "Handshake was completed" \
2191
2192requires_gnutls
2193run_test "DER format: with 9 trailing random bytes" \
2194 "$P_SRV crt_file=data_files/server5-der9.crt \
2195 key_file=data_files/server5.key" \
2196 "$G_CLI " \
2197 0 \
2198 -c "Handshake was completed" \
2199
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002200# Tests for auth_mode
2201
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002202run_test "Authentication: server badcert, client required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002203 "$P_SRV crt_file=data_files/server5-badsign.crt \
2204 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002205 "$P_CLI debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002206 1 \
2207 -c "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002208 -c "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002209 -c "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002210 -c "X509 - Certificate verification failed"
2211
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002212run_test "Authentication: server badcert, client optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002213 "$P_SRV crt_file=data_files/server5-badsign.crt \
2214 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002215 "$P_CLI debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002216 0 \
2217 -c "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002218 -c "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002219 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002220 -C "X509 - Certificate verification failed"
2221
Hanno Beckere6706e62017-05-15 16:05:15 +01002222run_test "Authentication: server goodcert, client optional, no trusted CA" \
2223 "$P_SRV" \
2224 "$P_CLI debug_level=3 auth_mode=optional ca_file=none ca_path=none" \
2225 0 \
2226 -c "x509_verify_cert() returned" \
2227 -c "! The certificate is not correctly signed by the trusted CA" \
2228 -c "! Certificate verification flags"\
2229 -C "! mbedtls_ssl_handshake returned" \
2230 -C "X509 - Certificate verification failed" \
2231 -C "SSL - No CA Chain is set, but required to operate"
2232
2233run_test "Authentication: server goodcert, client required, no trusted CA" \
2234 "$P_SRV" \
2235 "$P_CLI debug_level=3 auth_mode=required ca_file=none ca_path=none" \
2236 1 \
2237 -c "x509_verify_cert() returned" \
2238 -c "! The certificate is not correctly signed by the trusted CA" \
2239 -c "! Certificate verification flags"\
2240 -c "! mbedtls_ssl_handshake returned" \
2241 -c "SSL - No CA Chain is set, but required to operate"
2242
2243# The purpose of the next two tests is to test the client's behaviour when receiving a server
2244# certificate with an unsupported elliptic curve. This should usually not happen because
2245# the client informs the server about the supported curves - it does, though, in the
2246# corner case of a static ECDH suite, because the server doesn't check the curve on that
2247# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
2248# different means to have the server ignoring the client's supported curve list.
2249
2250requires_config_enabled MBEDTLS_ECP_C
2251run_test "Authentication: server ECDH p256v1, client required, p256v1 unsupported" \
2252 "$P_SRV debug_level=1 key_file=data_files/server5.key \
2253 crt_file=data_files/server5.ku-ka.crt" \
2254 "$P_CLI debug_level=3 auth_mode=required curves=secp521r1" \
2255 1 \
2256 -c "bad certificate (EC key curve)"\
2257 -c "! Certificate verification flags"\
2258 -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
2259
2260requires_config_enabled MBEDTLS_ECP_C
2261run_test "Authentication: server ECDH p256v1, client optional, p256v1 unsupported" \
2262 "$P_SRV debug_level=1 key_file=data_files/server5.key \
2263 crt_file=data_files/server5.ku-ka.crt" \
2264 "$P_CLI debug_level=3 auth_mode=optional curves=secp521r1" \
2265 1 \
2266 -c "bad certificate (EC key curve)"\
2267 -c "! Certificate verification flags"\
2268 -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
2269
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002270run_test "Authentication: server badcert, client none" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +01002271 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002272 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002273 "$P_CLI debug_level=1 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002274 0 \
2275 -C "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002276 -C "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002277 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002278 -C "X509 - Certificate verification failed"
2279
Simon Butcher99000142016-10-13 17:21:01 +01002280run_test "Authentication: client SHA256, server required" \
2281 "$P_SRV auth_mode=required" \
2282 "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
2283 key_file=data_files/server6.key \
2284 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
2285 0 \
2286 -c "Supported Signature Algorithm found: 4," \
2287 -c "Supported Signature Algorithm found: 5,"
2288
2289run_test "Authentication: client SHA384, server required" \
2290 "$P_SRV auth_mode=required" \
2291 "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
2292 key_file=data_files/server6.key \
2293 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2294 0 \
2295 -c "Supported Signature Algorithm found: 4," \
2296 -c "Supported Signature Algorithm found: 5,"
2297
Gilles Peskinefd8332e2017-05-03 16:25:07 +02002298requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
2299run_test "Authentication: client has no cert, server required (SSLv3)" \
2300 "$P_SRV debug_level=3 min_version=ssl3 auth_mode=required" \
2301 "$P_CLI debug_level=3 force_version=ssl3 crt_file=none \
2302 key_file=data_files/server5.key" \
2303 1 \
2304 -S "skip write certificate request" \
2305 -C "skip parse certificate request" \
2306 -c "got a certificate request" \
2307 -c "got no certificate to send" \
2308 -S "x509_verify_cert() returned" \
2309 -s "client has no certificate" \
2310 -s "! mbedtls_ssl_handshake returned" \
2311 -c "! mbedtls_ssl_handshake returned" \
2312 -s "No client certification received from the client, but required by the authentication mode"
2313
2314run_test "Authentication: client has no cert, server required (TLS)" \
2315 "$P_SRV debug_level=3 auth_mode=required" \
2316 "$P_CLI debug_level=3 crt_file=none \
2317 key_file=data_files/server5.key" \
2318 1 \
2319 -S "skip write certificate request" \
2320 -C "skip parse certificate request" \
2321 -c "got a certificate request" \
2322 -c "= write certificate$" \
2323 -C "skip write certificate$" \
2324 -S "x509_verify_cert() returned" \
2325 -s "client has no certificate" \
2326 -s "! mbedtls_ssl_handshake returned" \
2327 -c "! mbedtls_ssl_handshake returned" \
2328 -s "No client certification received from the client, but required by the authentication mode"
2329
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002330run_test "Authentication: client badcert, server required" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002331 "$P_SRV debug_level=3 auth_mode=required" \
2332 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002333 key_file=data_files/server5.key" \
2334 1 \
2335 -S "skip write certificate request" \
2336 -C "skip parse certificate request" \
2337 -c "got a certificate request" \
2338 -C "skip write certificate" \
2339 -C "skip write certificate verify" \
2340 -S "skip parse certificate verify" \
2341 -s "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002342 -s "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002343 -s "! mbedtls_ssl_handshake returned" \
Gilles Peskine1cc8e342017-05-03 16:28:34 +02002344 -s "send alert level=2 message=48" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002345 -c "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002346 -s "X509 - Certificate verification failed"
Gilles Peskine1cc8e342017-05-03 16:28:34 +02002347# We don't check that the client receives the alert because it might
2348# detect that its write end of the connection is closed and abort
2349# before reading the alert message.
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002350
Janos Follath89baba22017-04-10 14:34:35 +01002351run_test "Authentication: client cert not trusted, server required" \
2352 "$P_SRV debug_level=3 auth_mode=required" \
2353 "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
2354 key_file=data_files/server5.key" \
2355 1 \
2356 -S "skip write certificate request" \
2357 -C "skip parse certificate request" \
2358 -c "got a certificate request" \
2359 -C "skip write certificate" \
2360 -C "skip write certificate verify" \
2361 -S "skip parse certificate verify" \
2362 -s "x509_verify_cert() returned" \
2363 -s "! The certificate is not correctly signed by the trusted CA" \
2364 -s "! mbedtls_ssl_handshake returned" \
2365 -c "! mbedtls_ssl_handshake returned" \
2366 -s "X509 - Certificate verification failed"
2367
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002368run_test "Authentication: client badcert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002369 "$P_SRV debug_level=3 auth_mode=optional" \
2370 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002371 key_file=data_files/server5.key" \
2372 0 \
2373 -S "skip write certificate request" \
2374 -C "skip parse certificate request" \
2375 -c "got a certificate request" \
2376 -C "skip write certificate" \
2377 -C "skip write certificate verify" \
2378 -S "skip parse certificate verify" \
2379 -s "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002380 -s "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002381 -S "! mbedtls_ssl_handshake returned" \
2382 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002383 -S "X509 - Certificate verification failed"
2384
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002385run_test "Authentication: client badcert, server none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002386 "$P_SRV debug_level=3 auth_mode=none" \
2387 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002388 key_file=data_files/server5.key" \
2389 0 \
2390 -s "skip write certificate request" \
2391 -C "skip parse certificate request" \
2392 -c "got no certificate request" \
2393 -c "skip write certificate" \
2394 -c "skip write certificate verify" \
2395 -s "skip parse certificate verify" \
2396 -S "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002397 -S "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002398 -S "! mbedtls_ssl_handshake returned" \
2399 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002400 -S "X509 - Certificate verification failed"
2401
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002402run_test "Authentication: client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002403 "$P_SRV debug_level=3 auth_mode=optional" \
2404 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002405 0 \
2406 -S "skip write certificate request" \
2407 -C "skip parse certificate request" \
2408 -c "got a certificate request" \
2409 -C "skip write certificate$" \
2410 -C "got no certificate to send" \
2411 -S "SSLv3 client has no certificate" \
2412 -c "skip write certificate verify" \
2413 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002414 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002415 -S "! mbedtls_ssl_handshake returned" \
2416 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002417 -S "X509 - Certificate verification failed"
2418
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002419run_test "Authentication: openssl client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002420 "$P_SRV debug_level=3 auth_mode=optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002421 "$O_CLI" \
2422 0 \
2423 -S "skip write certificate request" \
2424 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002425 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002426 -S "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002427 -S "X509 - Certificate verification failed"
2428
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002429run_test "Authentication: client no cert, openssl server optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002430 "$O_SRV -verify 10" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002431 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002432 0 \
2433 -C "skip parse certificate request" \
2434 -c "got a certificate request" \
2435 -C "skip write certificate$" \
2436 -c "skip write certificate verify" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002437 -C "! mbedtls_ssl_handshake returned"
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002438
Gilles Peskinefd8332e2017-05-03 16:25:07 +02002439run_test "Authentication: client no cert, openssl server required" \
2440 "$O_SRV -Verify 10" \
2441 "$P_CLI debug_level=3 crt_file=none key_file=none" \
2442 1 \
2443 -C "skip parse certificate request" \
2444 -c "got a certificate request" \
2445 -C "skip write certificate$" \
2446 -c "skip write certificate verify" \
2447 -c "! mbedtls_ssl_handshake returned"
2448
Janos Follathe2681a42016-03-07 15:57:05 +00002449requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002450run_test "Authentication: client no cert, ssl3" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002451 "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01002452 "$P_CLI debug_level=3 crt_file=none key_file=none min_version=ssl3" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002453 0 \
2454 -S "skip write certificate request" \
2455 -C "skip parse certificate request" \
2456 -c "got a certificate request" \
2457 -C "skip write certificate$" \
2458 -c "skip write certificate verify" \
2459 -c "got no certificate to send" \
2460 -s "SSLv3 client has no certificate" \
2461 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002462 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002463 -S "! mbedtls_ssl_handshake returned" \
2464 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002465 -S "X509 - Certificate verification failed"
2466
Manuel Pégourié-Gonnard9107b5f2017-07-06 12:16:25 +02002467# The "max_int chain" tests assume that MAX_INTERMEDIATE_CA is set to its
2468# default value (8)
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002469
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002470MAX_IM_CA='8'
Simon Butcher06b78632017-07-28 01:00:17 +01002471MAX_IM_CA_CONFIG=$( ../scripts/config.pl get MBEDTLS_X509_MAX_INTERMEDIATE_CA)
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002472
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002473if [ -n "$MAX_IM_CA_CONFIG" ] && [ "$MAX_IM_CA_CONFIG" -ne "$MAX_IM_CA" ]; then
Simon Butcher06b78632017-07-28 01:00:17 +01002474 printf "The ${CONFIG_H} file contains a value for the configuration of\n"
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002475 printf "MBEDTLS_X509_MAX_INTERMEDIATE_CA that is different from the script’s\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002476 printf "test value of ${MAX_IM_CA}. \n"
2477 printf "\n"
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002478 printf "The tests assume this value and if it changes, the tests in this\n"
2479 printf "script should also be adjusted.\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002480 printf "\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002481
2482 exit 1
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002483fi
2484
Angus Grattonc4dd0732018-04-11 16:28:39 +10002485requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002486run_test "Authentication: server max_int chain, client default" \
2487 "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
2488 key_file=data_files/dir-maxpath/09.key" \
2489 "$P_CLI server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
2490 0 \
2491 -C "X509 - A fatal error occured"
2492
Angus Grattonc4dd0732018-04-11 16:28:39 +10002493requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002494run_test "Authentication: server max_int+1 chain, client default" \
2495 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2496 key_file=data_files/dir-maxpath/10.key" \
2497 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
2498 1 \
2499 -c "X509 - A fatal error occured"
2500
Angus Grattonc4dd0732018-04-11 16:28:39 +10002501requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002502run_test "Authentication: server max_int+1 chain, client optional" \
2503 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2504 key_file=data_files/dir-maxpath/10.key" \
2505 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
2506 auth_mode=optional" \
2507 1 \
2508 -c "X509 - A fatal error occured"
2509
Angus Grattonc4dd0732018-04-11 16:28:39 +10002510requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002511run_test "Authentication: server max_int+1 chain, client none" \
2512 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2513 key_file=data_files/dir-maxpath/10.key" \
2514 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
2515 auth_mode=none" \
2516 0 \
2517 -C "X509 - A fatal error occured"
2518
Angus Grattonc4dd0732018-04-11 16:28:39 +10002519requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002520run_test "Authentication: client max_int+1 chain, server default" \
2521 "$P_SRV ca_file=data_files/dir-maxpath/00.crt" \
2522 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2523 key_file=data_files/dir-maxpath/10.key" \
2524 0 \
2525 -S "X509 - A fatal error occured"
2526
Angus Grattonc4dd0732018-04-11 16:28:39 +10002527requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002528run_test "Authentication: client max_int+1 chain, server optional" \
2529 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
2530 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2531 key_file=data_files/dir-maxpath/10.key" \
2532 1 \
2533 -s "X509 - A fatal error occured"
2534
Angus Grattonc4dd0732018-04-11 16:28:39 +10002535requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002536run_test "Authentication: client max_int+1 chain, server required" \
2537 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
2538 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2539 key_file=data_files/dir-maxpath/10.key" \
2540 1 \
2541 -s "X509 - A fatal error occured"
2542
Angus Grattonc4dd0732018-04-11 16:28:39 +10002543requires_full_size_output_buffer
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002544run_test "Authentication: client max_int chain, server required" \
2545 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
2546 "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
2547 key_file=data_files/dir-maxpath/09.key" \
2548 0 \
2549 -S "X509 - A fatal error occured"
2550
Janos Follath89baba22017-04-10 14:34:35 +01002551# Tests for CA list in CertificateRequest messages
2552
2553run_test "Authentication: send CA list in CertificateRequest (default)" \
2554 "$P_SRV debug_level=3 auth_mode=required" \
2555 "$P_CLI crt_file=data_files/server6.crt \
2556 key_file=data_files/server6.key" \
2557 0 \
2558 -s "requested DN"
2559
2560run_test "Authentication: do not send CA list in CertificateRequest" \
2561 "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
2562 "$P_CLI crt_file=data_files/server6.crt \
2563 key_file=data_files/server6.key" \
2564 0 \
2565 -S "requested DN"
2566
2567run_test "Authentication: send CA list in CertificateRequest, client self signed" \
2568 "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
2569 "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
2570 key_file=data_files/server5.key" \
2571 1 \
2572 -S "requested DN" \
2573 -s "x509_verify_cert() returned" \
2574 -s "! The certificate is not correctly signed by the trusted CA" \
2575 -s "! mbedtls_ssl_handshake returned" \
2576 -c "! mbedtls_ssl_handshake returned" \
2577 -s "X509 - Certificate verification failed"
2578
Manuel Pégourié-Gonnarddf331a52015-01-08 16:43:07 +01002579# Tests for certificate selection based on SHA verson
2580
2581run_test "Certificate hash: client TLS 1.2 -> SHA-2" \
2582 "$P_SRV crt_file=data_files/server5.crt \
2583 key_file=data_files/server5.key \
2584 crt_file2=data_files/server5-sha1.crt \
2585 key_file2=data_files/server5.key" \
2586 "$P_CLI force_version=tls1_2" \
2587 0 \
2588 -c "signed using.*ECDSA with SHA256" \
2589 -C "signed using.*ECDSA with SHA1"
2590
2591run_test "Certificate hash: client TLS 1.1 -> SHA-1" \
2592 "$P_SRV crt_file=data_files/server5.crt \
2593 key_file=data_files/server5.key \
2594 crt_file2=data_files/server5-sha1.crt \
2595 key_file2=data_files/server5.key" \
2596 "$P_CLI force_version=tls1_1" \
2597 0 \
2598 -C "signed using.*ECDSA with SHA256" \
2599 -c "signed using.*ECDSA with SHA1"
2600
2601run_test "Certificate hash: client TLS 1.0 -> SHA-1" \
2602 "$P_SRV crt_file=data_files/server5.crt \
2603 key_file=data_files/server5.key \
2604 crt_file2=data_files/server5-sha1.crt \
2605 key_file2=data_files/server5.key" \
2606 "$P_CLI force_version=tls1" \
2607 0 \
2608 -C "signed using.*ECDSA with SHA256" \
2609 -c "signed using.*ECDSA with SHA1"
2610
2611run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 1)" \
2612 "$P_SRV crt_file=data_files/server5.crt \
2613 key_file=data_files/server5.key \
2614 crt_file2=data_files/server6.crt \
2615 key_file2=data_files/server6.key" \
2616 "$P_CLI force_version=tls1_1" \
2617 0 \
2618 -c "serial number.*09" \
2619 -c "signed using.*ECDSA with SHA256" \
2620 -C "signed using.*ECDSA with SHA1"
2621
2622run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 2)" \
2623 "$P_SRV crt_file=data_files/server6.crt \
2624 key_file=data_files/server6.key \
2625 crt_file2=data_files/server5.crt \
2626 key_file2=data_files/server5.key" \
2627 "$P_CLI force_version=tls1_1" \
2628 0 \
2629 -c "serial number.*0A" \
2630 -c "signed using.*ECDSA with SHA256" \
2631 -C "signed using.*ECDSA with SHA1"
2632
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002633# tests for SNI
2634
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002635run_test "SNI: no SNI callback" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002636 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002637 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002638 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002639 0 \
2640 -S "parse ServerName extension" \
2641 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
2642 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002643
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002644run_test "SNI: matching cert 1" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002645 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002646 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002647 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 +02002648 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002649 0 \
2650 -s "parse ServerName extension" \
2651 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2652 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002653
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002654run_test "SNI: matching cert 2" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002655 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002656 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002657 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 +02002658 "$P_CLI server_name=polarssl.example" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002659 0 \
2660 -s "parse ServerName extension" \
2661 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2662 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002663
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002664run_test "SNI: no matching cert" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002665 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002666 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002667 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 +02002668 "$P_CLI server_name=nonesuch.example" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002669 1 \
2670 -s "parse ServerName extension" \
2671 -s "ssl_sni_wrapper() returned" \
2672 -s "mbedtls_ssl_handshake returned" \
2673 -c "mbedtls_ssl_handshake returned" \
2674 -c "SSL - A fatal alert message was received from our peer"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002675
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002676run_test "SNI: client auth no override: optional" \
2677 "$P_SRV debug_level=3 auth_mode=optional \
2678 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2679 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
2680 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002681 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002682 -S "skip write certificate request" \
2683 -C "skip parse certificate request" \
2684 -c "got a certificate request" \
2685 -C "skip write certificate" \
2686 -C "skip write certificate verify" \
2687 -S "skip parse certificate verify"
2688
2689run_test "SNI: client auth override: none -> optional" \
2690 "$P_SRV debug_level=3 auth_mode=none \
2691 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2692 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
2693 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002694 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002695 -S "skip write certificate request" \
2696 -C "skip parse certificate request" \
2697 -c "got a certificate request" \
2698 -C "skip write certificate" \
2699 -C "skip write certificate verify" \
2700 -S "skip parse certificate verify"
2701
2702run_test "SNI: client auth override: optional -> none" \
2703 "$P_SRV debug_level=3 auth_mode=optional \
2704 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2705 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
2706 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002707 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002708 -s "skip write certificate request" \
2709 -C "skip parse certificate request" \
2710 -c "got no certificate request" \
2711 -c "skip write certificate" \
2712 -c "skip write certificate verify" \
2713 -s "skip parse certificate verify"
2714
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002715run_test "SNI: CA no override" \
2716 "$P_SRV debug_level=3 auth_mode=optional \
2717 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2718 ca_file=data_files/test-ca.crt \
2719 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
2720 "$P_CLI debug_level=3 server_name=localhost \
2721 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2722 1 \
2723 -S "skip write certificate request" \
2724 -C "skip parse certificate request" \
2725 -c "got a certificate request" \
2726 -C "skip write certificate" \
2727 -C "skip write certificate verify" \
2728 -S "skip parse certificate verify" \
2729 -s "x509_verify_cert() returned" \
2730 -s "! The certificate is not correctly signed by the trusted CA" \
2731 -S "The certificate has been revoked (is on a CRL)"
2732
2733run_test "SNI: CA override" \
2734 "$P_SRV debug_level=3 auth_mode=optional \
2735 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2736 ca_file=data_files/test-ca.crt \
2737 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
2738 "$P_CLI debug_level=3 server_name=localhost \
2739 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2740 0 \
2741 -S "skip write certificate request" \
2742 -C "skip parse certificate request" \
2743 -c "got a certificate request" \
2744 -C "skip write certificate" \
2745 -C "skip write certificate verify" \
2746 -S "skip parse certificate verify" \
2747 -S "x509_verify_cert() returned" \
2748 -S "! The certificate is not correctly signed by the trusted CA" \
2749 -S "The certificate has been revoked (is on a CRL)"
2750
2751run_test "SNI: CA override with CRL" \
2752 "$P_SRV debug_level=3 auth_mode=optional \
2753 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2754 ca_file=data_files/test-ca.crt \
2755 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
2756 "$P_CLI debug_level=3 server_name=localhost \
2757 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2758 1 \
2759 -S "skip write certificate request" \
2760 -C "skip parse certificate request" \
2761 -c "got a certificate request" \
2762 -C "skip write certificate" \
2763 -C "skip write certificate verify" \
2764 -S "skip parse certificate verify" \
2765 -s "x509_verify_cert() returned" \
2766 -S "! The certificate is not correctly signed by the trusted CA" \
2767 -s "The certificate has been revoked (is on a CRL)"
2768
Andres AG1a834452016-12-07 10:01:30 +00002769# Tests for SNI and DTLS
2770
Andres Amaya Garcia54306c12018-05-01 20:27:37 +01002771run_test "SNI: DTLS, no SNI callback" \
2772 "$P_SRV debug_level=3 dtls=1 \
2773 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
2774 "$P_CLI server_name=localhost dtls=1" \
2775 0 \
2776 -S "parse ServerName extension" \
2777 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
2778 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
2779
Andres Amaya Garciaf77d3d32018-05-01 20:26:47 +01002780run_test "SNI: DTLS, matching cert 1" \
Andres AG1a834452016-12-07 10:01:30 +00002781 "$P_SRV debug_level=3 dtls=1 \
2782 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2783 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
2784 "$P_CLI server_name=localhost dtls=1" \
2785 0 \
2786 -s "parse ServerName extension" \
2787 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2788 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
2789
Andres Amaya Garcia54306c12018-05-01 20:27:37 +01002790run_test "SNI: DTLS, matching cert 2" \
2791 "$P_SRV debug_level=3 dtls=1 \
2792 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2793 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
2794 "$P_CLI server_name=polarssl.example dtls=1" \
2795 0 \
2796 -s "parse ServerName extension" \
2797 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2798 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
2799
2800run_test "SNI: DTLS, no matching cert" \
2801 "$P_SRV debug_level=3 dtls=1 \
2802 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2803 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
2804 "$P_CLI server_name=nonesuch.example dtls=1" \
2805 1 \
2806 -s "parse ServerName extension" \
2807 -s "ssl_sni_wrapper() returned" \
2808 -s "mbedtls_ssl_handshake returned" \
2809 -c "mbedtls_ssl_handshake returned" \
2810 -c "SSL - A fatal alert message was received from our peer"
2811
2812run_test "SNI: DTLS, client auth no override: optional" \
2813 "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
2814 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2815 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
2816 "$P_CLI debug_level=3 server_name=localhost dtls=1" \
2817 0 \
2818 -S "skip write certificate request" \
2819 -C "skip parse certificate request" \
2820 -c "got a certificate request" \
2821 -C "skip write certificate" \
2822 -C "skip write certificate verify" \
2823 -S "skip parse certificate verify"
2824
2825run_test "SNI: DTLS, client auth override: none -> optional" \
2826 "$P_SRV debug_level=3 auth_mode=none dtls=1 \
2827 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2828 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
2829 "$P_CLI debug_level=3 server_name=localhost dtls=1" \
2830 0 \
2831 -S "skip write certificate request" \
2832 -C "skip parse certificate request" \
2833 -c "got a certificate request" \
2834 -C "skip write certificate" \
2835 -C "skip write certificate verify" \
2836 -S "skip parse certificate verify"
2837
2838run_test "SNI: DTLS, client auth override: optional -> none" \
2839 "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
2840 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2841 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
2842 "$P_CLI debug_level=3 server_name=localhost dtls=1" \
2843 0 \
2844 -s "skip write certificate request" \
2845 -C "skip parse certificate request" \
2846 -c "got no certificate request" \
2847 -c "skip write certificate" \
2848 -c "skip write certificate verify" \
2849 -s "skip parse certificate verify"
2850
2851run_test "SNI: DTLS, CA no override" \
2852 "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
2853 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2854 ca_file=data_files/test-ca.crt \
2855 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
2856 "$P_CLI debug_level=3 server_name=localhost dtls=1 \
2857 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2858 1 \
2859 -S "skip write certificate request" \
2860 -C "skip parse certificate request" \
2861 -c "got a certificate request" \
2862 -C "skip write certificate" \
2863 -C "skip write certificate verify" \
2864 -S "skip parse certificate verify" \
2865 -s "x509_verify_cert() returned" \
2866 -s "! The certificate is not correctly signed by the trusted CA" \
2867 -S "The certificate has been revoked (is on a CRL)"
2868
Andres Amaya Garciaf77d3d32018-05-01 20:26:47 +01002869run_test "SNI: DTLS, CA override" \
Andres AG1a834452016-12-07 10:01:30 +00002870 "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
2871 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2872 ca_file=data_files/test-ca.crt \
2873 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
2874 "$P_CLI debug_level=3 server_name=localhost dtls=1 \
2875 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2876 0 \
2877 -S "skip write certificate request" \
2878 -C "skip parse certificate request" \
2879 -c "got a certificate request" \
2880 -C "skip write certificate" \
2881 -C "skip write certificate verify" \
2882 -S "skip parse certificate verify" \
2883 -S "x509_verify_cert() returned" \
2884 -S "! The certificate is not correctly signed by the trusted CA" \
2885 -S "The certificate has been revoked (is on a CRL)"
2886
Andres Amaya Garciaf77d3d32018-05-01 20:26:47 +01002887run_test "SNI: DTLS, CA override with CRL" \
Andres AG1a834452016-12-07 10:01:30 +00002888 "$P_SRV debug_level=3 auth_mode=optional \
2889 crt_file=data_files/server5.crt key_file=data_files/server5.key dtls=1 \
2890 ca_file=data_files/test-ca.crt \
2891 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
2892 "$P_CLI debug_level=3 server_name=localhost dtls=1 \
2893 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2894 1 \
2895 -S "skip write certificate request" \
2896 -C "skip parse certificate request" \
2897 -c "got a certificate request" \
2898 -C "skip write certificate" \
2899 -C "skip write certificate verify" \
2900 -S "skip parse certificate verify" \
2901 -s "x509_verify_cert() returned" \
2902 -S "! The certificate is not correctly signed by the trusted CA" \
2903 -s "The certificate has been revoked (is on a CRL)"
2904
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002905# Tests for non-blocking I/O: exercise a variety of handshake flows
2906
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002907run_test "Non-blocking I/O: basic handshake" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002908 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
2909 "$P_CLI nbio=2 tickets=0" \
2910 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002911 -S "mbedtls_ssl_handshake returned" \
2912 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002913 -c "Read from server: .* bytes read"
2914
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002915run_test "Non-blocking I/O: client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002916 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
2917 "$P_CLI nbio=2 tickets=0" \
2918 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002919 -S "mbedtls_ssl_handshake returned" \
2920 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002921 -c "Read from server: .* bytes read"
2922
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002923run_test "Non-blocking I/O: ticket" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002924 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
2925 "$P_CLI nbio=2 tickets=1" \
2926 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002927 -S "mbedtls_ssl_handshake returned" \
2928 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002929 -c "Read from server: .* bytes read"
2930
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002931run_test "Non-blocking I/O: ticket + client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002932 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
2933 "$P_CLI nbio=2 tickets=1" \
2934 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002935 -S "mbedtls_ssl_handshake returned" \
2936 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002937 -c "Read from server: .* bytes read"
2938
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002939run_test "Non-blocking I/O: ticket + client auth + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002940 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
2941 "$P_CLI nbio=2 tickets=1 reconnect=1" \
2942 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002943 -S "mbedtls_ssl_handshake returned" \
2944 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002945 -c "Read from server: .* bytes read"
2946
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002947run_test "Non-blocking I/O: ticket + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002948 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
2949 "$P_CLI nbio=2 tickets=1 reconnect=1" \
2950 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002951 -S "mbedtls_ssl_handshake returned" \
2952 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002953 -c "Read from server: .* bytes read"
2954
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002955run_test "Non-blocking I/O: session-id resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002956 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
2957 "$P_CLI nbio=2 tickets=0 reconnect=1" \
2958 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002959 -S "mbedtls_ssl_handshake returned" \
2960 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002961 -c "Read from server: .* bytes read"
2962
Hanno Becker00076712017-11-15 16:39:08 +00002963# Tests for event-driven I/O: exercise a variety of handshake flows
2964
2965run_test "Event-driven I/O: basic handshake" \
2966 "$P_SRV event=1 tickets=0 auth_mode=none" \
2967 "$P_CLI event=1 tickets=0" \
2968 0 \
2969 -S "mbedtls_ssl_handshake returned" \
2970 -C "mbedtls_ssl_handshake returned" \
2971 -c "Read from server: .* bytes read"
2972
2973run_test "Event-driven I/O: client auth" \
2974 "$P_SRV event=1 tickets=0 auth_mode=required" \
2975 "$P_CLI event=1 tickets=0" \
2976 0 \
2977 -S "mbedtls_ssl_handshake returned" \
2978 -C "mbedtls_ssl_handshake returned" \
2979 -c "Read from server: .* bytes read"
2980
2981run_test "Event-driven I/O: ticket" \
2982 "$P_SRV event=1 tickets=1 auth_mode=none" \
2983 "$P_CLI event=1 tickets=1" \
2984 0 \
2985 -S "mbedtls_ssl_handshake returned" \
2986 -C "mbedtls_ssl_handshake returned" \
2987 -c "Read from server: .* bytes read"
2988
2989run_test "Event-driven I/O: ticket + client auth" \
2990 "$P_SRV event=1 tickets=1 auth_mode=required" \
2991 "$P_CLI event=1 tickets=1" \
2992 0 \
2993 -S "mbedtls_ssl_handshake returned" \
2994 -C "mbedtls_ssl_handshake returned" \
2995 -c "Read from server: .* bytes read"
2996
2997run_test "Event-driven I/O: ticket + client auth + resume" \
2998 "$P_SRV event=1 tickets=1 auth_mode=required" \
2999 "$P_CLI event=1 tickets=1 reconnect=1" \
3000 0 \
3001 -S "mbedtls_ssl_handshake returned" \
3002 -C "mbedtls_ssl_handshake returned" \
3003 -c "Read from server: .* bytes read"
3004
3005run_test "Event-driven I/O: ticket + resume" \
3006 "$P_SRV event=1 tickets=1 auth_mode=none" \
3007 "$P_CLI event=1 tickets=1 reconnect=1" \
3008 0 \
3009 -S "mbedtls_ssl_handshake returned" \
3010 -C "mbedtls_ssl_handshake returned" \
3011 -c "Read from server: .* bytes read"
3012
3013run_test "Event-driven I/O: session-id resume" \
3014 "$P_SRV event=1 tickets=0 auth_mode=none" \
3015 "$P_CLI event=1 tickets=0 reconnect=1" \
3016 0 \
3017 -S "mbedtls_ssl_handshake returned" \
3018 -C "mbedtls_ssl_handshake returned" \
3019 -c "Read from server: .* bytes read"
3020
Hanno Becker6a33f592018-03-13 11:38:46 +00003021run_test "Event-driven I/O, DTLS: basic handshake" \
3022 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
3023 "$P_CLI dtls=1 event=1 tickets=0" \
3024 0 \
3025 -c "Read from server: .* bytes read"
3026
3027run_test "Event-driven I/O, DTLS: client auth" \
3028 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
3029 "$P_CLI dtls=1 event=1 tickets=0" \
3030 0 \
3031 -c "Read from server: .* bytes read"
3032
3033run_test "Event-driven I/O, DTLS: ticket" \
3034 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
3035 "$P_CLI dtls=1 event=1 tickets=1" \
3036 0 \
3037 -c "Read from server: .* bytes read"
3038
3039run_test "Event-driven I/O, DTLS: ticket + client auth" \
3040 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
3041 "$P_CLI dtls=1 event=1 tickets=1" \
3042 0 \
3043 -c "Read from server: .* bytes read"
3044
3045run_test "Event-driven I/O, DTLS: ticket + client auth + resume" \
3046 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
3047 "$P_CLI dtls=1 event=1 tickets=1 reconnect=1" \
3048 0 \
3049 -c "Read from server: .* bytes read"
3050
3051run_test "Event-driven I/O, DTLS: ticket + resume" \
3052 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
3053 "$P_CLI dtls=1 event=1 tickets=1 reconnect=1" \
3054 0 \
3055 -c "Read from server: .* bytes read"
3056
3057run_test "Event-driven I/O, DTLS: session-id resume" \
3058 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
3059 "$P_CLI dtls=1 event=1 tickets=0 reconnect=1" \
3060 0 \
3061 -c "Read from server: .* bytes read"
Hanno Beckerbc6c1102018-03-13 11:39:40 +00003062
3063# This test demonstrates the need for the mbedtls_ssl_check_pending function.
3064# During session resumption, the client will send its ApplicationData record
3065# within the same datagram as the Finished messages. In this situation, the
3066# server MUST NOT idle on the underlying transport after handshake completion,
3067# because the ApplicationData request has already been queued internally.
3068run_test "Event-driven I/O, DTLS: session-id resume, UDP packing" \
Hanno Becker8d832182018-03-15 10:14:19 +00003069 -p "$P_PXY pack=50" \
Hanno Beckerbc6c1102018-03-13 11:39:40 +00003070 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
3071 "$P_CLI dtls=1 event=1 tickets=0 reconnect=1" \
3072 0 \
3073 -c "Read from server: .* bytes read"
3074
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003075# Tests for version negotiation
3076
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003077run_test "Version check: all -> 1.2" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003078 "$P_SRV" \
3079 "$P_CLI" \
3080 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003081 -S "mbedtls_ssl_handshake returned" \
3082 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003083 -s "Protocol is TLSv1.2" \
3084 -c "Protocol is TLSv1.2"
3085
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003086run_test "Version check: cli max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003087 "$P_SRV" \
3088 "$P_CLI max_version=tls1_1" \
3089 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003090 -S "mbedtls_ssl_handshake returned" \
3091 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003092 -s "Protocol is TLSv1.1" \
3093 -c "Protocol is TLSv1.1"
3094
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003095run_test "Version check: srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003096 "$P_SRV max_version=tls1_1" \
3097 "$P_CLI" \
3098 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003099 -S "mbedtls_ssl_handshake returned" \
3100 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003101 -s "Protocol is TLSv1.1" \
3102 -c "Protocol is TLSv1.1"
3103
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003104run_test "Version check: cli+srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003105 "$P_SRV max_version=tls1_1" \
3106 "$P_CLI max_version=tls1_1" \
3107 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003108 -S "mbedtls_ssl_handshake returned" \
3109 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003110 -s "Protocol is TLSv1.1" \
3111 -c "Protocol is TLSv1.1"
3112
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003113run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003114 "$P_SRV min_version=tls1_1" \
3115 "$P_CLI max_version=tls1_1" \
3116 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003117 -S "mbedtls_ssl_handshake returned" \
3118 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003119 -s "Protocol is TLSv1.1" \
3120 -c "Protocol is TLSv1.1"
3121
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003122run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003123 "$P_SRV max_version=tls1_1" \
3124 "$P_CLI min_version=tls1_1" \
3125 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003126 -S "mbedtls_ssl_handshake returned" \
3127 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003128 -s "Protocol is TLSv1.1" \
3129 -c "Protocol is TLSv1.1"
3130
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003131run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003132 "$P_SRV max_version=tls1_1" \
3133 "$P_CLI min_version=tls1_2" \
3134 1 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003135 -s "mbedtls_ssl_handshake returned" \
3136 -c "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003137 -c "SSL - Handshake protocol not within min/max boundaries"
3138
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003139run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003140 "$P_SRV min_version=tls1_2" \
3141 "$P_CLI max_version=tls1_1" \
3142 1 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003143 -s "mbedtls_ssl_handshake returned" \
3144 -c "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01003145 -s "SSL - Handshake protocol not within min/max boundaries"
3146
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003147# Tests for ALPN extension
3148
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003149run_test "ALPN: none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003150 "$P_SRV debug_level=3" \
3151 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003152 0 \
3153 -C "client hello, adding alpn extension" \
3154 -S "found alpn extension" \
3155 -C "got an alert message, type: \\[2:120]" \
3156 -S "server hello, adding alpn extension" \
3157 -C "found alpn extension " \
3158 -C "Application Layer Protocol is" \
3159 -S "Application Layer Protocol is"
3160
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003161run_test "ALPN: client only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003162 "$P_SRV debug_level=3" \
3163 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003164 0 \
3165 -c "client hello, adding alpn extension" \
3166 -s "found alpn extension" \
3167 -C "got an alert message, type: \\[2:120]" \
3168 -S "server hello, adding alpn extension" \
3169 -C "found alpn extension " \
3170 -c "Application Layer Protocol is (none)" \
3171 -S "Application Layer Protocol is"
3172
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003173run_test "ALPN: server only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003174 "$P_SRV debug_level=3 alpn=abc,1234" \
3175 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003176 0 \
3177 -C "client hello, adding alpn extension" \
3178 -S "found alpn extension" \
3179 -C "got an alert message, type: \\[2:120]" \
3180 -S "server hello, adding alpn extension" \
3181 -C "found alpn extension " \
3182 -C "Application Layer Protocol is" \
3183 -s "Application Layer Protocol is (none)"
3184
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003185run_test "ALPN: both, common cli1-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003186 "$P_SRV debug_level=3 alpn=abc,1234" \
3187 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003188 0 \
3189 -c "client hello, adding alpn extension" \
3190 -s "found alpn extension" \
3191 -C "got an alert message, type: \\[2:120]" \
3192 -s "server hello, adding alpn extension" \
3193 -c "found alpn extension" \
3194 -c "Application Layer Protocol is abc" \
3195 -s "Application Layer Protocol is abc"
3196
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003197run_test "ALPN: both, common cli2-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003198 "$P_SRV debug_level=3 alpn=abc,1234" \
3199 "$P_CLI debug_level=3 alpn=1234,abc" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003200 0 \
3201 -c "client hello, adding alpn extension" \
3202 -s "found alpn extension" \
3203 -C "got an alert message, type: \\[2:120]" \
3204 -s "server hello, adding alpn extension" \
3205 -c "found alpn extension" \
3206 -c "Application Layer Protocol is abc" \
3207 -s "Application Layer Protocol is abc"
3208
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003209run_test "ALPN: both, common cli1-srv2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003210 "$P_SRV debug_level=3 alpn=abc,1234" \
3211 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003212 0 \
3213 -c "client hello, adding alpn extension" \
3214 -s "found alpn extension" \
3215 -C "got an alert message, type: \\[2:120]" \
3216 -s "server hello, adding alpn extension" \
3217 -c "found alpn extension" \
3218 -c "Application Layer Protocol is 1234" \
3219 -s "Application Layer Protocol is 1234"
3220
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003221run_test "ALPN: both, no common" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003222 "$P_SRV debug_level=3 alpn=abc,123" \
3223 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02003224 1 \
3225 -c "client hello, adding alpn extension" \
3226 -s "found alpn extension" \
3227 -c "got an alert message, type: \\[2:120]" \
3228 -S "server hello, adding alpn extension" \
3229 -C "found alpn extension" \
3230 -C "Application Layer Protocol is 1234" \
3231 -S "Application Layer Protocol is 1234"
3232
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02003233
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003234# Tests for keyUsage in leaf certificates, part 1:
3235# server-side certificate/suite selection
3236
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003237run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003238 "$P_SRV key_file=data_files/server2.key \
3239 crt_file=data_files/server2.ku-ds.crt" \
3240 "$P_CLI" \
3241 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02003242 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003243
3244
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003245run_test "keyUsage srv: RSA, keyEncipherment -> RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003246 "$P_SRV key_file=data_files/server2.key \
3247 crt_file=data_files/server2.ku-ke.crt" \
3248 "$P_CLI" \
3249 0 \
3250 -c "Ciphersuite is TLS-RSA-WITH-"
3251
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003252run_test "keyUsage srv: RSA, keyAgreement -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02003253 "$P_SRV key_file=data_files/server2.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003254 crt_file=data_files/server2.ku-ka.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02003255 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003256 1 \
3257 -C "Ciphersuite is "
3258
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003259run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003260 "$P_SRV key_file=data_files/server5.key \
3261 crt_file=data_files/server5.ku-ds.crt" \
3262 "$P_CLI" \
3263 0 \
3264 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
3265
3266
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003267run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003268 "$P_SRV key_file=data_files/server5.key \
3269 crt_file=data_files/server5.ku-ka.crt" \
3270 "$P_CLI" \
3271 0 \
3272 -c "Ciphersuite is TLS-ECDH-"
3273
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003274run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02003275 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003276 crt_file=data_files/server5.ku-ke.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02003277 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003278 1 \
3279 -C "Ciphersuite is "
3280
3281# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003282# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003283
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003284run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003285 "$O_SRV -key data_files/server2.key \
3286 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003287 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003288 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3289 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003290 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003291 -C "Processing of the Certificate handshake message failed" \
3292 -c "Ciphersuite is TLS-"
3293
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003294run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003295 "$O_SRV -key data_files/server2.key \
3296 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003297 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003298 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
3299 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003300 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003301 -C "Processing of the Certificate handshake message failed" \
3302 -c "Ciphersuite is TLS-"
3303
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003304run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003305 "$O_SRV -key data_files/server2.key \
3306 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003307 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003308 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3309 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003310 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003311 -C "Processing of the Certificate handshake message failed" \
3312 -c "Ciphersuite is TLS-"
3313
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003314run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003315 "$O_SRV -key data_files/server2.key \
3316 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003317 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003318 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
3319 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003320 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003321 -c "Processing of the Certificate handshake message failed" \
3322 -C "Ciphersuite is TLS-"
3323
Manuel Pégourié-Gonnarde6efa6f2015-04-20 11:01:48 +01003324run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail, soft" \
3325 "$O_SRV -key data_files/server2.key \
3326 -cert data_files/server2.ku-ke.crt" \
3327 "$P_CLI debug_level=1 auth_mode=optional \
3328 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
3329 0 \
3330 -c "bad certificate (usage extensions)" \
3331 -C "Processing of the Certificate handshake message failed" \
3332 -c "Ciphersuite is TLS-" \
3333 -c "! Usage does not match the keyUsage extension"
3334
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003335run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003336 "$O_SRV -key data_files/server2.key \
3337 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003338 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003339 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
3340 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003341 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003342 -C "Processing of the Certificate handshake message failed" \
3343 -c "Ciphersuite is TLS-"
3344
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003345run_test "keyUsage cli: DigitalSignature, RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003346 "$O_SRV -key data_files/server2.key \
3347 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003348 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003349 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3350 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003351 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02003352 -c "Processing of the Certificate handshake message failed" \
3353 -C "Ciphersuite is TLS-"
3354
Manuel Pégourié-Gonnarde6efa6f2015-04-20 11:01:48 +01003355run_test "keyUsage cli: DigitalSignature, RSA: fail, soft" \
3356 "$O_SRV -key data_files/server2.key \
3357 -cert data_files/server2.ku-ds.crt" \
3358 "$P_CLI debug_level=1 auth_mode=optional \
3359 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3360 0 \
3361 -c "bad certificate (usage extensions)" \
3362 -C "Processing of the Certificate handshake message failed" \
3363 -c "Ciphersuite is TLS-" \
3364 -c "! Usage does not match the keyUsage extension"
3365
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003366# Tests for keyUsage in leaf certificates, part 3:
3367# server-side checking of client cert
3368
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003369run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003370 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003371 "$O_CLI -key data_files/server2.key \
3372 -cert data_files/server2.ku-ds.crt" \
3373 0 \
3374 -S "bad certificate (usage extensions)" \
3375 -S "Processing of the Certificate handshake message failed"
3376
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003377run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003378 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003379 "$O_CLI -key data_files/server2.key \
3380 -cert data_files/server2.ku-ke.crt" \
3381 0 \
3382 -s "bad certificate (usage extensions)" \
3383 -S "Processing of the Certificate handshake message failed"
3384
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003385run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003386 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003387 "$O_CLI -key data_files/server2.key \
3388 -cert data_files/server2.ku-ke.crt" \
3389 1 \
3390 -s "bad certificate (usage extensions)" \
3391 -s "Processing of the Certificate handshake message failed"
3392
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003393run_test "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003394 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003395 "$O_CLI -key data_files/server5.key \
3396 -cert data_files/server5.ku-ds.crt" \
3397 0 \
3398 -S "bad certificate (usage extensions)" \
3399 -S "Processing of the Certificate handshake message failed"
3400
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003401run_test "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003402 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02003403 "$O_CLI -key data_files/server5.key \
3404 -cert data_files/server5.ku-ka.crt" \
3405 0 \
3406 -s "bad certificate (usage extensions)" \
3407 -S "Processing of the Certificate handshake message failed"
3408
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003409# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
3410
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003411run_test "extKeyUsage srv: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003412 "$P_SRV key_file=data_files/server5.key \
3413 crt_file=data_files/server5.eku-srv.crt" \
3414 "$P_CLI" \
3415 0
3416
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003417run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003418 "$P_SRV key_file=data_files/server5.key \
3419 crt_file=data_files/server5.eku-srv.crt" \
3420 "$P_CLI" \
3421 0
3422
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003423run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003424 "$P_SRV key_file=data_files/server5.key \
3425 crt_file=data_files/server5.eku-cs_any.crt" \
3426 "$P_CLI" \
3427 0
3428
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003429run_test "extKeyUsage srv: codeSign -> fail" \
Manuel Pégourié-Gonnard7eb58cb2015-07-07 11:54:14 +02003430 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003431 crt_file=data_files/server5.eku-cli.crt" \
Manuel Pégourié-Gonnard7eb58cb2015-07-07 11:54:14 +02003432 "$P_CLI" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003433 1
3434
3435# Tests for extendedKeyUsage, part 2: client-side checking of server cert
3436
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003437run_test "extKeyUsage cli: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003438 "$O_SRV -key data_files/server5.key \
3439 -cert data_files/server5.eku-srv.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003440 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003441 0 \
3442 -C "bad certificate (usage extensions)" \
3443 -C "Processing of the Certificate handshake message failed" \
3444 -c "Ciphersuite is TLS-"
3445
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003446run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003447 "$O_SRV -key data_files/server5.key \
3448 -cert data_files/server5.eku-srv_cli.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003449 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003450 0 \
3451 -C "bad certificate (usage extensions)" \
3452 -C "Processing of the Certificate handshake message failed" \
3453 -c "Ciphersuite is TLS-"
3454
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003455run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003456 "$O_SRV -key data_files/server5.key \
3457 -cert data_files/server5.eku-cs_any.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003458 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003459 0 \
3460 -C "bad certificate (usage extensions)" \
3461 -C "Processing of the Certificate handshake message failed" \
3462 -c "Ciphersuite is TLS-"
3463
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003464run_test "extKeyUsage cli: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003465 "$O_SRV -key data_files/server5.key \
3466 -cert data_files/server5.eku-cs.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003467 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003468 1 \
3469 -c "bad certificate (usage extensions)" \
3470 -c "Processing of the Certificate handshake message failed" \
3471 -C "Ciphersuite is TLS-"
3472
3473# Tests for extendedKeyUsage, part 3: server-side checking of client cert
3474
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003475run_test "extKeyUsage cli-auth: clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003476 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003477 "$O_CLI -key data_files/server5.key \
3478 -cert data_files/server5.eku-cli.crt" \
3479 0 \
3480 -S "bad certificate (usage extensions)" \
3481 -S "Processing of the Certificate handshake message failed"
3482
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003483run_test "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003484 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003485 "$O_CLI -key data_files/server5.key \
3486 -cert data_files/server5.eku-srv_cli.crt" \
3487 0 \
3488 -S "bad certificate (usage extensions)" \
3489 -S "Processing of the Certificate handshake message failed"
3490
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003491run_test "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003492 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003493 "$O_CLI -key data_files/server5.key \
3494 -cert data_files/server5.eku-cs_any.crt" \
3495 0 \
3496 -S "bad certificate (usage extensions)" \
3497 -S "Processing of the Certificate handshake message failed"
3498
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003499run_test "extKeyUsage cli-auth: codeSign -> fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003500 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003501 "$O_CLI -key data_files/server5.key \
3502 -cert data_files/server5.eku-cs.crt" \
3503 0 \
3504 -s "bad certificate (usage extensions)" \
3505 -S "Processing of the Certificate handshake message failed"
3506
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003507run_test "extKeyUsage cli-auth: codeSign -> fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003508 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003509 "$O_CLI -key data_files/server5.key \
3510 -cert data_files/server5.eku-cs.crt" \
3511 1 \
3512 -s "bad certificate (usage extensions)" \
3513 -s "Processing of the Certificate handshake message failed"
3514
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003515# Tests for DHM parameters loading
3516
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003517run_test "DHM parameters: reference" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003518 "$P_SRV" \
3519 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3520 debug_level=3" \
3521 0 \
3522 -c "value of 'DHM: P ' (2048 bits)" \
Hanno Becker13be9902017-09-27 17:17:30 +01003523 -c "value of 'DHM: G ' (2 bits)"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003524
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003525run_test "DHM parameters: other parameters" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003526 "$P_SRV dhm_file=data_files/dhparams.pem" \
3527 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3528 debug_level=3" \
3529 0 \
3530 -c "value of 'DHM: P ' (1024 bits)" \
3531 -c "value of 'DHM: G ' (2 bits)"
3532
Manuel Pégourié-Gonnard7a010aa2015-06-12 11:19:10 +02003533# Tests for DHM client-side size checking
3534
3535run_test "DHM size: server default, client default, OK" \
3536 "$P_SRV" \
3537 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3538 debug_level=1" \
3539 0 \
3540 -C "DHM prime too short:"
3541
3542run_test "DHM size: server default, client 2048, OK" \
3543 "$P_SRV" \
3544 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3545 debug_level=1 dhmlen=2048" \
3546 0 \
3547 -C "DHM prime too short:"
3548
3549run_test "DHM size: server 1024, client default, OK" \
3550 "$P_SRV dhm_file=data_files/dhparams.pem" \
3551 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3552 debug_level=1" \
3553 0 \
3554 -C "DHM prime too short:"
3555
3556run_test "DHM size: server 1000, client default, rejected" \
3557 "$P_SRV dhm_file=data_files/dh.1000.pem" \
3558 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3559 debug_level=1" \
3560 1 \
3561 -c "DHM prime too short:"
3562
3563run_test "DHM size: server default, client 2049, rejected" \
3564 "$P_SRV" \
3565 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3566 debug_level=1 dhmlen=2049" \
3567 1 \
3568 -c "DHM prime too short:"
3569
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003570# Tests for PSK callback
3571
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003572run_test "PSK callback: psk, no callback" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003573 "$P_SRV psk=abc123 psk_identity=foo" \
3574 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3575 psk_identity=foo psk=abc123" \
3576 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003577 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02003578 -S "SSL - Unknown identity received" \
3579 -S "SSL - Verification of the message MAC failed"
3580
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003581run_test "PSK callback: no psk, no callback" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02003582 "$P_SRV" \
3583 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3584 psk_identity=foo psk=abc123" \
3585 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003586 -s "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003587 -S "SSL - Unknown identity received" \
3588 -S "SSL - Verification of the message MAC failed"
3589
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003590run_test "PSK callback: callback overrides other settings" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003591 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
3592 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3593 psk_identity=foo psk=abc123" \
3594 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003595 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003596 -s "SSL - Unknown identity received" \
3597 -S "SSL - Verification of the message MAC failed"
3598
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003599run_test "PSK callback: first id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003600 "$P_SRV psk_list=abc,dead,def,beef" \
3601 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3602 psk_identity=abc psk=dead" \
3603 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003604 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003605 -S "SSL - Unknown identity received" \
3606 -S "SSL - Verification of the message MAC failed"
3607
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003608run_test "PSK callback: second id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003609 "$P_SRV psk_list=abc,dead,def,beef" \
3610 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3611 psk_identity=def psk=beef" \
3612 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003613 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003614 -S "SSL - Unknown identity received" \
3615 -S "SSL - Verification of the message MAC failed"
3616
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003617run_test "PSK callback: no match" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003618 "$P_SRV psk_list=abc,dead,def,beef" \
3619 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3620 psk_identity=ghi psk=beef" \
3621 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003622 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003623 -s "SSL - Unknown identity received" \
3624 -S "SSL - Verification of the message MAC failed"
3625
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003626run_test "PSK callback: wrong key" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003627 "$P_SRV psk_list=abc,dead,def,beef" \
3628 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3629 psk_identity=abc psk=beef" \
3630 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003631 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003632 -S "SSL - Unknown identity received" \
3633 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003634
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003635# Tests for EC J-PAKE
3636
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003637requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003638run_test "ECJPAKE: client not configured" \
3639 "$P_SRV debug_level=3" \
3640 "$P_CLI debug_level=3" \
3641 0 \
3642 -C "add ciphersuite: c0ff" \
3643 -C "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003644 -S "found ecjpake kkpp extension" \
3645 -S "skip ecjpake kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003646 -S "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003647 -S "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003648 -C "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003649 -S "None of the common ciphersuites is usable"
3650
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003651requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003652run_test "ECJPAKE: server not configured" \
3653 "$P_SRV debug_level=3" \
3654 "$P_CLI debug_level=3 ecjpake_pw=bla \
3655 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3656 1 \
3657 -c "add ciphersuite: c0ff" \
3658 -c "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003659 -s "found ecjpake kkpp extension" \
3660 -s "skip ecjpake kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003661 -s "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003662 -S "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003663 -C "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003664 -s "None of the common ciphersuites is usable"
3665
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003666requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003667run_test "ECJPAKE: working, TLS" \
3668 "$P_SRV debug_level=3 ecjpake_pw=bla" \
3669 "$P_CLI debug_level=3 ecjpake_pw=bla \
3670 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
Manuel Pégourié-Gonnard0f1660a2015-09-16 22:41:06 +02003671 0 \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003672 -c "add ciphersuite: c0ff" \
3673 -c "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003674 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003675 -s "found ecjpake kkpp extension" \
3676 -S "skip ecjpake kkpp extension" \
3677 -S "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003678 -s "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003679 -c "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003680 -S "None of the common ciphersuites is usable" \
3681 -S "SSL - Verification of the message MAC failed"
3682
Janos Follath74537a62016-09-02 13:45:28 +01003683server_needs_more_time 1
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003684requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003685run_test "ECJPAKE: password mismatch, TLS" \
3686 "$P_SRV debug_level=3 ecjpake_pw=bla" \
3687 "$P_CLI debug_level=3 ecjpake_pw=bad \
3688 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3689 1 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003690 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003691 -s "SSL - Verification of the message MAC failed"
3692
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003693requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003694run_test "ECJPAKE: working, DTLS" \
3695 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
3696 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
3697 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3698 0 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003699 -c "re-using cached ecjpake parameters" \
3700 -S "SSL - Verification of the message MAC failed"
3701
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003702requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003703run_test "ECJPAKE: working, DTLS, no cookie" \
3704 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla cookies=0" \
3705 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
3706 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3707 0 \
3708 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003709 -S "SSL - Verification of the message MAC failed"
3710
Janos Follath74537a62016-09-02 13:45:28 +01003711server_needs_more_time 1
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003712requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003713run_test "ECJPAKE: password mismatch, DTLS" \
3714 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
3715 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bad \
3716 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3717 1 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003718 -c "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003719 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003720
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +02003721# for tests with configs/config-thread.h
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003722requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +02003723run_test "ECJPAKE: working, DTLS, nolog" \
3724 "$P_SRV dtls=1 ecjpake_pw=bla" \
3725 "$P_CLI dtls=1 ecjpake_pw=bla \
3726 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3727 0
3728
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003729# Tests for ciphersuites per version
3730
Janos Follathe2681a42016-03-07 15:57:05 +00003731requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003732run_test "Per-version suites: SSL3" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003733 "$P_SRV min_version=ssl3 version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003734 "$P_CLI force_version=ssl3" \
3735 0 \
3736 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
3737
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003738run_test "Per-version suites: TLS 1.0" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003739 "$P_SRV arc4=1 version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +01003740 "$P_CLI force_version=tls1 arc4=1" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003741 0 \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003742 -c "Ciphersuite is TLS-RSA-WITH-AES-256-CBC-SHA"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003743
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003744run_test "Per-version suites: TLS 1.1" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003745 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003746 "$P_CLI force_version=tls1_1" \
3747 0 \
3748 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
3749
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003750run_test "Per-version suites: TLS 1.2" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003751 "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003752 "$P_CLI force_version=tls1_2" \
3753 0 \
3754 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
3755
Manuel Pégourié-Gonnard4cc8c632015-07-23 12:24:03 +02003756# Test for ClientHello without extensions
3757
Manuel Pégourié-Gonnardd55bc202015-08-04 16:22:30 +02003758requires_gnutls
Gilles Peskine5d2511c2017-05-12 13:16:40 +02003759run_test "ClientHello without extensions, SHA-1 allowed" \
Manuel Pégourié-Gonnard4cc8c632015-07-23 12:24:03 +02003760 "$P_SRV debug_level=3" \
3761 "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \
3762 0 \
3763 -s "dumping 'client hello extensions' (0 bytes)"
3764
Gilles Peskine5d2511c2017-05-12 13:16:40 +02003765requires_gnutls
3766run_test "ClientHello without extensions, SHA-1 forbidden in certificates on server" \
3767 "$P_SRV debug_level=3 key_file=data_files/server2.key crt_file=data_files/server2.crt allow_sha1=0" \
3768 "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \
3769 0 \
3770 -s "dumping 'client hello extensions' (0 bytes)"
3771
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003772# Tests for mbedtls_ssl_get_bytes_avail()
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003773
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003774run_test "mbedtls_ssl_get_bytes_avail: no extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003775 "$P_SRV" \
3776 "$P_CLI request_size=100" \
3777 0 \
3778 -s "Read from client: 100 bytes read$"
3779
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003780run_test "mbedtls_ssl_get_bytes_avail: extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003781 "$P_SRV" \
3782 "$P_CLI request_size=500" \
3783 0 \
3784 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003785
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003786# Tests for small packets
3787
Janos Follathe2681a42016-03-07 15:57:05 +00003788requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003789run_test "Small packet SSLv3 BlockCipher" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01003790 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003791 "$P_CLI request_size=1 force_version=ssl3 \
3792 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3793 0 \
3794 -s "Read from client: 1 bytes read"
3795
Janos Follathe2681a42016-03-07 15:57:05 +00003796requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003797run_test "Small packet SSLv3 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003798 "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003799 "$P_CLI request_size=1 force_version=ssl3 \
3800 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3801 0 \
3802 -s "Read from client: 1 bytes read"
3803
3804run_test "Small packet TLS 1.0 BlockCipher" \
3805 "$P_SRV" \
3806 "$P_CLI request_size=1 force_version=tls1 \
3807 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3808 0 \
3809 -s "Read from client: 1 bytes read"
3810
Hanno Becker8501f982017-11-10 08:59:04 +00003811run_test "Small packet TLS 1.0 BlockCipher, without EtM" \
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003812 "$P_SRV" \
3813 "$P_CLI request_size=1 force_version=tls1 etm=0 \
3814 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3815 0 \
3816 -s "Read from client: 1 bytes read"
3817
Hanno Becker32c55012017-11-10 08:42:54 +00003818requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker8501f982017-11-10 08:59:04 +00003819run_test "Small packet TLS 1.0 BlockCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003820 "$P_SRV trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003821 "$P_CLI request_size=1 force_version=tls1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003822 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003823 0 \
3824 -s "Read from client: 1 bytes read"
3825
Hanno Becker32c55012017-11-10 08:42:54 +00003826requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker8501f982017-11-10 08:59:04 +00003827run_test "Small packet TLS 1.0 BlockCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003828 "$P_SRV trunc_hmac=1" \
Hanno Becker8501f982017-11-10 08:59:04 +00003829 "$P_CLI request_size=1 force_version=tls1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003830 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
Hanno Becker8501f982017-11-10 08:59:04 +00003831 0 \
3832 -s "Read from client: 1 bytes read"
3833
3834run_test "Small packet TLS 1.0 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003835 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003836 "$P_CLI request_size=1 force_version=tls1 \
Hanno Becker8501f982017-11-10 08:59:04 +00003837 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3838 0 \
3839 -s "Read from client: 1 bytes read"
3840
3841run_test "Small packet TLS 1.0 StreamCipher, without EtM" \
3842 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3843 "$P_CLI request_size=1 force_version=tls1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003844 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA etm=0" \
Hanno Becker8501f982017-11-10 08:59:04 +00003845 0 \
3846 -s "Read from client: 1 bytes read"
3847
3848requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
3849run_test "Small packet TLS 1.0 StreamCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003850 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003851 "$P_CLI request_size=1 force_version=tls1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003852 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003853 0 \
3854 -s "Read from client: 1 bytes read"
3855
Hanno Becker8501f982017-11-10 08:59:04 +00003856requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
3857run_test "Small packet TLS 1.0 StreamCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003858 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
3859 "$P_CLI request_size=1 force_version=tls1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3860 trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003861 0 \
3862 -s "Read from client: 1 bytes read"
3863
3864run_test "Small packet TLS 1.1 BlockCipher" \
3865 "$P_SRV" \
3866 "$P_CLI request_size=1 force_version=tls1_1 \
3867 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3868 0 \
3869 -s "Read from client: 1 bytes read"
3870
Hanno Becker8501f982017-11-10 08:59:04 +00003871run_test "Small packet TLS 1.1 BlockCipher, without EtM" \
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003872 "$P_SRV" \
Hanno Becker8501f982017-11-10 08:59:04 +00003873 "$P_CLI request_size=1 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003874 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
Hanno Becker8501f982017-11-10 08:59:04 +00003875 0 \
3876 -s "Read from client: 1 bytes read"
3877
3878requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
3879run_test "Small packet TLS 1.1 BlockCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003880 "$P_SRV trunc_hmac=1" \
Hanno Becker8501f982017-11-10 08:59:04 +00003881 "$P_CLI request_size=1 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003882 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Hanno Becker8501f982017-11-10 08:59:04 +00003883 0 \
3884 -s "Read from client: 1 bytes read"
3885
3886requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
3887run_test "Small packet TLS 1.1 BlockCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003888 "$P_SRV trunc_hmac=1" \
Hanno Becker8501f982017-11-10 08:59:04 +00003889 "$P_CLI request_size=1 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003890 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003891 0 \
3892 -s "Read from client: 1 bytes read"
3893
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003894run_test "Small packet TLS 1.1 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003895 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003896 "$P_CLI request_size=1 force_version=tls1_1 \
3897 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3898 0 \
3899 -s "Read from client: 1 bytes read"
3900
Hanno Becker8501f982017-11-10 08:59:04 +00003901run_test "Small packet TLS 1.1 StreamCipher, without EtM" \
3902 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003903 "$P_CLI request_size=1 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003904 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA etm=0" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003905 0 \
3906 -s "Read from client: 1 bytes read"
3907
Hanno Becker8501f982017-11-10 08:59:04 +00003908requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
3909run_test "Small packet TLS 1.1 StreamCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003910 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003911 "$P_CLI request_size=1 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003912 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003913 0 \
3914 -s "Read from client: 1 bytes read"
3915
Hanno Becker32c55012017-11-10 08:42:54 +00003916requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker8501f982017-11-10 08:59:04 +00003917run_test "Small packet TLS 1.1 StreamCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003918 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003919 "$P_CLI request_size=1 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003920 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003921 0 \
3922 -s "Read from client: 1 bytes read"
3923
3924run_test "Small packet TLS 1.2 BlockCipher" \
3925 "$P_SRV" \
3926 "$P_CLI request_size=1 force_version=tls1_2 \
3927 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3928 0 \
3929 -s "Read from client: 1 bytes read"
3930
Hanno Becker8501f982017-11-10 08:59:04 +00003931run_test "Small packet TLS 1.2 BlockCipher, without EtM" \
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003932 "$P_SRV" \
Hanno Becker8501f982017-11-10 08:59:04 +00003933 "$P_CLI request_size=1 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003934 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003935 0 \
3936 -s "Read from client: 1 bytes read"
3937
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003938run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
3939 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003940 "$P_CLI request_size=1 force_version=tls1_2 \
3941 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003942 0 \
3943 -s "Read from client: 1 bytes read"
3944
Hanno Becker32c55012017-11-10 08:42:54 +00003945requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker8501f982017-11-10 08:59:04 +00003946run_test "Small packet TLS 1.2 BlockCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003947 "$P_SRV trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003948 "$P_CLI request_size=1 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003949 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003950 0 \
3951 -s "Read from client: 1 bytes read"
3952
Hanno Becker8501f982017-11-10 08:59:04 +00003953requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
3954run_test "Small packet TLS 1.2 BlockCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003955 "$P_SRV trunc_hmac=1" \
Hanno Becker8501f982017-11-10 08:59:04 +00003956 "$P_CLI request_size=1 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003957 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003958 0 \
3959 -s "Read from client: 1 bytes read"
3960
3961run_test "Small packet TLS 1.2 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003962 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003963 "$P_CLI request_size=1 force_version=tls1_2 \
3964 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3965 0 \
3966 -s "Read from client: 1 bytes read"
3967
Hanno Becker8501f982017-11-10 08:59:04 +00003968run_test "Small packet TLS 1.2 StreamCipher, without EtM" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003969 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003970 "$P_CLI request_size=1 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003971 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA etm=0" \
Hanno Becker8501f982017-11-10 08:59:04 +00003972 0 \
3973 -s "Read from client: 1 bytes read"
3974
Hanno Becker32c55012017-11-10 08:42:54 +00003975requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker8501f982017-11-10 08:59:04 +00003976run_test "Small packet TLS 1.2 StreamCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003977 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003978 "$P_CLI request_size=1 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003979 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003980 0 \
3981 -s "Read from client: 1 bytes read"
3982
Hanno Becker8501f982017-11-10 08:59:04 +00003983requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
3984run_test "Small packet TLS 1.2 StreamCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00003985 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Hanno Becker8501f982017-11-10 08:59:04 +00003986 "$P_CLI request_size=1 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00003987 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003988 0 \
3989 -s "Read from client: 1 bytes read"
3990
3991run_test "Small packet TLS 1.2 AEAD" \
3992 "$P_SRV" \
3993 "$P_CLI request_size=1 force_version=tls1_2 \
3994 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
3995 0 \
3996 -s "Read from client: 1 bytes read"
3997
3998run_test "Small packet TLS 1.2 AEAD shorter tag" \
3999 "$P_SRV" \
4000 "$P_CLI request_size=1 force_version=tls1_2 \
4001 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
4002 0 \
4003 -s "Read from client: 1 bytes read"
4004
Hanno Beckere2148042017-11-10 08:59:18 +00004005# Tests for small packets in DTLS
4006
4007requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4008run_test "Small packet DTLS 1.0" \
4009 "$P_SRV dtls=1 force_version=dtls1" \
4010 "$P_CLI dtls=1 request_size=1 \
4011 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4012 0 \
4013 -s "Read from client: 1 bytes read"
4014
4015requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4016run_test "Small packet DTLS 1.0, without EtM" \
4017 "$P_SRV dtls=1 force_version=dtls1 etm=0" \
4018 "$P_CLI dtls=1 request_size=1 \
4019 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4020 0 \
4021 -s "Read from client: 1 bytes read"
4022
4023requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4024requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4025run_test "Small packet DTLS 1.0, truncated hmac" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004026 "$P_SRV dtls=1 force_version=dtls1 trunc_hmac=1" \
4027 "$P_CLI dtls=1 request_size=1 trunc_hmac=1 \
Hanno Beckere2148042017-11-10 08:59:18 +00004028 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4029 0 \
4030 -s "Read from client: 1 bytes read"
4031
4032requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4033requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4034run_test "Small packet DTLS 1.0, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004035 "$P_SRV dtls=1 force_version=dtls1 trunc_hmac=1 etm=0" \
Hanno Beckere2148042017-11-10 08:59:18 +00004036 "$P_CLI dtls=1 request_size=1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004037 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1"\
Hanno Beckere2148042017-11-10 08:59:18 +00004038 0 \
4039 -s "Read from client: 1 bytes read"
4040
4041requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4042run_test "Small packet DTLS 1.2" \
4043 "$P_SRV dtls=1 force_version=dtls1_2" \
4044 "$P_CLI dtls=1 request_size=1 \
4045 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4046 0 \
4047 -s "Read from client: 1 bytes read"
4048
4049requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4050run_test "Small packet DTLS 1.2, without EtM" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004051 "$P_SRV dtls=1 force_version=dtls1_2 etm=0" \
Hanno Beckere2148042017-11-10 08:59:18 +00004052 "$P_CLI dtls=1 request_size=1 \
4053 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4054 0 \
4055 -s "Read from client: 1 bytes read"
4056
4057requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4058requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4059run_test "Small packet DTLS 1.2, truncated hmac" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004060 "$P_SRV dtls=1 force_version=dtls1_2 trunc_hmac=1" \
Hanno Beckere2148042017-11-10 08:59:18 +00004061 "$P_CLI dtls=1 request_size=1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004062 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Hanno Beckere2148042017-11-10 08:59:18 +00004063 0 \
4064 -s "Read from client: 1 bytes read"
4065
4066requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4067requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4068run_test "Small packet DTLS 1.2, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004069 "$P_SRV dtls=1 force_version=dtls1_2 trunc_hmac=1 etm=0" \
Hanno Beckere2148042017-11-10 08:59:18 +00004070 "$P_CLI dtls=1 request_size=1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004071 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1"\
Hanno Beckere2148042017-11-10 08:59:18 +00004072 0 \
4073 -s "Read from client: 1 bytes read"
4074
Janos Follath00efff72016-05-06 13:48:23 +01004075# A test for extensions in SSLv3
4076
4077requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
4078run_test "SSLv3 with extensions, server side" \
4079 "$P_SRV min_version=ssl3 debug_level=3" \
4080 "$P_CLI force_version=ssl3 tickets=1 max_frag_len=4096 alpn=abc,1234" \
4081 0 \
4082 -S "dumping 'client hello extensions'" \
4083 -S "server hello, total extension length:"
4084
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004085# Test for large packets
4086
Angus Grattonc4dd0732018-04-11 16:28:39 +10004087# How many fragments do we expect to write $1 bytes?
4088fragments_for_write() {
4089 echo "$(( ( $1 + $MAX_OUT_LEN - 1 ) / $MAX_OUT_LEN ))"
4090}
4091
Janos Follathe2681a42016-03-07 15:57:05 +00004092requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004093run_test "Large packet SSLv3 BlockCipher" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01004094 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01004095 "$P_CLI request_size=16384 force_version=ssl3 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004096 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4097 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004098 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4099 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004100
Janos Follathe2681a42016-03-07 15:57:05 +00004101requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004102run_test "Large packet SSLv3 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01004103 "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004104 "$P_CLI request_size=16384 force_version=ssl3 \
4105 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
4106 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004107 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4108 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004109
4110run_test "Large packet TLS 1.0 BlockCipher" \
4111 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01004112 "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004113 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4114 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004115 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4116 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004117
Hanno Becker278fc7a2017-11-10 09:16:28 +00004118run_test "Large packet TLS 1.0 BlockCipher, without EtM" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004119 "$P_SRV" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004120 "$P_CLI request_size=16384 force_version=tls1 etm=0 recsplit=0 \
4121 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4122 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004123 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Hanno Becker278fc7a2017-11-10 09:16:28 +00004124
Hanno Becker32c55012017-11-10 08:42:54 +00004125requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker278fc7a2017-11-10 09:16:28 +00004126run_test "Large packet TLS 1.0 BlockCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004127 "$P_SRV trunc_hmac=1" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01004128 "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004129 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004130 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004131 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4132 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004133
Hanno Becker32c55012017-11-10 08:42:54 +00004134requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker278fc7a2017-11-10 09:16:28 +00004135run_test "Large packet TLS 1.0 BlockCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004136 "$P_SRV trunc_hmac=1" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004137 "$P_CLI request_size=16384 force_version=tls1 etm=0 recsplit=0 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004138 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004139 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004140 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Hanno Becker278fc7a2017-11-10 09:16:28 +00004141
4142run_test "Large packet TLS 1.0 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01004143 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004144 "$P_CLI request_size=16384 force_version=tls1 \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004145 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
4146 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004147 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Hanno Becker278fc7a2017-11-10 09:16:28 +00004148
4149run_test "Large packet TLS 1.0 StreamCipher, without EtM" \
4150 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
4151 "$P_CLI request_size=16384 force_version=tls1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004152 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA etm=0" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004153 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004154 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Hanno Becker278fc7a2017-11-10 09:16:28 +00004155
4156requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4157run_test "Large packet TLS 1.0 StreamCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004158 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004159 "$P_CLI request_size=16384 force_version=tls1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004160 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004161 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004162 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004163
Hanno Becker278fc7a2017-11-10 09:16:28 +00004164requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4165run_test "Large packet TLS 1.0 StreamCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004166 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004167 "$P_CLI request_size=16384 force_version=tls1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004168 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004169 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004170 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4171 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004172
4173run_test "Large packet TLS 1.1 BlockCipher" \
4174 "$P_SRV" \
4175 "$P_CLI request_size=16384 force_version=tls1_1 \
4176 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4177 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004178 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4179 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004180
Hanno Becker278fc7a2017-11-10 09:16:28 +00004181run_test "Large packet TLS 1.1 BlockCipher, without EtM" \
4182 "$P_SRV" \
4183 "$P_CLI request_size=16384 force_version=tls1_1 etm=0 \
4184 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004185 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004186 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004187
Hanno Becker32c55012017-11-10 08:42:54 +00004188requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker278fc7a2017-11-10 09:16:28 +00004189run_test "Large packet TLS 1.1 BlockCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004190 "$P_SRV trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004191 "$P_CLI request_size=16384 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004192 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004193 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004194 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004195
Hanno Becker32c55012017-11-10 08:42:54 +00004196requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker278fc7a2017-11-10 09:16:28 +00004197run_test "Large packet TLS 1.1 BlockCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004198 "$P_SRV trunc_hmac=1" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004199 "$P_CLI request_size=16384 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004200 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004201 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004202 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Hanno Becker278fc7a2017-11-10 09:16:28 +00004203
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004204run_test "Large packet TLS 1.1 StreamCipher" \
4205 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
4206 "$P_CLI request_size=16384 force_version=tls1_1 \
4207 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
4208 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004209 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4210 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004211
Hanno Becker278fc7a2017-11-10 09:16:28 +00004212run_test "Large packet TLS 1.1 StreamCipher, without EtM" \
4213 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004214 "$P_CLI request_size=16384 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004215 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA etm=0" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004216 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004217 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4218 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004219
Hanno Becker278fc7a2017-11-10 09:16:28 +00004220requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4221run_test "Large packet TLS 1.1 StreamCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004222 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004223 "$P_CLI request_size=16384 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004224 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004225 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004226 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004227
Hanno Becker278fc7a2017-11-10 09:16:28 +00004228requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4229run_test "Large packet TLS 1.1 StreamCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004230 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004231 "$P_CLI request_size=16384 force_version=tls1_1 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004232 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004233 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004234 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4235 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004236
4237run_test "Large packet TLS 1.2 BlockCipher" \
4238 "$P_SRV" \
4239 "$P_CLI request_size=16384 force_version=tls1_2 \
4240 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4241 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004242 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4243 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004244
Hanno Becker278fc7a2017-11-10 09:16:28 +00004245run_test "Large packet TLS 1.2 BlockCipher, without EtM" \
4246 "$P_SRV" \
4247 "$P_CLI request_size=16384 force_version=tls1_2 etm=0 \
4248 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
4249 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004250 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Hanno Becker278fc7a2017-11-10 09:16:28 +00004251
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004252run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
4253 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01004254 "$P_CLI request_size=16384 force_version=tls1_2 \
4255 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004256 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004257 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4258 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004259
Hanno Becker32c55012017-11-10 08:42:54 +00004260requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker278fc7a2017-11-10 09:16:28 +00004261run_test "Large packet TLS 1.2 BlockCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004262 "$P_SRV trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004263 "$P_CLI request_size=16384 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004264 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004265 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004266 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004267
Hanno Becker278fc7a2017-11-10 09:16:28 +00004268requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4269run_test "Large packet TLS 1.2 BlockCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004270 "$P_SRV trunc_hmac=1" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004271 "$P_CLI request_size=16384 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004272 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004273 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004274 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4275 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004276
4277run_test "Large packet TLS 1.2 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01004278 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004279 "$P_CLI request_size=16384 force_version=tls1_2 \
4280 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
4281 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004282 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4283 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004284
Hanno Becker278fc7a2017-11-10 09:16:28 +00004285run_test "Large packet TLS 1.2 StreamCipher, without EtM" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01004286 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004287 "$P_CLI request_size=16384 force_version=tls1_2 \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004288 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA etm=0" \
4289 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004290 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Hanno Becker278fc7a2017-11-10 09:16:28 +00004291
Hanno Becker32c55012017-11-10 08:42:54 +00004292requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
Hanno Becker278fc7a2017-11-10 09:16:28 +00004293run_test "Large packet TLS 1.2 StreamCipher, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004294 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004295 "$P_CLI request_size=16384 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004296 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004297 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004298 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004299
Hanno Becker278fc7a2017-11-10 09:16:28 +00004300requires_config_enabled MBEDTLS_SSL_TRUNCATED_HMAC
4301run_test "Large packet TLS 1.2 StreamCipher, without EtM, truncated MAC" \
Hanno Becker909f9a32017-11-21 17:10:12 +00004302 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1" \
Hanno Becker278fc7a2017-11-10 09:16:28 +00004303 "$P_CLI request_size=16384 force_version=tls1_2 \
Hanno Becker909f9a32017-11-21 17:10:12 +00004304 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA trunc_hmac=1 etm=0" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004305 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004306 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4307 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004308
4309run_test "Large packet TLS 1.2 AEAD" \
4310 "$P_SRV" \
4311 "$P_CLI request_size=16384 force_version=tls1_2 \
4312 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
4313 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004314 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4315 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004316
4317run_test "Large packet TLS 1.2 AEAD shorter tag" \
4318 "$P_SRV" \
4319 "$P_CLI request_size=16384 force_version=tls1_2 \
4320 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
4321 0 \
Angus Grattonc4dd0732018-04-11 16:28:39 +10004322 -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
4323 -s "Read from client: $MAX_CONTENT_LEN bytes read"
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02004324
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004325# Tests of asynchronous private key support in SSL
4326
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004327requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004328run_test "SSL async private: sign, delay=0" \
4329 "$P_SRV \
4330 async_operations=s async_private_delay1=0 async_private_delay2=0" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004331 "$P_CLI" \
4332 0 \
4333 -s "Async sign callback: using key slot " \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004334 -s "Async resume (slot [0-9]): sign done, status=0"
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004335
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004336requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004337run_test "SSL async private: sign, delay=1" \
4338 "$P_SRV \
4339 async_operations=s async_private_delay1=1 async_private_delay2=1" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004340 "$P_CLI" \
4341 0 \
4342 -s "Async sign callback: using key slot " \
4343 -s "Async resume (slot [0-9]): call 0 more times." \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004344 -s "Async resume (slot [0-9]): sign done, status=0"
4345
Gilles Peskine12d0cc12018-04-26 15:06:56 +02004346requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
4347run_test "SSL async private: sign, delay=2" \
4348 "$P_SRV \
4349 async_operations=s async_private_delay1=2 async_private_delay2=2" \
4350 "$P_CLI" \
4351 0 \
4352 -s "Async sign callback: using key slot " \
4353 -U "Async sign callback: using key slot " \
4354 -s "Async resume (slot [0-9]): call 1 more times." \
4355 -s "Async resume (slot [0-9]): call 0 more times." \
4356 -s "Async resume (slot [0-9]): sign done, status=0"
4357
Gilles Peskined3268832018-04-26 06:23:59 +02004358# Test that the async callback correctly signs the 36-byte hash of TLS 1.0/1.1
4359# with RSA PKCS#1v1.5 as used in TLS 1.0/1.1.
4360requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
4361requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
4362run_test "SSL async private: sign, RSA, TLS 1.1" \
4363 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt \
4364 async_operations=s async_private_delay1=0 async_private_delay2=0" \
4365 "$P_CLI force_version=tls1_1" \
4366 0 \
4367 -s "Async sign callback: using key slot " \
4368 -s "Async resume (slot [0-9]): sign done, status=0"
4369
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004370requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine807d74a2018-04-30 10:30:49 +02004371run_test "SSL async private: sign, SNI" \
4372 "$P_SRV debug_level=3 \
4373 async_operations=s async_private_delay1=0 async_private_delay2=0 \
4374 crt_file=data_files/server5.crt key_file=data_files/server5.key \
4375 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
4376 "$P_CLI server_name=polarssl.example" \
4377 0 \
4378 -s "Async sign callback: using key slot " \
4379 -s "Async resume (slot [0-9]): sign done, status=0" \
4380 -s "parse ServerName extension" \
4381 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
4382 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
4383
4384requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004385run_test "SSL async private: decrypt, delay=0" \
4386 "$P_SRV \
4387 async_operations=d async_private_delay1=0 async_private_delay2=0" \
4388 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4389 0 \
4390 -s "Async decrypt callback: using key slot " \
4391 -s "Async resume (slot [0-9]): decrypt done, status=0"
4392
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004393requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004394run_test "SSL async private: decrypt, delay=1" \
4395 "$P_SRV \
4396 async_operations=d async_private_delay1=1 async_private_delay2=1" \
4397 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4398 0 \
4399 -s "Async decrypt callback: using key slot " \
4400 -s "Async resume (slot [0-9]): call 0 more times." \
4401 -s "Async resume (slot [0-9]): decrypt done, status=0"
4402
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004403requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004404run_test "SSL async private: decrypt RSA-PSK, delay=0" \
4405 "$P_SRV psk=abc123 \
4406 async_operations=d async_private_delay1=0 async_private_delay2=0" \
4407 "$P_CLI psk=abc123 \
4408 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
4409 0 \
4410 -s "Async decrypt callback: using key slot " \
4411 -s "Async resume (slot [0-9]): decrypt done, status=0"
4412
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004413requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004414run_test "SSL async private: decrypt RSA-PSK, delay=1" \
4415 "$P_SRV psk=abc123 \
4416 async_operations=d async_private_delay1=1 async_private_delay2=1" \
4417 "$P_CLI psk=abc123 \
4418 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
4419 0 \
4420 -s "Async decrypt callback: using key slot " \
4421 -s "Async resume (slot [0-9]): call 0 more times." \
4422 -s "Async resume (slot [0-9]): decrypt done, status=0"
4423
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004424requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004425run_test "SSL async private: sign callback not present" \
4426 "$P_SRV \
4427 async_operations=d async_private_delay1=1 async_private_delay2=1" \
4428 "$P_CLI; [ \$? -eq 1 ] &&
4429 $P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4430 0 \
4431 -S "Async sign callback" \
4432 -s "! mbedtls_ssl_handshake returned" \
4433 -s "The own private key or pre-shared key is not set, but needed" \
4434 -s "Async resume (slot [0-9]): decrypt done, status=0" \
4435 -s "Successful connection"
4436
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004437requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004438run_test "SSL async private: decrypt callback not present" \
4439 "$P_SRV debug_level=1 \
4440 async_operations=s async_private_delay1=1 async_private_delay2=1" \
4441 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA;
4442 [ \$? -eq 1 ] && $P_CLI" \
4443 0 \
4444 -S "Async decrypt callback" \
4445 -s "! mbedtls_ssl_handshake returned" \
4446 -s "got no RSA private key" \
4447 -s "Async resume (slot [0-9]): sign done, status=0" \
4448 -s "Successful connection"
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004449
4450# key1: ECDSA, key2: RSA; use key1 from slot 0
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004451requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004452run_test "SSL async private: slot 0 used with key1" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004453 "$P_SRV \
4454 async_operations=s async_private_delay1=1 \
4455 key_file=data_files/server5.key crt_file=data_files/server5.crt \
4456 key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004457 "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
4458 0 \
4459 -s "Async sign callback: using key slot 0," \
4460 -s "Async resume (slot 0): call 0 more times." \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004461 -s "Async resume (slot 0): sign done, status=0"
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004462
4463# key1: ECDSA, key2: RSA; use key2 from slot 0
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004464requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004465run_test "SSL async private: slot 0 used with key2" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004466 "$P_SRV \
4467 async_operations=s async_private_delay2=1 \
4468 key_file=data_files/server5.key crt_file=data_files/server5.crt \
4469 key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004470 "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
4471 0 \
4472 -s "Async sign callback: using key slot 0," \
4473 -s "Async resume (slot 0): call 0 more times." \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004474 -s "Async resume (slot 0): sign done, status=0"
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004475
4476# key1: ECDSA, key2: RSA; use key2 from slot 1
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004477requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinead28bf02018-04-26 00:19:16 +02004478run_test "SSL async private: slot 1 used with key2" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004479 "$P_SRV \
Gilles Peskine168dae82018-04-25 23:35:42 +02004480 async_operations=s async_private_delay1=1 async_private_delay2=1 \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004481 key_file=data_files/server5.key crt_file=data_files/server5.crt \
4482 key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004483 "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
4484 0 \
4485 -s "Async sign callback: using key slot 1," \
4486 -s "Async resume (slot 1): call 0 more times." \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004487 -s "Async resume (slot 1): sign done, status=0"
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004488
4489# key1: ECDSA, key2: RSA; use key2 directly
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004490requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004491run_test "SSL async private: fall back to transparent key" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004492 "$P_SRV \
4493 async_operations=s async_private_delay1=1 \
4494 key_file=data_files/server5.key crt_file=data_files/server5.crt \
4495 key_file2=data_files/server2.key crt_file2=data_files/server2.crt " \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004496 "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
4497 0 \
4498 -s "Async sign callback: no key matches this certificate."
4499
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004500requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine725f1cb2018-06-12 15:06:40 +02004501run_test "SSL async private: sign, error in start" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004502 "$P_SRV \
4503 async_operations=s async_private_delay1=1 async_private_delay2=1 \
4504 async_private_error=1" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004505 "$P_CLI" \
4506 1 \
4507 -s "Async sign callback: injected error" \
4508 -S "Async resume" \
Gilles Peskine37289cd2018-04-27 11:50:14 +02004509 -S "Async cancel" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004510 -s "! mbedtls_ssl_handshake returned"
4511
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004512requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine725f1cb2018-06-12 15:06:40 +02004513run_test "SSL async private: sign, cancel after start" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004514 "$P_SRV \
4515 async_operations=s async_private_delay1=1 async_private_delay2=1 \
4516 async_private_error=2" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004517 "$P_CLI" \
4518 1 \
4519 -s "Async sign callback: using key slot " \
4520 -S "Async resume" \
4521 -s "Async cancel"
4522
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004523requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine725f1cb2018-06-12 15:06:40 +02004524run_test "SSL async private: sign, error in resume" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004525 "$P_SRV \
4526 async_operations=s async_private_delay1=1 async_private_delay2=1 \
4527 async_private_error=3" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004528 "$P_CLI" \
4529 1 \
4530 -s "Async sign callback: using key slot " \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004531 -s "Async resume callback: sign done but injected error" \
Gilles Peskine37289cd2018-04-27 11:50:14 +02004532 -S "Async cancel" \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004533 -s "! mbedtls_ssl_handshake returned"
4534
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004535requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine725f1cb2018-06-12 15:06:40 +02004536run_test "SSL async private: decrypt, error in start" \
4537 "$P_SRV \
4538 async_operations=d async_private_delay1=1 async_private_delay2=1 \
4539 async_private_error=1" \
4540 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4541 1 \
4542 -s "Async decrypt callback: injected error" \
4543 -S "Async resume" \
4544 -S "Async cancel" \
4545 -s "! mbedtls_ssl_handshake returned"
4546
4547requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
4548run_test "SSL async private: decrypt, cancel after start" \
4549 "$P_SRV \
4550 async_operations=d async_private_delay1=1 async_private_delay2=1 \
4551 async_private_error=2" \
4552 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4553 1 \
4554 -s "Async decrypt callback: using key slot " \
4555 -S "Async resume" \
4556 -s "Async cancel"
4557
4558requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
4559run_test "SSL async private: decrypt, error in resume" \
4560 "$P_SRV \
4561 async_operations=d async_private_delay1=1 async_private_delay2=1 \
4562 async_private_error=3" \
4563 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4564 1 \
4565 -s "Async decrypt callback: using key slot " \
4566 -s "Async resume callback: decrypt done but injected error" \
4567 -S "Async cancel" \
4568 -s "! mbedtls_ssl_handshake returned"
4569
4570requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004571run_test "SSL async private: cancel after start then operate correctly" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004572 "$P_SRV \
4573 async_operations=s async_private_delay1=1 async_private_delay2=1 \
4574 async_private_error=-2" \
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004575 "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
4576 0 \
4577 -s "Async cancel" \
4578 -s "! mbedtls_ssl_handshake returned" \
4579 -s "Async resume" \
4580 -s "Successful connection"
4581
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004582requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004583run_test "SSL async private: error in resume then operate correctly" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004584 "$P_SRV \
4585 async_operations=s async_private_delay1=1 async_private_delay2=1 \
4586 async_private_error=-3" \
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004587 "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
4588 0 \
4589 -s "! mbedtls_ssl_handshake returned" \
4590 -s "Async resume" \
4591 -s "Successful connection"
4592
4593# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004594requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004595run_test "SSL async private: cancel after start then fall back to transparent key" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004596 "$P_SRV \
4597 async_operations=s async_private_delay1=1 async_private_error=-2 \
4598 key_file=data_files/server5.key crt_file=data_files/server5.crt \
4599 key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004600 "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
4601 [ \$? -eq 1 ] &&
4602 $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
4603 0 \
Gilles Peskinededa75a2018-04-30 10:02:45 +02004604 -s "Async sign callback: using key slot 0" \
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004605 -S "Async resume" \
4606 -s "Async cancel" \
4607 -s "! mbedtls_ssl_handshake returned" \
4608 -s "Async sign callback: no key matches this certificate." \
4609 -s "Successful connection"
4610
4611# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004612requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine725f1cb2018-06-12 15:06:40 +02004613run_test "SSL async private: sign, error in resume then fall back to transparent key" \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004614 "$P_SRV \
4615 async_operations=s async_private_delay1=1 async_private_error=-3 \
4616 key_file=data_files/server5.key crt_file=data_files/server5.crt \
4617 key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
Gilles Peskine60ee4ca2018-01-08 11:28:05 +01004618 "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
4619 [ \$? -eq 1 ] &&
4620 $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
4621 0 \
4622 -s "Async resume" \
4623 -s "! mbedtls_ssl_handshake returned" \
4624 -s "Async sign callback: no key matches this certificate." \
4625 -s "Successful connection"
4626
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004627requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004628requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004629run_test "SSL async private: renegotiation: client-initiated; sign" \
4630 "$P_SRV \
4631 async_operations=s async_private_delay1=1 async_private_delay2=1 \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004632 exchanges=2 renegotiation=1" \
4633 "$P_CLI exchanges=2 renegotiation=1 renegotiate=1" \
4634 0 \
4635 -s "Async sign callback: using key slot " \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004636 -s "Async resume (slot [0-9]): sign done, status=0"
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004637
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004638requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004639requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004640run_test "SSL async private: renegotiation: server-initiated; sign" \
4641 "$P_SRV \
4642 async_operations=s async_private_delay1=1 async_private_delay2=1 \
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004643 exchanges=2 renegotiation=1 renegotiate=1" \
4644 "$P_CLI exchanges=2 renegotiation=1" \
4645 0 \
4646 -s "Async sign callback: using key slot " \
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004647 -s "Async resume (slot [0-9]): sign done, status=0"
4648
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004649requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004650requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4651run_test "SSL async private: renegotiation: client-initiated; decrypt" \
4652 "$P_SRV \
4653 async_operations=d async_private_delay1=1 async_private_delay2=1 \
4654 exchanges=2 renegotiation=1" \
4655 "$P_CLI exchanges=2 renegotiation=1 renegotiate=1 \
4656 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4657 0 \
4658 -s "Async decrypt callback: using key slot " \
4659 -s "Async resume (slot [0-9]): decrypt done, status=0"
4660
Gilles Peskineb74a1c72018-04-24 13:09:22 +02004661requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
Gilles Peskinefcca9d82018-01-12 13:47:48 +01004662requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4663run_test "SSL async private: renegotiation: server-initiated; decrypt" \
4664 "$P_SRV \
4665 async_operations=d async_private_delay1=1 async_private_delay2=1 \
4666 exchanges=2 renegotiation=1 renegotiate=1" \
4667 "$P_CLI exchanges=2 renegotiation=1 \
4668 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
4669 0 \
4670 -s "Async decrypt callback: using key slot " \
4671 -s "Async resume (slot [0-9]): decrypt done, status=0"
Gilles Peskine3665f1d2018-01-05 21:22:12 +01004672
Ron Eldor58093c82018-06-28 13:22:05 +03004673# Tests for ECC extensions (rfc 4492)
4674
Ron Eldor643df7c2018-06-28 16:17:00 +03004675requires_config_enabled MBEDTLS_AES_C
4676requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
4677requires_config_enabled MBEDTLS_SHA256_C
4678requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
Ron Eldor58093c82018-06-28 13:22:05 +03004679run_test "Force a non ECC ciphersuite in the client side" \
4680 "$P_SRV debug_level=3" \
Ron Eldor643df7c2018-06-28 16:17:00 +03004681 "$P_CLI debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
Ron Eldor58093c82018-06-28 13:22:05 +03004682 0 \
4683 -C "client hello, adding supported_elliptic_curves extension" \
4684 -C "client hello, adding supported_point_formats extension" \
4685 -S "found supported elliptic curves extension" \
4686 -S "found supported point formats extension"
4687
Ron Eldor643df7c2018-06-28 16:17:00 +03004688requires_config_enabled MBEDTLS_AES_C
4689requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
4690requires_config_enabled MBEDTLS_SHA256_C
4691requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
Ron Eldor58093c82018-06-28 13:22:05 +03004692run_test "Force a non ECC ciphersuite in the server side" \
Ron Eldor643df7c2018-06-28 16:17:00 +03004693 "$P_SRV debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
Ron Eldor58093c82018-06-28 13:22:05 +03004694 "$P_CLI debug_level=3" \
4695 0 \
4696 -C "found supported_point_formats extension" \
4697 -S "server hello, supported_point_formats extension"
4698
Ron Eldor643df7c2018-06-28 16:17:00 +03004699requires_config_enabled MBEDTLS_AES_C
4700requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
4701requires_config_enabled MBEDTLS_SHA256_C
4702requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Ron Eldor58093c82018-06-28 13:22:05 +03004703run_test "Force an ECC ciphersuite in the client side" \
4704 "$P_SRV debug_level=3" \
4705 "$P_CLI debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
4706 0 \
4707 -c "client hello, adding supported_elliptic_curves extension" \
4708 -c "client hello, adding supported_point_formats extension" \
4709 -s "found supported elliptic curves extension" \
4710 -s "found supported point formats extension"
4711
Ron Eldor643df7c2018-06-28 16:17:00 +03004712requires_config_enabled MBEDTLS_AES_C
4713requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
4714requires_config_enabled MBEDTLS_SHA256_C
4715requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Ron Eldor58093c82018-06-28 13:22:05 +03004716run_test "Force an ECC ciphersuite in the server side" \
4717 "$P_SRV debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
4718 "$P_CLI debug_level=3" \
4719 0 \
4720 -c "found supported_point_formats extension" \
4721 -s "server hello, supported_point_formats extension"
4722
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02004723# Tests for DTLS HelloVerifyRequest
4724
4725run_test "DTLS cookie: enabled" \
4726 "$P_SRV dtls=1 debug_level=2" \
4727 "$P_CLI dtls=1 debug_level=2" \
4728 0 \
4729 -s "cookie verification failed" \
4730 -s "cookie verification passed" \
4731 -S "cookie verification skipped" \
4732 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02004733 -s "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02004734 -S "SSL - The requested feature is not available"
4735
4736run_test "DTLS cookie: disabled" \
4737 "$P_SRV dtls=1 debug_level=2 cookies=0" \
4738 "$P_CLI dtls=1 debug_level=2" \
4739 0 \
4740 -S "cookie verification failed" \
4741 -S "cookie verification passed" \
4742 -s "cookie verification skipped" \
4743 -C "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02004744 -S "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02004745 -S "SSL - The requested feature is not available"
4746
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02004747run_test "DTLS cookie: default (failing)" \
4748 "$P_SRV dtls=1 debug_level=2 cookies=-1" \
4749 "$P_CLI dtls=1 debug_level=2 hs_timeout=100-400" \
4750 1 \
4751 -s "cookie verification failed" \
4752 -S "cookie verification passed" \
4753 -S "cookie verification skipped" \
4754 -C "received hello verify request" \
4755 -S "hello verification requested" \
4756 -s "SSL - The requested feature is not available"
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02004757
4758requires_ipv6
4759run_test "DTLS cookie: enabled, IPv6" \
4760 "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
4761 "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
4762 0 \
4763 -s "cookie verification failed" \
4764 -s "cookie verification passed" \
4765 -S "cookie verification skipped" \
4766 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02004767 -s "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02004768 -S "SSL - The requested feature is not available"
4769
Manuel Pégourié-Gonnard579950c2014-09-29 17:47:33 +02004770run_test "DTLS cookie: enabled, nbio" \
4771 "$P_SRV dtls=1 nbio=2 debug_level=2" \
4772 "$P_CLI dtls=1 nbio=2 debug_level=2" \
4773 0 \
4774 -s "cookie verification failed" \
4775 -s "cookie verification passed" \
4776 -S "cookie verification skipped" \
4777 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02004778 -s "hello verification requested" \
Manuel Pégourié-Gonnard579950c2014-09-29 17:47:33 +02004779 -S "SSL - The requested feature is not available"
4780
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004781# Tests for client reconnecting from the same port with DTLS
4782
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004783not_with_valgrind # spurious resend
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004784run_test "DTLS client reconnect from same port: reference" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004785 "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
4786 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004787 0 \
4788 -C "resend" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004789 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004790 -S "Client initiated reconnection from same port"
4791
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004792not_with_valgrind # spurious resend
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004793run_test "DTLS client reconnect from same port: reconnect" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004794 "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
4795 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000 reconnect_hard=1" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004796 0 \
4797 -C "resend" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004798 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004799 -s "Client initiated reconnection from same port"
4800
Paul Bakker362689d2016-05-13 10:33:25 +01004801not_with_valgrind # server/client too slow to respond in time (next test has higher timeouts)
4802run_test "DTLS client reconnect from same port: reconnect, nbio, no valgrind" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004803 "$P_SRV dtls=1 exchanges=2 read_timeout=1000 nbio=2" \
4804 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000 reconnect_hard=1" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004805 0 \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004806 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02004807 -s "Client initiated reconnection from same port"
4808
Paul Bakker362689d2016-05-13 10:33:25 +01004809only_with_valgrind # Only with valgrind, do previous test but with higher read_timeout and hs_timeout
4810run_test "DTLS client reconnect from same port: reconnect, nbio, valgrind" \
4811 "$P_SRV dtls=1 exchanges=2 read_timeout=2000 nbio=2 hs_timeout=1500-6000" \
4812 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=1500-3000 reconnect_hard=1" \
4813 0 \
4814 -S "The operation timed out" \
4815 -s "Client initiated reconnection from same port"
4816
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004817run_test "DTLS client reconnect from same port: no cookies" \
4818 "$P_SRV dtls=1 exchanges=2 read_timeout=1000 cookies=0" \
Manuel Pégourié-Gonnard6ad23b92015-09-15 12:57:46 +02004819 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-8000 reconnect_hard=1" \
4820 0 \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02004821 -s "The operation timed out" \
4822 -S "Client initiated reconnection from same port"
4823
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02004824# Tests for various cases of client authentication with DTLS
4825# (focused on handshake flows and message parsing)
4826
4827run_test "DTLS client auth: required" \
4828 "$P_SRV dtls=1 auth_mode=required" \
4829 "$P_CLI dtls=1" \
4830 0 \
4831 -s "Verifying peer X.509 certificate... ok"
4832
4833run_test "DTLS client auth: optional, client has no cert" \
4834 "$P_SRV dtls=1 auth_mode=optional" \
4835 "$P_CLI dtls=1 crt_file=none key_file=none" \
4836 0 \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01004837 -s "! Certificate was missing"
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02004838
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01004839run_test "DTLS client auth: none, client has no cert" \
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02004840 "$P_SRV dtls=1 auth_mode=none" \
4841 "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
4842 0 \
4843 -c "skip write certificate$" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01004844 -s "! Certificate verification was skipped"
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02004845
Manuel Pégourié-Gonnard0a885742015-08-04 12:08:35 +02004846run_test "DTLS wrong PSK: badmac alert" \
4847 "$P_SRV dtls=1 psk=abc123 force_ciphersuite=TLS-PSK-WITH-AES-128-GCM-SHA256" \
4848 "$P_CLI dtls=1 psk=abc124" \
4849 1 \
4850 -s "SSL - Verification of the message MAC failed" \
4851 -c "SSL - A fatal alert message was received from our peer"
4852
Manuel Pégourié-Gonnard502bf302014-08-20 13:12:58 +02004853# Tests for receiving fragmented handshake messages with DTLS
4854
4855requires_gnutls
4856run_test "DTLS reassembly: no fragmentation (gnutls server)" \
4857 "$G_SRV -u --mtu 2048 -a" \
4858 "$P_CLI dtls=1 debug_level=2" \
4859 0 \
4860 -C "found fragmented DTLS handshake message" \
4861 -C "error"
4862
4863requires_gnutls
4864run_test "DTLS reassembly: some fragmentation (gnutls server)" \
4865 "$G_SRV -u --mtu 512" \
4866 "$P_CLI dtls=1 debug_level=2" \
4867 0 \
4868 -c "found fragmented DTLS handshake message" \
4869 -C "error"
4870
4871requires_gnutls
4872run_test "DTLS reassembly: more fragmentation (gnutls server)" \
4873 "$G_SRV -u --mtu 128" \
4874 "$P_CLI dtls=1 debug_level=2" \
4875 0 \
4876 -c "found fragmented DTLS handshake message" \
4877 -C "error"
4878
4879requires_gnutls
4880run_test "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
4881 "$G_SRV -u --mtu 128" \
4882 "$P_CLI dtls=1 nbio=2 debug_level=2" \
4883 0 \
4884 -c "found fragmented DTLS handshake message" \
4885 -C "error"
4886
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02004887requires_gnutls
Hanno Becker6a243642017-10-12 15:18:45 +01004888requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02004889run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
4890 "$G_SRV -u --mtu 256" \
4891 "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
4892 0 \
4893 -c "found fragmented DTLS handshake message" \
4894 -c "client hello, adding renegotiation extension" \
4895 -c "found renegotiation extension" \
4896 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004897 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02004898 -C "error" \
4899 -s "Extra-header:"
4900
4901requires_gnutls
Hanno Becker6a243642017-10-12 15:18:45 +01004902requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02004903run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
4904 "$G_SRV -u --mtu 256" \
4905 "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
4906 0 \
4907 -c "found fragmented DTLS handshake message" \
4908 -c "client hello, adding renegotiation extension" \
4909 -c "found renegotiation extension" \
4910 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004911 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02004912 -C "error" \
4913 -s "Extra-header:"
4914
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02004915run_test "DTLS reassembly: no fragmentation (openssl server)" \
4916 "$O_SRV -dtls1 -mtu 2048" \
4917 "$P_CLI dtls=1 debug_level=2" \
4918 0 \
4919 -C "found fragmented DTLS handshake message" \
4920 -C "error"
4921
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02004922run_test "DTLS reassembly: some fragmentation (openssl server)" \
4923 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02004924 "$P_CLI dtls=1 debug_level=2" \
4925 0 \
4926 -c "found fragmented DTLS handshake message" \
4927 -C "error"
4928
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02004929run_test "DTLS reassembly: more fragmentation (openssl server)" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02004930 "$O_SRV -dtls1 -mtu 256" \
4931 "$P_CLI dtls=1 debug_level=2" \
4932 0 \
4933 -c "found fragmented DTLS handshake message" \
4934 -C "error"
4935
4936run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
4937 "$O_SRV -dtls1 -mtu 256" \
4938 "$P_CLI dtls=1 nbio=2 debug_level=2" \
4939 0 \
4940 -c "found fragmented DTLS handshake message" \
4941 -C "error"
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02004942
Manuel Pégourié-Gonnard2cb17e22017-09-19 13:00:47 +02004943# Tests for sending fragmented handshake messages with DTLS
4944#
4945# Use client auth when we need the client to send large messages,
4946# and use large cert chains on both sides too (the long chains we have all use
4947# both RSA and ECDSA, but ideally we should have long chains with either).
4948# Sizes reached (UDP payload):
4949# - 2037B for server certificate
4950# - 1542B for client certificate
4951# - 1013B for newsessionticket
4952# - all others below 512B
4953# All those tests assume MAX_CONTENT_LEN is at least 2048
4954
4955requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4956requires_config_enabled MBEDTLS_RSA_C
4957requires_config_enabled MBEDTLS_ECDSA_C
4958requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4959run_test "DTLS fragmenting: none (for reference)" \
4960 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
4961 crt_file=data_files/server7_int-ca.crt \
4962 key_file=data_files/server7.key \
4963 max_frag_len=2048" \
4964 "$P_CLI dtls=1 debug_level=2 \
4965 crt_file=data_files/server8_int-ca2.crt \
4966 key_file=data_files/server8.key \
4967 max_frag_len=2048" \
4968 0 \
4969 -S "found fragmented DTLS handshake message" \
4970 -C "found fragmented DTLS handshake message" \
4971 -C "error"
4972
4973requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4974requires_config_enabled MBEDTLS_RSA_C
4975requires_config_enabled MBEDTLS_ECDSA_C
4976requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnardb747c6c2018-08-12 13:28:53 +02004977run_test "DTLS fragmenting: server only (max_frag_len)" \
Manuel Pégourié-Gonnard2cb17e22017-09-19 13:00:47 +02004978 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
4979 crt_file=data_files/server7_int-ca.crt \
4980 key_file=data_files/server7.key \
4981 max_frag_len=1024" \
4982 "$P_CLI dtls=1 debug_level=2 \
4983 crt_file=data_files/server8_int-ca2.crt \
4984 key_file=data_files/server8.key \
4985 max_frag_len=2048" \
4986 0 \
4987 -S "found fragmented DTLS handshake message" \
4988 -c "found fragmented DTLS handshake message" \
4989 -C "error"
4990
4991requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
4992requires_config_enabled MBEDTLS_RSA_C
4993requires_config_enabled MBEDTLS_ECDSA_C
4994requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnardb747c6c2018-08-12 13:28:53 +02004995run_test "DTLS fragmenting: server only (more) (max_frag_len)" \
Manuel Pégourié-Gonnard2cb17e22017-09-19 13:00:47 +02004996 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
4997 crt_file=data_files/server7_int-ca.crt \
4998 key_file=data_files/server7.key \
4999 max_frag_len=512" \
5000 "$P_CLI dtls=1 debug_level=2 \
5001 crt_file=data_files/server8_int-ca2.crt \
5002 key_file=data_files/server8.key \
5003 max_frag_len=2048" \
5004 0 \
5005 -S "found fragmented DTLS handshake message" \
5006 -c "found fragmented DTLS handshake message" \
5007 -C "error"
5008
5009requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5010requires_config_enabled MBEDTLS_RSA_C
5011requires_config_enabled MBEDTLS_ECDSA_C
5012requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnardb747c6c2018-08-12 13:28:53 +02005013run_test "DTLS fragmenting: client-initiated, server only (max_frag_len)" \
Manuel Pégourié-Gonnard2cb17e22017-09-19 13:00:47 +02005014 "$P_SRV dtls=1 debug_level=2 auth_mode=none \
5015 crt_file=data_files/server7_int-ca.crt \
5016 key_file=data_files/server7.key \
5017 max_frag_len=2048" \
5018 "$P_CLI dtls=1 debug_level=2 \
5019 crt_file=data_files/server8_int-ca2.crt \
5020 key_file=data_files/server8.key \
5021 max_frag_len=512" \
5022 0 \
5023 -S "found fragmented DTLS handshake message" \
5024 -c "found fragmented DTLS handshake message" \
5025 -C "error"
5026
5027requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5028requires_config_enabled MBEDTLS_RSA_C
5029requires_config_enabled MBEDTLS_ECDSA_C
5030requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnardb747c6c2018-08-12 13:28:53 +02005031run_test "DTLS fragmenting: client-initiated, both (max_frag_len)" \
Manuel Pégourié-Gonnard2cb17e22017-09-19 13:00:47 +02005032 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5033 crt_file=data_files/server7_int-ca.crt \
5034 key_file=data_files/server7.key \
5035 max_frag_len=2048" \
5036 "$P_CLI dtls=1 debug_level=2 \
5037 crt_file=data_files/server8_int-ca2.crt \
5038 key_file=data_files/server8.key \
5039 max_frag_len=512" \
5040 0 \
5041 -s "found fragmented DTLS handshake message" \
5042 -c "found fragmented DTLS handshake message" \
5043 -C "error"
5044
Manuel Pégourié-Gonnardb747c6c2018-08-12 13:28:53 +02005045requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5046requires_config_enabled MBEDTLS_RSA_C
5047requires_config_enabled MBEDTLS_ECDSA_C
5048run_test "DTLS fragmenting: none (for reference) (MTU)" \
5049 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5050 crt_file=data_files/server7_int-ca.crt \
5051 key_file=data_files/server7.key \
5052 mtu=2048" \
5053 "$P_CLI dtls=1 debug_level=2 \
5054 crt_file=data_files/server8_int-ca2.crt \
5055 key_file=data_files/server8.key \
5056 mtu=2048" \
5057 0 \
5058 -S "found fragmented DTLS handshake message" \
5059 -C "found fragmented DTLS handshake message" \
5060 -C "error"
5061
5062requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5063requires_config_enabled MBEDTLS_RSA_C
5064requires_config_enabled MBEDTLS_ECDSA_C
5065run_test "DTLS fragmenting: client (MTU)" \
5066 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5067 crt_file=data_files/server7_int-ca.crt \
5068 key_file=data_files/server7.key \
5069 mtu=2048" \
5070 "$P_CLI dtls=1 debug_level=2 \
5071 crt_file=data_files/server8_int-ca2.crt \
5072 key_file=data_files/server8.key \
5073 mtu=512" \
5074 0 \
5075 -s "found fragmented DTLS handshake message" \
5076 -C "found fragmented DTLS handshake message" \
5077 -C "error"
5078
5079requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5080requires_config_enabled MBEDTLS_RSA_C
5081requires_config_enabled MBEDTLS_ECDSA_C
5082run_test "DTLS fragmenting: server (MTU)" \
5083 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5084 crt_file=data_files/server7_int-ca.crt \
5085 key_file=data_files/server7.key \
5086 mtu=512" \
5087 "$P_CLI dtls=1 debug_level=2 \
5088 crt_file=data_files/server8_int-ca2.crt \
5089 key_file=data_files/server8.key \
5090 mtu=2048" \
5091 0 \
5092 -S "found fragmented DTLS handshake message" \
5093 -c "found fragmented DTLS handshake message" \
5094 -C "error"
5095
5096requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5097requires_config_enabled MBEDTLS_RSA_C
5098requires_config_enabled MBEDTLS_ECDSA_C
5099run_test "DTLS fragmenting: both (MTU)" \
Manuel Pégourié-Gonnard45323292018-08-20 11:52:24 +02005100 -p "$P_PXY mtu=512" \
Manuel Pégourié-Gonnardb747c6c2018-08-12 13:28:53 +02005101 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5102 crt_file=data_files/server7_int-ca.crt \
5103 key_file=data_files/server7.key \
5104 mtu=512" \
5105 "$P_CLI dtls=1 debug_level=2 \
5106 crt_file=data_files/server8_int-ca2.crt \
5107 key_file=data_files/server8.key \
5108 mtu=512" \
5109 0 \
5110 -s "found fragmented DTLS handshake message" \
5111 -c "found fragmented DTLS handshake message" \
5112 -C "error"
5113
Manuel Pégourié-Gonnardb8eec192018-08-20 09:34:02 +02005114# Test for automatic MTU reduction on repeated resend
Hanno Becker37029eb2018-08-29 17:01:40 +01005115not_with_valgrind
Manuel Pégourié-Gonnardb8eec192018-08-20 09:34:02 +02005116requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5117requires_config_enabled MBEDTLS_RSA_C
5118requires_config_enabled MBEDTLS_ECDSA_C
5119run_test "DTLS fragmenting: proxy MTU: auto-reduction" \
5120 -p "$P_PXY mtu=508" \
5121 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5122 crt_file=data_files/server7_int-ca.crt \
5123 key_file=data_files/server7.key\
5124 hs_timeout=100-400" \
5125 "$P_CLI dtls=1 debug_level=2 \
5126 crt_file=data_files/server8_int-ca2.crt \
5127 key_file=data_files/server8.key \
5128 hs_timeout=100-400" \
5129 0 \
5130 -s "found fragmented DTLS handshake message" \
5131 -c "found fragmented DTLS handshake message" \
5132 -C "error"
5133
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005134# the proxy shouldn't drop or mess up anything, so we shouldn't need to resend
Manuel Pégourié-Gonnard3d183ce2018-08-22 09:56:22 +02005135# OTOH the client might resend if the server is to slow to reset after sending
5136# a HelloVerifyRequest, so only check for no retransmission server-side
Manuel Pégourié-Gonnard0794d492018-08-17 10:54:24 +02005137not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005138requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5139requires_config_enabled MBEDTLS_RSA_C
5140requires_config_enabled MBEDTLS_ECDSA_C
5141run_test "DTLS fragmenting: proxy MTU, simple handshake" \
5142 -p "$P_PXY mtu=512" \
5143 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5144 crt_file=data_files/server7_int-ca.crt \
5145 key_file=data_files/server7.key \
5146 mtu=512" \
5147 "$P_CLI dtls=1 debug_level=2 \
5148 crt_file=data_files/server8_int-ca2.crt \
5149 key_file=data_files/server8.key \
5150 mtu=512" \
5151 0 \
5152 -S "resend" \
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005153 -s "found fragmented DTLS handshake message" \
5154 -c "found fragmented DTLS handshake message" \
5155 -C "error"
5156
Manuel Pégourié-Gonnardc1d54b72018-08-22 10:02:59 +02005157not_with_valgrind # spurious resend due to timeout
5158requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5159requires_config_enabled MBEDTLS_RSA_C
5160requires_config_enabled MBEDTLS_ECDSA_C
5161run_test "DTLS fragmenting: proxy MTU, simple handshake, nbio" \
5162 -p "$P_PXY mtu=512" \
5163 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5164 crt_file=data_files/server7_int-ca.crt \
5165 key_file=data_files/server7.key \
5166 mtu=512 nbio=2" \
5167 "$P_CLI dtls=1 debug_level=2 \
5168 crt_file=data_files/server8_int-ca2.crt \
5169 key_file=data_files/server8.key \
5170 mtu=512 nbio=2" \
5171 0 \
5172 -S "resend" \
5173 -s "found fragmented DTLS handshake message" \
5174 -c "found fragmented DTLS handshake message" \
5175 -C "error"
5176
Manuel Pégourié-Gonnard19c62f92018-08-16 10:50:39 +02005177# This ensures things still work after session_reset(),
5178# for example it would have caught #1941.
5179# It also exercises the "resumed hanshake" flow.
5180# Since we don't support reading fragmented ClientHello yet,
5181# up the MTU to 1450 (larger than ClientHello with session ticket,
5182# but still smaller than client's Certificate to ensure fragmentation).
Manuel Pégourié-Gonnard2f2d9022018-08-21 12:17:54 +02005183# reco_delay avoids races where the client reconnects before the server has
5184# resumed listening, which would result in a spurious resend.
Manuel Pégourié-Gonnard0794d492018-08-17 10:54:24 +02005185not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard19c62f92018-08-16 10:50:39 +02005186requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5187requires_config_enabled MBEDTLS_RSA_C
5188requires_config_enabled MBEDTLS_ECDSA_C
5189run_test "DTLS fragmenting: proxy MTU, resumed handshake" \
5190 -p "$P_PXY mtu=1450" \
5191 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5192 crt_file=data_files/server7_int-ca.crt \
5193 key_file=data_files/server7.key \
5194 mtu=1450" \
5195 "$P_CLI dtls=1 debug_level=2 \
5196 crt_file=data_files/server8_int-ca2.crt \
5197 key_file=data_files/server8.key \
Manuel Pégourié-Gonnard2f2d9022018-08-21 12:17:54 +02005198 mtu=1450 reconnect=1 reco_delay=1" \
Manuel Pégourié-Gonnard19c62f92018-08-16 10:50:39 +02005199 0 \
5200 -S "resend" \
Manuel Pégourié-Gonnard19c62f92018-08-16 10:50:39 +02005201 -s "found fragmented DTLS handshake message" \
5202 -c "found fragmented DTLS handshake message" \
5203 -C "error"
5204
Manuel Pégourié-Gonnard0794d492018-08-17 10:54:24 +02005205not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005206requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5207requires_config_enabled MBEDTLS_RSA_C
5208requires_config_enabled MBEDTLS_ECDSA_C
5209requires_config_enabled MBEDTLS_SHA256_C
5210requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA
5211requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5212requires_config_enabled MBEDTLS_CHACHAPOLY_C
5213run_test "DTLS fragmenting: proxy MTU, ChachaPoly renego" \
5214 -p "$P_PXY mtu=512" \
5215 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5216 crt_file=data_files/server7_int-ca.crt \
5217 key_file=data_files/server7.key \
5218 exchanges=2 renegotiation=1 \
5219 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256 \
5220 mtu=512" \
5221 "$P_CLI dtls=1 debug_level=2 \
5222 crt_file=data_files/server8_int-ca2.crt \
5223 key_file=data_files/server8.key \
5224 exchanges=2 renegotiation=1 renegotiate=1 \
5225 mtu=512" \
5226 0 \
5227 -S "resend" \
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005228 -s "found fragmented DTLS handshake message" \
5229 -c "found fragmented DTLS handshake message" \
5230 -C "error"
5231
Manuel Pégourié-Gonnard0794d492018-08-17 10:54:24 +02005232not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005233requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5234requires_config_enabled MBEDTLS_RSA_C
5235requires_config_enabled MBEDTLS_ECDSA_C
5236requires_config_enabled MBEDTLS_SHA256_C
5237requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA
5238requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5239requires_config_enabled MBEDTLS_AES_C
5240requires_config_enabled MBEDTLS_GCM_C
5241run_test "DTLS fragmenting: proxy MTU, AES-GCM renego" \
5242 -p "$P_PXY mtu=512" \
5243 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5244 crt_file=data_files/server7_int-ca.crt \
5245 key_file=data_files/server7.key \
5246 exchanges=2 renegotiation=1 \
5247 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
5248 mtu=512" \
5249 "$P_CLI dtls=1 debug_level=2 \
5250 crt_file=data_files/server8_int-ca2.crt \
5251 key_file=data_files/server8.key \
5252 exchanges=2 renegotiation=1 renegotiate=1 \
5253 mtu=512" \
5254 0 \
5255 -S "resend" \
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005256 -s "found fragmented DTLS handshake message" \
5257 -c "found fragmented DTLS handshake message" \
5258 -C "error"
5259
Manuel Pégourié-Gonnard0794d492018-08-17 10:54:24 +02005260not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005261requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5262requires_config_enabled MBEDTLS_RSA_C
5263requires_config_enabled MBEDTLS_ECDSA_C
5264requires_config_enabled MBEDTLS_SHA256_C
5265requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA
5266requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5267requires_config_enabled MBEDTLS_AES_C
5268requires_config_enabled MBEDTLS_CCM_C
5269run_test "DTLS fragmenting: proxy MTU, AES-CCM renego" \
5270 -p "$P_PXY mtu=512" \
5271 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5272 crt_file=data_files/server7_int-ca.crt \
5273 key_file=data_files/server7.key \
5274 exchanges=2 renegotiation=1 \
5275 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8 \
5276 mtu=512" \
5277 "$P_CLI dtls=1 debug_level=2 \
5278 crt_file=data_files/server8_int-ca2.crt \
5279 key_file=data_files/server8.key \
5280 exchanges=2 renegotiation=1 renegotiate=1 \
5281 mtu=512" \
5282 0 \
5283 -S "resend" \
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005284 -s "found fragmented DTLS handshake message" \
5285 -c "found fragmented DTLS handshake message" \
5286 -C "error"
5287
Manuel Pégourié-Gonnard0794d492018-08-17 10:54:24 +02005288not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005289requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5290requires_config_enabled MBEDTLS_RSA_C
5291requires_config_enabled MBEDTLS_ECDSA_C
5292requires_config_enabled MBEDTLS_SHA256_C
5293requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA
5294requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5295requires_config_enabled MBEDTLS_AES_C
5296requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
5297requires_config_enabled MBEDTLS_SSL_ENCRYPT_THEN_MAC
5298run_test "DTLS fragmenting: proxy MTU, AES-CBC EtM renego" \
5299 -p "$P_PXY mtu=512" \
5300 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5301 crt_file=data_files/server7_int-ca.crt \
5302 key_file=data_files/server7.key \
5303 exchanges=2 renegotiation=1 \
5304 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 \
5305 mtu=512" \
5306 "$P_CLI dtls=1 debug_level=2 \
5307 crt_file=data_files/server8_int-ca2.crt \
5308 key_file=data_files/server8.key \
5309 exchanges=2 renegotiation=1 renegotiate=1 \
5310 mtu=512" \
5311 0 \
5312 -S "resend" \
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005313 -s "found fragmented DTLS handshake message" \
5314 -c "found fragmented DTLS handshake message" \
5315 -C "error"
5316
Manuel Pégourié-Gonnard0794d492018-08-17 10:54:24 +02005317not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005318requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5319requires_config_enabled MBEDTLS_RSA_C
5320requires_config_enabled MBEDTLS_ECDSA_C
5321requires_config_enabled MBEDTLS_SHA256_C
5322requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA
5323requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5324requires_config_enabled MBEDTLS_AES_C
5325requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
5326run_test "DTLS fragmenting: proxy MTU, AES-CBC non-EtM renego" \
5327 -p "$P_PXY mtu=512" \
5328 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5329 crt_file=data_files/server7_int-ca.crt \
5330 key_file=data_files/server7.key \
5331 exchanges=2 renegotiation=1 \
5332 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 etm=0 \
5333 mtu=512" \
5334 "$P_CLI dtls=1 debug_level=2 \
5335 crt_file=data_files/server8_int-ca2.crt \
5336 key_file=data_files/server8.key \
5337 exchanges=2 renegotiation=1 renegotiate=1 \
5338 mtu=512" \
5339 0 \
5340 -S "resend" \
Manuel Pégourié-Gonnard72c27072018-08-13 12:37:51 +02005341 -s "found fragmented DTLS handshake message" \
5342 -c "found fragmented DTLS handshake message" \
5343 -C "error"
5344
Manuel Pégourié-Gonnard2d56f0d2018-08-16 11:09:03 +02005345requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5346requires_config_enabled MBEDTLS_RSA_C
5347requires_config_enabled MBEDTLS_ECDSA_C
5348client_needs_more_time 2
5349run_test "DTLS fragmenting: proxy MTU + 3d" \
5350 -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
5351 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5352 crt_file=data_files/server7_int-ca.crt \
5353 key_file=data_files/server7.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005354 hs_timeout=250-10000 mtu=512" \
Manuel Pégourié-Gonnard2d56f0d2018-08-16 11:09:03 +02005355 "$P_CLI dtls=1 debug_level=2 \
5356 crt_file=data_files/server8_int-ca2.crt \
5357 key_file=data_files/server8.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005358 hs_timeout=250-10000 mtu=512" \
Manuel Pégourié-Gonnard2d56f0d2018-08-16 11:09:03 +02005359 0 \
5360 -s "found fragmented DTLS handshake message" \
5361 -c "found fragmented DTLS handshake message" \
5362 -C "error"
5363
Manuel Pégourié-Gonnardc1d54b72018-08-22 10:02:59 +02005364requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5365requires_config_enabled MBEDTLS_RSA_C
5366requires_config_enabled MBEDTLS_ECDSA_C
5367client_needs_more_time 2
5368run_test "DTLS fragmenting: proxy MTU + 3d, nbio" \
5369 -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
5370 "$P_SRV dtls=1 debug_level=2 auth_mode=required \
5371 crt_file=data_files/server7_int-ca.crt \
5372 key_file=data_files/server7.key \
5373 hs_timeout=250-10000 mtu=512 nbio=2" \
5374 "$P_CLI dtls=1 debug_level=2 \
5375 crt_file=data_files/server8_int-ca2.crt \
5376 key_file=data_files/server8.key \
5377 hs_timeout=250-10000 mtu=512 nbio=2" \
5378 0 \
5379 -s "found fragmented DTLS handshake message" \
5380 -c "found fragmented DTLS handshake message" \
5381 -C "error"
5382
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005383# interop tests for DTLS fragmentating with reliable connection
5384#
Manuel Pégourié-Gonnard1218bc02018-08-17 10:51:26 +02005385# here and below we just want to test that the we fragment in a way that
5386# pleases other implementations, so we don't need the peer to fragment
5387requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5388requires_config_enabled MBEDTLS_RSA_C
5389requires_config_enabled MBEDTLS_ECDSA_C
5390requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
Manuel Pégourié-Gonnard61512982018-08-21 09:40:07 +02005391requires_gnutls
Manuel Pégourié-Gonnard1218bc02018-08-17 10:51:26 +02005392run_test "DTLS fragmenting: gnutls server, DTLS 1.2" \
5393 "$G_SRV -u" \
5394 "$P_CLI dtls=1 debug_level=2 \
5395 crt_file=data_files/server8_int-ca2.crt \
5396 key_file=data_files/server8.key \
5397 mtu=512 force_version=dtls1_2" \
5398 0 \
5399 -c "fragmenting handshake message" \
5400 -C "error"
5401
5402requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5403requires_config_enabled MBEDTLS_RSA_C
5404requires_config_enabled MBEDTLS_ECDSA_C
5405requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
Manuel Pégourié-Gonnard61512982018-08-21 09:40:07 +02005406requires_gnutls
Manuel Pégourié-Gonnard1218bc02018-08-17 10:51:26 +02005407run_test "DTLS fragmenting: gnutls server, DTLS 1.0" \
5408 "$G_SRV -u" \
5409 "$P_CLI dtls=1 debug_level=2 \
5410 crt_file=data_files/server8_int-ca2.crt \
5411 key_file=data_files/server8.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005412 mtu=512 force_version=dtls1" \
Manuel Pégourié-Gonnard1218bc02018-08-17 10:51:26 +02005413 0 \
5414 -c "fragmenting handshake message" \
5415 -C "error"
5416
5417# gnutls-cli always tries IPv6 first, and doesn't fall back to IPv4 with DTLS
5418requires_ipv6
5419requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5420requires_config_enabled MBEDTLS_RSA_C
5421requires_config_enabled MBEDTLS_ECDSA_C
5422requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
Manuel Pégourié-Gonnard61512982018-08-21 09:40:07 +02005423requires_gnutls
Manuel Pégourié-Gonnard1218bc02018-08-17 10:51:26 +02005424run_test "DTLS fragmenting: gnutls client, DTLS 1.2" \
5425 "$P_SRV dtls=1 debug_level=2 server_addr=::1 \
5426 crt_file=data_files/server7_int-ca.crt \
5427 key_file=data_files/server7.key \
5428 mtu=512 force_version=dtls1_2" \
5429 "$G_CLI -u" \
5430 0 \
5431 -s "fragmenting handshake message"
5432
5433# gnutls-cli always tries IPv6 first, and doesn't fall back to IPv4 with DTLS
5434requires_ipv6
5435requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5436requires_config_enabled MBEDTLS_RSA_C
5437requires_config_enabled MBEDTLS_ECDSA_C
5438requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
Manuel Pégourié-Gonnard61512982018-08-21 09:40:07 +02005439requires_gnutls
Manuel Pégourié-Gonnard1218bc02018-08-17 10:51:26 +02005440run_test "DTLS fragmenting: gnutls client, DTLS 1.0" \
5441 "$P_SRV dtls=1 debug_level=2 server_addr=::1 \
5442 crt_file=data_files/server7_int-ca.crt \
5443 key_file=data_files/server7.key \
5444 mtu=512 force_version=dtls1" \
5445 "$G_CLI -u" \
5446 0 \
5447 -s "fragmenting handshake message"
5448
5449requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5450requires_config_enabled MBEDTLS_RSA_C
5451requires_config_enabled MBEDTLS_ECDSA_C
5452requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5453run_test "DTLS fragmenting: openssl server, DTLS 1.2" \
5454 "$O_SRV -dtls1_2 -verify 10" \
5455 "$P_CLI dtls=1 debug_level=2 \
5456 crt_file=data_files/server8_int-ca2.crt \
5457 key_file=data_files/server8.key \
5458 mtu=512 force_version=dtls1_2" \
5459 0 \
5460 -c "fragmenting handshake message" \
5461 -C "error"
5462
5463requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5464requires_config_enabled MBEDTLS_RSA_C
5465requires_config_enabled MBEDTLS_ECDSA_C
5466requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
5467run_test "DTLS fragmenting: openssl server, DTLS 1.0" \
5468 "$O_SRV -dtls1 -verify 10" \
5469 "$P_CLI dtls=1 debug_level=2 \
5470 crt_file=data_files/server8_int-ca2.crt \
5471 key_file=data_files/server8.key \
5472 mtu=512 force_version=dtls1" \
5473 0 \
5474 -c "fragmenting handshake message" \
5475 -C "error"
5476
5477requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5478requires_config_enabled MBEDTLS_RSA_C
5479requires_config_enabled MBEDTLS_ECDSA_C
5480requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5481run_test "DTLS fragmenting: openssl client, DTLS 1.2" \
5482 "$P_SRV dtls=1 debug_level=2 \
5483 crt_file=data_files/server7_int-ca.crt \
5484 key_file=data_files/server7.key \
5485 mtu=512 force_version=dtls1_2" \
5486 "$O_CLI -dtls1_2" \
5487 0 \
5488 -s "fragmenting handshake message"
5489
5490requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5491requires_config_enabled MBEDTLS_RSA_C
5492requires_config_enabled MBEDTLS_ECDSA_C
5493requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
5494run_test "DTLS fragmenting: openssl client, DTLS 1.0" \
5495 "$P_SRV dtls=1 debug_level=2 \
5496 crt_file=data_files/server7_int-ca.crt \
5497 key_file=data_files/server7.key \
5498 mtu=512 force_version=dtls1" \
5499 "$O_CLI -dtls1" \
5500 0 \
5501 -s "fragmenting handshake message"
5502
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005503# interop tests for DTLS fragmentating with unreliable connection
5504#
5505# again we just want to test that the we fragment in a way that
5506# pleases other implementations, so we don't need the peer to fragment
5507requires_gnutls_next
5508requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5509requires_config_enabled MBEDTLS_RSA_C
5510requires_config_enabled MBEDTLS_ECDSA_C
5511requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005512client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005513run_test "DTLS fragmenting: 3d, gnutls server, DTLS 1.2" \
5514 -p "$P_PXY drop=8 delay=8 duplicate=8" \
5515 "$G_NEXT_SRV -u" \
5516 "$P_CLI dtls=1 debug_level=2 \
5517 crt_file=data_files/server8_int-ca2.crt \
5518 key_file=data_files/server8.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005519 hs_timeout=250-60000 mtu=512 force_version=dtls1_2" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005520 0 \
5521 -c "fragmenting handshake message" \
5522 -C "error"
5523
5524requires_gnutls_next
5525requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5526requires_config_enabled MBEDTLS_RSA_C
5527requires_config_enabled MBEDTLS_ECDSA_C
5528requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005529client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005530run_test "DTLS fragmenting: 3d, gnutls server, DTLS 1.0" \
5531 -p "$P_PXY drop=8 delay=8 duplicate=8" \
5532 "$G_NEXT_SRV -u" \
5533 "$P_CLI dtls=1 debug_level=2 \
5534 crt_file=data_files/server8_int-ca2.crt \
5535 key_file=data_files/server8.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005536 hs_timeout=250-60000 mtu=512 force_version=dtls1" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005537 0 \
5538 -c "fragmenting handshake message" \
5539 -C "error"
5540
5541## The two tests below are disabled due to a bug in GnuTLS client that causes
5542## handshake failures when the NewSessionTicket message is lost, see
5543## https://gitlab.com/gnutls/gnutls/issues/543
5544## We can re-enable them when a fixed version fo GnuTLS is available
5545## and installed in our CI system.
5546##
5547## # gnutls-cli always tries IPv6 first, and doesn't fall back to IPv4 with DTLS
5548## requires_ipv6
Manuel Pégourié-Gonnard61512982018-08-21 09:40:07 +02005549## requires_gnutls
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005550## requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5551## requires_config_enabled MBEDTLS_RSA_C
5552## requires_config_enabled MBEDTLS_ECDSA_C
5553## requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005554## client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005555## run_test "DTLS fragmenting: 3d, gnutls client, DTLS 1.2" \
5556## -p "$P_PXY drop=8 delay=8 duplicate=8" \
5557## "$P_SRV dtls=1 debug_level=2 server_addr=::1 \
5558## crt_file=data_files/server7_int-ca.crt \
5559## key_file=data_files/server7.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005560## hs_timeout=250-60000 mtu=512 force_version=dtls1_2" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005561## "$G_CLI -u" \
5562## 0 \
5563## -s "fragmenting handshake message"
5564##
5565## # gnutls-cli always tries IPv6 first, and doesn't fall back to IPv4 with DTLS
5566## requires_ipv6
Manuel Pégourié-Gonnard61512982018-08-21 09:40:07 +02005567## requires_gnutls
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005568## requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5569## requires_config_enabled MBEDTLS_RSA_C
5570## requires_config_enabled MBEDTLS_ECDSA_C
5571## requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005572## client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005573## run_test "DTLS fragmenting: 3d, gnutls client, DTLS 1.0" \
5574## -p "$P_PXY drop=8 delay=8 duplicate=8" \
5575## "$P_SRV dtls=1 debug_level=2 server_addr=::1 \
5576## crt_file=data_files/server7_int-ca.crt \
5577## key_file=data_files/server7.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005578## hs_timeout=250-60000 mtu=512 force_version=dtls1" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005579## "$G_CLI -u" \
5580## 0 \
5581## -s "fragmenting handshake message"
5582
5583## Interop test with OpenSSL might triger a bug in recent versions (that
5584## probably won't be fixed before 1.1.1X), so we use an old version that
5585## doesn't have this bug, but unfortunately it doesn't have support for DTLS
5586## 1.2 either, so the DTLS 1.2 tests are commented for now.
5587## Bug report: https://github.com/openssl/openssl/issues/6902
5588## They should be re-enabled (and the DTLS 1.0 switched back to a non-legacy
5589## version of OpenSSL once a fixed version of OpenSSL is available)
5590##
5591## requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5592## requires_config_enabled MBEDTLS_RSA_C
5593## requires_config_enabled MBEDTLS_ECDSA_C
5594## requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005595## client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005596## run_test "DTLS fragmenting: 3d, openssl server, DTLS 1.2" \
5597## -p "$P_PXY drop=8 delay=8 duplicate=8" \
5598## "$O_SRV -dtls1_2 -verify 10" \
5599## "$P_CLI dtls=1 debug_level=2 \
5600## crt_file=data_files/server8_int-ca2.crt \
5601## key_file=data_files/server8.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005602## hs_timeout=250-60000 mtu=512 force_version=dtls1_2" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005603## 0 \
5604## -c "fragmenting handshake message" \
5605## -C "error"
5606
5607requires_openssl_legacy
5608requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5609requires_config_enabled MBEDTLS_RSA_C
5610requires_config_enabled MBEDTLS_ECDSA_C
5611requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005612client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005613run_test "DTLS fragmenting: 3d, openssl server, DTLS 1.0" \
5614 -p "$P_PXY drop=8 delay=8 duplicate=8" \
5615 "$O_LEGACY_SRV -dtls1 -verify 10" \
5616 "$P_CLI dtls=1 debug_level=2 \
5617 crt_file=data_files/server8_int-ca2.crt \
5618 key_file=data_files/server8.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005619 hs_timeout=250-60000 mtu=512 force_version=dtls1" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005620 0 \
5621 -c "fragmenting handshake message" \
5622 -C "error"
5623
5624## see comment on the previous-previous test
5625## requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5626## requires_config_enabled MBEDTLS_RSA_C
5627## requires_config_enabled MBEDTLS_ECDSA_C
5628## requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005629## client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005630## run_test "DTLS fragmenting: 3d, openssl client, DTLS 1.2" \
5631## -p "$P_PXY drop=8 delay=8 duplicate=8" \
5632## "$P_SRV dtls=1 debug_level=2 \
5633## crt_file=data_files/server7_int-ca.crt \
5634## key_file=data_files/server7.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005635## hs_timeout=250-60000 mtu=512 force_version=dtls1_2" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005636## "$O_CLI -dtls1_2" \
5637## 0 \
5638## -s "fragmenting handshake message"
5639
5640# -nbio is added to prevent s_client from blocking in case of duplicated
5641# messages at the end of the handshake
Hanno Becker98293152018-08-17 16:10:47 +01005642requires_openssl_legacy
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005643requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
5644requires_config_enabled MBEDTLS_RSA_C
5645requires_config_enabled MBEDTLS_ECDSA_C
5646requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005647client_needs_more_time 4
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005648run_test "DTLS fragmenting: 3d, openssl client, DTLS 1.0" \
5649 -p "$P_PXY drop=8 delay=8 duplicate=8" \
5650 "$P_SRV dtls=1 debug_level=2 \
5651 crt_file=data_files/server7_int-ca.crt \
5652 key_file=data_files/server7.key \
Manuel Pégourié-Gonnard02f3a8a2018-08-20 10:49:28 +02005653 hs_timeout=250-60000 mtu=512 force_version=dtls1" \
Manuel Pégourié-Gonnard38110df2018-08-17 12:44:54 +02005654 "$O_LEGACY_CLI -nbio -dtls1" \
5655 0 \
5656 -s "fragmenting handshake message"
5657
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02005658# Tests for specific things with "unreliable" UDP connection
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02005659
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005660not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02005661run_test "DTLS proxy: reference" \
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02005662 -p "$P_PXY" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005663 "$P_SRV dtls=1 debug_level=2" \
5664 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02005665 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02005666 -C "replayed record" \
5667 -S "replayed record" \
5668 -C "record from another epoch" \
5669 -S "record from another epoch" \
5670 -C "discarding invalid record" \
5671 -S "discarding invalid record" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005672 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02005673 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02005674 -c "HTTP/1.0 200 OK"
5675
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005676not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02005677run_test "DTLS proxy: duplicate every packet" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02005678 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005679 "$P_SRV dtls=1 debug_level=2" \
5680 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02005681 0 \
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02005682 -c "replayed record" \
5683 -s "replayed record" \
Hanno Becker52c6dc62017-05-26 16:07:36 +01005684 -c "record from another epoch" \
5685 -s "record from another epoch" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005686 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02005687 -s "Extra-header:" \
5688 -c "HTTP/1.0 200 OK"
5689
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02005690run_test "DTLS proxy: duplicate every packet, server anti-replay off" \
5691 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005692 "$P_SRV dtls=1 debug_level=2 anti_replay=0" \
5693 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02005694 0 \
5695 -c "replayed record" \
5696 -S "replayed record" \
Hanno Becker52c6dc62017-05-26 16:07:36 +01005697 -c "record from another epoch" \
5698 -s "record from another epoch" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02005699 -c "resend" \
5700 -s "resend" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02005701 -s "Extra-header:" \
5702 -c "HTTP/1.0 200 OK"
5703
Hanno Becker72a4f032017-11-15 16:39:20 +00005704run_test "DTLS proxy: multiple records in same datagram" \
Hanno Becker8d832182018-03-15 10:14:19 +00005705 -p "$P_PXY pack=50" \
Hanno Becker72a4f032017-11-15 16:39:20 +00005706 "$P_SRV dtls=1 debug_level=2" \
5707 "$P_CLI dtls=1 debug_level=2" \
5708 0 \
5709 -c "next record in same datagram" \
5710 -s "next record in same datagram"
5711
5712run_test "DTLS proxy: multiple records in same datagram, duplicate every packet" \
Hanno Becker8d832182018-03-15 10:14:19 +00005713 -p "$P_PXY pack=50 duplicate=1" \
Hanno Becker72a4f032017-11-15 16:39:20 +00005714 "$P_SRV dtls=1 debug_level=2" \
5715 "$P_CLI dtls=1 debug_level=2" \
5716 0 \
5717 -c "next record in same datagram" \
5718 -s "next record in same datagram"
5719
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02005720run_test "DTLS proxy: inject invalid AD record, default badmac_limit" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02005721 -p "$P_PXY bad_ad=1" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02005722 "$P_SRV dtls=1 debug_level=1" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02005723 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02005724 0 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02005725 -c "discarding invalid record (mac)" \
5726 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02005727 -s "Extra-header:" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02005728 -c "HTTP/1.0 200 OK" \
5729 -S "too many records with bad MAC" \
5730 -S "Verification of the message MAC failed"
5731
5732run_test "DTLS proxy: inject invalid AD record, badmac_limit 1" \
5733 -p "$P_PXY bad_ad=1" \
5734 "$P_SRV dtls=1 debug_level=1 badmac_limit=1" \
5735 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
5736 1 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02005737 -C "discarding invalid record (mac)" \
5738 -S "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02005739 -S "Extra-header:" \
5740 -C "HTTP/1.0 200 OK" \
5741 -s "too many records with bad MAC" \
5742 -s "Verification of the message MAC failed"
5743
5744run_test "DTLS proxy: inject invalid AD record, badmac_limit 2" \
5745 -p "$P_PXY bad_ad=1" \
5746 "$P_SRV dtls=1 debug_level=1 badmac_limit=2" \
5747 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
5748 0 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02005749 -c "discarding invalid record (mac)" \
5750 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02005751 -s "Extra-header:" \
5752 -c "HTTP/1.0 200 OK" \
5753 -S "too many records with bad MAC" \
5754 -S "Verification of the message MAC failed"
5755
5756run_test "DTLS proxy: inject invalid AD record, badmac_limit 2, exchanges 2"\
5757 -p "$P_PXY bad_ad=1" \
5758 "$P_SRV dtls=1 debug_level=1 badmac_limit=2 exchanges=2" \
5759 "$P_CLI dtls=1 debug_level=1 read_timeout=100 exchanges=2" \
5760 1 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02005761 -c "discarding invalid record (mac)" \
5762 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02005763 -s "Extra-header:" \
5764 -c "HTTP/1.0 200 OK" \
5765 -s "too many records with bad MAC" \
5766 -s "Verification of the message MAC failed"
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02005767
5768run_test "DTLS proxy: delay ChangeCipherSpec" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02005769 -p "$P_PXY delay_ccs=1" \
5770 "$P_SRV dtls=1 debug_level=1" \
5771 "$P_CLI dtls=1 debug_level=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02005772 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02005773 -c "record from another epoch" \
5774 -s "record from another epoch" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02005775 -s "Extra-header:" \
5776 -c "HTTP/1.0 200 OK"
5777
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02005778# Tests for "randomly unreliable connection": try a variety of flows and peers
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005779
Janos Follath74537a62016-09-02 13:45:28 +01005780client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005781run_test "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02005782 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005783 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
5784 psk=abc123" \
5785 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005786 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
5787 0 \
5788 -s "Extra-header:" \
5789 -c "HTTP/1.0 200 OK"
5790
Janos Follath74537a62016-09-02 13:45:28 +01005791client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005792run_test "DTLS proxy: 3d, \"short\" RSA handshake" \
5793 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005794 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
5795 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005796 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
5797 0 \
5798 -s "Extra-header:" \
5799 -c "HTTP/1.0 200 OK"
5800
Janos Follath74537a62016-09-02 13:45:28 +01005801client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005802run_test "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
5803 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005804 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
5805 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005806 0 \
5807 -s "Extra-header:" \
5808 -c "HTTP/1.0 200 OK"
5809
Janos Follath74537a62016-09-02 13:45:28 +01005810client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005811run_test "DTLS proxy: 3d, FS, client auth" \
5812 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005813 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=required" \
5814 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005815 0 \
5816 -s "Extra-header:" \
5817 -c "HTTP/1.0 200 OK"
5818
Janos Follath74537a62016-09-02 13:45:28 +01005819client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005820run_test "DTLS proxy: 3d, FS, ticket" \
5821 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005822 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=none" \
5823 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005824 0 \
5825 -s "Extra-header:" \
5826 -c "HTTP/1.0 200 OK"
5827
Janos Follath74537a62016-09-02 13:45:28 +01005828client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02005829run_test "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
5830 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005831 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=required" \
5832 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02005833 0 \
5834 -s "Extra-header:" \
5835 -c "HTTP/1.0 200 OK"
5836
Janos Follath74537a62016-09-02 13:45:28 +01005837client_needs_more_time 2
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005838run_test "DTLS proxy: 3d, max handshake, nbio" \
5839 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005840 "$P_SRV dtls=1 hs_timeout=250-10000 nbio=2 tickets=1 \
5841 auth_mode=required" \
5842 "$P_CLI dtls=1 hs_timeout=250-10000 nbio=2 tickets=1" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005843 0 \
5844 -s "Extra-header:" \
5845 -c "HTTP/1.0 200 OK"
5846
Janos Follath74537a62016-09-02 13:45:28 +01005847client_needs_more_time 4
Manuel Pégourié-Gonnard7a26d732014-10-02 14:50:46 +02005848run_test "DTLS proxy: 3d, min handshake, resumption" \
5849 -p "$P_PXY drop=5 delay=5 duplicate=5" \
5850 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
5851 psk=abc123 debug_level=3" \
5852 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
5853 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
5854 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
5855 0 \
5856 -s "a session has been resumed" \
5857 -c "a session has been resumed" \
5858 -s "Extra-header:" \
5859 -c "HTTP/1.0 200 OK"
5860
Janos Follath74537a62016-09-02 13:45:28 +01005861client_needs_more_time 4
Manuel Pégourié-Gonnard85beb302014-10-02 17:59:19 +02005862run_test "DTLS proxy: 3d, min handshake, resumption, nbio" \
5863 -p "$P_PXY drop=5 delay=5 duplicate=5" \
5864 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
5865 psk=abc123 debug_level=3 nbio=2" \
5866 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
5867 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
5868 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
5869 0 \
5870 -s "a session has been resumed" \
5871 -c "a session has been resumed" \
5872 -s "Extra-header:" \
5873 -c "HTTP/1.0 200 OK"
5874
Janos Follath74537a62016-09-02 13:45:28 +01005875client_needs_more_time 4
Hanno Becker6a243642017-10-12 15:18:45 +01005876requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005877run_test "DTLS proxy: 3d, min handshake, client-initiated renego" \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02005878 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005879 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
5880 psk=abc123 renegotiation=1 debug_level=2" \
5881 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
5882 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02005883 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
5884 0 \
5885 -c "=> renegotiate" \
5886 -s "=> renegotiate" \
5887 -s "Extra-header:" \
5888 -c "HTTP/1.0 200 OK"
5889
Janos Follath74537a62016-09-02 13:45:28 +01005890client_needs_more_time 4
Hanno Becker6a243642017-10-12 15:18:45 +01005891requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005892run_test "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
5893 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02005894 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
5895 psk=abc123 renegotiation=1 debug_level=2" \
5896 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
5897 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005898 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
5899 0 \
5900 -c "=> renegotiate" \
5901 -s "=> renegotiate" \
5902 -s "Extra-header:" \
5903 -c "HTTP/1.0 200 OK"
5904
Janos Follath74537a62016-09-02 13:45:28 +01005905client_needs_more_time 4
Hanno Becker6a243642017-10-12 15:18:45 +01005906requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005907run_test "DTLS proxy: 3d, min handshake, server-initiated renego" \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02005908 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005909 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02005910 psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005911 debug_level=2" \
5912 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02005913 renegotiation=1 exchanges=4 debug_level=2 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005914 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
5915 0 \
5916 -c "=> renegotiate" \
5917 -s "=> renegotiate" \
5918 -s "Extra-header:" \
5919 -c "HTTP/1.0 200 OK"
5920
Janos Follath74537a62016-09-02 13:45:28 +01005921client_needs_more_time 4
Hanno Becker6a243642017-10-12 15:18:45 +01005922requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005923run_test "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02005924 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005925 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02005926 psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005927 debug_level=2 nbio=2" \
5928 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02005929 renegotiation=1 exchanges=4 debug_level=2 nbio=2 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02005930 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
5931 0 \
5932 -c "=> renegotiate" \
5933 -s "=> renegotiate" \
5934 -s "Extra-header:" \
5935 -c "HTTP/1.0 200 OK"
5936
Janos Follath74537a62016-09-02 13:45:28 +01005937client_needs_more_time 6
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02005938not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005939run_test "DTLS proxy: 3d, openssl server" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02005940 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
5941 "$O_SRV -dtls1 -mtu 2048" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00005942 "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02005943 0 \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02005944 -c "HTTP/1.0 200 OK"
5945
Janos Follath74537a62016-09-02 13:45:28 +01005946client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02005947not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005948run_test "DTLS proxy: 3d, openssl server, fragmentation" \
5949 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
5950 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00005951 "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005952 0 \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005953 -c "HTTP/1.0 200 OK"
5954
Janos Follath74537a62016-09-02 13:45:28 +01005955client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02005956not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005957run_test "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
5958 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
5959 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00005960 "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2 tickets=0" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005961 0 \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005962 -c "HTTP/1.0 200 OK"
5963
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00005964requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01005965client_needs_more_time 6
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02005966not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005967run_test "DTLS proxy: 3d, gnutls server" \
5968 -p "$P_PXY drop=5 delay=5 duplicate=5" \
5969 "$G_SRV -u --mtu 2048 -a" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02005970 "$P_CLI dtls=1 hs_timeout=250-60000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005971 0 \
5972 -s "Extra-header:" \
5973 -c "Extra-header:"
5974
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00005975requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01005976client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02005977not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005978run_test "DTLS proxy: 3d, gnutls server, fragmentation" \
5979 -p "$P_PXY drop=5 delay=5 duplicate=5" \
5980 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02005981 "$P_CLI dtls=1 hs_timeout=250-60000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02005982 0 \
5983 -s "Extra-header:" \
5984 -c "Extra-header:"
5985
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00005986requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01005987client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02005988not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005989run_test "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
5990 -p "$P_PXY drop=5 delay=5 duplicate=5" \
5991 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02005992 "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02005993 0 \
5994 -s "Extra-header:" \
5995 -c "Extra-header:"
5996
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01005997# Final report
5998
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01005999echo "------------------------------------------------------------------------"
6000
6001if [ $FAILS = 0 ]; then
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +01006002 printf "PASSED"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01006003else
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +01006004 printf "FAILED"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01006005fi
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +02006006PASSES=$(( $TESTS - $FAILS ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +02006007echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01006008
6009exit $FAILS