blob: 1682a8476f6e8d25ff18645633500978ebbe87ef [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 Beckeradfa64f2018-03-15 11:35:07 +0000450 wait $SRV_PID
Hanno Beckerd82d8462017-05-29 21:37:46 +0100451
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200452 if [ -n "$PXY_CMD" ]; then
453 kill $PXY_PID >/dev/null 2>&1
Hanno Beckeradfa64f2018-03-15 11:35:07 +0000454 wait $PXY_PID
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200455 fi
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100456
Manuel Pégourié-Gonnardab5f7b42015-08-04 21:01:37 +0200457 # retry only on timeouts
458 if grep '===CLIENT_TIMEOUT===' $CLI_OUT >/dev/null; then
459 printf "RETRY "
460 else
461 TIMES_LEFT=0
462 fi
Manuel Pégourié-Gonnarda365add2015-08-04 20:57:59 +0200463 done
464
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100465 # check if the client and server went at least to the handshake stage
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200466 # (useful to avoid tests with only negative assertions and non-zero
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100467 # expected client exit to incorrectly succeed in case of catastrophic
468 # failure)
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100469 if is_polar "$SRV_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200470 if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100471 else
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100472 fail "server or client failed to reach handshake stage"
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100473 return
474 fi
475 fi
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100476 if is_polar "$CLI_CMD"; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200477 if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100478 else
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100479 fail "server or client failed to reach handshake stage"
Manuel Pégourié-Gonnard677884d2014-02-25 16:42:31 +0100480 return
481 fi
482 fi
483
Manuel Pégourié-Gonnardf8bdbb52014-02-21 09:20:14 +0100484 # check server exit code
485 if [ $? != 0 ]; then
486 fail "server fail"
487 return
488 fi
489
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100490 # check client exit code
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +0100491 if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
492 \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100493 then
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200494 fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100495 return
496 fi
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100497
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100498 # check other assertions
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200499 # lines beginning with == are added by valgrind, ignore them
Paul Bakker1f650922016-05-13 10:16:46 +0100500 # lines with 'Serious error when reading debug info', are valgrind issues as well
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100501 while [ $# -gt 0 ]
502 do
503 case $1 in
504 "-s")
Paul Bakker1f650922016-05-13 10:16:46 +0100505 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 +0100506 fail "pattern '$2' MUST be present in the Server output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100507 return
508 fi
509 ;;
510
511 "-c")
Paul Bakker1f650922016-05-13 10:16:46 +0100512 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 +0100513 fail "pattern '$2' MUST be present in the Client output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100514 return
515 fi
516 ;;
517
518 "-S")
Paul Bakker1f650922016-05-13 10:16:46 +0100519 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 +0100520 fail "pattern '$2' MUST NOT be present in the Server output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100521 return
522 fi
523 ;;
524
525 "-C")
Paul Bakker1f650922016-05-13 10:16:46 +0100526 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 +0100527 fail "pattern '$2' MUST NOT be present in the Client output"
528 return
529 fi
530 ;;
531
532 # The filtering in the following two options (-u and -U) do the following
533 # - ignore valgrind output
534 # - filter out everything but lines right after the pattern occurances
535 # - keep one of each non-unique line
536 # - count how many lines remain
537 # A line with '--' will remain in the result from previous outputs, so the number of lines in the result will be 1
538 # if there were no duplicates.
539 "-U")
540 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
541 fail "lines following pattern '$2' must be unique in Server output"
542 return
543 fi
544 ;;
545
546 "-u")
547 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
548 fail "lines following pattern '$2' must be unique in Client output"
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100549 return
550 fi
551 ;;
552
553 *)
Paul Bakker1ebc0c52014-05-22 15:47:58 +0200554 echo "Unknown test: $1" >&2
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100555 exit 1
556 esac
557 shift 2
558 done
559
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100560 # check valgrind's results
561 if [ "$MEMCHECK" -gt 0 ]; then
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200562 if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100563 fail "Server has memory errors"
564 return
565 fi
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200566 if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +0100567 fail "Client has memory errors"
568 return
569 fi
570 fi
571
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100572 # if we're here, everything is ok
573 echo "PASS"
Paul Bakkeracaac852016-05-10 11:47:13 +0100574 if [ "$PRESERVE_LOGS" -gt 0 ]; then
575 mv $SRV_OUT o-srv-${TESTS}.log
576 mv $CLI_OUT o-cli-${TESTS}.log
577 fi
578
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200579 rm -f $SRV_OUT $CLI_OUT $PXY_OUT
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100580}
581
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100582cleanup() {
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200583 rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
Manuel Pégourié-Gonnarda6189f02014-09-20 13:15:43 +0200584 test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
585 test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
586 test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
587 test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100588 exit 1
589}
590
Manuel Pégourié-Gonnard9dea8bd2014-02-26 18:21:02 +0100591#
592# MAIN
593#
594
Manuel Pégourié-Gonnard19db8ea2015-03-10 13:41:04 +0000595if cd $( dirname $0 ); then :; else
596 echo "cd $( dirname $0 ) failed" >&2
597 exit 1
598fi
599
Manuel Pégourié-Gonnard913030c2014-03-28 10:12:38 +0100600get_options "$@"
601
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100602# sanity checks, avoid an avalanche of errors
Hanno Becker4ac73e72017-10-23 15:27:37 +0100603P_SRV_BIN="${P_SRV%%[ ]*}"
604P_CLI_BIN="${P_CLI%%[ ]*}"
605P_PXY_BIN="${P_PXY%%[ ]*}"
Hanno Becker17c04932017-10-10 14:44:53 +0100606if [ ! -x "$P_SRV_BIN" ]; then
607 echo "Command '$P_SRV_BIN' is not an executable file"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100608 exit 1
609fi
Hanno Becker17c04932017-10-10 14:44:53 +0100610if [ ! -x "$P_CLI_BIN" ]; then
611 echo "Command '$P_CLI_BIN' is not an executable file"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100612 exit 1
613fi
Hanno Becker17c04932017-10-10 14:44:53 +0100614if [ ! -x "$P_PXY_BIN" ]; then
615 echo "Command '$P_PXY_BIN' is not an executable file"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200616 exit 1
617fi
Simon Butcher3c0d7b82016-05-23 11:13:17 +0100618if [ "$MEMCHECK" -gt 0 ]; then
619 if which valgrind >/dev/null 2>&1; then :; else
620 echo "Memcheck not possible. Valgrind not found"
621 exit 1
622 fi
623fi
Manuel Pégourié-Gonnard74faf3c2014-03-13 18:47:44 +0100624if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
625 echo "Command '$OPENSSL_CMD' not found"
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +0100626 exit 1
627fi
628
Manuel Pégourié-Gonnard32f8f4d2014-05-29 11:31:20 +0200629# used by watchdog
630MAIN_PID="$$"
631
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200632# be more patient with valgrind
633if [ "$MEMCHECK" -gt 0 ]; then
634 START_DELAY=3
635 DOG_DELAY=30
636else
637 START_DELAY=1
638 DOG_DELAY=10
639fi
Manuel Pégourié-Gonnarda0719722014-09-20 12:46:27 +0200640CLI_DELAY_FACTOR=1
Janos Follath74537a62016-09-02 13:45:28 +0100641SRV_DELAY_SECONDS=0
Manuel Pégourié-Gonnard0c1ec472014-06-20 18:41:11 +0200642
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +0200643# fix commands to use this port, force IPv4 while at it
Manuel Pégourié-Gonnard0af1ba32015-01-21 11:44:33 +0000644# +SRV_PORT will be replaced by either $SRV_PORT or $PXY_PORT later
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200645P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
646P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
Andres AGf04f54d2016-10-10 15:46:20 +0100647P_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 +0200648O_SRV="$O_SRV -accept $SRV_PORT -dhparam data_files/dhparams.pem"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200649O_CLI="$O_CLI -connect localhost:+SRV_PORT"
650G_SRV="$G_SRV -p $SRV_PORT"
Manuel Pégourié-Gonnard0af1ba32015-01-21 11:44:33 +0000651G_CLI="$G_CLI -p +SRV_PORT localhost"
Manuel Pégourié-Gonnard8066b812014-05-28 22:59:30 +0200652
Gilles Peskine62469d92017-05-10 10:13:59 +0200653# Allow SHA-1, because many of our test certificates use it
654P_SRV="$P_SRV allow_sha1=1"
655P_CLI="$P_CLI allow_sha1=1"
656
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200657# Also pick a unique name for intermediate files
658SRV_OUT="srv_out.$$"
659CLI_OUT="cli_out.$$"
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +0200660PXY_OUT="pxy_out.$$"
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +0200661SESSION="session.$$"
662
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +0200663SKIP_NEXT="NO"
664
Manuel Pégourié-Gonnarda9062e92014-02-25 16:21:22 +0100665trap cleanup INT TERM HUP
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +0100666
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200667# Basic test
668
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200669# Checks that:
670# - things work with all ciphersuites active (used with config-full in all.sh)
671# - the expected (highest security) parameters are selected
672# ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200673run_test "Default" \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200674 "$P_SRV debug_level=3" \
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200675 "$P_CLI" \
676 0 \
Manuel Pégourié-Gonnard480905d2014-08-21 19:38:32 +0200677 -s "Protocol is TLSv1.2" \
678 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
679 -s "client hello v3, signature_algorithm ext: 6" \
680 -s "ECDHE curve: secp521r1" \
681 -S "error" \
682 -C "error"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200683
Manuel Pégourié-Gonnard3bb08012015-01-22 13:34:21 +0000684run_test "Default, DTLS" \
685 "$P_SRV dtls=1" \
686 "$P_CLI dtls=1" \
687 0 \
688 -s "Protocol is DTLSv1.2" \
689 -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384"
690
Simon Butcher8e004102016-10-14 00:48:33 +0100691# Test for uniqueness of IVs in AEAD ciphersuites
692run_test "Unique IV in GCM" \
693 "$P_SRV exchanges=20 debug_level=4" \
694 "$P_CLI exchanges=20 debug_level=4 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
695 0 \
696 -u "IV used" \
697 -U "IV used"
698
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100699# Tests for rc4 option
700
Simon Butchera410af52016-05-19 22:12:18 +0100701requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100702run_test "RC4: server disabled, client enabled" \
703 "$P_SRV" \
704 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
705 1 \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100706 -s "SSL - The server has no ciphersuites in common"
707
Simon Butchera410af52016-05-19 22:12:18 +0100708requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100709run_test "RC4: server half, client enabled" \
710 "$P_SRV arc4=1" \
711 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
712 1 \
713 -s "SSL - The server has no ciphersuites in common"
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100714
715run_test "RC4: server enabled, client disabled" \
716 "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
717 "$P_CLI" \
718 1 \
719 -s "SSL - The server has no ciphersuites in common"
720
721run_test "RC4: both enabled" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100722 "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100723 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
724 0 \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100725 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnardbd47a582015-01-12 13:43:29 +0100726 -S "SSL - The server has no ciphersuites in common"
727
Gilles Peskinebc70a182017-05-09 15:59:24 +0200728# Tests for SHA-1 support
729
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200730requires_config_disabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinebc70a182017-05-09 15:59:24 +0200731run_test "SHA-1 forbidden by default in server certificate" \
732 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
733 "$P_CLI debug_level=2 allow_sha1=0" \
734 1 \
735 -c "The certificate is signed with an unacceptable hash"
736
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200737requires_config_enabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
738run_test "SHA-1 forbidden by default in server certificate" \
739 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
740 "$P_CLI debug_level=2 allow_sha1=0" \
741 0
742
Gilles Peskinebc70a182017-05-09 15:59:24 +0200743run_test "SHA-1 explicitly allowed in server certificate" \
744 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
745 "$P_CLI allow_sha1=1" \
746 0
747
748run_test "SHA-256 allowed by default in server certificate" \
749 "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2-sha256.crt" \
750 "$P_CLI allow_sha1=0" \
751 0
752
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200753requires_config_disabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
Gilles Peskinebc70a182017-05-09 15:59:24 +0200754run_test "SHA-1 forbidden by default in client certificate" \
755 "$P_SRV auth_mode=required allow_sha1=0" \
756 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
757 1 \
758 -s "The certificate is signed with an unacceptable hash"
759
Manuel Pégourié-Gonnardaf63c212017-06-08 17:51:08 +0200760requires_config_enabled MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
761run_test "SHA-1 forbidden by default in client certificate" \
762 "$P_SRV auth_mode=required allow_sha1=0" \
763 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
764 0
765
Gilles Peskinebc70a182017-05-09 15:59:24 +0200766run_test "SHA-1 explicitly allowed in client certificate" \
767 "$P_SRV auth_mode=required allow_sha1=1" \
768 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
769 0
770
771run_test "SHA-256 allowed by default in client certificate" \
772 "$P_SRV auth_mode=required allow_sha1=0" \
773 "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha256.crt" \
774 0
775
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100776# Tests for Truncated HMAC extension
777
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100778run_test "Truncated HMAC: client default, server default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200779 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100780 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100781 0 \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100782 -s "dumping 'computed mac' (20 bytes)" \
783 -S "dumping 'computed mac' (10 bytes)"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +0100784
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100785run_test "Truncated HMAC: client disabled, server default" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +0200786 "$P_SRV debug_level=4" \
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100787 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
788 trunc_hmac=0" \
Manuel Pégourié-Gonnardeaadc502014-02-20 11:01:30 +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)"
792
793run_test "Truncated HMAC: client enabled, server default" \
794 "$P_SRV debug_level=4" \
795 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
796 trunc_hmac=1" \
797 0 \
Manuel Pégourié-Gonnard662c6e82015-05-06 17:39:23 +0100798 -s "dumping 'computed mac' (20 bytes)" \
799 -S "dumping 'computed mac' (10 bytes)"
Manuel Pégourié-Gonnarde117a8f2015-01-09 12:39:35 +0100800
801run_test "Truncated HMAC: client enabled, server disabled" \
802 "$P_SRV debug_level=4 trunc_hmac=0" \
803 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
804 trunc_hmac=1" \
805 0 \
806 -s "dumping 'computed mac' (20 bytes)" \
807 -S "dumping 'computed mac' (10 bytes)"
808
809run_test "Truncated HMAC: client enabled, server enabled" \
810 "$P_SRV debug_level=4 trunc_hmac=1" \
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)" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +0100815 -s "dumping 'computed mac' (10 bytes)"
816
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100817# Tests for Encrypt-then-MAC extension
818
819run_test "Encrypt then MAC: default" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100820 "$P_SRV debug_level=3 \
821 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100822 "$P_CLI debug_level=3" \
823 0 \
824 -c "client hello, adding encrypt_then_mac extension" \
825 -s "found encrypt then mac extension" \
826 -s "server hello, adding encrypt then mac extension" \
827 -c "found encrypt_then_mac extension" \
828 -c "using encrypt then mac" \
829 -s "using encrypt then mac"
830
831run_test "Encrypt then MAC: client enabled, server disabled" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100832 "$P_SRV debug_level=3 etm=0 \
833 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100834 "$P_CLI debug_level=3 etm=1" \
835 0 \
836 -c "client hello, adding encrypt_then_mac extension" \
837 -s "found encrypt then mac extension" \
838 -S "server hello, adding encrypt then mac extension" \
839 -C "found encrypt_then_mac extension" \
840 -C "using encrypt then mac" \
841 -S "using encrypt then mac"
842
Manuel Pégourié-Gonnard78e745f2014-11-04 15:44:06 +0100843run_test "Encrypt then MAC: client enabled, aead cipher" \
844 "$P_SRV debug_level=3 etm=1 \
845 force_ciphersuite=TLS-RSA-WITH-AES-128-GCM-SHA256" \
846 "$P_CLI debug_level=3 etm=1" \
847 0 \
848 -c "client hello, adding encrypt_then_mac extension" \
849 -s "found encrypt then mac extension" \
850 -S "server hello, adding encrypt then mac extension" \
851 -C "found encrypt_then_mac extension" \
852 -C "using encrypt then mac" \
853 -S "using encrypt then mac"
854
855run_test "Encrypt then MAC: client enabled, stream cipher" \
856 "$P_SRV debug_level=3 etm=1 \
857 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +0100858 "$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 +0100859 0 \
860 -c "client hello, adding encrypt_then_mac extension" \
861 -s "found encrypt then mac extension" \
862 -S "server hello, adding encrypt then mac extension" \
863 -C "found encrypt_then_mac extension" \
864 -C "using encrypt then mac" \
865 -S "using encrypt then mac"
866
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100867run_test "Encrypt then MAC: client disabled, server enabled" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100868 "$P_SRV debug_level=3 etm=1 \
869 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100870 "$P_CLI debug_level=3 etm=0" \
871 0 \
872 -C "client hello, adding encrypt_then_mac extension" \
873 -S "found encrypt then mac extension" \
874 -S "server hello, adding encrypt then mac extension" \
875 -C "found encrypt_then_mac extension" \
876 -C "using encrypt then mac" \
877 -S "using encrypt then mac"
878
Janos Follathe2681a42016-03-07 15:57:05 +0000879requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100880run_test "Encrypt then MAC: client SSLv3, server enabled" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100881 "$P_SRV debug_level=3 min_version=ssl3 \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100882 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100883 "$P_CLI debug_level=3 force_version=ssl3" \
884 0 \
885 -C "client hello, adding encrypt_then_mac extension" \
886 -S "found encrypt then mac extension" \
887 -S "server hello, adding encrypt then mac extension" \
888 -C "found encrypt_then_mac extension" \
889 -C "using encrypt then mac" \
890 -S "using encrypt then mac"
891
Janos Follathe2681a42016-03-07 15:57:05 +0000892requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100893run_test "Encrypt then MAC: client enabled, server SSLv3" \
Manuel Pégourié-Gonnard0098e7d2014-10-28 13:08:59 +0100894 "$P_SRV debug_level=3 force_version=ssl3 \
895 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100896 "$P_CLI debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100897 0 \
898 -c "client hello, adding encrypt_then_mac extension" \
Janos Follath00efff72016-05-06 13:48:23 +0100899 -S "found encrypt then mac extension" \
Manuel Pégourié-Gonnard699cafa2014-10-27 13:57:03 +0100900 -S "server hello, adding encrypt then mac extension" \
901 -C "found encrypt_then_mac extension" \
902 -C "using encrypt then mac" \
903 -S "using encrypt then mac"
904
Manuel Pégourié-Gonnard367381f2014-10-20 18:40:56 +0200905# Tests for Extended Master Secret extension
906
907run_test "Extended Master Secret: default" \
908 "$P_SRV debug_level=3" \
909 "$P_CLI debug_level=3" \
910 0 \
911 -c "client hello, adding extended_master_secret extension" \
912 -s "found extended master secret extension" \
913 -s "server hello, adding extended master secret extension" \
914 -c "found extended_master_secret extension" \
915 -c "using extended master secret" \
916 -s "using extended master secret"
917
918run_test "Extended Master Secret: client enabled, server disabled" \
919 "$P_SRV debug_level=3 extended_ms=0" \
920 "$P_CLI debug_level=3 extended_ms=1" \
921 0 \
922 -c "client hello, adding extended_master_secret extension" \
923 -s "found extended master secret extension" \
924 -S "server hello, adding extended master secret extension" \
925 -C "found extended_master_secret extension" \
926 -C "using extended master secret" \
927 -S "using extended master secret"
928
929run_test "Extended Master Secret: client disabled, server enabled" \
930 "$P_SRV debug_level=3 extended_ms=1" \
931 "$P_CLI debug_level=3 extended_ms=0" \
932 0 \
933 -C "client hello, adding extended_master_secret extension" \
934 -S "found extended master secret extension" \
935 -S "server hello, adding extended master secret extension" \
936 -C "found extended_master_secret extension" \
937 -C "using extended master secret" \
938 -S "using extended master secret"
939
Janos Follathe2681a42016-03-07 15:57:05 +0000940requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200941run_test "Extended Master Secret: client SSLv3, server enabled" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100942 "$P_SRV debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200943 "$P_CLI debug_level=3 force_version=ssl3" \
944 0 \
945 -C "client hello, adding extended_master_secret extension" \
946 -S "found extended master secret extension" \
947 -S "server hello, adding extended master secret extension" \
948 -C "found extended_master_secret extension" \
949 -C "using extended master secret" \
950 -S "using extended master secret"
951
Janos Follathe2681a42016-03-07 15:57:05 +0000952requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200953run_test "Extended Master Secret: client enabled, server SSLv3" \
954 "$P_SRV debug_level=3 force_version=ssl3" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +0100955 "$P_CLI debug_level=3 min_version=ssl3" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200956 0 \
957 -c "client hello, adding extended_master_secret extension" \
Janos Follath00efff72016-05-06 13:48:23 +0100958 -S "found extended master secret extension" \
Manuel Pégourié-Gonnardb575b542014-10-24 15:12:31 +0200959 -S "server hello, adding extended master secret extension" \
960 -C "found extended_master_secret extension" \
961 -C "using extended master secret" \
962 -S "using extended master secret"
963
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200964# Tests for FALLBACK_SCSV
965
966run_test "Fallback SCSV: default" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +0200967 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200968 "$P_CLI debug_level=3 force_version=tls1_1" \
969 0 \
970 -C "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200971 -S "received FALLBACK_SCSV" \
972 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200973 -C "is a fatal alert message (msg 86)"
974
975run_test "Fallback SCSV: explicitly disabled" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +0200976 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200977 "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
978 0 \
979 -C "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200980 -S "received FALLBACK_SCSV" \
981 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200982 -C "is a fatal alert message (msg 86)"
983
984run_test "Fallback SCSV: enabled" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +0200985 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200986 "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200987 1 \
988 -c "adding FALLBACK_SCSV" \
989 -s "received FALLBACK_SCSV" \
990 -s "inapropriate fallback" \
991 -c "is a fatal alert message (msg 86)"
992
993run_test "Fallback SCSV: enabled, max version" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +0200994 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200995 "$P_CLI debug_level=3 fallback=1" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +0200996 0 \
997 -c "adding FALLBACK_SCSV" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +0200998 -s "received FALLBACK_SCSV" \
999 -S "inapropriate fallback" \
Manuel Pégourié-Gonnard1cbd39d2014-10-20 13:34:59 +02001000 -C "is a fatal alert message (msg 86)"
1001
1002requires_openssl_with_fallback_scsv
1003run_test "Fallback SCSV: default, openssl server" \
1004 "$O_SRV" \
1005 "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
1006 0 \
1007 -C "adding FALLBACK_SCSV" \
1008 -C "is a fatal alert message (msg 86)"
1009
1010requires_openssl_with_fallback_scsv
1011run_test "Fallback SCSV: enabled, openssl server" \
1012 "$O_SRV" \
1013 "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
1014 1 \
1015 -c "adding FALLBACK_SCSV" \
1016 -c "is a fatal alert message (msg 86)"
1017
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001018requires_openssl_with_fallback_scsv
1019run_test "Fallback SCSV: disabled, openssl client" \
Manuel Pégourié-Gonnard4268ae02015-08-04 12:44:10 +02001020 "$P_SRV debug_level=2" \
Manuel Pégourié-Gonnard01b26992014-10-20 14:05:28 +02001021 "$O_CLI -tls1_1" \
1022 0 \
1023 -S "received FALLBACK_SCSV" \
1024 -S "inapropriate fallback"
1025
1026requires_openssl_with_fallback_scsv
1027run_test "Fallback SCSV: enabled, 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 -fallback_scsv" \
1030 1 \
1031 -s "received FALLBACK_SCSV" \
1032 -s "inapropriate fallback"
1033
1034requires_openssl_with_fallback_scsv
1035run_test "Fallback SCSV: enabled, max version, 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 -fallback_scsv" \
1038 0 \
1039 -s "received FALLBACK_SCSV" \
1040 -S "inapropriate fallback"
1041
Gilles Peskined50177f2017-05-16 17:53:03 +02001042## ClientHello generated with
1043## "openssl s_client -CAfile tests/data_files/test-ca.crt -tls1_1 -connect localhost:4433 -cipher ..."
1044## then manually twiddling the ciphersuite list.
1045## The ClientHello content is spelled out below as a hex string as
1046## "prefix ciphersuite1 ciphersuite2 ciphersuite3 ciphersuite4 suffix".
1047## The expected response is an inappropriate_fallback alert.
1048requires_openssl_with_fallback_scsv
1049run_test "Fallback SCSV: beginning of list" \
1050 "$P_SRV debug_level=2" \
1051 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 5600 0031 0032 0033 0100000900230000000f000101' '15030200020256'" \
1052 0 \
1053 -s "received FALLBACK_SCSV" \
1054 -s "inapropriate fallback"
1055
1056requires_openssl_with_fallback_scsv
1057run_test "Fallback SCSV: end of list" \
1058 "$P_SRV debug_level=2" \
1059 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 0031 0032 0033 5600 0100000900230000000f000101' '15030200020256'" \
1060 0 \
1061 -s "received FALLBACK_SCSV" \
1062 -s "inapropriate fallback"
1063
1064## Here the expected response is a valid ServerHello prefix, up to the random.
1065requires_openssl_with_fallback_scsv
1066run_test "Fallback SCSV: not in list" \
1067 "$P_SRV debug_level=2" \
1068 "$TCP_CLIENT localhost $SRV_PORT '160301003e0100003a03022aafb94308dc22ca1086c65acc00e414384d76b61ecab37df1633b1ae1034dbe000008 0056 0031 0032 0033 0100000900230000000f000101' '16030200300200002c0302'" \
1069 0 \
1070 -S "received FALLBACK_SCSV" \
1071 -S "inapropriate fallback"
1072
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001073# Tests for CBC 1/n-1 record splitting
1074
1075run_test "CBC Record splitting: TLS 1.2, no splitting" \
1076 "$P_SRV" \
1077 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1078 request_size=123 force_version=tls1_2" \
1079 0 \
1080 -s "Read from client: 123 bytes read" \
1081 -S "Read from client: 1 bytes read" \
1082 -S "122 bytes read"
1083
1084run_test "CBC Record splitting: TLS 1.1, no splitting" \
1085 "$P_SRV" \
1086 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1087 request_size=123 force_version=tls1_1" \
1088 0 \
1089 -s "Read from client: 123 bytes read" \
1090 -S "Read from client: 1 bytes read" \
1091 -S "122 bytes read"
1092
1093run_test "CBC Record splitting: TLS 1.0, splitting" \
1094 "$P_SRV" \
1095 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1096 request_size=123 force_version=tls1" \
1097 0 \
1098 -S "Read from client: 123 bytes read" \
1099 -s "Read from client: 1 bytes read" \
1100 -s "122 bytes read"
1101
Janos Follathe2681a42016-03-07 15:57:05 +00001102requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001103run_test "CBC Record splitting: SSLv3, splitting" \
Manuel Pégourié-Gonnard51d81662015-01-14 17:20:46 +01001104 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001105 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1106 request_size=123 force_version=ssl3" \
1107 0 \
1108 -S "Read from client: 123 bytes read" \
1109 -s "Read from client: 1 bytes read" \
1110 -s "122 bytes read"
1111
1112run_test "CBC Record splitting: TLS 1.0 RC4, no splitting" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01001113 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard3ff78232015-01-08 11:15:09 +01001114 "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
1115 request_size=123 force_version=tls1" \
1116 0 \
1117 -s "Read from client: 123 bytes read" \
1118 -S "Read from client: 1 bytes read" \
1119 -S "122 bytes read"
1120
1121run_test "CBC Record splitting: TLS 1.0, splitting disabled" \
1122 "$P_SRV" \
1123 "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1124 request_size=123 force_version=tls1 recsplit=0" \
1125 0 \
1126 -s "Read from client: 123 bytes read" \
1127 -S "Read from client: 1 bytes read" \
1128 -S "122 bytes read"
1129
Manuel Pégourié-Gonnarda852cf42015-01-13 20:56:15 +01001130run_test "CBC Record splitting: TLS 1.0, splitting, nbio" \
1131 "$P_SRV nbio=2" \
1132 "$P_CLI nbio=2 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
1133 request_size=123 force_version=tls1" \
1134 0 \
1135 -S "Read from client: 123 bytes read" \
1136 -s "Read from client: 1 bytes read" \
1137 -s "122 bytes read"
1138
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001139# Tests for Session Tickets
1140
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001141run_test "Session resume using tickets: basic" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001142 "$P_SRV debug_level=3 tickets=1" \
1143 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001144 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001145 -c "client hello, adding session ticket extension" \
1146 -s "found session ticket extension" \
1147 -s "server hello, adding session ticket extension" \
1148 -c "found session_ticket extension" \
1149 -c "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001150 -S "session successfully restored from cache" \
1151 -s "session successfully restored from ticket" \
1152 -s "a session has been resumed" \
1153 -c "a session has been resumed"
1154
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001155run_test "Session resume using tickets: cache disabled" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001156 "$P_SRV debug_level=3 tickets=1 cache_max=0" \
1157 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +01001158 0 \
1159 -c "client hello, adding session ticket extension" \
1160 -s "found session ticket extension" \
1161 -s "server hello, adding session ticket extension" \
1162 -c "found session_ticket extension" \
1163 -c "parse new session ticket" \
1164 -S "session successfully restored from cache" \
1165 -s "session successfully restored from ticket" \
1166 -s "a session has been resumed" \
1167 -c "a session has been resumed"
1168
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001169run_test "Session resume using tickets: timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001170 "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
1171 "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnarddbe1ee12014-02-21 09:18:13 +01001172 0 \
1173 -c "client hello, adding session ticket extension" \
1174 -s "found session ticket extension" \
1175 -s "server hello, adding session ticket extension" \
1176 -c "found session_ticket extension" \
1177 -c "parse new session ticket" \
1178 -S "session successfully restored from cache" \
1179 -S "session successfully restored from ticket" \
1180 -S "a session has been resumed" \
1181 -C "a session has been resumed"
1182
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001183run_test "Session resume using tickets: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +01001184 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001185 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +01001186 0 \
1187 -c "client hello, adding session ticket extension" \
1188 -c "found session_ticket extension" \
1189 -c "parse new session ticket" \
1190 -c "a session has been resumed"
1191
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001192run_test "Session resume using tickets: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001193 "$P_SRV debug_level=3 tickets=1" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +02001194 "( $O_CLI -sess_out $SESSION; \
1195 $O_CLI -sess_in $SESSION; \
1196 rm -f $SESSION )" \
Manuel Pégourié-Gonnardfccd3252014-02-25 17:14:15 +01001197 0 \
1198 -s "found session ticket extension" \
1199 -s "server hello, adding session ticket extension" \
1200 -S "session successfully restored from cache" \
1201 -s "session successfully restored from ticket" \
1202 -s "a session has been resumed"
1203
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001204# Tests for Session Resume based on session-ID and cache
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001205
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001206run_test "Session resume using cache: tickets enabled on client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001207 "$P_SRV debug_level=3 tickets=0" \
1208 "$P_CLI debug_level=3 tickets=1 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001209 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001210 -c "client hello, adding session ticket extension" \
1211 -s "found session ticket extension" \
1212 -S "server hello, adding session ticket extension" \
1213 -C "found session_ticket extension" \
1214 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001215 -s "session successfully restored from cache" \
1216 -S "session successfully restored from ticket" \
1217 -s "a session has been resumed" \
1218 -c "a session has been resumed"
1219
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001220run_test "Session resume using cache: tickets enabled on server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001221 "$P_SRV debug_level=3 tickets=1" \
1222 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001223 0 \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001224 -C "client hello, adding session ticket extension" \
1225 -S "found session ticket extension" \
1226 -S "server hello, adding session ticket extension" \
1227 -C "found session_ticket extension" \
1228 -C "parse new session ticket" \
Manuel Pégourié-Gonnardf7c52012014-02-20 11:43:46 +01001229 -s "session successfully restored from cache" \
1230 -S "session successfully restored from ticket" \
1231 -s "a session has been resumed" \
1232 -c "a session has been resumed"
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001233
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001234run_test "Session resume using cache: cache_max=0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001235 "$P_SRV debug_level=3 tickets=0 cache_max=0" \
1236 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001237 0 \
1238 -S "session successfully restored from cache" \
1239 -S "session successfully restored from ticket" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001240 -S "a session has been resumed" \
1241 -C "a session has been resumed"
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001242
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001243run_test "Session resume using cache: cache_max=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001244 "$P_SRV debug_level=3 tickets=0 cache_max=1" \
1245 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001246 0 \
1247 -s "session successfully restored from cache" \
1248 -S "session successfully restored from ticket" \
1249 -s "a session has been resumed" \
1250 -c "a session has been resumed"
1251
Manuel Pégourié-Gonnard6df31962015-05-04 10:55:47 +02001252run_test "Session resume using cache: timeout > delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001253 "$P_SRV debug_level=3 tickets=0" \
1254 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001255 0 \
1256 -s "session successfully restored from cache" \
1257 -S "session successfully restored from ticket" \
1258 -s "a session has been resumed" \
1259 -c "a session has been resumed"
1260
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001261run_test "Session resume using cache: timeout < delay" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001262 "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
1263 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnardc55a5b72014-02-20 22:50:56 +01001264 0 \
1265 -S "session successfully restored from cache" \
1266 -S "session successfully restored from ticket" \
1267 -S "a session has been resumed" \
1268 -C "a session has been resumed"
1269
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001270run_test "Session resume using cache: no timeout" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001271 "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
1272 "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
Manuel Pégourié-Gonnard4c883452014-02-20 21:32:41 +01001273 0 \
1274 -s "session successfully restored from cache" \
1275 -S "session successfully restored from ticket" \
1276 -s "a session has been resumed" \
1277 -c "a session has been resumed"
1278
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001279run_test "Session resume using cache: openssl client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001280 "$P_SRV debug_level=3 tickets=0" \
Manuel Pégourié-Gonnardbc3b16c2014-05-28 23:06:50 +02001281 "( $O_CLI -sess_out $SESSION; \
1282 $O_CLI -sess_in $SESSION; \
1283 rm -f $SESSION )" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +01001284 0 \
1285 -s "found session ticket extension" \
1286 -S "server hello, adding session ticket extension" \
1287 -s "session successfully restored from cache" \
1288 -S "session successfully restored from ticket" \
1289 -s "a session has been resumed"
1290
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001291run_test "Session resume using cache: openssl server" \
Manuel Pégourié-Gonnardf7a26902014-02-27 12:25:54 +01001292 "$O_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001293 "$P_CLI debug_level=3 tickets=0 reconnect=1" \
Manuel Pégourié-Gonnarddb735f62014-02-25 17:57:59 +01001294 0 \
1295 -C "found session_ticket extension" \
1296 -C "parse new session ticket" \
1297 -c "a session has been resumed"
1298
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001299# Tests for Max Fragment Length extension
1300
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001301run_test "Max fragment length: not used, reference" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001302 "$P_SRV debug_level=3" \
1303 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001304 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001305 -c "Maximum fragment length is 16384" \
1306 -s "Maximum fragment length is 16384" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001307 -C "client hello, adding max_fragment_length extension" \
1308 -S "found max fragment length extension" \
1309 -S "server hello, max_fragment_length extension" \
1310 -C "found max_fragment_length extension"
1311
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001312run_test "Max fragment length: used by client" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001313 "$P_SRV debug_level=3" \
1314 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001315 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001316 -c "Maximum fragment length is 4096" \
1317 -s "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001318 -c "client hello, adding max_fragment_length extension" \
1319 -s "found max fragment length extension" \
1320 -s "server hello, max_fragment_length extension" \
1321 -c "found max_fragment_length extension"
1322
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001323run_test "Max fragment length: used by server" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001324 "$P_SRV debug_level=3 max_frag_len=4096" \
1325 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001326 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001327 -c "Maximum fragment length is 16384" \
1328 -s "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardde143782014-02-20 14:50:42 +01001329 -C "client hello, adding max_fragment_length extension" \
1330 -S "found max fragment length extension" \
1331 -S "server hello, max_fragment_length extension" \
1332 -C "found max_fragment_length extension"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001333
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001334requires_gnutls
1335run_test "Max fragment length: gnutls server" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001336 "$G_SRV" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001337 "$P_CLI debug_level=3 max_frag_len=4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001338 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001339 -c "Maximum fragment length is 4096" \
Manuel Pégourié-Gonnardbaa7f072014-08-20 20:15:53 +02001340 -c "client hello, adding max_fragment_length extension" \
1341 -c "found max_fragment_length extension"
1342
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001343run_test "Max fragment length: client, message just fits" \
1344 "$P_SRV debug_level=3" \
1345 "$P_CLI debug_level=3 max_frag_len=2048 request_size=2048" \
1346 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001347 -c "Maximum fragment length is 2048" \
1348 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001349 -c "client hello, adding max_fragment_length extension" \
1350 -s "found max fragment length extension" \
1351 -s "server hello, max_fragment_length extension" \
1352 -c "found max_fragment_length extension" \
1353 -c "2048 bytes written in 1 fragments" \
1354 -s "2048 bytes read"
1355
1356run_test "Max fragment length: client, larger message" \
1357 "$P_SRV debug_level=3" \
1358 "$P_CLI debug_level=3 max_frag_len=2048 request_size=2345" \
1359 0 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001360 -c "Maximum fragment length is 2048" \
1361 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001362 -c "client hello, adding max_fragment_length extension" \
1363 -s "found max fragment length extension" \
1364 -s "server hello, max_fragment_length extension" \
1365 -c "found max_fragment_length extension" \
1366 -c "2345 bytes written in 2 fragments" \
1367 -s "2048 bytes read" \
1368 -s "297 bytes read"
1369
Manuel Pégourié-Gonnard23eb74d2015-01-21 14:37:13 +00001370run_test "Max fragment length: DTLS client, larger message" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001371 "$P_SRV debug_level=3 dtls=1" \
1372 "$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
1373 1 \
Manuel Pégourié-Gonnarda2cda6b2015-08-31 18:30:52 +02001374 -c "Maximum fragment length is 2048" \
1375 -s "Maximum fragment length is 2048" \
Manuel Pégourié-Gonnard37e08e12014-10-13 17:55:52 +02001376 -c "client hello, adding max_fragment_length extension" \
1377 -s "found max fragment length extension" \
1378 -s "server hello, max_fragment_length extension" \
1379 -c "found max_fragment_length extension" \
1380 -c "fragment larger than.*maximum"
1381
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001382# Tests for renegotiation
1383
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001384run_test "Renegotiation: none, for reference" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001385 "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001386 "$P_CLI debug_level=3 exchanges=2" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001387 0 \
1388 -C "client hello, adding renegotiation extension" \
1389 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1390 -S "found renegotiation extension" \
1391 -s "server hello, secure renegotiation extension" \
1392 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001393 -C "=> renegotiate" \
1394 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001395 -S "write hello request"
1396
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001397run_test "Renegotiation: client-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001398 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001399 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001400 0 \
1401 -c "client hello, adding renegotiation extension" \
1402 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1403 -s "found renegotiation extension" \
1404 -s "server hello, secure renegotiation extension" \
1405 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001406 -c "=> renegotiate" \
1407 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001408 -S "write hello request"
1409
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001410run_test "Renegotiation: server-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001411 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001412 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001413 0 \
1414 -c "client hello, adding renegotiation extension" \
1415 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1416 -s "found renegotiation extension" \
1417 -s "server hello, secure renegotiation extension" \
1418 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001419 -c "=> renegotiate" \
1420 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001421 -s "write hello request"
1422
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001423run_test "Renegotiation: double" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001424 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001425 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001426 0 \
1427 -c "client hello, adding renegotiation extension" \
1428 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1429 -s "found renegotiation extension" \
1430 -s "server hello, secure renegotiation extension" \
1431 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001432 -c "=> renegotiate" \
1433 -s "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001434 -s "write hello request"
1435
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001436run_test "Renegotiation: client-initiated, server-rejected" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001437 "$P_SRV debug_level=3 exchanges=2 renegotiation=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001438 "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001439 1 \
1440 -c "client hello, adding renegotiation extension" \
1441 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1442 -S "found renegotiation extension" \
1443 -s "server hello, secure renegotiation extension" \
1444 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001445 -c "=> renegotiate" \
1446 -S "=> renegotiate" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001447 -S "write hello request" \
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +02001448 -c "SSL - Unexpected message at ServerHello in renegotiation" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001449 -c "failed"
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001450
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001451run_test "Renegotiation: server-initiated, client-rejected, default" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001452 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001453 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001454 0 \
1455 -C "client hello, adding renegotiation extension" \
1456 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1457 -S "found renegotiation extension" \
1458 -s "server hello, secure renegotiation extension" \
1459 -c "found renegotiation extension" \
Manuel Pégourié-Gonnardc73339f2014-02-26 16:35:27 +01001460 -C "=> renegotiate" \
1461 -S "=> renegotiate" \
Manuel Pégourié-Gonnard780d6712014-02-20 17:19:59 +01001462 -s "write hello request" \
Manuel Pégourié-Gonnarda9964db2014-07-03 19:29:16 +02001463 -S "SSL - An unexpected message was received from our peer" \
1464 -S "failed"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01001465
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001466run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001467 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001468 renego_delay=-1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001469 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001470 0 \
1471 -C "client hello, adding renegotiation extension" \
1472 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1473 -S "found renegotiation extension" \
1474 -s "server hello, secure renegotiation extension" \
1475 -c "found renegotiation extension" \
1476 -C "=> renegotiate" \
1477 -S "=> renegotiate" \
1478 -s "write hello request" \
1479 -S "SSL - An unexpected message was received from our peer" \
1480 -S "failed"
1481
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +02001482# delay 2 for 1 alert record + 1 application data record
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001483run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001484 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001485 renego_delay=2 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001486 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001487 0 \
1488 -C "client hello, adding renegotiation extension" \
1489 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1490 -S "found renegotiation extension" \
1491 -s "server hello, secure renegotiation extension" \
1492 -c "found renegotiation extension" \
1493 -C "=> renegotiate" \
1494 -S "=> renegotiate" \
1495 -s "write hello request" \
1496 -S "SSL - An unexpected message was received from our peer" \
1497 -S "failed"
1498
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001499run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001500 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001501 renego_delay=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001502 "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001503 0 \
1504 -C "client hello, adding renegotiation extension" \
1505 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1506 -S "found renegotiation extension" \
1507 -s "server hello, secure renegotiation extension" \
1508 -c "found renegotiation extension" \
1509 -C "=> renegotiate" \
1510 -S "=> renegotiate" \
1511 -s "write hello request" \
Manuel Pégourié-Gonnarda8c0a0d2014-08-15 12:07:38 +02001512 -s "SSL - An unexpected message was received from our peer"
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001513
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001514run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001515 "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001516 renego_delay=0 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001517 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardfae355e2014-07-04 14:32:27 +02001518 0 \
1519 -c "client hello, adding renegotiation extension" \
1520 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1521 -s "found renegotiation extension" \
1522 -s "server hello, secure renegotiation extension" \
1523 -c "found renegotiation extension" \
1524 -c "=> renegotiate" \
1525 -s "=> renegotiate" \
1526 -s "write hello request" \
1527 -S "SSL - An unexpected message was received from our peer" \
1528 -S "failed"
1529
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001530run_test "Renegotiation: periodic, just below period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001531 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001532 "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
1533 0 \
1534 -C "client hello, adding renegotiation extension" \
1535 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1536 -S "found renegotiation extension" \
1537 -s "server hello, secure renegotiation extension" \
1538 -c "found renegotiation extension" \
1539 -S "record counter limit reached: renegotiate" \
1540 -C "=> renegotiate" \
1541 -S "=> renegotiate" \
1542 -S "write hello request" \
1543 -S "SSL - An unexpected message was received from our peer" \
1544 -S "failed"
1545
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001546# one extra exchange to be able to complete renego
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001547run_test "Renegotiation: periodic, just above period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001548 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001549 "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001550 0 \
1551 -c "client hello, adding renegotiation extension" \
1552 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1553 -s "found renegotiation extension" \
1554 -s "server hello, secure renegotiation extension" \
1555 -c "found renegotiation extension" \
1556 -s "record counter limit reached: renegotiate" \
1557 -c "=> renegotiate" \
1558 -s "=> renegotiate" \
1559 -s "write hello request" \
1560 -S "SSL - An unexpected message was received from our peer" \
1561 -S "failed"
1562
1563run_test "Renegotiation: periodic, two times period" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001564 "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard9835bc02015-01-14 14:41:58 +01001565 "$P_CLI debug_level=3 exchanges=7 renegotiation=1" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001566 0 \
1567 -c "client hello, adding renegotiation extension" \
1568 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1569 -s "found renegotiation extension" \
1570 -s "server hello, secure renegotiation extension" \
1571 -c "found renegotiation extension" \
1572 -s "record counter limit reached: renegotiate" \
1573 -c "=> renegotiate" \
1574 -s "=> renegotiate" \
1575 -s "write hello request" \
1576 -S "SSL - An unexpected message was received from our peer" \
1577 -S "failed"
1578
1579run_test "Renegotiation: periodic, above period, disabled" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001580 "$P_SRV debug_level=3 exchanges=9 renegotiation=0 renego_period=3 auth_mode=optional" \
Manuel Pégourié-Gonnard590f4162014-11-05 14:23:03 +01001581 "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
1582 0 \
1583 -C "client hello, adding renegotiation extension" \
1584 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1585 -S "found renegotiation extension" \
1586 -s "server hello, secure renegotiation extension" \
1587 -c "found renegotiation extension" \
1588 -S "record counter limit reached: renegotiate" \
1589 -C "=> renegotiate" \
1590 -S "=> renegotiate" \
1591 -S "write hello request" \
1592 -S "SSL - An unexpected message was received from our peer" \
1593 -S "failed"
1594
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001595run_test "Renegotiation: nbio, client-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001596 "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 auth_mode=optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001597 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +02001598 0 \
1599 -c "client hello, adding renegotiation extension" \
1600 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1601 -s "found renegotiation extension" \
1602 -s "server hello, secure renegotiation extension" \
1603 -c "found renegotiation extension" \
1604 -c "=> renegotiate" \
1605 -s "=> renegotiate" \
1606 -S "write hello request"
1607
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001608run_test "Renegotiation: nbio, server-initiated" \
Manuel Pégourié-Gonnardfa44f202015-03-27 17:52:25 +01001609 "$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 +02001610 "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
Manuel Pégourié-Gonnardf07f4212014-08-15 19:04:47 +02001611 0 \
1612 -c "client hello, adding renegotiation extension" \
1613 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1614 -s "found renegotiation extension" \
1615 -s "server hello, secure renegotiation extension" \
1616 -c "found renegotiation extension" \
1617 -c "=> renegotiate" \
1618 -s "=> renegotiate" \
1619 -s "write hello request"
1620
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001621run_test "Renegotiation: openssl server, client-initiated" \
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02001622 "$O_SRV -www" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001623 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001624 0 \
1625 -c "client hello, adding renegotiation extension" \
1626 -c "found renegotiation extension" \
1627 -c "=> renegotiate" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001628 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001629 -C "error" \
1630 -c "HTTP/1.0 200 [Oo][Kk]"
1631
Paul Bakker539d9722015-02-08 16:18:35 +01001632requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001633run_test "Renegotiation: gnutls server strict, client-initiated" \
1634 "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001635 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001636 0 \
1637 -c "client hello, adding renegotiation extension" \
1638 -c "found renegotiation extension" \
1639 -c "=> renegotiate" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001640 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard51362962014-08-30 21:22:47 +02001641 -C "error" \
1642 -c "HTTP/1.0 200 [Oo][Kk]"
1643
Paul Bakker539d9722015-02-08 16:18:35 +01001644requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001645run_test "Renegotiation: gnutls server unsafe, client-initiated default" \
1646 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1647 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
1648 1 \
1649 -c "client hello, adding renegotiation extension" \
1650 -C "found renegotiation extension" \
1651 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001652 -c "mbedtls_ssl_handshake() returned" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001653 -c "error" \
1654 -C "HTTP/1.0 200 [Oo][Kk]"
1655
Paul Bakker539d9722015-02-08 16:18:35 +01001656requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001657run_test "Renegotiation: gnutls server unsafe, client-inititated no legacy" \
1658 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1659 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
1660 allow_legacy=0" \
1661 1 \
1662 -c "client hello, adding renegotiation extension" \
1663 -C "found renegotiation extension" \
1664 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001665 -c "mbedtls_ssl_handshake() returned" \
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001666 -c "error" \
1667 -C "HTTP/1.0 200 [Oo][Kk]"
1668
Paul Bakker539d9722015-02-08 16:18:35 +01001669requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001670run_test "Renegotiation: gnutls server unsafe, client-inititated legacy" \
1671 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1672 "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
1673 allow_legacy=1" \
1674 0 \
1675 -c "client hello, adding renegotiation extension" \
1676 -C "found renegotiation extension" \
1677 -c "=> renegotiate" \
1678 -C "ssl_hanshake() returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001679 -C "error" \
1680 -c "HTTP/1.0 200 [Oo][Kk]"
1681
Manuel Pégourié-Gonnard30d16eb2014-08-19 17:43:50 +02001682run_test "Renegotiation: DTLS, client-initiated" \
1683 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
1684 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
1685 0 \
1686 -c "client hello, adding renegotiation extension" \
1687 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1688 -s "found renegotiation extension" \
1689 -s "server hello, secure renegotiation extension" \
1690 -c "found renegotiation extension" \
1691 -c "=> renegotiate" \
1692 -s "=> renegotiate" \
1693 -S "write hello request"
1694
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +02001695run_test "Renegotiation: DTLS, server-initiated" \
1696 "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
Manuel Pégourié-Gonnarddf9a0a82014-10-02 14:17:18 +02001697 "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
1698 read_timeout=1000 max_resend=2" \
Manuel Pégourié-Gonnardc392b242014-08-19 17:53:11 +02001699 0 \
1700 -c "client hello, adding renegotiation extension" \
1701 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1702 -s "found renegotiation extension" \
1703 -s "server hello, secure renegotiation extension" \
1704 -c "found renegotiation extension" \
1705 -c "=> renegotiate" \
1706 -s "=> renegotiate" \
1707 -s "write hello request"
1708
Andres AG692ad842017-01-19 16:30:57 +00001709run_test "Renegotiation: DTLS, renego_period overflow" \
1710 "$P_SRV debug_level=3 dtls=1 exchanges=4 renegotiation=1 renego_period=18446462598732840962 auth_mode=optional" \
1711 "$P_CLI debug_level=3 dtls=1 exchanges=4 renegotiation=1" \
1712 0 \
1713 -c "client hello, adding renegotiation extension" \
1714 -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
1715 -s "found renegotiation extension" \
1716 -s "server hello, secure renegotiation extension" \
1717 -s "record counter limit reached: renegotiate" \
1718 -c "=> renegotiate" \
1719 -s "=> renegotiate" \
1720 -s "write hello request" \
1721
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00001722requires_gnutls
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +02001723run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
1724 "$G_SRV -u --mtu 4096" \
1725 "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
1726 0 \
1727 -c "client hello, adding renegotiation extension" \
1728 -c "found renegotiation extension" \
1729 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001730 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardf1499f62014-08-31 17:13:13 +02001731 -C "error" \
1732 -s "Extra-header:"
1733
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001734# Test for the "secure renegotation" extension only (no actual renegotiation)
1735
Paul Bakker539d9722015-02-08 16:18:35 +01001736requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001737run_test "Renego ext: gnutls server strict, client default" \
1738 "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
1739 "$P_CLI debug_level=3" \
1740 0 \
1741 -c "found renegotiation extension" \
1742 -C "error" \
1743 -c "HTTP/1.0 200 [Oo][Kk]"
1744
Paul Bakker539d9722015-02-08 16:18:35 +01001745requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001746run_test "Renego ext: gnutls server unsafe, client default" \
1747 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1748 "$P_CLI debug_level=3" \
1749 0 \
1750 -C "found renegotiation extension" \
1751 -C "error" \
1752 -c "HTTP/1.0 200 [Oo][Kk]"
1753
Paul Bakker539d9722015-02-08 16:18:35 +01001754requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001755run_test "Renego ext: gnutls server unsafe, client break legacy" \
1756 "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1757 "$P_CLI debug_level=3 allow_legacy=-1" \
1758 1 \
1759 -C "found renegotiation extension" \
1760 -c "error" \
1761 -C "HTTP/1.0 200 [Oo][Kk]"
1762
Paul Bakker539d9722015-02-08 16:18:35 +01001763requires_gnutls
Manuel Pégourié-Gonnard85d915b2014-11-03 20:10:36 +01001764run_test "Renego ext: gnutls client strict, server default" \
1765 "$P_SRV debug_level=3" \
1766 "$G_CLI --priority=NORMAL:%SAFE_RENEGOTIATION" \
1767 0 \
1768 -s "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
1769 -s "server hello, secure renegotiation extension"
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 unsafe, server default" \
1773 "$P_SRV debug_level=3" \
1774 "$G_CLI --priority=NORMAL:%DISABLE_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 break legacy" \
1781 "$P_SRV debug_level=3 allow_legacy=-1" \
1782 "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
1783 1 \
1784 -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
1785 -S "server hello, secure renegotiation extension"
1786
Janos Follath0b242342016-02-17 10:11:21 +00001787# Tests for silently dropping trailing extra bytes in .der certificates
1788
1789requires_gnutls
1790run_test "DER format: no trailing bytes" \
1791 "$P_SRV crt_file=data_files/server5-der0.crt \
1792 key_file=data_files/server5.key" \
1793 "$G_CLI " \
1794 0 \
1795 -c "Handshake was completed" \
1796
1797requires_gnutls
1798run_test "DER format: with a trailing zero byte" \
1799 "$P_SRV crt_file=data_files/server5-der1a.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 random byte" \
1807 "$P_SRV crt_file=data_files/server5-der1b.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 2 trailing random bytes" \
1815 "$P_SRV crt_file=data_files/server5-der2.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 4 trailing random bytes" \
1823 "$P_SRV crt_file=data_files/server5-der4.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 8 trailing random bytes" \
1831 "$P_SRV crt_file=data_files/server5-der8.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 9 trailing random bytes" \
1839 "$P_SRV crt_file=data_files/server5-der9.crt \
1840 key_file=data_files/server5.key" \
1841 "$G_CLI " \
1842 0 \
1843 -c "Handshake was completed" \
1844
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001845# Tests for auth_mode
1846
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001847run_test "Authentication: server badcert, client required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001848 "$P_SRV crt_file=data_files/server5-badsign.crt \
1849 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001850 "$P_CLI debug_level=1 auth_mode=required" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001851 1 \
1852 -c "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01001853 -c "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001854 -c "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001855 -c "X509 - Certificate verification failed"
1856
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001857run_test "Authentication: server badcert, client optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001858 "$P_SRV crt_file=data_files/server5-badsign.crt \
1859 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001860 "$P_CLI debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001861 0 \
1862 -c "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01001863 -c "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001864 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001865 -C "X509 - Certificate verification failed"
1866
Hanno Beckere6706e62017-05-15 16:05:15 +01001867run_test "Authentication: server goodcert, client optional, no trusted CA" \
1868 "$P_SRV" \
1869 "$P_CLI debug_level=3 auth_mode=optional ca_file=none ca_path=none" \
1870 0 \
1871 -c "x509_verify_cert() returned" \
1872 -c "! The certificate is not correctly signed by the trusted CA" \
1873 -c "! Certificate verification flags"\
1874 -C "! mbedtls_ssl_handshake returned" \
1875 -C "X509 - Certificate verification failed" \
1876 -C "SSL - No CA Chain is set, but required to operate"
1877
1878run_test "Authentication: server goodcert, client required, no trusted CA" \
1879 "$P_SRV" \
1880 "$P_CLI debug_level=3 auth_mode=required ca_file=none ca_path=none" \
1881 1 \
1882 -c "x509_verify_cert() returned" \
1883 -c "! The certificate is not correctly signed by the trusted CA" \
1884 -c "! Certificate verification flags"\
1885 -c "! mbedtls_ssl_handshake returned" \
1886 -c "SSL - No CA Chain is set, but required to operate"
1887
1888# The purpose of the next two tests is to test the client's behaviour when receiving a server
1889# certificate with an unsupported elliptic curve. This should usually not happen because
1890# the client informs the server about the supported curves - it does, though, in the
1891# corner case of a static ECDH suite, because the server doesn't check the curve on that
1892# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
1893# different means to have the server ignoring the client's supported curve list.
1894
1895requires_config_enabled MBEDTLS_ECP_C
1896run_test "Authentication: server ECDH p256v1, client required, p256v1 unsupported" \
1897 "$P_SRV debug_level=1 key_file=data_files/server5.key \
1898 crt_file=data_files/server5.ku-ka.crt" \
1899 "$P_CLI debug_level=3 auth_mode=required curves=secp521r1" \
1900 1 \
1901 -c "bad certificate (EC key curve)"\
1902 -c "! Certificate verification flags"\
1903 -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
1904
1905requires_config_enabled MBEDTLS_ECP_C
1906run_test "Authentication: server ECDH p256v1, client optional, p256v1 unsupported" \
1907 "$P_SRV debug_level=1 key_file=data_files/server5.key \
1908 crt_file=data_files/server5.ku-ka.crt" \
1909 "$P_CLI debug_level=3 auth_mode=optional curves=secp521r1" \
1910 1 \
1911 -c "bad certificate (EC key curve)"\
1912 -c "! Certificate verification flags"\
1913 -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
1914
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001915run_test "Authentication: server badcert, client none" \
Manuel Pégourié-Gonnardc1da6642014-02-25 14:18:30 +01001916 "$P_SRV crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001917 key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001918 "$P_CLI debug_level=1 auth_mode=none" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001919 0 \
1920 -C "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01001921 -C "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001922 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001923 -C "X509 - Certificate verification failed"
1924
Simon Butcher99000142016-10-13 17:21:01 +01001925run_test "Authentication: client SHA256, server required" \
1926 "$P_SRV auth_mode=required" \
1927 "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
1928 key_file=data_files/server6.key \
1929 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
1930 0 \
1931 -c "Supported Signature Algorithm found: 4," \
1932 -c "Supported Signature Algorithm found: 5,"
1933
1934run_test "Authentication: client SHA384, server required" \
1935 "$P_SRV auth_mode=required" \
1936 "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
1937 key_file=data_files/server6.key \
1938 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
1939 0 \
1940 -c "Supported Signature Algorithm found: 4," \
1941 -c "Supported Signature Algorithm found: 5,"
1942
Gilles Peskinefd8332e2017-05-03 16:25:07 +02001943requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
1944run_test "Authentication: client has no cert, server required (SSLv3)" \
1945 "$P_SRV debug_level=3 min_version=ssl3 auth_mode=required" \
1946 "$P_CLI debug_level=3 force_version=ssl3 crt_file=none \
1947 key_file=data_files/server5.key" \
1948 1 \
1949 -S "skip write certificate request" \
1950 -C "skip parse certificate request" \
1951 -c "got a certificate request" \
1952 -c "got no certificate to send" \
1953 -S "x509_verify_cert() returned" \
1954 -s "client has no certificate" \
1955 -s "! mbedtls_ssl_handshake returned" \
1956 -c "! mbedtls_ssl_handshake returned" \
1957 -s "No client certification received from the client, but required by the authentication mode"
1958
1959run_test "Authentication: client has no cert, server required (TLS)" \
1960 "$P_SRV debug_level=3 auth_mode=required" \
1961 "$P_CLI debug_level=3 crt_file=none \
1962 key_file=data_files/server5.key" \
1963 1 \
1964 -S "skip write certificate request" \
1965 -C "skip parse certificate request" \
1966 -c "got a certificate request" \
1967 -c "= write certificate$" \
1968 -C "skip write certificate$" \
1969 -S "x509_verify_cert() returned" \
1970 -s "client has no certificate" \
1971 -s "! mbedtls_ssl_handshake returned" \
1972 -c "! mbedtls_ssl_handshake returned" \
1973 -s "No client certification received from the client, but required by the authentication mode"
1974
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02001975run_test "Authentication: client badcert, server required" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02001976 "$P_SRV debug_level=3 auth_mode=required" \
1977 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001978 key_file=data_files/server5.key" \
1979 1 \
1980 -S "skip write certificate request" \
1981 -C "skip parse certificate request" \
1982 -c "got a certificate request" \
1983 -C "skip write certificate" \
1984 -C "skip write certificate verify" \
1985 -S "skip parse certificate verify" \
1986 -s "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02001987 -s "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001988 -s "! mbedtls_ssl_handshake returned" \
Gilles Peskine1cc8e342017-05-03 16:28:34 +02001989 -s "send alert level=2 message=48" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001990 -c "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001991 -s "X509 - Certificate verification failed"
Gilles Peskine1cc8e342017-05-03 16:28:34 +02001992# We don't check that the client receives the alert because it might
1993# detect that its write end of the connection is closed and abort
1994# before reading the alert message.
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01001995
Janos Follath89baba22017-04-10 14:34:35 +01001996run_test "Authentication: client cert not trusted, server required" \
1997 "$P_SRV debug_level=3 auth_mode=required" \
1998 "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
1999 key_file=data_files/server5.key" \
2000 1 \
2001 -S "skip write certificate request" \
2002 -C "skip parse certificate request" \
2003 -c "got a certificate request" \
2004 -C "skip write certificate" \
2005 -C "skip write certificate verify" \
2006 -S "skip parse certificate verify" \
2007 -s "x509_verify_cert() returned" \
2008 -s "! The certificate is not correctly signed by the trusted CA" \
2009 -s "! mbedtls_ssl_handshake returned" \
2010 -c "! mbedtls_ssl_handshake returned" \
2011 -s "X509 - Certificate verification failed"
2012
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002013run_test "Authentication: client badcert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002014 "$P_SRV debug_level=3 auth_mode=optional" \
2015 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002016 key_file=data_files/server5.key" \
2017 0 \
2018 -S "skip write certificate request" \
2019 -C "skip parse certificate request" \
2020 -c "got a certificate request" \
2021 -C "skip write certificate" \
2022 -C "skip write certificate verify" \
2023 -S "skip parse certificate verify" \
2024 -s "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002025 -s "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002026 -S "! mbedtls_ssl_handshake returned" \
2027 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002028 -S "X509 - Certificate verification failed"
2029
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002030run_test "Authentication: client badcert, server none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002031 "$P_SRV debug_level=3 auth_mode=none" \
2032 "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002033 key_file=data_files/server5.key" \
2034 0 \
2035 -s "skip write certificate request" \
2036 -C "skip parse certificate request" \
2037 -c "got no certificate request" \
2038 -c "skip write certificate" \
2039 -c "skip write certificate verify" \
2040 -s "skip parse certificate verify" \
2041 -S "x509_verify_cert() returned" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002042 -S "! The certificate is not correctly signed by the trusted CA" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002043 -S "! mbedtls_ssl_handshake returned" \
2044 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01002045 -S "X509 - Certificate verification failed"
2046
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002047run_test "Authentication: client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002048 "$P_SRV debug_level=3 auth_mode=optional" \
2049 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002050 0 \
2051 -S "skip write certificate request" \
2052 -C "skip parse certificate request" \
2053 -c "got a certificate request" \
2054 -C "skip write certificate$" \
2055 -C "got no certificate to send" \
2056 -S "SSLv3 client has no certificate" \
2057 -c "skip write certificate verify" \
2058 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002059 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002060 -S "! mbedtls_ssl_handshake returned" \
2061 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002062 -S "X509 - Certificate verification failed"
2063
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002064run_test "Authentication: openssl client no cert, server optional" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002065 "$P_SRV debug_level=3 auth_mode=optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002066 "$O_CLI" \
2067 0 \
2068 -S "skip write certificate request" \
2069 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002070 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002071 -S "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002072 -S "X509 - Certificate verification failed"
2073
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002074run_test "Authentication: client no cert, openssl server optional" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002075 "$O_SRV -verify 10" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002076 "$P_CLI debug_level=3 crt_file=none key_file=none" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002077 0 \
2078 -C "skip parse certificate request" \
2079 -c "got a certificate request" \
2080 -C "skip write certificate$" \
2081 -c "skip write certificate verify" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002082 -C "! mbedtls_ssl_handshake returned"
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002083
Gilles Peskinefd8332e2017-05-03 16:25:07 +02002084run_test "Authentication: client no cert, openssl server required" \
2085 "$O_SRV -Verify 10" \
2086 "$P_CLI debug_level=3 crt_file=none key_file=none" \
2087 1 \
2088 -C "skip parse certificate request" \
2089 -c "got a certificate request" \
2090 -C "skip write certificate$" \
2091 -c "skip write certificate verify" \
2092 -c "! mbedtls_ssl_handshake returned"
2093
Janos Follathe2681a42016-03-07 15:57:05 +00002094requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002095run_test "Authentication: client no cert, ssl3" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002096 "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01002097 "$P_CLI debug_level=3 crt_file=none key_file=none min_version=ssl3" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002098 0 \
2099 -S "skip write certificate request" \
2100 -C "skip parse certificate request" \
2101 -c "got a certificate request" \
2102 -C "skip write certificate$" \
2103 -c "skip write certificate verify" \
2104 -c "got no certificate to send" \
2105 -s "SSLv3 client has no certificate" \
2106 -s "skip parse certificate verify" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01002107 -s "! Certificate was missing" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002108 -S "! mbedtls_ssl_handshake returned" \
2109 -C "! mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnardde515cc2014-02-27 14:58:26 +01002110 -S "X509 - Certificate verification failed"
2111
Manuel Pégourié-Gonnard9107b5f2017-07-06 12:16:25 +02002112# The "max_int chain" tests assume that MAX_INTERMEDIATE_CA is set to its
2113# default value (8)
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002114
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002115MAX_IM_CA='8'
Simon Butcher06b78632017-07-28 01:00:17 +01002116MAX_IM_CA_CONFIG=$( ../scripts/config.pl get MBEDTLS_X509_MAX_INTERMEDIATE_CA)
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002117
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002118if [ -n "$MAX_IM_CA_CONFIG" ] && [ "$MAX_IM_CA_CONFIG" -ne "$MAX_IM_CA" ]; then
Simon Butcher06b78632017-07-28 01:00:17 +01002119 printf "The ${CONFIG_H} file contains a value for the configuration of\n"
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002120 printf "MBEDTLS_X509_MAX_INTERMEDIATE_CA that is different from the script’s\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002121 printf "test value of ${MAX_IM_CA}. \n"
2122 printf "\n"
Simon Butcherbcfa6f42017-07-28 15:59:35 +01002123 printf "The tests assume this value and if it changes, the tests in this\n"
2124 printf "script should also be adjusted.\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002125 printf "\n"
Simon Butcher06b78632017-07-28 01:00:17 +01002126
2127 exit 1
Hanno Beckera6bca9f2017-07-26 13:35:11 +01002128fi
2129
Manuel Pégourié-Gonnard81bb6b62017-06-26 10:45:33 +02002130run_test "Authentication: server max_int chain, client default" \
2131 "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
2132 key_file=data_files/dir-maxpath/09.key" \
2133 "$P_CLI server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
2134 0 \
2135 -C "X509 - A fatal error occured"
2136
2137run_test "Authentication: server max_int+1 chain, client default" \
2138 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2139 key_file=data_files/dir-maxpath/10.key" \
2140 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
2141 1 \
2142 -c "X509 - A fatal error occured"
2143
2144run_test "Authentication: server max_int+1 chain, client optional" \
2145 "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
2146 key_file=data_files/dir-maxpath/10.key" \
2147 "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
2148 auth_mode=optional" \
2149 1 \
2150 -c "X509 - A fatal error occured"
2151
2152run_test "Authentication: server max_int+1 chain, client none" \
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=none" \
2157 0 \
2158 -C "X509 - A fatal error occured"
2159
2160run_test "Authentication: client max_int+1 chain, server default" \
2161 "$P_SRV ca_file=data_files/dir-maxpath/00.crt" \
2162 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2163 key_file=data_files/dir-maxpath/10.key" \
2164 0 \
2165 -S "X509 - A fatal error occured"
2166
2167run_test "Authentication: client max_int+1 chain, server optional" \
2168 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
2169 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2170 key_file=data_files/dir-maxpath/10.key" \
2171 1 \
2172 -s "X509 - A fatal error occured"
2173
2174run_test "Authentication: client max_int+1 chain, server required" \
2175 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
2176 "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
2177 key_file=data_files/dir-maxpath/10.key" \
2178 1 \
2179 -s "X509 - A fatal error occured"
2180
2181run_test "Authentication: client max_int chain, server required" \
2182 "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
2183 "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
2184 key_file=data_files/dir-maxpath/09.key" \
2185 0 \
2186 -S "X509 - A fatal error occured"
2187
Janos Follath89baba22017-04-10 14:34:35 +01002188# Tests for CA list in CertificateRequest messages
2189
2190run_test "Authentication: send CA list in CertificateRequest (default)" \
2191 "$P_SRV debug_level=3 auth_mode=required" \
2192 "$P_CLI crt_file=data_files/server6.crt \
2193 key_file=data_files/server6.key" \
2194 0 \
2195 -s "requested DN"
2196
2197run_test "Authentication: do not send CA list in CertificateRequest" \
2198 "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
2199 "$P_CLI crt_file=data_files/server6.crt \
2200 key_file=data_files/server6.key" \
2201 0 \
2202 -S "requested DN"
2203
2204run_test "Authentication: send CA list in CertificateRequest, client self signed" \
2205 "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
2206 "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
2207 key_file=data_files/server5.key" \
2208 1 \
2209 -S "requested DN" \
2210 -s "x509_verify_cert() returned" \
2211 -s "! The certificate is not correctly signed by the trusted CA" \
2212 -s "! mbedtls_ssl_handshake returned" \
2213 -c "! mbedtls_ssl_handshake returned" \
2214 -s "X509 - Certificate verification failed"
2215
Manuel Pégourié-Gonnarddf331a52015-01-08 16:43:07 +01002216# Tests for certificate selection based on SHA verson
2217
2218run_test "Certificate hash: client TLS 1.2 -> SHA-2" \
2219 "$P_SRV crt_file=data_files/server5.crt \
2220 key_file=data_files/server5.key \
2221 crt_file2=data_files/server5-sha1.crt \
2222 key_file2=data_files/server5.key" \
2223 "$P_CLI force_version=tls1_2" \
2224 0 \
2225 -c "signed using.*ECDSA with SHA256" \
2226 -C "signed using.*ECDSA with SHA1"
2227
2228run_test "Certificate hash: client TLS 1.1 -> SHA-1" \
2229 "$P_SRV crt_file=data_files/server5.crt \
2230 key_file=data_files/server5.key \
2231 crt_file2=data_files/server5-sha1.crt \
2232 key_file2=data_files/server5.key" \
2233 "$P_CLI force_version=tls1_1" \
2234 0 \
2235 -C "signed using.*ECDSA with SHA256" \
2236 -c "signed using.*ECDSA with SHA1"
2237
2238run_test "Certificate hash: client TLS 1.0 -> SHA-1" \
2239 "$P_SRV crt_file=data_files/server5.crt \
2240 key_file=data_files/server5.key \
2241 crt_file2=data_files/server5-sha1.crt \
2242 key_file2=data_files/server5.key" \
2243 "$P_CLI force_version=tls1" \
2244 0 \
2245 -C "signed using.*ECDSA with SHA256" \
2246 -c "signed using.*ECDSA with SHA1"
2247
2248run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 1)" \
2249 "$P_SRV crt_file=data_files/server5.crt \
2250 key_file=data_files/server5.key \
2251 crt_file2=data_files/server6.crt \
2252 key_file2=data_files/server6.key" \
2253 "$P_CLI force_version=tls1_1" \
2254 0 \
2255 -c "serial number.*09" \
2256 -c "signed using.*ECDSA with SHA256" \
2257 -C "signed using.*ECDSA with SHA1"
2258
2259run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 2)" \
2260 "$P_SRV crt_file=data_files/server6.crt \
2261 key_file=data_files/server6.key \
2262 crt_file2=data_files/server5.crt \
2263 key_file2=data_files/server5.key" \
2264 "$P_CLI force_version=tls1_1" \
2265 0 \
2266 -c "serial number.*0A" \
2267 -c "signed using.*ECDSA with SHA256" \
2268 -C "signed using.*ECDSA with SHA1"
2269
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002270# tests for SNI
2271
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002272run_test "SNI: no SNI callback" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002273 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002274 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002275 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002276 0 \
2277 -S "parse ServerName extension" \
2278 -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
2279 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002280
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002281run_test "SNI: matching cert 1" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002282 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002283 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002284 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 +02002285 "$P_CLI server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002286 0 \
2287 -s "parse ServerName extension" \
2288 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2289 -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002290
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002291run_test "SNI: matching cert 2" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002292 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002293 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002294 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 +02002295 "$P_CLI server_name=polarssl.example" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002296 0 \
2297 -s "parse ServerName extension" \
2298 -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
2299 -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002300
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002301run_test "SNI: no matching cert" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02002302 "$P_SRV debug_level=3 \
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002303 crt_file=data_files/server5.crt key_file=data_files/server5.key \
Manuel Pégourié-Gonnard4d6f1782015-06-19 14:40:39 +02002304 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 +02002305 "$P_CLI server_name=nonesuch.example" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002306 1 \
2307 -s "parse ServerName extension" \
2308 -s "ssl_sni_wrapper() returned" \
2309 -s "mbedtls_ssl_handshake returned" \
2310 -c "mbedtls_ssl_handshake returned" \
2311 -c "SSL - A fatal alert message was received from our peer"
Manuel Pégourié-Gonnard96ea2f22014-02-25 12:26:29 +01002312
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002313run_test "SNI: client auth no override: optional" \
2314 "$P_SRV debug_level=3 auth_mode=optional \
2315 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2316 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
2317 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002318 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002319 -S "skip write certificate request" \
2320 -C "skip parse certificate request" \
2321 -c "got a certificate request" \
2322 -C "skip write certificate" \
2323 -C "skip write certificate verify" \
2324 -S "skip parse certificate verify"
2325
2326run_test "SNI: client auth override: none -> optional" \
2327 "$P_SRV debug_level=3 auth_mode=none \
2328 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2329 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
2330 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002331 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002332 -S "skip write certificate request" \
2333 -C "skip parse certificate request" \
2334 -c "got a certificate request" \
2335 -C "skip write certificate" \
2336 -C "skip write certificate verify" \
2337 -S "skip parse certificate verify"
2338
2339run_test "SNI: client auth override: optional -> none" \
2340 "$P_SRV debug_level=3 auth_mode=optional \
2341 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2342 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
2343 "$P_CLI debug_level=3 server_name=localhost" \
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002344 0 \
Manuel Pégourié-Gonnardc948a792015-06-22 16:04:20 +02002345 -s "skip write certificate request" \
2346 -C "skip parse certificate request" \
2347 -c "got no certificate request" \
2348 -c "skip write certificate" \
2349 -c "skip write certificate verify" \
2350 -s "skip parse certificate verify"
2351
Manuel Pégourié-Gonnard6ea831d2015-06-22 16:50:52 +02002352run_test "SNI: CA no override" \
2353 "$P_SRV debug_level=3 auth_mode=optional \
2354 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2355 ca_file=data_files/test-ca.crt \
2356 sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
2357 "$P_CLI debug_level=3 server_name=localhost \
2358 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2359 1 \
2360 -S "skip write certificate request" \
2361 -C "skip parse certificate request" \
2362 -c "got a certificate request" \
2363 -C "skip write certificate" \
2364 -C "skip write certificate verify" \
2365 -S "skip parse certificate verify" \
2366 -s "x509_verify_cert() returned" \
2367 -s "! The certificate is not correctly signed by the trusted CA" \
2368 -S "The certificate has been revoked (is on a CRL)"
2369
2370run_test "SNI: CA override" \
2371 "$P_SRV debug_level=3 auth_mode=optional \
2372 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2373 ca_file=data_files/test-ca.crt \
2374 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
2375 "$P_CLI debug_level=3 server_name=localhost \
2376 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2377 0 \
2378 -S "skip write certificate request" \
2379 -C "skip parse certificate request" \
2380 -c "got a certificate request" \
2381 -C "skip write certificate" \
2382 -C "skip write certificate verify" \
2383 -S "skip parse certificate verify" \
2384 -S "x509_verify_cert() returned" \
2385 -S "! The certificate is not correctly signed by the trusted CA" \
2386 -S "The certificate has been revoked (is on a CRL)"
2387
2388run_test "SNI: CA override with CRL" \
2389 "$P_SRV debug_level=3 auth_mode=optional \
2390 crt_file=data_files/server5.crt key_file=data_files/server5.key \
2391 ca_file=data_files/test-ca.crt \
2392 sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
2393 "$P_CLI debug_level=3 server_name=localhost \
2394 crt_file=data_files/server6.crt key_file=data_files/server6.key" \
2395 1 \
2396 -S "skip write certificate request" \
2397 -C "skip parse certificate request" \
2398 -c "got a certificate request" \
2399 -C "skip write certificate" \
2400 -C "skip write certificate verify" \
2401 -S "skip parse certificate verify" \
2402 -s "x509_verify_cert() returned" \
2403 -S "! The certificate is not correctly signed by the trusted CA" \
2404 -s "The certificate has been revoked (is on a CRL)"
2405
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002406# Tests for non-blocking I/O: exercise a variety of handshake flows
2407
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002408run_test "Non-blocking I/O: basic handshake" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002409 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
2410 "$P_CLI nbio=2 tickets=0" \
2411 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002412 -S "mbedtls_ssl_handshake returned" \
2413 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002414 -c "Read from server: .* bytes read"
2415
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002416run_test "Non-blocking I/O: client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002417 "$P_SRV nbio=2 tickets=0 auth_mode=required" \
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: ticket" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002425 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
2426 "$P_CLI nbio=2 tickets=1" \
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 + client auth" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002433 "$P_SRV nbio=2 tickets=1 auth_mode=required" \
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 + resume" \
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 reconnect=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 + resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002449 "$P_SRV nbio=2 tickets=1 auth_mode=none" \
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: session-id resume" \
Manuel Pégourié-Gonnard0b6609b2014-02-26 14:45:12 +01002457 "$P_SRV nbio=2 tickets=0 auth_mode=none" \
2458 "$P_CLI nbio=2 tickets=0 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
Hanno Becker00076712017-11-15 16:39:08 +00002464# Tests for event-driven I/O: exercise a variety of handshake flows
2465
2466run_test "Event-driven I/O: basic handshake" \
2467 "$P_SRV event=1 tickets=0 auth_mode=none" \
2468 "$P_CLI event=1 tickets=0" \
2469 0 \
2470 -S "mbedtls_ssl_handshake returned" \
2471 -C "mbedtls_ssl_handshake returned" \
2472 -c "Read from server: .* bytes read"
2473
2474run_test "Event-driven I/O: client auth" \
2475 "$P_SRV event=1 tickets=0 auth_mode=required" \
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: ticket" \
2483 "$P_SRV event=1 tickets=1 auth_mode=none" \
2484 "$P_CLI event=1 tickets=1" \
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 + client auth" \
2491 "$P_SRV event=1 tickets=1 auth_mode=required" \
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 + resume" \
2499 "$P_SRV event=1 tickets=1 auth_mode=required" \
2500 "$P_CLI event=1 tickets=1 reconnect=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 + resume" \
2507 "$P_SRV event=1 tickets=1 auth_mode=none" \
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: session-id resume" \
2515 "$P_SRV event=1 tickets=0 auth_mode=none" \
2516 "$P_CLI event=1 tickets=0 reconnect=1" \
2517 0 \
2518 -S "mbedtls_ssl_handshake returned" \
2519 -C "mbedtls_ssl_handshake returned" \
2520 -c "Read from server: .* bytes read"
2521
Hanno Becker6a33f592018-03-13 11:38:46 +00002522run_test "Event-driven I/O, DTLS: basic handshake" \
2523 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
2524 "$P_CLI dtls=1 event=1 tickets=0" \
2525 0 \
2526 -c "Read from server: .* bytes read"
2527
2528run_test "Event-driven I/O, DTLS: client auth" \
2529 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
2530 "$P_CLI dtls=1 event=1 tickets=0" \
2531 0 \
2532 -c "Read from server: .* bytes read"
2533
2534run_test "Event-driven I/O, DTLS: ticket" \
2535 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
2536 "$P_CLI dtls=1 event=1 tickets=1" \
2537 0 \
2538 -c "Read from server: .* bytes read"
2539
2540run_test "Event-driven I/O, DTLS: ticket + client auth" \
2541 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
2542 "$P_CLI dtls=1 event=1 tickets=1" \
2543 0 \
2544 -c "Read from server: .* bytes read"
2545
2546run_test "Event-driven I/O, DTLS: ticket + client auth + resume" \
2547 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
2548 "$P_CLI dtls=1 event=1 tickets=1 reconnect=1" \
2549 0 \
2550 -c "Read from server: .* bytes read"
2551
2552run_test "Event-driven I/O, DTLS: ticket + resume" \
2553 "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
2554 "$P_CLI dtls=1 event=1 tickets=1 reconnect=1" \
2555 0 \
2556 -c "Read from server: .* bytes read"
2557
2558run_test "Event-driven I/O, DTLS: session-id resume" \
2559 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
2560 "$P_CLI dtls=1 event=1 tickets=0 reconnect=1" \
2561 0 \
2562 -c "Read from server: .* bytes read"
Hanno Beckerbc6c1102018-03-13 11:39:40 +00002563
2564# This test demonstrates the need for the mbedtls_ssl_check_pending function.
2565# During session resumption, the client will send its ApplicationData record
2566# within the same datagram as the Finished messages. In this situation, the
2567# server MUST NOT idle on the underlying transport after handshake completion,
2568# because the ApplicationData request has already been queued internally.
2569run_test "Event-driven I/O, DTLS: session-id resume, UDP packing" \
Hanno Becker8d832182018-03-15 10:14:19 +00002570 -p "$P_PXY pack=50" \
Hanno Beckerbc6c1102018-03-13 11:39:40 +00002571 "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
2572 "$P_CLI dtls=1 event=1 tickets=0 reconnect=1" \
2573 0 \
2574 -c "Read from server: .* bytes read"
2575
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002576# Tests for version negotiation
2577
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002578run_test "Version check: all -> 1.2" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002579 "$P_SRV" \
2580 "$P_CLI" \
2581 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002582 -S "mbedtls_ssl_handshake returned" \
2583 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002584 -s "Protocol is TLSv1.2" \
2585 -c "Protocol is TLSv1.2"
2586
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002587run_test "Version check: cli max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002588 "$P_SRV" \
2589 "$P_CLI max_version=tls1_1" \
2590 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002591 -S "mbedtls_ssl_handshake returned" \
2592 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002593 -s "Protocol is TLSv1.1" \
2594 -c "Protocol is TLSv1.1"
2595
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002596run_test "Version check: srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002597 "$P_SRV max_version=tls1_1" \
2598 "$P_CLI" \
2599 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002600 -S "mbedtls_ssl_handshake returned" \
2601 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002602 -s "Protocol is TLSv1.1" \
2603 -c "Protocol is TLSv1.1"
2604
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002605run_test "Version check: cli+srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002606 "$P_SRV max_version=tls1_1" \
2607 "$P_CLI max_version=tls1_1" \
2608 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002609 -S "mbedtls_ssl_handshake returned" \
2610 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002611 -s "Protocol is TLSv1.1" \
2612 -c "Protocol is TLSv1.1"
2613
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002614run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002615 "$P_SRV min_version=tls1_1" \
2616 "$P_CLI max_version=tls1_1" \
2617 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002618 -S "mbedtls_ssl_handshake returned" \
2619 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002620 -s "Protocol is TLSv1.1" \
2621 -c "Protocol is TLSv1.1"
2622
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002623run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002624 "$P_SRV max_version=tls1_1" \
2625 "$P_CLI min_version=tls1_1" \
2626 0 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002627 -S "mbedtls_ssl_handshake returned" \
2628 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002629 -s "Protocol is TLSv1.1" \
2630 -c "Protocol is TLSv1.1"
2631
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002632run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002633 "$P_SRV max_version=tls1_1" \
2634 "$P_CLI min_version=tls1_2" \
2635 1 \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002636 -s "mbedtls_ssl_handshake returned" \
2637 -c "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002638 -c "SSL - Handshake protocol not within min/max boundaries"
2639
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002640run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
Manuel Pégourié-Gonnarda3d808e2014-02-26 16:33:03 +01002641 "$P_SRV min_version=tls1_2" \
2642 "$P_CLI max_version=tls1_1" \
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 -s "SSL - Handshake protocol not within min/max boundaries"
2647
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002648# Tests for ALPN extension
2649
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002650run_test "ALPN: none" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002651 "$P_SRV debug_level=3" \
2652 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002653 0 \
2654 -C "client hello, adding alpn extension" \
2655 -S "found alpn extension" \
2656 -C "got an alert message, type: \\[2:120]" \
2657 -S "server hello, adding alpn extension" \
2658 -C "found alpn extension " \
2659 -C "Application Layer Protocol is" \
2660 -S "Application Layer Protocol is"
2661
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002662run_test "ALPN: client only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002663 "$P_SRV debug_level=3" \
2664 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002665 0 \
2666 -c "client hello, adding alpn extension" \
2667 -s "found alpn extension" \
2668 -C "got an alert message, type: \\[2:120]" \
2669 -S "server hello, adding alpn extension" \
2670 -C "found alpn extension " \
2671 -c "Application Layer Protocol is (none)" \
2672 -S "Application Layer Protocol is"
2673
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002674run_test "ALPN: server only" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002675 "$P_SRV debug_level=3 alpn=abc,1234" \
2676 "$P_CLI debug_level=3" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002677 0 \
2678 -C "client hello, adding alpn extension" \
2679 -S "found alpn extension" \
2680 -C "got an alert message, type: \\[2:120]" \
2681 -S "server hello, adding alpn extension" \
2682 -C "found alpn extension " \
2683 -C "Application Layer Protocol is" \
2684 -s "Application Layer Protocol is (none)"
2685
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002686run_test "ALPN: both, common cli1-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002687 "$P_SRV debug_level=3 alpn=abc,1234" \
2688 "$P_CLI debug_level=3 alpn=abc,1234" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002689 0 \
2690 -c "client hello, adding alpn extension" \
2691 -s "found alpn extension" \
2692 -C "got an alert message, type: \\[2:120]" \
2693 -s "server hello, adding alpn extension" \
2694 -c "found alpn extension" \
2695 -c "Application Layer Protocol is abc" \
2696 -s "Application Layer Protocol is abc"
2697
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002698run_test "ALPN: both, common cli2-srv1" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002699 "$P_SRV debug_level=3 alpn=abc,1234" \
2700 "$P_CLI debug_level=3 alpn=1234,abc" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002701 0 \
2702 -c "client hello, adding alpn extension" \
2703 -s "found alpn extension" \
2704 -C "got an alert message, type: \\[2:120]" \
2705 -s "server hello, adding alpn extension" \
2706 -c "found alpn extension" \
2707 -c "Application Layer Protocol is abc" \
2708 -s "Application Layer Protocol is abc"
2709
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002710run_test "ALPN: both, common cli1-srv2" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002711 "$P_SRV debug_level=3 alpn=abc,1234" \
2712 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002713 0 \
2714 -c "client hello, adding alpn extension" \
2715 -s "found alpn extension" \
2716 -C "got an alert message, type: \\[2:120]" \
2717 -s "server hello, adding alpn extension" \
2718 -c "found alpn extension" \
2719 -c "Application Layer Protocol is 1234" \
2720 -s "Application Layer Protocol is 1234"
2721
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002722run_test "ALPN: both, no common" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002723 "$P_SRV debug_level=3 alpn=abc,123" \
2724 "$P_CLI debug_level=3 alpn=1234,abcde" \
Manuel Pégourié-Gonnardf6521de2014-04-07 12:42:04 +02002725 1 \
2726 -c "client hello, adding alpn extension" \
2727 -s "found alpn extension" \
2728 -c "got an alert message, type: \\[2:120]" \
2729 -S "server hello, adding alpn extension" \
2730 -C "found alpn extension" \
2731 -C "Application Layer Protocol is 1234" \
2732 -S "Application Layer Protocol is 1234"
2733
Manuel Pégourié-Gonnard83d8c732014-04-07 13:24:21 +02002734
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002735# Tests for keyUsage in leaf certificates, part 1:
2736# server-side certificate/suite selection
2737
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002738run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002739 "$P_SRV key_file=data_files/server2.key \
2740 crt_file=data_files/server2.ku-ds.crt" \
2741 "$P_CLI" \
2742 0 \
Manuel Pégourié-Gonnard17cde5f2014-05-22 14:42:39 +02002743 -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002744
2745
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002746run_test "keyUsage srv: RSA, keyEncipherment -> 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-ke.crt" \
2749 "$P_CLI" \
2750 0 \
2751 -c "Ciphersuite is TLS-RSA-WITH-"
2752
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002753run_test "keyUsage srv: RSA, keyAgreement -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002754 "$P_SRV key_file=data_files/server2.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002755 crt_file=data_files/server2.ku-ka.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002756 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002757 1 \
2758 -C "Ciphersuite is "
2759
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002760run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002761 "$P_SRV key_file=data_files/server5.key \
2762 crt_file=data_files/server5.ku-ds.crt" \
2763 "$P_CLI" \
2764 0 \
2765 -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
2766
2767
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002768run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
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-ka.crt" \
2771 "$P_CLI" \
2772 0 \
2773 -c "Ciphersuite is TLS-ECDH-"
2774
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002775run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002776 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002777 crt_file=data_files/server5.ku-ke.crt" \
Manuel Pégourié-Gonnardf2629b92014-08-30 14:20:14 +02002778 "$P_CLI" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002779 1 \
2780 -C "Ciphersuite is "
2781
2782# Tests for keyUsage in leaf certificates, part 2:
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002783# client-side checking of server cert
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002784
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002785run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002786 "$O_SRV -key data_files/server2.key \
2787 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002788 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002789 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2790 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002791 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002792 -C "Processing of the Certificate handshake message failed" \
2793 -c "Ciphersuite is TLS-"
2794
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002795run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002796 "$O_SRV -key data_files/server2.key \
2797 -cert data_files/server2.ku-ds_ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002798 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002799 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2800 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002801 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002802 -C "Processing of the Certificate handshake message failed" \
2803 -c "Ciphersuite is TLS-"
2804
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002805run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002806 "$O_SRV -key data_files/server2.key \
2807 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002808 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002809 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2810 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002811 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002812 -C "Processing of the Certificate handshake message failed" \
2813 -c "Ciphersuite is TLS-"
2814
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002815run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002816 "$O_SRV -key data_files/server2.key \
2817 -cert data_files/server2.ku-ke.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002818 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002819 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2820 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002821 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002822 -c "Processing of the Certificate handshake message failed" \
2823 -C "Ciphersuite is TLS-"
2824
Manuel Pégourié-Gonnarde6efa6f2015-04-20 11:01:48 +01002825run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail, soft" \
2826 "$O_SRV -key data_files/server2.key \
2827 -cert data_files/server2.ku-ke.crt" \
2828 "$P_CLI debug_level=1 auth_mode=optional \
2829 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2830 0 \
2831 -c "bad certificate (usage extensions)" \
2832 -C "Processing of the Certificate handshake message failed" \
2833 -c "Ciphersuite is TLS-" \
2834 -c "! Usage does not match the keyUsage extension"
2835
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002836run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002837 "$O_SRV -key data_files/server2.key \
2838 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002839 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002840 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2841 0 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002842 -C "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002843 -C "Processing of the Certificate handshake message failed" \
2844 -c "Ciphersuite is TLS-"
2845
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002846run_test "keyUsage cli: DigitalSignature, RSA: fail" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002847 "$O_SRV -key data_files/server2.key \
2848 -cert data_files/server2.ku-ds.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002849 "$P_CLI debug_level=1 \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002850 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2851 1 \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002852 -c "bad certificate (usage extensions)" \
Manuel Pégourié-Gonnard7f2a07d2014-04-09 09:50:57 +02002853 -c "Processing of the Certificate handshake message failed" \
2854 -C "Ciphersuite is TLS-"
2855
Manuel Pégourié-Gonnarde6efa6f2015-04-20 11:01:48 +01002856run_test "keyUsage cli: DigitalSignature, RSA: fail, soft" \
2857 "$O_SRV -key data_files/server2.key \
2858 -cert data_files/server2.ku-ds.crt" \
2859 "$P_CLI debug_level=1 auth_mode=optional \
2860 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
2861 0 \
2862 -c "bad certificate (usage extensions)" \
2863 -C "Processing of the Certificate handshake message failed" \
2864 -c "Ciphersuite is TLS-" \
2865 -c "! Usage does not match the keyUsage extension"
2866
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002867# Tests for keyUsage in leaf certificates, part 3:
2868# server-side checking of client cert
2869
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002870run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002871 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002872 "$O_CLI -key data_files/server2.key \
2873 -cert data_files/server2.ku-ds.crt" \
2874 0 \
2875 -S "bad certificate (usage extensions)" \
2876 -S "Processing of the Certificate handshake message failed"
2877
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002878run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
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-ke.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 (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002887 "$P_SRV debug_level=1 auth_mode=required" \
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 1 \
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: ECDSA, DigitalSignature: OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002895 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnarda9db85d2014-04-09 14:53:05 +02002896 "$O_CLI -key data_files/server5.key \
2897 -cert data_files/server5.ku-ds.crt" \
2898 0 \
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, KeyAgreement: fail (soft)" \
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-ka.crt" \
2906 0 \
2907 -s "bad certificate (usage extensions)" \
2908 -S "Processing of the Certificate handshake message failed"
2909
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002910# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
2911
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002912run_test "extKeyUsage srv: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002913 "$P_SRV key_file=data_files/server5.key \
2914 crt_file=data_files/server5.eku-srv.crt" \
2915 "$P_CLI" \
2916 0
2917
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002918run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002919 "$P_SRV key_file=data_files/server5.key \
2920 crt_file=data_files/server5.eku-srv.crt" \
2921 "$P_CLI" \
2922 0
2923
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002924run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002925 "$P_SRV key_file=data_files/server5.key \
2926 crt_file=data_files/server5.eku-cs_any.crt" \
2927 "$P_CLI" \
2928 0
2929
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002930run_test "extKeyUsage srv: codeSign -> fail" \
Manuel Pégourié-Gonnard7eb58cb2015-07-07 11:54:14 +02002931 "$P_SRV key_file=data_files/server5.key \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002932 crt_file=data_files/server5.eku-cli.crt" \
Manuel Pégourié-Gonnard7eb58cb2015-07-07 11:54:14 +02002933 "$P_CLI" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002934 1
2935
2936# Tests for extendedKeyUsage, part 2: client-side checking of server cert
2937
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002938run_test "extKeyUsage cli: serverAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002939 "$O_SRV -key data_files/server5.key \
2940 -cert data_files/server5.eku-srv.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002941 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002942 0 \
2943 -C "bad certificate (usage extensions)" \
2944 -C "Processing of the Certificate handshake message failed" \
2945 -c "Ciphersuite is TLS-"
2946
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002947run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002948 "$O_SRV -key data_files/server5.key \
2949 -cert data_files/server5.eku-srv_cli.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002950 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002951 0 \
2952 -C "bad certificate (usage extensions)" \
2953 -C "Processing of the Certificate handshake message failed" \
2954 -c "Ciphersuite is TLS-"
2955
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002956run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002957 "$O_SRV -key data_files/server5.key \
2958 -cert data_files/server5.eku-cs_any.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002959 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002960 0 \
2961 -C "bad certificate (usage extensions)" \
2962 -C "Processing of the Certificate handshake message failed" \
2963 -c "Ciphersuite is TLS-"
2964
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002965run_test "extKeyUsage cli: codeSign -> fail" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002966 "$O_SRV -key data_files/server5.key \
2967 -cert data_files/server5.eku-cs.crt" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002968 "$P_CLI debug_level=1" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002969 1 \
2970 -c "bad certificate (usage extensions)" \
2971 -c "Processing of the Certificate handshake message failed" \
2972 -C "Ciphersuite is TLS-"
2973
2974# Tests for extendedKeyUsage, part 3: server-side checking of client cert
2975
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002976run_test "extKeyUsage cli-auth: clientAuth -> OK" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02002977 "$P_SRV debug_level=1 auth_mode=optional" \
Manuel Pégourié-Gonnard0408fd12014-04-11 11:06:22 +02002978 "$O_CLI -key data_files/server5.key \
2979 -cert data_files/server5.eku-cli.crt" \
2980 0 \
2981 -S "bad certificate (usage extensions)" \
2982 -S "Processing of the Certificate handshake message failed"
2983
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02002984run_test "extKeyUsage cli-auth: serverAuth,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-srv_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: codeSign,anyEKU -> 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-cs_any.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 -> fail (soft)" \
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.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 (hard)" \
Manuel Pégourié-Gonnard644e8f32014-08-30 21:59:31 +02003009 "$P_SRV debug_level=1 auth_mode=required" \
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 1 \
3013 -s "bad certificate (usage extensions)" \
3014 -s "Processing of the Certificate handshake message failed"
3015
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003016# Tests for DHM parameters loading
3017
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003018run_test "DHM parameters: reference" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003019 "$P_SRV" \
3020 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3021 debug_level=3" \
3022 0 \
3023 -c "value of 'DHM: P ' (2048 bits)" \
3024 -c "value of 'DHM: G ' (2048 bits)"
3025
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003026run_test "DHM parameters: other parameters" \
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003027 "$P_SRV dhm_file=data_files/dhparams.pem" \
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 ' (1024 bits)" \
3032 -c "value of 'DHM: G ' (2 bits)"
3033
Manuel Pégourié-Gonnard7a010aa2015-06-12 11:19:10 +02003034# Tests for DHM client-side size checking
3035
3036run_test "DHM size: server default, client default, OK" \
3037 "$P_SRV" \
3038 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3039 debug_level=1" \
3040 0 \
3041 -C "DHM prime too short:"
3042
3043run_test "DHM size: server default, client 2048, OK" \
3044 "$P_SRV" \
3045 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3046 debug_level=1 dhmlen=2048" \
3047 0 \
3048 -C "DHM prime too short:"
3049
3050run_test "DHM size: server 1024, client default, OK" \
3051 "$P_SRV dhm_file=data_files/dhparams.pem" \
3052 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3053 debug_level=1" \
3054 0 \
3055 -C "DHM prime too short:"
3056
3057run_test "DHM size: server 1000, client default, rejected" \
3058 "$P_SRV dhm_file=data_files/dh.1000.pem" \
3059 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3060 debug_level=1" \
3061 1 \
3062 -c "DHM prime too short:"
3063
3064run_test "DHM size: server default, client 2049, rejected" \
3065 "$P_SRV" \
3066 "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
3067 debug_level=1 dhmlen=2049" \
3068 1 \
3069 -c "DHM prime too short:"
3070
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003071# Tests for PSK callback
3072
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003073run_test "PSK callback: psk, no callback" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003074 "$P_SRV psk=abc123 psk_identity=foo" \
3075 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3076 psk_identity=foo psk=abc123" \
3077 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003078 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02003079 -S "SSL - Unknown identity received" \
3080 -S "SSL - Verification of the message MAC failed"
3081
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003082run_test "PSK callback: no psk, no callback" \
Manuel Pégourié-Gonnard10c3c9f2014-06-10 15:28:52 +02003083 "$P_SRV" \
3084 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3085 psk_identity=foo psk=abc123" \
3086 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003087 -s "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003088 -S "SSL - Unknown identity received" \
3089 -S "SSL - Verification of the message MAC failed"
3090
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003091run_test "PSK callback: callback overrides other settings" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003092 "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
3093 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3094 psk_identity=foo psk=abc123" \
3095 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003096 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003097 -s "SSL - Unknown identity received" \
3098 -S "SSL - Verification of the message MAC failed"
3099
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003100run_test "PSK callback: first id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003101 "$P_SRV psk_list=abc,dead,def,beef" \
3102 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3103 psk_identity=abc psk=dead" \
3104 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003105 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003106 -S "SSL - Unknown identity received" \
3107 -S "SSL - Verification of the message MAC failed"
3108
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003109run_test "PSK callback: second id matches" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003110 "$P_SRV psk_list=abc,dead,def,beef" \
3111 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3112 psk_identity=def psk=beef" \
3113 0 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003114 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003115 -S "SSL - Unknown identity received" \
3116 -S "SSL - Verification of the message MAC failed"
3117
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003118run_test "PSK callback: no match" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003119 "$P_SRV psk_list=abc,dead,def,beef" \
3120 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3121 psk_identity=ghi psk=beef" \
3122 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003123 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003124 -s "SSL - Unknown identity received" \
3125 -S "SSL - Verification of the message MAC failed"
3126
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003127run_test "PSK callback: wrong key" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003128 "$P_SRV psk_list=abc,dead,def,beef" \
3129 "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
3130 psk_identity=abc psk=beef" \
3131 1 \
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +01003132 -S "SSL - None of the common ciphersuites is usable" \
Manuel Pégourié-Gonnarda6781c92014-06-10 15:00:46 +02003133 -S "SSL - Unknown identity received" \
3134 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnard0cc7e312014-06-09 11:36:47 +02003135
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003136# Tests for EC J-PAKE
3137
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003138requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003139run_test "ECJPAKE: client not configured" \
3140 "$P_SRV debug_level=3" \
3141 "$P_CLI debug_level=3" \
3142 0 \
3143 -C "add ciphersuite: c0ff" \
3144 -C "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003145 -S "found ecjpake kkpp extension" \
3146 -S "skip ecjpake kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003147 -S "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003148 -S "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003149 -C "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003150 -S "None of the common ciphersuites is usable"
3151
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003152requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003153run_test "ECJPAKE: server not configured" \
3154 "$P_SRV debug_level=3" \
3155 "$P_CLI debug_level=3 ecjpake_pw=bla \
3156 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3157 1 \
3158 -c "add ciphersuite: c0ff" \
3159 -c "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003160 -s "found ecjpake kkpp extension" \
3161 -s "skip ecjpake kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003162 -s "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003163 -S "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003164 -C "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnarde511b4e2015-09-16 14:11:09 +02003165 -s "None of the common ciphersuites is usable"
3166
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003167requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003168run_test "ECJPAKE: working, TLS" \
3169 "$P_SRV debug_level=3 ecjpake_pw=bla" \
3170 "$P_CLI debug_level=3 ecjpake_pw=bla \
3171 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
Manuel Pégourié-Gonnard0f1660a2015-09-16 22:41:06 +02003172 0 \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003173 -c "add ciphersuite: c0ff" \
3174 -c "adding ecjpake_kkpp extension" \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003175 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003176 -s "found ecjpake kkpp extension" \
3177 -S "skip ecjpake kkpp extension" \
3178 -S "ciphersuite mismatch: ecjpake not configured" \
Manuel Pégourié-Gonnard55c7f992015-09-16 15:35:27 +02003179 -s "server hello, ecjpake kkpp extension" \
Manuel Pégourié-Gonnard0a1324a2015-09-16 16:01:00 +02003180 -c "found ecjpake_kkpp extension" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003181 -S "None of the common ciphersuites is usable" \
3182 -S "SSL - Verification of the message MAC failed"
3183
Janos Follath74537a62016-09-02 13:45:28 +01003184server_needs_more_time 1
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003185requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003186run_test "ECJPAKE: password mismatch, TLS" \
3187 "$P_SRV debug_level=3 ecjpake_pw=bla" \
3188 "$P_CLI debug_level=3 ecjpake_pw=bad \
3189 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3190 1 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003191 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003192 -s "SSL - Verification of the message MAC failed"
3193
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003194requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003195run_test "ECJPAKE: working, DTLS" \
3196 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
3197 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
3198 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3199 0 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003200 -c "re-using cached ecjpake parameters" \
3201 -S "SSL - Verification of the message MAC failed"
3202
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003203requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003204run_test "ECJPAKE: working, DTLS, no cookie" \
3205 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla cookies=0" \
3206 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
3207 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3208 0 \
3209 -C "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003210 -S "SSL - Verification of the message MAC failed"
3211
Janos Follath74537a62016-09-02 13:45:28 +01003212server_needs_more_time 1
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003213requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003214run_test "ECJPAKE: password mismatch, DTLS" \
3215 "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
3216 "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bad \
3217 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3218 1 \
Manuel Pégourié-Gonnardd0d8cb32015-09-17 14:16:30 +02003219 -c "re-using cached ecjpake parameters" \
Manuel Pégourié-Gonnard921f2d02015-09-16 22:52:18 +02003220 -s "SSL - Verification of the message MAC failed"
Manuel Pégourié-Gonnardbf57be62015-09-16 15:04:01 +02003221
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +02003222# for tests with configs/config-thread.h
Manuel Pégourié-Gonnard12ca6f52015-10-20 15:24:51 +02003223requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
Manuel Pégourié-Gonnardca700b22015-10-20 14:47:00 +02003224run_test "ECJPAKE: working, DTLS, nolog" \
3225 "$P_SRV dtls=1 ecjpake_pw=bla" \
3226 "$P_CLI dtls=1 ecjpake_pw=bla \
3227 force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
3228 0
3229
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003230# Tests for ciphersuites per version
3231
Janos Follathe2681a42016-03-07 15:57:05 +00003232requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003233run_test "Per-version suites: SSL3" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003234 "$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 +02003235 "$P_CLI force_version=ssl3" \
3236 0 \
3237 -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
3238
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003239run_test "Per-version suites: TLS 1.0" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003240 "$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 +01003241 "$P_CLI force_version=tls1 arc4=1" \
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003242 0 \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003243 -c "Ciphersuite is TLS-RSA-WITH-AES-256-CBC-SHA"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003244
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003245run_test "Per-version suites: TLS 1.1" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003246 "$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 +02003247 "$P_CLI force_version=tls1_1" \
3248 0 \
3249 -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
3250
Manuel Pégourié-Gonnard8e03c712014-08-30 21:42:40 +02003251run_test "Per-version suites: TLS 1.2" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003252 "$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 +02003253 "$P_CLI force_version=tls1_2" \
3254 0 \
3255 -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
3256
Manuel Pégourié-Gonnard4cc8c632015-07-23 12:24:03 +02003257# Test for ClientHello without extensions
3258
Manuel Pégourié-Gonnardd55bc202015-08-04 16:22:30 +02003259requires_gnutls
Gilles Peskine5d2511c2017-05-12 13:16:40 +02003260run_test "ClientHello without extensions, SHA-1 allowed" \
Manuel Pégourié-Gonnard4cc8c632015-07-23 12:24:03 +02003261 "$P_SRV debug_level=3" \
3262 "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \
3263 0 \
3264 -s "dumping 'client hello extensions' (0 bytes)"
3265
Gilles Peskine5d2511c2017-05-12 13:16:40 +02003266requires_gnutls
3267run_test "ClientHello without extensions, SHA-1 forbidden in certificates on server" \
3268 "$P_SRV debug_level=3 key_file=data_files/server2.key crt_file=data_files/server2.crt allow_sha1=0" \
3269 "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \
3270 0 \
3271 -s "dumping 'client hello extensions' (0 bytes)"
3272
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003273# Tests for mbedtls_ssl_get_bytes_avail()
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003274
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003275run_test "mbedtls_ssl_get_bytes_avail: no extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003276 "$P_SRV" \
3277 "$P_CLI request_size=100" \
3278 0 \
3279 -s "Read from client: 100 bytes read$"
3280
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003281run_test "mbedtls_ssl_get_bytes_avail: extra data" \
Manuel Pégourié-Gonnard95c0a632014-06-11 18:32:36 +02003282 "$P_SRV" \
3283 "$P_CLI request_size=500" \
3284 0 \
3285 -s "Read from client: 500 bytes read (.*+.*)"
Manuel Pégourié-Gonnard90805a82014-06-11 14:06:01 +02003286
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003287# Tests for small packets
3288
Janos Follathe2681a42016-03-07 15:57:05 +00003289requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003290run_test "Small packet SSLv3 BlockCipher" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01003291 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003292 "$P_CLI request_size=1 force_version=ssl3 \
3293 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3294 0 \
3295 -s "Read from client: 1 bytes read"
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 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003299 "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003300 "$P_CLI request_size=1 force_version=ssl3 \
3301 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3302 0 \
3303 -s "Read from client: 1 bytes read"
3304
3305run_test "Small packet TLS 1.0 BlockCipher" \
3306 "$P_SRV" \
3307 "$P_CLI request_size=1 force_version=tls1 \
3308 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3309 0 \
3310 -s "Read from client: 1 bytes read"
3311
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003312run_test "Small packet TLS 1.0 BlockCipher without EtM" \
3313 "$P_SRV" \
3314 "$P_CLI request_size=1 force_version=tls1 etm=0 \
3315 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3316 0 \
3317 -s "Read from client: 1 bytes read"
3318
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003319run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
3320 "$P_SRV" \
3321 "$P_CLI request_size=1 force_version=tls1 \
3322 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3323 trunc_hmac=1" \
3324 0 \
3325 -s "Read from client: 1 bytes read"
3326
3327run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003328 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003329 "$P_CLI request_size=1 force_version=tls1 \
3330 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3331 trunc_hmac=1" \
3332 0 \
3333 -s "Read from client: 1 bytes read"
3334
3335run_test "Small packet TLS 1.1 BlockCipher" \
3336 "$P_SRV" \
3337 "$P_CLI request_size=1 force_version=tls1_1 \
3338 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3339 0 \
3340 -s "Read from client: 1 bytes read"
3341
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003342run_test "Small packet TLS 1.1 BlockCipher without EtM" \
3343 "$P_SRV" \
3344 "$P_CLI request_size=1 force_version=tls1_1 etm=0 \
3345 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3346 0 \
3347 -s "Read from client: 1 bytes read"
3348
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003349run_test "Small packet TLS 1.1 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003350 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003351 "$P_CLI request_size=1 force_version=tls1_1 \
3352 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3353 0 \
3354 -s "Read from client: 1 bytes read"
3355
3356run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
3357 "$P_SRV" \
3358 "$P_CLI request_size=1 force_version=tls1_1 \
3359 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3360 trunc_hmac=1" \
3361 0 \
3362 -s "Read from client: 1 bytes read"
3363
3364run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003365 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003366 "$P_CLI request_size=1 force_version=tls1_1 \
3367 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3368 trunc_hmac=1" \
3369 0 \
3370 -s "Read from client: 1 bytes read"
3371
3372run_test "Small packet TLS 1.2 BlockCipher" \
3373 "$P_SRV" \
3374 "$P_CLI request_size=1 force_version=tls1_2 \
3375 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3376 0 \
3377 -s "Read from client: 1 bytes read"
3378
Manuel Pégourié-Gonnard169dd6a2014-11-04 16:15:39 +01003379run_test "Small packet TLS 1.2 BlockCipher without EtM" \
3380 "$P_SRV" \
3381 "$P_CLI request_size=1 force_version=tls1_2 etm=0 \
3382 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3383 0 \
3384 -s "Read from client: 1 bytes read"
3385
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003386run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
3387 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003388 "$P_CLI request_size=1 force_version=tls1_2 \
3389 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003390 0 \
3391 -s "Read from client: 1 bytes read"
3392
3393run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
3394 "$P_SRV" \
3395 "$P_CLI request_size=1 force_version=tls1_2 \
3396 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3397 trunc_hmac=1" \
3398 0 \
3399 -s "Read from client: 1 bytes read"
3400
3401run_test "Small packet TLS 1.2 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003402 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003403 "$P_CLI request_size=1 force_version=tls1_2 \
3404 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3405 0 \
3406 -s "Read from client: 1 bytes read"
3407
3408run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003409 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnardee415032014-06-18 15:08:56 +02003410 "$P_CLI request_size=1 force_version=tls1_2 \
3411 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3412 trunc_hmac=1" \
3413 0 \
3414 -s "Read from client: 1 bytes read"
3415
3416run_test "Small packet TLS 1.2 AEAD" \
3417 "$P_SRV" \
3418 "$P_CLI request_size=1 force_version=tls1_2 \
3419 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
3420 0 \
3421 -s "Read from client: 1 bytes read"
3422
3423run_test "Small packet TLS 1.2 AEAD shorter tag" \
3424 "$P_SRV" \
3425 "$P_CLI request_size=1 force_version=tls1_2 \
3426 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
3427 0 \
3428 -s "Read from client: 1 bytes read"
3429
Janos Follath00efff72016-05-06 13:48:23 +01003430# A test for extensions in SSLv3
3431
3432requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
3433run_test "SSLv3 with extensions, server side" \
3434 "$P_SRV min_version=ssl3 debug_level=3" \
3435 "$P_CLI force_version=ssl3 tickets=1 max_frag_len=4096 alpn=abc,1234" \
3436 0 \
3437 -S "dumping 'client hello extensions'" \
3438 -S "server hello, total extension length:"
3439
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003440# Test for large packets
3441
Janos Follathe2681a42016-03-07 15:57:05 +00003442requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003443run_test "Large packet SSLv3 BlockCipher" \
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +01003444 "$P_SRV min_version=ssl3" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003445 "$P_CLI request_size=16384 force_version=ssl3 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003446 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3447 0 \
3448 -s "Read from client: 16384 bytes read"
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 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003452 "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003453 "$P_CLI request_size=16384 force_version=ssl3 \
3454 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3455 0 \
3456 -s "Read from client: 16384 bytes read"
3457
3458run_test "Large packet TLS 1.0 BlockCipher" \
3459 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003460 "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003461 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3462 0 \
3463 -s "Read from client: 16384 bytes read"
3464
3465run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
3466 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003467 "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003468 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3469 trunc_hmac=1" \
3470 0 \
3471 -s "Read from client: 16384 bytes read"
3472
3473run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003474 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003475 "$P_CLI request_size=16384 force_version=tls1 \
3476 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3477 trunc_hmac=1" \
3478 0 \
3479 -s "Read from client: 16384 bytes read"
3480
3481run_test "Large packet TLS 1.1 BlockCipher" \
3482 "$P_SRV" \
3483 "$P_CLI request_size=16384 force_version=tls1_1 \
3484 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3485 0 \
3486 -s "Read from client: 16384 bytes read"
3487
3488run_test "Large packet TLS 1.1 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003489 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003490 "$P_CLI request_size=16384 force_version=tls1_1 \
3491 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3492 0 \
3493 -s "Read from client: 16384 bytes read"
3494
3495run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
3496 "$P_SRV" \
3497 "$P_CLI request_size=16384 force_version=tls1_1 \
3498 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3499 trunc_hmac=1" \
3500 0 \
3501 -s "Read from client: 16384 bytes read"
3502
3503run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003504 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003505 "$P_CLI request_size=16384 force_version=tls1_1 \
3506 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3507 trunc_hmac=1" \
3508 0 \
3509 -s "Read from client: 16384 bytes read"
3510
3511run_test "Large packet TLS 1.2 BlockCipher" \
3512 "$P_SRV" \
3513 "$P_CLI request_size=16384 force_version=tls1_2 \
3514 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
3515 0 \
3516 -s "Read from client: 16384 bytes read"
3517
3518run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
3519 "$P_SRV" \
Manuel Pégourié-Gonnardc82ee352015-01-07 16:35:25 +01003520 "$P_CLI request_size=16384 force_version=tls1_2 \
3521 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003522 0 \
3523 -s "Read from client: 16384 bytes read"
3524
3525run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
3526 "$P_SRV" \
3527 "$P_CLI request_size=16384 force_version=tls1_2 \
3528 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
3529 trunc_hmac=1" \
3530 0 \
3531 -s "Read from client: 16384 bytes read"
3532
3533run_test "Large packet TLS 1.2 StreamCipher" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003534 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003535 "$P_CLI request_size=16384 force_version=tls1_2 \
3536 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
3537 0 \
3538 -s "Read from client: 16384 bytes read"
3539
3540run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
Manuel Pégourié-Gonnardea0920f2015-03-24 09:50:15 +01003541 "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
Manuel Pégourié-Gonnard8920f692014-06-18 22:05:08 +02003542 "$P_CLI request_size=16384 force_version=tls1_2 \
3543 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
3544 trunc_hmac=1" \
3545 0 \
3546 -s "Read from client: 16384 bytes read"
3547
3548run_test "Large packet TLS 1.2 AEAD" \
3549 "$P_SRV" \
3550 "$P_CLI request_size=16384 force_version=tls1_2 \
3551 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
3552 0 \
3553 -s "Read from client: 16384 bytes read"
3554
3555run_test "Large packet TLS 1.2 AEAD shorter tag" \
3556 "$P_SRV" \
3557 "$P_CLI request_size=16384 force_version=tls1_2 \
3558 force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
3559 0 \
3560 -s "Read from client: 16384 bytes read"
3561
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003562# Tests for DTLS HelloVerifyRequest
3563
3564run_test "DTLS cookie: enabled" \
3565 "$P_SRV dtls=1 debug_level=2" \
3566 "$P_CLI dtls=1 debug_level=2" \
3567 0 \
3568 -s "cookie verification failed" \
3569 -s "cookie verification passed" \
3570 -S "cookie verification skipped" \
3571 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003572 -s "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003573 -S "SSL - The requested feature is not available"
3574
3575run_test "DTLS cookie: disabled" \
3576 "$P_SRV dtls=1 debug_level=2 cookies=0" \
3577 "$P_CLI dtls=1 debug_level=2" \
3578 0 \
3579 -S "cookie verification failed" \
3580 -S "cookie verification passed" \
3581 -s "cookie verification skipped" \
3582 -C "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003583 -S "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003584 -S "SSL - The requested feature is not available"
3585
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003586run_test "DTLS cookie: default (failing)" \
3587 "$P_SRV dtls=1 debug_level=2 cookies=-1" \
3588 "$P_CLI dtls=1 debug_level=2 hs_timeout=100-400" \
3589 1 \
3590 -s "cookie verification failed" \
3591 -S "cookie verification passed" \
3592 -S "cookie verification skipped" \
3593 -C "received hello verify request" \
3594 -S "hello verification requested" \
3595 -s "SSL - The requested feature is not available"
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003596
3597requires_ipv6
3598run_test "DTLS cookie: enabled, IPv6" \
3599 "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
3600 "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
3601 0 \
3602 -s "cookie verification failed" \
3603 -s "cookie verification passed" \
3604 -S "cookie verification skipped" \
3605 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003606 -s "hello verification requested" \
Manuel Pégourié-Gonnard0eb6cab2014-07-23 20:17:47 +02003607 -S "SSL - The requested feature is not available"
3608
Manuel Pégourié-Gonnard579950c2014-09-29 17:47:33 +02003609run_test "DTLS cookie: enabled, nbio" \
3610 "$P_SRV dtls=1 nbio=2 debug_level=2" \
3611 "$P_CLI dtls=1 nbio=2 debug_level=2" \
3612 0 \
3613 -s "cookie verification failed" \
3614 -s "cookie verification passed" \
3615 -S "cookie verification skipped" \
3616 -c "received hello verify request" \
Manuel Pégourié-Gonnardcaecdae2014-10-13 19:04:37 +02003617 -s "hello verification requested" \
Manuel Pégourié-Gonnard579950c2014-09-29 17:47:33 +02003618 -S "SSL - The requested feature is not available"
3619
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003620# Tests for client reconnecting from the same port with DTLS
3621
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003622not_with_valgrind # spurious resend
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003623run_test "DTLS client reconnect from same port: reference" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003624 "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
3625 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003626 0 \
3627 -C "resend" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003628 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003629 -S "Client initiated reconnection from same port"
3630
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003631not_with_valgrind # spurious resend
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003632run_test "DTLS client reconnect from same port: reconnect" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003633 "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
3634 "$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 +02003635 0 \
3636 -C "resend" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003637 -S "The operation timed out" \
Manuel Pégourié-Gonnardd745a1a2015-09-08 12:40:43 +02003638 -s "Client initiated reconnection from same port"
3639
Paul Bakker362689d2016-05-13 10:33:25 +01003640not_with_valgrind # server/client too slow to respond in time (next test has higher timeouts)
3641run_test "DTLS client reconnect from same port: reconnect, nbio, no valgrind" \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003642 "$P_SRV dtls=1 exchanges=2 read_timeout=1000 nbio=2" \
3643 "$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 +02003644 0 \
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 +01003648only_with_valgrind # Only with valgrind, do previous test but with higher read_timeout and hs_timeout
3649run_test "DTLS client reconnect from same port: reconnect, nbio, valgrind" \
3650 "$P_SRV dtls=1 exchanges=2 read_timeout=2000 nbio=2 hs_timeout=1500-6000" \
3651 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=1500-3000 reconnect_hard=1" \
3652 0 \
3653 -S "The operation timed out" \
3654 -s "Client initiated reconnection from same port"
3655
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003656run_test "DTLS client reconnect from same port: no cookies" \
3657 "$P_SRV dtls=1 exchanges=2 read_timeout=1000 cookies=0" \
Manuel Pégourié-Gonnard6ad23b92015-09-15 12:57:46 +02003658 "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-8000 reconnect_hard=1" \
3659 0 \
Manuel Pégourié-Gonnard259db912015-09-09 11:37:17 +02003660 -s "The operation timed out" \
3661 -S "Client initiated reconnection from same port"
3662
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003663# Tests for various cases of client authentication with DTLS
3664# (focused on handshake flows and message parsing)
3665
3666run_test "DTLS client auth: required" \
3667 "$P_SRV dtls=1 auth_mode=required" \
3668 "$P_CLI dtls=1" \
3669 0 \
3670 -s "Verifying peer X.509 certificate... ok"
3671
3672run_test "DTLS client auth: optional, client has no cert" \
3673 "$P_SRV dtls=1 auth_mode=optional" \
3674 "$P_CLI dtls=1 crt_file=none key_file=none" \
3675 0 \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01003676 -s "! Certificate was missing"
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003677
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01003678run_test "DTLS client auth: none, client has no cert" \
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003679 "$P_SRV dtls=1 auth_mode=none" \
3680 "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
3681 0 \
3682 -c "skip write certificate$" \
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +01003683 -s "! Certificate verification was skipped"
Manuel Pégourié-Gonnard08a1d4b2014-09-26 10:35:50 +02003684
Manuel Pégourié-Gonnard0a885742015-08-04 12:08:35 +02003685run_test "DTLS wrong PSK: badmac alert" \
3686 "$P_SRV dtls=1 psk=abc123 force_ciphersuite=TLS-PSK-WITH-AES-128-GCM-SHA256" \
3687 "$P_CLI dtls=1 psk=abc124" \
3688 1 \
3689 -s "SSL - Verification of the message MAC failed" \
3690 -c "SSL - A fatal alert message was received from our peer"
3691
Manuel Pégourié-Gonnard502bf302014-08-20 13:12:58 +02003692# Tests for receiving fragmented handshake messages with DTLS
3693
3694requires_gnutls
3695run_test "DTLS reassembly: no fragmentation (gnutls server)" \
3696 "$G_SRV -u --mtu 2048 -a" \
3697 "$P_CLI dtls=1 debug_level=2" \
3698 0 \
3699 -C "found fragmented DTLS handshake message" \
3700 -C "error"
3701
3702requires_gnutls
3703run_test "DTLS reassembly: some fragmentation (gnutls server)" \
3704 "$G_SRV -u --mtu 512" \
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: more fragmentation (gnutls server)" \
3712 "$G_SRV -u --mtu 128" \
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, nbio (gnutls server)" \
3720 "$G_SRV -u --mtu 128" \
3721 "$P_CLI dtls=1 nbio=2 debug_level=2" \
3722 0 \
3723 -c "found fragmented DTLS handshake message" \
3724 -C "error"
3725
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003726requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003727run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
3728 "$G_SRV -u --mtu 256" \
3729 "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
3730 0 \
3731 -c "found fragmented DTLS handshake message" \
3732 -c "client hello, adding renegotiation extension" \
3733 -c "found renegotiation extension" \
3734 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003735 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003736 -C "error" \
3737 -s "Extra-header:"
3738
3739requires_gnutls
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003740run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
3741 "$G_SRV -u --mtu 256" \
3742 "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
3743 0 \
3744 -c "found fragmented DTLS handshake message" \
3745 -c "client hello, adding renegotiation extension" \
3746 -c "found renegotiation extension" \
3747 -c "=> renegotiate" \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02003748 -C "mbedtls_ssl_handshake returned" \
Manuel Pégourié-Gonnard0c4cbc72014-09-02 14:47:31 +02003749 -C "error" \
3750 -s "Extra-header:"
3751
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02003752run_test "DTLS reassembly: no fragmentation (openssl server)" \
3753 "$O_SRV -dtls1 -mtu 2048" \
3754 "$P_CLI dtls=1 debug_level=2" \
3755 0 \
3756 -C "found fragmented DTLS handshake message" \
3757 -C "error"
3758
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003759run_test "DTLS reassembly: some fragmentation (openssl server)" \
3760 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02003761 "$P_CLI dtls=1 debug_level=2" \
3762 0 \
3763 -c "found fragmented DTLS handshake message" \
3764 -C "error"
3765
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003766run_test "DTLS reassembly: more fragmentation (openssl server)" \
Manuel Pégourié-Gonnard64dffc52014-09-02 13:39:16 +02003767 "$O_SRV -dtls1 -mtu 256" \
3768 "$P_CLI dtls=1 debug_level=2" \
3769 0 \
3770 -c "found fragmented DTLS handshake message" \
3771 -C "error"
3772
3773run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
3774 "$O_SRV -dtls1 -mtu 256" \
3775 "$P_CLI dtls=1 nbio=2 debug_level=2" \
3776 0 \
3777 -c "found fragmented DTLS handshake message" \
3778 -C "error"
Manuel Pégourié-Gonnarda7756172014-08-31 18:37:01 +02003779
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02003780# Tests for specific things with "unreliable" UDP connection
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02003781
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003782not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003783run_test "DTLS proxy: reference" \
Manuel Pégourié-Gonnardbe9eb872014-09-05 17:45:19 +02003784 -p "$P_PXY" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003785 "$P_SRV dtls=1 debug_level=2" \
3786 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003787 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003788 -C "replayed record" \
3789 -S "replayed record" \
3790 -C "record from another epoch" \
3791 -S "record from another epoch" \
3792 -C "discarding invalid record" \
3793 -S "discarding invalid record" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003794 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02003795 -s "Extra-header:" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003796 -c "HTTP/1.0 200 OK"
3797
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003798not_with_valgrind # spurious resend due to timeout
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02003799run_test "DTLS proxy: duplicate every packet" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003800 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003801 "$P_SRV dtls=1 debug_level=2" \
3802 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard990f9e42014-09-06 12:27:02 +02003803 0 \
Manuel Pégourié-Gonnardb47368a2014-09-24 13:29:58 +02003804 -c "replayed record" \
3805 -s "replayed record" \
Hanno Becker52c6dc62017-05-26 16:07:36 +01003806 -c "record from another epoch" \
3807 -s "record from another epoch" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003808 -S "resend" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02003809 -s "Extra-header:" \
3810 -c "HTTP/1.0 200 OK"
3811
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02003812run_test "DTLS proxy: duplicate every packet, server anti-replay off" \
3813 -p "$P_PXY duplicate=1" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003814 "$P_SRV dtls=1 debug_level=2 anti_replay=0" \
3815 "$P_CLI dtls=1 debug_level=2" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02003816 0 \
3817 -c "replayed record" \
3818 -S "replayed record" \
Hanno Becker52c6dc62017-05-26 16:07:36 +01003819 -c "record from another epoch" \
3820 -s "record from another epoch" \
Manuel Pégourié-Gonnard76fe9e42014-09-24 15:17:31 +02003821 -c "resend" \
3822 -s "resend" \
Manuel Pégourié-Gonnard27393132014-09-24 14:41:11 +02003823 -s "Extra-header:" \
3824 -c "HTTP/1.0 200 OK"
3825
Hanno Becker72a4f032017-11-15 16:39:20 +00003826run_test "DTLS proxy: multiple records in same datagram" \
Hanno Becker8d832182018-03-15 10:14:19 +00003827 -p "$P_PXY pack=50" \
Hanno Becker72a4f032017-11-15 16:39:20 +00003828 "$P_SRV dtls=1 debug_level=2" \
3829 "$P_CLI dtls=1 debug_level=2" \
3830 0 \
3831 -c "next record in same datagram" \
3832 -s "next record in same datagram"
3833
3834run_test "DTLS proxy: multiple records in same datagram, duplicate every packet" \
Hanno Becker8d832182018-03-15 10:14:19 +00003835 -p "$P_PXY pack=50 duplicate=1" \
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
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003842run_test "DTLS proxy: inject invalid AD record, default badmac_limit" \
Manuel Pégourié-Gonnard63eca932014-09-08 16:39:08 +02003843 -p "$P_PXY bad_ad=1" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003844 "$P_SRV dtls=1 debug_level=1" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003845 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003846 0 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003847 -c "discarding invalid record (mac)" \
3848 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003849 -s "Extra-header:" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003850 -c "HTTP/1.0 200 OK" \
3851 -S "too many records with bad MAC" \
3852 -S "Verification of the message MAC failed"
3853
3854run_test "DTLS proxy: inject invalid AD record, badmac_limit 1" \
3855 -p "$P_PXY bad_ad=1" \
3856 "$P_SRV dtls=1 debug_level=1 badmac_limit=1" \
3857 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
3858 1 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003859 -C "discarding invalid record (mac)" \
3860 -S "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003861 -S "Extra-header:" \
3862 -C "HTTP/1.0 200 OK" \
3863 -s "too many records with bad MAC" \
3864 -s "Verification of the message MAC failed"
3865
3866run_test "DTLS proxy: inject invalid AD record, badmac_limit 2" \
3867 -p "$P_PXY bad_ad=1" \
3868 "$P_SRV dtls=1 debug_level=1 badmac_limit=2" \
3869 "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
3870 0 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003871 -c "discarding invalid record (mac)" \
3872 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003873 -s "Extra-header:" \
3874 -c "HTTP/1.0 200 OK" \
3875 -S "too many records with bad MAC" \
3876 -S "Verification of the message MAC failed"
3877
3878run_test "DTLS proxy: inject invalid AD record, badmac_limit 2, exchanges 2"\
3879 -p "$P_PXY bad_ad=1" \
3880 "$P_SRV dtls=1 debug_level=1 badmac_limit=2 exchanges=2" \
3881 "$P_CLI dtls=1 debug_level=1 read_timeout=100 exchanges=2" \
3882 1 \
Manuel Pégourié-Gonnard74a13782014-10-14 22:34:08 +02003883 -c "discarding invalid record (mac)" \
3884 -s "discarding invalid record (mac)" \
Manuel Pégourié-Gonnarde698f592014-10-14 19:36:36 +02003885 -s "Extra-header:" \
3886 -c "HTTP/1.0 200 OK" \
3887 -s "too many records with bad MAC" \
3888 -s "Verification of the message MAC failed"
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003889
3890run_test "DTLS proxy: delay ChangeCipherSpec" \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003891 -p "$P_PXY delay_ccs=1" \
3892 "$P_SRV dtls=1 debug_level=1" \
3893 "$P_CLI dtls=1 debug_level=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003894 0 \
Manuel Pégourié-Gonnard246c13a2014-09-24 13:56:09 +02003895 -c "record from another epoch" \
3896 -s "record from another epoch" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003897 -s "Extra-header:" \
3898 -c "HTTP/1.0 200 OK"
3899
Manuel Pégourié-Gonnard7a66cbc2014-09-26 16:31:46 +02003900# Tests for "randomly unreliable connection": try a variety of flows and peers
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003901
Janos Follath74537a62016-09-02 13:45:28 +01003902client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003903run_test "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003904 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003905 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
3906 psk=abc123" \
3907 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003908 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
3909 0 \
3910 -s "Extra-header:" \
3911 -c "HTTP/1.0 200 OK"
3912
Janos Follath74537a62016-09-02 13:45:28 +01003913client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003914run_test "DTLS proxy: 3d, \"short\" RSA handshake" \
3915 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003916 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
3917 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003918 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3919 0 \
3920 -s "Extra-header:" \
3921 -c "HTTP/1.0 200 OK"
3922
Janos Follath74537a62016-09-02 13:45:28 +01003923client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003924run_test "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
3925 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003926 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
3927 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003928 0 \
3929 -s "Extra-header:" \
3930 -c "HTTP/1.0 200 OK"
3931
Janos Follath74537a62016-09-02 13:45:28 +01003932client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003933run_test "DTLS proxy: 3d, FS, client auth" \
3934 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003935 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=required" \
3936 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003937 0 \
3938 -s "Extra-header:" \
3939 -c "HTTP/1.0 200 OK"
3940
Janos Follath74537a62016-09-02 13:45:28 +01003941client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003942run_test "DTLS proxy: 3d, FS, ticket" \
3943 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003944 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=none" \
3945 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003946 0 \
3947 -s "Extra-header:" \
3948 -c "HTTP/1.0 200 OK"
3949
Janos Follath74537a62016-09-02 13:45:28 +01003950client_needs_more_time 2
Manuel Pégourié-Gonnard18e519a2014-09-24 19:09:17 +02003951run_test "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
3952 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003953 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=required" \
3954 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
Manuel Pégourié-Gonnard825a49e2014-09-23 11:00:37 +02003955 0 \
3956 -s "Extra-header:" \
3957 -c "HTTP/1.0 200 OK"
3958
Janos Follath74537a62016-09-02 13:45:28 +01003959client_needs_more_time 2
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02003960run_test "DTLS proxy: 3d, max handshake, nbio" \
3961 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02003962 "$P_SRV dtls=1 hs_timeout=250-10000 nbio=2 tickets=1 \
3963 auth_mode=required" \
3964 "$P_CLI dtls=1 hs_timeout=250-10000 nbio=2 tickets=1" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02003965 0 \
3966 -s "Extra-header:" \
3967 -c "HTTP/1.0 200 OK"
3968
Janos Follath74537a62016-09-02 13:45:28 +01003969client_needs_more_time 4
Manuel Pégourié-Gonnard7a26d732014-10-02 14:50:46 +02003970run_test "DTLS proxy: 3d, min handshake, resumption" \
3971 -p "$P_PXY drop=5 delay=5 duplicate=5" \
3972 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
3973 psk=abc123 debug_level=3" \
3974 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
3975 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
3976 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
3977 0 \
3978 -s "a session has been resumed" \
3979 -c "a session has been resumed" \
3980 -s "Extra-header:" \
3981 -c "HTTP/1.0 200 OK"
3982
Janos Follath74537a62016-09-02 13:45:28 +01003983client_needs_more_time 4
Manuel Pégourié-Gonnard85beb302014-10-02 17:59:19 +02003984run_test "DTLS proxy: 3d, min handshake, resumption, nbio" \
3985 -p "$P_PXY drop=5 delay=5 duplicate=5" \
3986 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
3987 psk=abc123 debug_level=3 nbio=2" \
3988 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
3989 debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
3990 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
3991 0 \
3992 -s "a session has been resumed" \
3993 -c "a session has been resumed" \
3994 -s "Extra-header:" \
3995 -c "HTTP/1.0 200 OK"
3996
Janos Follath74537a62016-09-02 13:45:28 +01003997client_needs_more_time 4
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02003998run_test "DTLS proxy: 3d, min handshake, client-initiated renego" \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02003999 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02004000 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
4001 psk=abc123 renegotiation=1 debug_level=2" \
4002 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
4003 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard1b753f12014-09-25 16:09:36 +02004004 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4005 0 \
4006 -c "=> renegotiate" \
4007 -s "=> renegotiate" \
4008 -s "Extra-header:" \
4009 -c "HTTP/1.0 200 OK"
4010
Janos Follath74537a62016-09-02 13:45:28 +01004011client_needs_more_time 4
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004012run_test "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
4013 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnard37a4de22014-10-01 16:38:03 +02004014 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
4015 psk=abc123 renegotiation=1 debug_level=2" \
4016 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
4017 renegotiate=1 debug_level=2 \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004018 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4019 0 \
4020 -c "=> renegotiate" \
4021 -s "=> renegotiate" \
4022 -s "Extra-header:" \
4023 -c "HTTP/1.0 200 OK"
4024
Janos Follath74537a62016-09-02 13:45:28 +01004025client_needs_more_time 4
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004026run_test "DTLS proxy: 3d, min handshake, server-initiated renego" \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004027 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004028 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004029 psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004030 debug_level=2" \
4031 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004032 renegotiation=1 exchanges=4 debug_level=2 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004033 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4034 0 \
4035 -c "=> renegotiate" \
4036 -s "=> renegotiate" \
4037 -s "Extra-header:" \
4038 -c "HTTP/1.0 200 OK"
4039
Janos Follath74537a62016-09-02 13:45:28 +01004040client_needs_more_time 4
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004041run_test "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004042 -p "$P_PXY drop=5 delay=5 duplicate=5" \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004043 "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004044 psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004045 debug_level=2 nbio=2" \
4046 "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
Manuel Pégourié-Gonnarda6ace042014-10-15 12:44:41 +02004047 renegotiation=1 exchanges=4 debug_level=2 nbio=2 \
Manuel Pégourié-Gonnardba958b82014-10-09 16:13:44 +02004048 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
4049 0 \
4050 -c "=> renegotiate" \
4051 -s "=> renegotiate" \
4052 -s "Extra-header:" \
4053 -c "HTTP/1.0 200 OK"
4054
Janos Follath74537a62016-09-02 13:45:28 +01004055client_needs_more_time 6
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004056not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004057run_test "DTLS proxy: 3d, openssl server" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02004058 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
4059 "$O_SRV -dtls1 -mtu 2048" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00004060 "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02004061 0 \
Manuel Pégourié-Gonnardd0fd1da2014-09-25 17:00:27 +02004062 -c "HTTP/1.0 200 OK"
4063
Janos Follath74537a62016-09-02 13:45:28 +01004064client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004065not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004066run_test "DTLS proxy: 3d, openssl server, fragmentation" \
4067 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
4068 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00004069 "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004070 0 \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004071 -c "HTTP/1.0 200 OK"
4072
Janos Follath74537a62016-09-02 13:45:28 +01004073client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004074not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004075run_test "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
4076 -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
4077 "$O_SRV -dtls1 -mtu 768" \
Manuel Pégourié-Gonnard8fe411e2015-03-09 16:09:53 +00004078 "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2 tickets=0" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004079 0 \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004080 -c "HTTP/1.0 200 OK"
4081
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00004082requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01004083client_needs_more_time 6
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004084not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004085run_test "DTLS proxy: 3d, gnutls server" \
4086 -p "$P_PXY drop=5 delay=5 duplicate=5" \
4087 "$G_SRV -u --mtu 2048 -a" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02004088 "$P_CLI dtls=1 hs_timeout=250-60000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004089 0 \
4090 -s "Extra-header:" \
4091 -c "Extra-header:"
4092
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00004093requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01004094client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004095not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004096run_test "DTLS proxy: 3d, gnutls server, fragmentation" \
4097 -p "$P_PXY drop=5 delay=5 duplicate=5" \
4098 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02004099 "$P_CLI dtls=1 hs_timeout=250-60000" \
Manuel Pégourié-Gonnard9590e0a2014-09-26 16:27:59 +02004100 0 \
4101 -s "Extra-header:" \
4102 -c "Extra-header:"
4103
Manuel Pégourié-Gonnard96999962015-02-17 16:02:37 +00004104requires_gnutls
Janos Follath74537a62016-09-02 13:45:28 +01004105client_needs_more_time 8
Manuel Pégourié-Gonnardd68434e2015-08-31 12:48:22 +02004106not_with_valgrind # risk of non-mbedtls peer timing out
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004107run_test "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
4108 -p "$P_PXY drop=5 delay=5 duplicate=5" \
4109 "$G_SRV -u --mtu 512" \
Manuel Pégourié-Gonnardf1384472014-10-14 22:57:46 +02004110 "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2" \
Manuel Pégourié-Gonnard6093d812014-09-29 17:52:57 +02004111 0 \
4112 -s "Extra-header:" \
4113 -c "Extra-header:"
4114
Manuel Pégourié-Gonnard8520dac2014-02-21 12:12:23 +01004115# Final report
4116
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004117echo "------------------------------------------------------------------------"
4118
4119if [ $FAILS = 0 ]; then
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +01004120 printf "PASSED"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004121else
Manuel Pégourié-Gonnardf46f1282014-12-11 11:51:28 +01004122 printf "FAILED"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004123fi
Manuel Pégourié-Gonnard72e51ee2014-08-31 10:22:11 +02004124PASSES=$(( $TESTS - $FAILS ))
Manuel Pégourié-Gonnard6f4fbbb2014-08-14 14:31:29 +02004125echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
Manuel Pégourié-Gonnard33a752e2014-02-21 09:47:37 +01004126
4127exit $FAILS