blob: a1155e8d0a79faea5e35c86db46d1601c02803a7 [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
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +010024# default values, can be overriden by the environment
25: ${P_SRV:=../programs/ssl/ssl_server2}
26: ${P_CLI:=../programs/ssl/ssl_client2}
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +020027: ${P_PXY:=../programs/test/udp_proxy}
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +010028: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020029: ${GNUTLS_CLI:=gnutls-cli}
30: ${GNUTLS_SERV:=gnutls-serv}
Gilles Peskined50177f2017-05-16 17:53:03 +020031: ${PERL:=perl}
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +010032
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +020033O_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 +010034O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +020035G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +010036G_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_CLI --x509cafile data_files/test-ca_cat12.crt"
Gilles Peskined50177f2017-05-16 17:53:03 +020037TCP_CLIENT="$PERL scripts/tcp_client.pl"
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +010038
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010039TESTS=0
40FAILS=0
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020041SKIPS=0
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +010042
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000043CONFIG_H='../include/mbedtls/config.h'
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +020044
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010045MEMCHECK=0
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010046FILTER='.*'
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +020047EXCLUDE='^$'
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010048
Paul Bakkere20310a2016-05-10 11:18:17 +010049SHOW_TEST_NUMBER=0
Paul Bakkerb7584a52016-05-10 10:50:43 +010050RUN_TEST_NUMBER=''
51
Paul Bakkeracaac852016-05-10 11:47:13 +010052PRESERVE_LOGS=0
53
Gilles Peskinef93c7d32017-04-14 17:55:28 +020054# Pick a "unique" server port in the range 10000-19999, and a proxy
55# port which is this plus 10000. Each port number may be independently
56# overridden by a command line option.
57SRV_PORT=$(($$ % 10000 + 10000))
58PXY_PORT=$((SRV_PORT + 10000))
59
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010060print_usage() {
61 echo "Usage: $0 [options]"
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +010062 printf " -h|--help\tPrint this help.\n"
63 printf " -m|--memcheck\tCheck memory leaks and errors.\n"
Gilles Peskinef93c7d32017-04-14 17:55:28 +020064 printf " -f|--filter\tOnly matching tests are executed (BRE; default: '$FILTER')\n"
65 printf " -e|--exclude\tMatching tests are excluded (BRE; default: '$EXCLUDE')\n"
Paul Bakkerb7584a52016-05-10 10:50:43 +010066 printf " -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
Paul Bakkere20310a2016-05-10 11:18:17 +010067 printf " -s|--show-numbers\tShow test numbers in front of test names\n"
Paul Bakkeracaac852016-05-10 11:47:13 +010068 printf " -p|--preserve-logs\tPreserve logs of successful tests as well\n"
Gilles Peskinef93c7d32017-04-14 17:55:28 +020069 printf " --port\tTCP/UDP port (default: randomish 1xxxx)\n"
70 printf " --proxy-port\tTCP/UDP proxy port (default: randomish 2xxxx)\n"
Andres AGf04f54d2016-10-10 15:46:20 +010071 printf " --seed\tInteger seed value to use for this test run\n"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010072}
73
74get_options() {
75 while [ $# -gt 0 ]; do
76 case "$1" in
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +010077 -f|--filter)
78 shift; FILTER=$1
79 ;;
80 -e|--exclude)
81 shift; EXCLUDE=$1
82 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +010083 -m|--memcheck)
84 MEMCHECK=1
85 ;;
Paul Bakkerb7584a52016-05-10 10:50:43 +010086 -n|--number)
87 shift; RUN_TEST_NUMBER=$1
88 ;;
Paul Bakkere20310a2016-05-10 11:18:17 +010089 -s|--show-numbers)
90 SHOW_TEST_NUMBER=1
91 ;;
Paul Bakkeracaac852016-05-10 11:47:13 +010092 -p|--preserve-logs)
93 PRESERVE_LOGS=1
94 ;;
Gilles Peskinef93c7d32017-04-14 17:55:28 +020095 --port)
96 shift; SRV_PORT=$1
97 ;;
98 --proxy-port)
99 shift; PXY_PORT=$1
100 ;;
Andres AGf04f54d2016-10-10 15:46:20 +0100101 --seed)
102 shift; SEED="$1"
103 ;;
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100104 -h|--help)
105 print_usage
106 exit 0
107 ;;
108 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200109 echo "Unknown argument: '$1'"
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100110 print_usage
111 exit 1
112 ;;
113 esac
114 shift
115 done
116}
117
Manuel Pégourié-Gonnard988209f2015-03-24 10:43:55 +0100118# skip next test if the flag is not enabled in config.h
119requires_config_enabled() {
120 if grep "^#define $1" $CONFIG_H > /dev/null; then :; else
121 SKIP_NEXT="YES"
122 fi
123}
124
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200125# skip next test if the flag is enabled in config.h
126requires_config_disabled() {
127 if grep "^#define $1" $CONFIG_H > /dev/null; then
128 SKIP_NEXT="YES"
129 fi
130}
131
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200132# skip next test if OpenSSL doesn't support FALLBACK_SCSV
133requires_openssl_with_fallback_scsv() {
134 if [ -z "${OPENSSL_HAS_FBSCSV:-}" ]; then
135 if $OPENSSL_CMD s_client -help 2>&1 | grep fallback_scsv >/dev/null
136 then
137 OPENSSL_HAS_FBSCSV="YES"
138 else
139 OPENSSL_HAS_FBSCSV="NO"
140 fi
141 fi
142 if [ "$OPENSSL_HAS_FBSCSV" = "NO" ]; then
143 SKIP_NEXT="YES"
144 fi
145}
146
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200147# skip next test if GnuTLS isn't available
148requires_gnutls() {
149 if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
Manuel Pégourié-Gonnard03db6b02015-06-26 15:45:30 +0200150 if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null 2>&1; then
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +0200151 GNUTLS_AVAILABLE="YES"
152 else
153 GNUTLS_AVAILABLE="NO"
154 fi
155 fi
156 if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
157 SKIP_NEXT="YES"
158 fi
159}
160
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200161# skip next test if IPv6 isn't available on this host
162requires_ipv6() {
163 if [ -z "${HAS_IPV6:-}" ]; then
164 $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
165 SRV_PID=$!
166 sleep 1
167 kill $SRV_PID >/dev/null 2>&1
168 if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
169 HAS_IPV6="NO"
170 else
171 HAS_IPV6="YES"
172 fi
173 rm -r $SRV_OUT
174 fi
175
176 if [ "$HAS_IPV6" = "NO" ]; then
177 SKIP_NEXT="YES"
178 fi
179}
180
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +0200181# skip the next test if valgrind is in use
182not_with_valgrind() {
183 if [ "$MEMCHECK" -gt 0 ]; then
184 SKIP_NEXT="YES"
185 fi
186}
187
Paul Bakker362689d2016-05-13 10:33:25 +0100188# skip the next test if valgrind is NOT in use
189only_with_valgrind() {
190 if [ "$MEMCHECK" -eq 0 ]; then
191 SKIP_NEXT="YES"
192 fi
193}
194
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200195# multiply the client timeout delay by the given factor for the next test
Janos Follath74537a62016-09-02 13:45:28 +0100196client_needs_more_time() {
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200197 CLI_DELAY_FACTOR=$1
198}
199
Janos Follath74537a62016-09-02 13:45:28 +0100200# wait for the given seconds after the client finished in the next test
201server_needs_more_time() {
202 SRV_DELAY_SECONDS=$1
203}
204
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100205# print_name <name>
206print_name() {
Paul Bakkere20310a2016-05-10 11:18:17 +0100207 TESTS=$(( $TESTS + 1 ))
208 LINE=""
209
210 if [ "$SHOW_TEST_NUMBER" -gt 0 ]; then
211 LINE="$TESTS "
212 fi
213
214 LINE="$LINE$1"
215 printf "$LINE "
216 LEN=$(( 72 - `echo "$LINE" | wc -c` ))
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +0100217 for i in `seq 1 $LEN`; do printf '.'; done
218 printf ' '
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100219
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100220}
221
222# fail <message>
223fail() {
224 echo "FAIL"
Manuel Pégourié-Gonnard3eec6042014-02-27 15:37:24 +0100225 echo " ! $1"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100226
Manuel Pégourié-Gonnardc2b00922014-08-31 16:46:04 +0200227 mv $SRV_OUT o-srv-${TESTS}.log
228 mv $CLI_OUT o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200229 if [ -n "$PXY_CMD" ]; then
230 mv $PXY_OUT o-pxy-${TESTS}.log
231 fi
232 echo " ! outputs saved to o-XXX-${TESTS}.log"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +0100233
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200234 if [ "X${USER:-}" = Xbuildbot -o "X${LOGNAME:-}" = Xbuildbot ]; then
235 echo " ! server output:"
236 cat o-srv-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200237 echo " ! ========================================================"
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200238 echo " ! client output:"
239 cat o-cli-${TESTS}.log
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200240 if [ -n "$PXY_CMD" ]; then
241 echo " ! ========================================================"
242 echo " ! proxy output:"
243 cat o-pxy-${TESTS}.log
244 fi
245 echo ""
Manuel Pégourié-Gonnard7fa67722014-08-31 17:42:53 +0200246 fi
247
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200248 FAILS=$(( $FAILS + 1 ))
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100249}
250
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100251# is_polar <cmd_line>
252is_polar() {
253 echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
254}
255
Manuel Pégourié-Gonnardfa60f122014-09-26 16:07:29 +0200256# openssl s_server doesn't have -www with DTLS
257check_osrv_dtls() {
258 if echo "$SRV_CMD" | grep 's_server.*-dtls' >/dev/null; then
259 NEEDS_INPUT=1
260 SRV_CMD="$( echo $SRV_CMD | sed s/-www// )"
261 else
262 NEEDS_INPUT=0
263 fi
264}
265
266# provide input to commands that need it
267provide_input() {
268 if [ $NEEDS_INPUT -eq 0 ]; then
269 return
270 fi
271
272 while true; do
273 echo "HTTP/1.0 200 OK"
274 sleep 1
275 done
276}
277
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100278# has_mem_err <log_file_name>
279has_mem_err() {
280 if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
281 grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
282 then
283 return 1 # false: does not have errors
284 else
285 return 0 # true: has errors
286 fi
287}
288
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200289# wait for server to start: two versions depending on lsof availability
290wait_server_start() {
Manuel Pégourié-Gonnard03db6b02015-06-26 15:45:30 +0200291 if which lsof >/dev/null 2>&1; then
Manuel Pégourié-Gonnard74681fa2015-08-04 20:34:39 +0200292 START_TIME=$( date +%s )
293 DONE=0
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200294
295 # make a tight loop, server usually takes less than 1 sec to start
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200296 if [ "$DTLS" -eq 1 ]; then
Manuel Pégourié-Gonnard74681fa2015-08-04 20:34:39 +0200297 while [ $DONE -eq 0 ]; do
298 if lsof -nbi UDP:"$SRV_PORT" 2>/dev/null | grep UDP >/dev/null
299 then
300 DONE=1
301 elif [ $(( $( date +%s ) - $START_TIME )) -gt $DOG_DELAY ]; then
302 echo "SERVERSTART TIMEOUT"
303 echo "SERVERSTART TIMEOUT" >> $SRV_OUT
304 DONE=1
305 fi
306 done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200307 else
Manuel Pégourié-Gonnard74681fa2015-08-04 20:34:39 +0200308 while [ $DONE -eq 0 ]; do
309 if lsof -nbi TCP:"$SRV_PORT" 2>/dev/null | grep LISTEN >/dev/null
310 then
311 DONE=1
312 elif [ $(( $( date +%s ) - $START_TIME )) -gt $DOG_DELAY ]; then
313 echo "SERVERSTART TIMEOUT"
314 echo "SERVERSTART TIMEOUT" >> $SRV_OUT
315 DONE=1
316 fi
317 done
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200318 fi
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200319 else
320 sleep "$START_DELAY"
321 fi
322}
323
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200324# wait for client to terminate and set CLI_EXIT
325# must be called right after starting the client
326wait_client_done() {
327 CLI_PID=$!
328
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200329 CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
330 CLI_DELAY_FACTOR=1
331
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200332 ( sleep $CLI_DELAY; echo "===CLIENT_TIMEOUT===" >> $CLI_OUT; kill $CLI_PID ) &
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200333 DOG_PID=$!
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200334
335 wait $CLI_PID
336 CLI_EXIT=$?
337
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200338 kill $DOG_PID >/dev/null 2>&1
339 wait $DOG_PID
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200340
341 echo "EXIT: $CLI_EXIT" >> $CLI_OUT
Janos Follath74537a62016-09-02 13:45:28 +0100342
343 sleep $SRV_DELAY_SECONDS
344 SRV_DELAY_SECONDS=0
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200345}
346
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200347# check if the given command uses dtls and sets global variable DTLS
348detect_dtls() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200349 if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200350 DTLS=1
351 else
352 DTLS=0
353 fi
354}
355
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200356# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100357# Options: -s pattern pattern that must be present in server output
358# -c pattern pattern that must be present in client output
Simon Butcher8e004102016-10-14 00:48:33 +0100359# -u pattern lines after pattern must be unique in client output
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100360# -S pattern pattern that must be absent in server output
361# -C pattern pattern that must be absent in client output
Simon Butcher8e004102016-10-14 00:48:33 +0100362# -U pattern lines after pattern must be unique in server output
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100363run_test() {
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100364 NAME="$1"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200365 shift 1
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100366
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100367 if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
368 else
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +0200369 SKIP_NEXT="NO"
Manuel Pégourié-Gonnard417d46c2014-03-13 19:17:53 +0100370 return
371 fi
372
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100373 print_name "$NAME"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100374
Paul Bakkerb7584a52016-05-10 10:50:43 +0100375 # Do we only run numbered tests?
376 if [ "X$RUN_TEST_NUMBER" = "X" ]; then :
377 elif echo ",$RUN_TEST_NUMBER," | grep ",$TESTS," >/dev/null; then :
378 else
379 SKIP_NEXT="YES"
380 fi
381
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200382 # should we skip?
383 if [ "X$SKIP_NEXT" = "XYES" ]; then
384 SKIP_NEXT="NO"
385 echo "SKIP"
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +0200386 SKIPS=$(( $SKIPS + 1 ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200387 return
388 fi
389
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200390 # does this test use a proxy?
391 if [ "X$1" = "X-p" ]; then
392 PXY_CMD="$2"
393 shift 2
394 else
395 PXY_CMD=""
396 fi
397
398 # get commands and client output
399 SRV_CMD="$1"
400 CLI_CMD="$2"
401 CLI_EXPECT="$3"
402 shift 3
403
404 # fix client port
405 if [ -n "$PXY_CMD" ]; then
406 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
407 else
408 CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
409 fi
410
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200411 # update DTLS variable
412 detect_dtls "$SRV_CMD"
413
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100414 # prepend valgrind to our commands if active
415 if [ "$MEMCHECK" -gt 0 ]; then
416 if is_polar "$SRV_CMD"; then
417 SRV_CMD="valgrind --leak-check=full $SRV_CMD"
418 fi
419 if is_polar "$CLI_CMD"; then
420 CLI_CMD="valgrind --leak-check=full $CLI_CMD"
421 fi
422 fi
423
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200424 TIMES_LEFT=2
425 while [ $TIMES_LEFT -gt 0 ]; do
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200426 TIMES_LEFT=$(( $TIMES_LEFT - 1 ))
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200427
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200428 # run the commands
429 if [ -n "$PXY_CMD" ]; then
430 echo "$PXY_CMD" > $PXY_OUT
431 $PXY_CMD >> $PXY_OUT 2>&1 &
432 PXY_PID=$!
433 # assume proxy starts faster than server
434 fi
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200435
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200436 check_osrv_dtls
437 echo "$SRV_CMD" > $SRV_OUT
438 provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
439 SRV_PID=$!
440 wait_server_start
Manuel Pégourié-Gonnardc0f6a692014-08-30 22:41:47 +0200441
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200442 echo "$CLI_CMD" > $CLI_OUT
443 eval "$CLI_CMD" >> $CLI_OUT 2>&1 &
444 wait_client_done
Manuel Pégourié-Gonnarde01af4c2014-03-25 14:16:44 +0100445
Hanno Beckercadb5bb2017-05-26 13:56:10 +0100446 sleep 0.05
447
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200448 # terminate the server (and the proxy)
449 kill $SRV_PID
Hanno Beckerd82d8462017-05-29 21:37:46 +0100450 sleep 0.01
451 if kill -0 $SRV_PID >/dev/null 2>&1; then
Hanno Becker7b6582b2018-03-15 09:37:27 +0000452 kill -3 $SRV_PID
Hanno Beckerd82d8462017-05-29 21:37:46 +0100453 wait $SRV_PID
454 fi
455
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200456 if [ -n "$PXY_CMD" ]; then
457 kill $PXY_PID >/dev/null 2>&1
Hanno Beckerd82d8462017-05-29 21:37:46 +0100458 sleep 0.01
459 if kill -0 $PXY_PID >/dev/null 2>&1; then
Hanno Becker7b6582b2018-03-15 09:37:27 +0000460 kill -3 $PXY_PID
Hanno Beckerd82d8462017-05-29 21:37:46 +0100461 wait $PXY_PID
462 fi
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200463 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100464
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200465 # retry only on timeouts
466 if grep '===CLIENT_TIMEOUT===' $CLI_OUT >/dev/null; then
467 printf "RETRY "
468 else
469 TIMES_LEFT=0
470 fi
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200471 done
472
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100473 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200474 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100475 # expected client exit to incorrectly succeed in case of catastrophic
476 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100477 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200478 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100479 else
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100480 fail "server or client failed to reach handshake stage"
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100481 return
482 fi
483 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100484 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200485 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100486 else
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100487 fail "server or client failed to reach handshake stage"
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100488 return
489 fi
490 fi
491
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100492 # check server exit code
493 if [ $? != 0 ]; then
494 fail "server fail"
495 return
496 fi
497
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100498 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100499 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
500 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100501 then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200502 fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100503 return
504 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100505
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100506 # check other assertions
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200507 # lines beginning with == are added by valgrind, ignore them
Paul Bakker1f650922016-05-13 10:16:46 +0100508 # lines with 'Serious error when reading debug info', are valgrind issues as well
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100509 while [ $# -gt 0 ]
510 do
511 case $1 in
512 "-s")
Paul Bakker1f650922016-05-13 10:16:46 +0100513 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 +0100514 fail "pattern '$2' MUST be present in the Server output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100515 return
516 fi
517 ;;
518
519 "-c")
Paul Bakker1f650922016-05-13 10:16:46 +0100520 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 +0100521 fail "pattern '$2' MUST be present in the Client output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100522 return
523 fi
524 ;;
525
526 "-S")
Paul Bakker1f650922016-05-13 10:16:46 +0100527 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 +0100528 fail "pattern '$2' MUST NOT be present in the Server output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100529 return
530 fi
531 ;;
532
533 "-C")
Paul Bakker1f650922016-05-13 10:16:46 +0100534 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 +0100535 fail "pattern '$2' MUST NOT be present in the Client output"
536 return
537 fi
538 ;;
539
540 # The filtering in the following two options (-u and -U) do the following
541 # - ignore valgrind output
542 # - filter out everything but lines right after the pattern occurances
543 # - keep one of each non-unique line
544 # - count how many lines remain
545 # A line with '--' will remain in the result from previous outputs, so the number of lines in the result will be 1
546 # if there were no duplicates.
547 "-U")
548 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
549 fail "lines following pattern '$2' must be unique in Server output"
550 return
551 fi
552 ;;
553
554 "-u")
555 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
556 fail "lines following pattern '$2' must be unique in Client output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100557 return
558 fi
559 ;;
560
561 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200562 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100563 exit 1
564 esac
565 shift 2
566 done
567
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100568 # check valgrind's results
569 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200570 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100571 fail "Server has memory errors"
572 return
573 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200574 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100575 fail "Client has memory errors"
576 return
577 fi
578 fi
579
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100580 # if we're here, everything is ok
581 echo "PASS"
Paul Bakkeracaac852016-05-10 11:47:13 +0100582 if [ "$PRESERVE_LOGS" -gt 0 ]; then
583 mv $SRV_OUT o-srv-${TESTS}.log
584 mv $CLI_OUT o-cli-${TESTS}.log
585 fi
586
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200587 rm -f $SRV_OUT $CLI_OUT $PXY_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100588}
589
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100590cleanup() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200591 rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200592 test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
593 test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
594 test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
595 test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100596 exit 1
597}
598
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100599#
600# MAIN
601#
602
Manuel Pégourié-Gonnard19db8ea2015-03-10 13:41:04 +0000603if cd $( dirname $0 ); then :; else
604 echo "cd $( dirname $0 ) failed" >&2
605 exit 1
606fi
607
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100608get_options "$@"
609
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100610# sanity checks, avoid an avalanche of errors
Hanno Becker4ac73e72017-10-23 15:27:37 +0100611P_SRV_BIN="${P_SRV%%[ ]*}"
612P_CLI_BIN="${P_CLI%%[ ]*}"
613P_PXY_BIN="${P_PXY%%[ ]*}"
Hanno Becker17c04932017-10-10 14:44:53 +0100614if [ ! -x "$P_SRV_BIN" ]; then
615 echo "Command '$P_SRV_BIN' is not an executable file"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100616 exit 1
617fi
Hanno Becker17c04932017-10-10 14:44:53 +0100618if [ ! -x "$P_CLI_BIN" ]; then
619 echo "Command '$P_CLI_BIN' is not an executable file"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100620 exit 1
621fi
Hanno Becker17c04932017-10-10 14:44:53 +0100622if [ ! -x "$P_PXY_BIN" ]; then
623 echo "Command '$P_PXY_BIN' is not an executable file"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200624 exit 1
625fi
Simon Butcher3c0d7b82016-05-23 11:13:17 +0100626if [ "$MEMCHECK" -gt 0 ]; then
627 if which valgrind >/dev/null 2>&1; then :; else
628 echo "Memcheck not possible. Valgrind not found"
629 exit 1
630 fi
631fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100632if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
633 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100634 exit 1
635fi
636
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200637# used by watchdog
638MAIN_PID="$$"
639
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200640# be more patient with valgrind
641if [ "$MEMCHECK" -gt 0 ]; then
642 START_DELAY=3
643 DOG_DELAY=30
644else
645 START_DELAY=1
646 DOG_DELAY=10
647fi
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200648CLI_DELAY_FACTOR=1
Janos Follath74537a62016-09-02 13:45:28 +0100649SRV_DELAY_SECONDS=0
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200650
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200651# fix commands to use this port, force IPv4 while at it
Manuel Pégourié-Gonnard0af1ba32015-01-21 11:44:33 +0000652# +SRV_PORT will be replaced by either $SRV_PORT or $PXY_PORT later
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200653P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
654P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
Andres AGf04f54d2016-10-10 15:46:20 +0100655P_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 +0200656O_SRV="$O_SRV -accept $SRV_PORT -dhparam data_files/dhparams.pem"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200657O_CLI="$O_CLI -connect localhost:+SRV_PORT"
658G_SRV="$G_SRV -p $SRV_PORT"
Manuel Pégourié-Gonnard0af1ba32015-01-21 11:44:33 +0000659G_CLI="$G_CLI -p +SRV_PORT localhost"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200660
Gilles Peskine62469d92017-05-10 10:13:59 +0200661# Allow SHA-1, because many of our test certificates use it
662P_SRV="$P_SRV allow_sha1=1"
663P_CLI="$P_CLI allow_sha1=1"
664
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200665# Also pick a unique name for intermediate files
666SRV_OUT="srv_out.$$"
667CLI_OUT="cli_out.$$"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200668PXY_OUT="pxy_out.$$"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200669SESSION="session.$$"
670
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200671SKIP_NEXT="NO"
672
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100673trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100674
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200675# Basic test
676
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200677# Checks that:
678# - things work with all ciphersuites active (used with config-full in all.sh)
679# - the expected (highest security) parameters are selected
680# ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200681run_test "Default" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200682 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200683 "$P_CLI" \
684 0 \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200685 -s "Protocol is TLSv1.2" \
686 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
687 -s "client hello v3, signature_algorithm ext: 6" \
688 -s "ECDHE curve: secp521r1" \
689 -S "error" \
690 -C "error"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200691
Manuel Pégourié-Gonnard3bb08012015-01-22 13:34:21 +0000692run_test "Default, DTLS" \
693 "$P_SRV dtls=1" \
694 "$P_CLI dtls=1" \
695 0 \
696 -s "Protocol is DTLSv1.2" \
697 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384"
698
Simon Butcher8e004102016-10-14 00:48:33 +0100699# Test for uniqueness of IVs in AEAD ciphersuites
700run_test "Unique IV in GCM" \
701 "$P_SRV exchanges=20 debug_level=4" \
702 "$P_CLI exchanges=20 debug_level=4 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
703 0 \
704 -u "IV used" \
705 -U "IV used"
706
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100707# Tests for rc4 option
708
Simon Butchera410af52016-05-19 22:12:18 +0100709requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100710run_test "RC4: server disabled, client enabled" \
711 "$P_SRV" \
712 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
713 1 \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100714 -s "SSL - The server has no ciphersuites in common"
715
Simon Butchera410af52016-05-19 22:12:18 +0100716requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100717run_test "RC4: server half, client enabled" \
718 "$P_SRV arc4=1" \
719 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
720 1 \
721 -s "SSL - The server has no ciphersuites in common"
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100722
723run_test "RC4: server enabled, client disabled" \
724 "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
725 "$P_CLI" \
726 1 \
727 -s "SSL - The server has no ciphersuites in common"
728
729run_test "RC4: both enabled" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100730 "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100731 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
732 0 \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100733 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100734 -S "SSL - The server has no ciphersuites in common"
735
Gilles Peskinebc70a182017-05-09 15:59:24 +0200736# Tests for SHA-1 support
737
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200738requires_config_disabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinebc70a182017-05-09 15:59:24 +0200739run_test "SHA-1 forbidden by default in server certificate" \
740 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
741 "$P_CLI debug_level=2 allow_sha1=0" \
742 1 \
743 -c "The certificate is signed with an unacceptable hash"
744
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200745requires_config_enabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
746run_test "SHA-1 forbidden by default in server certificate" \
747 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
748 "$P_CLI debug_level=2 allow_sha1=0" \
749 0
750
Gilles Peskinebc70a182017-05-09 15:59:24 +0200751run_test "SHA-1 explicitly allowed in server certificate" \
752 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
753 "$P_CLI allow_sha1=1" \
754 0
755
756run_test "SHA-256 allowed by default in server certificate" \
757 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2-sha256.crt" \
758 "$P_CLI allow_sha1=0" \
759 0
760
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200761requires_config_disabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinebc70a182017-05-09 15:59:24 +0200762run_test "SHA-1 forbidden by default in client certificate" \
763 "$P_SRV auth_mode=required allow_sha1=0" \
764 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
765 1 \
766 -s "The certificate is signed with an unacceptable hash"
767
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200768requires_config_enabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
769run_test "SHA-1 forbidden by default in client certificate" \
770 "$P_SRV auth_mode=required allow_sha1=0" \
771 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
772 0
773
Gilles Peskinebc70a182017-05-09 15:59:24 +0200774run_test "SHA-1 explicitly allowed in client certificate" \
775 "$P_SRV auth_mode=required allow_sha1=1" \
776 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
777 0
778
779run_test "SHA-256 allowed by default in client certificate" \
780 "$P_SRV auth_mode=required allow_sha1=0" \
781 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha256.crt" \
782 0
783
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100784# Tests for Truncated HMAC extension
785
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100786run_test "Truncated HMAC: client default, server default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200787 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100788 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100789 0 \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100790 -s "dumping 'computed mac' (20 bytes)" \
791 -S "dumping 'computed mac' (10 bytes)"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100792
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100793run_test "Truncated HMAC: client disabled, server default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200794 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100795 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
796 trunc_hmac=0" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100797 0 \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100798 -s "dumping 'computed mac' (20 bytes)" \
799 -S "dumping 'computed mac' (10 bytes)"
800
801run_test "Truncated HMAC: client enabled, server default" \
802 "$P_SRV debug_level=4" \
803 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
804 trunc_hmac=1" \
805 0 \
Manuel Pégourié-Gonnard662c6e82015-05-06 17:39:23 +0100806 -s "dumping 'computed mac' (20 bytes)" \
807 -S "dumping 'computed mac' (10 bytes)"
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100808
809run_test "Truncated HMAC: client enabled, server disabled" \
810 "$P_SRV debug_level=4 trunc_hmac=0" \
811 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
812 trunc_hmac=1" \
813 0 \
814 -s "dumping 'computed mac' (20 bytes)" \
815 -S "dumping 'computed mac' (10 bytes)"
816
817run_test "Truncated HMAC: client enabled, server enabled" \
818 "$P_SRV debug_level=4 trunc_hmac=1" \
819 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
820 trunc_hmac=1" \
821 0 \
822 -S "dumping 'computed mac' (20 bytes)" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100823 -s "dumping 'computed mac' (10 bytes)"
824
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100825# Tests for Encrypt-then-MAC extension
826
827run_test "Encrypt then MAC: default" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100828 "$P_SRV debug_level=3 \
829 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100830 "$P_CLI debug_level=3" \
831 0 \
832 -c "client hello, adding encrypt_then_mac extension" \
833 -s "found encrypt then mac extension" \
834 -s "server hello, adding encrypt then mac extension" \
835 -c "found encrypt_then_mac extension" \
836 -c "using encrypt then mac" \
837 -s "using encrypt then mac"
838
839run_test "Encrypt then MAC: client enabled, server disabled" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100840 "$P_SRV debug_level=3 etm=0 \
841 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100842 "$P_CLI debug_level=3 etm=1" \
843 0 \
844 -c "client hello, adding encrypt_then_mac extension" \
845 -s "found encrypt then mac extension" \
846 -S "server hello, adding encrypt then mac extension" \
847 -C "found encrypt_then_mac extension" \
848 -C "using encrypt then mac" \
849 -S "using encrypt then mac"
850
Manuel Pégourié-Gonnard78e745f2014-11-04 15:44:06 +0100851run_test "Encrypt then MAC: client enabled, aead cipher" \
852 "$P_SRV debug_level=3 etm=1 \
853 force_ciphersuite=TLS-RSA-WITH-AES-128-GCM-SHA256" \
854 "$P_CLI debug_level=3 etm=1" \
855 0 \
856 -c "client hello, adding encrypt_then_mac extension" \
857 -s "found encrypt then mac extension" \
858 -S "server hello, adding encrypt then mac extension" \
859 -C "found encrypt_then_mac extension" \
860 -C "using encrypt then mac" \
861 -S "using encrypt then mac"
862
863run_test "Encrypt then MAC: client enabled, stream cipher" \
864 "$P_SRV debug_level=3 etm=1 \
865 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100866 "$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 +0100867 0 \
868 -c "client hello, adding encrypt_then_mac extension" \
869 -s "found encrypt then mac extension" \
870 -S "server hello, adding encrypt then mac extension" \
871 -C "found encrypt_then_mac extension" \
872 -C "using encrypt then mac" \
873 -S "using encrypt then mac"
874
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100875run_test "Encrypt then MAC: client disabled, server enabled" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100876 "$P_SRV debug_level=3 etm=1 \
877 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100878 "$P_CLI debug_level=3 etm=0" \
879 0 \
880 -C "client hello, adding encrypt_then_mac extension" \
881 -S "found encrypt then mac extension" \
882 -S "server hello, adding encrypt then mac extension" \
883 -C "found encrypt_then_mac extension" \
884 -C "using encrypt then mac" \
885 -S "using encrypt then mac"
886
Janos Follathe2681a42016-03-07 15:57:05 +0000887requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100888run_test "Encrypt then MAC: client SSLv3, server enabled" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100889 "$P_SRV debug_level=3 min_version=ssl3 \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100890 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100891 "$P_CLI debug_level=3 force_version=ssl3" \
892 0 \
893 -C "client hello, adding encrypt_then_mac extension" \
894 -S "found encrypt then mac extension" \
895 -S "server hello, adding encrypt then mac extension" \
896 -C "found encrypt_then_mac extension" \
897 -C "using encrypt then mac" \
898 -S "using encrypt then mac"
899
Janos Follathe2681a42016-03-07 15:57:05 +0000900requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100901run_test "Encrypt then MAC: client enabled, server SSLv3" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100902 "$P_SRV debug_level=3 force_version=ssl3 \
903 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100904 "$P_CLI debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100905 0 \
906 -c "client hello, adding encrypt_then_mac extension" \
Janos Follath00efff72016-05-06 13:48:23 +0100907 -S "found encrypt then mac extension" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100908 -S "server hello, adding encrypt then mac extension" \
909 -C "found encrypt_then_mac extension" \
910 -C "using encrypt then mac" \
911 -S "using encrypt then mac"
912
Manuel Pégourié-Gonnard367381f2014-10-20 18:40:56 +0200913# Tests for Extended Master Secret extension
914
915run_test "Extended Master Secret: default" \
916 "$P_SRV debug_level=3" \
917 "$P_CLI debug_level=3" \
918 0 \
919 -c "client hello, adding extended_master_secret extension" \
920 -s "found extended master secret extension" \
921 -s "server hello, adding extended master secret extension" \
922 -c "found extended_master_secret extension" \
923 -c "using extended master secret" \
924 -s "using extended master secret"
925
926run_test "Extended Master Secret: client enabled, server disabled" \
927 "$P_SRV debug_level=3 extended_ms=0" \
928 "$P_CLI debug_level=3 extended_ms=1" \
929 0 \
930 -c "client hello, adding extended_master_secret extension" \
931 -s "found extended master secret extension" \
932 -S "server hello, adding extended master secret extension" \
933 -C "found extended_master_secret extension" \
934 -C "using extended master secret" \
935 -S "using extended master secret"
936
937run_test "Extended Master Secret: client disabled, server enabled" \
938 "$P_SRV debug_level=3 extended_ms=1" \
939 "$P_CLI debug_level=3 extended_ms=0" \
940 0 \
941 -C "client hello, adding extended_master_secret extension" \
942 -S "found extended master secret extension" \
943 -S "server hello, adding extended master secret extension" \
944 -C "found extended_master_secret extension" \
945 -C "using extended master secret" \
946 -S "using extended master secret"
947
Janos Follathe2681a42016-03-07 15:57:05 +0000948requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200949run_test "Extended Master Secret: client SSLv3, server enabled" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100950 "$P_SRV debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200951 "$P_CLI debug_level=3 force_version=ssl3" \
952 0 \
953 -C "client hello, adding extended_master_secret extension" \
954 -S "found extended master secret extension" \
955 -S "server hello, adding extended master secret extension" \
956 -C "found extended_master_secret extension" \
957 -C "using extended master secret" \
958 -S "using extended master secret"
959
Janos Follathe2681a42016-03-07 15:57:05 +0000960requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200961run_test "Extended Master Secret: client enabled, server SSLv3" \
962 "$P_SRV debug_level=3 force_version=ssl3" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100963 "$P_CLI debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200964 0 \
965 -c "client hello, adding extended_master_secret extension" \
Janos Follath00efff72016-05-06 13:48:23 +0100966 -S "found extended master secret extension" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200967 -S "server hello, adding extended master secret extension" \
968 -C "found extended_master_secret extension" \
969 -C "using extended master secret" \
970 -S "using extended master secret"
971
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200972# Tests for FALLBACK_SCSV
973
974run_test "Fallback SCSV: default" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +0200975 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200976 "$P_CLI debug_level=3 force_version=tls1_1" \
977 0 \
978 -C "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200979 -S "received FALLBACK_SCSV" \
980 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200981 -C "is a fatal alert message (msg 86)"
982
983run_test "Fallback SCSV: explicitly disabled" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +0200984 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200985 "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
986 0 \
987 -C "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200988 -S "received FALLBACK_SCSV" \
989 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200990 -C "is a fatal alert message (msg 86)"
991
992run_test "Fallback SCSV: enabled" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +0200993 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200994 "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200995 1 \
996 -c "adding FALLBACK_SCSV" \
997 -s "received FALLBACK_SCSV" \
998 -s "inapropriate fallback" \
999 -c "is a fatal alert message (msg 86)"
1000
1001run_test "Fallback SCSV: enabled, max version" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001002 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001003 "$P_CLI debug_level=3 fallback=1" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001004 0 \
1005 -c "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001006 -s "received FALLBACK_SCSV" \
1007 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001008 -C "is a fatal alert message (msg 86)"
1009
1010requires_openssl_with_fallback_scsv
1011run_test "Fallback SCSV: default, openssl server" \
1012 "$O_SRV" \
1013 "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
1014 0 \
1015 -C "adding FALLBACK_SCSV" \
1016 -C "is a fatal alert message (msg 86)"
1017
1018requires_openssl_with_fallback_scsv
1019run_test "Fallback SCSV: enabled, openssl server" \
1020 "$O_SRV" \
1021 "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
1022 1 \
1023 -c "adding FALLBACK_SCSV" \
1024 -c "is a fatal alert message (msg 86)"
1025
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001026requires_openssl_with_fallback_scsv
1027run_test "Fallback SCSV: disabled, openssl client" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001028 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001029 "$O_CLI -tls1_1" \
1030 0 \
1031 -S "received FALLBACK_SCSV" \
1032 -S "inapropriate fallback"
1033
1034requires_openssl_with_fallback_scsv
1035run_test "Fallback SCSV: enabled, openssl client" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001036 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001037 "$O_CLI -tls1_1 -fallback_scsv" \
1038 1 \
1039 -s "received FALLBACK_SCSV" \
1040 -s "inapropriate fallback"
1041
1042requires_openssl_with_fallback_scsv
1043run_test "Fallback SCSV: enabled, max version, openssl client" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001044 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001045 "$O_CLI -fallback_scsv" \
1046 0 \
1047 -s "received FALLBACK_SCSV" \
1048 -S "inapropriate fallback"
1049
Gilles Peskined50177f2017-05-16 17:53:03 +02001050## ClientHello generated with
1051## "openssl s_client -CAfile tests/data_files/test-ca.crt -tls1_1 -connect localhost:4433 -cipher ..."
1052## then manually twiddling the ciphersuite list.
1053## The ClientHello content is spelled out below as a hex string as
1054## "prefix ciphersuite1 ciphersuite2 ciphersuite3 ciphersuite4 suffix".
1055## The expected response is an inappropriate_fallback alert.
1056requires_openssl_with_fallback_scsv
1057run_test "Fallback SCSV: beginning of list" \
1058 "$P_SRV debug_level=2" \
1059 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 5600 0031 0032 0033 0100000900230000000f000101' '15030200020256'" \
1060 0 \
1061 -s "received FALLBACK_SCSV" \
1062 -s "inapropriate fallback"
1063
1064requires_openssl_with_fallback_scsv
1065run_test "Fallback SCSV: end of list" \
1066 "$P_SRV debug_level=2" \
1067 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 0031 0032 0033 5600 0100000900230000000f000101' '15030200020256'" \
1068 0 \
1069 -s "received FALLBACK_SCSV" \
1070 -s "inapropriate fallback"
1071
1072## Here the expected response is a valid ServerHello prefix, up to the random.
1073requires_openssl_with_fallback_scsv
1074run_test "Fallback SCSV: not in list" \
1075 "$P_SRV debug_level=2" \
1076 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 0056 0031 0032 0033 0100000900230000000f000101' '16030200300200002c0302'" \
1077 0 \
1078 -S "received FALLBACK_SCSV" \
1079 -S "inapropriate fallback"
1080
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001081# Tests for CBC 1/n-1 record splitting
1082
1083run_test "CBC Record splitting: TLS 1.2, no splitting" \
1084 "$P_SRV" \
1085 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1086 request_size=123 force_version=tls1_2" \
1087 0 \
1088 -s "Read from client: 123 bytes read" \
1089 -S "Read from client: 1 bytes read" \
1090 -S "122 bytes read"
1091
1092run_test "CBC Record splitting: TLS 1.1, no splitting" \
1093 "$P_SRV" \
1094 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1095 request_size=123 force_version=tls1_1" \
1096 0 \
1097 -s "Read from client: 123 bytes read" \
1098 -S "Read from client: 1 bytes read" \
1099 -S "122 bytes read"
1100
1101run_test "CBC Record splitting: TLS 1.0, splitting" \
1102 "$P_SRV" \
1103 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1104 request_size=123 force_version=tls1" \
1105 0 \
1106 -S "Read from client: 123 bytes read" \
1107 -s "Read from client: 1 bytes read" \
1108 -s "122 bytes read"
1109
Janos Follathe2681a42016-03-07 15:57:05 +00001110requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001111run_test "CBC Record splitting: SSLv3, splitting" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +01001112 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001113 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1114 request_size=123 force_version=ssl3" \
1115 0 \
1116 -S "Read from client: 123 bytes read" \
1117 -s "Read from client: 1 bytes read" \
1118 -s "122 bytes read"
1119
1120run_test "CBC Record splitting: TLS 1.0 RC4, no splitting" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01001121 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001122 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1123 request_size=123 force_version=tls1" \
1124 0 \
1125 -s "Read from client: 123 bytes read" \
1126 -S "Read from client: 1 bytes read" \
1127 -S "122 bytes read"
1128
1129run_test "CBC Record splitting: TLS 1.0, splitting disabled" \
1130 "$P_SRV" \
1131 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1132 request_size=123 force_version=tls1 recsplit=0" \
1133 0 \
1134 -s "Read from client: 123 bytes read" \
1135 -S "Read from client: 1 bytes read" \
1136 -S "122 bytes read"
1137
Manuel Pégourié-Gonnarda852cf42015-01-13 20:56:15 +01001138run_test "CBC Record splitting: TLS 1.0, splitting, nbio" \
1139 "$P_SRV nbio=2" \
1140 "$P_CLI nbio=2 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1141 request_size=123 force_version=tls1" \
1142 0 \
1143 -S "Read from client: 123 bytes read" \
1144 -s "Read from client: 1 bytes read" \
1145 -s "122 bytes read"
1146
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001147# Tests for Session Tickets
1148
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001149run_test "Session resume using tickets: basic" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001150 "$P_SRV debug_level=3 tickets=1" \
1151 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001152 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001153 -c "client hello, adding session ticket extension" \
1154 -s "found session ticket extension" \
1155 -s "server hello, adding session ticket extension" \
1156 -c "found session_ticket extension" \
1157 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001158 -S "session successfully restored from cache" \
1159 -s "session successfully restored from ticket" \
1160 -s "a session has been resumed" \
1161 -c "a session has been resumed"
1162
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001163run_test "Session resume using tickets: cache disabled" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001164 "$P_SRV debug_level=3 tickets=1 cache_max=0" \
1165 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +01001166 0 \
1167 -c "client hello, adding session ticket extension" \
1168 -s "found session ticket extension" \
1169 -s "server hello, adding session ticket extension" \
1170 -c "found session_ticket extension" \
1171 -c "parse new session ticket" \
1172 -S "session successfully restored from cache" \
1173 -s "session successfully restored from ticket" \
1174 -s "a session has been resumed" \
1175 -c "a session has been resumed"
1176
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001177run_test "Session resume using tickets: timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001178 "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
1179 "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +01001180 0 \
1181 -c "client hello, adding session ticket extension" \
1182 -s "found session ticket extension" \
1183 -s "server hello, adding session ticket extension" \
1184 -c "found session_ticket extension" \
1185 -c "parse new session ticket" \
1186 -S "session successfully restored from cache" \
1187 -S "session successfully restored from ticket" \
1188 -S "a session has been resumed" \
1189 -C "a session has been resumed"
1190
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001191run_test "Session resume using tickets: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +01001192 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001193 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +01001194 0 \
1195 -c "client hello, adding session ticket extension" \
1196 -c "found session_ticket extension" \
1197 -c "parse new session ticket" \
1198 -c "a session has been resumed"
1199
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001200run_test "Session resume using tickets: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001201 "$P_SRV debug_level=3 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +02001202 "( $O_CLI -sess_out $SESSION; \
1203 $O_CLI -sess_in $SESSION; \
1204 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +01001205 0 \
1206 -s "found session ticket extension" \
1207 -s "server hello, adding session ticket extension" \
1208 -S "session successfully restored from cache" \
1209 -s "session successfully restored from ticket" \
1210 -s "a session has been resumed"
1211
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001212# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001213
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001214run_test "Session resume using cache: tickets enabled on client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001215 "$P_SRV debug_level=3 tickets=0" \
1216 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001217 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001218 -c "client hello, adding session ticket extension" \
1219 -s "found session ticket extension" \
1220 -S "server hello, adding session ticket extension" \
1221 -C "found session_ticket extension" \
1222 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001223 -s "session successfully restored from cache" \
1224 -S "session successfully restored from ticket" \
1225 -s "a session has been resumed" \
1226 -c "a session has been resumed"
1227
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001228run_test "Session resume using cache: tickets enabled on server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001229 "$P_SRV debug_level=3 tickets=1" \
1230 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001231 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001232 -C "client hello, adding session ticket extension" \
1233 -S "found session ticket extension" \
1234 -S "server hello, adding session ticket extension" \
1235 -C "found session_ticket extension" \
1236 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001237 -s "session successfully restored from cache" \
1238 -S "session successfully restored from ticket" \
1239 -s "a session has been resumed" \
1240 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001241
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001242run_test "Session resume using cache: cache_max=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001243 "$P_SRV debug_level=3 tickets=0 cache_max=0" \
1244 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001245 0 \
1246 -S "session successfully restored from cache" \
1247 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001248 -S "a session has been resumed" \
1249 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001250
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001251run_test "Session resume using cache: cache_max=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001252 "$P_SRV debug_level=3 tickets=0 cache_max=1" \
1253 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001254 0 \
1255 -s "session successfully restored from cache" \
1256 -S "session successfully restored from ticket" \
1257 -s "a session has been resumed" \
1258 -c "a session has been resumed"
1259
Manuel Pégourié-Gonnard6df31962015-05-04 10:55:47 +02001260run_test "Session resume using cache: timeout > delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001261 "$P_SRV debug_level=3 tickets=0" \
1262 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001263 0 \
1264 -s "session successfully restored from cache" \
1265 -S "session successfully restored from ticket" \
1266 -s "a session has been resumed" \
1267 -c "a session has been resumed"
1268
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001269run_test "Session resume using cache: timeout < delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001270 "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
1271 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001272 0 \
1273 -S "session successfully restored from cache" \
1274 -S "session successfully restored from ticket" \
1275 -S "a session has been resumed" \
1276 -C "a session has been resumed"
1277
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001278run_test "Session resume using cache: no timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001279 "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
1280 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001281 0 \
1282 -s "session successfully restored from cache" \
1283 -S "session successfully restored from ticket" \
1284 -s "a session has been resumed" \
1285 -c "a session has been resumed"
1286
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001287run_test "Session resume using cache: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001288 "$P_SRV debug_level=3 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +02001289 "( $O_CLI -sess_out $SESSION; \
1290 $O_CLI -sess_in $SESSION; \
1291 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +01001292 0 \
1293 -s "found session ticket extension" \
1294 -S "server hello, adding session ticket extension" \
1295 -s "session successfully restored from cache" \
1296 -S "session successfully restored from ticket" \
1297 -s "a session has been resumed"
1298
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001299run_test "Session resume using cache: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +01001300 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001301 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +01001302 0 \
1303 -C "found session_ticket extension" \
1304 -C "parse new session ticket" \
1305 -c "a session has been resumed"
1306
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001307# Tests for Max Fragment Length extension
1308
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001309run_test "Max fragment length: not used, reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001310 "$P_SRV debug_level=3" \
1311 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001312 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001313 -c "Maximum fragment length is 16384" \
1314 -s "Maximum fragment length is 16384" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001315 -C "client hello, adding max_fragment_length extension" \
1316 -S "found max fragment length extension" \
1317 -S "server hello, max_fragment_length extension" \
1318 -C "found max_fragment_length extension"
1319
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001320run_test "Max fragment length: used by client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001321 "$P_SRV debug_level=3" \
1322 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001323 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001324 -c "Maximum fragment length is 4096" \
1325 -s "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001326 -c "client hello, adding max_fragment_length extension" \
1327 -s "found max fragment length extension" \
1328 -s "server hello, max_fragment_length extension" \
1329 -c "found max_fragment_length extension"
1330
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001331run_test "Max fragment length: used by server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001332 "$P_SRV debug_level=3 max_frag_len=4096" \
1333 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001334 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001335 -c "Maximum fragment length is 16384" \
1336 -s "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001337 -C "client hello, adding max_fragment_length extension" \
1338 -S "found max fragment length extension" \
1339 -S "server hello, max_fragment_length extension" \
1340 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001341
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001342requires_gnutls
1343run_test "Max fragment length: gnutls server" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001344 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001345 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001346 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001347 -c "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001348 -c "client hello, adding max_fragment_length extension" \
1349 -c "found max_fragment_length extension"
1350
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001351run_test "Max fragment length: client, message just fits" \
1352 "$P_SRV debug_level=3" \
1353 "$P_CLI debug_level=3 max_frag_len=2048 request_size=2048" \
1354 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001355 -c "Maximum fragment length is 2048" \
1356 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001357 -c "client hello, adding max_fragment_length extension" \
1358 -s "found max fragment length extension" \
1359 -s "server hello, max_fragment_length extension" \
1360 -c "found max_fragment_length extension" \
1361 -c "2048 bytes written in 1 fragments" \
1362 -s "2048 bytes read"
1363
1364run_test "Max fragment length: client, larger message" \
1365 "$P_SRV debug_level=3" \
1366 "$P_CLI debug_level=3 max_frag_len=2048 request_size=2345" \
1367 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001368 -c "Maximum fragment length is 2048" \
1369 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001370 -c "client hello, adding max_fragment_length extension" \
1371 -s "found max fragment length extension" \
1372 -s "server hello, max_fragment_length extension" \
1373 -c "found max_fragment_length extension" \
1374 -c "2345 bytes written in 2 fragments" \
1375 -s "2048 bytes read" \
1376 -s "297 bytes read"
1377
Manuel Pégourié-Gonnard23eb74d2015-01-21 14:37:13 +00001378run_test "Max fragment length: DTLS client, larger message" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001379 "$P_SRV debug_level=3 dtls=1" \
1380 "$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
1381 1 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001382 -c "Maximum fragment length is 2048" \
1383 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001384 -c "client hello, adding max_fragment_length extension" \
1385 -s "found max fragment length extension" \
1386 -s "server hello, max_fragment_length extension" \
1387 -c "found max_fragment_length extension" \
1388 -c "fragment larger than.*maximum"
1389
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001390# Tests for renegotiation
1391
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001392run_test "Renegotiation: none, for reference" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001393 "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001394 "$P_CLI debug_level=3 exchanges=2" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001395 0 \
1396 -C "client hello, adding renegotiation extension" \
1397 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1398 -S "found renegotiation extension" \
1399 -s "server hello, secure renegotiation extension" \
1400 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001401 -C "=> renegotiate" \
1402 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001403 -S "write hello request"
1404
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001405run_test "Renegotiation: client-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001406 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001407 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001408 0 \
1409 -c "client hello, adding renegotiation extension" \
1410 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1411 -s "found renegotiation extension" \
1412 -s "server hello, secure renegotiation extension" \
1413 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001414 -c "=> renegotiate" \
1415 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001416 -S "write hello request"
1417
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001418run_test "Renegotiation: server-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001419 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001420 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001421 0 \
1422 -c "client hello, adding renegotiation extension" \
1423 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1424 -s "found renegotiation extension" \
1425 -s "server hello, secure renegotiation extension" \
1426 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001427 -c "=> renegotiate" \
1428 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001429 -s "write hello request"
1430
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001431run_test "Renegotiation: double" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001432 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001433 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001434 0 \
1435 -c "client hello, adding renegotiation extension" \
1436 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1437 -s "found renegotiation extension" \
1438 -s "server hello, secure renegotiation extension" \
1439 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001440 -c "=> renegotiate" \
1441 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001442 -s "write hello request"
1443
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001444run_test "Renegotiation: client-initiated, server-rejected" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001445 "$P_SRV debug_level=3 exchanges=2 renegotiation=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001446 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001447 1 \
1448 -c "client hello, adding renegotiation extension" \
1449 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1450 -S "found renegotiation extension" \
1451 -s "server hello, secure renegotiation extension" \
1452 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001453 -c "=> renegotiate" \
1454 -S "=> renegotiate" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001455 -S "write hello request" \
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +02001456 -c "SSL - Unexpected message at ServerHello in renegotiation" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001457 -c "failed"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001458
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001459run_test "Renegotiation: server-initiated, client-rejected, default" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001460 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001461 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001462 0 \
1463 -C "client hello, adding renegotiation extension" \
1464 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1465 -S "found renegotiation extension" \
1466 -s "server hello, secure renegotiation extension" \
1467 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001468 -C "=> renegotiate" \
1469 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001470 -s "write hello request" \
Manuel Pégourié-Gonnarda9964db2014-07-03 19:29:16 +02001471 -S "SSL - An unexpected message was received from our peer" \
1472 -S "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001473
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001474run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001475 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001476 renego_delay=-1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001477 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001478 0 \
1479 -C "client hello, adding renegotiation extension" \
1480 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1481 -S "found renegotiation extension" \
1482 -s "server hello, secure renegotiation extension" \
1483 -c "found renegotiation extension" \
1484 -C "=> renegotiate" \
1485 -S "=> renegotiate" \
1486 -s "write hello request" \
1487 -S "SSL - An unexpected message was received from our peer" \
1488 -S "failed"
1489
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +02001490# delay 2 for 1 alert record + 1 application data record
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001491run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001492 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001493 renego_delay=2 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001494 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001495 0 \
1496 -C "client hello, adding renegotiation extension" \
1497 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1498 -S "found renegotiation extension" \
1499 -s "server hello, secure renegotiation extension" \
1500 -c "found renegotiation extension" \
1501 -C "=> renegotiate" \
1502 -S "=> renegotiate" \
1503 -s "write hello request" \
1504 -S "SSL - An unexpected message was received from our peer" \
1505 -S "failed"
1506
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001507run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001508 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001509 renego_delay=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001510 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001511 0 \
1512 -C "client hello, adding renegotiation extension" \
1513 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1514 -S "found renegotiation extension" \
1515 -s "server hello, secure renegotiation extension" \
1516 -c "found renegotiation extension" \
1517 -C "=> renegotiate" \
1518 -S "=> renegotiate" \
1519 -s "write hello request" \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +02001520 -s "SSL - An unexpected message was received from our peer"
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001521
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001522run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001523 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001524 renego_delay=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001525 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001526 0 \
1527 -c "client hello, adding renegotiation extension" \
1528 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1529 -s "found renegotiation extension" \
1530 -s "server hello, secure renegotiation extension" \
1531 -c "found renegotiation extension" \
1532 -c "=> renegotiate" \
1533 -s "=> renegotiate" \
1534 -s "write hello request" \
1535 -S "SSL - An unexpected message was received from our peer" \
1536 -S "failed"
1537
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001538run_test "Renegotiation: periodic, just below period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001539 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001540 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
1541 0 \
1542 -C "client hello, adding renegotiation extension" \
1543 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1544 -S "found renegotiation extension" \
1545 -s "server hello, secure renegotiation extension" \
1546 -c "found renegotiation extension" \
1547 -S "record counter limit reached: renegotiate" \
1548 -C "=> renegotiate" \
1549 -S "=> renegotiate" \
1550 -S "write hello request" \
1551 -S "SSL - An unexpected message was received from our peer" \
1552 -S "failed"
1553
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001554# one extra exchange to be able to complete renego
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001555run_test "Renegotiation: periodic, just above period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001556 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001557 "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001558 0 \
1559 -c "client hello, adding renegotiation extension" \
1560 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1561 -s "found renegotiation extension" \
1562 -s "server hello, secure renegotiation extension" \
1563 -c "found renegotiation extension" \
1564 -s "record counter limit reached: renegotiate" \
1565 -c "=> renegotiate" \
1566 -s "=> renegotiate" \
1567 -s "write hello request" \
1568 -S "SSL - An unexpected message was received from our peer" \
1569 -S "failed"
1570
1571run_test "Renegotiation: periodic, two times period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001572 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001573 "$P_CLI debug_level=3 exchanges=7 renegotiation=1" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001574 0 \
1575 -c "client hello, adding renegotiation extension" \
1576 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1577 -s "found renegotiation extension" \
1578 -s "server hello, secure renegotiation extension" \
1579 -c "found renegotiation extension" \
1580 -s "record counter limit reached: renegotiate" \
1581 -c "=> renegotiate" \
1582 -s "=> renegotiate" \
1583 -s "write hello request" \
1584 -S "SSL - An unexpected message was received from our peer" \
1585 -S "failed"
1586
1587run_test "Renegotiation: periodic, above period, disabled" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001588 "$P_SRV debug_level=3 exchanges=9 renegotiation=0 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001589 "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
1590 0 \
1591 -C "client hello, adding renegotiation extension" \
1592 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1593 -S "found renegotiation extension" \
1594 -s "server hello, secure renegotiation extension" \
1595 -c "found renegotiation extension" \
1596 -S "record counter limit reached: renegotiate" \
1597 -C "=> renegotiate" \
1598 -S "=> renegotiate" \
1599 -S "write hello request" \
1600 -S "SSL - An unexpected message was received from our peer" \
1601 -S "failed"
1602
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001603run_test "Renegotiation: nbio, client-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001604 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001605 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +02001606 0 \
1607 -c "client hello, adding renegotiation extension" \
1608 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1609 -s "found renegotiation extension" \
1610 -s "server hello, secure renegotiation extension" \
1611 -c "found renegotiation extension" \
1612 -c "=> renegotiate" \
1613 -s "=> renegotiate" \
1614 -S "write hello request"
1615
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001616run_test "Renegotiation: nbio, server-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001617 "$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 +02001618 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +02001619 0 \
1620 -c "client hello, adding renegotiation extension" \
1621 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1622 -s "found renegotiation extension" \
1623 -s "server hello, secure renegotiation extension" \
1624 -c "found renegotiation extension" \
1625 -c "=> renegotiate" \
1626 -s "=> renegotiate" \
1627 -s "write hello request"
1628
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001629run_test "Renegotiation: openssl server, client-initiated" \
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02001630 "$O_SRV -www" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001631 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001632 0 \
1633 -c "client hello, adding renegotiation extension" \
1634 -c "found renegotiation extension" \
1635 -c "=> renegotiate" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001636 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001637 -C "error" \
1638 -c "HTTP/1.0 200 [Oo][Kk]"
1639
Paul Bakker539d9722015-02-08 16:18:35 +01001640requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001641run_test "Renegotiation: gnutls server strict, client-initiated" \
1642 "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001643 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001644 0 \
1645 -c "client hello, adding renegotiation extension" \
1646 -c "found renegotiation extension" \
1647 -c "=> renegotiate" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001648 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001649 -C "error" \
1650 -c "HTTP/1.0 200 [Oo][Kk]"
1651
Paul Bakker539d9722015-02-08 16:18:35 +01001652requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001653run_test "Renegotiation: gnutls server unsafe, client-initiated default" \
1654 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1655 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
1656 1 \
1657 -c "client hello, adding renegotiation extension" \
1658 -C "found renegotiation extension" \
1659 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001660 -c "mbedtls_ssl_handshake() returned" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001661 -c "error" \
1662 -C "HTTP/1.0 200 [Oo][Kk]"
1663
Paul Bakker539d9722015-02-08 16:18:35 +01001664requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001665run_test "Renegotiation: gnutls server unsafe, client-inititated no legacy" \
1666 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1667 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
1668 allow_legacy=0" \
1669 1 \
1670 -c "client hello, adding renegotiation extension" \
1671 -C "found renegotiation extension" \
1672 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001673 -c "mbedtls_ssl_handshake() returned" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001674 -c "error" \
1675 -C "HTTP/1.0 200 [Oo][Kk]"
1676
Paul Bakker539d9722015-02-08 16:18:35 +01001677requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001678run_test "Renegotiation: gnutls server unsafe, client-inititated legacy" \
1679 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1680 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
1681 allow_legacy=1" \
1682 0 \
1683 -c "client hello, adding renegotiation extension" \
1684 -C "found renegotiation extension" \
1685 -c "=> renegotiate" \
1686 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001687 -C "error" \
1688 -c "HTTP/1.0 200 [Oo][Kk]"
1689
Manuel Pégourié-Gonnard30d16eb2014-08-19 17:43:50 +02001690run_test "Renegotiation: DTLS, client-initiated" \
1691 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
1692 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
1693 0 \
1694 -c "client hello, adding renegotiation extension" \
1695 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1696 -s "found renegotiation extension" \
1697 -s "server hello, secure renegotiation extension" \
1698 -c "found renegotiation extension" \
1699 -c "=> renegotiate" \
1700 -s "=> renegotiate" \
1701 -S "write hello request"
1702
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +02001703run_test "Renegotiation: DTLS, server-initiated" \
1704 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnarddf9a0a82014-10-02 14:17:18 +02001705 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
1706 read_timeout=1000 max_resend=2" \
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +02001707 0 \
1708 -c "client hello, adding renegotiation extension" \
1709 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1710 -s "found renegotiation extension" \
1711 -s "server hello, secure renegotiation extension" \
1712 -c "found renegotiation extension" \
1713 -c "=> renegotiate" \
1714 -s "=> renegotiate" \
1715 -s "write hello request"
1716
Andres AG692ad842017-01-19 16:30:57 +00001717run_test "Renegotiation: DTLS, renego_period overflow" \
1718 "$P_SRV debug_level=3 dtls=1 exchanges=4 renegotiation=1 renego_period=18446462598732840962 auth_mode=optional" \
1719 "$P_CLI debug_level=3 dtls=1 exchanges=4 renegotiation=1" \
1720 0 \
1721 -c "client hello, adding renegotiation extension" \
1722 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1723 -s "found renegotiation extension" \
1724 -s "server hello, secure renegotiation extension" \
1725 -s "record counter limit reached: renegotiate" \
1726 -c "=> renegotiate" \
1727 -s "=> renegotiate" \
1728 -s "write hello request" \
1729
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00001730requires_gnutls
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +02001731run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
1732 "$G_SRV -u --mtu 4096" \
1733 "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
1734 0 \
1735 -c "client hello, adding renegotiation extension" \
1736 -c "found renegotiation extension" \
1737 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001738 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +02001739 -C "error" \
1740 -s "Extra-header:"
1741
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001742# Test for the "secure renegotation" extension only (no actual renegotiation)
1743
Paul Bakker539d9722015-02-08 16:18:35 +01001744requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001745run_test "Renego ext: gnutls server strict, client default" \
1746 "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
1747 "$P_CLI debug_level=3" \
1748 0 \
1749 -c "found renegotiation extension" \
1750 -C "error" \
1751 -c "HTTP/1.0 200 [Oo][Kk]"
1752
Paul Bakker539d9722015-02-08 16:18:35 +01001753requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001754run_test "Renego ext: gnutls server unsafe, client default" \
1755 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1756 "$P_CLI debug_level=3" \
1757 0 \
1758 -C "found renegotiation extension" \
1759 -C "error" \
1760 -c "HTTP/1.0 200 [Oo][Kk]"
1761
Paul Bakker539d9722015-02-08 16:18:35 +01001762requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001763run_test "Renego ext: gnutls server unsafe, client break legacy" \
1764 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1765 "$P_CLI debug_level=3 allow_legacy=-1" \
1766 1 \
1767 -C "found renegotiation extension" \
1768 -c "error" \
1769 -C "HTTP/1.0 200 [Oo][Kk]"
1770
Paul Bakker539d9722015-02-08 16:18:35 +01001771requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001772run_test "Renego ext: gnutls client strict, server default" \
1773 "$P_SRV debug_level=3" \
1774 "$G_CLI --priority=NORMAL:%SAFE_RENEGOTIATION" \
1775 0 \
1776 -s "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
1777 -s "server hello, secure renegotiation extension"
1778
Paul Bakker539d9722015-02-08 16:18:35 +01001779requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001780run_test "Renego ext: gnutls client unsafe, server default" \
1781 "$P_SRV debug_level=3" \
1782 "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1783 0 \
1784 -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
1785 -S "server hello, secure renegotiation extension"
1786
Paul Bakker539d9722015-02-08 16:18:35 +01001787requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001788run_test "Renego ext: gnutls client unsafe, server break legacy" \
1789 "$P_SRV debug_level=3 allow_legacy=-1" \
1790 "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1791 1 \
1792 -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
1793 -S "server hello, secure renegotiation extension"
1794
Janos Follath0b242342016-02-17 10:11:21 +00001795# Tests for silently dropping trailing extra bytes in .der certificates
1796
1797requires_gnutls
1798run_test "DER format: no trailing bytes" \
1799 "$P_SRV crt_file=data_files/server5-der0.crt \
1800 key_file=data_files/server5.key" \
1801 "$G_CLI " \
1802 0 \
1803 -c "Handshake was completed" \
1804
1805requires_gnutls
1806run_test "DER format: with a trailing zero byte" \
1807 "$P_SRV crt_file=data_files/server5-der1a.crt \
1808 key_file=data_files/server5.key" \
1809 "$G_CLI " \
1810 0 \
1811 -c "Handshake was completed" \
1812
1813requires_gnutls
1814run_test "DER format: with a trailing random byte" \
1815 "$P_SRV crt_file=data_files/server5-der1b.crt \
1816 key_file=data_files/server5.key" \
1817 "$G_CLI " \
1818 0 \
1819 -c "Handshake was completed" \
1820
1821requires_gnutls
1822run_test "DER format: with 2 trailing random bytes" \
1823 "$P_SRV crt_file=data_files/server5-der2.crt \
1824 key_file=data_files/server5.key" \
1825 "$G_CLI " \
1826 0 \
1827 -c "Handshake was completed" \
1828
1829requires_gnutls
1830run_test "DER format: with 4 trailing random bytes" \
1831 "$P_SRV crt_file=data_files/server5-der4.crt \
1832 key_file=data_files/server5.key" \
1833 "$G_CLI " \
1834 0 \
1835 -c "Handshake was completed" \
1836
1837requires_gnutls
1838run_test "DER format: with 8 trailing random bytes" \
1839 "$P_SRV crt_file=data_files/server5-der8.crt \
1840 key_file=data_files/server5.key" \
1841 "$G_CLI " \
1842 0 \
1843 -c "Handshake was completed" \
1844
1845requires_gnutls
1846run_test "DER format: with 9 trailing random bytes" \
1847 "$P_SRV crt_file=data_files/server5-der9.crt \
1848 key_file=data_files/server5.key" \
1849 "$G_CLI " \
1850 0 \
1851 -c "Handshake was completed" \
1852
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001853# Tests for auth_mode
1854
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001855run_test "Authentication: server badcert, client required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001856 "$P_SRV crt_file=data_files/server5-badsign.crt \
1857 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001858 "$P_CLI debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001859 1 \
1860 -c "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01001861 -c "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001862 -c "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001863 -c "X509 - Certificate verification failed"
1864
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001865run_test "Authentication: server badcert, client optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001866 "$P_SRV crt_file=data_files/server5-badsign.crt \
1867 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001868 "$P_CLI debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001869 0 \
1870 -c "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01001871 -c "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001872 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001873 -C "X509 - Certificate verification failed"
1874
Hanno Beckere6706e62017-05-15 16:05:15 +01001875run_test "Authentication: server goodcert, client optional, no trusted CA" \
1876 "$P_SRV" \
1877 "$P_CLI debug_level=3 auth_mode=optional ca_file=none ca_path=none" \
1878 0 \
1879 -c "x509_verify_cert() returned" \
1880 -c "! The certificate is not correctly signed by the trusted CA" \
1881 -c "! Certificate verification flags"\
1882 -C "! mbedtls_ssl_handshake returned" \
1883 -C "X509 - Certificate verification failed" \
1884 -C "SSL - No CA Chain is set, but required to operate"
1885
1886run_test "Authentication: server goodcert, client required, no trusted CA" \
1887 "$P_SRV" \
1888 "$P_CLI debug_level=3 auth_mode=required ca_file=none ca_path=none" \
1889 1 \
1890 -c "x509_verify_cert() returned" \
1891 -c "! The certificate is not correctly signed by the trusted CA" \
1892 -c "! Certificate verification flags"\
1893 -c "! mbedtls_ssl_handshake returned" \
1894 -c "SSL - No CA Chain is set, but required to operate"
1895
1896# The purpose of the next two tests is to test the client's behaviour when receiving a server
1897# certificate with an unsupported elliptic curve. This should usually not happen because
1898# the client informs the server about the supported curves - it does, though, in the
1899# corner case of a static ECDH suite, because the server doesn't check the curve on that
1900# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
1901# different means to have the server ignoring the client's supported curve list.
1902
1903requires_config_enabled MBEDTLS_ECP_C
1904run_test "Authentication: server ECDH p256v1, client required, p256v1 unsupported" \
1905 "$P_SRV debug_level=1 key_file=data_files/server5.key \
1906 crt_file=data_files/server5.ku-ka.crt" \
1907 "$P_CLI debug_level=3 auth_mode=required curves=secp521r1" \
1908 1 \
1909 -c "bad certificate (EC key curve)"\
1910 -c "! Certificate verification flags"\
1911 -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
1912
1913requires_config_enabled MBEDTLS_ECP_C
1914run_test "Authentication: server ECDH p256v1, client optional, p256v1 unsupported" \
1915 "$P_SRV debug_level=1 key_file=data_files/server5.key \
1916 crt_file=data_files/server5.ku-ka.crt" \
1917 "$P_CLI debug_level=3 auth_mode=optional curves=secp521r1" \
1918 1 \
1919 -c "bad certificate (EC key curve)"\
1920 -c "! Certificate verification flags"\
1921 -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
1922
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001923run_test "Authentication: server badcert, client none" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +01001924 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001925 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001926 "$P_CLI debug_level=1 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001927 0 \
1928 -C "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01001929 -C "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001930 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001931 -C "X509 - Certificate verification failed"
1932
Simon Butcher99000142016-10-13 17:21:01 +01001933run_test "Authentication: client SHA256, server required" \
1934 "$P_SRV auth_mode=required" \
1935 "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
1936 key_file=data_files/server6.key \
1937 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
1938 0 \
1939 -c "Supported Signature Algorithm found: 4," \
1940 -c "Supported Signature Algorithm found: 5,"
1941
1942run_test "Authentication: client SHA384, server required" \
1943 "$P_SRV auth_mode=required" \
1944 "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
1945 key_file=data_files/server6.key \
1946 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
1947 0 \
1948 -c "Supported Signature Algorithm found: 4," \
1949 -c "Supported Signature Algorithm found: 5,"
1950
Gilles Peskinefd8332e2017-05-03 16:25:07 +02001951requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
1952run_test "Authentication: client has no cert, server required (SSLv3)" \
1953 "$P_SRV debug_level=3 min_version=ssl3 auth_mode=required" \
1954 "$P_CLI debug_level=3 force_version=ssl3 crt_file=none \
1955 key_file=data_files/server5.key" \
1956 1 \
1957 -S "skip write certificate request" \
1958 -C "skip parse certificate request" \
1959 -c "got a certificate request" \
1960 -c "got no certificate to send" \
1961 -S "x509_verify_cert() returned" \
1962 -s "client has no certificate" \
1963 -s "! mbedtls_ssl_handshake returned" \
1964 -c "! mbedtls_ssl_handshake returned" \
1965 -s "No client certification received from the client, but required by the authentication mode"
1966
1967run_test "Authentication: client has no cert, server required (TLS)" \
1968 "$P_SRV debug_level=3 auth_mode=required" \
1969 "$P_CLI debug_level=3 crt_file=none \
1970 key_file=data_files/server5.key" \
1971 1 \
1972 -S "skip write certificate request" \
1973 -C "skip parse certificate request" \
1974 -c "got a certificate request" \
1975 -c "= write certificate$" \
1976 -C "skip write certificate$" \
1977 -S "x509_verify_cert() returned" \
1978 -s "client has no certificate" \
1979 -s "! mbedtls_ssl_handshake returned" \
1980 -c "! mbedtls_ssl_handshake returned" \
1981 -s "No client certification received from the client, but required by the authentication mode"
1982
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001983run_test "Authentication: client badcert, server required" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001984 "$P_SRV debug_level=3 auth_mode=required" \
1985 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001986 key_file=data_files/server5.key" \
1987 1 \
1988 -S "skip write certificate request" \
1989 -C "skip parse certificate request" \
1990 -c "got a certificate request" \
1991 -C "skip write certificate" \
1992 -C "skip write certificate verify" \
1993 -S "skip parse certificate verify" \
1994 -s "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02001995 -s "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001996 -s "! mbedtls_ssl_handshake returned" \
Gilles Peskine1cc8e342017-05-03 16:28:34 +02001997 -s "send alert level=2 message=48" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001998 -c "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001999 -s "X509 - Certificate verification failed"
Gilles Peskine1cc8e342017-05-03 16:28:34 +02002000# We don't check that the client receives the alert because it might
2001# detect that its write end of the connection is closed and abort
2002# before reading the alert message.
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002003
Janos Follath89baba22017-04-10 14:34:35 +01002004run_test "Authentication: client cert not trusted, server required" \
2005 "$P_SRV debug_level=3 auth_mode=required" \
2006 "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
2007 key_file=data_files/server5.key" \
2008 1 \
2009 -S "skip write certificate request" \
2010 -C "skip parse certificate request" \
2011 -c "got a certificate request" \
2012 -C "skip write certificate" \
2013 -C "skip write certificate verify" \
2014 -S "skip parse certificate verify" \
2015 -s "x509_verify_cert() returned" \
2016 -s "! The certificate is not correctly signed by the trusted CA" \
2017 -s "! mbedtls_ssl_handshake returned" \
2018 -c "! mbedtls_ssl_handshake returned" \
2019 -s "X509 - Certificate verification failed"
2020
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002021run_test "Authentication: client badcert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002022 "$P_SRV debug_level=3 auth_mode=optional" \
2023 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002024 key_file=data_files/server5.key" \
2025 0 \
2026 -S "skip write certificate request" \
2027 -C "skip parse certificate request" \
2028 -c "got a certificate request" \
2029 -C "skip write certificate" \
2030 -C "skip write certificate verify" \
2031 -S "skip parse certificate verify" \
2032 -s "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002033 -s "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002034 -S "! mbedtls_ssl_handshake returned" \
2035 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002036 -S "X509 - Certificate verification failed"
2037
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002038run_test "Authentication: client badcert, server none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002039 "$P_SRV debug_level=3 auth_mode=none" \
2040 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002041 key_file=data_files/server5.key" \
2042 0 \
2043 -s "skip write certificate request" \
2044 -C "skip parse certificate request" \
2045 -c "got no certificate request" \
2046 -c "skip write certificate" \
2047 -c "skip write certificate verify" \
2048 -s "skip parse certificate verify" \
2049 -S "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002050 -S "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002051 -S "! mbedtls_ssl_handshake returned" \
2052 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002053 -S "X509 - Certificate verification failed"
2054
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002055run_test "Authentication: client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002056 "$P_SRV debug_level=3 auth_mode=optional" \
2057 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002058 0 \
2059 -S "skip write certificate request" \
2060 -C "skip parse certificate request" \
2061 -c "got a certificate request" \
2062 -C "skip write certificate$" \
2063 -C "got no certificate to send" \
2064 -S "SSLv3 client has no certificate" \
2065 -c "skip write certificate verify" \
2066 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002067 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002068 -S "! mbedtls_ssl_handshake returned" \
2069 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002070 -S "X509 - Certificate verification failed"
2071
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002072run_test "Authentication: openssl client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002073 "$P_SRV debug_level=3 auth_mode=optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002074 "$O_CLI" \
2075 0 \
2076 -S "skip write certificate request" \
2077 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002078 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002079 -S "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002080 -S "X509 - Certificate verification failed"
2081
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002082run_test "Authentication: client no cert, openssl server optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002083 "$O_SRV -verify 10" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002084 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002085 0 \
2086 -C "skip parse certificate request" \
2087 -c "got a certificate request" \
2088 -C "skip write certificate$" \
2089 -c "skip write certificate verify" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002090 -C "! mbedtls_ssl_handshake returned"
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002091
Gilles Peskinefd8332e2017-05-03 16:25:07 +02002092run_test "Authentication: client no cert, openssl server required" \
2093 "$O_SRV -Verify 10" \
2094 "$P_CLI debug_level=3 crt_file=none key_file=none" \
2095 1 \
2096 -C "skip parse certificate request" \
2097 -c "got a certificate request" \
2098 -C "skip write certificate$" \
2099 -c "skip write certificate verify" \
2100 -c "! mbedtls_ssl_handshake returned"
2101
Janos Follathe2681a42016-03-07 15:57:05 +00002102requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002103run_test "Authentication: client no cert, ssl3" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002104 "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01002105 "$P_CLI debug_level=3 crt_file=none key_file=none min_version=ssl3" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002106 0 \
2107 -S "skip write certificate request" \
2108 -C "skip parse certificate request" \
2109 -c "got a certificate request" \
2110 -C "skip write certificate$" \
2111 -c "skip write certificate verify" \
2112 -c "got no certificate to send" \
2113 -s "SSLv3 client has no certificate" \
2114 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002115 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002116 -S "! mbedtls_ssl_handshake returned" \
2117 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002118 -S "X509 - Certificate verification failed"
2119
Manuel Pégourié-Gonnard9107b5f2017-07-06 12:16:25 +02002120# The "max_int chain" tests assume that MAX_INTERMEDIATE_CA is set to its
2121# default value (8)
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002122
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002123MAX_IM_CA='8'
Simon Butcher06b78632017-07-28 01:00:17 +01002124MAX_IM_CA_CONFIG=$( ../scripts/config.pl get MBEDTLS_X509_MAX_INTERMEDIATE_CA)
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002125
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002126if [ -n "$MAX_IM_CA_CONFIG" ] && [ "$MAX_IM_CA_CONFIG" -ne "$MAX_IM_CA" ]; then
Simon Butcher06b78632017-07-28 01:00:17 +01002127 printf "The ${CONFIG_H} file contains a value for the configuration of\n"
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002128 printf "MBEDTLS_X509_MAX_INTERMEDIATE_CA that is different from the script’s\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002129 printf "test value of ${MAX_IM_CA}. \n"
2130 printf "\n"
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002131 printf "The tests assume this value and if it changes, the tests in this\n"
2132 printf "script should also be adjusted.\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002133 printf "\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002134
2135 exit 1
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002136fi
2137
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002138run_test "Authentication: server max_int chain, client default" \
2139 "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
2140 key_file=data_files/dir-maxpath/09.key" \
2141 "$P_CLI server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
2142 0 \
2143 -C "X509 - A fatal error occured"
2144
2145run_test "Authentication: server max_int+1 chain, client default" \
2146 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2147 key_file=data_files/dir-maxpath/10.key" \
2148 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
2149 1 \
2150 -c "X509 - A fatal error occured"
2151
2152run_test "Authentication: server max_int+1 chain, client optional" \
2153 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2154 key_file=data_files/dir-maxpath/10.key" \
2155 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
2156 auth_mode=optional" \
2157 1 \
2158 -c "X509 - A fatal error occured"
2159
2160run_test "Authentication: server max_int+1 chain, client none" \
2161 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2162 key_file=data_files/dir-maxpath/10.key" \
2163 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
2164 auth_mode=none" \
2165 0 \
2166 -C "X509 - A fatal error occured"
2167
2168run_test "Authentication: client max_int+1 chain, server default" \
2169 "$P_SRV ca_file=data_files/dir-maxpath/00.crt" \
2170 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2171 key_file=data_files/dir-maxpath/10.key" \
2172 0 \
2173 -S "X509 - A fatal error occured"
2174
2175run_test "Authentication: client max_int+1 chain, server optional" \
2176 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
2177 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2178 key_file=data_files/dir-maxpath/10.key" \
2179 1 \
2180 -s "X509 - A fatal error occured"
2181
2182run_test "Authentication: client max_int+1 chain, server required" \
2183 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
2184 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2185 key_file=data_files/dir-maxpath/10.key" \
2186 1 \
2187 -s "X509 - A fatal error occured"
2188
2189run_test "Authentication: client max_int chain, server required" \
2190 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
2191 "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
2192 key_file=data_files/dir-maxpath/09.key" \
2193 0 \
2194 -S "X509 - A fatal error occured"
2195
Janos Follath89baba22017-04-10 14:34:35 +01002196# Tests for CA list in CertificateRequest messages
2197
2198run_test "Authentication: send CA list in CertificateRequest (default)" \
2199 "$P_SRV debug_level=3 auth_mode=required" \
2200 "$P_CLI crt_file=data_files/server6.crt \
2201 key_file=data_files/server6.key" \
2202 0 \
2203 -s "requested DN"
2204
2205run_test "Authentication: do not send CA list in CertificateRequest" \
2206 "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
2207 "$P_CLI crt_file=data_files/server6.crt \
2208 key_file=data_files/server6.key" \
2209 0 \
2210 -S "requested DN"
2211
2212run_test "Authentication: send CA list in CertificateRequest, client self signed" \
2213 "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
2214 "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
2215 key_file=data_files/server5.key" \
2216 1 \
2217 -S "requested DN" \
2218 -s "x509_verify_cert() returned" \
2219 -s "! The certificate is not correctly signed by the trusted CA" \
2220 -s "! mbedtls_ssl_handshake returned" \
2221 -c "! mbedtls_ssl_handshake returned" \
2222 -s "X509 - Certificate verification failed"
2223
Manuel Pégourié-Gonnarddf331a52015-01-08 16:43:07 +01002224# Tests for certificate selection based on SHA verson
2225
2226run_test "Certificate hash: client TLS 1.2 -> SHA-2" \
2227 "$P_SRV crt_file=data_files/server5.crt \
2228 key_file=data_files/server5.key \
2229 crt_file2=data_files/server5-sha1.crt \
2230 key_file2=data_files/server5.key" \
2231 "$P_CLI force_version=tls1_2" \
2232 0 \
2233 -c "signed using.*ECDSA with SHA256" \
2234 -C "signed using.*ECDSA with SHA1"
2235
2236run_test "Certificate hash: client TLS 1.1 -> SHA-1" \
2237 "$P_SRV crt_file=data_files/server5.crt \
2238 key_file=data_files/server5.key \
2239 crt_file2=data_files/server5-sha1.crt \
2240 key_file2=data_files/server5.key" \
2241 "$P_CLI force_version=tls1_1" \
2242 0 \
2243 -C "signed using.*ECDSA with SHA256" \
2244 -c "signed using.*ECDSA with SHA1"
2245
2246run_test "Certificate hash: client TLS 1.0 -> SHA-1" \
2247 "$P_SRV crt_file=data_files/server5.crt \
2248 key_file=data_files/server5.key \
2249 crt_file2=data_files/server5-sha1.crt \
2250 key_file2=data_files/server5.key" \
2251 "$P_CLI force_version=tls1" \
2252 0 \
2253 -C "signed using.*ECDSA with SHA256" \
2254 -c "signed using.*ECDSA with SHA1"
2255
2256run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 1)" \
2257 "$P_SRV crt_file=data_files/server5.crt \
2258 key_file=data_files/server5.key \
2259 crt_file2=data_files/server6.crt \
2260 key_file2=data_files/server6.key" \
2261 "$P_CLI force_version=tls1_1" \
2262 0 \
2263 -c "serial number.*09" \
2264 -c "signed using.*ECDSA with SHA256" \
2265 -C "signed using.*ECDSA with SHA1"
2266
2267run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 2)" \
2268 "$P_SRV crt_file=data_files/server6.crt \
2269 key_file=data_files/server6.key \
2270 crt_file2=data_files/server5.crt \
2271 key_file2=data_files/server5.key" \
2272 "$P_CLI force_version=tls1_1" \
2273 0 \
2274 -c "serial number.*0A" \
2275 -c "signed using.*ECDSA with SHA256" \
2276 -C "signed using.*ECDSA with SHA1"
2277
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002278# tests for SNI
2279
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002280run_test "SNI: no SNI callback" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002281 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002282 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002283 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002284 0 \
2285 -S "parse ServerName extension" \
2286 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
2287 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002288
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002289run_test "SNI: matching cert 1" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002290 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002291 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002292 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 +02002293 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002294 0 \
2295 -s "parse ServerName extension" \
2296 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2297 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002298
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002299run_test "SNI: matching cert 2" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002300 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002301 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002302 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 +02002303 "$P_CLI server_name=polarssl.example" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002304 0 \
2305 -s "parse ServerName extension" \
2306 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2307 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002308
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002309run_test "SNI: no matching cert" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002310 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002311 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002312 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 +02002313 "$P_CLI server_name=nonesuch.example" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002314 1 \
2315 -s "parse ServerName extension" \
2316 -s "ssl_sni_wrapper() returned" \
2317 -s "mbedtls_ssl_handshake returned" \
2318 -c "mbedtls_ssl_handshake returned" \
2319 -c "SSL - A fatal alert message was received from our peer"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002320
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002321run_test "SNI: client auth no override: optional" \
2322 "$P_SRV debug_level=3 auth_mode=optional \
2323 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2324 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
2325 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002326 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002327 -S "skip write certificate request" \
2328 -C "skip parse certificate request" \
2329 -c "got a certificate request" \
2330 -C "skip write certificate" \
2331 -C "skip write certificate verify" \
2332 -S "skip parse certificate verify"
2333
2334run_test "SNI: client auth override: none -> optional" \
2335 "$P_SRV debug_level=3 auth_mode=none \
2336 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2337 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
2338 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002339 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002340 -S "skip write certificate request" \
2341 -C "skip parse certificate request" \
2342 -c "got a certificate request" \
2343 -C "skip write certificate" \
2344 -C "skip write certificate verify" \
2345 -S "skip parse certificate verify"
2346
2347run_test "SNI: client auth override: optional -> none" \
2348 "$P_SRV debug_level=3 auth_mode=optional \
2349 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2350 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
2351 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002352 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002353 -s "skip write certificate request" \
2354 -C "skip parse certificate request" \
2355 -c "got no certificate request" \
2356 -c "skip write certificate" \
2357 -c "skip write certificate verify" \
2358 -s "skip parse certificate verify"
2359
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002360run_test "SNI: CA no override" \
2361 "$P_SRV debug_level=3 auth_mode=optional \
2362 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2363 ca_file=data_files/test-ca.crt \
2364 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
2365 "$P_CLI debug_level=3 server_name=localhost \
2366 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2367 1 \
2368 -S "skip write certificate request" \
2369 -C "skip parse certificate request" \
2370 -c "got a certificate request" \
2371 -C "skip write certificate" \
2372 -C "skip write certificate verify" \
2373 -S "skip parse certificate verify" \
2374 -s "x509_verify_cert() returned" \
2375 -s "! The certificate is not correctly signed by the trusted CA" \
2376 -S "The certificate has been revoked (is on a CRL)"
2377
2378run_test "SNI: CA override" \
2379 "$P_SRV debug_level=3 auth_mode=optional \
2380 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2381 ca_file=data_files/test-ca.crt \
2382 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
2383 "$P_CLI debug_level=3 server_name=localhost \
2384 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2385 0 \
2386 -S "skip write certificate request" \
2387 -C "skip parse certificate request" \
2388 -c "got a certificate request" \
2389 -C "skip write certificate" \
2390 -C "skip write certificate verify" \
2391 -S "skip parse certificate verify" \
2392 -S "x509_verify_cert() returned" \
2393 -S "! The certificate is not correctly signed by the trusted CA" \
2394 -S "The certificate has been revoked (is on a CRL)"
2395
2396run_test "SNI: CA override with CRL" \
2397 "$P_SRV debug_level=3 auth_mode=optional \
2398 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2399 ca_file=data_files/test-ca.crt \
2400 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
2401 "$P_CLI debug_level=3 server_name=localhost \
2402 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2403 1 \
2404 -S "skip write certificate request" \
2405 -C "skip parse certificate request" \
2406 -c "got a certificate request" \
2407 -C "skip write certificate" \
2408 -C "skip write certificate verify" \
2409 -S "skip parse certificate verify" \
2410 -s "x509_verify_cert() returned" \
2411 -S "! The certificate is not correctly signed by the trusted CA" \
2412 -s "The certificate has been revoked (is on a CRL)"
2413
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002414# Tests for non-blocking I/O: exercise a variety of handshake flows
2415
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002416run_test "Non-blocking I/O: basic handshake" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002417 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
2418 "$P_CLI nbio=2 tickets=0" \
2419 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002420 -S "mbedtls_ssl_handshake returned" \
2421 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002422 -c "Read from server: .* bytes read"
2423
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002424run_test "Non-blocking I/O: client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002425 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
2426 "$P_CLI nbio=2 tickets=0" \
2427 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002428 -S "mbedtls_ssl_handshake returned" \
2429 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002430 -c "Read from server: .* bytes read"
2431
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002432run_test "Non-blocking I/O: ticket" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002433 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
2434 "$P_CLI nbio=2 tickets=1" \
2435 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002436 -S "mbedtls_ssl_handshake returned" \
2437 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002438 -c "Read from server: .* bytes read"
2439
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002440run_test "Non-blocking I/O: ticket + client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002441 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
2442 "$P_CLI nbio=2 tickets=1" \
2443 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002444 -S "mbedtls_ssl_handshake returned" \
2445 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002446 -c "Read from server: .* bytes read"
2447
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002448run_test "Non-blocking I/O: ticket + client auth + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002449 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
2450 "$P_CLI nbio=2 tickets=1 reconnect=1" \
2451 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002452 -S "mbedtls_ssl_handshake returned" \
2453 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002454 -c "Read from server: .* bytes read"
2455
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002456run_test "Non-blocking I/O: ticket + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002457 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
2458 "$P_CLI nbio=2 tickets=1 reconnect=1" \
2459 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002460 -S "mbedtls_ssl_handshake returned" \
2461 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002462 -c "Read from server: .* bytes read"
2463
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002464run_test "Non-blocking I/O: session-id resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002465 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
2466 "$P_CLI nbio=2 tickets=0 reconnect=1" \
2467 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002468 -S "mbedtls_ssl_handshake returned" \
2469 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002470 -c "Read from server: .* bytes read"
2471
Hanno Becker00076712017-11-15 16:39:08 +00002472# Tests for event-driven I/O: exercise a variety of handshake flows
2473
2474run_test "Event-driven I/O: basic handshake" \
2475 "$P_SRV event=1 tickets=0 auth_mode=none" \
2476 "$P_CLI event=1 tickets=0" \
2477 0 \
2478 -S "mbedtls_ssl_handshake returned" \
2479 -C "mbedtls_ssl_handshake returned" \
2480 -c "Read from server: .* bytes read"
2481
2482run_test "Event-driven I/O: client auth" \
2483 "$P_SRV event=1 tickets=0 auth_mode=required" \
2484 "$P_CLI event=1 tickets=0" \
2485 0 \
2486 -S "mbedtls_ssl_handshake returned" \
2487 -C "mbedtls_ssl_handshake returned" \
2488 -c "Read from server: .* bytes read"
2489
2490run_test "Event-driven I/O: ticket" \
2491 "$P_SRV event=1 tickets=1 auth_mode=none" \
2492 "$P_CLI event=1 tickets=1" \
2493 0 \
2494 -S "mbedtls_ssl_handshake returned" \
2495 -C "mbedtls_ssl_handshake returned" \
2496 -c "Read from server: .* bytes read"
2497
2498run_test "Event-driven I/O: ticket + client auth" \
2499 "$P_SRV event=1 tickets=1 auth_mode=required" \
2500 "$P_CLI event=1 tickets=1" \
2501 0 \
2502 -S "mbedtls_ssl_handshake returned" \
2503 -C "mbedtls_ssl_handshake returned" \
2504 -c "Read from server: .* bytes read"
2505
2506run_test "Event-driven I/O: ticket + client auth + resume" \
2507 "$P_SRV event=1 tickets=1 auth_mode=required" \
2508 "$P_CLI event=1 tickets=1 reconnect=1" \
2509 0 \
2510 -S "mbedtls_ssl_handshake returned" \
2511 -C "mbedtls_ssl_handshake returned" \
2512 -c "Read from server: .* bytes read"
2513
2514run_test "Event-driven I/O: ticket + resume" \
2515 "$P_SRV event=1 tickets=1 auth_mode=none" \
2516 "$P_CLI event=1 tickets=1 reconnect=1" \
2517 0 \
2518 -S "mbedtls_ssl_handshake returned" \
2519 -C "mbedtls_ssl_handshake returned" \
2520 -c "Read from server: .* bytes read"
2521
2522run_test "Event-driven I/O: session-id resume" \
2523 "$P_SRV event=1 tickets=0 auth_mode=none" \
2524 "$P_CLI event=1 tickets=0 reconnect=1" \
2525 0 \
2526 -S "mbedtls_ssl_handshake returned" \
2527 -C "mbedtls_ssl_handshake returned" \
2528 -c "Read from server: .* bytes read"
2529
Hanno Becker6a33f592018-03-13 11:38:46 +00002530run_test "Event-driven I/O, DTLS: basic handshake" \
2531 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
2532 "$P_CLI dtls=1 event=1 tickets=0" \
2533 0 \
2534 -c "Read from server: .* bytes read"
2535
2536run_test "Event-driven I/O, DTLS: client auth" \
2537 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
2538 "$P_CLI dtls=1 event=1 tickets=0" \
2539 0 \
2540 -c "Read from server: .* bytes read"
2541
2542run_test "Event-driven I/O, DTLS: ticket" \
2543 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
2544 "$P_CLI dtls=1 event=1 tickets=1" \
2545 0 \
2546 -c "Read from server: .* bytes read"
2547
2548run_test "Event-driven I/O, DTLS: ticket + client auth" \
2549 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
2550 "$P_CLI dtls=1 event=1 tickets=1" \
2551 0 \
2552 -c "Read from server: .* bytes read"
2553
2554run_test "Event-driven I/O, DTLS: ticket + client auth + resume" \
2555 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
2556 "$P_CLI dtls=1 event=1 tickets=1 reconnect=1" \
2557 0 \
2558 -c "Read from server: .* bytes read"
2559
2560run_test "Event-driven I/O, DTLS: ticket + resume" \
2561 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
2562 "$P_CLI dtls=1 event=1 tickets=1 reconnect=1" \
2563 0 \
2564 -c "Read from server: .* bytes read"
2565
2566run_test "Event-driven I/O, DTLS: session-id resume" \
2567 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
2568 "$P_CLI dtls=1 event=1 tickets=0 reconnect=1" \
2569 0 \
2570 -c "Read from server: .* bytes read"
Hanno Beckerbc6c1102018-03-13 11:39:40 +00002571
2572# This test demonstrates the need for the mbedtls_ssl_check_pending function.
2573# During session resumption, the client will send its ApplicationData record
2574# within the same datagram as the Finished messages. In this situation, the
2575# server MUST NOT idle on the underlying transport after handshake completion,
2576# because the ApplicationData request has already been queued internally.
2577run_test "Event-driven I/O, DTLS: session-id resume, UDP packing" \
Hanno Becker8d832182018-03-15 10:14:19 +00002578 -p "$P_PXY pack=50" \
Hanno Beckerbc6c1102018-03-13 11:39:40 +00002579 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
2580 "$P_CLI dtls=1 event=1 tickets=0 reconnect=1" \
2581 0 \
2582 -c "Read from server: .* bytes read"
2583
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002584# Tests for version negotiation
2585
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002586run_test "Version check: all -> 1.2" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002587 "$P_SRV" \
2588 "$P_CLI" \
2589 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002590 -S "mbedtls_ssl_handshake returned" \
2591 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002592 -s "Protocol is TLSv1.2" \
2593 -c "Protocol is TLSv1.2"
2594
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002595run_test "Version check: cli max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002596 "$P_SRV" \
2597 "$P_CLI max_version=tls1_1" \
2598 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002599 -S "mbedtls_ssl_handshake returned" \
2600 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002601 -s "Protocol is TLSv1.1" \
2602 -c "Protocol is TLSv1.1"
2603
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002604run_test "Version check: srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002605 "$P_SRV max_version=tls1_1" \
2606 "$P_CLI" \
2607 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002608 -S "mbedtls_ssl_handshake returned" \
2609 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002610 -s "Protocol is TLSv1.1" \
2611 -c "Protocol is TLSv1.1"
2612
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002613run_test "Version check: cli+srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002614 "$P_SRV max_version=tls1_1" \
2615 "$P_CLI max_version=tls1_1" \
2616 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002617 -S "mbedtls_ssl_handshake returned" \
2618 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002619 -s "Protocol is TLSv1.1" \
2620 -c "Protocol is TLSv1.1"
2621
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002622run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002623 "$P_SRV min_version=tls1_1" \
2624 "$P_CLI max_version=tls1_1" \
2625 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002626 -S "mbedtls_ssl_handshake returned" \
2627 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002628 -s "Protocol is TLSv1.1" \
2629 -c "Protocol is TLSv1.1"
2630
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002631run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002632 "$P_SRV max_version=tls1_1" \
2633 "$P_CLI min_version=tls1_1" \
2634 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002635 -S "mbedtls_ssl_handshake returned" \
2636 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002637 -s "Protocol is TLSv1.1" \
2638 -c "Protocol is TLSv1.1"
2639
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002640run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002641 "$P_SRV max_version=tls1_1" \
2642 "$P_CLI min_version=tls1_2" \
2643 1 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002644 -s "mbedtls_ssl_handshake returned" \
2645 -c "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002646 -c "SSL - Handshake protocol not within min/max boundaries"
2647
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002648run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002649 "$P_SRV min_version=tls1_2" \
2650 "$P_CLI max_version=tls1_1" \
2651 1 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002652 -s "mbedtls_ssl_handshake returned" \
2653 -c "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002654 -s "SSL - Handshake protocol not within min/max boundaries"
2655
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002656# Tests for ALPN extension
2657
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002658run_test "ALPN: none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002659 "$P_SRV debug_level=3" \
2660 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002661 0 \
2662 -C "client hello, adding alpn extension" \
2663 -S "found alpn extension" \
2664 -C "got an alert message, type: \\[2:120]" \
2665 -S "server hello, adding alpn extension" \
2666 -C "found alpn extension " \
2667 -C "Application Layer Protocol is" \
2668 -S "Application Layer Protocol is"
2669
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002670run_test "ALPN: client only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002671 "$P_SRV debug_level=3" \
2672 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002673 0 \
2674 -c "client hello, adding alpn extension" \
2675 -s "found alpn extension" \
2676 -C "got an alert message, type: \\[2:120]" \
2677 -S "server hello, adding alpn extension" \
2678 -C "found alpn extension " \
2679 -c "Application Layer Protocol is (none)" \
2680 -S "Application Layer Protocol is"
2681
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002682run_test "ALPN: server only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002683 "$P_SRV debug_level=3 alpn=abc,1234" \
2684 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002685 0 \
2686 -C "client hello, adding alpn extension" \
2687 -S "found alpn extension" \
2688 -C "got an alert message, type: \\[2:120]" \
2689 -S "server hello, adding alpn extension" \
2690 -C "found alpn extension " \
2691 -C "Application Layer Protocol is" \
2692 -s "Application Layer Protocol is (none)"
2693
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002694run_test "ALPN: both, common cli1-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002695 "$P_SRV debug_level=3 alpn=abc,1234" \
2696 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002697 0 \
2698 -c "client hello, adding alpn extension" \
2699 -s "found alpn extension" \
2700 -C "got an alert message, type: \\[2:120]" \
2701 -s "server hello, adding alpn extension" \
2702 -c "found alpn extension" \
2703 -c "Application Layer Protocol is abc" \
2704 -s "Application Layer Protocol is abc"
2705
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002706run_test "ALPN: both, common cli2-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002707 "$P_SRV debug_level=3 alpn=abc,1234" \
2708 "$P_CLI debug_level=3 alpn=1234,abc" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002709 0 \
2710 -c "client hello, adding alpn extension" \
2711 -s "found alpn extension" \
2712 -C "got an alert message, type: \\[2:120]" \
2713 -s "server hello, adding alpn extension" \
2714 -c "found alpn extension" \
2715 -c "Application Layer Protocol is abc" \
2716 -s "Application Layer Protocol is abc"
2717
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002718run_test "ALPN: both, common cli1-srv2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002719 "$P_SRV debug_level=3 alpn=abc,1234" \
2720 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002721 0 \
2722 -c "client hello, adding alpn extension" \
2723 -s "found alpn extension" \
2724 -C "got an alert message, type: \\[2:120]" \
2725 -s "server hello, adding alpn extension" \
2726 -c "found alpn extension" \
2727 -c "Application Layer Protocol is 1234" \
2728 -s "Application Layer Protocol is 1234"
2729
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002730run_test "ALPN: both, no common" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002731 "$P_SRV debug_level=3 alpn=abc,123" \
2732 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002733 1 \
2734 -c "client hello, adding alpn extension" \
2735 -s "found alpn extension" \
2736 -c "got an alert message, type: \\[2:120]" \
2737 -S "server hello, adding alpn extension" \
2738 -C "found alpn extension" \
2739 -C "Application Layer Protocol is 1234" \
2740 -S "Application Layer Protocol is 1234"
2741
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02002742
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002743# Tests for keyUsage in leaf certificates, part 1:
2744# server-side certificate/suite selection
2745
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002746run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002747 "$P_SRV key_file=data_files/server2.key \
2748 crt_file=data_files/server2.ku-ds.crt" \
2749 "$P_CLI" \
2750 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02002751 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002752
2753
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002754run_test "keyUsage srv: RSA, keyEncipherment -> RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002755 "$P_SRV key_file=data_files/server2.key \
2756 crt_file=data_files/server2.ku-ke.crt" \
2757 "$P_CLI" \
2758 0 \
2759 -c "Ciphersuite is TLS-RSA-WITH-"
2760
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002761run_test "keyUsage srv: RSA, keyAgreement -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002762 "$P_SRV key_file=data_files/server2.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002763 crt_file=data_files/server2.ku-ka.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002764 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002765 1 \
2766 -C "Ciphersuite is "
2767
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002768run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002769 "$P_SRV key_file=data_files/server5.key \
2770 crt_file=data_files/server5.ku-ds.crt" \
2771 "$P_CLI" \
2772 0 \
2773 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
2774
2775
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002776run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002777 "$P_SRV key_file=data_files/server5.key \
2778 crt_file=data_files/server5.ku-ka.crt" \
2779 "$P_CLI" \
2780 0 \
2781 -c "Ciphersuite is TLS-ECDH-"
2782
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002783run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002784 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002785 crt_file=data_files/server5.ku-ke.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002786 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002787 1 \
2788 -C "Ciphersuite is "
2789
2790# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002791# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002792
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002793run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002794 "$O_SRV -key data_files/server2.key \
2795 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002796 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002797 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2798 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002799 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002800 -C "Processing of the Certificate handshake message failed" \
2801 -c "Ciphersuite is TLS-"
2802
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002803run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002804 "$O_SRV -key data_files/server2.key \
2805 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002806 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002807 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2808 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002809 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002810 -C "Processing of the Certificate handshake message failed" \
2811 -c "Ciphersuite is TLS-"
2812
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002813run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002814 "$O_SRV -key data_files/server2.key \
2815 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002816 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002817 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2818 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002819 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002820 -C "Processing of the Certificate handshake message failed" \
2821 -c "Ciphersuite is TLS-"
2822
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002823run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002824 "$O_SRV -key data_files/server2.key \
2825 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002826 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002827 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2828 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002829 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002830 -c "Processing of the Certificate handshake message failed" \
2831 -C "Ciphersuite is TLS-"
2832
Manuel Pégourié-Gonnarde6efa6f2015-04-20 11:01:48 +01002833run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail, soft" \
2834 "$O_SRV -key data_files/server2.key \
2835 -cert data_files/server2.ku-ke.crt" \
2836 "$P_CLI debug_level=1 auth_mode=optional \
2837 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2838 0 \
2839 -c "bad certificate (usage extensions)" \
2840 -C "Processing of the Certificate handshake message failed" \
2841 -c "Ciphersuite is TLS-" \
2842 -c "! Usage does not match the keyUsage extension"
2843
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002844run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002845 "$O_SRV -key data_files/server2.key \
2846 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002847 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002848 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2849 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002850 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002851 -C "Processing of the Certificate handshake message failed" \
2852 -c "Ciphersuite is TLS-"
2853
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002854run_test "keyUsage cli: DigitalSignature, RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002855 "$O_SRV -key data_files/server2.key \
2856 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002857 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002858 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2859 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002860 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002861 -c "Processing of the Certificate handshake message failed" \
2862 -C "Ciphersuite is TLS-"
2863
Manuel Pégourié-Gonnarde6efa6f2015-04-20 11:01:48 +01002864run_test "keyUsage cli: DigitalSignature, RSA: fail, soft" \
2865 "$O_SRV -key data_files/server2.key \
2866 -cert data_files/server2.ku-ds.crt" \
2867 "$P_CLI debug_level=1 auth_mode=optional \
2868 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2869 0 \
2870 -c "bad certificate (usage extensions)" \
2871 -C "Processing of the Certificate handshake message failed" \
2872 -c "Ciphersuite is TLS-" \
2873 -c "! Usage does not match the keyUsage extension"
2874
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002875# Tests for keyUsage in leaf certificates, part 3:
2876# server-side checking of client cert
2877
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002878run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002879 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002880 "$O_CLI -key data_files/server2.key \
2881 -cert data_files/server2.ku-ds.crt" \
2882 0 \
2883 -S "bad certificate (usage extensions)" \
2884 -S "Processing of the Certificate handshake message failed"
2885
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002886run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002887 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002888 "$O_CLI -key data_files/server2.key \
2889 -cert data_files/server2.ku-ke.crt" \
2890 0 \
2891 -s "bad certificate (usage extensions)" \
2892 -S "Processing of the Certificate handshake message failed"
2893
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002894run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002895 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002896 "$O_CLI -key data_files/server2.key \
2897 -cert data_files/server2.ku-ke.crt" \
2898 1 \
2899 -s "bad certificate (usage extensions)" \
2900 -s "Processing of the Certificate handshake message failed"
2901
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002902run_test "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002903 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002904 "$O_CLI -key data_files/server5.key \
2905 -cert data_files/server5.ku-ds.crt" \
2906 0 \
2907 -S "bad certificate (usage extensions)" \
2908 -S "Processing of the Certificate handshake message failed"
2909
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002910run_test "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002911 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002912 "$O_CLI -key data_files/server5.key \
2913 -cert data_files/server5.ku-ka.crt" \
2914 0 \
2915 -s "bad certificate (usage extensions)" \
2916 -S "Processing of the Certificate handshake message failed"
2917
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002918# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
2919
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002920run_test "extKeyUsage srv: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002921 "$P_SRV key_file=data_files/server5.key \
2922 crt_file=data_files/server5.eku-srv.crt" \
2923 "$P_CLI" \
2924 0
2925
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002926run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002927 "$P_SRV key_file=data_files/server5.key \
2928 crt_file=data_files/server5.eku-srv.crt" \
2929 "$P_CLI" \
2930 0
2931
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002932run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002933 "$P_SRV key_file=data_files/server5.key \
2934 crt_file=data_files/server5.eku-cs_any.crt" \
2935 "$P_CLI" \
2936 0
2937
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002938run_test "extKeyUsage srv: codeSign -> fail" \
Manuel Pégourié-Gonnard7eb58cb2015-07-07 11:54:14 +02002939 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002940 crt_file=data_files/server5.eku-cli.crt" \
Manuel Pégourié-Gonnard7eb58cb2015-07-07 11:54:14 +02002941 "$P_CLI" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002942 1
2943
2944# Tests for extendedKeyUsage, part 2: client-side checking of server cert
2945
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002946run_test "extKeyUsage cli: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002947 "$O_SRV -key data_files/server5.key \
2948 -cert data_files/server5.eku-srv.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002949 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002950 0 \
2951 -C "bad certificate (usage extensions)" \
2952 -C "Processing of the Certificate handshake message failed" \
2953 -c "Ciphersuite is TLS-"
2954
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002955run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002956 "$O_SRV -key data_files/server5.key \
2957 -cert data_files/server5.eku-srv_cli.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002958 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002959 0 \
2960 -C "bad certificate (usage extensions)" \
2961 -C "Processing of the Certificate handshake message failed" \
2962 -c "Ciphersuite is TLS-"
2963
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002964run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002965 "$O_SRV -key data_files/server5.key \
2966 -cert data_files/server5.eku-cs_any.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002967 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002968 0 \
2969 -C "bad certificate (usage extensions)" \
2970 -C "Processing of the Certificate handshake message failed" \
2971 -c "Ciphersuite is TLS-"
2972
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002973run_test "extKeyUsage cli: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002974 "$O_SRV -key data_files/server5.key \
2975 -cert data_files/server5.eku-cs.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002976 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002977 1 \
2978 -c "bad certificate (usage extensions)" \
2979 -c "Processing of the Certificate handshake message failed" \
2980 -C "Ciphersuite is TLS-"
2981
2982# Tests for extendedKeyUsage, part 3: server-side checking of client cert
2983
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002984run_test "extKeyUsage cli-auth: clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002985 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002986 "$O_CLI -key data_files/server5.key \
2987 -cert data_files/server5.eku-cli.crt" \
2988 0 \
2989 -S "bad certificate (usage extensions)" \
2990 -S "Processing of the Certificate handshake message failed"
2991
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002992run_test "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002993 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002994 "$O_CLI -key data_files/server5.key \
2995 -cert data_files/server5.eku-srv_cli.crt" \
2996 0 \
2997 -S "bad certificate (usage extensions)" \
2998 -S "Processing of the Certificate handshake message failed"
2999
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003000run_test "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003001 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003002 "$O_CLI -key data_files/server5.key \
3003 -cert data_files/server5.eku-cs_any.crt" \
3004 0 \
3005 -S "bad certificate (usage extensions)" \
3006 -S "Processing of the Certificate handshake message failed"
3007
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003008run_test "extKeyUsage cli-auth: codeSign -> fail (soft)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003009 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003010 "$O_CLI -key data_files/server5.key \
3011 -cert data_files/server5.eku-cs.crt" \
3012 0 \
3013 -s "bad certificate (usage extensions)" \
3014 -S "Processing of the Certificate handshake message failed"
3015
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003016run_test "extKeyUsage cli-auth: codeSign -> fail (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003017 "$P_SRV debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02003018 "$O_CLI -key data_files/server5.key \
3019 -cert data_files/server5.eku-cs.crt" \
3020 1 \
3021 -s "bad certificate (usage extensions)" \
3022 -s "Processing of the Certificate handshake message failed"
3023
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003024# Tests for DHM parameters loading
3025
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003026run_test "DHM parameters: reference" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003027 "$P_SRV" \
3028 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3029 debug_level=3" \
3030 0 \
3031 -c "value of 'DHM: P ' (2048 bits)" \
3032 -c "value of 'DHM: G ' (2048 bits)"
3033
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003034run_test "DHM parameters: other parameters" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003035 "$P_SRV dhm_file=data_files/dhparams.pem" \
3036 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3037 debug_level=3" \
3038 0 \
3039 -c "value of 'DHM: P ' (1024 bits)" \
3040 -c "value of 'DHM: G ' (2 bits)"
3041
Manuel Pégourié-Gonnard7a010aa2015-06-12 11:19:10 +02003042# Tests for DHM client-side size checking
3043
3044run_test "DHM size: server default, client default, OK" \
3045 "$P_SRV" \
3046 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3047 debug_level=1" \
3048 0 \
3049 -C "DHM prime too short:"
3050
3051run_test "DHM size: server default, client 2048, OK" \
3052 "$P_SRV" \
3053 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3054 debug_level=1 dhmlen=2048" \
3055 0 \
3056 -C "DHM prime too short:"
3057
3058run_test "DHM size: server 1024, client default, OK" \
3059 "$P_SRV dhm_file=data_files/dhparams.pem" \
3060 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3061 debug_level=1" \
3062 0 \
3063 -C "DHM prime too short:"
3064
3065run_test "DHM size: server 1000, client default, rejected" \
3066 "$P_SRV dhm_file=data_files/dh.1000.pem" \
3067 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3068 debug_level=1" \
3069 1 \
3070 -c "DHM prime too short:"
3071
3072run_test "DHM size: server default, client 2049, rejected" \
3073 "$P_SRV" \
3074 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3075 debug_level=1 dhmlen=2049" \
3076 1 \
3077 -c "DHM prime too short:"
3078
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003079# Tests for PSK callback
3080
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003081run_test "PSK callback: psk, no callback" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003082 "$P_SRV psk=abc123 psk_identity=foo" \
3083 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3084 psk_identity=foo psk=abc123" \
3085 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003086 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02003087 -S "SSL - Unknown identity received" \
3088 -S "SSL - Verification of the message MAC failed"
3089
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003090run_test "PSK callback: no psk, no callback" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02003091 "$P_SRV" \
3092 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3093 psk_identity=foo psk=abc123" \
3094 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003095 -s "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003096 -S "SSL - Unknown identity received" \
3097 -S "SSL - Verification of the message MAC failed"
3098
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003099run_test "PSK callback: callback overrides other settings" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003100 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
3101 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3102 psk_identity=foo psk=abc123" \
3103 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003104 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003105 -s "SSL - Unknown identity received" \
3106 -S "SSL - Verification of the message MAC failed"
3107
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003108run_test "PSK callback: first id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003109 "$P_SRV psk_list=abc,dead,def,beef" \
3110 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3111 psk_identity=abc psk=dead" \
3112 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003113 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003114 -S "SSL - Unknown identity received" \
3115 -S "SSL - Verification of the message MAC failed"
3116
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003117run_test "PSK callback: second id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003118 "$P_SRV psk_list=abc,dead,def,beef" \
3119 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3120 psk_identity=def psk=beef" \
3121 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003122 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003123 -S "SSL - Unknown identity received" \
3124 -S "SSL - Verification of the message MAC failed"
3125
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003126run_test "PSK callback: no match" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003127 "$P_SRV psk_list=abc,dead,def,beef" \
3128 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3129 psk_identity=ghi psk=beef" \
3130 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003131 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003132 -s "SSL - Unknown identity received" \
3133 -S "SSL - Verification of the message MAC failed"
3134
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003135run_test "PSK callback: wrong key" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003136 "$P_SRV psk_list=abc,dead,def,beef" \
3137 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3138 psk_identity=abc psk=beef" \
3139 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003140 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003141 -S "SSL - Unknown identity received" \
3142 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003143
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003144# Tests for EC J-PAKE
3145
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003146requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003147run_test "ECJPAKE: client not configured" \
3148 "$P_SRV debug_level=3" \
3149 "$P_CLI debug_level=3" \
3150 0 \
3151 -C "add ciphersuite: c0ff" \
3152 -C "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003153 -S "found ecjpake kkpp extension" \
3154 -S "skip ecjpake kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003155 -S "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003156 -S "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003157 -C "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003158 -S "None of the common ciphersuites is usable"
3159
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003160requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003161run_test "ECJPAKE: server not configured" \
3162 "$P_SRV debug_level=3" \
3163 "$P_CLI debug_level=3 ecjpake_pw=bla \
3164 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3165 1 \
3166 -c "add ciphersuite: c0ff" \
3167 -c "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003168 -s "found ecjpake kkpp extension" \
3169 -s "skip ecjpake kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003170 -s "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003171 -S "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003172 -C "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003173 -s "None of the common ciphersuites is usable"
3174
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003175requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003176run_test "ECJPAKE: working, TLS" \
3177 "$P_SRV debug_level=3 ecjpake_pw=bla" \
3178 "$P_CLI debug_level=3 ecjpake_pw=bla \
3179 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
Manuel Pégourié-Gonnard0f1660a2015-09-16 22:41:06 +02003180 0 \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003181 -c "add ciphersuite: c0ff" \
3182 -c "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003183 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003184 -s "found ecjpake kkpp extension" \
3185 -S "skip ecjpake kkpp extension" \
3186 -S "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003187 -s "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003188 -c "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003189 -S "None of the common ciphersuites is usable" \
3190 -S "SSL - Verification of the message MAC failed"
3191
Janos Follath74537a62016-09-02 13:45:28 +01003192server_needs_more_time 1
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003193requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003194run_test "ECJPAKE: password mismatch, TLS" \
3195 "$P_SRV debug_level=3 ecjpake_pw=bla" \
3196 "$P_CLI debug_level=3 ecjpake_pw=bad \
3197 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3198 1 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003199 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003200 -s "SSL - Verification of the message MAC failed"
3201
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003202requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003203run_test "ECJPAKE: working, DTLS" \
3204 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
3205 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
3206 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3207 0 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003208 -c "re-using cached ecjpake parameters" \
3209 -S "SSL - Verification of the message MAC failed"
3210
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003211requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003212run_test "ECJPAKE: working, DTLS, no cookie" \
3213 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla cookies=0" \
3214 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
3215 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3216 0 \
3217 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003218 -S "SSL - Verification of the message MAC failed"
3219
Janos Follath74537a62016-09-02 13:45:28 +01003220server_needs_more_time 1
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003221requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003222run_test "ECJPAKE: password mismatch, DTLS" \
3223 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
3224 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bad \
3225 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3226 1 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003227 -c "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003228 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003229
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +02003230# for tests with configs/config-thread.h
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003231requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +02003232run_test "ECJPAKE: working, DTLS, nolog" \
3233 "$P_SRV dtls=1 ecjpake_pw=bla" \
3234 "$P_CLI dtls=1 ecjpake_pw=bla \
3235 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3236 0
3237
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003238# Tests for ciphersuites per version
3239
Janos Follathe2681a42016-03-07 15:57:05 +00003240requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003241run_test "Per-version suites: SSL3" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003242 "$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 +02003243 "$P_CLI force_version=ssl3" \
3244 0 \
3245 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
3246
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003247run_test "Per-version suites: TLS 1.0" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003248 "$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 +01003249 "$P_CLI force_version=tls1 arc4=1" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003250 0 \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003251 -c "Ciphersuite is TLS-RSA-WITH-AES-256-CBC-SHA"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003252
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003253run_test "Per-version suites: TLS 1.1" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003254 "$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 +02003255 "$P_CLI force_version=tls1_1" \
3256 0 \
3257 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
3258
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003259run_test "Per-version suites: TLS 1.2" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003260 "$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 +02003261 "$P_CLI force_version=tls1_2" \
3262 0 \
3263 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
3264
Manuel Pégourié-Gonnard4cc8c632015-07-23 12:24:03 +02003265# Test for ClientHello without extensions
3266
Manuel Pégourié-Gonnardd55bc202015-08-04 16:22:30 +02003267requires_gnutls
Gilles Peskine5d2511c2017-05-12 13:16:40 +02003268run_test "ClientHello without extensions, SHA-1 allowed" \
Manuel Pégourié-Gonnard4cc8c632015-07-23 12:24:03 +02003269 "$P_SRV debug_level=3" \
3270 "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \
3271 0 \
3272 -s "dumping 'client hello extensions' (0 bytes)"
3273
Gilles Peskine5d2511c2017-05-12 13:16:40 +02003274requires_gnutls
3275run_test "ClientHello without extensions, SHA-1 forbidden in certificates on server" \
3276 "$P_SRV debug_level=3 key_file=data_files/server2.key crt_file=data_files/server2.crt allow_sha1=0" \
3277 "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \
3278 0 \
3279 -s "dumping 'client hello extensions' (0 bytes)"
3280
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003281# Tests for mbedtls_ssl_get_bytes_avail()
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003282
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003283run_test "mbedtls_ssl_get_bytes_avail: no extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003284 "$P_SRV" \
3285 "$P_CLI request_size=100" \
3286 0 \
3287 -s "Read from client: 100 bytes read$"
3288
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003289run_test "mbedtls_ssl_get_bytes_avail: extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003290 "$P_SRV" \
3291 "$P_CLI request_size=500" \
3292 0 \
3293 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003294
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003295# Tests for small packets
3296
Janos Follathe2681a42016-03-07 15:57:05 +00003297requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003298run_test "Small packet SSLv3 BlockCipher" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01003299 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003300 "$P_CLI request_size=1 force_version=ssl3 \
3301 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3302 0 \
3303 -s "Read from client: 1 bytes read"
3304
Janos Follathe2681a42016-03-07 15:57:05 +00003305requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003306run_test "Small packet SSLv3 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003307 "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003308 "$P_CLI request_size=1 force_version=ssl3 \
3309 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3310 0 \
3311 -s "Read from client: 1 bytes read"
3312
3313run_test "Small packet TLS 1.0 BlockCipher" \
3314 "$P_SRV" \
3315 "$P_CLI request_size=1 force_version=tls1 \
3316 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3317 0 \
3318 -s "Read from client: 1 bytes read"
3319
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003320run_test "Small packet TLS 1.0 BlockCipher without EtM" \
3321 "$P_SRV" \
3322 "$P_CLI request_size=1 force_version=tls1 etm=0 \
3323 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3324 0 \
3325 -s "Read from client: 1 bytes read"
3326
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003327run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
3328 "$P_SRV" \
3329 "$P_CLI request_size=1 force_version=tls1 \
3330 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3331 trunc_hmac=1" \
3332 0 \
3333 -s "Read from client: 1 bytes read"
3334
3335run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003336 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003337 "$P_CLI request_size=1 force_version=tls1 \
3338 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3339 trunc_hmac=1" \
3340 0 \
3341 -s "Read from client: 1 bytes read"
3342
3343run_test "Small packet TLS 1.1 BlockCipher" \
3344 "$P_SRV" \
3345 "$P_CLI request_size=1 force_version=tls1_1 \
3346 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3347 0 \
3348 -s "Read from client: 1 bytes read"
3349
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003350run_test "Small packet TLS 1.1 BlockCipher without EtM" \
3351 "$P_SRV" \
3352 "$P_CLI request_size=1 force_version=tls1_1 etm=0 \
3353 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3354 0 \
3355 -s "Read from client: 1 bytes read"
3356
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003357run_test "Small packet TLS 1.1 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003358 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003359 "$P_CLI request_size=1 force_version=tls1_1 \
3360 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3361 0 \
3362 -s "Read from client: 1 bytes read"
3363
3364run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
3365 "$P_SRV" \
3366 "$P_CLI request_size=1 force_version=tls1_1 \
3367 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3368 trunc_hmac=1" \
3369 0 \
3370 -s "Read from client: 1 bytes read"
3371
3372run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003373 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003374 "$P_CLI request_size=1 force_version=tls1_1 \
3375 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3376 trunc_hmac=1" \
3377 0 \
3378 -s "Read from client: 1 bytes read"
3379
3380run_test "Small packet TLS 1.2 BlockCipher" \
3381 "$P_SRV" \
3382 "$P_CLI request_size=1 force_version=tls1_2 \
3383 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3384 0 \
3385 -s "Read from client: 1 bytes read"
3386
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003387run_test "Small packet TLS 1.2 BlockCipher without EtM" \
3388 "$P_SRV" \
3389 "$P_CLI request_size=1 force_version=tls1_2 etm=0 \
3390 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3391 0 \
3392 -s "Read from client: 1 bytes read"
3393
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003394run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
3395 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003396 "$P_CLI request_size=1 force_version=tls1_2 \
3397 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003398 0 \
3399 -s "Read from client: 1 bytes read"
3400
3401run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
3402 "$P_SRV" \
3403 "$P_CLI request_size=1 force_version=tls1_2 \
3404 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3405 trunc_hmac=1" \
3406 0 \
3407 -s "Read from client: 1 bytes read"
3408
3409run_test "Small packet TLS 1.2 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003410 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003411 "$P_CLI request_size=1 force_version=tls1_2 \
3412 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3413 0 \
3414 -s "Read from client: 1 bytes read"
3415
3416run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003417 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003418 "$P_CLI request_size=1 force_version=tls1_2 \
3419 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3420 trunc_hmac=1" \
3421 0 \
3422 -s "Read from client: 1 bytes read"
3423
3424run_test "Small packet TLS 1.2 AEAD" \
3425 "$P_SRV" \
3426 "$P_CLI request_size=1 force_version=tls1_2 \
3427 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
3428 0 \
3429 -s "Read from client: 1 bytes read"
3430
3431run_test "Small packet TLS 1.2 AEAD shorter tag" \
3432 "$P_SRV" \
3433 "$P_CLI request_size=1 force_version=tls1_2 \
3434 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
3435 0 \
3436 -s "Read from client: 1 bytes read"
3437
Janos Follath00efff72016-05-06 13:48:23 +01003438# A test for extensions in SSLv3
3439
3440requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
3441run_test "SSLv3 with extensions, server side" \
3442 "$P_SRV min_version=ssl3 debug_level=3" \
3443 "$P_CLI force_version=ssl3 tickets=1 max_frag_len=4096 alpn=abc,1234" \
3444 0 \
3445 -S "dumping 'client hello extensions'" \
3446 -S "server hello, total extension length:"
3447
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003448# Test for large packets
3449
Janos Follathe2681a42016-03-07 15:57:05 +00003450requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003451run_test "Large packet SSLv3 BlockCipher" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01003452 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003453 "$P_CLI request_size=16384 force_version=ssl3 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003454 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3455 0 \
3456 -s "Read from client: 16384 bytes read"
3457
Janos Follathe2681a42016-03-07 15:57:05 +00003458requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003459run_test "Large packet SSLv3 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003460 "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003461 "$P_CLI request_size=16384 force_version=ssl3 \
3462 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3463 0 \
3464 -s "Read from client: 16384 bytes read"
3465
3466run_test "Large packet TLS 1.0 BlockCipher" \
3467 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003468 "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003469 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3470 0 \
3471 -s "Read from client: 16384 bytes read"
3472
3473run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
3474 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003475 "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003476 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3477 trunc_hmac=1" \
3478 0 \
3479 -s "Read from client: 16384 bytes read"
3480
3481run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003482 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003483 "$P_CLI request_size=16384 force_version=tls1 \
3484 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3485 trunc_hmac=1" \
3486 0 \
3487 -s "Read from client: 16384 bytes read"
3488
3489run_test "Large packet TLS 1.1 BlockCipher" \
3490 "$P_SRV" \
3491 "$P_CLI request_size=16384 force_version=tls1_1 \
3492 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3493 0 \
3494 -s "Read from client: 16384 bytes read"
3495
3496run_test "Large packet TLS 1.1 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003497 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003498 "$P_CLI request_size=16384 force_version=tls1_1 \
3499 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3500 0 \
3501 -s "Read from client: 16384 bytes read"
3502
3503run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
3504 "$P_SRV" \
3505 "$P_CLI request_size=16384 force_version=tls1_1 \
3506 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3507 trunc_hmac=1" \
3508 0 \
3509 -s "Read from client: 16384 bytes read"
3510
3511run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003512 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003513 "$P_CLI request_size=16384 force_version=tls1_1 \
3514 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3515 trunc_hmac=1" \
3516 0 \
3517 -s "Read from client: 16384 bytes read"
3518
3519run_test "Large packet TLS 1.2 BlockCipher" \
3520 "$P_SRV" \
3521 "$P_CLI request_size=16384 force_version=tls1_2 \
3522 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3523 0 \
3524 -s "Read from client: 16384 bytes read"
3525
3526run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
3527 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003528 "$P_CLI request_size=16384 force_version=tls1_2 \
3529 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003530 0 \
3531 -s "Read from client: 16384 bytes read"
3532
3533run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
3534 "$P_SRV" \
3535 "$P_CLI request_size=16384 force_version=tls1_2 \
3536 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3537 trunc_hmac=1" \
3538 0 \
3539 -s "Read from client: 16384 bytes read"
3540
3541run_test "Large packet TLS 1.2 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003542 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003543 "$P_CLI request_size=16384 force_version=tls1_2 \
3544 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3545 0 \
3546 -s "Read from client: 16384 bytes read"
3547
3548run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003549 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003550 "$P_CLI request_size=16384 force_version=tls1_2 \
3551 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3552 trunc_hmac=1" \
3553 0 \
3554 -s "Read from client: 16384 bytes read"
3555
3556run_test "Large packet TLS 1.2 AEAD" \
3557 "$P_SRV" \
3558 "$P_CLI request_size=16384 force_version=tls1_2 \
3559 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
3560 0 \
3561 -s "Read from client: 16384 bytes read"
3562
3563run_test "Large packet TLS 1.2 AEAD shorter tag" \
3564 "$P_SRV" \
3565 "$P_CLI request_size=16384 force_version=tls1_2 \
3566 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
3567 0 \
3568 -s "Read from client: 16384 bytes read"
3569
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003570# Tests for DTLS HelloVerifyRequest
3571
3572run_test "DTLS cookie: enabled" \
3573 "$P_SRV dtls=1 debug_level=2" \
3574 "$P_CLI dtls=1 debug_level=2" \
3575 0 \
3576 -s "cookie verification failed" \
3577 -s "cookie verification passed" \
3578 -S "cookie verification skipped" \
3579 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003580 -s "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003581 -S "SSL - The requested feature is not available"
3582
3583run_test "DTLS cookie: disabled" \
3584 "$P_SRV dtls=1 debug_level=2 cookies=0" \
3585 "$P_CLI dtls=1 debug_level=2" \
3586 0 \
3587 -S "cookie verification failed" \
3588 -S "cookie verification passed" \
3589 -s "cookie verification skipped" \
3590 -C "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003591 -S "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003592 -S "SSL - The requested feature is not available"
3593
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003594run_test "DTLS cookie: default (failing)" \
3595 "$P_SRV dtls=1 debug_level=2 cookies=-1" \
3596 "$P_CLI dtls=1 debug_level=2 hs_timeout=100-400" \
3597 1 \
3598 -s "cookie verification failed" \
3599 -S "cookie verification passed" \
3600 -S "cookie verification skipped" \
3601 -C "received hello verify request" \
3602 -S "hello verification requested" \
3603 -s "SSL - The requested feature is not available"
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003604
3605requires_ipv6
3606run_test "DTLS cookie: enabled, IPv6" \
3607 "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
3608 "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
3609 0 \
3610 -s "cookie verification failed" \
3611 -s "cookie verification passed" \
3612 -S "cookie verification skipped" \
3613 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003614 -s "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003615 -S "SSL - The requested feature is not available"
3616
Manuel Pégourié-Gonnard579950c2014-09-29 17:47:33 +02003617run_test "DTLS cookie: enabled, nbio" \
3618 "$P_SRV dtls=1 nbio=2 debug_level=2" \
3619 "$P_CLI dtls=1 nbio=2 debug_level=2" \
3620 0 \
3621 -s "cookie verification failed" \
3622 -s "cookie verification passed" \
3623 -S "cookie verification skipped" \
3624 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003625 -s "hello verification requested" \
Manuel Pégourié-Gonnard579950c2014-09-29 17:47:33 +02003626 -S "SSL - The requested feature is not available"
3627
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003628# Tests for client reconnecting from the same port with DTLS
3629
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003630not_with_valgrind # spurious resend
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003631run_test "DTLS client reconnect from same port: reference" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003632 "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
3633 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003634 0 \
3635 -C "resend" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003636 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003637 -S "Client initiated reconnection from same port"
3638
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003639not_with_valgrind # spurious resend
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003640run_test "DTLS client reconnect from same port: reconnect" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003641 "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
3642 "$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 +02003643 0 \
3644 -C "resend" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003645 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003646 -s "Client initiated reconnection from same port"
3647
Paul Bakker362689d2016-05-13 10:33:25 +01003648not_with_valgrind # server/client too slow to respond in time (next test has higher timeouts)
3649run_test "DTLS client reconnect from same port: reconnect, nbio, no valgrind" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003650 "$P_SRV dtls=1 exchanges=2 read_timeout=1000 nbio=2" \
3651 "$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 +02003652 0 \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003653 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003654 -s "Client initiated reconnection from same port"
3655
Paul Bakker362689d2016-05-13 10:33:25 +01003656only_with_valgrind # Only with valgrind, do previous test but with higher read_timeout and hs_timeout
3657run_test "DTLS client reconnect from same port: reconnect, nbio, valgrind" \
3658 "$P_SRV dtls=1 exchanges=2 read_timeout=2000 nbio=2 hs_timeout=1500-6000" \
3659 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=1500-3000 reconnect_hard=1" \
3660 0 \
3661 -S "The operation timed out" \
3662 -s "Client initiated reconnection from same port"
3663
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003664run_test "DTLS client reconnect from same port: no cookies" \
3665 "$P_SRV dtls=1 exchanges=2 read_timeout=1000 cookies=0" \
Manuel Pégourié-Gonnard6ad23b92015-09-15 12:57:46 +02003666 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-8000 reconnect_hard=1" \
3667 0 \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003668 -s "The operation timed out" \
3669 -S "Client initiated reconnection from same port"
3670
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003671# Tests for various cases of client authentication with DTLS
3672# (focused on handshake flows and message parsing)
3673
3674run_test "DTLS client auth: required" \
3675 "$P_SRV dtls=1 auth_mode=required" \
3676 "$P_CLI dtls=1" \
3677 0 \
3678 -s "Verifying peer X.509 certificate... ok"
3679
3680run_test "DTLS client auth: optional, client has no cert" \
3681 "$P_SRV dtls=1 auth_mode=optional" \
3682 "$P_CLI dtls=1 crt_file=none key_file=none" \
3683 0 \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01003684 -s "! Certificate was missing"
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003685
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01003686run_test "DTLS client auth: none, client has no cert" \
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003687 "$P_SRV dtls=1 auth_mode=none" \
3688 "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
3689 0 \
3690 -c "skip write certificate$" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01003691 -s "! Certificate verification was skipped"
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003692
Manuel Pégourié-Gonnard0a885742015-08-04 12:08:35 +02003693run_test "DTLS wrong PSK: badmac alert" \
3694 "$P_SRV dtls=1 psk=abc123 force_ciphersuite=TLS-PSK-WITH-AES-128-GCM-SHA256" \
3695 "$P_CLI dtls=1 psk=abc124" \
3696 1 \
3697 -s "SSL - Verification of the message MAC failed" \
3698 -c "SSL - A fatal alert message was received from our peer"
3699
Manuel Pégourié-Gonnard502bf302014-08-20 13:12:58 +02003700# Tests for receiving fragmented handshake messages with DTLS
3701
3702requires_gnutls
3703run_test "DTLS reassembly: no fragmentation (gnutls server)" \
3704 "$G_SRV -u --mtu 2048 -a" \
3705 "$P_CLI dtls=1 debug_level=2" \
3706 0 \
3707 -C "found fragmented DTLS handshake message" \
3708 -C "error"
3709
3710requires_gnutls
3711run_test "DTLS reassembly: some fragmentation (gnutls server)" \
3712 "$G_SRV -u --mtu 512" \
3713 "$P_CLI dtls=1 debug_level=2" \
3714 0 \
3715 -c "found fragmented DTLS handshake message" \
3716 -C "error"
3717
3718requires_gnutls
3719run_test "DTLS reassembly: more fragmentation (gnutls server)" \
3720 "$G_SRV -u --mtu 128" \
3721 "$P_CLI dtls=1 debug_level=2" \
3722 0 \
3723 -c "found fragmented DTLS handshake message" \
3724 -C "error"
3725
3726requires_gnutls
3727run_test "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
3728 "$G_SRV -u --mtu 128" \
3729 "$P_CLI dtls=1 nbio=2 debug_level=2" \
3730 0 \
3731 -c "found fragmented DTLS handshake message" \
3732 -C "error"
3733
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003734requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003735run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
3736 "$G_SRV -u --mtu 256" \
3737 "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
3738 0 \
3739 -c "found fragmented DTLS handshake message" \
3740 -c "client hello, adding renegotiation extension" \
3741 -c "found renegotiation extension" \
3742 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003743 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003744 -C "error" \
3745 -s "Extra-header:"
3746
3747requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003748run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
3749 "$G_SRV -u --mtu 256" \
3750 "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
3751 0 \
3752 -c "found fragmented DTLS handshake message" \
3753 -c "client hello, adding renegotiation extension" \
3754 -c "found renegotiation extension" \
3755 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003756 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003757 -C "error" \
3758 -s "Extra-header:"
3759
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02003760run_test "DTLS reassembly: no fragmentation (openssl server)" \
3761 "$O_SRV -dtls1 -mtu 2048" \
3762 "$P_CLI dtls=1 debug_level=2" \
3763 0 \
3764 -C "found fragmented DTLS handshake message" \
3765 -C "error"
3766
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003767run_test "DTLS reassembly: some fragmentation (openssl server)" \
3768 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02003769 "$P_CLI dtls=1 debug_level=2" \
3770 0 \
3771 -c "found fragmented DTLS handshake message" \
3772 -C "error"
3773
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003774run_test "DTLS reassembly: more fragmentation (openssl server)" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02003775 "$O_SRV -dtls1 -mtu 256" \
3776 "$P_CLI dtls=1 debug_level=2" \
3777 0 \
3778 -c "found fragmented DTLS handshake message" \
3779 -C "error"
3780
3781run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
3782 "$O_SRV -dtls1 -mtu 256" \
3783 "$P_CLI dtls=1 nbio=2 debug_level=2" \
3784 0 \
3785 -c "found fragmented DTLS handshake message" \
3786 -C "error"
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02003787
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02003788# Tests for specific things with "unreliable" UDP connection
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02003789
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003790not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003791run_test "DTLS proxy: reference" \
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02003792 -p "$P_PXY" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003793 "$P_SRV dtls=1 debug_level=2" \
3794 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003795 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003796 -C "replayed record" \
3797 -S "replayed record" \
3798 -C "record from another epoch" \
3799 -S "record from another epoch" \
3800 -C "discarding invalid record" \
3801 -S "discarding invalid record" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003802 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02003803 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003804 -c "HTTP/1.0 200 OK"
3805
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003806not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02003807run_test "DTLS proxy: duplicate every packet" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003808 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003809 "$P_SRV dtls=1 debug_level=2" \
3810 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003811 0 \
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02003812 -c "replayed record" \
3813 -s "replayed record" \
Hanno Becker52c6dc62017-05-26 16:07:36 +01003814 -c "record from another epoch" \
3815 -s "record from another epoch" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003816 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02003817 -s "Extra-header:" \
3818 -c "HTTP/1.0 200 OK"
3819
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02003820run_test "DTLS proxy: duplicate every packet, server anti-replay off" \
3821 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003822 "$P_SRV dtls=1 debug_level=2 anti_replay=0" \
3823 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02003824 0 \
3825 -c "replayed record" \
3826 -S "replayed record" \
Hanno Becker52c6dc62017-05-26 16:07:36 +01003827 -c "record from another epoch" \
3828 -s "record from another epoch" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003829 -c "resend" \
3830 -s "resend" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02003831 -s "Extra-header:" \
3832 -c "HTTP/1.0 200 OK"
3833
Hanno Becker72a4f032017-11-15 16:39:20 +00003834run_test "DTLS proxy: multiple records in same datagram" \
Hanno Becker8d832182018-03-15 10:14:19 +00003835 -p "$P_PXY pack=50" \
Hanno Becker72a4f032017-11-15 16:39:20 +00003836 "$P_SRV dtls=1 debug_level=2" \
3837 "$P_CLI dtls=1 debug_level=2" \
3838 0 \
3839 -c "next record in same datagram" \
3840 -s "next record in same datagram"
3841
3842run_test "DTLS proxy: multiple records in same datagram, duplicate every packet" \
Hanno Becker8d832182018-03-15 10:14:19 +00003843 -p "$P_PXY pack=50 duplicate=1" \
Hanno Becker72a4f032017-11-15 16:39:20 +00003844 "$P_SRV dtls=1 debug_level=2" \
3845 "$P_CLI dtls=1 debug_level=2" \
3846 0 \
3847 -c "next record in same datagram" \
3848 -s "next record in same datagram"
3849
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003850run_test "DTLS proxy: inject invalid AD record, default badmac_limit" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02003851 -p "$P_PXY bad_ad=1" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003852 "$P_SRV dtls=1 debug_level=1" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003853 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003854 0 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003855 -c "discarding invalid record (mac)" \
3856 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003857 -s "Extra-header:" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003858 -c "HTTP/1.0 200 OK" \
3859 -S "too many records with bad MAC" \
3860 -S "Verification of the message MAC failed"
3861
3862run_test "DTLS proxy: inject invalid AD record, badmac_limit 1" \
3863 -p "$P_PXY bad_ad=1" \
3864 "$P_SRV dtls=1 debug_level=1 badmac_limit=1" \
3865 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
3866 1 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003867 -C "discarding invalid record (mac)" \
3868 -S "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003869 -S "Extra-header:" \
3870 -C "HTTP/1.0 200 OK" \
3871 -s "too many records with bad MAC" \
3872 -s "Verification of the message MAC failed"
3873
3874run_test "DTLS proxy: inject invalid AD record, badmac_limit 2" \
3875 -p "$P_PXY bad_ad=1" \
3876 "$P_SRV dtls=1 debug_level=1 badmac_limit=2" \
3877 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
3878 0 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003879 -c "discarding invalid record (mac)" \
3880 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003881 -s "Extra-header:" \
3882 -c "HTTP/1.0 200 OK" \
3883 -S "too many records with bad MAC" \
3884 -S "Verification of the message MAC failed"
3885
3886run_test "DTLS proxy: inject invalid AD record, badmac_limit 2, exchanges 2"\
3887 -p "$P_PXY bad_ad=1" \
3888 "$P_SRV dtls=1 debug_level=1 badmac_limit=2 exchanges=2" \
3889 "$P_CLI dtls=1 debug_level=1 read_timeout=100 exchanges=2" \
3890 1 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003891 -c "discarding invalid record (mac)" \
3892 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003893 -s "Extra-header:" \
3894 -c "HTTP/1.0 200 OK" \
3895 -s "too many records with bad MAC" \
3896 -s "Verification of the message MAC failed"
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003897
3898run_test "DTLS proxy: delay ChangeCipherSpec" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003899 -p "$P_PXY delay_ccs=1" \
3900 "$P_SRV dtls=1 debug_level=1" \
3901 "$P_CLI dtls=1 debug_level=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003902 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003903 -c "record from another epoch" \
3904 -s "record from another epoch" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003905 -s "Extra-header:" \
3906 -c "HTTP/1.0 200 OK"
3907
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02003908# Tests for "randomly unreliable connection": try a variety of flows and peers
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003909
Janos Follath74537a62016-09-02 13:45:28 +01003910client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003911run_test "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003912 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003913 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
3914 psk=abc123" \
3915 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003916 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
3917 0 \
3918 -s "Extra-header:" \
3919 -c "HTTP/1.0 200 OK"
3920
Janos Follath74537a62016-09-02 13:45:28 +01003921client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003922run_test "DTLS proxy: 3d, \"short\" RSA handshake" \
3923 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003924 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
3925 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003926 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3927 0 \
3928 -s "Extra-header:" \
3929 -c "HTTP/1.0 200 OK"
3930
Janos Follath74537a62016-09-02 13:45:28 +01003931client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003932run_test "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
3933 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003934 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
3935 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003936 0 \
3937 -s "Extra-header:" \
3938 -c "HTTP/1.0 200 OK"
3939
Janos Follath74537a62016-09-02 13:45:28 +01003940client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003941run_test "DTLS proxy: 3d, FS, client auth" \
3942 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003943 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=required" \
3944 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003945 0 \
3946 -s "Extra-header:" \
3947 -c "HTTP/1.0 200 OK"
3948
Janos Follath74537a62016-09-02 13:45:28 +01003949client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003950run_test "DTLS proxy: 3d, FS, ticket" \
3951 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003952 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=none" \
3953 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003954 0 \
3955 -s "Extra-header:" \
3956 -c "HTTP/1.0 200 OK"
3957
Janos Follath74537a62016-09-02 13:45:28 +01003958client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003959run_test "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
3960 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003961 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=required" \
3962 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003963 0 \
3964 -s "Extra-header:" \
3965 -c "HTTP/1.0 200 OK"
3966
Janos Follath74537a62016-09-02 13:45:28 +01003967client_needs_more_time 2
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02003968run_test "DTLS proxy: 3d, max handshake, nbio" \
3969 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003970 "$P_SRV dtls=1 hs_timeout=250-10000 nbio=2 tickets=1 \
3971 auth_mode=required" \
3972 "$P_CLI dtls=1 hs_timeout=250-10000 nbio=2 tickets=1" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02003973 0 \
3974 -s "Extra-header:" \
3975 -c "HTTP/1.0 200 OK"
3976
Janos Follath74537a62016-09-02 13:45:28 +01003977client_needs_more_time 4
Manuel Pégourié-Gonnard7a26d732014-10-02 14:50:46 +02003978run_test "DTLS proxy: 3d, min handshake, resumption" \
3979 -p "$P_PXY drop=5 delay=5 duplicate=5" \
3980 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
3981 psk=abc123 debug_level=3" \
3982 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
3983 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
3984 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
3985 0 \
3986 -s "a session has been resumed" \
3987 -c "a session has been resumed" \
3988 -s "Extra-header:" \
3989 -c "HTTP/1.0 200 OK"
3990
Janos Follath74537a62016-09-02 13:45:28 +01003991client_needs_more_time 4
Manuel Pégourié-Gonnard85beb302014-10-02 17:59:19 +02003992run_test "DTLS proxy: 3d, min handshake, resumption, nbio" \
3993 -p "$P_PXY drop=5 delay=5 duplicate=5" \
3994 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
3995 psk=abc123 debug_level=3 nbio=2" \
3996 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
3997 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
3998 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
3999 0 \
4000 -s "a session has been resumed" \
4001 -c "a session has been resumed" \
4002 -s "Extra-header:" \
4003 -c "HTTP/1.0 200 OK"
4004
Janos Follath74537a62016-09-02 13:45:28 +01004005client_needs_more_time 4
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004006run_test "DTLS proxy: 3d, min handshake, client-initiated renego" \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02004007 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02004008 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
4009 psk=abc123 renegotiation=1 debug_level=2" \
4010 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
4011 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02004012 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4013 0 \
4014 -c "=> renegotiate" \
4015 -s "=> renegotiate" \
4016 -s "Extra-header:" \
4017 -c "HTTP/1.0 200 OK"
4018
Janos Follath74537a62016-09-02 13:45:28 +01004019client_needs_more_time 4
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004020run_test "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
4021 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02004022 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
4023 psk=abc123 renegotiation=1 debug_level=2" \
4024 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
4025 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004026 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4027 0 \
4028 -c "=> renegotiate" \
4029 -s "=> renegotiate" \
4030 -s "Extra-header:" \
4031 -c "HTTP/1.0 200 OK"
4032
Janos Follath74537a62016-09-02 13:45:28 +01004033client_needs_more_time 4
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004034run_test "DTLS proxy: 3d, min handshake, server-initiated renego" \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004035 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004036 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004037 psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004038 debug_level=2" \
4039 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004040 renegotiation=1 exchanges=4 debug_level=2 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004041 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4042 0 \
4043 -c "=> renegotiate" \
4044 -s "=> renegotiate" \
4045 -s "Extra-header:" \
4046 -c "HTTP/1.0 200 OK"
4047
Janos Follath74537a62016-09-02 13:45:28 +01004048client_needs_more_time 4
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004049run_test "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004050 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004051 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004052 psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004053 debug_level=2 nbio=2" \
4054 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004055 renegotiation=1 exchanges=4 debug_level=2 nbio=2 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004056 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4057 0 \
4058 -c "=> renegotiate" \
4059 -s "=> renegotiate" \
4060 -s "Extra-header:" \
4061 -c "HTTP/1.0 200 OK"
4062
Janos Follath74537a62016-09-02 13:45:28 +01004063client_needs_more_time 6
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004064not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004065run_test "DTLS proxy: 3d, openssl server" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02004066 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
4067 "$O_SRV -dtls1 -mtu 2048" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00004068 "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02004069 0 \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02004070 -c "HTTP/1.0 200 OK"
4071
Janos Follath74537a62016-09-02 13:45:28 +01004072client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004073not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004074run_test "DTLS proxy: 3d, openssl server, fragmentation" \
4075 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
4076 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00004077 "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004078 0 \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004079 -c "HTTP/1.0 200 OK"
4080
Janos Follath74537a62016-09-02 13:45:28 +01004081client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004082not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004083run_test "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
4084 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
4085 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00004086 "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2 tickets=0" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004087 0 \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004088 -c "HTTP/1.0 200 OK"
4089
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00004090requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01004091client_needs_more_time 6
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004092not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004093run_test "DTLS proxy: 3d, gnutls server" \
4094 -p "$P_PXY drop=5 delay=5 duplicate=5" \
4095 "$G_SRV -u --mtu 2048 -a" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02004096 "$P_CLI dtls=1 hs_timeout=250-60000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004097 0 \
4098 -s "Extra-header:" \
4099 -c "Extra-header:"
4100
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00004101requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01004102client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004103not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004104run_test "DTLS proxy: 3d, gnutls server, fragmentation" \
4105 -p "$P_PXY drop=5 delay=5 duplicate=5" \
4106 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02004107 "$P_CLI dtls=1 hs_timeout=250-60000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004108 0 \
4109 -s "Extra-header:" \
4110 -c "Extra-header:"
4111
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00004112requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01004113client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004114not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004115run_test "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
4116 -p "$P_PXY drop=5 delay=5 duplicate=5" \
4117 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02004118 "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004119 0 \
4120 -s "Extra-header:" \
4121 -c "Extra-header:"
4122
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01004123# Final report
4124
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004125echo "------------------------------------------------------------------------"
4126
4127if [ $FAILS = 0 ]; then
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +01004128 printf "PASSED"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004129else
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +01004130 printf "FAILED"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004131fi
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +02004132PASSES=$(( $TESTS - $FAILS ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +02004133echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004134
4135exit $FAILS