1#!/bin/sh
2
3# ssl-opt.sh
4#
5# Copyright The Mbed TLS Contributors
6# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7#
8# Purpose
9#
10# Executes tests to prove various TLS/SSL options and extensions.
11#
12# The goal is not to cover every ciphersuite/version, but instead to cover
13# specific options (max fragment length, truncated hmac, etc) or procedures
14# (session resumption from cache or ticket, renego, etc).
15#
16# The tests assume a build with default options, with exceptions expressed
17# with a dependency.  The tests focus on functionality and do not consider
18# performance.
19#
20
21set -u
22
23# Limit the size of each log to 10 GiB, in case of failures with this script
24# where it may output seemingly unlimited length error logs.
25ulimit -f 20971520
26
27ORIGINAL_PWD=$PWD
28if ! cd "$(dirname "$0")"; then
29    exit 125
30fi
31
32# default values, can be overridden by the environment
33: ${P_SRV:=../programs/ssl/ssl_server2}
34: ${P_CLI:=../programs/ssl/ssl_client2}
35: ${P_PXY:=../programs/test/udp_proxy}
36: ${P_QUERY:=../programs/test/query_compile_time_config}
37: ${OPENSSL:=openssl}
38: ${GNUTLS_CLI:=gnutls-cli}
39: ${GNUTLS_SERV:=gnutls-serv}
40: ${PERL:=perl}
41
42# The OPENSSL variable used to be OPENSSL_CMD for historical reasons.
43# To help the migration, error out if the old variable is set,
44# but only if it has a different value than the new one.
45if [ "${OPENSSL_CMD+set}" = set ]; then
46    # the variable is set, we can now check its value
47    if [ "$OPENSSL_CMD" != "$OPENSSL" ]; then
48        echo "Please use OPENSSL instead of OPENSSL_CMD." >&2
49        exit 125
50    fi
51fi
52
53guess_config_name() {
54    if git diff --quiet ../include/mbedtls/mbedtls_config.h 2>/dev/null; then
55        echo "default"
56    else
57        echo "unknown"
58    fi
59}
60: ${MBEDTLS_TEST_OUTCOME_FILE=}
61: ${MBEDTLS_TEST_CONFIGURATION:="$(guess_config_name)"}
62: ${MBEDTLS_TEST_PLATFORM:="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
63: ${EARLY_DATA_INPUT:=data_files/tls13_early_data.txt}
64
65O_SRV="$OPENSSL s_server -www -cert data_files/server5.crt -key data_files/server5.key"
66O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL s_client"
67G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
68G_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_CLI --x509cafile data_files/test-ca_cat12.crt"
69TCP_CLIENT="$PERL scripts/tcp_client.pl"
70
71# alternative versions of OpenSSL and GnuTLS (no default path)
72
73if [ -n "${OPENSSL_NEXT:-}" ]; then
74    O_NEXT_SRV="$OPENSSL_NEXT s_server -www -cert data_files/server5.crt -key data_files/server5.key"
75    O_NEXT_SRV_EARLY_DATA="$OPENSSL_NEXT s_server -early_data -cert data_files/server5.crt -key data_files/server5.key"
76    O_NEXT_SRV_NO_CERT="$OPENSSL_NEXT s_server -www "
77    O_NEXT_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client -CAfile data_files/test-ca_cat12.crt"
78    O_NEXT_CLI_NO_CERT="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client"
79else
80    O_NEXT_SRV=false
81    O_NEXT_SRV_NO_CERT=false
82    O_NEXT_SRV_EARLY_DATA=false
83    O_NEXT_CLI_NO_CERT=false
84    O_NEXT_CLI=false
85fi
86
87if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
88    G_NEXT_SRV="$GNUTLS_NEXT_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
89    G_NEXT_SRV_NO_CERT="$GNUTLS_NEXT_SERV"
90else
91    G_NEXT_SRV=false
92    G_NEXT_SRV_NO_CERT=false
93fi
94
95if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
96    G_NEXT_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_NEXT_CLI --x509cafile data_files/test-ca_cat12.crt"
97    G_NEXT_CLI_NO_CERT="echo 'GET / HTTP/1.0' | $GNUTLS_NEXT_CLI"
98else
99    G_NEXT_CLI=false
100    G_NEXT_CLI_NO_CERT=false
101fi
102
103TESTS=0
104FAILS=0
105SKIPS=0
106
107CONFIG_H='../include/mbedtls/mbedtls_config.h'
108
109MEMCHECK=0
110FILTER='.*'
111EXCLUDE='^$'
112
113SHOW_TEST_NUMBER=0
114LIST_TESTS=0
115RUN_TEST_NUMBER=''
116RUN_TEST_SUITE=''
117
118PRESERVE_LOGS=0
119
120# Pick a "unique" server port in the range 10000-19999, and a proxy
121# port which is this plus 10000. Each port number may be independently
122# overridden by a command line option.
123SRV_PORT=$(($$ % 10000 + 10000))
124PXY_PORT=$((SRV_PORT + 10000))
125
126print_usage() {
127    echo "Usage: $0 [options]"
128    printf "  -h|--help\tPrint this help.\n"
129    printf "  -m|--memcheck\tCheck memory leaks and errors.\n"
130    printf "  -f|--filter\tOnly matching tests are executed (substring or BRE)\n"
131    printf "  -e|--exclude\tMatching tests are excluded (substring or BRE)\n"
132    printf "  -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
133    printf "  -s|--show-numbers\tShow test numbers in front of test names\n"
134    printf "  -p|--preserve-logs\tPreserve logs of successful tests as well\n"
135    printf "     --list-test-cases\tList all potential test cases (No Execution)\n"
136    printf "     --outcome-file\tFile where test outcomes are written\n"
137    printf "                \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n"
138    printf "     --port     \tTCP/UDP port (default: randomish 1xxxx)\n"
139    printf "     --proxy-port\tTCP/UDP proxy port (default: randomish 2xxxx)\n"
140    printf "     --seed     \tInteger seed value to use for this test run\n"
141    printf "     --test-suite\tOnly matching test suites are executed\n"
142    printf "                 \t(comma-separated, e.g. 'ssl-opt,tls13-compat')\n\n"
143}
144
145get_options() {
146    while [ $# -gt 0 ]; do
147        case "$1" in
148            -f|--filter)
149                shift; FILTER=$1
150                ;;
151            -e|--exclude)
152                shift; EXCLUDE=$1
153                ;;
154            -m|--memcheck)
155                MEMCHECK=1
156                ;;
157            -n|--number)
158                shift; RUN_TEST_NUMBER=$1
159                ;;
160            -s|--show-numbers)
161                SHOW_TEST_NUMBER=1
162                ;;
163            -l|--list-test-cases)
164                LIST_TESTS=1
165                ;;
166            -p|--preserve-logs)
167                PRESERVE_LOGS=1
168                ;;
169            --outcome-file)
170                shift; MBEDTLS_TEST_OUTCOME_FILE=$1
171                ;;
172            --port)
173                shift; SRV_PORT=$1
174                ;;
175            --proxy-port)
176                shift; PXY_PORT=$1
177                ;;
178            --seed)
179                shift; SEED="$1"
180                ;;
181            --test-suite)
182                shift; RUN_TEST_SUITE="$1"
183                ;;
184            -h|--help)
185                print_usage
186                exit 0
187                ;;
188            *)
189                echo "Unknown argument: '$1'"
190                print_usage
191                exit 1
192                ;;
193        esac
194        shift
195    done
196}
197
198get_options "$@"
199
200# Read boolean configuration options from mbedtls_config.h for easy and quick
201# testing. Skip non-boolean options (with something other than spaces
202# and a comment after "#define SYMBOL"). The variable contains a
203# space-separated list of symbols.
204if [ "$LIST_TESTS" -eq 0 ];then
205    CONFIGS_ENABLED=" $(echo `$P_QUERY -l` )"
206else
207    P_QUERY=":"
208    CONFIGS_ENABLED=""
209fi
210# Skip next test; use this macro to skip tests which are legitimate
211# in theory and expected to be re-introduced at some point, but
212# aren't expected to succeed at the moment due to problems outside
213# our control (such as bugs in other TLS implementations).
214skip_next_test() {
215    SKIP_NEXT="YES"
216}
217
218# Check if the required configuration ($1) is enabled
219is_config_enabled()
220{
221    case $CONFIGS_ENABLED in
222        *" $1"[\ =]*) return 0;;
223        *) return 1;;
224    esac
225}
226
227# skip next test if the flag is not enabled in mbedtls_config.h
228requires_config_enabled() {
229    case $CONFIGS_ENABLED in
230        *" $1"[\ =]*) :;;
231        *) SKIP_NEXT="YES";;
232    esac
233}
234
235# skip next test if the flag is enabled in mbedtls_config.h
236requires_config_disabled() {
237    case $CONFIGS_ENABLED in
238        *" $1"[\ =]*) SKIP_NEXT="YES";;
239    esac
240}
241
242requires_all_configs_enabled() {
243    if ! $P_QUERY -all $* 2>&1 > /dev/null
244    then
245        SKIP_NEXT="YES"
246    fi
247}
248
249requires_all_configs_disabled() {
250    if $P_QUERY -any $* 2>&1 > /dev/null
251    then
252        SKIP_NEXT="YES"
253    fi
254}
255
256requires_any_configs_enabled() {
257    if ! $P_QUERY -any $* 2>&1 > /dev/null
258    then
259        SKIP_NEXT="YES"
260    fi
261}
262
263requires_any_configs_disabled() {
264    if $P_QUERY -all $* 2>&1 > /dev/null
265    then
266        SKIP_NEXT="YES"
267    fi
268}
269
270TLS1_2_KEY_EXCHANGES_WITH_CERT="MBEDTLS_KEY_EXCHANGE_RSA_ENABLED \
271                                MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED \
272                                MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED \
273                                MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED \
274                                MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED \
275                                MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED \
276                                MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED"
277
278TLS1_2_KEY_EXCHANGES_WITH_ECDSA_CERT="MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED \
279                                      MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED"
280
281TLS1_2_KEY_EXCHANGES_WITH_CERT_WO_ECDH="MBEDTLS_KEY_EXCHANGE_RSA_ENABLED \
282                                       MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED \
283                                       MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED \
284                                       MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED \
285                                       MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED"
286
287requires_key_exchange_with_cert_in_tls12_or_tls13_enabled() {
288    if $P_QUERY -all MBEDTLS_SSL_PROTO_TLS1_2
289    then
290        requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
291    elif ! $P_QUERY -all MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
292    then
293        SKIP_NEXT="YES"
294    fi
295}
296
297get_config_value_or_default() {
298    # This function uses the query_config command line option to query the
299    # required Mbed TLS compile time configuration from the ssl_server2
300    # program. The command will always return a success value if the
301    # configuration is defined and the value will be printed to stdout.
302    #
303    # Note that if the configuration is not defined or is defined to nothing,
304    # the output of this function will be an empty string.
305    if [ "$LIST_TESTS" -eq 0 ];then
306        ${P_SRV} "query_config=${1}"
307    else
308        echo "1"
309    fi
310
311}
312
313requires_config_value_at_least() {
314    VAL="$( get_config_value_or_default "$1" )"
315    if [ -z "$VAL" ]; then
316        # Should never happen
317        echo "Mbed TLS configuration $1 is not defined"
318        exit 1
319    elif [ "$VAL" -lt "$2" ]; then
320       SKIP_NEXT="YES"
321    fi
322}
323
324requires_config_value_at_most() {
325    VAL=$( get_config_value_or_default "$1" )
326    if [ -z "$VAL" ]; then
327        # Should never happen
328        echo "Mbed TLS configuration $1 is not defined"
329        exit 1
330    elif [ "$VAL" -gt "$2" ]; then
331       SKIP_NEXT="YES"
332    fi
333}
334
335requires_config_value_equals() {
336    VAL=$( get_config_value_or_default "$1" )
337    if [ -z "$VAL" ]; then
338        # Should never happen
339        echo "Mbed TLS configuration $1 is not defined"
340        exit 1
341    elif [ "$VAL" -ne "$2" ]; then
342       SKIP_NEXT="YES"
343    fi
344}
345
346# Require Mbed TLS to support the given protocol version.
347#
348# Inputs:
349# * $1: protocol version in mbedtls syntax (argument to force_version=)
350requires_protocol_version() {
351    # Support for DTLS is detected separately in detect_dtls().
352    case "$1" in
353        tls12|dtls12) requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2;;
354        tls13|dtls13) requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3;;
355        *) echo "Unknown required protocol version: $1"; exit 1;;
356    esac
357}
358
359# Space-separated list of ciphersuites supported by this build of
360# Mbed TLS.
361P_CIPHERSUITES=""
362if [ "$LIST_TESTS" -eq 0 ]; then
363    P_CIPHERSUITES=" $($P_CLI help_ciphersuites 2>/dev/null |
364                       grep 'TLS-\|TLS1-3' |
365                       tr -s ' \n' ' ')"
366
367    if [ -z "${P_CIPHERSUITES# }" ]; then
368        echo >&2 "$0: fatal error: no cipher suites found!"
369        exit 125
370    fi
371fi
372
373requires_ciphersuite_enabled() {
374    case $P_CIPHERSUITES in
375        *" $1 "*) :;;
376        *) SKIP_NEXT="YES";;
377    esac
378}
379
380requires_cipher_enabled() {
381    KEY_TYPE=$1
382    MODE=${2:-}
383    if is_config_enabled MBEDTLS_USE_PSA_CRYPTO; then
384        case "$KEY_TYPE" in
385            CHACHA20)
386                requires_config_enabled PSA_WANT_ALG_CHACHA20_POLY1305
387                requires_config_enabled PSA_WANT_KEY_TYPE_CHACHA20
388                ;;
389            *)
390                requires_config_enabled PSA_WANT_ALG_${MODE}
391                requires_config_enabled PSA_WANT_KEY_TYPE_${KEY_TYPE}
392                ;;
393        esac
394    else
395        case "$KEY_TYPE" in
396            CHACHA20)
397                requires_config_enabled MBEDTLS_CHACHA20_C
398                requires_config_enabled MBEDTLS_CHACHAPOLY_C
399                ;;
400            *)
401                requires_config_enabled MBEDTLS_${MODE}_C
402                requires_config_enabled MBEDTLS_${KEY_TYPE}_C
403                ;;
404        esac
405    fi
406}
407
408# Automatically detect required features based on command line parameters.
409# Parameters are:
410# - $1 = command line (call to a TLS client or server program)
411# - $2 = client/server
412# - $3 = TLS version (TLS12 or TLS13)
413# - $4 = Use an external tool without ECDH support
414# - $5 = run test options
415detect_required_features() {
416    CMD_LINE=$1
417    ROLE=$2
418    TLS_VERSION=$3
419    EXT_WO_ECDH=$4
420    TEST_OPTIONS=${5:-}
421
422    case "$CMD_LINE" in
423        *\ force_version=*)
424            tmp="${CMD_LINE##*\ force_version=}"
425            tmp="${tmp%%[!-0-9A-Z_a-z]*}"
426            requires_protocol_version "$tmp";;
427    esac
428
429    case "$CMD_LINE" in
430        *\ force_ciphersuite=*)
431            tmp="${CMD_LINE##*\ force_ciphersuite=}"
432            tmp="${tmp%%[!-0-9A-Z_a-z]*}"
433            requires_ciphersuite_enabled "$tmp";;
434    esac
435
436    case " $CMD_LINE " in
437        *[-_\ =]tickets=[^0]*)
438            requires_config_enabled MBEDTLS_SSL_TICKET_C;;
439    esac
440    case " $CMD_LINE " in
441        *[-_\ =]alpn=*)
442            requires_config_enabled MBEDTLS_SSL_ALPN;;
443    esac
444
445    case "$CMD_LINE" in
446        *server5*|\
447        *server7*|\
448        *dir-maxpath*)
449            if [ "$TLS_VERSION" = "TLS13" ]; then
450                # In case of TLS13 the support for ECDSA is enough
451                requires_pk_alg "ECDSA"
452            else
453                # For TLS12 requirements are different between server and client
454                if [ "$ROLE" = "server" ]; then
455                    # If the server uses "server5*" certificates, then an ECDSA based
456                    # key exchange is required. However gnutls also does not
457                    # support ECDH, so this limit the choice to ECDHE-ECDSA
458                    if [ "$EXT_WO_ECDH" = "yes" ]; then
459                        requires_any_configs_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
460                    else
461                        requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_ECDSA_CERT
462                    fi
463                elif [ "$ROLE" = "client" ]; then
464                    # On the client side it is enough to have any certificate
465                    # based authentication together with support for ECDSA.
466                    # Of course the GnuTLS limitation mentioned above applies
467                    # also here.
468                    if [ "$EXT_WO_ECDH" = "yes" ]; then
469                        requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT_WO_ECDH
470                    else
471                        requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
472                    fi
473                    requires_pk_alg "ECDSA"
474                fi
475            fi
476            ;;
477    esac
478
479    case "$CMD_LINE" in
480        *server2*|\
481        *server7*)
482            # server2 and server7 certificates use RSA encryption
483            requires_config_enabled "MBEDTLS_RSA_C"
484    esac
485
486    unset tmp
487}
488
489requires_certificate_authentication () {
490    if [ "$PSK_ONLY" = "YES" ]; then
491        SKIP_NEXT="YES"
492    fi
493}
494
495adapt_cmd_for_psk () {
496    case "$2" in
497        *openssl*) s='-psk abc123 -nocert';;
498        *gnutls-*) s='--pskkey=abc123';;
499        *) s='psk=abc123';;
500    esac
501    eval $1='"$2 $s"'
502    unset s
503}
504
505# maybe_adapt_for_psk [RUN_TEST_OPTION...]
506# If running in a PSK-only build, maybe adapt the test to use a pre-shared key.
507#
508# If not running in a PSK-only build, do nothing.
509# If the test looks like it doesn't use a pre-shared key but can run with a
510# pre-shared key, pass a pre-shared key. If the test looks like it can't run
511# with a pre-shared key, skip it. If the test looks like it's already using
512# a pre-shared key, do nothing.
513#
514# This code does not consider builds with ECDHE-PSK or RSA-PSK.
515#
516# Inputs:
517# * $CLI_CMD, $SRV_CMD, $PXY_CMD: client/server/proxy commands.
518# * $PSK_ONLY: YES if running in a PSK-only build (no asymmetric key exchanges).
519# * "$@": options passed to run_test.
520#
521# Outputs:
522# * $CLI_CMD, $SRV_CMD: may be modified to add PSK-relevant arguments.
523# * $SKIP_NEXT: set to YES if the test can't run with PSK.
524maybe_adapt_for_psk() {
525    if [ "$PSK_ONLY" != "YES" ]; then
526        return
527    fi
528    if [ "$SKIP_NEXT" = "YES" ]; then
529        return
530    fi
531    case "$CLI_CMD $SRV_CMD" in
532        *[-_\ =]psk*|*[-_\ =]PSK*)
533            return;;
534        *force_ciphersuite*)
535            # The test case forces a non-PSK cipher suite. In some cases, a
536            # PSK cipher suite could be substituted, but we're not ready for
537            # that yet.
538            SKIP_NEXT="YES"
539            return;;
540        *\ auth_mode=*|*[-_\ =]crt[_=]*)
541            # The test case involves certificates. PSK won't do.
542            SKIP_NEXT="YES"
543            return;;
544    esac
545    adapt_cmd_for_psk CLI_CMD "$CLI_CMD"
546    adapt_cmd_for_psk SRV_CMD "$SRV_CMD"
547}
548
549case " $CONFIGS_ENABLED " in
550    *\ MBEDTLS_KEY_EXCHANGE_[^P]*) PSK_ONLY="NO";;
551    *\ MBEDTLS_KEY_EXCHANGE_P[^S]*) PSK_ONLY="NO";;
552    *\ MBEDTLS_KEY_EXCHANGE_PS[^K]*) PSK_ONLY="NO";;
553    *\ MBEDTLS_KEY_EXCHANGE_PSK[^_]*) PSK_ONLY="NO";;
554    *\ MBEDTLS_KEY_EXCHANGE_PSK_ENABLED\ *) PSK_ONLY="YES";;
555    *) PSK_ONLY="NO";;
556esac
557
558HAS_ALG_SHA_1="NO"
559HAS_ALG_SHA_224="NO"
560HAS_ALG_SHA_256="NO"
561HAS_ALG_SHA_384="NO"
562HAS_ALG_SHA_512="NO"
563
564check_for_hash_alg()
565{
566    CURR_ALG="INVALID";
567    USE_PSA="NO"
568    if is_config_enabled "MBEDTLS_USE_PSA_CRYPTO"; then
569        USE_PSA="YES";
570    fi
571    if [ $USE_PSA = "YES" ]; then
572        CURR_ALG=PSA_WANT_ALG_${1}
573    else
574        CURR_ALG=MBEDTLS_${1}_C
575        # Remove the second underscore to match MBEDTLS_* naming convention
576        CURR_ALG=$(echo "$CURR_ALG" | sed 's/_//2')
577    fi
578
579    case $CONFIGS_ENABLED in
580        *" $CURR_ALG"[\ =]*)
581            return 0
582        ;;
583        *) :;;
584    esac
585    return 1
586}
587
588populate_enabled_hash_algs()
589{
590    for hash_alg in SHA_1 SHA_224 SHA_256 SHA_384 SHA_512; do
591        if check_for_hash_alg "$hash_alg"; then
592            hash_alg_variable=HAS_ALG_${hash_alg}
593            eval ${hash_alg_variable}=YES
594        fi
595    done
596}
597
598# skip next test if the given hash alg is not supported
599requires_hash_alg() {
600    HASH_DEFINE="Invalid"
601    HAS_HASH_ALG="NO"
602    case $1 in
603        SHA_1):;;
604        SHA_224):;;
605        SHA_256):;;
606        SHA_384):;;
607        SHA_512):;;
608      *)
609            echo "Unsupported hash alg - $1"
610            exit 1
611        ;;
612    esac
613
614    HASH_DEFINE=HAS_ALG_${1}
615    eval "HAS_HASH_ALG=\${${HASH_DEFINE}}"
616    if [ "$HAS_HASH_ALG" = "NO" ]
617    then
618        SKIP_NEXT="YES"
619    fi
620}
621
622# Skip next test if the given pk alg is not enabled
623requires_pk_alg() {
624    case $1 in
625        ECDSA)
626            if is_config_enabled MBEDTLS_USE_PSA_CRYPTO; then
627                requires_config_enabled PSA_WANT_ALG_ECDSA
628            else
629                requires_config_enabled MBEDTLS_ECDSA_C
630            fi
631            ;;
632        *)
633            echo "Unknown/unimplemented case $1 in requires_pk_alg"
634            exit 1
635            ;;
636    esac
637}
638
639# skip next test if OpenSSL doesn't support FALLBACK_SCSV
640requires_openssl_with_fallback_scsv() {
641    if [ -z "${OPENSSL_HAS_FBSCSV:-}" ]; then
642        if $OPENSSL s_client -help 2>&1 | grep fallback_scsv >/dev/null
643        then
644            OPENSSL_HAS_FBSCSV="YES"
645        else
646            OPENSSL_HAS_FBSCSV="NO"
647        fi
648    fi
649    if [ "$OPENSSL_HAS_FBSCSV" = "NO" ]; then
650        SKIP_NEXT="YES"
651    fi
652}
653
654# skip next test if either IN_CONTENT_LEN or MAX_CONTENT_LEN are below a value
655requires_max_content_len() {
656    requires_config_value_at_least "MBEDTLS_SSL_IN_CONTENT_LEN" $1
657    requires_config_value_at_least "MBEDTLS_SSL_OUT_CONTENT_LEN" $1
658}
659
660# skip next test if GnuTLS isn't available
661requires_gnutls() {
662    if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
663        if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null 2>&1; then
664            GNUTLS_AVAILABLE="YES"
665        else
666            GNUTLS_AVAILABLE="NO"
667        fi
668    fi
669    if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
670        SKIP_NEXT="YES"
671    fi
672}
673
674# skip next test if GnuTLS-next isn't available
675requires_gnutls_next() {
676    if [ -z "${GNUTLS_NEXT_AVAILABLE:-}" ]; then
677        if ( which "${GNUTLS_NEXT_CLI:-}" && which "${GNUTLS_NEXT_SERV:-}" ) >/dev/null 2>&1; then
678            GNUTLS_NEXT_AVAILABLE="YES"
679        else
680            GNUTLS_NEXT_AVAILABLE="NO"
681        fi
682    fi
683    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
684        SKIP_NEXT="YES"
685    fi
686}
687
688requires_openssl_next() {
689    if [ -z "${OPENSSL_NEXT_AVAILABLE:-}" ]; then
690        if which "${OPENSSL_NEXT:-}" >/dev/null 2>&1; then
691            OPENSSL_NEXT_AVAILABLE="YES"
692        else
693            OPENSSL_NEXT_AVAILABLE="NO"
694        fi
695    fi
696    if [ "$OPENSSL_NEXT_AVAILABLE" = "NO" ]; then
697        SKIP_NEXT="YES"
698    fi
699}
700
701# skip next test if openssl version is lower than 3.0
702requires_openssl_3_x() {
703    requires_openssl_next
704    if [ "$OPENSSL_NEXT_AVAILABLE" = "NO" ]; then
705        OPENSSL_3_X_AVAILABLE="NO"
706    fi
707    if [ -z "${OPENSSL_3_X_AVAILABLE:-}" ]; then
708        if $OPENSSL_NEXT version 2>&1 | grep "OpenSSL 3." >/dev/null
709        then
710            OPENSSL_3_X_AVAILABLE="YES"
711        else
712            OPENSSL_3_X_AVAILABLE="NO"
713        fi
714    fi
715    if [ "$OPENSSL_3_X_AVAILABLE" = "NO" ]; then
716        SKIP_NEXT="YES"
717    fi
718}
719
720# skip next test if openssl does not support ffdh keys
721requires_openssl_tls1_3_with_ffdh() {
722    requires_openssl_3_x
723}
724
725# skip next test if openssl cannot handle ephemeral key exchange
726requires_openssl_tls1_3_with_compatible_ephemeral() {
727    requires_openssl_next
728
729    if !(is_config_enabled "PSA_WANT_ALG_ECDH"); then
730        requires_openssl_tls1_3_with_ffdh
731    fi
732}
733
734# skip next test if tls1_3 is not available
735requires_openssl_tls1_3() {
736    requires_openssl_next
737    if [ "$OPENSSL_NEXT_AVAILABLE" = "NO" ]; then
738        OPENSSL_TLS1_3_AVAILABLE="NO"
739    fi
740    if [ -z "${OPENSSL_TLS1_3_AVAILABLE:-}" ]; then
741        if $OPENSSL_NEXT s_client -help 2>&1 | grep tls1_3 >/dev/null
742        then
743            OPENSSL_TLS1_3_AVAILABLE="YES"
744        else
745            OPENSSL_TLS1_3_AVAILABLE="NO"
746        fi
747    fi
748    if [ "$OPENSSL_TLS1_3_AVAILABLE" = "NO" ]; then
749        SKIP_NEXT="YES"
750    fi
751}
752
753# skip next test if tls1_3 is not available
754requires_gnutls_tls1_3() {
755    requires_gnutls_next
756    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
757        GNUTLS_TLS1_3_AVAILABLE="NO"
758    fi
759    if [ -z "${GNUTLS_TLS1_3_AVAILABLE:-}" ]; then
760        if $GNUTLS_NEXT_CLI -l 2>&1 | grep VERS-TLS1.3 >/dev/null
761        then
762            GNUTLS_TLS1_3_AVAILABLE="YES"
763        else
764            GNUTLS_TLS1_3_AVAILABLE="NO"
765        fi
766    fi
767    if [ "$GNUTLS_TLS1_3_AVAILABLE" = "NO" ]; then
768        SKIP_NEXT="YES"
769    fi
770}
771
772# Check %NO_TICKETS option
773requires_gnutls_next_no_ticket() {
774    requires_gnutls_next
775    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
776        GNUTLS_NO_TICKETS_AVAILABLE="NO"
777    fi
778    if [ -z "${GNUTLS_NO_TICKETS_AVAILABLE:-}" ]; then
779        if $GNUTLS_NEXT_CLI --priority-list 2>&1 | grep NO_TICKETS >/dev/null
780        then
781            GNUTLS_NO_TICKETS_AVAILABLE="YES"
782        else
783            GNUTLS_NO_TICKETS_AVAILABLE="NO"
784        fi
785    fi
786    if [ "$GNUTLS_NO_TICKETS_AVAILABLE" = "NO" ]; then
787        SKIP_NEXT="YES"
788    fi
789}
790
791# Check %DISABLE_TLS13_COMPAT_MODE option
792requires_gnutls_next_disable_tls13_compat() {
793    requires_gnutls_next
794    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
795        GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="NO"
796    fi
797    if [ -z "${GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE:-}" ]; then
798        if $GNUTLS_NEXT_CLI --priority-list 2>&1 | grep DISABLE_TLS13_COMPAT_MODE >/dev/null
799        then
800            GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="YES"
801        else
802            GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="NO"
803        fi
804    fi
805    if [ "$GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE" = "NO" ]; then
806        SKIP_NEXT="YES"
807    fi
808}
809
810# skip next test if GnuTLS does not support the record size limit extension
811requires_gnutls_record_size_limit() {
812    requires_gnutls_next
813    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
814        GNUTLS_RECORD_SIZE_LIMIT_AVAILABLE="NO"
815    else
816        GNUTLS_RECORD_SIZE_LIMIT_AVAILABLE="YES"
817    fi
818    if [ "$GNUTLS_RECORD_SIZE_LIMIT_AVAILABLE" = "NO" ]; then
819        SKIP_NEXT="YES"
820    fi
821}
822
823# skip next test if IPv6 isn't available on this host
824requires_ipv6() {
825    if [ -z "${HAS_IPV6:-}" ]; then
826        $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
827        SRV_PID=$!
828        sleep 1
829        kill $SRV_PID >/dev/null 2>&1
830        if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
831            HAS_IPV6="NO"
832        else
833            HAS_IPV6="YES"
834        fi
835        rm -r $SRV_OUT
836    fi
837
838    if [ "$HAS_IPV6" = "NO" ]; then
839        SKIP_NEXT="YES"
840    fi
841}
842
843# skip next test if it's i686 or uname is not available
844requires_not_i686() {
845    if [ -z "${IS_I686:-}" ]; then
846        IS_I686="YES"
847        if which "uname" >/dev/null 2>&1; then
848            if [ -z "$(uname -a | grep i686)" ]; then
849                IS_I686="NO"
850            fi
851        fi
852    fi
853    if [ "$IS_I686" = "YES" ]; then
854        SKIP_NEXT="YES"
855    fi
856}
857
858MAX_CONTENT_LEN=16384
859MAX_IN_LEN=$( get_config_value_or_default "MBEDTLS_SSL_IN_CONTENT_LEN" )
860MAX_OUT_LEN=$( get_config_value_or_default "MBEDTLS_SSL_OUT_CONTENT_LEN" )
861if [ "$LIST_TESTS" -eq 0 ];then
862    # Calculate the input & output maximum content lengths set in the config
863
864    # Calculate the maximum content length that fits both
865    if [ "$MAX_IN_LEN" -lt "$MAX_CONTENT_LEN" ]; then
866        MAX_CONTENT_LEN="$MAX_IN_LEN"
867    fi
868    if [ "$MAX_OUT_LEN" -lt "$MAX_CONTENT_LEN" ]; then
869        MAX_CONTENT_LEN="$MAX_OUT_LEN"
870    fi
871fi
872# skip the next test if the SSL output buffer is less than 16KB
873requires_full_size_output_buffer() {
874    if [ "$MAX_OUT_LEN" -ne 16384 ]; then
875        SKIP_NEXT="YES"
876    fi
877}
878
879# skip the next test if valgrind is in use
880not_with_valgrind() {
881    if [ "$MEMCHECK" -gt 0 ]; then
882        SKIP_NEXT="YES"
883    fi
884}
885
886# skip the next test if valgrind is NOT in use
887only_with_valgrind() {
888    if [ "$MEMCHECK" -eq 0 ]; then
889        SKIP_NEXT="YES"
890    fi
891}
892
893# multiply the client timeout delay by the given factor for the next test
894client_needs_more_time() {
895    CLI_DELAY_FACTOR=$1
896}
897
898# wait for the given seconds after the client finished in the next test
899server_needs_more_time() {
900    SRV_DELAY_SECONDS=$1
901}
902
903# print_name <name>
904print_name() {
905    TESTS=$(( $TESTS + 1 ))
906    LINE=""
907
908    if [ "$SHOW_TEST_NUMBER" -gt 0 ]; then
909        LINE="$TESTS "
910    fi
911
912    LINE="$LINE$1"
913
914    printf "%s " "$LINE"
915    LEN=$(( 72 - `echo "$LINE" | wc -c` ))
916    for i in `seq 1 $LEN`; do printf '.'; done
917    printf ' '
918
919}
920
921# record_outcome <outcome> [<failure-reason>]
922# The test name must be in $NAME.
923# Use $TEST_SUITE_NAME as the test suite name if set.
924record_outcome() {
925    echo "$1"
926    if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
927        printf '%s;%s;%s;%s;%s;%s\n' \
928               "$MBEDTLS_TEST_PLATFORM" "$MBEDTLS_TEST_CONFIGURATION" \
929               "${TEST_SUITE_NAME:-ssl-opt}" "$NAME" \
930               "$1" "${2-}" \
931               >>"$MBEDTLS_TEST_OUTCOME_FILE"
932    fi
933}
934unset TEST_SUITE_NAME
935
936# True if the presence of the given pattern in a log definitely indicates
937# that the test has failed. False if the presence is inconclusive.
938#
939# Inputs:
940# * $1: pattern found in the logs
941# * $TIMES_LEFT: >0 if retrying is an option
942#
943# Outputs:
944# * $outcome: set to a retry reason if the pattern is inconclusive,
945#             unchanged otherwise.
946# * Return value: 1 if the pattern is inconclusive,
947#                 0 if the failure is definitive.
948log_pattern_presence_is_conclusive() {
949    # If we've run out of attempts, then don't retry no matter what.
950    if [ $TIMES_LEFT -eq 0 ]; then
951        return 0
952    fi
953    case $1 in
954        "resend")
955            # An undesired resend may have been caused by the OS dropping or
956            # delaying a packet at an inopportune time.
957            outcome="RETRY(resend)"
958            return 1;;
959    esac
960}
961
962# fail <message>
963fail() {
964    record_outcome "FAIL" "$1"
965    echo "  ! $1"
966
967    mv $SRV_OUT o-srv-${TESTS}.log
968    mv $CLI_OUT o-cli-${TESTS}.log
969    if [ -n "$PXY_CMD" ]; then
970        mv $PXY_OUT o-pxy-${TESTS}.log
971    fi
972    echo "  ! outputs saved to o-XXX-${TESTS}.log"
973
974    if [ "${LOG_FAILURE_ON_STDOUT:-0}" != 0 ]; then
975        echo "  ! server output:"
976        cat o-srv-${TESTS}.log
977        echo "  ! ========================================================"
978        echo "  ! client output:"
979        cat o-cli-${TESTS}.log
980        if [ -n "$PXY_CMD" ]; then
981            echo "  ! ========================================================"
982            echo "  ! proxy output:"
983            cat o-pxy-${TESTS}.log
984        fi
985        echo ""
986    fi
987
988    FAILS=$(( $FAILS + 1 ))
989}
990
991# is_polar <cmd_line>
992is_polar() {
993    case "$1" in
994        *ssl_client2*) true;;
995        *ssl_server2*) true;;
996        *) false;;
997    esac
998}
999
1000# openssl s_server doesn't have -www with DTLS
1001check_osrv_dtls() {
1002    case "$SRV_CMD" in
1003        *s_server*-dtls*)
1004            NEEDS_INPUT=1
1005            SRV_CMD="$( echo $SRV_CMD | sed s/-www// )";;
1006        *) NEEDS_INPUT=0;;
1007    esac
1008}
1009
1010# provide input to commands that need it
1011provide_input() {
1012    if [ $NEEDS_INPUT -eq 0 ]; then
1013        return
1014    fi
1015
1016    while true; do
1017        echo "HTTP/1.0 200 OK"
1018        sleep 1
1019    done
1020}
1021
1022# has_mem_err <log_file_name>
1023has_mem_err() {
1024    if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
1025         grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
1026    then
1027        return 1 # false: does not have errors
1028    else
1029        return 0 # true: has errors
1030    fi
1031}
1032
1033# Wait for process $2 named $3 to be listening on port $1. Print error to $4.
1034if type lsof >/dev/null 2>/dev/null; then
1035    wait_app_start() {
1036        newline='
1037'
1038        START_TIME=$(date +%s)
1039        if [ "$DTLS" -eq 1 ]; then
1040            proto=UDP
1041        else
1042            proto=TCP
1043        fi
1044        # Make a tight loop, server normally takes less than 1s to start.
1045        while true; do
1046              SERVER_PIDS=$(lsof -a -n -b -i "$proto:$1" -t)
1047              # When we use a proxy, it will be listening on the same port we
1048              # are checking for as well as the server and lsof will list both.
1049             case ${newline}${SERVER_PIDS}${newline} in
1050                  *${newline}${2}${newline}*) break;;
1051              esac
1052              if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then
1053                  echo "$3 START TIMEOUT"
1054                  echo "$3 START TIMEOUT" >> $4
1055                  break
1056              fi
1057              # Linux and *BSD support decimal arguments to sleep. On other
1058              # OSes this may be a tight loop.
1059              sleep 0.1 2>/dev/null || true
1060        done
1061    }
1062else
1063    echo "Warning: lsof not available, wait_app_start = sleep"
1064    wait_app_start() {
1065        sleep "$START_DELAY"
1066    }
1067fi
1068
1069# Wait for server process $2 to be listening on port $1.
1070wait_server_start() {
1071    wait_app_start $1 $2 "SERVER" $SRV_OUT
1072}
1073
1074# Wait for proxy process $2 to be listening on port $1.
1075wait_proxy_start() {
1076    wait_app_start $1 $2 "PROXY" $PXY_OUT
1077}
1078
1079# Given the client or server debug output, parse the unix timestamp that is
1080# included in the first 4 bytes of the random bytes and check that it's within
1081# acceptable bounds
1082check_server_hello_time() {
1083    # Extract the time from the debug (lvl 3) output of the client
1084    SERVER_HELLO_TIME="$(sed -n 's/.*server hello, current time: //p' < "$1")"
1085    # Get the Unix timestamp for now
1086    CUR_TIME=$(date +'%s')
1087    THRESHOLD_IN_SECS=300
1088
1089    # Check if the ServerHello time was printed
1090    if [ -z "$SERVER_HELLO_TIME" ]; then
1091        return 1
1092    fi
1093
1094    # Check the time in ServerHello is within acceptable bounds
1095    if [ $SERVER_HELLO_TIME -lt $(( $CUR_TIME - $THRESHOLD_IN_SECS )) ]; then
1096        # The time in ServerHello is at least 5 minutes before now
1097        return 1
1098    elif [ $SERVER_HELLO_TIME -gt $(( $CUR_TIME + $THRESHOLD_IN_SECS )) ]; then
1099        # The time in ServerHello is at least 5 minutes later than now
1100        return 1
1101    else
1102        return 0
1103    fi
1104}
1105
1106# Get handshake memory usage from server or client output and put it into the variable specified by the first argument
1107handshake_memory_get() {
1108    OUTPUT_VARIABLE="$1"
1109    OUTPUT_FILE="$2"
1110
1111    # Get memory usage from a pattern like "Heap memory usage after handshake: 23112 bytes. Peak memory usage was 33112"
1112    MEM_USAGE=$(sed -n 's/.*Heap memory usage after handshake: //p' < "$OUTPUT_FILE" | grep -o "[0-9]*" | head -1)
1113
1114    # Check if memory usage was read
1115    if [ -z "$MEM_USAGE" ]; then
1116        echo "Error: Can not read the value of handshake memory usage"
1117        return 1
1118    else
1119        eval "$OUTPUT_VARIABLE=$MEM_USAGE"
1120        return 0
1121    fi
1122}
1123
1124# Get handshake memory usage from server or client output and check if this value
1125# is not higher than the maximum given by the first argument
1126handshake_memory_check() {
1127    MAX_MEMORY="$1"
1128    OUTPUT_FILE="$2"
1129
1130    # Get memory usage
1131    if ! handshake_memory_get "MEMORY_USAGE" "$OUTPUT_FILE"; then
1132        return 1
1133    fi
1134
1135    # Check if memory usage is below max value
1136    if [ "$MEMORY_USAGE" -gt "$MAX_MEMORY" ]; then
1137        echo "\nFailed: Handshake memory usage was $MEMORY_USAGE bytes," \
1138             "but should be below $MAX_MEMORY bytes"
1139        return 1
1140    else
1141        return 0
1142    fi
1143}
1144
1145# wait for client to terminate and set CLI_EXIT
1146# must be called right after starting the client
1147wait_client_done() {
1148    CLI_PID=$!
1149
1150    CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
1151    CLI_DELAY_FACTOR=1
1152
1153    ( sleep $CLI_DELAY; echo "===CLIENT_TIMEOUT===" >> $CLI_OUT; kill $CLI_PID ) &
1154    DOG_PID=$!
1155
1156    # For Ubuntu 22.04, `Terminated` message is outputed by wait command.
1157    # To remove it from stdout, redirect stdout/stderr to CLI_OUT
1158    wait $CLI_PID >> $CLI_OUT 2>&1
1159    CLI_EXIT=$?
1160
1161    kill $DOG_PID >/dev/null 2>&1
1162    wait $DOG_PID >> $CLI_OUT 2>&1
1163
1164    echo "EXIT: $CLI_EXIT" >> $CLI_OUT
1165
1166    sleep $SRV_DELAY_SECONDS
1167    SRV_DELAY_SECONDS=0
1168}
1169
1170# check if the given command uses dtls and sets global variable DTLS
1171detect_dtls() {
1172    case "$1" in
1173        *dtls=1*|*-dtls*|*-u*) DTLS=1;;
1174        *) DTLS=0;;
1175    esac
1176}
1177
1178# check if the given command uses gnutls and sets global variable CMD_IS_GNUTLS
1179is_gnutls() {
1180    case "$1" in
1181    *gnutls-cli*)
1182        CMD_IS_GNUTLS=1
1183        ;;
1184    *gnutls-serv*)
1185        CMD_IS_GNUTLS=1
1186        ;;
1187    *)
1188        CMD_IS_GNUTLS=0
1189        ;;
1190    esac
1191}
1192
1193# Some external tools (gnutls or openssl) might not have support for static ECDH
1194# and this limit the tests that can be run with them. This function checks server
1195# and client command lines, given as input, to verify if the current test
1196# is using one of these tools.
1197use_ext_tool_without_ecdh_support() {
1198    case "$1" in
1199        *$GNUTLS_SERV*|\
1200        *${GNUTLS_NEXT_SERV:-"gnutls-serv-dummy"}*|\
1201        *${OPENSSL_NEXT:-"openssl-dummy"}*)
1202                echo "yes"
1203                return;;
1204    esac
1205    case "$2" in
1206        *$GNUTLS_CLI*|\
1207        *${GNUTLS_NEXT_CLI:-"gnutls-cli-dummy"}*|\
1208        *${OPENSSL_NEXT:-"openssl-dummy"}*)
1209                echo "yes"
1210                return;;
1211    esac
1212    echo "no"
1213}
1214
1215# Generate random psk_list argument for ssl_server2
1216get_srv_psk_list ()
1217{
1218    case $(( TESTS % 3 )) in
1219        0) echo "psk_list=abc,dead,def,beef,Client_identity,6162636465666768696a6b6c6d6e6f70";;
1220        1) echo "psk_list=abc,dead,Client_identity,6162636465666768696a6b6c6d6e6f70,def,beef";;
1221        2) echo "psk_list=Client_identity,6162636465666768696a6b6c6d6e6f70,abc,dead,def,beef";;
1222    esac
1223}
1224
1225# Determine what calc_verify trace is to be expected, if any.
1226#
1227# calc_verify is only called for two things: to calculate the
1228# extended master secret, and to process client authentication.
1229#
1230# Warning: the current implementation assumes that extended_ms is not
1231#          disabled on the client or on the server.
1232#
1233# Inputs:
1234# * $1: the value of the server auth_mode parameter.
1235#       'required' if client authentication is expected,
1236#       'none' or absent if not.
1237# * $CONFIGS_ENABLED
1238#
1239# Outputs:
1240# * $maybe_calc_verify: set to a trace expected in the debug logs
1241set_maybe_calc_verify() {
1242    maybe_calc_verify=
1243    case $CONFIGS_ENABLED in
1244        *\ MBEDTLS_SSL_EXTENDED_MASTER_SECRET\ *) :;;
1245        *)
1246            case ${1-} in
1247                ''|none) return;;
1248                required) :;;
1249                *) echo "Bad parameter 1 to set_maybe_calc_verify: $1"; exit 1;;
1250            esac
1251    esac
1252    case $CONFIGS_ENABLED in
1253        *\ MBEDTLS_USE_PSA_CRYPTO\ *) maybe_calc_verify="PSA calc verify";;
1254        *) maybe_calc_verify="<= calc verify";;
1255    esac
1256}
1257
1258# Compare file content
1259# Usage: find_in_both pattern file1 file2
1260# extract from file1 the first line matching the pattern
1261# check in file2 that the same line can be found
1262find_in_both() {
1263        srv_pattern=$(grep -m 1 "$1" "$2");
1264        if [ -z "$srv_pattern" ]; then
1265                return 1;
1266        fi
1267
1268        if grep "$srv_pattern" $3 >/dev/null; then :
1269                return 0;
1270        else
1271                return 1;
1272        fi
1273}
1274
1275SKIP_HANDSHAKE_CHECK="NO"
1276skip_handshake_stage_check() {
1277    SKIP_HANDSHAKE_CHECK="YES"
1278}
1279
1280# Analyze the commands that will be used in a test.
1281#
1282# Analyze and possibly instrument $PXY_CMD, $CLI_CMD, $SRV_CMD to pass
1283# extra arguments or go through wrappers.
1284#
1285# Inputs:
1286# * $@: supplemental options to run_test() (after the mandatory arguments).
1287# * $CLI_CMD, $PXY_CMD, $SRV_CMD: the client, proxy and server commands.
1288# * $DTLS: 1 if DTLS, otherwise 0.
1289#
1290# Outputs:
1291# * $CLI_CMD, $PXY_CMD, $SRV_CMD: may be tweaked.
1292analyze_test_commands() {
1293    # if the test uses DTLS but no custom proxy, add a simple proxy
1294    # as it provides timing info that's useful to debug failures
1295    if [ -z "$PXY_CMD" ] && [ "$DTLS" -eq 1 ]; then
1296        PXY_CMD="$P_PXY"
1297        case " $SRV_CMD " in
1298            *' server_addr=::1 '*)
1299                PXY_CMD="$PXY_CMD server_addr=::1 listen_addr=::1";;
1300        esac
1301    fi
1302
1303    # update CMD_IS_GNUTLS variable
1304    is_gnutls "$SRV_CMD"
1305
1306    # if the server uses gnutls but doesn't set priority, explicitly
1307    # set the default priority
1308    if [ "$CMD_IS_GNUTLS" -eq 1 ]; then
1309        case "$SRV_CMD" in
1310              *--priority*) :;;
1311              *) SRV_CMD="$SRV_CMD --priority=NORMAL";;
1312        esac
1313    fi
1314
1315    # update CMD_IS_GNUTLS variable
1316    is_gnutls "$CLI_CMD"
1317
1318    # if the client uses gnutls but doesn't set priority, explicitly
1319    # set the default priority
1320    if [ "$CMD_IS_GNUTLS" -eq 1 ]; then
1321        case "$CLI_CMD" in
1322              *--priority*) :;;
1323              *) CLI_CMD="$CLI_CMD --priority=NORMAL";;
1324        esac
1325    fi
1326
1327    # fix client port
1328    if [ -n "$PXY_CMD" ]; then
1329        CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
1330    else
1331        CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
1332    fi
1333
1334    # prepend valgrind to our commands if active
1335    if [ "$MEMCHECK" -gt 0 ]; then
1336        if is_polar "$SRV_CMD"; then
1337            SRV_CMD="valgrind --leak-check=full $SRV_CMD"
1338        fi
1339        if is_polar "$CLI_CMD"; then
1340            CLI_CMD="valgrind --leak-check=full $CLI_CMD"
1341        fi
1342    fi
1343}
1344
1345# Check for failure conditions after a test case.
1346#
1347# Inputs from run_test:
1348# * positional parameters: test options (see run_test documentation)
1349# * $CLI_EXIT: client return code
1350# * $CLI_EXPECT: expected client return code
1351# * $SRV_RET: server return code
1352# * $CLI_OUT, $SRV_OUT, $PXY_OUT: files containing client/server/proxy logs
1353# * $TIMES_LEFT: if nonzero, a RETRY outcome is allowed
1354#
1355# Outputs:
1356# * $outcome: one of PASS/RETRY*/FAIL
1357check_test_failure() {
1358    outcome=FAIL
1359
1360    if [ $TIMES_LEFT -gt 0 ] &&
1361       grep '===CLIENT_TIMEOUT===' $CLI_OUT >/dev/null
1362    then
1363        outcome="RETRY(client-timeout)"
1364        return
1365    fi
1366
1367    # check if the client and server went at least to the handshake stage
1368    # (useful to avoid tests with only negative assertions and non-zero
1369    # expected client exit to incorrectly succeed in case of catastrophic
1370    # failure)
1371    if [ "X$SKIP_HANDSHAKE_CHECK" != "XYES" ]
1372    then
1373        if is_polar "$SRV_CMD"; then
1374            if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
1375            else
1376                fail "server or client failed to reach handshake stage"
1377                return
1378            fi
1379        fi
1380        if is_polar "$CLI_CMD"; then
1381            if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
1382            else
1383                fail "server or client failed to reach handshake stage"
1384                return
1385            fi
1386        fi
1387    fi
1388
1389    SKIP_HANDSHAKE_CHECK="NO"
1390    # Check server exit code (only for Mbed TLS: GnuTLS and OpenSSL don't
1391    # exit with status 0 when interrupted by a signal, and we don't really
1392    # care anyway), in case e.g. the server reports a memory leak.
1393    if [ $SRV_RET != 0 ] && is_polar "$SRV_CMD"; then
1394        fail "Server exited with status $SRV_RET"
1395        return
1396    fi
1397
1398    # check client exit code
1399    if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
1400         \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
1401    then
1402        fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
1403        return
1404    fi
1405
1406    # check other assertions
1407    # lines beginning with == are added by valgrind, ignore them
1408    # lines with 'Serious error when reading debug info', are valgrind issues as well
1409    while [ $# -gt 0 ]
1410    do
1411        case $1 in
1412            "-s")
1413                if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
1414                    fail "pattern '$2' MUST be present in the Server output"
1415                    return
1416                fi
1417                ;;
1418
1419            "-c")
1420                if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
1421                    fail "pattern '$2' MUST be present in the Client output"
1422                    return
1423                fi
1424                ;;
1425
1426            "-S")
1427                if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
1428                    if log_pattern_presence_is_conclusive "$2"; then
1429                        fail "pattern '$2' MUST NOT be present in the Server output"
1430                    fi
1431                    return
1432                fi
1433                ;;
1434
1435            "-C")
1436                if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
1437                    if log_pattern_presence_is_conclusive "$2"; then
1438                        fail "pattern '$2' MUST NOT be present in the Client output"
1439                    fi
1440                    return
1441                fi
1442                ;;
1443
1444                # The filtering in the following two options (-u and -U) do the following
1445                #   - ignore valgrind output
1446                #   - filter out everything but lines right after the pattern occurrences
1447                #   - keep one of each non-unique line
1448                #   - count how many lines remain
1449                # A line with '--' will remain in the result from previous outputs, so the number of lines in the result will be 1
1450                # if there were no duplicates.
1451            "-U")
1452                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
1453                    fail "lines following pattern '$2' must be unique in Server output"
1454                    return
1455                fi
1456                ;;
1457
1458            "-u")
1459                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
1460                    fail "lines following pattern '$2' must be unique in Client output"
1461                    return
1462                fi
1463                ;;
1464            "-F")
1465                if ! $2 "$SRV_OUT"; then
1466                    fail "function call to '$2' failed on Server output"
1467                    return
1468                fi
1469                ;;
1470            "-f")
1471                if ! $2 "$CLI_OUT"; then
1472                    fail "function call to '$2' failed on Client output"
1473                    return
1474                fi
1475                ;;
1476            "-g")
1477                if ! eval "$2 '$SRV_OUT' '$CLI_OUT'"; then
1478                    fail "function call to '$2' failed on Server and Client output"
1479                    return
1480                fi
1481                ;;
1482
1483            *)
1484                echo "Unknown test: $1" >&2
1485                exit 1
1486        esac
1487        shift 2
1488    done
1489
1490    # check valgrind's results
1491    if [ "$MEMCHECK" -gt 0 ]; then
1492        if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
1493            fail "Server has memory errors"
1494            return
1495        fi
1496        if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
1497            fail "Client has memory errors"
1498            return
1499        fi
1500    fi
1501
1502    # if we're here, everything is ok
1503    outcome=PASS
1504}
1505
1506# Run the current test case: start the server and if applicable the proxy, run
1507# the client, wait for all processes to finish or time out.
1508#
1509# Inputs:
1510# * $NAME: test case name
1511# * $CLI_CMD, $SRV_CMD, $PXY_CMD: commands to run
1512# * $CLI_OUT, $SRV_OUT, $PXY_OUT: files to contain client/server/proxy logs
1513#
1514# Outputs:
1515# * $CLI_EXIT: client return code
1516# * $SRV_RET: server return code
1517do_run_test_once() {
1518    # run the commands
1519    if [ -n "$PXY_CMD" ]; then
1520        printf "# %s\n%s\n" "$NAME" "$PXY_CMD" > $PXY_OUT
1521        $PXY_CMD >> $PXY_OUT 2>&1 &
1522        PXY_PID=$!
1523        wait_proxy_start "$PXY_PORT" "$PXY_PID"
1524    fi
1525
1526    check_osrv_dtls
1527    printf '# %s\n%s\n' "$NAME" "$SRV_CMD" > $SRV_OUT
1528    provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
1529    SRV_PID=$!
1530    wait_server_start "$SRV_PORT" "$SRV_PID"
1531
1532    printf '# %s\n%s\n' "$NAME" "$CLI_CMD" > $CLI_OUT
1533    # The client must be a subprocess of the script in order for killing it to
1534    # work properly, that's why the ampersand is placed inside the eval command,
1535    # not at the end of the line: the latter approach will spawn eval as a
1536    # subprocess, and the $CLI_CMD as a grandchild.
1537    eval "$CLI_CMD &" >> $CLI_OUT 2>&1
1538    wait_client_done
1539
1540    sleep 0.05
1541
1542    # terminate the server (and the proxy)
1543    kill $SRV_PID
1544    # For Ubuntu 22.04, `Terminated` message is outputed by wait command.
1545    # To remove it from stdout, redirect stdout/stderr to SRV_OUT
1546    wait $SRV_PID >> $SRV_OUT 2>&1
1547    SRV_RET=$?
1548
1549    if [ -n "$PXY_CMD" ]; then
1550        kill $PXY_PID >/dev/null 2>&1
1551        wait $PXY_PID >> $PXY_OUT 2>&1
1552    fi
1553}
1554
1555# Detect if the current test is going to use TLS 1.3 or TLS 1.2.
1556# $1 and $2 contain the server and client command lines, respectively.
1557#
1558# Note: this function only provides some guess about TLS version by simply
1559#       looking at the server/client command lines. Even though this works
1560#       for the sake of tests' filtering (especially in conjunction with the
1561#       detect_required_features() function), it does NOT guarantee that the
1562#       result is accurate. It does not check other conditions, such as:
1563#       - we can force a ciphersuite which contains "WITH" in its name, meaning
1564#         that we are going to use TLS 1.2
1565#       - etc etc
1566get_tls_version() {
1567    # First check if the version is forced on an Mbed TLS peer
1568    case $1 in
1569        *tls12*)
1570            echo "TLS12"
1571            return;;
1572        *tls13*)
1573            echo "TLS13"
1574            return;;
1575    esac
1576    case $2 in
1577        *tls12*)
1578            echo "TLS12"
1579            return;;
1580        *tls13*)
1581            echo "TLS13"
1582            return;;
1583    esac
1584    # Second check if the version is forced on an OpenSSL or GnuTLS peer
1585    case $1 in
1586        tls1_2*)
1587            echo "TLS12"
1588            return;;
1589        *tls1_3)
1590            echo "TLS13"
1591            return;;
1592    esac
1593    case $2 in
1594        *tls1_2)
1595            echo "TLS12"
1596            return;;
1597        *tls1_3)
1598            echo "TLS13"
1599            return;;
1600    esac
1601    # Third if the version is not forced, if TLS 1.3 is enabled then the test
1602    # is aimed to run a TLS 1.3 handshake.
1603    if $P_QUERY -all MBEDTLS_SSL_PROTO_TLS1_3
1604    then
1605        echo "TLS13"
1606    else
1607        echo "TLS12"
1608    fi
1609}
1610
1611# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
1612# Options:  -s pattern  pattern that must be present in server output
1613#           -c pattern  pattern that must be present in client output
1614#           -u pattern  lines after pattern must be unique in client output
1615#           -f call shell function on client output
1616#           -S pattern  pattern that must be absent in server output
1617#           -C pattern  pattern that must be absent in client output
1618#           -U pattern  lines after pattern must be unique in server output
1619#           -F call shell function on server output
1620#           -g call shell function on server and client output
1621run_test() {
1622    NAME="$1"
1623    shift 1
1624
1625    if is_excluded "$NAME"; then
1626        SKIP_NEXT="NO"
1627        # There was no request to run the test, so don't record its outcome.
1628        return
1629    fi
1630
1631    if [ "$LIST_TESTS" -gt 0 ]; then
1632        printf "%s\n" "${TEST_SUITE_NAME:-ssl-opt};$NAME"
1633        return
1634    fi
1635
1636    # Use ssl-opt as default test suite name. Also see record_outcome function
1637    if is_excluded_test_suite "${TEST_SUITE_NAME:-ssl-opt}"; then
1638        # Do not skip next test and skip current test.
1639        SKIP_NEXT="NO"
1640        return
1641    fi
1642
1643    print_name "$NAME"
1644
1645    # Do we only run numbered tests?
1646    if [ -n "$RUN_TEST_NUMBER" ]; then
1647        case ",$RUN_TEST_NUMBER," in
1648            *",$TESTS,"*) :;;
1649            *) SKIP_NEXT="YES";;
1650        esac
1651    fi
1652
1653    # does this test use a proxy?
1654    if [ "X$1" = "X-p" ]; then
1655        PXY_CMD="$2"
1656        shift 2
1657    else
1658        PXY_CMD=""
1659    fi
1660
1661    # get commands and client output
1662    SRV_CMD="$1"
1663    CLI_CMD="$2"
1664    CLI_EXPECT="$3"
1665    shift 3
1666
1667    # Check if test uses files
1668    case "$SRV_CMD $CLI_CMD" in
1669        *data_files/*)
1670            requires_config_enabled MBEDTLS_FS_IO;;
1671    esac
1672
1673    # Check if the test uses DTLS.
1674    detect_dtls "$SRV_CMD"
1675    if [ "$DTLS" -eq 1 ]; then
1676        requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
1677    fi
1678
1679    # Check if we are trying to use an external tool which does not support ECDH
1680    EXT_WO_ECDH=$(use_ext_tool_without_ecdh_support "$SRV_CMD" "$CLI_CMD")
1681
1682    # Guess the TLS version which is going to be used
1683    if [ "$EXT_WO_ECDH" = "no" ]; then
1684        TLS_VERSION=$(get_tls_version "$SRV_CMD" "$CLI_CMD")
1685    else
1686        TLS_VERSION="TLS12"
1687    fi
1688
1689    # If the client or server requires certain features that can be detected
1690    # from their command-line arguments, check whether they're enabled.
1691    detect_required_features "$SRV_CMD" "server" "$TLS_VERSION" "$EXT_WO_ECDH" "$@"
1692    detect_required_features "$CLI_CMD" "client" "$TLS_VERSION" "$EXT_WO_ECDH" "$@"
1693
1694    # If we're in a PSK-only build and the test can be adapted to PSK, do that.
1695    maybe_adapt_for_psk "$@"
1696
1697    # should we skip?
1698    if [ "X$SKIP_NEXT" = "XYES" ]; then
1699        SKIP_NEXT="NO"
1700        record_outcome "SKIP"
1701        SKIPS=$(( $SKIPS + 1 ))
1702        return
1703    fi
1704
1705    analyze_test_commands "$@"
1706
1707    # One regular run and two retries
1708    TIMES_LEFT=3
1709    while [ $TIMES_LEFT -gt 0 ]; do
1710        TIMES_LEFT=$(( $TIMES_LEFT - 1 ))
1711
1712        do_run_test_once
1713
1714        check_test_failure "$@"
1715        case $outcome in
1716            PASS) break;;
1717            RETRY*) printf "$outcome ";;
1718            FAIL) return;;
1719        esac
1720    done
1721
1722    # If we get this far, the test case passed.
1723    record_outcome "PASS"
1724    if [ "$PRESERVE_LOGS" -gt 0 ]; then
1725        mv $SRV_OUT o-srv-${TESTS}.log
1726        mv $CLI_OUT o-cli-${TESTS}.log
1727        if [ -n "$PXY_CMD" ]; then
1728            mv $PXY_OUT o-pxy-${TESTS}.log
1729        fi
1730    fi
1731
1732    rm -f $SRV_OUT $CLI_OUT $PXY_OUT
1733}
1734
1735run_test_psa() {
1736    requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1737    set_maybe_calc_verify none
1738    run_test    "PSA-supported ciphersuite: $1" \
1739                "$P_SRV debug_level=3 force_version=tls12" \
1740                "$P_CLI debug_level=3 force_ciphersuite=$1" \
1741                0 \
1742                -c "$maybe_calc_verify" \
1743                -c "calc PSA finished" \
1744                -s "$maybe_calc_verify" \
1745                -s "calc PSA finished" \
1746                -s "Protocol is TLSv1.2" \
1747                -c "Perform PSA-based ECDH computation."\
1748                -c "Perform PSA-based computation of digest of ServerKeyExchange" \
1749                -S "error" \
1750                -C "error"
1751    unset maybe_calc_verify
1752}
1753
1754run_test_psa_force_curve() {
1755    requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1756    set_maybe_calc_verify none
1757    run_test    "PSA - ECDH with $1" \
1758                "$P_SRV debug_level=4 force_version=tls12 groups=$1" \
1759                "$P_CLI debug_level=4 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 groups=$1" \
1760                0 \
1761                -c "$maybe_calc_verify" \
1762                -c "calc PSA finished" \
1763                -s "$maybe_calc_verify" \
1764                -s "calc PSA finished" \
1765                -s "Protocol is TLSv1.2" \
1766                -c "Perform PSA-based ECDH computation."\
1767                -c "Perform PSA-based computation of digest of ServerKeyExchange" \
1768                -S "error" \
1769                -C "error"
1770    unset maybe_calc_verify
1771}
1772
1773# Test that the server's memory usage after a handshake is reduced when a client specifies
1774# a maximum fragment length.
1775#  first argument ($1) is MFL for SSL client
1776#  second argument ($2) is memory usage for SSL client with default MFL (16k)
1777run_test_memory_after_hanshake_with_mfl()
1778{
1779    # The test passes if the difference is around 2*(16k-MFL)
1780    MEMORY_USAGE_LIMIT="$(( $2 - ( 2 * ( 16384 - $1 )) ))"
1781
1782    # Leave some margin for robustness
1783    MEMORY_USAGE_LIMIT="$(( ( MEMORY_USAGE_LIMIT * 110 ) / 100 ))"
1784
1785    run_test    "Handshake memory usage (MFL $1)" \
1786                "$P_SRV debug_level=3 auth_mode=required force_version=tls12" \
1787                "$P_CLI debug_level=3 \
1788                    crt_file=data_files/server5.crt key_file=data_files/server5.key \
1789                    force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM max_frag_len=$1" \
1790                0 \
1791                -F "handshake_memory_check $MEMORY_USAGE_LIMIT"
1792}
1793
1794
1795# Test that the server's memory usage after a handshake is reduced when a client specifies
1796# different values of Maximum Fragment Length: default (16k), 4k, 2k, 1k and 512 bytes
1797run_tests_memory_after_hanshake()
1798{
1799    # all tests in this sequence requires the same configuration (see requires_config_enabled())
1800    SKIP_THIS_TESTS="$SKIP_NEXT"
1801
1802    # first test with default MFU is to get reference memory usage
1803    MEMORY_USAGE_MFL_16K=0
1804    run_test    "Handshake memory usage initial (MFL 16384 - default)" \
1805                "$P_SRV debug_level=3 auth_mode=required force_version=tls12" \
1806                "$P_CLI debug_level=3 \
1807                    crt_file=data_files/server5.crt key_file=data_files/server5.key \
1808                    force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM" \
1809                0 \
1810                -F "handshake_memory_get MEMORY_USAGE_MFL_16K"
1811
1812    SKIP_NEXT="$SKIP_THIS_TESTS"
1813    run_test_memory_after_hanshake_with_mfl 4096 "$MEMORY_USAGE_MFL_16K"
1814
1815    SKIP_NEXT="$SKIP_THIS_TESTS"
1816    run_test_memory_after_hanshake_with_mfl 2048 "$MEMORY_USAGE_MFL_16K"
1817
1818    SKIP_NEXT="$SKIP_THIS_TESTS"
1819    run_test_memory_after_hanshake_with_mfl 1024 "$MEMORY_USAGE_MFL_16K"
1820
1821    SKIP_NEXT="$SKIP_THIS_TESTS"
1822    run_test_memory_after_hanshake_with_mfl 512 "$MEMORY_USAGE_MFL_16K"
1823}
1824
1825cleanup() {
1826    rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
1827    rm -f context_srv.txt
1828    rm -f context_cli.txt
1829    test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
1830    test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
1831    test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
1832    test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
1833    exit 1
1834}
1835
1836#
1837# MAIN
1838#
1839
1840# Make the outcome file path relative to the original directory, not
1841# to .../tests
1842case "$MBEDTLS_TEST_OUTCOME_FILE" in
1843    [!/]*)
1844        MBEDTLS_TEST_OUTCOME_FILE="$ORIGINAL_PWD/$MBEDTLS_TEST_OUTCOME_FILE"
1845        ;;
1846esac
1847
1848populate_enabled_hash_algs
1849
1850# Optimize filters: if $FILTER and $EXCLUDE can be expressed as shell
1851# patterns rather than regular expressions, use a case statement instead
1852# of calling grep. To keep the optimizer simple, it is incomplete and only
1853# detects simple cases: plain substring, everything, nothing.
1854#
1855# As an exception, the character '.' is treated as an ordinary character
1856# if it is the only special character in the string. This is because it's
1857# rare to need "any one character", but needing a literal '.' is common
1858# (e.g. '-f "DTLS 1.2"').
1859need_grep=
1860case "$FILTER" in
1861    '^$') simple_filter=;;
1862    '.*') simple_filter='*';;
1863    *[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
1864        need_grep=1;;
1865    *) # No regexp or shell-pattern special character
1866        simple_filter="*$FILTER*";;
1867esac
1868case "$EXCLUDE" in
1869    '^$') simple_exclude=;;
1870    '.*') simple_exclude='*';;
1871    *[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
1872        need_grep=1;;
1873    *) # No regexp or shell-pattern special character
1874        simple_exclude="*$EXCLUDE*";;
1875esac
1876if [ -n "$need_grep" ]; then
1877    is_excluded () {
1878        ! echo "$1" | grep "$FILTER" | grep -q -v "$EXCLUDE"
1879    }
1880else
1881    is_excluded () {
1882        case "$1" in
1883            $simple_exclude) true;;
1884            $simple_filter) false;;
1885            *) true;;
1886        esac
1887    }
1888fi
1889
1890# Filter tests according to TEST_SUITE_NAME
1891is_excluded_test_suite () {
1892    if [ -n "$RUN_TEST_SUITE" ]
1893    then
1894        case ",$RUN_TEST_SUITE," in
1895            *",$1,"*) false;;
1896            *) true;;
1897        esac
1898    else
1899        false
1900    fi
1901
1902}
1903
1904
1905if [ "$LIST_TESTS" -eq 0 ];then
1906
1907    # sanity checks, avoid an avalanche of errors
1908    P_SRV_BIN="${P_SRV%%[  ]*}"
1909    P_CLI_BIN="${P_CLI%%[  ]*}"
1910    P_PXY_BIN="${P_PXY%%[  ]*}"
1911    if [ ! -x "$P_SRV_BIN" ]; then
1912        echo "Command '$P_SRV_BIN' is not an executable file"
1913        exit 1
1914    fi
1915    if [ ! -x "$P_CLI_BIN" ]; then
1916        echo "Command '$P_CLI_BIN' is not an executable file"
1917        exit 1
1918    fi
1919    if [ ! -x "$P_PXY_BIN" ]; then
1920        echo "Command '$P_PXY_BIN' is not an executable file"
1921        exit 1
1922    fi
1923    if [ "$MEMCHECK" -gt 0 ]; then
1924        if which valgrind >/dev/null 2>&1; then :; else
1925            echo "Memcheck not possible. Valgrind not found"
1926            exit 1
1927        fi
1928    fi
1929    if which $OPENSSL >/dev/null 2>&1; then :; else
1930        echo "Command '$OPENSSL' not found"
1931        exit 1
1932    fi
1933
1934    # used by watchdog
1935    MAIN_PID="$$"
1936
1937    # We use somewhat arbitrary delays for tests:
1938    # - how long do we wait for the server to start (when lsof not available)?
1939    # - how long do we allow for the client to finish?
1940    #   (not to check performance, just to avoid waiting indefinitely)
1941    # Things are slower with valgrind, so give extra time here.
1942    #
1943    # Note: without lsof, there is a trade-off between the running time of this
1944    # script and the risk of spurious errors because we didn't wait long enough.
1945    # The watchdog delay on the other hand doesn't affect normal running time of
1946    # the script, only the case where a client or server gets stuck.
1947    if [ "$MEMCHECK" -gt 0 ]; then
1948        START_DELAY=6
1949        DOG_DELAY=60
1950    else
1951        START_DELAY=2
1952        DOG_DELAY=20
1953    fi
1954
1955    # some particular tests need more time:
1956    # - for the client, we multiply the usual watchdog limit by a factor
1957    # - for the server, we sleep for a number of seconds after the client exits
1958    # see client_need_more_time() and server_needs_more_time()
1959    CLI_DELAY_FACTOR=1
1960    SRV_DELAY_SECONDS=0
1961
1962    # fix commands to use this port, force IPv4 while at it
1963    # +SRV_PORT will be replaced by either $SRV_PORT or $PXY_PORT later
1964    # Note: Using 'localhost' rather than 127.0.0.1 here is unwise, as on many
1965    # machines that will resolve to ::1, and we don't want ipv6 here.
1966    P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
1967    P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
1968    P_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"}"
1969    O_SRV="$O_SRV -accept $SRV_PORT"
1970    O_CLI="$O_CLI -connect 127.0.0.1:+SRV_PORT"
1971    G_SRV="$G_SRV -p $SRV_PORT"
1972    G_CLI="$G_CLI -p +SRV_PORT"
1973
1974    # Newer versions of OpenSSL have a syntax to enable all "ciphers", even
1975    # low-security ones. This covers not just cipher suites but also protocol
1976    # versions. It is necessary, for example, to use (D)TLS 1.0/1.1 on
1977    # OpenSSL 1.1.1f from Ubuntu 20.04. The syntax was only introduced in
1978    # OpenSSL 1.1.0 (21e0c1d23afff48601eb93135defddae51f7e2e3) and I can't find
1979    # a way to discover it from -help, so check the openssl version.
1980    case $($OPENSSL version) in
1981        "OpenSSL 0"*|"OpenSSL 1.0"*) :;;
1982        *)
1983            O_CLI="$O_CLI -cipher ALL@SECLEVEL=0"
1984            O_SRV="$O_SRV -cipher ALL@SECLEVEL=0"
1985            ;;
1986    esac
1987
1988    if [ -n "${OPENSSL_NEXT:-}" ]; then
1989        O_NEXT_SRV="$O_NEXT_SRV -accept $SRV_PORT"
1990        O_NEXT_SRV_NO_CERT="$O_NEXT_SRV_NO_CERT -accept $SRV_PORT"
1991        O_NEXT_SRV_EARLY_DATA="$O_NEXT_SRV_EARLY_DATA -accept $SRV_PORT"
1992        O_NEXT_CLI="$O_NEXT_CLI -connect 127.0.0.1:+SRV_PORT"
1993        O_NEXT_CLI_NO_CERT="$O_NEXT_CLI_NO_CERT -connect 127.0.0.1:+SRV_PORT"
1994    fi
1995
1996    if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
1997        G_NEXT_SRV="$G_NEXT_SRV -p $SRV_PORT"
1998        G_NEXT_SRV_NO_CERT="$G_NEXT_SRV_NO_CERT -p $SRV_PORT"
1999    fi
2000
2001    if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
2002        G_NEXT_CLI="$G_NEXT_CLI -p +SRV_PORT"
2003        G_NEXT_CLI_NO_CERT="$G_NEXT_CLI_NO_CERT -p +SRV_PORT localhost"
2004    fi
2005
2006    # Allow SHA-1, because many of our test certificates use it
2007    P_SRV="$P_SRV allow_sha1=1"
2008    P_CLI="$P_CLI allow_sha1=1"
2009
2010fi
2011# Also pick a unique name for intermediate files
2012SRV_OUT="srv_out.$$"
2013CLI_OUT="cli_out.$$"
2014PXY_OUT="pxy_out.$$"
2015SESSION="session.$$"
2016
2017SKIP_NEXT="NO"
2018
2019trap cleanup INT TERM HUP
2020
2021# Basic test
2022
2023# Checks that:
2024# - things work with all ciphersuites active (used with config-full in all.sh)
2025# - the expected parameters are selected
2026requires_ciphersuite_enabled TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256
2027requires_hash_alg SHA_512 # "signature_algorithm ext: 6"
2028requires_any_configs_enabled "MBEDTLS_ECP_DP_CURVE25519_ENABLED \
2029                              PSA_WANT_ECC_MONTGOMERY_255"
2030run_test    "Default, TLS 1.2" \
2031            "$P_SRV debug_level=3" \
2032            "$P_CLI force_version=tls12" \
2033            0 \
2034            -s "Protocol is TLSv1.2" \
2035            -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256" \
2036            -s "client hello v3, signature_algorithm ext: 6" \
2037            -s "ECDHE curve: x25519" \
2038            -S "error" \
2039            -C "error"
2040
2041requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2042requires_ciphersuite_enabled TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256
2043run_test    "Default, DTLS" \
2044            "$P_SRV dtls=1" \
2045            "$P_CLI dtls=1" \
2046            0 \
2047            -s "Protocol is DTLSv1.2" \
2048            -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256"
2049
2050requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
2051run_test    "TLS client auth: required" \
2052            "$P_SRV auth_mode=required" \
2053            "$P_CLI" \
2054            0 \
2055            -s "Verifying peer X.509 certificate... ok"
2056
2057run_test    "key size: TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2058            "$P_SRV" \
2059            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2060            0 \
2061            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2062            -c "Key size is 256"
2063
2064run_test    "key size: TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2065            "$P_SRV" \
2066            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2067            0 \
2068            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2069            -c "Key size is 128"
2070
2071requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2072requires_config_enabled MBEDTLS_MD_CAN_MD5
2073# server5.key.enc is in PEM format and AES-256-CBC crypted. Unfortunately PEM
2074# module does not support PSA dispatching so we need builtin support.
2075requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
2076requires_config_enabled MBEDTLS_AES_C
2077requires_hash_alg SHA_256
2078run_test    "TLS: password protected client key" \
2079            "$P_SRV force_version=tls12 auth_mode=required" \
2080            "$P_CLI crt_file=data_files/server5.crt key_file=data_files/server5.key.enc key_pwd=PolarSSLTest" \
2081            0
2082
2083requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2084requires_config_enabled MBEDTLS_MD_CAN_MD5
2085# server5.key.enc is in PEM format and AES-256-CBC crypted. Unfortunately PEM
2086# module does not support PSA dispatching so we need builtin support.
2087requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
2088requires_config_enabled MBEDTLS_AES_C
2089requires_hash_alg SHA_256
2090run_test    "TLS: password protected server key" \
2091            "$P_SRV crt_file=data_files/server5.crt key_file=data_files/server5.key.enc key_pwd=PolarSSLTest" \
2092            "$P_CLI force_version=tls12" \
2093            0
2094
2095requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2096requires_config_enabled MBEDTLS_RSA_C
2097requires_config_enabled MBEDTLS_MD_CAN_MD5
2098# server5.key.enc is in PEM format and AES-256-CBC crypted. Unfortunately PEM
2099# module does not support PSA dispatching so we need builtin support.
2100requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
2101requires_config_enabled MBEDTLS_AES_C
2102requires_hash_alg SHA_256
2103run_test    "TLS: password protected server key, two certificates" \
2104            "$P_SRV force_version=tls12\
2105              key_file=data_files/server5.key.enc key_pwd=PolarSSLTest crt_file=data_files/server5.crt \
2106              key_file2=data_files/server2.key.enc key_pwd2=PolarSSLTest crt_file2=data_files/server2.crt" \
2107            "$P_CLI" \
2108            0
2109
2110requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
2111run_test    "CA callback on client" \
2112            "$P_SRV debug_level=3" \
2113            "$P_CLI force_version=tls12 ca_callback=1 debug_level=3 " \
2114            0 \
2115            -c "use CA callback for X.509 CRT verification" \
2116            -S "error" \
2117            -C "error"
2118
2119requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
2120requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2121requires_hash_alg SHA_256
2122run_test    "CA callback on server" \
2123            "$P_SRV force_version=tls12 auth_mode=required" \
2124            "$P_CLI ca_callback=1 debug_level=3 crt_file=data_files/server5.crt \
2125             key_file=data_files/server5.key" \
2126            0 \
2127            -c "use CA callback for X.509 CRT verification" \
2128            -s "Verifying peer X.509 certificate... ok" \
2129            -S "error" \
2130            -C "error"
2131
2132# Test using an EC opaque private key for client authentication
2133requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2134requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2135requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2136requires_hash_alg SHA_256
2137run_test    "Opaque key for client authentication: ECDHE-ECDSA" \
2138            "$P_SRV force_version=tls12 auth_mode=required crt_file=data_files/server5.crt \
2139             key_file=data_files/server5.key" \
2140            "$P_CLI key_opaque=1 crt_file=data_files/server5.crt \
2141             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
2142            0 \
2143            -c "key type: Opaque" \
2144            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2145            -s "Verifying peer X.509 certificate... ok" \
2146            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2147            -S "error" \
2148            -C "error"
2149
2150# Test using a RSA opaque private key for client authentication
2151requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2152requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2153requires_config_enabled MBEDTLS_RSA_C
2154requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2155requires_hash_alg SHA_256
2156run_test    "Opaque key for client authentication: ECDHE-RSA" \
2157            "$P_SRV force_version=tls12 auth_mode=required crt_file=data_files/server2-sha256.crt \
2158             key_file=data_files/server2.key" \
2159            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
2160             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
2161            0 \
2162            -c "key type: Opaque" \
2163            -c "Ciphersuite is TLS-ECDHE-RSA" \
2164            -s "Verifying peer X.509 certificate... ok" \
2165            -s "Ciphersuite is TLS-ECDHE-RSA" \
2166            -S "error" \
2167            -C "error"
2168
2169requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2170requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2171requires_config_enabled MBEDTLS_RSA_C
2172requires_hash_alg SHA_256
2173run_test    "Opaque key for client authentication: DHE-RSA" \
2174            "$P_SRV force_version=tls12 auth_mode=required crt_file=data_files/server2-sha256.crt \
2175             key_file=data_files/server2.key" \
2176            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
2177             key_file=data_files/server2.key force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
2178             key_opaque_algs=rsa-sign-pkcs1,none" \
2179            0 \
2180            -c "key type: Opaque" \
2181            -c "Ciphersuite is TLS-DHE-RSA" \
2182            -s "Verifying peer X.509 certificate... ok" \
2183            -s "Ciphersuite is TLS-DHE-RSA" \
2184            -S "error" \
2185            -C "error"
2186
2187# Test using an EC opaque private key for server authentication
2188requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2189requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2190requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2191requires_hash_alg SHA_256
2192run_test    "Opaque key for server authentication: ECDHE-ECDSA" \
2193            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2194             key_file=data_files/server5.key  key_opaque_algs=ecdsa-sign,none" \
2195            "$P_CLI force_version=tls12" \
2196            0 \
2197            -c "Verifying peer X.509 certificate... ok" \
2198            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2199            -s "key types: Opaque, none" \
2200            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2201            -S "error" \
2202            -C "error"
2203
2204requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2205requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2206requires_hash_alg SHA_256
2207run_test    "Opaque key for server authentication: ECDH-" \
2208            "$P_SRV auth_mode=required key_opaque=1\
2209             crt_file=data_files/server5.ku-ka.crt\
2210             key_file=data_files/server5.key key_opaque_algs=ecdh,none" \
2211            "$P_CLI force_version=tls12" \
2212            0 \
2213            -c "Verifying peer X.509 certificate... ok" \
2214            -c "Ciphersuite is TLS-ECDH-" \
2215            -s "key types: Opaque, none" \
2216            -s "Ciphersuite is TLS-ECDH-" \
2217            -S "error" \
2218            -C "error"
2219
2220requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2221requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2222requires_config_disabled MBEDTLS_SSL_ASYNC_PRIVATE
2223requires_hash_alg SHA_256
2224run_test    "Opaque key for server authentication: invalid key: decrypt with ECC key, no async" \
2225            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2226             key_file=data_files/server5.key key_opaque_algs=rsa-decrypt,none \
2227             debug_level=1" \
2228            "$P_CLI force_version=tls12" \
2229            1 \
2230            -s "key types: Opaque, none" \
2231            -s "error" \
2232            -c "error" \
2233            -c "Public key type mismatch"
2234
2235requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2236requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2237requires_config_enabled MBEDTLS_ECDSA_C
2238requires_config_enabled MBEDTLS_RSA_C
2239requires_config_disabled MBEDTLS_SSL_ASYNC_PRIVATE
2240requires_hash_alg SHA_256
2241run_test    "Opaque key for server authentication: invalid key: ecdh with RSA key, no async" \
2242            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2243             key_file=data_files/server2.key key_opaque_algs=ecdh,none \
2244             debug_level=1" \
2245            "$P_CLI force_version=tls12" \
2246            1 \
2247            -s "key types: Opaque, none" \
2248            -s "error" \
2249            -c "error" \
2250            -c "Public key type mismatch"
2251
2252requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2253requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2254requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
2255requires_hash_alg SHA_256
2256run_test    "Opaque key for server authentication: invalid alg: decrypt with ECC key, async" \
2257            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2258             key_file=data_files/server5.key key_opaque_algs=rsa-decrypt,none \
2259             debug_level=1" \
2260            "$P_CLI force_version=tls12" \
2261            1 \
2262            -s "key types: Opaque, none" \
2263            -s "got ciphersuites in common, but none of them usable" \
2264            -s "error" \
2265            -c "error"
2266
2267requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2268requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2269requires_config_enabled MBEDTLS_RSA_C
2270requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
2271requires_hash_alg SHA_256
2272run_test    "Opaque key for server authentication: invalid alg: ecdh with RSA key, async" \
2273            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2274             key_file=data_files/server2.key key_opaque_algs=ecdh,none \
2275             debug_level=1" \
2276            "$P_CLI force_version=tls12" \
2277            1 \
2278            -s "key types: Opaque, none" \
2279            -s "got ciphersuites in common, but none of them usable" \
2280            -s "error" \
2281            -c "error"
2282
2283requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2284requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2285requires_hash_alg SHA_256
2286run_test    "Opaque key for server authentication: invalid alg: ECDHE-ECDSA with ecdh" \
2287            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2288             key_file=data_files/server5.key key_opaque_algs=ecdh,none \
2289             debug_level=1" \
2290            "$P_CLI force_version=tls12 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-CCM" \
2291            1 \
2292            -s "key types: Opaque, none" \
2293            -s "got ciphersuites in common, but none of them usable" \
2294            -s "error" \
2295            -c "error"
2296
2297requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2298requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2299requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2300requires_hash_alg SHA_256
2301requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2302run_test    "Opaque keys for server authentication: EC keys with different algs, force ECDHE-ECDSA" \
2303            "$P_SRV force_version=tls12 key_opaque=1 crt_file=data_files/server7.crt \
2304             key_file=data_files/server7.key key_opaque_algs=ecdh,none \
2305             crt_file2=data_files/server5.crt key_file2=data_files/server5.key \
2306             key_opaque_algs2=ecdsa-sign,none" \
2307            "$P_CLI force_version=tls12" \
2308            0 \
2309            -c "Verifying peer X.509 certificate... ok" \
2310            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2311            -c "CN=Polarssl Test EC CA" \
2312            -s "key types: Opaque, Opaque" \
2313            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2314            -S "error" \
2315            -C "error"
2316
2317requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2318requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2319requires_hash_alg SHA_384
2320requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2321run_test    "Opaque keys for server authentication: EC keys with different algs, force ECDH-ECDSA" \
2322            "$P_SRV key_opaque=1 crt_file=data_files/server7.crt \
2323             key_file=data_files/server7.key key_opaque_algs=ecdsa-sign,none \
2324             crt_file2=data_files/server5.crt key_file2=data_files/server5.key \
2325             key_opaque_algs2=ecdh,none debug_level=3" \
2326            "$P_CLI force_version=tls12 force_ciphersuite=TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384" \
2327            0 \
2328            -c "Verifying peer X.509 certificate... ok" \
2329            -c "Ciphersuite is TLS-ECDH-ECDSA" \
2330            -c "CN=Polarssl Test EC CA" \
2331            -s "key types: Opaque, Opaque" \
2332            -s "Ciphersuite is TLS-ECDH-ECDSA" \
2333            -S "error" \
2334            -C "error"
2335
2336requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2337requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2338requires_hash_alg SHA_384
2339requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2340run_test    "Opaque keys for server authentication: EC + RSA, force ECDHE-ECDSA" \
2341            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2342             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none \
2343             crt_file2=data_files/server2-sha256.crt \
2344             key_file2=data_files/server2.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2345            "$P_CLI force_version=tls12 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-CCM" \
2346            0 \
2347            -c "Verifying peer X.509 certificate... ok" \
2348            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2349            -c "CN=Polarssl Test EC CA" \
2350            -s "key types: Opaque, Opaque" \
2351            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2352            -S "error" \
2353            -C "error"
2354
2355requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2356requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2357requires_config_enabled MBEDTLS_RSA_C
2358requires_config_enabled MBEDTLS_SSL_SRV_C
2359requires_config_enabled MBEDTLS_SSL_CLI_C
2360run_test    "TLS 1.3 opaque key: no suitable algorithm found" \
2361            "$P_SRV debug_level=4 auth_mode=required key_opaque=1 key_opaque_algs=rsa-decrypt,none" \
2362            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2363            1 \
2364            -c "key type: Opaque" \
2365            -s "key types: Opaque, Opaque" \
2366            -c "error" \
2367            -s "no suitable signature algorithm"
2368
2369requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2370requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2371requires_config_enabled MBEDTLS_RSA_C
2372requires_config_enabled MBEDTLS_SSL_SRV_C
2373requires_config_enabled MBEDTLS_SSL_CLI_C
2374run_test    "TLS 1.3 opaque key: suitable algorithm found" \
2375            "$P_SRV debug_level=4 auth_mode=required key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2376            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2377            0 \
2378            -c "key type: Opaque" \
2379            -s "key types: Opaque, Opaque" \
2380            -C "error" \
2381            -S "error"
2382
2383requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2384requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2385requires_config_enabled MBEDTLS_RSA_C
2386requires_config_enabled MBEDTLS_SSL_SRV_C
2387requires_config_enabled MBEDTLS_SSL_CLI_C
2388run_test    "TLS 1.3 opaque key: first client sig alg not suitable" \
2389            "$P_SRV debug_level=4 auth_mode=required key_opaque=1 key_opaque_algs=rsa-sign-pss-sha512,none" \
2390            "$P_CLI debug_level=4 sig_algs=rsa_pss_rsae_sha256,rsa_pss_rsae_sha512" \
2391            0 \
2392            -s "key types: Opaque, Opaque" \
2393            -s "CertificateVerify signature failed with rsa_pss_rsae_sha256" \
2394            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
2395            -C "error" \
2396            -S "error" \
2397
2398requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2399requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2400requires_config_enabled MBEDTLS_RSA_C
2401requires_config_enabled MBEDTLS_SSL_SRV_C
2402requires_config_enabled MBEDTLS_SSL_CLI_C
2403run_test    "TLS 1.3 opaque key: 2 keys on server, suitable algorithm found" \
2404            "$P_SRV debug_level=4 auth_mode=required key_opaque=1 key_opaque_algs2=ecdsa-sign,none key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2405            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2406            0 \
2407            -c "key type: Opaque" \
2408            -s "key types: Opaque, Opaque" \
2409            -C "error" \
2410            -S "error" \
2411
2412# Test using a RSA opaque private key for server authentication
2413requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2414requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2415requires_config_enabled MBEDTLS_RSA_C
2416requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2417requires_hash_alg SHA_256
2418run_test    "Opaque key for server authentication: ECDHE-RSA" \
2419            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2420             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
2421            "$P_CLI force_version=tls12" \
2422            0 \
2423            -c "Verifying peer X.509 certificate... ok" \
2424            -c "Ciphersuite is TLS-ECDHE-RSA" \
2425            -s "key types: Opaque, none" \
2426            -s "Ciphersuite is TLS-ECDHE-RSA" \
2427            -S "error" \
2428            -C "error"
2429
2430requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2431requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2432requires_config_enabled MBEDTLS_RSA_C
2433requires_hash_alg SHA_256
2434run_test    "Opaque key for server authentication: DHE-RSA" \
2435            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2436             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
2437            "$P_CLI force_version=tls12 force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2438            0 \
2439            -c "Verifying peer X.509 certificate... ok" \
2440            -c "Ciphersuite is TLS-DHE-RSA" \
2441            -s "key types: Opaque, none" \
2442            -s "Ciphersuite is TLS-DHE-RSA" \
2443            -S "error" \
2444            -C "error"
2445
2446requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2447requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2448requires_config_enabled MBEDTLS_RSA_C
2449requires_hash_alg SHA_256
2450run_test    "Opaque key for server authentication: RSA-PSK" \
2451            "$P_SRV debug_level=1 key_opaque=1 key_opaque_algs=rsa-decrypt,none \
2452             psk=abc123 psk_identity=foo" \
2453            "$P_CLI force_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256 \
2454             psk=abc123 psk_identity=foo" \
2455            0 \
2456            -c "Verifying peer X.509 certificate... ok" \
2457            -c "Ciphersuite is TLS-RSA-PSK-" \
2458            -s "key types: Opaque, Opaque" \
2459            -s "Ciphersuite is TLS-RSA-PSK-" \
2460            -S "error" \
2461            -C "error"
2462
2463requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2464requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2465requires_config_enabled MBEDTLS_RSA_C
2466requires_hash_alg SHA_256
2467run_test    "Opaque key for server authentication: RSA-" \
2468            "$P_SRV debug_level=3 key_opaque=1 key_opaque_algs=rsa-decrypt,none " \
2469            "$P_CLI force_version=tls12 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA256" \
2470            0 \
2471            -c "Verifying peer X.509 certificate... ok" \
2472            -c "Ciphersuite is TLS-RSA-" \
2473            -s "key types: Opaque, Opaque" \
2474            -s "Ciphersuite is TLS-RSA-" \
2475            -S "error" \
2476            -C "error"
2477
2478requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2479requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2480requires_config_enabled MBEDTLS_RSA_C
2481requires_hash_alg SHA_256
2482run_test    "Opaque key for server authentication: DHE-RSA, PSS instead of PKCS1" \
2483            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2484             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pss,none debug_level=1" \
2485            "$P_CLI crt_file=data_files/server2-sha256.crt \
2486             key_file=data_files/server2.key force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2487            1 \
2488            -s "key types: Opaque, none" \
2489            -s "got ciphersuites in common, but none of them usable" \
2490            -s "error" \
2491            -c "error"
2492
2493requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2494requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2495requires_config_enabled MBEDTLS_RSA_C
2496requires_hash_alg SHA_256
2497requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2498requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2499run_test    "Opaque keys for server authentication: RSA keys with different algs" \
2500            "$P_SRV force_version=tls12 auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2501             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pss,none \
2502             crt_file2=data_files/server4.crt \
2503             key_file2=data_files/server4.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2504            "$P_CLI force_version=tls12" \
2505            0 \
2506            -c "Verifying peer X.509 certificate... ok" \
2507            -c "Ciphersuite is TLS-ECDHE-RSA" \
2508            -c "CN=Polarssl Test EC CA" \
2509            -s "key types: Opaque, Opaque" \
2510            -s "Ciphersuite is TLS-ECDHE-RSA" \
2511            -S "error" \
2512            -C "error"
2513
2514requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2515requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2516requires_config_enabled MBEDTLS_RSA_C
2517requires_hash_alg SHA_384
2518requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2519run_test    "Opaque keys for server authentication: EC + RSA, force DHE-RSA" \
2520            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server5.crt \
2521             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none \
2522             crt_file2=data_files/server4.crt \
2523             key_file2=data_files/server4.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2524            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2525            0 \
2526            -c "Verifying peer X.509 certificate... ok" \
2527            -c "Ciphersuite is TLS-DHE-RSA" \
2528            -c "CN=Polarssl Test EC CA" \
2529            -s "key types: Opaque, Opaque" \
2530            -s "Ciphersuite is TLS-DHE-RSA" \
2531            -S "error" \
2532            -C "error"
2533
2534# Test using an EC opaque private key for client/server authentication
2535requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2536requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2537requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2538requires_hash_alg SHA_256
2539run_test    "Opaque key for client/server authentication: ECDHE-ECDSA" \
2540            "$P_SRV force_version=tls12 auth_mode=required key_opaque=1 crt_file=data_files/server5.crt \
2541             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
2542            "$P_CLI key_opaque=1 crt_file=data_files/server5.crt \
2543             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
2544            0 \
2545            -c "key type: Opaque" \
2546            -c "Verifying peer X.509 certificate... ok" \
2547            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2548            -s "key types: Opaque, none" \
2549            -s "Verifying peer X.509 certificate... ok" \
2550            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2551            -S "error" \
2552            -C "error"
2553
2554# Test using a RSA opaque private key for client/server authentication
2555requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2556requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2557requires_config_enabled MBEDTLS_RSA_C
2558requires_hash_alg SHA_256
2559requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2560run_test    "Opaque key for client/server authentication: ECDHE-RSA" \
2561            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2562             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2563            "$P_CLI force_version=tls12 key_opaque=1 crt_file=data_files/server2-sha256.crt \
2564             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2565            0 \
2566            -c "key type: Opaque" \
2567            -c "Verifying peer X.509 certificate... ok" \
2568            -c "Ciphersuite is TLS-ECDHE-RSA" \
2569            -s "key types: Opaque, none" \
2570            -s "Verifying peer X.509 certificate... ok" \
2571            -s "Ciphersuite is TLS-ECDHE-RSA" \
2572            -S "error" \
2573            -C "error"
2574
2575requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2576requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2577requires_config_enabled MBEDTLS_RSA_C
2578requires_hash_alg SHA_256
2579run_test    "Opaque key for client/server authentication: DHE-RSA" \
2580            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2581             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2582            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
2583             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none \
2584             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2585            0 \
2586            -c "key type: Opaque" \
2587            -c "Verifying peer X.509 certificate... ok" \
2588            -c "Ciphersuite is TLS-DHE-RSA" \
2589            -s "key types: Opaque, none" \
2590            -s "Verifying peer X.509 certificate... ok" \
2591            -s "Ciphersuite is TLS-DHE-RSA" \
2592            -S "error" \
2593            -C "error"
2594
2595
2596# Test ciphersuites which we expect to be fully supported by PSA Crypto
2597# and check that we don't fall back to Mbed TLS' internal crypto primitives.
2598run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CCM
2599run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8
2600run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CCM
2601run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CCM-8
2602run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
2603run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384
2604run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA
2605run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256
2606run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384
2607
2608requires_config_enabled PSA_WANT_ECC_SECP_R1_521
2609run_test_psa_force_curve "secp521r1"
2610requires_config_enabled PSA_WANT_ECC_BRAINPOOL_P_R1_512
2611run_test_psa_force_curve "brainpoolP512r1"
2612requires_config_enabled PSA_WANT_ECC_SECP_R1_384
2613run_test_psa_force_curve "secp384r1"
2614requires_config_enabled PSA_WANT_ECC_BRAINPOOL_P_R1_384
2615run_test_psa_force_curve "brainpoolP384r1"
2616requires_config_enabled PSA_WANT_ECC_SECP_R1_256
2617run_test_psa_force_curve "secp256r1"
2618requires_config_enabled PSA_WANT_ECC_SECP_K1_256
2619run_test_psa_force_curve "secp256k1"
2620requires_config_enabled PSA_WANT_ECC_BRAINPOOL_P_R1_256
2621run_test_psa_force_curve "brainpoolP256r1"
2622requires_config_enabled PSA_WANT_ECC_SECP_R1_224
2623run_test_psa_force_curve "secp224r1"
2624## SECP224K1 is buggy via the PSA API
2625## (https://github.com/Mbed-TLS/mbedtls/issues/3541),
2626## so it is disabled in PSA even when it's enabled in Mbed TLS.
2627## The proper dependency would be on PSA_WANT_ECC_SECP_K1_224 but
2628## dependencies on PSA symbols in ssl-opt.sh are not implemented yet.
2629#requires_config_enabled PSA_WANT_ECC_SECP_K1_224
2630#run_test_psa_force_curve "secp224k1"
2631requires_config_enabled PSA_WANT_ECC_SECP_R1_192
2632run_test_psa_force_curve "secp192r1"
2633requires_config_enabled PSA_WANT_ECC_SECP_K1_192
2634run_test_psa_force_curve "secp192k1"
2635
2636# Test current time in ServerHello
2637requires_config_enabled MBEDTLS_HAVE_TIME
2638run_test    "ServerHello contains gmt_unix_time" \
2639            "$P_SRV debug_level=3" \
2640            "$P_CLI force_version=tls12 debug_level=3" \
2641            0 \
2642            -f "check_server_hello_time" \
2643            -F "check_server_hello_time"
2644
2645# Test for uniqueness of IVs in AEAD ciphersuites
2646run_test    "Unique IV in GCM" \
2647            "$P_SRV exchanges=20 debug_level=4" \
2648            "$P_CLI exchanges=20 debug_level=4 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
2649            0 \
2650            -u "IV used" \
2651            -U "IV used"
2652
2653# Test for correctness of sent single supported algorithm
2654requires_any_configs_enabled "MBEDTLS_ECP_DP_SECP256R1_ENABLED \
2655                              PSA_WANT_ECC_SECP_R1_256"
2656requires_config_enabled MBEDTLS_DEBUG_C
2657requires_config_enabled MBEDTLS_SSL_CLI_C
2658requires_config_enabled MBEDTLS_SSL_SRV_C
2659requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
2660requires_pk_alg "ECDSA"
2661requires_hash_alg SHA_256
2662run_test    "Single supported algorithm sending: mbedtls client" \
2663            "$P_SRV sig_algs=ecdsa_secp256r1_sha256 auth_mode=required" \
2664            "$P_CLI force_version=tls12 sig_algs=ecdsa_secp256r1_sha256 debug_level=3" \
2665            0 \
2666            -c "Supported Signature Algorithm found: 04 03"
2667
2668requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2669requires_config_enabled MBEDTLS_SSL_SRV_C
2670requires_any_configs_enabled "MBEDTLS_ECP_DP_SECP256R1_ENABLED \
2671                              PSA_WANT_ECC_SECP_R1_256"
2672requires_hash_alg SHA_256
2673run_test    "Single supported algorithm sending: openssl client" \
2674            "$P_SRV sig_algs=ecdsa_secp256r1_sha256 auth_mode=required" \
2675            "$O_CLI -cert data_files/server6.crt \
2676                    -key data_files/server6.key" \
2677            0
2678
2679# Tests for certificate verification callback
2680run_test    "Configuration-specific CRT verification callback" \
2681            "$P_SRV debug_level=3" \
2682            "$P_CLI force_version=tls12 context_crt_cb=0 debug_level=3" \
2683            0 \
2684            -S "error" \
2685            -c "Verify requested for " \
2686            -c "Use configuration-specific verification callback" \
2687            -C "Use context-specific verification callback" \
2688            -C "error"
2689
2690run_test    "Context-specific CRT verification callback" \
2691            "$P_SRV debug_level=3" \
2692            "$P_CLI force_version=tls12 context_crt_cb=1 debug_level=3" \
2693            0 \
2694            -S "error" \
2695            -c "Verify requested for " \
2696            -c "Use context-specific verification callback" \
2697            -C "Use configuration-specific verification callback" \
2698            -C "error"
2699
2700# Tests for SHA-1 support
2701run_test    "SHA-1 forbidden by default in server certificate" \
2702            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
2703            "$P_CLI debug_level=2 force_version=tls12 allow_sha1=0" \
2704            1 \
2705            -c "The certificate is signed with an unacceptable hash"
2706
2707run_test    "SHA-1 explicitly allowed in server certificate" \
2708            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
2709            "$P_CLI force_version=tls12 allow_sha1=1" \
2710            0
2711
2712run_test    "SHA-256 allowed by default in server certificate" \
2713            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2-sha256.crt" \
2714            "$P_CLI force_version=tls12 allow_sha1=0" \
2715            0
2716
2717run_test    "SHA-1 forbidden by default in client certificate" \
2718            "$P_SRV force_version=tls12 auth_mode=required allow_sha1=0" \
2719            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
2720            1 \
2721            -s "The certificate is signed with an unacceptable hash"
2722
2723run_test    "SHA-1 explicitly allowed in client certificate" \
2724            "$P_SRV force_version=tls12 auth_mode=required allow_sha1=1" \
2725            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
2726            0
2727
2728run_test    "SHA-256 allowed by default in client certificate" \
2729            "$P_SRV force_version=tls12 auth_mode=required allow_sha1=0" \
2730            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha256.crt" \
2731            0
2732
2733# Tests for datagram packing
2734requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2735run_test    "DTLS: multiple records in same datagram, client and server" \
2736            "$P_SRV dtls=1 dgram_packing=1 debug_level=2" \
2737            "$P_CLI dtls=1 dgram_packing=1 debug_level=2" \
2738            0 \
2739            -c "next record in same datagram" \
2740            -s "next record in same datagram"
2741
2742requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2743run_test    "DTLS: multiple records in same datagram, client only" \
2744            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
2745            "$P_CLI dtls=1 dgram_packing=1 debug_level=2" \
2746            0 \
2747            -s "next record in same datagram" \
2748            -C "next record in same datagram"
2749
2750requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2751run_test    "DTLS: multiple records in same datagram, server only" \
2752            "$P_SRV dtls=1 dgram_packing=1 debug_level=2" \
2753            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
2754            0 \
2755            -S "next record in same datagram" \
2756            -c "next record in same datagram"
2757
2758requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2759run_test    "DTLS: multiple records in same datagram, neither client nor server" \
2760            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
2761            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
2762            0 \
2763            -S "next record in same datagram" \
2764            -C "next record in same datagram"
2765
2766# Tests for Context serialization
2767
2768requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2769run_test    "Context serialization, client serializes, CCM" \
2770            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2771            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2772            0 \
2773            -c "Deserializing connection..." \
2774            -S "Deserializing connection..."
2775
2776requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2777run_test    "Context serialization, client serializes, ChaChaPoly" \
2778            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2779            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2780            0 \
2781            -c "Deserializing connection..." \
2782            -S "Deserializing connection..."
2783
2784requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2785run_test    "Context serialization, client serializes, GCM" \
2786            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2787            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2788            0 \
2789            -c "Deserializing connection..." \
2790            -S "Deserializing connection..."
2791
2792requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2793requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2794requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2795run_test    "Context serialization, client serializes, with CID" \
2796            "$P_SRV dtls=1 serialize=0 exchanges=2 cid=1 cid_val=dead" \
2797            "$P_CLI dtls=1 serialize=1 exchanges=2 cid=1 cid_val=beef" \
2798            0 \
2799            -c "Deserializing connection..." \
2800            -S "Deserializing connection..."
2801
2802requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2803run_test    "Context serialization, server serializes, CCM" \
2804            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2805            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2806            0 \
2807            -C "Deserializing connection..." \
2808            -s "Deserializing connection..."
2809
2810requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2811run_test    "Context serialization, server serializes, ChaChaPoly" \
2812            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2813            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2814            0 \
2815            -C "Deserializing connection..." \
2816            -s "Deserializing connection..."
2817
2818requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2819run_test    "Context serialization, server serializes, GCM" \
2820            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2821            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2822            0 \
2823            -C "Deserializing connection..." \
2824            -s "Deserializing connection..."
2825
2826requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2827requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2828requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2829run_test    "Context serialization, server serializes, with CID" \
2830            "$P_SRV dtls=1 serialize=1 exchanges=2 cid=1 cid_val=dead" \
2831            "$P_CLI dtls=1 serialize=0 exchanges=2 cid=1 cid_val=beef" \
2832            0 \
2833            -C "Deserializing connection..." \
2834            -s "Deserializing connection..."
2835
2836requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2837run_test    "Context serialization, both serialize, CCM" \
2838            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2839            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2840            0 \
2841            -c "Deserializing connection..." \
2842            -s "Deserializing connection..."
2843
2844requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2845run_test    "Context serialization, both serialize, ChaChaPoly" \
2846            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2847            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2848            0 \
2849            -c "Deserializing connection..." \
2850            -s "Deserializing connection..."
2851
2852requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2853run_test    "Context serialization, both serialize, GCM" \
2854            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2855            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2856            0 \
2857            -c "Deserializing connection..." \
2858            -s "Deserializing connection..."
2859
2860requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2861requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2862requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2863run_test    "Context serialization, both serialize, with CID" \
2864            "$P_SRV dtls=1 serialize=1 exchanges=2 cid=1 cid_val=dead" \
2865            "$P_CLI dtls=1 serialize=1 exchanges=2 cid=1 cid_val=beef" \
2866            0 \
2867            -c "Deserializing connection..." \
2868            -s "Deserializing connection..."
2869
2870requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2871run_test    "Context serialization, re-init, client serializes, CCM" \
2872            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2873            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2874            0 \
2875            -c "Deserializing connection..." \
2876            -S "Deserializing connection..."
2877
2878requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2879requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2880run_test    "Context serialization, re-init, client serializes, ChaChaPoly" \
2881            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2882            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2883            0 \
2884            -c "Deserializing connection..." \
2885            -S "Deserializing connection..."
2886
2887requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2888run_test    "Context serialization, re-init, client serializes, GCM" \
2889            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2890            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2891            0 \
2892            -c "Deserializing connection..." \
2893            -S "Deserializing connection..."
2894
2895requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2896requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2897requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2898run_test    "Context serialization, re-init, client serializes, with CID" \
2899            "$P_SRV dtls=1 serialize=0 exchanges=2 cid=1 cid_val=dead" \
2900            "$P_CLI dtls=1 serialize=2 exchanges=2 cid=1 cid_val=beef" \
2901            0 \
2902            -c "Deserializing connection..." \
2903            -S "Deserializing connection..."
2904
2905requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2906run_test    "Context serialization, re-init, server serializes, CCM" \
2907            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2908            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2909            0 \
2910            -C "Deserializing connection..." \
2911            -s "Deserializing connection..."
2912
2913requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2914run_test    "Context serialization, re-init, server serializes, ChaChaPoly" \
2915            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2916            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2917            0 \
2918            -C "Deserializing connection..." \
2919            -s "Deserializing connection..."
2920
2921requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2922run_test    "Context serialization, re-init, server serializes, GCM" \
2923            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2924            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2925            0 \
2926            -C "Deserializing connection..." \
2927            -s "Deserializing connection..."
2928
2929requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2930requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2931requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2932run_test    "Context serialization, re-init, server serializes, with CID" \
2933            "$P_SRV dtls=1 serialize=2 exchanges=2 cid=1 cid_val=dead" \
2934            "$P_CLI dtls=1 serialize=0 exchanges=2 cid=1 cid_val=beef" \
2935            0 \
2936            -C "Deserializing connection..." \
2937            -s "Deserializing connection..."
2938
2939requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2940run_test    "Context serialization, re-init, both serialize, CCM" \
2941            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2942            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2943            0 \
2944            -c "Deserializing connection..." \
2945            -s "Deserializing connection..."
2946
2947requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2948run_test    "Context serialization, re-init, both serialize, ChaChaPoly" \
2949            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2950            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2951            0 \
2952            -c "Deserializing connection..." \
2953            -s "Deserializing connection..."
2954
2955requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2956run_test    "Context serialization, re-init, both serialize, GCM" \
2957            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2958            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2959            0 \
2960            -c "Deserializing connection..." \
2961            -s "Deserializing connection..."
2962
2963requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2964requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2965requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2966run_test    "Context serialization, re-init, both serialize, with CID" \
2967            "$P_SRV dtls=1 serialize=2 exchanges=2 cid=1 cid_val=dead" \
2968            "$P_CLI dtls=1 serialize=2 exchanges=2 cid=1 cid_val=beef" \
2969            0 \
2970            -c "Deserializing connection..." \
2971            -s "Deserializing connection..."
2972
2973requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2974requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2975run_test    "Saving the serialized context to a file" \
2976            "$P_SRV dtls=1 serialize=1 context_file=context_srv.txt" \
2977            "$P_CLI dtls=1 serialize=1 context_file=context_cli.txt" \
2978            0 \
2979            -s "Save serialized context to a file... ok" \
2980            -c "Save serialized context to a file... ok"
2981rm -f context_srv.txt
2982rm -f context_cli.txt
2983
2984# Tests for DTLS Connection ID extension
2985
2986# So far, the CID API isn't implemented, so we can't
2987# grep for output witnessing its use. This needs to be
2988# changed once the CID extension is implemented.
2989
2990requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2991requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2992run_test    "Connection ID: Cli enabled, Srv disabled" \
2993            "$P_SRV debug_level=3 dtls=1 cid=0" \
2994            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
2995            0 \
2996            -s "Disable use of CID extension." \
2997            -s "found CID extension"           \
2998            -s "Client sent CID extension, but CID disabled" \
2999            -c "Enable use of CID extension."  \
3000            -c "client hello, adding CID extension" \
3001            -S "server hello, adding CID extension" \
3002            -C "found CID extension" \
3003            -S "Copy CIDs into SSL transform" \
3004            -C "Copy CIDs into SSL transform" \
3005            -c "Use of Connection ID was rejected by the server"
3006
3007requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3008requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3009run_test    "Connection ID: Cli disabled, Srv enabled" \
3010            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3011            "$P_CLI debug_level=3 dtls=1 cid=0" \
3012            0 \
3013            -c "Disable use of CID extension." \
3014            -C "client hello, adding CID extension"           \
3015            -S "found CID extension"           \
3016            -s "Enable use of CID extension." \
3017            -S "server hello, adding CID extension" \
3018            -C "found CID extension" \
3019            -S "Copy CIDs into SSL transform" \
3020            -C "Copy CIDs into SSL transform"  \
3021            -s "Use of Connection ID was not offered by client"
3022
3023requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3024requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3025run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty" \
3026            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
3027            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef" \
3028            0 \
3029            -c "Enable use of CID extension." \
3030            -s "Enable use of CID extension." \
3031            -c "client hello, adding CID extension" \
3032            -s "found CID extension"           \
3033            -s "Use of CID extension negotiated" \
3034            -s "server hello, adding CID extension" \
3035            -c "found CID extension" \
3036            -c "Use of CID extension negotiated" \
3037            -s "Copy CIDs into SSL transform" \
3038            -c "Copy CIDs into SSL transform" \
3039            -c "Peer CID (length 2 Bytes): de ad" \
3040            -s "Peer CID (length 2 Bytes): be ef" \
3041            -s "Use of Connection ID has been negotiated" \
3042            -c "Use of Connection ID has been negotiated"
3043
3044requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3045requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3046run_test    "Connection ID, 3D: Cli+Srv enabled, Cli+Srv CID nonempty" \
3047            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3048            "$P_SRV debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=dead" \
3049            "$P_CLI debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=beef" \
3050            0 \
3051            -c "Enable use of CID extension." \
3052            -s "Enable use of CID extension." \
3053            -c "client hello, adding CID extension" \
3054            -s "found CID extension"           \
3055            -s "Use of CID extension negotiated" \
3056            -s "server hello, adding CID extension" \
3057            -c "found CID extension" \
3058            -c "Use of CID extension negotiated" \
3059            -s "Copy CIDs into SSL transform" \
3060            -c "Copy CIDs into SSL transform" \
3061            -c "Peer CID (length 2 Bytes): de ad" \
3062            -s "Peer CID (length 2 Bytes): be ef" \
3063            -s "Use of Connection ID has been negotiated" \
3064            -c "Use of Connection ID has been negotiated" \
3065            -c "ignoring unexpected CID" \
3066            -s "ignoring unexpected CID"
3067
3068requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3069requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3070run_test    "Connection ID, MTU: Cli+Srv enabled, Cli+Srv CID nonempty" \
3071            -p "$P_PXY mtu=800" \
3072            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead" \
3073            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef" \
3074            0 \
3075            -c "Enable use of CID extension." \
3076            -s "Enable use of CID extension." \
3077            -c "client hello, adding CID extension" \
3078            -s "found CID extension"           \
3079            -s "Use of CID extension negotiated" \
3080            -s "server hello, adding CID extension" \
3081            -c "found CID extension" \
3082            -c "Use of CID extension negotiated" \
3083            -s "Copy CIDs into SSL transform" \
3084            -c "Copy CIDs into SSL transform" \
3085            -c "Peer CID (length 2 Bytes): de ad" \
3086            -s "Peer CID (length 2 Bytes): be ef" \
3087            -s "Use of Connection ID has been negotiated" \
3088            -c "Use of Connection ID has been negotiated"
3089
3090requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3091requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3092run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, Cli+Srv CID nonempty" \
3093            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3094            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead" \
3095            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef" \
3096            0 \
3097            -c "Enable use of CID extension." \
3098            -s "Enable use of CID extension." \
3099            -c "client hello, adding CID extension" \
3100            -s "found CID extension"           \
3101            -s "Use of CID extension negotiated" \
3102            -s "server hello, adding CID extension" \
3103            -c "found CID extension" \
3104            -c "Use of CID extension negotiated" \
3105            -s "Copy CIDs into SSL transform" \
3106            -c "Copy CIDs into SSL transform" \
3107            -c "Peer CID (length 2 Bytes): de ad" \
3108            -s "Peer CID (length 2 Bytes): be ef" \
3109            -s "Use of Connection ID has been negotiated" \
3110            -c "Use of Connection ID has been negotiated" \
3111            -c "ignoring unexpected CID" \
3112            -s "ignoring unexpected CID"
3113
3114requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3115requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3116run_test    "Connection ID: Cli+Srv enabled, Cli CID empty" \
3117            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3118            "$P_CLI debug_level=3 dtls=1 cid=1" \
3119            0 \
3120            -c "Enable use of CID extension." \
3121            -s "Enable use of CID extension." \
3122            -c "client hello, adding CID extension" \
3123            -s "found CID extension"           \
3124            -s "Use of CID extension negotiated" \
3125            -s "server hello, adding CID extension" \
3126            -c "found CID extension" \
3127            -c "Use of CID extension negotiated" \
3128            -s "Copy CIDs into SSL transform" \
3129            -c "Copy CIDs into SSL transform" \
3130            -c "Peer CID (length 4 Bytes): de ad be ef" \
3131            -s "Peer CID (length 0 Bytes):" \
3132            -s "Use of Connection ID has been negotiated" \
3133            -c "Use of Connection ID has been negotiated"
3134
3135requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3136requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3137run_test    "Connection ID: Cli+Srv enabled, Srv CID empty" \
3138            "$P_SRV debug_level=3 dtls=1 cid=1" \
3139            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3140            0 \
3141            -c "Enable use of CID extension." \
3142            -s "Enable use of CID extension." \
3143            -c "client hello, adding CID extension" \
3144            -s "found CID extension"           \
3145            -s "Use of CID extension negotiated" \
3146            -s "server hello, adding CID extension" \
3147            -c "found CID extension" \
3148            -c "Use of CID extension negotiated" \
3149            -s "Copy CIDs into SSL transform" \
3150            -c "Copy CIDs into SSL transform" \
3151            -s "Peer CID (length 4 Bytes): de ad be ef" \
3152            -c "Peer CID (length 0 Bytes):" \
3153            -s "Use of Connection ID has been negotiated" \
3154            -c "Use of Connection ID has been negotiated"
3155
3156requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3157requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3158run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty" \
3159            "$P_SRV debug_level=3 dtls=1 cid=1" \
3160            "$P_CLI debug_level=3 dtls=1 cid=1" \
3161            0 \
3162            -c "Enable use of CID extension." \
3163            -s "Enable use of CID extension." \
3164            -c "client hello, adding CID extension" \
3165            -s "found CID extension"           \
3166            -s "Use of CID extension negotiated" \
3167            -s "server hello, adding CID extension" \
3168            -c "found CID extension" \
3169            -c "Use of CID extension negotiated" \
3170            -s "Copy CIDs into SSL transform" \
3171            -c "Copy CIDs into SSL transform" \
3172            -S "Use of Connection ID has been negotiated" \
3173            -C "Use of Connection ID has been negotiated"
3174
3175requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3176run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty, AES-128-CCM-8" \
3177            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
3178            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3179            0 \
3180            -c "Enable use of CID extension." \
3181            -s "Enable use of CID extension." \
3182            -c "client hello, adding CID extension" \
3183            -s "found CID extension"           \
3184            -s "Use of CID extension negotiated" \
3185            -s "server hello, adding CID extension" \
3186            -c "found CID extension" \
3187            -c "Use of CID extension negotiated" \
3188            -s "Copy CIDs into SSL transform" \
3189            -c "Copy CIDs into SSL transform" \
3190            -c "Peer CID (length 2 Bytes): de ad" \
3191            -s "Peer CID (length 2 Bytes): be ef" \
3192            -s "Use of Connection ID has been negotiated" \
3193            -c "Use of Connection ID has been negotiated"
3194
3195requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3196run_test    "Connection ID: Cli+Srv enabled, Cli CID empty, AES-128-CCM-8" \
3197            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3198            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3199            0 \
3200            -c "Enable use of CID extension." \
3201            -s "Enable use of CID extension." \
3202            -c "client hello, adding CID extension" \
3203            -s "found CID extension"           \
3204            -s "Use of CID extension negotiated" \
3205            -s "server hello, adding CID extension" \
3206            -c "found CID extension" \
3207            -c "Use of CID extension negotiated" \
3208            -s "Copy CIDs into SSL transform" \
3209            -c "Copy CIDs into SSL transform" \
3210            -c "Peer CID (length 4 Bytes): de ad be ef" \
3211            -s "Peer CID (length 0 Bytes):" \
3212            -s "Use of Connection ID has been negotiated" \
3213            -c "Use of Connection ID has been negotiated"
3214
3215requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3216run_test    "Connection ID: Cli+Srv enabled, Srv CID empty, AES-128-CCM-8" \
3217            "$P_SRV debug_level=3 dtls=1 cid=1" \
3218            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3219            0 \
3220            -c "Enable use of CID extension." \
3221            -s "Enable use of CID extension." \
3222            -c "client hello, adding CID extension" \
3223            -s "found CID extension"           \
3224            -s "Use of CID extension negotiated" \
3225            -s "server hello, adding CID extension" \
3226            -c "found CID extension" \
3227            -c "Use of CID extension negotiated" \
3228            -s "Copy CIDs into SSL transform" \
3229            -c "Copy CIDs into SSL transform" \
3230            -s "Peer CID (length 4 Bytes): de ad be ef" \
3231            -c "Peer CID (length 0 Bytes):" \
3232            -s "Use of Connection ID has been negotiated" \
3233            -c "Use of Connection ID has been negotiated"
3234
3235requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3236run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty, AES-128-CCM-8" \
3237            "$P_SRV debug_level=3 dtls=1 cid=1" \
3238            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3239            0 \
3240            -c "Enable use of CID extension." \
3241            -s "Enable use of CID extension." \
3242            -c "client hello, adding CID extension" \
3243            -s "found CID extension"           \
3244            -s "Use of CID extension negotiated" \
3245            -s "server hello, adding CID extension" \
3246            -c "found CID extension" \
3247            -c "Use of CID extension negotiated" \
3248            -s "Copy CIDs into SSL transform" \
3249            -c "Copy CIDs into SSL transform" \
3250            -S "Use of Connection ID has been negotiated" \
3251            -C "Use of Connection ID has been negotiated"
3252
3253requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3254run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty, AES-128-CBC" \
3255            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
3256            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3257            0 \
3258            -c "Enable use of CID extension." \
3259            -s "Enable use of CID extension." \
3260            -c "client hello, adding CID extension" \
3261            -s "found CID extension"           \
3262            -s "Use of CID extension negotiated" \
3263            -s "server hello, adding CID extension" \
3264            -c "found CID extension" \
3265            -c "Use of CID extension negotiated" \
3266            -s "Copy CIDs into SSL transform" \
3267            -c "Copy CIDs into SSL transform" \
3268            -c "Peer CID (length 2 Bytes): de ad" \
3269            -s "Peer CID (length 2 Bytes): be ef" \
3270            -s "Use of Connection ID has been negotiated" \
3271            -c "Use of Connection ID has been negotiated"
3272
3273requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3274run_test    "Connection ID: Cli+Srv enabled, Cli CID empty, AES-128-CBC" \
3275            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3276            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3277            0 \
3278            -c "Enable use of CID extension." \
3279            -s "Enable use of CID extension." \
3280            -c "client hello, adding CID extension" \
3281            -s "found CID extension"           \
3282            -s "Use of CID extension negotiated" \
3283            -s "server hello, adding CID extension" \
3284            -c "found CID extension" \
3285            -c "Use of CID extension negotiated" \
3286            -s "Copy CIDs into SSL transform" \
3287            -c "Copy CIDs into SSL transform" \
3288            -c "Peer CID (length 4 Bytes): de ad be ef" \
3289            -s "Peer CID (length 0 Bytes):" \
3290            -s "Use of Connection ID has been negotiated" \
3291            -c "Use of Connection ID has been negotiated"
3292
3293requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3294run_test    "Connection ID: Cli+Srv enabled, Srv CID empty, AES-128-CBC" \
3295            "$P_SRV debug_level=3 dtls=1 cid=1" \
3296            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3297            0 \
3298            -c "Enable use of CID extension." \
3299            -s "Enable use of CID extension." \
3300            -c "client hello, adding CID extension" \
3301            -s "found CID extension"           \
3302            -s "Use of CID extension negotiated" \
3303            -s "server hello, adding CID extension" \
3304            -c "found CID extension" \
3305            -c "Use of CID extension negotiated" \
3306            -s "Copy CIDs into SSL transform" \
3307            -c "Copy CIDs into SSL transform" \
3308            -s "Peer CID (length 4 Bytes): de ad be ef" \
3309            -c "Peer CID (length 0 Bytes):" \
3310            -s "Use of Connection ID has been negotiated" \
3311            -c "Use of Connection ID has been negotiated"
3312
3313requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3314run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty, AES-128-CBC" \
3315            "$P_SRV debug_level=3 dtls=1 cid=1" \
3316            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3317            0 \
3318            -c "Enable use of CID extension." \
3319            -s "Enable use of CID extension." \
3320            -c "client hello, adding CID extension" \
3321            -s "found CID extension"           \
3322            -s "Use of CID extension negotiated" \
3323            -s "server hello, adding CID extension" \
3324            -c "found CID extension" \
3325            -c "Use of CID extension negotiated" \
3326            -s "Copy CIDs into SSL transform" \
3327            -c "Copy CIDs into SSL transform" \
3328            -S "Use of Connection ID has been negotiated" \
3329            -C "Use of Connection ID has been negotiated"
3330
3331requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3332requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3333requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3334run_test    "Connection ID: Cli+Srv enabled, renegotiate without change of CID" \
3335            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3336            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3337            0 \
3338            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3339            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3340            -s "(initial handshake) Use of Connection ID has been negotiated" \
3341            -c "(initial handshake) Use of Connection ID has been negotiated" \
3342            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3343            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3344            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3345            -c "(after renegotiation) Use of Connection ID has been negotiated"
3346
3347requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3348requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3349requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3350run_test    "Connection ID: Cli+Srv enabled, renegotiate with different CID" \
3351            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_val_renego=beef renegotiation=1" \
3352            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3353            0 \
3354            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3355            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3356            -s "(initial handshake) Use of Connection ID has been negotiated" \
3357            -c "(initial handshake) Use of Connection ID has been negotiated" \
3358            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3359            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3360            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3361            -c "(after renegotiation) Use of Connection ID has been negotiated"
3362
3363requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3364requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3365requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3366run_test    "Connection ID, no packing: Cli+Srv enabled, renegotiate with different CID" \
3367            "$P_SRV debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=dead cid_val_renego=beef renegotiation=1" \
3368            "$P_CLI debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3369            0 \
3370            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3371            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3372            -s "(initial handshake) Use of Connection ID has been negotiated" \
3373            -c "(initial handshake) Use of Connection ID has been negotiated" \
3374            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3375            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3376            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3377            -c "(after renegotiation) Use of Connection ID has been negotiated"
3378
3379requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3380requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3381requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3382run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, renegotiate with different CID" \
3383            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3384            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead cid_val_renego=beef renegotiation=1" \
3385            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3386            0 \
3387            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3388            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3389            -s "(initial handshake) Use of Connection ID has been negotiated" \
3390            -c "(initial handshake) Use of Connection ID has been negotiated" \
3391            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3392            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3393            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3394            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3395            -c "ignoring unexpected CID" \
3396            -s "ignoring unexpected CID"
3397
3398requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3399requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3400requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3401run_test    "Connection ID: Cli+Srv enabled, renegotiate without CID" \
3402            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3403            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3404            0 \
3405            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3406            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3407            -s "(initial handshake) Use of Connection ID has been negotiated" \
3408            -c "(initial handshake) Use of Connection ID has been negotiated" \
3409            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3410            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3411            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3412            -S "(after renegotiation) Use of Connection ID has been negotiated"
3413
3414requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3415requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3416requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3417run_test    "Connection ID, no packing: Cli+Srv enabled, renegotiate without CID" \
3418            "$P_SRV debug_level=3 dtls=1 dgram_packing=0 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3419            "$P_CLI debug_level=3 dtls=1 dgram_packing=0 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3420            0 \
3421            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3422            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3423            -s "(initial handshake) Use of Connection ID has been negotiated" \
3424            -c "(initial handshake) Use of Connection ID has been negotiated" \
3425            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3426            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3427            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3428            -S "(after renegotiation) Use of Connection ID has been negotiated"
3429
3430requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3431requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3432requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3433run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, renegotiate without CID" \
3434            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3435            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3436            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3437            0 \
3438            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3439            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3440            -s "(initial handshake) Use of Connection ID has been negotiated" \
3441            -c "(initial handshake) Use of Connection ID has been negotiated" \
3442            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3443            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3444            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3445            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3446            -c "ignoring unexpected CID" \
3447            -s "ignoring unexpected CID"
3448
3449requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3450requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3451requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3452run_test    "Connection ID: Cli+Srv enabled, CID on renegotiation" \
3453            "$P_SRV debug_level=3 dtls=1 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3454            "$P_CLI debug_level=3 dtls=1 cid=0 cid_renego=1 cid_val_renego=beef renegotiation=1 renegotiate=1" \
3455            0 \
3456            -S "(initial handshake) Use of Connection ID has been negotiated" \
3457            -C "(initial handshake) Use of Connection ID has been negotiated" \
3458            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3459            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3460            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3461            -s "(after renegotiation) Use of Connection ID has been negotiated"
3462
3463requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3464requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3465requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3466run_test    "Connection ID, no packing: Cli+Srv enabled, CID on renegotiation" \
3467            "$P_SRV debug_level=3 dtls=1 dgram_packing=0 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3468            "$P_CLI debug_level=3 dtls=1 dgram_packing=0 cid=0 cid_renego=1 cid_val_renego=beef renegotiation=1 renegotiate=1" \
3469            0 \
3470            -S "(initial handshake) Use of Connection ID has been negotiated" \
3471            -C "(initial handshake) Use of Connection ID has been negotiated" \
3472            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3473            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3474            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3475            -s "(after renegotiation) Use of Connection ID has been negotiated"
3476
3477requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3478requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3479requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3480run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, CID on renegotiation" \
3481            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3482            "$P_SRV debug_level=3 mtu=800 dtls=1 dgram_packing=1 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3483            "$P_CLI debug_level=3 mtu=800 dtls=1 dgram_packing=1 cid=0 cid_renego=1 cid_val_renego=beef renegotiation=1 renegotiate=1" \
3484            0 \
3485            -S "(initial handshake) Use of Connection ID has been negotiated" \
3486            -C "(initial handshake) Use of Connection ID has been negotiated" \
3487            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3488            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3489            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3490            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3491            -c "ignoring unexpected CID" \
3492            -s "ignoring unexpected CID"
3493
3494requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3495requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3496requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3497run_test    "Connection ID: Cli+Srv enabled, Cli disables on renegotiation" \
3498            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3499            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3500            0 \
3501            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3502            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3503            -s "(initial handshake) Use of Connection ID has been negotiated" \
3504            -c "(initial handshake) Use of Connection ID has been negotiated" \
3505            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3506            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3507            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3508            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3509            -s "(after renegotiation) Use of Connection ID was not offered by client"
3510
3511requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3512requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3513requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3514run_test    "Connection ID, 3D: Cli+Srv enabled, Cli disables on renegotiation" \
3515            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3516            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3517            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3518            0 \
3519            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3520            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3521            -s "(initial handshake) Use of Connection ID has been negotiated" \
3522            -c "(initial handshake) Use of Connection ID has been negotiated" \
3523            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3524            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3525            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3526            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3527            -s "(after renegotiation) Use of Connection ID was not offered by client" \
3528            -c "ignoring unexpected CID" \
3529            -s "ignoring unexpected CID"
3530
3531requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3532requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3533requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3534run_test    "Connection ID: Cli+Srv enabled, Srv disables on renegotiation" \
3535            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3536            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3537            0 \
3538            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3539            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3540            -s "(initial handshake) Use of Connection ID has been negotiated" \
3541            -c "(initial handshake) Use of Connection ID has been negotiated" \
3542            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3543            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3544            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3545            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3546            -c "(after renegotiation) Use of Connection ID was rejected by the server"
3547
3548requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3549requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3550requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3551run_test    "Connection ID, 3D: Cli+Srv enabled, Srv disables on renegotiation" \
3552            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3553            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3554            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3555            0 \
3556            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3557            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3558            -s "(initial handshake) Use of Connection ID has been negotiated" \
3559            -c "(initial handshake) Use of Connection ID has been negotiated" \
3560            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3561            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3562            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3563            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3564            -c "(after renegotiation) Use of Connection ID was rejected by the server" \
3565            -c "ignoring unexpected CID" \
3566            -s "ignoring unexpected CID"
3567
3568# This and the test below it require MAX_CONTENT_LEN to be at least MFL+1, because the
3569# tests check that the buffer contents are reallocated when the message is
3570# larger than the buffer.
3571requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3572requires_config_enabled MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3573requires_max_content_len 513
3574run_test    "Connection ID: Cli+Srv enabled, variable buffer lengths, MFL=512" \
3575            "$P_SRV dtls=1 cid=1 cid_val=dead debug_level=2" \
3576            "$P_CLI force_ciphersuite="TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" max_frag_len=512 dtls=1 cid=1 cid_val=beef" \
3577            0 \
3578            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3579            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3580            -s "(initial handshake) Use of Connection ID has been negotiated" \
3581            -c "(initial handshake) Use of Connection ID has been negotiated" \
3582            -s "Reallocating in_buf" \
3583            -s "Reallocating out_buf"
3584
3585requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3586requires_config_enabled MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3587requires_max_content_len 1025
3588run_test    "Connection ID: Cli+Srv enabled, variable buffer lengths, MFL=1024" \
3589            "$P_SRV dtls=1 cid=1 cid_val=dead debug_level=2" \
3590            "$P_CLI force_ciphersuite="TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" max_frag_len=1024 dtls=1 cid=1 cid_val=beef" \
3591            0 \
3592            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3593            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3594            -s "(initial handshake) Use of Connection ID has been negotiated" \
3595            -c "(initial handshake) Use of Connection ID has been negotiated" \
3596            -s "Reallocating in_buf" \
3597            -s "Reallocating out_buf"
3598
3599# Tests for Encrypt-then-MAC extension
3600
3601run_test    "Encrypt then MAC: default" \
3602            "$P_SRV debug_level=3 \
3603             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3604            "$P_CLI debug_level=3" \
3605            0 \
3606            -c "client hello, adding encrypt_then_mac extension" \
3607            -s "found encrypt then mac extension" \
3608            -s "server hello, adding encrypt then mac extension" \
3609            -c "found encrypt_then_mac extension" \
3610            -c "using encrypt then mac" \
3611            -s "using encrypt then mac"
3612
3613run_test    "Encrypt then MAC: client enabled, server disabled" \
3614            "$P_SRV debug_level=3 etm=0 \
3615             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3616            "$P_CLI debug_level=3 etm=1" \
3617            0 \
3618            -c "client hello, adding encrypt_then_mac extension" \
3619            -s "found encrypt then mac extension" \
3620            -S "server hello, adding encrypt then mac extension" \
3621            -C "found encrypt_then_mac extension" \
3622            -C "using encrypt then mac" \
3623            -S "using encrypt then mac"
3624
3625run_test    "Encrypt then MAC: client enabled, aead cipher" \
3626            "$P_SRV debug_level=3 etm=1 \
3627             force_ciphersuite=TLS-RSA-WITH-AES-128-GCM-SHA256" \
3628            "$P_CLI debug_level=3 etm=1" \
3629            0 \
3630            -c "client hello, adding encrypt_then_mac extension" \
3631            -s "found encrypt then mac extension" \
3632            -S "server hello, adding encrypt then mac extension" \
3633            -C "found encrypt_then_mac extension" \
3634            -C "using encrypt then mac" \
3635            -S "using encrypt then mac"
3636
3637run_test    "Encrypt then MAC: client disabled, server enabled" \
3638            "$P_SRV debug_level=3 etm=1 \
3639             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3640            "$P_CLI debug_level=3 etm=0" \
3641            0 \
3642            -C "client hello, adding encrypt_then_mac extension" \
3643            -S "found encrypt then mac extension" \
3644            -S "server hello, adding encrypt then mac extension" \
3645            -C "found encrypt_then_mac extension" \
3646            -C "using encrypt then mac" \
3647            -S "using encrypt then mac"
3648
3649# Tests for Extended Master Secret extension
3650
3651requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3652run_test    "Extended Master Secret: default" \
3653            "$P_SRV debug_level=3" \
3654            "$P_CLI force_version=tls12 debug_level=3" \
3655            0 \
3656            -c "client hello, adding extended_master_secret extension" \
3657            -s "found extended master secret extension" \
3658            -s "server hello, adding extended master secret extension" \
3659            -c "found extended_master_secret extension" \
3660            -c "session hash for extended master secret" \
3661            -s "session hash for extended master secret"
3662
3663requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3664run_test    "Extended Master Secret: client enabled, server disabled" \
3665            "$P_SRV debug_level=3 extended_ms=0" \
3666            "$P_CLI force_version=tls12 debug_level=3 extended_ms=1" \
3667            0 \
3668            -c "client hello, adding extended_master_secret extension" \
3669            -s "found extended master secret extension" \
3670            -S "server hello, adding extended master secret extension" \
3671            -C "found extended_master_secret extension" \
3672            -C "session hash for extended master secret" \
3673            -S "session hash for extended master secret"
3674
3675requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3676run_test    "Extended Master Secret: client disabled, server enabled" \
3677            "$P_SRV force_version=tls12 debug_level=3 extended_ms=1" \
3678            "$P_CLI debug_level=3 extended_ms=0" \
3679            0 \
3680            -C "client hello, adding extended_master_secret extension" \
3681            -S "found extended master secret extension" \
3682            -S "server hello, adding extended master secret extension" \
3683            -C "found extended_master_secret extension" \
3684            -C "session hash for extended master secret" \
3685            -S "session hash for extended master secret"
3686
3687# Test sending and receiving empty application data records
3688
3689run_test    "Encrypt then MAC: empty application data record" \
3690            "$P_SRV auth_mode=none debug_level=4 etm=1" \
3691            "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA" \
3692            0 \
3693            -S "0000:  0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
3694            -s "dumping 'input payload after decrypt' (0 bytes)" \
3695            -c "0 bytes written in 1 fragments"
3696
3697requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3698run_test    "Encrypt then MAC: disabled, empty application data record" \
3699            "$P_SRV auth_mode=none debug_level=4 etm=0" \
3700            "$P_CLI auth_mode=none etm=0 request_size=0" \
3701            0 \
3702            -s "dumping 'input payload after decrypt' (0 bytes)" \
3703            -c "0 bytes written in 1 fragments"
3704
3705run_test    "Encrypt then MAC, DTLS: empty application data record" \
3706            "$P_SRV auth_mode=none debug_level=4 etm=1 dtls=1" \
3707            "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA dtls=1" \
3708            0 \
3709            -S "0000:  0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
3710            -s "dumping 'input payload after decrypt' (0 bytes)" \
3711            -c "0 bytes written in 1 fragments"
3712
3713requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3714run_test    "Encrypt then MAC, DTLS: disabled, empty application data record" \
3715            "$P_SRV auth_mode=none debug_level=4 etm=0 dtls=1" \
3716            "$P_CLI auth_mode=none etm=0 request_size=0 dtls=1" \
3717            0 \
3718            -s "dumping 'input payload after decrypt' (0 bytes)" \
3719            -c "0 bytes written in 1 fragments"
3720
3721# Tests for CBC 1/n-1 record splitting
3722
3723run_test    "CBC Record splitting: TLS 1.2, no splitting" \
3724            "$P_SRV force_version=tls12" \
3725            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
3726             request_size=123" \
3727            0 \
3728            -s "Read from client: 123 bytes read" \
3729            -S "Read from client: 1 bytes read" \
3730            -S "122 bytes read"
3731
3732# Tests for Session Tickets
3733
3734run_test    "Session resume using tickets: basic" \
3735            "$P_SRV debug_level=3 tickets=1" \
3736            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3737            0 \
3738            -c "client hello, adding session ticket extension" \
3739            -s "found session ticket extension" \
3740            -s "server hello, adding session ticket extension" \
3741            -c "found session_ticket extension" \
3742            -c "parse new session ticket" \
3743            -S "session successfully restored from cache" \
3744            -s "session successfully restored from ticket" \
3745            -s "a session has been resumed" \
3746            -c "a session has been resumed"
3747
3748run_test    "Session resume using tickets: manual rotation" \
3749            "$P_SRV debug_level=3 tickets=1 ticket_rotate=1" \
3750            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3751            0 \
3752            -c "client hello, adding session ticket extension" \
3753            -s "found session ticket extension" \
3754            -s "server hello, adding session ticket extension" \
3755            -c "found session_ticket extension" \
3756            -c "parse new session ticket" \
3757            -S "session successfully restored from cache" \
3758            -s "session successfully restored from ticket" \
3759            -s "a session has been resumed" \
3760            -c "a session has been resumed"
3761
3762run_test    "Session resume using tickets: cache disabled" \
3763            "$P_SRV debug_level=3 tickets=1 cache_max=0" \
3764            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3765            0 \
3766            -c "client hello, adding session ticket extension" \
3767            -s "found session ticket extension" \
3768            -s "server hello, adding session ticket extension" \
3769            -c "found session_ticket extension" \
3770            -c "parse new session ticket" \
3771            -S "session successfully restored from cache" \
3772            -s "session successfully restored from ticket" \
3773            -s "a session has been resumed" \
3774            -c "a session has been resumed"
3775
3776run_test    "Session resume using tickets: timeout" \
3777            "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
3778            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1 reco_delay=2000" \
3779            0 \
3780            -c "client hello, adding session ticket extension" \
3781            -s "found session ticket extension" \
3782            -s "server hello, adding session ticket extension" \
3783            -c "found session_ticket extension" \
3784            -c "parse new session ticket" \
3785            -S "session successfully restored from cache" \
3786            -S "session successfully restored from ticket" \
3787            -S "a session has been resumed" \
3788            -C "a session has been resumed"
3789
3790run_test    "Session resume using tickets: session copy" \
3791            "$P_SRV debug_level=3 tickets=1 cache_max=0" \
3792            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1 reco_mode=0" \
3793            0 \
3794            -c "client hello, adding session ticket extension" \
3795            -s "found session ticket extension" \
3796            -s "server hello, adding session ticket extension" \
3797            -c "found session_ticket extension" \
3798            -c "parse new session ticket" \
3799            -S "session successfully restored from cache" \
3800            -s "session successfully restored from ticket" \
3801            -s "a session has been resumed" \
3802            -c "a session has been resumed"
3803
3804requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3805run_test    "Session resume using tickets: openssl server" \
3806            "$O_SRV -tls1_2" \
3807            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3808            0 \
3809            -c "client hello, adding session ticket extension" \
3810            -c "found session_ticket extension" \
3811            -c "parse new session ticket" \
3812            -c "a session has been resumed"
3813
3814requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3815run_test    "Session resume using tickets: openssl client" \
3816            "$P_SRV debug_level=3 tickets=1" \
3817            "( $O_CLI -sess_out $SESSION; \
3818               $O_CLI -sess_in $SESSION; \
3819               rm -f $SESSION )" \
3820            0 \
3821            -s "found session ticket extension" \
3822            -s "server hello, adding session ticket extension" \
3823            -S "session successfully restored from cache" \
3824            -s "session successfully restored from ticket" \
3825            -s "a session has been resumed"
3826
3827requires_cipher_enabled "AES" "GCM"
3828run_test    "Session resume using tickets: AES-128-GCM" \
3829            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-128-GCM" \
3830            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3831            0 \
3832            -c "client hello, adding session ticket extension" \
3833            -s "found session ticket extension" \
3834            -s "server hello, adding session ticket extension" \
3835            -c "found session_ticket extension" \
3836            -c "parse new session ticket" \
3837            -S "session successfully restored from cache" \
3838            -s "session successfully restored from ticket" \
3839            -s "a session has been resumed" \
3840            -c "a session has been resumed"
3841
3842requires_cipher_enabled "AES" "GCM"
3843run_test    "Session resume using tickets: AES-192-GCM" \
3844            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-192-GCM" \
3845            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3846            0 \
3847            -c "client hello, adding session ticket extension" \
3848            -s "found session ticket extension" \
3849            -s "server hello, adding session ticket extension" \
3850            -c "found session_ticket extension" \
3851            -c "parse new session ticket" \
3852            -S "session successfully restored from cache" \
3853            -s "session successfully restored from ticket" \
3854            -s "a session has been resumed" \
3855            -c "a session has been resumed"
3856
3857requires_cipher_enabled "AES" "CCM"
3858run_test    "Session resume using tickets: AES-128-CCM" \
3859            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-128-CCM" \
3860            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3861            0 \
3862            -c "client hello, adding session ticket extension" \
3863            -s "found session ticket extension" \
3864            -s "server hello, adding session ticket extension" \
3865            -c "found session_ticket extension" \
3866            -c "parse new session ticket" \
3867            -S "session successfully restored from cache" \
3868            -s "session successfully restored from ticket" \
3869            -s "a session has been resumed" \
3870            -c "a session has been resumed"
3871
3872requires_cipher_enabled "AES" "CCM"
3873run_test    "Session resume using tickets: AES-192-CCM" \
3874            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-192-CCM" \
3875            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3876            0 \
3877            -c "client hello, adding session ticket extension" \
3878            -s "found session ticket extension" \
3879            -s "server hello, adding session ticket extension" \
3880            -c "found session_ticket extension" \
3881            -c "parse new session ticket" \
3882            -S "session successfully restored from cache" \
3883            -s "session successfully restored from ticket" \
3884            -s "a session has been resumed" \
3885            -c "a session has been resumed"
3886
3887requires_cipher_enabled "AES" "CCM"
3888run_test    "Session resume using tickets: AES-256-CCM" \
3889            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-256-CCM" \
3890            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3891            0 \
3892            -c "client hello, adding session ticket extension" \
3893            -s "found session ticket extension" \
3894            -s "server hello, adding session ticket extension" \
3895            -c "found session_ticket extension" \
3896            -c "parse new session ticket" \
3897            -S "session successfully restored from cache" \
3898            -s "session successfully restored from ticket" \
3899            -s "a session has been resumed" \
3900            -c "a session has been resumed"
3901
3902requires_cipher_enabled "CAMELLIA" "CCM"
3903run_test    "Session resume using tickets: CAMELLIA-128-CCM" \
3904            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-128-CCM" \
3905            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3906            0 \
3907            -c "client hello, adding session ticket extension" \
3908            -s "found session ticket extension" \
3909            -s "server hello, adding session ticket extension" \
3910            -c "found session_ticket extension" \
3911            -c "parse new session ticket" \
3912            -S "session successfully restored from cache" \
3913            -s "session successfully restored from ticket" \
3914            -s "a session has been resumed" \
3915            -c "a session has been resumed"
3916
3917requires_cipher_enabled "CAMELLIA" "CCM"
3918run_test    "Session resume using tickets: CAMELLIA-192-CCM" \
3919            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-192-CCM" \
3920            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3921            0 \
3922            -c "client hello, adding session ticket extension" \
3923            -s "found session ticket extension" \
3924            -s "server hello, adding session ticket extension" \
3925            -c "found session_ticket extension" \
3926            -c "parse new session ticket" \
3927            -S "session successfully restored from cache" \
3928            -s "session successfully restored from ticket" \
3929            -s "a session has been resumed" \
3930            -c "a session has been resumed"
3931
3932requires_cipher_enabled "CAMELLIA" "CCM"
3933run_test    "Session resume using tickets: CAMELLIA-256-CCM" \
3934            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-256-CCM" \
3935            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3936            0 \
3937            -c "client hello, adding session ticket extension" \
3938            -s "found session ticket extension" \
3939            -s "server hello, adding session ticket extension" \
3940            -c "found session_ticket extension" \
3941            -c "parse new session ticket" \
3942            -S "session successfully restored from cache" \
3943            -s "session successfully restored from ticket" \
3944            -s "a session has been resumed" \
3945            -c "a session has been resumed"
3946
3947requires_cipher_enabled "ARIA" "GCM"
3948run_test    "Session resume using tickets: ARIA-128-GCM" \
3949            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-128-GCM" \
3950            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3951            0 \
3952            -c "client hello, adding session ticket extension" \
3953            -s "found session ticket extension" \
3954            -s "server hello, adding session ticket extension" \
3955            -c "found session_ticket extension" \
3956            -c "parse new session ticket" \
3957            -S "session successfully restored from cache" \
3958            -s "session successfully restored from ticket" \
3959            -s "a session has been resumed" \
3960            -c "a session has been resumed"
3961
3962requires_cipher_enabled "ARIA" "GCM"
3963run_test    "Session resume using tickets: ARIA-192-GCM" \
3964            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-192-GCM" \
3965            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3966            0 \
3967            -c "client hello, adding session ticket extension" \
3968            -s "found session ticket extension" \
3969            -s "server hello, adding session ticket extension" \
3970            -c "found session_ticket extension" \
3971            -c "parse new session ticket" \
3972            -S "session successfully restored from cache" \
3973            -s "session successfully restored from ticket" \
3974            -s "a session has been resumed" \
3975            -c "a session has been resumed"
3976
3977requires_cipher_enabled "ARIA" "GCM"
3978run_test    "Session resume using tickets: ARIA-256-GCM" \
3979            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-256-GCM" \
3980            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3981            0 \
3982            -c "client hello, adding session ticket extension" \
3983            -s "found session ticket extension" \
3984            -s "server hello, adding session ticket extension" \
3985            -c "found session_ticket extension" \
3986            -c "parse new session ticket" \
3987            -S "session successfully restored from cache" \
3988            -s "session successfully restored from ticket" \
3989            -s "a session has been resumed" \
3990            -c "a session has been resumed"
3991
3992requires_cipher_enabled "ARIA" "CCM"
3993run_test    "Session resume using tickets: ARIA-128-CCM" \
3994            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-128-CCM" \
3995            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
3996            0 \
3997            -c "client hello, adding session ticket extension" \
3998            -s "found session ticket extension" \
3999            -s "server hello, adding session ticket extension" \
4000            -c "found session_ticket extension" \
4001            -c "parse new session ticket" \
4002            -S "session successfully restored from cache" \
4003            -s "session successfully restored from ticket" \
4004            -s "a session has been resumed" \
4005            -c "a session has been resumed"
4006
4007requires_cipher_enabled "ARIA" "CCM"
4008run_test    "Session resume using tickets: ARIA-192-CCM" \
4009            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-192-CCM" \
4010            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
4011            0 \
4012            -c "client hello, adding session ticket extension" \
4013            -s "found session ticket extension" \
4014            -s "server hello, adding session ticket extension" \
4015            -c "found session_ticket extension" \
4016            -c "parse new session ticket" \
4017            -S "session successfully restored from cache" \
4018            -s "session successfully restored from ticket" \
4019            -s "a session has been resumed" \
4020            -c "a session has been resumed"
4021
4022requires_cipher_enabled "ARIA" "CCM"
4023run_test    "Session resume using tickets: ARIA-256-CCM" \
4024            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-256-CCM" \
4025            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
4026            0 \
4027            -c "client hello, adding session ticket extension" \
4028            -s "found session ticket extension" \
4029            -s "server hello, adding session ticket extension" \
4030            -c "found session_ticket extension" \
4031            -c "parse new session ticket" \
4032            -S "session successfully restored from cache" \
4033            -s "session successfully restored from ticket" \
4034            -s "a session has been resumed" \
4035            -c "a session has been resumed"
4036
4037requires_cipher_enabled "CHACHA20"
4038run_test    "Session resume using tickets: CHACHA20-POLY1305" \
4039            "$P_SRV debug_level=3 tickets=1 ticket_aead=CHACHA20-POLY1305" \
4040            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
4041            0 \
4042            -c "client hello, adding session ticket extension" \
4043            -s "found session ticket extension" \
4044            -s "server hello, adding session ticket extension" \
4045            -c "found session_ticket extension" \
4046            -c "parse new session ticket" \
4047            -S "session successfully restored from cache" \
4048            -s "session successfully restored from ticket" \
4049            -s "a session has been resumed" \
4050            -c "a session has been resumed"
4051
4052# Tests for Session Tickets with DTLS
4053
4054requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4055run_test    "Session resume using tickets, DTLS: basic" \
4056            "$P_SRV debug_level=3 dtls=1 tickets=1" \
4057            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1" \
4058            0 \
4059            -c "client hello, adding session ticket extension" \
4060            -s "found session ticket extension" \
4061            -s "server hello, adding session ticket extension" \
4062            -c "found session_ticket extension" \
4063            -c "parse new session ticket" \
4064            -S "session successfully restored from cache" \
4065            -s "session successfully restored from ticket" \
4066            -s "a session has been resumed" \
4067            -c "a session has been resumed"
4068
4069requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4070run_test    "Session resume using tickets, DTLS: cache disabled" \
4071            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0" \
4072            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1" \
4073            0 \
4074            -c "client hello, adding session ticket extension" \
4075            -s "found session ticket extension" \
4076            -s "server hello, adding session ticket extension" \
4077            -c "found session_ticket extension" \
4078            -c "parse new session ticket" \
4079            -S "session successfully restored from cache" \
4080            -s "session successfully restored from ticket" \
4081            -s "a session has been resumed" \
4082            -c "a session has been resumed"
4083
4084requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4085run_test    "Session resume using tickets, DTLS: timeout" \
4086            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0 ticket_timeout=1" \
4087            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1 reco_delay=2000" \
4088            0 \
4089            -c "client hello, adding session ticket extension" \
4090            -s "found session ticket extension" \
4091            -s "server hello, adding session ticket extension" \
4092            -c "found session_ticket extension" \
4093            -c "parse new session ticket" \
4094            -S "session successfully restored from cache" \
4095            -S "session successfully restored from ticket" \
4096            -S "a session has been resumed" \
4097            -C "a session has been resumed"
4098
4099requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4100run_test    "Session resume using tickets, DTLS: session copy" \
4101            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0" \
4102            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1 reco_mode=0" \
4103            0 \
4104            -c "client hello, adding session ticket extension" \
4105            -s "found session ticket extension" \
4106            -s "server hello, adding session ticket extension" \
4107            -c "found session_ticket extension" \
4108            -c "parse new session ticket" \
4109            -S "session successfully restored from cache" \
4110            -s "session successfully restored from ticket" \
4111            -s "a session has been resumed" \
4112            -c "a session has been resumed"
4113
4114requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4115run_test    "Session resume using tickets, DTLS: openssl server" \
4116            "$O_SRV -dtls" \
4117            "$P_CLI dtls=1 debug_level=3 tickets=1 reconnect=1" \
4118            0 \
4119            -c "client hello, adding session ticket extension" \
4120            -c "found session_ticket extension" \
4121            -c "parse new session ticket" \
4122            -c "a session has been resumed"
4123
4124# For reasons that aren't fully understood, this test randomly fails with high
4125# probability with OpenSSL 1.0.2g on the CI, see #5012.
4126requires_openssl_next
4127requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4128run_test    "Session resume using tickets, DTLS: openssl client" \
4129            "$P_SRV dtls=1 debug_level=3 tickets=1" \
4130            "( $O_NEXT_CLI -dtls -sess_out $SESSION; \
4131               $O_NEXT_CLI -dtls -sess_in $SESSION; \
4132               rm -f $SESSION )" \
4133            0 \
4134            -s "found session ticket extension" \
4135            -s "server hello, adding session ticket extension" \
4136            -S "session successfully restored from cache" \
4137            -s "session successfully restored from ticket" \
4138            -s "a session has been resumed"
4139
4140# Tests for Session Resume based on session-ID and cache
4141
4142requires_config_enabled MBEDTLS_SSL_CACHE_C
4143run_test    "Session resume using cache: tickets enabled on client" \
4144            "$P_SRV debug_level=3 tickets=0" \
4145            "$P_CLI force_version=tls12 debug_level=3 tickets=1 reconnect=1" \
4146            0 \
4147            -c "client hello, adding session ticket extension" \
4148            -s "found session ticket extension" \
4149            -S "server hello, adding session ticket extension" \
4150            -C "found session_ticket extension" \
4151            -C "parse new session ticket" \
4152            -s "session successfully restored from cache" \
4153            -S "session successfully restored from ticket" \
4154            -s "a session has been resumed" \
4155            -c "a session has been resumed"
4156
4157requires_config_enabled MBEDTLS_SSL_CACHE_C
4158run_test    "Session resume using cache: tickets enabled on server" \
4159            "$P_SRV debug_level=3 tickets=1" \
4160            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1" \
4161            0 \
4162            -C "client hello, adding session ticket extension" \
4163            -S "found session ticket extension" \
4164            -S "server hello, adding session ticket extension" \
4165            -C "found session_ticket extension" \
4166            -C "parse new session ticket" \
4167            -s "session successfully restored from cache" \
4168            -S "session successfully restored from ticket" \
4169            -s "a session has been resumed" \
4170            -c "a session has been resumed"
4171
4172requires_config_enabled MBEDTLS_SSL_CACHE_C
4173run_test    "Session resume using cache: cache_max=0" \
4174            "$P_SRV debug_level=3 tickets=0 cache_max=0" \
4175            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1" \
4176            0 \
4177            -S "session successfully restored from cache" \
4178            -S "session successfully restored from ticket" \
4179            -S "a session has been resumed" \
4180            -C "a session has been resumed"
4181
4182requires_config_enabled MBEDTLS_SSL_CACHE_C
4183run_test    "Session resume using cache: cache_max=1" \
4184            "$P_SRV debug_level=3 tickets=0 cache_max=1" \
4185            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1" \
4186            0 \
4187            -s "session successfully restored from cache" \
4188            -S "session successfully restored from ticket" \
4189            -s "a session has been resumed" \
4190            -c "a session has been resumed"
4191
4192requires_config_enabled MBEDTLS_SSL_CACHE_C
4193run_test    "Session resume using cache: cache removed" \
4194            "$P_SRV debug_level=3 tickets=0 cache_remove=1" \
4195            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1" \
4196            0 \
4197            -C "client hello, adding session ticket extension" \
4198            -S "found session ticket extension" \
4199            -S "server hello, adding session ticket extension" \
4200            -C "found session_ticket extension" \
4201            -C "parse new session ticket" \
4202            -S "session successfully restored from cache" \
4203            -S "session successfully restored from ticket" \
4204            -S "a session has been resumed" \
4205            -C "a session has been resumed"
4206
4207requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4208requires_config_enabled MBEDTLS_SSL_CACHE_C
4209run_test    "Session resume using cache: timeout > delay" \
4210            "$P_SRV debug_level=3 tickets=0" \
4211            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
4212            0 \
4213            -s "session successfully restored from cache" \
4214            -S "session successfully restored from ticket" \
4215            -s "a session has been resumed" \
4216            -c "a session has been resumed"
4217
4218requires_config_enabled MBEDTLS_SSL_CACHE_C
4219run_test    "Session resume using cache: timeout < delay" \
4220            "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
4221            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1 reco_delay=2000" \
4222            0 \
4223            -S "session successfully restored from cache" \
4224            -S "session successfully restored from ticket" \
4225            -S "a session has been resumed" \
4226            -C "a session has been resumed"
4227
4228requires_config_enabled MBEDTLS_SSL_CACHE_C
4229run_test    "Session resume using cache: no timeout" \
4230            "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
4231            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1 reco_delay=2000" \
4232            0 \
4233            -s "session successfully restored from cache" \
4234            -S "session successfully restored from ticket" \
4235            -s "a session has been resumed" \
4236            -c "a session has been resumed"
4237
4238requires_config_enabled MBEDTLS_SSL_CACHE_C
4239run_test    "Session resume using cache: session copy" \
4240            "$P_SRV debug_level=3 tickets=0" \
4241            "$P_CLI force_version=tls12 debug_level=3 tickets=0 reconnect=1 reco_mode=0" \
4242            0 \
4243            -s "session successfully restored from cache" \
4244            -S "session successfully restored from ticket" \
4245            -s "a session has been resumed" \
4246            -c "a session has been resumed"
4247
4248requires_config_enabled MBEDTLS_SSL_CACHE_C
4249run_test    "Session resume using cache: openssl client" \
4250            "$P_SRV force_version=tls12 debug_level=3 tickets=0" \
4251            "( $O_CLI -sess_out $SESSION; \
4252               $O_CLI -sess_in $SESSION; \
4253               rm -f $SESSION )" \
4254            0 \
4255            -s "found session ticket extension" \
4256            -S "server hello, adding session ticket extension" \
4257            -s "session successfully restored from cache" \
4258            -S "session successfully restored from ticket" \
4259            -s "a session has been resumed"
4260
4261requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4262requires_config_enabled MBEDTLS_SSL_CACHE_C
4263run_test    "Session resume using cache: openssl server" \
4264            "$O_SRV -tls1_2" \
4265            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4266            0 \
4267            -C "found session_ticket extension" \
4268            -C "parse new session ticket" \
4269            -c "a session has been resumed"
4270
4271# Tests for Session resume and extensions
4272
4273requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4274requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
4275run_test    "Session resume and connection ID" \
4276            "$P_SRV debug_level=3 cid=1 cid_val=dead dtls=1 tickets=0" \
4277            "$P_CLI debug_level=3 cid=1 cid_val=beef dtls=1 tickets=0 reconnect=1" \
4278            0 \
4279            -c "Enable use of CID extension." \
4280            -s "Enable use of CID extension." \
4281            -c "client hello, adding CID extension" \
4282            -s "found CID extension"           \
4283            -s "Use of CID extension negotiated" \
4284            -s "server hello, adding CID extension" \
4285            -c "found CID extension" \
4286            -c "Use of CID extension negotiated" \
4287            -s "Copy CIDs into SSL transform" \
4288            -c "Copy CIDs into SSL transform" \
4289            -c "Peer CID (length 2 Bytes): de ad" \
4290            -s "Peer CID (length 2 Bytes): be ef" \
4291            -s "Use of Connection ID has been negotiated" \
4292            -c "Use of Connection ID has been negotiated"
4293
4294# Tests for Session Resume based on session-ID and cache, DTLS
4295
4296requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4297requires_config_enabled MBEDTLS_SSL_CACHE_C
4298run_test    "Session resume using cache, DTLS: tickets enabled on client" \
4299            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4300            "$P_CLI dtls=1 debug_level=3 tickets=1 reconnect=1 skip_close_notify=1" \
4301            0 \
4302            -c "client hello, adding session ticket extension" \
4303            -s "found session ticket extension" \
4304            -S "server hello, adding session ticket extension" \
4305            -C "found session_ticket extension" \
4306            -C "parse new session ticket" \
4307            -s "session successfully restored from cache" \
4308            -S "session successfully restored from ticket" \
4309            -s "a session has been resumed" \
4310            -c "a session has been resumed"
4311
4312requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4313requires_config_enabled MBEDTLS_SSL_CACHE_C
4314run_test    "Session resume using cache, DTLS: tickets enabled on server" \
4315            "$P_SRV dtls=1 debug_level=3 tickets=1" \
4316            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4317            0 \
4318            -C "client hello, adding session ticket extension" \
4319            -S "found session ticket extension" \
4320            -S "server hello, adding session ticket extension" \
4321            -C "found session_ticket extension" \
4322            -C "parse new session ticket" \
4323            -s "session successfully restored from cache" \
4324            -S "session successfully restored from ticket" \
4325            -s "a session has been resumed" \
4326            -c "a session has been resumed"
4327
4328requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4329requires_config_enabled MBEDTLS_SSL_CACHE_C
4330run_test    "Session resume using cache, DTLS: cache_max=0" \
4331            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_max=0" \
4332            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4333            0 \
4334            -S "session successfully restored from cache" \
4335            -S "session successfully restored from ticket" \
4336            -S "a session has been resumed" \
4337            -C "a session has been resumed"
4338
4339requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4340requires_config_enabled MBEDTLS_SSL_CACHE_C
4341run_test    "Session resume using cache, DTLS: cache_max=1" \
4342            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_max=1" \
4343            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4344            0 \
4345            -s "session successfully restored from cache" \
4346            -S "session successfully restored from ticket" \
4347            -s "a session has been resumed" \
4348            -c "a session has been resumed"
4349
4350requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4351requires_config_enabled MBEDTLS_SSL_CACHE_C
4352run_test    "Session resume using cache, DTLS: timeout > delay" \
4353            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4354            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=0" \
4355            0 \
4356            -s "session successfully restored from cache" \
4357            -S "session successfully restored from ticket" \
4358            -s "a session has been resumed" \
4359            -c "a session has been resumed"
4360
4361requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4362requires_config_enabled MBEDTLS_SSL_CACHE_C
4363run_test    "Session resume using cache, DTLS: timeout < delay" \
4364            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_timeout=1" \
4365            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=2000" \
4366            0 \
4367            -S "session successfully restored from cache" \
4368            -S "session successfully restored from ticket" \
4369            -S "a session has been resumed" \
4370            -C "a session has been resumed"
4371
4372requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4373requires_config_enabled MBEDTLS_SSL_CACHE_C
4374run_test    "Session resume using cache, DTLS: no timeout" \
4375            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_timeout=0" \
4376            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=2000" \
4377            0 \
4378            -s "session successfully restored from cache" \
4379            -S "session successfully restored from ticket" \
4380            -s "a session has been resumed" \
4381            -c "a session has been resumed"
4382
4383requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4384requires_config_enabled MBEDTLS_SSL_CACHE_C
4385run_test    "Session resume using cache, DTLS: session copy" \
4386            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4387            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_mode=0" \
4388            0 \
4389            -s "session successfully restored from cache" \
4390            -S "session successfully restored from ticket" \
4391            -s "a session has been resumed" \
4392            -c "a session has been resumed"
4393
4394# For reasons that aren't fully understood, this test randomly fails with high
4395# probability with OpenSSL 1.0.2g on the CI, see #5012.
4396requires_openssl_next
4397requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4398requires_config_enabled MBEDTLS_SSL_CACHE_C
4399run_test    "Session resume using cache, DTLS: openssl client" \
4400            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4401            "( $O_NEXT_CLI -dtls -sess_out $SESSION; \
4402               $O_NEXT_CLI -dtls -sess_in $SESSION; \
4403               rm -f $SESSION )" \
4404            0 \
4405            -s "found session ticket extension" \
4406            -S "server hello, adding session ticket extension" \
4407            -s "session successfully restored from cache" \
4408            -S "session successfully restored from ticket" \
4409            -s "a session has been resumed"
4410
4411requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4412requires_config_enabled MBEDTLS_SSL_CACHE_C
4413run_test    "Session resume using cache, DTLS: openssl server" \
4414            "$O_SRV -dtls" \
4415            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1" \
4416            0 \
4417            -C "found session_ticket extension" \
4418            -C "parse new session ticket" \
4419            -c "a session has been resumed"
4420
4421# Tests for Max Fragment Length extension
4422
4423requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4424requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4425run_test    "Max fragment length: enabled, default" \
4426            "$P_SRV debug_level=3 force_version=tls12" \
4427            "$P_CLI debug_level=3" \
4428            0 \
4429            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4430            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4431            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4432            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4433            -C "client hello, adding max_fragment_length extension" \
4434            -S "found max fragment length extension" \
4435            -S "server hello, max_fragment_length extension" \
4436            -C "found max_fragment_length extension"
4437
4438requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4439requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4440run_test    "Max fragment length: enabled, default, larger message" \
4441            "$P_SRV debug_level=3 force_version=tls12" \
4442            "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4443            0 \
4444            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4445            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4446            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4447            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4448            -C "client hello, adding max_fragment_length extension" \
4449            -S "found max fragment length extension" \
4450            -S "server hello, max_fragment_length extension" \
4451            -C "found max_fragment_length extension" \
4452            -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
4453            -s "$MAX_CONTENT_LEN bytes read" \
4454            -s "1 bytes read"
4455
4456requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4457requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4458run_test    "Max fragment length, DTLS: enabled, default, larger message" \
4459            "$P_SRV debug_level=3 dtls=1" \
4460            "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4461            1 \
4462            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4463            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4464            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4465            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4466            -C "client hello, adding max_fragment_length extension" \
4467            -S "found max fragment length extension" \
4468            -S "server hello, max_fragment_length extension" \
4469            -C "found max_fragment_length extension" \
4470            -c "fragment larger than.*maximum "
4471
4472# Run some tests with MBEDTLS_SSL_MAX_FRAGMENT_LENGTH disabled
4473# (session fragment length will be 16384 regardless of mbedtls
4474# content length configuration.)
4475
4476requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4477requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4478run_test    "Max fragment length: disabled, larger message" \
4479            "$P_SRV debug_level=3 force_version=tls12" \
4480            "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4481            0 \
4482            -C "Maximum incoming record payload length is 16384" \
4483            -C "Maximum outgoing record payload length is 16384" \
4484            -S "Maximum incoming record payload length is 16384" \
4485            -S "Maximum outgoing record payload length is 16384" \
4486            -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
4487            -s "$MAX_CONTENT_LEN bytes read" \
4488            -s "1 bytes read"
4489
4490requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4491requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4492run_test    "Max fragment length, DTLS: disabled, larger message" \
4493            "$P_SRV debug_level=3 dtls=1 force_version=tls12" \
4494            "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4495            1 \
4496            -C "Maximum incoming record payload length is 16384" \
4497            -C "Maximum outgoing record payload length is 16384" \
4498            -S "Maximum incoming record payload length is 16384" \
4499            -S "Maximum outgoing record payload length is 16384" \
4500            -c "fragment larger than.*maximum "
4501
4502requires_max_content_len 4096
4503requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4504run_test    "Max fragment length: used by client" \
4505            "$P_SRV debug_level=3" \
4506            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=4096" \
4507            0 \
4508            -c "Maximum incoming record payload length is 4096" \
4509            -c "Maximum outgoing record payload length is 4096" \
4510            -s "Maximum incoming record payload length is 4096" \
4511            -s "Maximum outgoing record payload length is 4096" \
4512            -c "client hello, adding max_fragment_length extension" \
4513            -s "found max fragment length extension" \
4514            -s "server hello, max_fragment_length extension" \
4515            -c "found max_fragment_length extension"
4516
4517requires_max_content_len 1024
4518requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4519run_test    "Max fragment length: client 512, server 1024" \
4520            "$P_SRV debug_level=3 max_frag_len=1024" \
4521            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=512" \
4522            0 \
4523            -c "Maximum incoming record payload length is 512" \
4524            -c "Maximum outgoing record payload length is 512" \
4525            -s "Maximum incoming record payload length is 512" \
4526            -s "Maximum outgoing record payload length is 512" \
4527            -c "client hello, adding max_fragment_length extension" \
4528            -s "found max fragment length extension" \
4529            -s "server hello, max_fragment_length extension" \
4530            -c "found max_fragment_length extension"
4531
4532requires_max_content_len 2048
4533requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4534run_test    "Max fragment length: client 512, server 2048" \
4535            "$P_SRV debug_level=3 max_frag_len=2048" \
4536            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=512" \
4537            0 \
4538            -c "Maximum incoming record payload length is 512" \
4539            -c "Maximum outgoing record payload length is 512" \
4540            -s "Maximum incoming record payload length is 512" \
4541            -s "Maximum outgoing record payload length is 512" \
4542            -c "client hello, adding max_fragment_length extension" \
4543            -s "found max fragment length extension" \
4544            -s "server hello, max_fragment_length extension" \
4545            -c "found max_fragment_length extension"
4546
4547requires_max_content_len 4096
4548requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4549run_test    "Max fragment length: client 512, server 4096" \
4550            "$P_SRV debug_level=3 max_frag_len=4096" \
4551            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=512" \
4552            0 \
4553            -c "Maximum incoming record payload length is 512" \
4554            -c "Maximum outgoing record payload length is 512" \
4555            -s "Maximum incoming record payload length is 512" \
4556            -s "Maximum outgoing record payload length is 512" \
4557            -c "client hello, adding max_fragment_length extension" \
4558            -s "found max fragment length extension" \
4559            -s "server hello, max_fragment_length extension" \
4560            -c "found max_fragment_length extension"
4561
4562requires_max_content_len 1024
4563requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4564run_test    "Max fragment length: client 1024, server 512" \
4565            "$P_SRV force_version=tls12 debug_level=3 max_frag_len=512" \
4566            "$P_CLI debug_level=3 max_frag_len=1024" \
4567            0 \
4568            -c "Maximum incoming record payload length is 1024" \
4569            -c "Maximum outgoing record payload length is 1024" \
4570            -s "Maximum incoming record payload length is 1024" \
4571            -s "Maximum outgoing record payload length is 512" \
4572            -c "client hello, adding max_fragment_length extension" \
4573            -s "found max fragment length extension" \
4574            -s "server hello, max_fragment_length extension" \
4575            -c "found max_fragment_length extension"
4576
4577requires_max_content_len 2048
4578requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4579run_test    "Max fragment length: client 1024, server 2048" \
4580            "$P_SRV debug_level=3 max_frag_len=2048" \
4581            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=1024" \
4582            0 \
4583            -c "Maximum incoming record payload length is 1024" \
4584            -c "Maximum outgoing record payload length is 1024" \
4585            -s "Maximum incoming record payload length is 1024" \
4586            -s "Maximum outgoing record payload length is 1024" \
4587            -c "client hello, adding max_fragment_length extension" \
4588            -s "found max fragment length extension" \
4589            -s "server hello, max_fragment_length extension" \
4590            -c "found max_fragment_length extension"
4591
4592requires_max_content_len 4096
4593requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4594run_test    "Max fragment length: client 1024, server 4096" \
4595            "$P_SRV debug_level=3 max_frag_len=4096" \
4596            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=1024" \
4597            0 \
4598            -c "Maximum incoming record payload length is 1024" \
4599            -c "Maximum outgoing record payload length is 1024" \
4600            -s "Maximum incoming record payload length is 1024" \
4601            -s "Maximum outgoing record payload length is 1024" \
4602            -c "client hello, adding max_fragment_length extension" \
4603            -s "found max fragment length extension" \
4604            -s "server hello, max_fragment_length extension" \
4605            -c "found max_fragment_length extension"
4606
4607requires_max_content_len 2048
4608requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4609run_test    "Max fragment length: client 2048, server 512" \
4610            "$P_SRV force_version=tls12 debug_level=3 max_frag_len=512" \
4611            "$P_CLI debug_level=3 max_frag_len=2048" \
4612            0 \
4613            -c "Maximum incoming record payload length is 2048" \
4614            -c "Maximum outgoing record payload length is 2048" \
4615            -s "Maximum incoming record payload length is 2048" \
4616            -s "Maximum outgoing record payload length is 512" \
4617            -c "client hello, adding max_fragment_length extension" \
4618            -s "found max fragment length extension" \
4619            -s "server hello, max_fragment_length extension" \
4620            -c "found max_fragment_length extension"
4621
4622requires_max_content_len 2048
4623requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4624run_test    "Max fragment length: client 2048, server 1024" \
4625            "$P_SRV force_version=tls12 debug_level=3 max_frag_len=1024" \
4626            "$P_CLI debug_level=3 max_frag_len=2048" \
4627            0 \
4628            -c "Maximum incoming record payload length is 2048" \
4629            -c "Maximum outgoing record payload length is 2048" \
4630            -s "Maximum incoming record payload length is 2048" \
4631            -s "Maximum outgoing record payload length is 1024" \
4632            -c "client hello, adding max_fragment_length extension" \
4633            -s "found max fragment length extension" \
4634            -s "server hello, max_fragment_length extension" \
4635            -c "found max_fragment_length extension"
4636
4637requires_max_content_len 4096
4638requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4639run_test    "Max fragment length: client 2048, server 4096" \
4640            "$P_SRV debug_level=3 max_frag_len=4096" \
4641            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=2048" \
4642            0 \
4643            -c "Maximum incoming record payload length is 2048" \
4644            -c "Maximum outgoing record payload length is 2048" \
4645            -s "Maximum incoming record payload length is 2048" \
4646            -s "Maximum outgoing record payload length is 2048" \
4647            -c "client hello, adding max_fragment_length extension" \
4648            -s "found max fragment length extension" \
4649            -s "server hello, max_fragment_length extension" \
4650            -c "found max_fragment_length extension"
4651
4652requires_max_content_len 4096
4653requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4654run_test    "Max fragment length: client 4096, server 512" \
4655            "$P_SRV force_version=tls12 debug_level=3 max_frag_len=512" \
4656            "$P_CLI debug_level=3 max_frag_len=4096" \
4657            0 \
4658            -c "Maximum incoming record payload length is 4096" \
4659            -c "Maximum outgoing record payload length is 4096" \
4660            -s "Maximum incoming record payload length is 4096" \
4661            -s "Maximum outgoing record payload length is 512" \
4662            -c "client hello, adding max_fragment_length extension" \
4663            -s "found max fragment length extension" \
4664            -s "server hello, max_fragment_length extension" \
4665            -c "found max_fragment_length extension"
4666
4667requires_max_content_len 4096
4668requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4669run_test    "Max fragment length: client 4096, server 1024" \
4670            "$P_SRV force_version=tls12 debug_level=3 max_frag_len=1024" \
4671            "$P_CLI debug_level=3 max_frag_len=4096" \
4672            0 \
4673            -c "Maximum incoming record payload length is 4096" \
4674            -c "Maximum outgoing record payload length is 4096" \
4675            -s "Maximum incoming record payload length is 4096" \
4676            -s "Maximum outgoing record payload length is 1024" \
4677            -c "client hello, adding max_fragment_length extension" \
4678            -s "found max fragment length extension" \
4679            -s "server hello, max_fragment_length extension" \
4680            -c "found max_fragment_length extension"
4681
4682requires_max_content_len 4096
4683requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4684run_test    "Max fragment length: client 4096, server 2048" \
4685            "$P_SRV force_version=tls12 debug_level=3 max_frag_len=2048" \
4686            "$P_CLI debug_level=3 max_frag_len=4096" \
4687            0 \
4688            -c "Maximum incoming record payload length is 4096" \
4689            -c "Maximum outgoing record payload length is 4096" \
4690            -s "Maximum incoming record payload length is 4096" \
4691            -s "Maximum outgoing record payload length is 2048" \
4692            -c "client hello, adding max_fragment_length extension" \
4693            -s "found max fragment length extension" \
4694            -s "server hello, max_fragment_length extension" \
4695            -c "found max_fragment_length extension"
4696
4697requires_max_content_len 4096
4698requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4699run_test    "Max fragment length: used by server" \
4700            "$P_SRV force_version=tls12 debug_level=3 max_frag_len=4096" \
4701            "$P_CLI debug_level=3" \
4702            0 \
4703            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4704            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4705            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4706            -s "Maximum outgoing record payload length is 4096" \
4707            -C "client hello, adding max_fragment_length extension" \
4708            -S "found max fragment length extension" \
4709            -S "server hello, max_fragment_length extension" \
4710            -C "found max_fragment_length extension"
4711
4712requires_max_content_len 4096
4713requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4714requires_gnutls
4715requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4716run_test    "Max fragment length: gnutls server" \
4717            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
4718            "$P_CLI debug_level=3 max_frag_len=4096" \
4719            0 \
4720            -c "Maximum incoming record payload length is 4096" \
4721            -c "Maximum outgoing record payload length is 4096" \
4722            -c "client hello, adding max_fragment_length extension" \
4723            -c "found max_fragment_length extension"
4724
4725requires_max_content_len 2048
4726requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4727run_test    "Max fragment length: client, message just fits" \
4728            "$P_SRV debug_level=3" \
4729            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=2048 request_size=2048" \
4730            0 \
4731            -c "Maximum incoming record payload length is 2048" \
4732            -c "Maximum outgoing record payload length is 2048" \
4733            -s "Maximum incoming record payload length is 2048" \
4734            -s "Maximum outgoing record payload length is 2048" \
4735            -c "client hello, adding max_fragment_length extension" \
4736            -s "found max fragment length extension" \
4737            -s "server hello, max_fragment_length extension" \
4738            -c "found max_fragment_length extension" \
4739            -c "2048 bytes written in 1 fragments" \
4740            -s "2048 bytes read"
4741
4742requires_max_content_len 2048
4743requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4744run_test    "Max fragment length: client, larger message" \
4745            "$P_SRV debug_level=3" \
4746            "$P_CLI force_version=tls12 debug_level=3 max_frag_len=2048 request_size=2345" \
4747            0 \
4748            -c "Maximum incoming record payload length is 2048" \
4749            -c "Maximum outgoing record payload length is 2048" \
4750            -s "Maximum incoming record payload length is 2048" \
4751            -s "Maximum outgoing record payload length is 2048" \
4752            -c "client hello, adding max_fragment_length extension" \
4753            -s "found max fragment length extension" \
4754            -s "server hello, max_fragment_length extension" \
4755            -c "found max_fragment_length extension" \
4756            -c "2345 bytes written in 2 fragments" \
4757            -s "2048 bytes read" \
4758            -s "297 bytes read"
4759
4760requires_max_content_len 2048
4761requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4762requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4763run_test    "Max fragment length: DTLS client, larger message" \
4764            "$P_SRV debug_level=3 dtls=1" \
4765            "$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
4766            1 \
4767            -c "Maximum incoming record payload length is 2048" \
4768            -c "Maximum outgoing record payload length is 2048" \
4769            -s "Maximum incoming record payload length is 2048" \
4770            -s "Maximum outgoing record payload length is 2048" \
4771            -c "client hello, adding max_fragment_length extension" \
4772            -s "found max fragment length extension" \
4773            -s "server hello, max_fragment_length extension" \
4774            -c "found max_fragment_length extension" \
4775            -c "fragment larger than.*maximum"
4776
4777# Tests for Record Size Limit extension
4778
4779requires_gnutls_tls1_3
4780requires_gnutls_record_size_limit
4781requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4782requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4783requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4784run_test    "Record Size Limit: TLS 1.3: Server-side parsing and debug output" \
4785            "$P_SRV debug_level=3 force_version=tls13" \
4786            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4" \
4787            0 \
4788            -s "RecordSizeLimit: 16385 Bytes" \
4789            -s "ClientHello: record_size_limit(28) extension exists." \
4790            -s "Maximum outgoing record payload length is 16383" \
4791            -s "bytes written in 1 fragments"
4792
4793requires_gnutls_tls1_3
4794requires_gnutls_record_size_limit
4795requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
4796requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4797requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4798run_test    "Record Size Limit: TLS 1.3: Client-side parsing and debug output" \
4799            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL --disable-client-cert -d 4" \
4800            "$P_CLI debug_level=4 force_version=tls13" \
4801            0 \
4802            -c "Sent RecordSizeLimit: 16384 Bytes"                                      \
4803            -c "ClientHello: record_size_limit(28) extension exists."                   \
4804            -c "EncryptedExtensions: record_size_limit(28) extension received."         \
4805            -c "RecordSizeLimit: 16385 Bytes"                                           \
4806
4807# In the following tests, --recordsize is the value used by the G_NEXT_CLI (3.7.2) to configure the
4808# maximum record size using gnutls_record_set_max_size()
4809# (https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-size).
4810# There is currently a lower limit of 512, caused by gnutls_record_set_max_size()
4811# not respecting the "%ALLOW_SMALL_RECORDS" priority string and not using the
4812# more recent function gnutls_record_set_max_recv_size()
4813# (https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-recv-size).
4814# There is currently an upper limit of 4096, caused by the cli arg parser:
4815# https://gitlab.com/gnutls/gnutls/-/blob/3.7.2/src/cli-args.def#L395.
4816# Thus, these tests are currently limited to the value range 512-4096.
4817# Also, the value sent in the extension will be one larger than the value
4818# set at the command line:
4819# https://gitlab.com/gnutls/gnutls/-/blob/3.7.2/lib/ext/record_size_limit.c#L142
4820
4821# Currently test certificates being used do not fit in 513 record size limit
4822# so for 513 record size limit tests we use preshared key to avoid sending
4823# the certificate.
4824
4825requires_gnutls_tls1_3
4826requires_gnutls_record_size_limit
4827requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4828requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4829requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4830run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (513), 1 fragment" \
4831            "$P_SRV debug_level=3 force_version=tls13 tls13_kex_modes=psk \
4832                    psk_list=Client_identity,6162636465666768696a6b6c6d6e6f70 \
4833                    response_size=256" \
4834            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK --recordsize 512 \
4835                    --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" \
4836            0 \
4837            -s "RecordSizeLimit: 513 Bytes" \
4838            -s "ClientHello: record_size_limit(28) extension exists." \
4839            -s "Sent RecordSizeLimit: 16384 Bytes" \
4840            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4841            -s "Maximum outgoing record payload length is 511" \
4842            -s "256 bytes written in 1 fragments"
4843
4844requires_gnutls_tls1_3
4845requires_gnutls_record_size_limit
4846requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4847requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4848requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4849run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (513), 2 fragments" \
4850            "$P_SRV debug_level=3 force_version=tls13 tls13_kex_modes=psk \
4851                    psk_list=Client_identity,6162636465666768696a6b6c6d6e6f70 \
4852                    response_size=768" \
4853            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK --recordsize 512 \
4854                         --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" \
4855            0 \
4856            -s "RecordSizeLimit: 513 Bytes" \
4857            -s "ClientHello: record_size_limit(28) extension exists." \
4858            -s "Sent RecordSizeLimit: 16384 Bytes" \
4859            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4860            -s "Maximum outgoing record payload length is 511" \
4861            -s "768 bytes written in 2 fragments"
4862
4863requires_gnutls_tls1_3
4864requires_gnutls_record_size_limit
4865requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4866requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4867requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4868run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (513), 3 fragments" \
4869            "$P_SRV debug_level=3 force_version=tls13 tls13_kex_modes=psk \
4870                    psk_list=Client_identity,6162636465666768696a6b6c6d6e6f70 \
4871                    response_size=1280" \
4872            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK --recordsize 512 \
4873                         --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" \
4874            0 \
4875            -s "RecordSizeLimit: 513 Bytes" \
4876            -s "ClientHello: record_size_limit(28) extension exists." \
4877            -s "Sent RecordSizeLimit: 16384 Bytes" \
4878            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4879            -s "Maximum outgoing record payload length is 511" \
4880            -s "1280 bytes written in 3 fragments"
4881
4882requires_gnutls_tls1_3
4883requires_gnutls_record_size_limit
4884requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4885requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4886requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4887run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (1024), 1 fragment" \
4888            "$P_SRV debug_level=3 force_version=tls13 response_size=512" \
4889            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \
4890            0 \
4891            -s "RecordSizeLimit: 1024 Bytes" \
4892            -s "ClientHello: record_size_limit(28) extension exists." \
4893            -s "Sent RecordSizeLimit: 16384 Bytes" \
4894            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4895            -s "Maximum outgoing record payload length is 1023" \
4896            -s "512 bytes written in 1 fragments"
4897
4898requires_gnutls_tls1_3
4899requires_gnutls_record_size_limit
4900requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4901requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4902requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4903run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (1024), 2 fragments" \
4904            "$P_SRV debug_level=3 force_version=tls13 response_size=1536" \
4905            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \
4906            0 \
4907            -s "RecordSizeLimit: 1024 Bytes" \
4908            -s "ClientHello: record_size_limit(28) extension exists." \
4909            -s "Sent RecordSizeLimit: 16384 Bytes" \
4910            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4911            -s "Maximum outgoing record payload length is 1023" \
4912            -s "1536 bytes written in 2 fragments"
4913
4914requires_gnutls_tls1_3
4915requires_gnutls_record_size_limit
4916requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4917requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4918requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4919run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (1024), 3 fragments" \
4920            "$P_SRV debug_level=3 force_version=tls13 response_size=2560" \
4921            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \
4922            0 \
4923            -s "RecordSizeLimit: 1024 Bytes" \
4924            -s "ClientHello: record_size_limit(28) extension exists." \
4925            -s "Sent RecordSizeLimit: 16384 Bytes" \
4926            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4927            -s "Maximum outgoing record payload length is 1023" \
4928            -s "2560 bytes written in 3 fragments"
4929
4930requires_gnutls_tls1_3
4931requires_gnutls_record_size_limit
4932requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4933requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4934requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4935run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (4096), 1 fragment" \
4936            "$P_SRV debug_level=3 force_version=tls13 response_size=2048" \
4937            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \
4938            0 \
4939            -s "RecordSizeLimit: 4096 Bytes" \
4940            -s "ClientHello: record_size_limit(28) extension exists." \
4941            -s "Sent RecordSizeLimit: 16384 Bytes" \
4942            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4943            -s "Maximum outgoing record payload length is 4095" \
4944            -s "2048 bytes written in 1 fragments"
4945
4946requires_gnutls_tls1_3
4947requires_gnutls_record_size_limit
4948requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4949requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4950requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4951run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (4096), 2 fragments" \
4952            "$P_SRV debug_level=3 force_version=tls13 response_size=6144" \
4953            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \
4954            0 \
4955            -s "RecordSizeLimit: 4096 Bytes" \
4956            -s "ClientHello: record_size_limit(28) extension exists." \
4957            -s "Sent RecordSizeLimit: 16384 Bytes" \
4958            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4959            -s "Maximum outgoing record payload length is 4095" \
4960            -s "6144 bytes written in 2 fragments"
4961
4962requires_gnutls_tls1_3
4963requires_gnutls_record_size_limit
4964requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
4965requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4966requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4967run_test    "Record Size Limit: TLS 1.3: Server complies with record size limit (4096), 3 fragments" \
4968            "$P_SRV debug_level=3 force_version=tls13 response_size=10240" \
4969            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \
4970            0 \
4971            -s "RecordSizeLimit: 4096 Bytes" \
4972            -s "ClientHello: record_size_limit(28) extension exists." \
4973            -s "Sent RecordSizeLimit: 16384 Bytes" \
4974            -s "EncryptedExtensions: record_size_limit(28) extension exists." \
4975            -s "Maximum outgoing record payload length is 4095" \
4976            -s "10240 bytes written in 3 fragments"
4977
4978requires_gnutls_tls1_3
4979requires_gnutls_record_size_limit
4980requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
4981requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4982requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4983run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (513), 1 fragment" \
4984            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \
4985            "$P_CLI debug_level=4 force_version=tls13 request_size=256" \
4986            0 \
4987            -c "Sent RecordSizeLimit: 16384 Bytes" \
4988            -c "ClientHello: record_size_limit(28) extension exists." \
4989            -c "RecordSizeLimit: 513 Bytes" \
4990            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
4991            -c "Maximum outgoing record payload length is 511" \
4992            -c "256 bytes written in 1 fragments"
4993
4994requires_gnutls_tls1_3
4995requires_gnutls_record_size_limit
4996requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
4997requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4998requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4999run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (513), 2 fragments" \
5000            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \
5001            "$P_CLI debug_level=4 force_version=tls13 request_size=768" \
5002            0 \
5003            -c "Sent RecordSizeLimit: 16384 Bytes" \
5004            -c "ClientHello: record_size_limit(28) extension exists." \
5005            -c "RecordSizeLimit: 513 Bytes" \
5006            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5007            -c "Maximum outgoing record payload length is 511" \
5008            -c "768 bytes written in 2 fragments"
5009
5010requires_gnutls_tls1_3
5011requires_gnutls_record_size_limit
5012requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
5013requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5014requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5015run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (513), 3 fragments" \
5016            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \
5017            "$P_CLI debug_level=4 force_version=tls13 request_size=1280" \
5018            0 \
5019            -c "Sent RecordSizeLimit: 16384 Bytes" \
5020            -c "ClientHello: record_size_limit(28) extension exists." \
5021            -c "RecordSizeLimit: 513 Bytes" \
5022            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5023            -c "Maximum outgoing record payload length is 511" \
5024            -c "1280 bytes written in 3 fragments"
5025
5026requires_gnutls_tls1_3
5027requires_gnutls_record_size_limit
5028requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
5029requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5030requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5031run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (1024), 1 fragment" \
5032            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \
5033            "$P_CLI debug_level=4 force_version=tls13 request_size=512" \
5034            0 \
5035            -c "Sent RecordSizeLimit: 16384 Bytes" \
5036            -c "ClientHello: record_size_limit(28) extension exists." \
5037            -c "RecordSizeLimit: 1024 Bytes" \
5038            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5039            -c "Maximum outgoing record payload length is 1023" \
5040            -c "512 bytes written in 1 fragments"
5041
5042requires_gnutls_tls1_3
5043requires_gnutls_record_size_limit
5044requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
5045requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5046requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5047run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (1024), 2 fragments" \
5048            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \
5049            "$P_CLI debug_level=4 force_version=tls13 request_size=1536" \
5050            0 \
5051            -c "Sent RecordSizeLimit: 16384 Bytes" \
5052            -c "ClientHello: record_size_limit(28) extension exists." \
5053            -c "RecordSizeLimit: 1024 Bytes" \
5054            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5055            -c "Maximum outgoing record payload length is 1023" \
5056            -c "1536 bytes written in 2 fragments"
5057
5058requires_gnutls_tls1_3
5059requires_gnutls_record_size_limit
5060requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
5061requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5062requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5063run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (1024), 3 fragments" \
5064            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \
5065            "$P_CLI debug_level=4 force_version=tls13 request_size=2560" \
5066            0 \
5067            -c "Sent RecordSizeLimit: 16384 Bytes" \
5068            -c "ClientHello: record_size_limit(28) extension exists." \
5069            -c "RecordSizeLimit: 1024 Bytes" \
5070            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5071            -c "Maximum outgoing record payload length is 1023" \
5072            -c "2560 bytes written in 3 fragments"
5073
5074requires_gnutls_tls1_3
5075requires_gnutls_record_size_limit
5076requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
5077requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5078requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5079run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (4096), 1 fragment" \
5080            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \
5081            "$P_CLI debug_level=4 force_version=tls13 request_size=2048" \
5082            0 \
5083            -c "Sent RecordSizeLimit: 16384 Bytes" \
5084            -c "ClientHello: record_size_limit(28) extension exists." \
5085            -c "RecordSizeLimit: 4096 Bytes" \
5086            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5087            -c "Maximum outgoing record payload length is 4095" \
5088            -c "2048 bytes written in 1 fragments"
5089
5090requires_gnutls_tls1_3
5091requires_gnutls_record_size_limit
5092requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
5093requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5094requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5095run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (4096), 2 fragments" \
5096            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \
5097            "$P_CLI debug_level=4 force_version=tls13 request_size=6144" \
5098            0 \
5099            -c "Sent RecordSizeLimit: 16384 Bytes" \
5100            -c "ClientHello: record_size_limit(28) extension exists." \
5101            -c "RecordSizeLimit: 4096 Bytes" \
5102            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5103            -c "Maximum outgoing record payload length is 4095" \
5104            -c "6144 bytes written in 2 fragments"
5105
5106requires_gnutls_tls1_3
5107requires_gnutls_record_size_limit
5108requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C
5109requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5110requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5111run_test    "Record Size Limit: TLS 1.3: Client complies with record size limit (4096), 3 fragments" \
5112            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \
5113            "$P_CLI debug_level=4 force_version=tls13 request_size=10240" \
5114            0 \
5115            -c "Sent RecordSizeLimit: 16384 Bytes" \
5116            -c "ClientHello: record_size_limit(28) extension exists." \
5117            -c "RecordSizeLimit: 4096 Bytes" \
5118            -c "EncryptedExtensions: record_size_limit(28) extension exists." \
5119            -c "Maximum outgoing record payload length is 4095" \
5120            -c "10240 bytes written in 3 fragments"
5121
5122# TODO: For time being, we send fixed value of RecordSizeLimit defined by
5123# MBEDTLS_SSL_IN_CONTENT_LEN. Once we support variable buffer length of
5124# RecordSizeLimit, we need to modify value of RecordSizeLimit in below test.
5125requires_config_value_equals "MBEDTLS_SSL_IN_CONTENT_LEN" 16384
5126requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C
5127requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
5128requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5129run_test    "Record Size Limit: TLS 1.3 m->m: both peer comply with record size limit (default)" \
5130            "$P_SRV debug_level=4 force_version=tls13" \
5131            "$P_CLI debug_level=4" \
5132            0 \
5133            -c "Sent RecordSizeLimit: $MAX_IN_LEN Bytes"         \
5134            -c "RecordSizeLimit: $MAX_IN_LEN Bytes"              \
5135            -s "RecordSizeLimit: $MAX_IN_LEN Bytes"              \
5136            -s "Sent RecordSizeLimit: $MAX_IN_LEN Bytes"         \
5137            -s "Maximum outgoing record payload length is 16383" \
5138            -s "Maximum incoming record payload length is 16384"
5139
5140# End of Record size limit tests
5141
5142# Tests for renegotiation
5143
5144# G_NEXT_SRV is used in renegotiation tests becuase of the increased
5145# extensions limit since we exceed the limit in G_SRV when we send
5146# TLS 1.3 extensions in the initial handshake.
5147
5148# Renegotiation SCSV always added, regardless of SSL_RENEGOTIATION
5149run_test    "Renegotiation: none, for reference" \
5150            "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \
5151            "$P_CLI force_version=tls12 debug_level=3 exchanges=2" \
5152            0 \
5153            -C "client hello, adding renegotiation extension" \
5154            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5155            -S "found renegotiation extension" \
5156            -s "server hello, secure renegotiation extension" \
5157            -c "found renegotiation extension" \
5158            -C "=> renegotiate" \
5159            -S "=> renegotiate" \
5160            -S "write hello request"
5161
5162requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5163run_test    "Renegotiation: client-initiated" \
5164            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
5165            "$P_CLI force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
5166            0 \
5167            -c "client hello, adding renegotiation extension" \
5168            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5169            -s "found renegotiation extension" \
5170            -s "server hello, secure renegotiation extension" \
5171            -c "found renegotiation extension" \
5172            -c "=> renegotiate" \
5173            -s "=> renegotiate" \
5174            -S "write hello request"
5175
5176requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5177run_test    "Renegotiation: server-initiated" \
5178            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
5179            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
5180            0 \
5181            -c "client hello, adding renegotiation extension" \
5182            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5183            -s "found renegotiation extension" \
5184            -s "server hello, secure renegotiation extension" \
5185            -c "found renegotiation extension" \
5186            -c "=> renegotiate" \
5187            -s "=> renegotiate" \
5188            -s "write hello request"
5189
5190# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
5191# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
5192# algorithm stronger than SHA-1 is enabled in mbedtls_config.h
5193requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5194run_test    "Renegotiation: Signature Algorithms parsing, client-initiated" \
5195            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
5196            "$P_CLI force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
5197            0 \
5198            -c "client hello, adding renegotiation extension" \
5199            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5200            -s "found renegotiation extension" \
5201            -s "server hello, secure renegotiation extension" \
5202            -c "found renegotiation extension" \
5203            -c "=> renegotiate" \
5204            -s "=> renegotiate" \
5205            -S "write hello request" \
5206            -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
5207
5208# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
5209# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
5210# algorithm stronger than SHA-1 is enabled in mbedtls_config.h
5211requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5212run_test    "Renegotiation: Signature Algorithms parsing, server-initiated" \
5213            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
5214            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
5215            0 \
5216            -c "client hello, adding renegotiation extension" \
5217            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5218            -s "found renegotiation extension" \
5219            -s "server hello, secure renegotiation extension" \
5220            -c "found renegotiation extension" \
5221            -c "=> renegotiate" \
5222            -s "=> renegotiate" \
5223            -s "write hello request" \
5224            -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
5225
5226requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5227run_test    "Renegotiation: double" \
5228            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
5229            "$P_CLI force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
5230            0 \
5231            -c "client hello, adding renegotiation extension" \
5232            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5233            -s "found renegotiation extension" \
5234            -s "server hello, secure renegotiation extension" \
5235            -c "found renegotiation extension" \
5236            -c "=> renegotiate" \
5237            -s "=> renegotiate" \
5238            -s "write hello request"
5239
5240requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5241requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
5242requires_max_content_len 2048
5243run_test    "Renegotiation with max fragment length: client 2048, server 512" \
5244            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1 max_frag_len=512" \
5245            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 max_frag_len=2048 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
5246            0 \
5247            -c "Maximum incoming record payload length is 2048" \
5248            -c "Maximum outgoing record payload length is 2048" \
5249            -s "Maximum incoming record payload length is 2048" \
5250            -s "Maximum outgoing record payload length is 512" \
5251            -c "client hello, adding max_fragment_length extension" \
5252            -s "found max fragment length extension" \
5253            -s "server hello, max_fragment_length extension" \
5254            -c "found max_fragment_length extension" \
5255            -c "client hello, adding renegotiation extension" \
5256            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5257            -s "found renegotiation extension" \
5258            -s "server hello, secure renegotiation extension" \
5259            -c "found renegotiation extension" \
5260            -c "=> renegotiate" \
5261            -s "=> renegotiate" \
5262            -s "write hello request"
5263
5264requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5265run_test    "Renegotiation: client-initiated, server-rejected" \
5266            "$P_SRV debug_level=3 exchanges=2 renegotiation=0 auth_mode=optional" \
5267            "$P_CLI force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
5268            1 \
5269            -c "client hello, adding renegotiation extension" \
5270            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5271            -S "found renegotiation extension" \
5272            -s "server hello, secure renegotiation extension" \
5273            -c "found renegotiation extension" \
5274            -c "=> renegotiate" \
5275            -S "=> renegotiate" \
5276            -S "write hello request" \
5277            -c "SSL - Unexpected message at ServerHello in renegotiation" \
5278            -c "failed"
5279
5280requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5281run_test    "Renegotiation: server-initiated, client-rejected, default" \
5282            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
5283            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
5284            0 \
5285            -C "client hello, adding renegotiation extension" \
5286            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5287            -S "found renegotiation extension" \
5288            -s "server hello, secure renegotiation extension" \
5289            -c "found renegotiation extension" \
5290            -C "=> renegotiate" \
5291            -S "=> renegotiate" \
5292            -s "write hello request" \
5293            -S "SSL - An unexpected message was received from our peer" \
5294            -S "failed"
5295
5296requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5297run_test    "Renegotiation: server-initiated, client-rejected, not enforced" \
5298            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
5299             renego_delay=-1 auth_mode=optional" \
5300            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
5301            0 \
5302            -C "client hello, adding renegotiation extension" \
5303            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5304            -S "found renegotiation extension" \
5305            -s "server hello, secure renegotiation extension" \
5306            -c "found renegotiation extension" \
5307            -C "=> renegotiate" \
5308            -S "=> renegotiate" \
5309            -s "write hello request" \
5310            -S "SSL - An unexpected message was received from our peer" \
5311            -S "failed"
5312
5313# delay 2 for 1 alert record + 1 application data record
5314requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5315run_test    "Renegotiation: server-initiated, client-rejected, delay 2" \
5316            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
5317             renego_delay=2 auth_mode=optional" \
5318            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
5319            0 \
5320            -C "client hello, adding renegotiation extension" \
5321            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5322            -S "found renegotiation extension" \
5323            -s "server hello, secure renegotiation extension" \
5324            -c "found renegotiation extension" \
5325            -C "=> renegotiate" \
5326            -S "=> renegotiate" \
5327            -s "write hello request" \
5328            -S "SSL - An unexpected message was received from our peer" \
5329            -S "failed"
5330
5331requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5332run_test    "Renegotiation: server-initiated, client-rejected, delay 0" \
5333            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
5334             renego_delay=0 auth_mode=optional" \
5335            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
5336            0 \
5337            -C "client hello, adding renegotiation extension" \
5338            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5339            -S "found renegotiation extension" \
5340            -s "server hello, secure renegotiation extension" \
5341            -c "found renegotiation extension" \
5342            -C "=> renegotiate" \
5343            -S "=> renegotiate" \
5344            -s "write hello request" \
5345            -s "SSL - An unexpected message was received from our peer"
5346
5347requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5348run_test    "Renegotiation: server-initiated, client-accepted, delay 0" \
5349            "$P_SRV force_version=tls12 debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
5350             renego_delay=0 auth_mode=optional" \
5351            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
5352            0 \
5353            -c "client hello, adding renegotiation extension" \
5354            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5355            -s "found renegotiation extension" \
5356            -s "server hello, secure renegotiation extension" \
5357            -c "found renegotiation extension" \
5358            -c "=> renegotiate" \
5359            -s "=> renegotiate" \
5360            -s "write hello request" \
5361            -S "SSL - An unexpected message was received from our peer" \
5362            -S "failed"
5363
5364requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5365run_test    "Renegotiation: periodic, just below period" \
5366            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
5367            "$P_CLI force_version=tls12 debug_level=3 exchanges=2 renegotiation=1" \
5368            0 \
5369            -C "client hello, adding renegotiation extension" \
5370            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5371            -S "found renegotiation extension" \
5372            -s "server hello, secure renegotiation extension" \
5373            -c "found renegotiation extension" \
5374            -S "record counter limit reached: renegotiate" \
5375            -C "=> renegotiate" \
5376            -S "=> renegotiate" \
5377            -S "write hello request" \
5378            -S "SSL - An unexpected message was received from our peer" \
5379            -S "failed"
5380
5381# one extra exchange to be able to complete renego
5382requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5383run_test    "Renegotiation: periodic, just above period" \
5384            "$P_SRV force_version=tls12 debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
5385            "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
5386            0 \
5387            -c "client hello, adding renegotiation extension" \
5388            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5389            -s "found renegotiation extension" \
5390            -s "server hello, secure renegotiation extension" \
5391            -c "found renegotiation extension" \
5392            -s "record counter limit reached: renegotiate" \
5393            -c "=> renegotiate" \
5394            -s "=> renegotiate" \
5395            -s "write hello request" \
5396            -S "SSL - An unexpected message was received from our peer" \
5397            -S "failed"
5398
5399requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5400run_test    "Renegotiation: periodic, two times period" \
5401            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
5402            "$P_CLI force_version=tls12 debug_level=3 exchanges=7 renegotiation=1" \
5403            0 \
5404            -c "client hello, adding renegotiation extension" \
5405            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5406            -s "found renegotiation extension" \
5407            -s "server hello, secure renegotiation extension" \
5408            -c "found renegotiation extension" \
5409            -s "record counter limit reached: renegotiate" \
5410            -c "=> renegotiate" \
5411            -s "=> renegotiate" \
5412            -s "write hello request" \
5413            -S "SSL - An unexpected message was received from our peer" \
5414            -S "failed"
5415
5416requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5417run_test    "Renegotiation: periodic, above period, disabled" \
5418            "$P_SRV force_version=tls12 debug_level=3 exchanges=9 renegotiation=0 renego_period=3 auth_mode=optional" \
5419            "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
5420            0 \
5421            -C "client hello, adding renegotiation extension" \
5422            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5423            -S "found renegotiation extension" \
5424            -s "server hello, secure renegotiation extension" \
5425            -c "found renegotiation extension" \
5426            -S "record counter limit reached: renegotiate" \
5427            -C "=> renegotiate" \
5428            -S "=> renegotiate" \
5429            -S "write hello request" \
5430            -S "SSL - An unexpected message was received from our peer" \
5431            -S "failed"
5432
5433requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5434run_test    "Renegotiation: nbio, client-initiated" \
5435            "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 auth_mode=optional" \
5436            "$P_CLI force_version=tls12 debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
5437            0 \
5438            -c "client hello, adding renegotiation extension" \
5439            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5440            -s "found renegotiation extension" \
5441            -s "server hello, secure renegotiation extension" \
5442            -c "found renegotiation extension" \
5443            -c "=> renegotiate" \
5444            -s "=> renegotiate" \
5445            -S "write hello request"
5446
5447requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5448run_test    "Renegotiation: nbio, server-initiated" \
5449            "$P_SRV force_version=tls12 debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
5450            "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
5451            0 \
5452            -c "client hello, adding renegotiation extension" \
5453            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5454            -s "found renegotiation extension" \
5455            -s "server hello, secure renegotiation extension" \
5456            -c "found renegotiation extension" \
5457            -c "=> renegotiate" \
5458            -s "=> renegotiate" \
5459            -s "write hello request"
5460
5461requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5462requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5463run_test    "Renegotiation: openssl server, client-initiated" \
5464            "$O_SRV -www -tls1_2" \
5465            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
5466            0 \
5467            -c "client hello, adding renegotiation extension" \
5468            -c "found renegotiation extension" \
5469            -c "=> renegotiate" \
5470            -C "ssl_hanshake() returned" \
5471            -C "error" \
5472            -c "HTTP/1.0 200 [Oo][Kk]"
5473
5474requires_gnutls
5475requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5476requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5477run_test    "Renegotiation: gnutls server strict, client-initiated" \
5478            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \
5479            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
5480            0 \
5481            -c "client hello, adding renegotiation extension" \
5482            -c "found renegotiation extension" \
5483            -c "=> renegotiate" \
5484            -C "ssl_hanshake() returned" \
5485            -C "error" \
5486            -c "HTTP/1.0 200 [Oo][Kk]"
5487
5488requires_gnutls
5489requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5490requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5491run_test    "Renegotiation: gnutls server unsafe, client-initiated default" \
5492            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5493            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
5494            1 \
5495            -c "client hello, adding renegotiation extension" \
5496            -C "found renegotiation extension" \
5497            -c "=> renegotiate" \
5498            -c "mbedtls_ssl_handshake() returned" \
5499            -c "error" \
5500            -C "HTTP/1.0 200 [Oo][Kk]"
5501
5502requires_gnutls
5503requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5504requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5505run_test    "Renegotiation: gnutls server unsafe, client-inititated no legacy" \
5506            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5507            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
5508             allow_legacy=0" \
5509            1 \
5510            -c "client hello, adding renegotiation extension" \
5511            -C "found renegotiation extension" \
5512            -c "=> renegotiate" \
5513            -c "mbedtls_ssl_handshake() returned" \
5514            -c "error" \
5515            -C "HTTP/1.0 200 [Oo][Kk]"
5516
5517requires_gnutls
5518requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5519requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5520run_test    "Renegotiation: gnutls server unsafe, client-inititated legacy" \
5521            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5522            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
5523             allow_legacy=1" \
5524            0 \
5525            -c "client hello, adding renegotiation extension" \
5526            -C "found renegotiation extension" \
5527            -c "=> renegotiate" \
5528            -C "ssl_hanshake() returned" \
5529            -C "error" \
5530            -c "HTTP/1.0 200 [Oo][Kk]"
5531
5532requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5533requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5534run_test    "Renegotiation: DTLS, client-initiated" \
5535            "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
5536            "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
5537            0 \
5538            -c "client hello, adding renegotiation extension" \
5539            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5540            -s "found renegotiation extension" \
5541            -s "server hello, secure renegotiation extension" \
5542            -c "found renegotiation extension" \
5543            -c "=> renegotiate" \
5544            -s "=> renegotiate" \
5545            -S "write hello request"
5546
5547requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5548requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5549run_test    "Renegotiation: DTLS, server-initiated" \
5550            "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
5551            "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
5552             read_timeout=1000 max_resend=2" \
5553            0 \
5554            -c "client hello, adding renegotiation extension" \
5555            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5556            -s "found renegotiation extension" \
5557            -s "server hello, secure renegotiation extension" \
5558            -c "found renegotiation extension" \
5559            -c "=> renegotiate" \
5560            -s "=> renegotiate" \
5561            -s "write hello request"
5562
5563requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5564requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5565run_test    "Renegotiation: DTLS, renego_period overflow" \
5566            "$P_SRV debug_level=3 dtls=1 exchanges=4 renegotiation=1 renego_period=18446462598732840962 auth_mode=optional" \
5567            "$P_CLI debug_level=3 dtls=1 exchanges=4 renegotiation=1" \
5568            0 \
5569            -c "client hello, adding renegotiation extension" \
5570            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5571            -s "found renegotiation extension" \
5572            -s "server hello, secure renegotiation extension" \
5573            -s "record counter limit reached: renegotiate" \
5574            -c "=> renegotiate" \
5575            -s "=> renegotiate" \
5576            -s "write hello request"
5577
5578requires_gnutls
5579requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5580requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5581run_test    "Renegotiation: DTLS, gnutls server, client-initiated" \
5582            "$G_NEXT_SRV -u --mtu 4096" \
5583            "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
5584            0 \
5585            -c "client hello, adding renegotiation extension" \
5586            -c "found renegotiation extension" \
5587            -c "=> renegotiate" \
5588            -C "mbedtls_ssl_handshake returned" \
5589            -C "error" \
5590            -s "Extra-header:"
5591
5592# Test for the "secure renegotiation" extension only (no actual renegotiation)
5593
5594requires_gnutls
5595requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5596run_test    "Renego ext: gnutls server strict, client default" \
5597            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \
5598            "$P_CLI debug_level=3" \
5599            0 \
5600            -c "found renegotiation extension" \
5601            -C "error" \
5602            -c "HTTP/1.0 200 [Oo][Kk]"
5603
5604requires_gnutls
5605requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5606run_test    "Renego ext: gnutls server unsafe, client default" \
5607            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5608            "$P_CLI debug_level=3" \
5609            0 \
5610            -C "found renegotiation extension" \
5611            -C "error" \
5612            -c "HTTP/1.0 200 [Oo][Kk]"
5613
5614requires_gnutls
5615requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5616run_test    "Renego ext: gnutls server unsafe, client break legacy" \
5617            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5618            "$P_CLI debug_level=3 allow_legacy=-1" \
5619            1 \
5620            -C "found renegotiation extension" \
5621            -c "error" \
5622            -C "HTTP/1.0 200 [Oo][Kk]"
5623
5624requires_gnutls
5625requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5626run_test    "Renego ext: gnutls client strict, server default" \
5627            "$P_SRV debug_level=3" \
5628            "$G_CLI --priority=NORMAL:%SAFE_RENEGOTIATION localhost" \
5629            0 \
5630            -s "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5631            -s "server hello, secure renegotiation extension"
5632
5633requires_gnutls
5634requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5635run_test    "Renego ext: gnutls client unsafe, server default" \
5636            "$P_SRV debug_level=3" \
5637            "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION localhost" \
5638            0 \
5639            -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5640            -S "server hello, secure renegotiation extension"
5641
5642requires_gnutls
5643requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5644run_test    "Renego ext: gnutls client unsafe, server break legacy" \
5645            "$P_SRV debug_level=3 allow_legacy=-1" \
5646            "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION localhost" \
5647            1 \
5648            -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5649            -S "server hello, secure renegotiation extension"
5650
5651# Tests for silently dropping trailing extra bytes in .der certificates
5652
5653requires_gnutls
5654requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5655run_test    "DER format: no trailing bytes" \
5656            "$P_SRV crt_file=data_files/server5-der0.crt \
5657             key_file=data_files/server5.key" \
5658            "$G_CLI localhost" \
5659            0 \
5660            -c "Handshake was completed" \
5661
5662requires_gnutls
5663requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5664run_test    "DER format: with a trailing zero byte" \
5665            "$P_SRV crt_file=data_files/server5-der1a.crt \
5666             key_file=data_files/server5.key" \
5667            "$G_CLI localhost" \
5668            0 \
5669            -c "Handshake was completed" \
5670
5671requires_gnutls
5672requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5673run_test    "DER format: with a trailing random byte" \
5674            "$P_SRV crt_file=data_files/server5-der1b.crt \
5675             key_file=data_files/server5.key" \
5676            "$G_CLI localhost" \
5677            0 \
5678            -c "Handshake was completed" \
5679
5680requires_gnutls
5681requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5682run_test    "DER format: with 2 trailing random bytes" \
5683            "$P_SRV crt_file=data_files/server5-der2.crt \
5684             key_file=data_files/server5.key" \
5685            "$G_CLI localhost" \
5686            0 \
5687            -c "Handshake was completed" \
5688
5689requires_gnutls
5690requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5691run_test    "DER format: with 4 trailing random bytes" \
5692            "$P_SRV crt_file=data_files/server5-der4.crt \
5693             key_file=data_files/server5.key" \
5694            "$G_CLI localhost" \
5695            0 \
5696            -c "Handshake was completed" \
5697
5698requires_gnutls
5699requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5700run_test    "DER format: with 8 trailing random bytes" \
5701            "$P_SRV crt_file=data_files/server5-der8.crt \
5702             key_file=data_files/server5.key" \
5703            "$G_CLI localhost" \
5704            0 \
5705            -c "Handshake was completed" \
5706
5707requires_gnutls
5708requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5709run_test    "DER format: with 9 trailing random bytes" \
5710            "$P_SRV crt_file=data_files/server5-der9.crt \
5711             key_file=data_files/server5.key" \
5712            "$G_CLI localhost" \
5713            0 \
5714            -c "Handshake was completed" \
5715
5716# Tests for auth_mode, there are duplicated tests using ca callback for authentication
5717# When updating these tests, modify the matching authentication tests accordingly
5718
5719requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5720run_test    "Authentication: server badcert, client required" \
5721            "$P_SRV crt_file=data_files/server5-badsign.crt \
5722             key_file=data_files/server5.key" \
5723            "$P_CLI debug_level=1 auth_mode=required" \
5724            1 \
5725            -c "x509_verify_cert() returned" \
5726            -c "! The certificate is not correctly signed by the trusted CA" \
5727            -c "! mbedtls_ssl_handshake returned" \
5728            -c "X509 - Certificate verification failed"
5729
5730run_test    "Authentication: server badcert, client optional" \
5731            "$P_SRV crt_file=data_files/server5-badsign.crt \
5732             key_file=data_files/server5.key" \
5733            "$P_CLI force_version=tls12 debug_level=1 auth_mode=optional" \
5734            0 \
5735            -c "x509_verify_cert() returned" \
5736            -c "! The certificate is not correctly signed by the trusted CA" \
5737            -C "! mbedtls_ssl_handshake returned" \
5738            -C "X509 - Certificate verification failed"
5739
5740requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5741run_test    "Authentication: server goodcert, client optional, no trusted CA" \
5742            "$P_SRV" \
5743            "$P_CLI force_version=tls12 debug_level=3 auth_mode=optional ca_file=none ca_path=none" \
5744            0 \
5745            -c "x509_verify_cert() returned" \
5746            -c "! The certificate is not correctly signed by the trusted CA" \
5747            -c "! Certificate verification flags"\
5748            -C "! mbedtls_ssl_handshake returned" \
5749            -C "X509 - Certificate verification failed" \
5750            -C "SSL - No CA Chain is set, but required to operate"
5751
5752requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5753run_test    "Authentication: server goodcert, client required, no trusted CA" \
5754            "$P_SRV" \
5755            "$P_CLI debug_level=3 auth_mode=required ca_file=none ca_path=none" \
5756            1 \
5757            -c "x509_verify_cert() returned" \
5758            -c "! The certificate is not correctly signed by the trusted CA" \
5759            -c "! Certificate verification flags"\
5760            -c "! mbedtls_ssl_handshake returned" \
5761            -c "SSL - No CA Chain is set, but required to operate"
5762
5763# The purpose of the next two tests is to test the client's behaviour when receiving a server
5764# certificate with an unsupported elliptic curve. This should usually not happen because
5765# the client informs the server about the supported curves - it does, though, in the
5766# corner case of a static ECDH suite, because the server doesn't check the curve on that
5767# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
5768# different means to have the server ignoring the client's supported curve list.
5769
5770run_test    "Authentication: server ECDH p256v1, client required, p256v1 unsupported" \
5771            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5772             crt_file=data_files/server5.ku-ka.crt" \
5773            "$P_CLI force_version=tls12 debug_level=3 auth_mode=required groups=secp521r1" \
5774            1 \
5775            -c "bad certificate (EC key curve)"\
5776            -c "! Certificate verification flags"\
5777            -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
5778
5779run_test    "Authentication: server ECDH p256v1, client optional, p256v1 unsupported" \
5780            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5781             crt_file=data_files/server5.ku-ka.crt" \
5782            "$P_CLI force_version=tls12 debug_level=3 auth_mode=optional groups=secp521r1" \
5783            1 \
5784            -c "bad certificate (EC key curve)"\
5785            -c "! Certificate verification flags"\
5786            -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
5787
5788run_test    "Authentication: server badcert, client none" \
5789            "$P_SRV crt_file=data_files/server5-badsign.crt \
5790             key_file=data_files/server5.key" \
5791            "$P_CLI force_version=tls12 debug_level=1 auth_mode=none" \
5792            0 \
5793            -C "x509_verify_cert() returned" \
5794            -C "! The certificate is not correctly signed by the trusted CA" \
5795            -C "! mbedtls_ssl_handshake returned" \
5796            -C "X509 - Certificate verification failed"
5797
5798requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5799run_test    "Authentication: client SHA256, server required" \
5800            "$P_SRV auth_mode=required" \
5801            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5802             key_file=data_files/server6.key \
5803             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
5804            0 \
5805            -c "Supported Signature Algorithm found: 04 " \
5806            -c "Supported Signature Algorithm found: 05 "
5807
5808requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5809run_test    "Authentication: client SHA384, server required" \
5810            "$P_SRV auth_mode=required" \
5811            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5812             key_file=data_files/server6.key \
5813             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
5814            0 \
5815            -c "Supported Signature Algorithm found: 04 " \
5816            -c "Supported Signature Algorithm found: 05 "
5817
5818requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5819run_test    "Authentication: client has no cert, server required (TLS)" \
5820            "$P_SRV debug_level=3 auth_mode=required" \
5821            "$P_CLI debug_level=3 crt_file=none \
5822             key_file=data_files/server5.key" \
5823            1 \
5824            -S "skip write certificate request" \
5825            -C "skip parse certificate request" \
5826            -c "got a certificate request" \
5827            -c "= write certificate$" \
5828            -C "skip write certificate$" \
5829            -S "x509_verify_cert() returned" \
5830            -s "peer has no certificate" \
5831            -s "! mbedtls_ssl_handshake returned" \
5832            -s "No client certification received from the client, but required by the authentication mode"
5833
5834requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5835run_test    "Authentication: client badcert, server required" \
5836            "$P_SRV debug_level=3 auth_mode=required" \
5837            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5838             key_file=data_files/server5.key" \
5839            1 \
5840            -S "skip write certificate request" \
5841            -C "skip parse certificate request" \
5842            -c "got a certificate request" \
5843            -C "skip write certificate" \
5844            -C "skip write certificate verify" \
5845            -S "skip parse certificate verify" \
5846            -s "x509_verify_cert() returned" \
5847            -s "! The certificate is not correctly signed by the trusted CA" \
5848            -s "! mbedtls_ssl_handshake returned" \
5849            -s "send alert level=2 message=48" \
5850            -s "X509 - Certificate verification failed"
5851# We don't check that the client receives the alert because it might
5852# detect that its write end of the connection is closed and abort
5853# before reading the alert message.
5854
5855requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5856run_test    "Authentication: client cert self-signed and trusted, server required" \
5857            "$P_SRV debug_level=3 auth_mode=required ca_file=data_files/server5-selfsigned.crt" \
5858            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5859             key_file=data_files/server5.key" \
5860            0 \
5861            -S "skip write certificate request" \
5862            -C "skip parse certificate request" \
5863            -c "got a certificate request" \
5864            -C "skip write certificate" \
5865            -C "skip write certificate verify" \
5866            -S "skip parse certificate verify" \
5867            -S "x509_verify_cert() returned" \
5868            -S "! The certificate is not correctly signed" \
5869            -S "X509 - Certificate verification failed"
5870
5871requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5872run_test    "Authentication: client cert not trusted, server required" \
5873            "$P_SRV debug_level=3 auth_mode=required" \
5874            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5875             key_file=data_files/server5.key" \
5876            1 \
5877            -S "skip write certificate request" \
5878            -C "skip parse certificate request" \
5879            -c "got a certificate request" \
5880            -C "skip write certificate" \
5881            -C "skip write certificate verify" \
5882            -S "skip parse certificate verify" \
5883            -s "x509_verify_cert() returned" \
5884            -s "! The certificate is not correctly signed by the trusted CA" \
5885            -s "! mbedtls_ssl_handshake returned" \
5886            -s "X509 - Certificate verification failed"
5887
5888requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5889run_test    "Authentication: client badcert, server optional" \
5890            "$P_SRV debug_level=3 auth_mode=optional" \
5891            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5892             key_file=data_files/server5.key" \
5893            0 \
5894            -S "skip write certificate request" \
5895            -C "skip parse certificate request" \
5896            -c "got a certificate request" \
5897            -C "skip write certificate" \
5898            -C "skip write certificate verify" \
5899            -S "skip parse certificate verify" \
5900            -s "x509_verify_cert() returned" \
5901            -s "! The certificate is not correctly signed by the trusted CA" \
5902            -S "! mbedtls_ssl_handshake returned" \
5903            -C "! mbedtls_ssl_handshake returned" \
5904            -S "X509 - Certificate verification failed"
5905
5906requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5907run_test    "Authentication: client badcert, server none" \
5908            "$P_SRV debug_level=3 auth_mode=none" \
5909            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5910             key_file=data_files/server5.key" \
5911            0 \
5912            -s "skip write certificate request" \
5913            -C "skip parse certificate request" \
5914            -c "got no certificate request" \
5915            -c "skip write certificate" \
5916            -c "skip write certificate verify" \
5917            -s "skip parse certificate verify" \
5918            -S "x509_verify_cert() returned" \
5919            -S "! The certificate is not correctly signed by the trusted CA" \
5920            -S "! mbedtls_ssl_handshake returned" \
5921            -C "! mbedtls_ssl_handshake returned" \
5922            -S "X509 - Certificate verification failed"
5923
5924requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5925run_test    "Authentication: client no cert, server optional" \
5926            "$P_SRV debug_level=3 auth_mode=optional" \
5927            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5928            0 \
5929            -S "skip write certificate request" \
5930            -C "skip parse certificate request" \
5931            -c "got a certificate request" \
5932            -C "skip write certificate$" \
5933            -C "got no certificate to send" \
5934            -c "skip write certificate verify" \
5935            -s "skip parse certificate verify" \
5936            -s "! Certificate was missing" \
5937            -S "! mbedtls_ssl_handshake returned" \
5938            -C "! mbedtls_ssl_handshake returned" \
5939            -S "X509 - Certificate verification failed"
5940
5941requires_openssl_tls1_3_with_compatible_ephemeral
5942requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5943run_test    "Authentication: openssl client no cert, server optional" \
5944            "$P_SRV debug_level=3 auth_mode=optional" \
5945            "$O_NEXT_CLI_NO_CERT -no_middlebox" \
5946            0 \
5947            -S "skip write certificate request" \
5948            -s "skip parse certificate verify" \
5949            -s "! Certificate was missing" \
5950            -S "! mbedtls_ssl_handshake returned" \
5951            -S "X509 - Certificate verification failed"
5952
5953requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5954run_test    "Authentication: client no cert, openssl server optional" \
5955            "$O_SRV -verify 10 -tls1_2" \
5956            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5957            0 \
5958            -C "skip parse certificate request" \
5959            -c "got a certificate request" \
5960            -C "skip write certificate$" \
5961            -c "skip write certificate verify" \
5962            -C "! mbedtls_ssl_handshake returned"
5963
5964requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5965run_test    "Authentication: client no cert, openssl server required" \
5966            "$O_SRV -Verify 10 -tls1_2" \
5967            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5968            1 \
5969            -C "skip parse certificate request" \
5970            -c "got a certificate request" \
5971            -C "skip write certificate$" \
5972            -c "skip write certificate verify" \
5973            -c "! mbedtls_ssl_handshake returned"
5974
5975# This script assumes that MBEDTLS_X509_MAX_INTERMEDIATE_CA has its default
5976# value, defined here as MAX_IM_CA. Some test cases will be skipped if the
5977# library is configured with a different value.
5978
5979MAX_IM_CA='8'
5980
5981# The tests for the max_int tests can pass with any number higher than MAX_IM_CA
5982# because only a chain of MAX_IM_CA length is tested. Equally, the max_int+1
5983# tests can pass with any number less than MAX_IM_CA. However, stricter preconditions
5984# are in place so that the semantics are consistent with the test description.
5985requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5986requires_full_size_output_buffer
5987run_test    "Authentication: server max_int chain, client default" \
5988            "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
5989                    key_file=data_files/dir-maxpath/09.key" \
5990            "$P_CLI server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
5991            0 \
5992            -C "X509 - A fatal error occurred"
5993
5994requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5995requires_full_size_output_buffer
5996run_test    "Authentication: server max_int+1 chain, client default" \
5997            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5998                    key_file=data_files/dir-maxpath/10.key" \
5999            "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
6000            1 \
6001            -c "X509 - A fatal error occurred"
6002
6003requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6004requires_full_size_output_buffer
6005run_test    "Authentication: server max_int+1 chain, client optional" \
6006            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
6007                    key_file=data_files/dir-maxpath/10.key" \
6008            "$P_CLI force_version=tls12 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
6009                    auth_mode=optional" \
6010            1 \
6011            -c "X509 - A fatal error occurred"
6012
6013requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6014requires_full_size_output_buffer
6015run_test    "Authentication: server max_int+1 chain, client none" \
6016            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
6017                    key_file=data_files/dir-maxpath/10.key" \
6018            "$P_CLI force_version=tls12 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
6019                    auth_mode=none" \
6020            0 \
6021            -C "X509 - A fatal error occurred"
6022
6023requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6024requires_full_size_output_buffer
6025run_test    "Authentication: client max_int+1 chain, server default" \
6026            "$P_SRV ca_file=data_files/dir-maxpath/00.crt" \
6027            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
6028                    key_file=data_files/dir-maxpath/10.key" \
6029            0 \
6030            -S "X509 - A fatal error occurred"
6031
6032requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6033requires_full_size_output_buffer
6034run_test    "Authentication: client max_int+1 chain, server optional" \
6035            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
6036            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
6037                    key_file=data_files/dir-maxpath/10.key" \
6038            1 \
6039            -s "X509 - A fatal error occurred"
6040
6041requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6042requires_full_size_output_buffer
6043run_test    "Authentication: client max_int+1 chain, server required" \
6044            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
6045            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
6046                    key_file=data_files/dir-maxpath/10.key" \
6047            1 \
6048            -s "X509 - A fatal error occurred"
6049
6050requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6051requires_full_size_output_buffer
6052run_test    "Authentication: client max_int chain, server required" \
6053            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
6054            "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
6055                    key_file=data_files/dir-maxpath/09.key" \
6056            0 \
6057            -S "X509 - A fatal error occurred"
6058
6059# Tests for CA list in CertificateRequest messages
6060
6061requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6062run_test    "Authentication: send CA list in CertificateRequest  (default)" \
6063            "$P_SRV debug_level=3 auth_mode=required" \
6064            "$P_CLI force_version=tls12 crt_file=data_files/server6.crt \
6065             key_file=data_files/server6.key" \
6066            0 \
6067            -s "requested DN"
6068
6069requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6070run_test    "Authentication: do not send CA list in CertificateRequest" \
6071            "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
6072            "$P_CLI force_version=tls12 crt_file=data_files/server6.crt \
6073             key_file=data_files/server6.key" \
6074            0 \
6075            -S "requested DN"
6076
6077run_test    "Authentication: send CA list in CertificateRequest, client self signed" \
6078            "$P_SRV force_version=tls12 debug_level=3 auth_mode=required cert_req_ca_list=0" \
6079            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
6080             key_file=data_files/server5.key" \
6081            1 \
6082            -S "requested DN" \
6083            -s "x509_verify_cert() returned" \
6084            -s "! The certificate is not correctly signed by the trusted CA" \
6085            -s "! mbedtls_ssl_handshake returned" \
6086            -c "! mbedtls_ssl_handshake returned" \
6087            -s "X509 - Certificate verification failed"
6088
6089requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6090run_test    "Authentication: send alt conf DN hints in CertificateRequest" \
6091            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=2 \
6092             crt_file2=data_files/server1.crt \
6093             key_file2=data_files/server1.key" \
6094            "$P_CLI force_version=tls12 debug_level=3 auth_mode=optional \
6095             crt_file=data_files/server6.crt \
6096             key_file=data_files/server6.key" \
6097            0 \
6098            -c "DN hint: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
6099
6100requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6101run_test    "Authentication: send alt conf DN hints in CertificateRequest (2)" \
6102            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=2 \
6103             crt_file2=data_files/server2.crt \
6104             key_file2=data_files/server2.key" \
6105            "$P_CLI force_version=tls12 debug_level=3 auth_mode=optional \
6106             crt_file=data_files/server6.crt \
6107             key_file=data_files/server6.key" \
6108            0 \
6109            -c "DN hint: C=NL, O=PolarSSL, CN=localhost"
6110
6111requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6112run_test    "Authentication: send alt hs DN hints in CertificateRequest" \
6113            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=3 \
6114             crt_file2=data_files/server1.crt \
6115             key_file2=data_files/server1.key" \
6116            "$P_CLI force_version=tls12 debug_level=3 auth_mode=optional \
6117             crt_file=data_files/server6.crt \
6118             key_file=data_files/server6.key" \
6119            0 \
6120            -c "DN hint: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
6121
6122# Tests for auth_mode, using CA callback, these are duplicated from the authentication tests
6123# When updating these tests, modify the matching authentication tests accordingly
6124
6125requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6126run_test    "Authentication, CA callback: server badcert, client required" \
6127            "$P_SRV crt_file=data_files/server5-badsign.crt \
6128             key_file=data_files/server5.key" \
6129            "$P_CLI force_version=tls12 ca_callback=1 debug_level=3 auth_mode=required" \
6130            1 \
6131            -c "use CA callback for X.509 CRT verification" \
6132            -c "x509_verify_cert() returned" \
6133            -c "! The certificate is not correctly signed by the trusted CA" \
6134            -c "! mbedtls_ssl_handshake returned" \
6135            -c "X509 - Certificate verification failed"
6136
6137requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6138run_test    "Authentication, CA callback: server badcert, client optional" \
6139            "$P_SRV crt_file=data_files/server5-badsign.crt \
6140             key_file=data_files/server5.key" \
6141            "$P_CLI force_version=tls12 ca_callback=1 debug_level=3 auth_mode=optional" \
6142            0 \
6143            -c "use CA callback for X.509 CRT verification" \
6144            -c "x509_verify_cert() returned" \
6145            -c "! The certificate is not correctly signed by the trusted CA" \
6146            -C "! mbedtls_ssl_handshake returned" \
6147            -C "X509 - Certificate verification failed"
6148
6149# The purpose of the next two tests is to test the client's behaviour when receiving a server
6150# certificate with an unsupported elliptic curve. This should usually not happen because
6151# the client informs the server about the supported curves - it does, though, in the
6152# corner case of a static ECDH suite, because the server doesn't check the curve on that
6153# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
6154# different means to have the server ignoring the client's supported curve list.
6155
6156requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6157run_test    "Authentication, CA callback: server ECDH p256v1, client required, p256v1 unsupported" \
6158            "$P_SRV debug_level=1 key_file=data_files/server5.key \
6159             crt_file=data_files/server5.ku-ka.crt" \
6160            "$P_CLI force_version=tls12 ca_callback=1 debug_level=3 auth_mode=required groups=secp521r1" \
6161            1 \
6162            -c "use CA callback for X.509 CRT verification" \
6163            -c "bad certificate (EC key curve)" \
6164            -c "! Certificate verification flags" \
6165            -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
6166
6167requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6168run_test    "Authentication, CA callback: server ECDH p256v1, client optional, p256v1 unsupported" \
6169            "$P_SRV debug_level=1 key_file=data_files/server5.key \
6170             crt_file=data_files/server5.ku-ka.crt" \
6171            "$P_CLI force_version=tls12 ca_callback=1 debug_level=3 auth_mode=optional groups=secp521r1" \
6172            1 \
6173            -c "use CA callback for X.509 CRT verification" \
6174            -c "bad certificate (EC key curve)"\
6175            -c "! Certificate verification flags"\
6176            -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
6177
6178requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6179requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6180run_test    "Authentication, CA callback: client SHA256, server required" \
6181            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
6182            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
6183             key_file=data_files/server6.key \
6184             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
6185            0 \
6186            -s "use CA callback for X.509 CRT verification" \
6187            -c "Supported Signature Algorithm found: 04 " \
6188            -c "Supported Signature Algorithm found: 05 "
6189
6190requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6191requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6192run_test    "Authentication, CA callback: client SHA384, server required" \
6193            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
6194            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
6195             key_file=data_files/server6.key \
6196             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
6197            0 \
6198            -s "use CA callback for X.509 CRT verification" \
6199            -c "Supported Signature Algorithm found: 04 " \
6200            -c "Supported Signature Algorithm found: 05 "
6201
6202requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6203run_test    "Authentication, CA callback: client badcert, server required" \
6204            "$P_SRV force_version=tls12 ca_callback=1 debug_level=3 auth_mode=required" \
6205            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
6206             key_file=data_files/server5.key" \
6207            1 \
6208            -s "use CA callback for X.509 CRT verification" \
6209            -S "skip write certificate request" \
6210            -C "skip parse certificate request" \
6211            -c "got a certificate request" \
6212            -C "skip write certificate" \
6213            -C "skip write certificate verify" \
6214            -S "skip parse certificate verify" \
6215            -s "x509_verify_cert() returned" \
6216            -s "! The certificate is not correctly signed by the trusted CA" \
6217            -s "! mbedtls_ssl_handshake returned" \
6218            -s "send alert level=2 message=48" \
6219            -c "! mbedtls_ssl_handshake returned" \
6220            -s "X509 - Certificate verification failed"
6221# We don't check that the client receives the alert because it might
6222# detect that its write end of the connection is closed and abort
6223# before reading the alert message.
6224
6225requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6226run_test    "Authentication, CA callback: client cert not trusted, server required" \
6227            "$P_SRV force_version=tls12 ca_callback=1 debug_level=3 auth_mode=required" \
6228            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
6229             key_file=data_files/server5.key" \
6230            1 \
6231            -s "use CA callback for X.509 CRT verification" \
6232            -S "skip write certificate request" \
6233            -C "skip parse certificate request" \
6234            -c "got a certificate request" \
6235            -C "skip write certificate" \
6236            -C "skip write certificate verify" \
6237            -S "skip parse certificate verify" \
6238            -s "x509_verify_cert() returned" \
6239            -s "! The certificate is not correctly signed by the trusted CA" \
6240            -s "! mbedtls_ssl_handshake returned" \
6241            -c "! mbedtls_ssl_handshake returned" \
6242            -s "X509 - Certificate verification failed"
6243
6244requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6245run_test    "Authentication, CA callback: client badcert, server optional" \
6246            "$P_SRV force_version=tls12 ca_callback=1 debug_level=3 auth_mode=optional" \
6247            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
6248             key_file=data_files/server5.key" \
6249            0 \
6250            -s "use CA callback for X.509 CRT verification" \
6251            -S "skip write certificate request" \
6252            -C "skip parse certificate request" \
6253            -c "got a certificate request" \
6254            -C "skip write certificate" \
6255            -C "skip write certificate verify" \
6256            -S "skip parse certificate verify" \
6257            -s "x509_verify_cert() returned" \
6258            -s "! The certificate is not correctly signed by the trusted CA" \
6259            -S "! mbedtls_ssl_handshake returned" \
6260            -C "! mbedtls_ssl_handshake returned" \
6261            -S "X509 - Certificate verification failed"
6262
6263requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6264requires_full_size_output_buffer
6265requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6266run_test    "Authentication, CA callback: server max_int chain, client default" \
6267            "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
6268                    key_file=data_files/dir-maxpath/09.key" \
6269            "$P_CLI force_version=tls12 ca_callback=1 debug_level=3 server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
6270            0 \
6271            -c "use CA callback for X.509 CRT verification" \
6272            -C "X509 - A fatal error occurred"
6273
6274requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6275requires_full_size_output_buffer
6276requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6277run_test    "Authentication, CA callback: server max_int+1 chain, client default" \
6278            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
6279                    key_file=data_files/dir-maxpath/10.key" \
6280            "$P_CLI force_version=tls12 debug_level=3 ca_callback=1 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
6281            1 \
6282            -c "use CA callback for X.509 CRT verification" \
6283            -c "X509 - A fatal error occurred"
6284
6285requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6286requires_full_size_output_buffer
6287requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6288run_test    "Authentication, CA callback: server max_int+1 chain, client optional" \
6289            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
6290                    key_file=data_files/dir-maxpath/10.key" \
6291            "$P_CLI force_version=tls12 ca_callback=1 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
6292                    debug_level=3 auth_mode=optional" \
6293            1 \
6294            -c "use CA callback for X.509 CRT verification" \
6295            -c "X509 - A fatal error occurred"
6296
6297requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6298requires_full_size_output_buffer
6299requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6300run_test    "Authentication, CA callback: client max_int+1 chain, server optional" \
6301            "$P_SRV force_version=tls12 ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
6302            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
6303                    key_file=data_files/dir-maxpath/10.key" \
6304            1 \
6305            -s "use CA callback for X.509 CRT verification" \
6306            -s "X509 - A fatal error occurred"
6307
6308requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6309requires_full_size_output_buffer
6310requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6311run_test    "Authentication, CA callback: client max_int+1 chain, server required" \
6312            "$P_SRV force_version=tls12 ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
6313            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
6314                    key_file=data_files/dir-maxpath/10.key" \
6315            1 \
6316            -s "use CA callback for X.509 CRT verification" \
6317            -s "X509 - A fatal error occurred"
6318
6319requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6320requires_full_size_output_buffer
6321requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6322run_test    "Authentication, CA callback: client max_int chain, server required" \
6323            "$P_SRV force_version=tls12 ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
6324            "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
6325                    key_file=data_files/dir-maxpath/09.key" \
6326            0 \
6327            -s "use CA callback for X.509 CRT verification" \
6328            -S "X509 - A fatal error occurred"
6329
6330# Tests for certificate selection based on SHA version
6331
6332requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6333run_test    "Certificate hash: client TLS 1.2 -> SHA-2" \
6334            "$P_SRV force_version=tls12 crt_file=data_files/server5.crt \
6335                    key_file=data_files/server5.key \
6336                    crt_file2=data_files/server5-sha1.crt \
6337                    key_file2=data_files/server5.key" \
6338            "$P_CLI" \
6339            0 \
6340            -c "signed using.*ECDSA with SHA256" \
6341            -C "signed using.*ECDSA with SHA1"
6342
6343# tests for SNI
6344
6345requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6346requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6347run_test    "SNI: no SNI callback" \
6348            "$P_SRV debug_level=3 \
6349             crt_file=data_files/server5.crt key_file=data_files/server5.key" \
6350            "$P_CLI server_name=localhost" \
6351            0 \
6352            -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
6353            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6354
6355requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6356requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6357run_test    "SNI: matching cert 1" \
6358            "$P_SRV debug_level=3 \
6359             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6360             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6361            "$P_CLI server_name=localhost" \
6362            0 \
6363            -s "parse ServerName extension" \
6364            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6365            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6366
6367requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6368requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6369run_test    "SNI: matching cert 2" \
6370            "$P_SRV debug_level=3 \
6371             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6372             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6373            "$P_CLI server_name=polarssl.example" \
6374            0 \
6375            -s "parse ServerName extension" \
6376            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6377            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
6378
6379requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6380requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6381run_test    "SNI: no matching cert" \
6382            "$P_SRV debug_level=3 \
6383             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6384             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6385            "$P_CLI server_name=nonesuch.example" \
6386            1 \
6387            -s "parse ServerName extension" \
6388            -s "ssl_sni_wrapper() returned" \
6389            -s "mbedtls_ssl_handshake returned" \
6390            -c "mbedtls_ssl_handshake returned" \
6391            -c "SSL - A fatal alert message was received from our peer"
6392
6393requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6394run_test    "SNI: client auth no override: optional" \
6395            "$P_SRV debug_level=3 auth_mode=optional \
6396             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6397             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
6398            "$P_CLI debug_level=3 server_name=localhost" \
6399            0 \
6400            -S "skip write certificate request" \
6401            -C "skip parse certificate request" \
6402            -c "got a certificate request" \
6403            -C "skip write certificate" \
6404            -C "skip write certificate verify" \
6405            -S "skip parse certificate verify"
6406
6407requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6408run_test    "SNI: client auth override: none -> optional" \
6409            "$P_SRV debug_level=3 auth_mode=none \
6410             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6411             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
6412            "$P_CLI debug_level=3 server_name=localhost" \
6413            0 \
6414            -S "skip write certificate request" \
6415            -C "skip parse certificate request" \
6416            -c "got a certificate request" \
6417            -C "skip write certificate" \
6418            -C "skip write certificate verify" \
6419            -S "skip parse certificate verify"
6420
6421requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6422run_test    "SNI: client auth override: optional -> none" \
6423            "$P_SRV debug_level=3 auth_mode=optional \
6424             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6425             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
6426            "$P_CLI debug_level=3 server_name=localhost" \
6427            0 \
6428            -s "skip write certificate request" \
6429            -C "skip parse certificate request" \
6430            -c "got no certificate request" \
6431            -c "skip write certificate"
6432
6433requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6434run_test    "SNI: CA no override" \
6435            "$P_SRV debug_level=3 auth_mode=optional \
6436             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6437             ca_file=data_files/test-ca.crt \
6438             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
6439            "$P_CLI debug_level=3 server_name=localhost \
6440             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6441            1 \
6442            -S "skip write certificate request" \
6443            -C "skip parse certificate request" \
6444            -c "got a certificate request" \
6445            -C "skip write certificate" \
6446            -C "skip write certificate verify" \
6447            -S "skip parse certificate verify" \
6448            -s "x509_verify_cert() returned" \
6449            -s "! The certificate is not correctly signed by the trusted CA" \
6450            -S "The certificate has been revoked (is on a CRL)"
6451
6452requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6453run_test    "SNI: CA override" \
6454            "$P_SRV debug_level=3 auth_mode=optional \
6455             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6456             ca_file=data_files/test-ca.crt \
6457             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
6458            "$P_CLI debug_level=3 server_name=localhost \
6459             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6460            0 \
6461            -S "skip write certificate request" \
6462            -C "skip parse certificate request" \
6463            -c "got a certificate request" \
6464            -C "skip write certificate" \
6465            -C "skip write certificate verify" \
6466            -S "skip parse certificate verify" \
6467            -S "x509_verify_cert() returned" \
6468            -S "! The certificate is not correctly signed by the trusted CA" \
6469            -S "The certificate has been revoked (is on a CRL)"
6470
6471requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6472run_test    "SNI: CA override with CRL" \
6473            "$P_SRV debug_level=3 auth_mode=optional \
6474             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6475             ca_file=data_files/test-ca.crt \
6476             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
6477            "$P_CLI debug_level=3 server_name=localhost \
6478             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6479            1 \
6480            -S "skip write certificate request" \
6481            -C "skip parse certificate request" \
6482            -c "got a certificate request" \
6483            -C "skip write certificate" \
6484            -C "skip write certificate verify" \
6485            -S "skip parse certificate verify" \
6486            -s "x509_verify_cert() returned" \
6487            -S "! The certificate is not correctly signed by the trusted CA" \
6488            -s "The certificate has been revoked (is on a CRL)"
6489
6490# Tests for SNI and DTLS
6491
6492requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6493requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6494run_test    "SNI: DTLS, no SNI callback" \
6495            "$P_SRV debug_level=3 dtls=1 \
6496             crt_file=data_files/server5.crt key_file=data_files/server5.key" \
6497            "$P_CLI server_name=localhost dtls=1" \
6498            0 \
6499            -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
6500            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6501
6502requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6503requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6504run_test    "SNI: DTLS, matching cert 1" \
6505            "$P_SRV debug_level=3 dtls=1 \
6506             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6507             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6508            "$P_CLI server_name=localhost dtls=1" \
6509            0 \
6510            -s "parse ServerName extension" \
6511            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6512            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6513
6514requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6515requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6516run_test    "SNI: DTLS, matching cert 2" \
6517            "$P_SRV debug_level=3 dtls=1 \
6518             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6519             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6520            "$P_CLI server_name=polarssl.example dtls=1" \
6521            0 \
6522            -s "parse ServerName extension" \
6523            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6524            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
6525
6526requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6527run_test    "SNI: DTLS, no matching cert" \
6528            "$P_SRV debug_level=3 dtls=1 \
6529             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6530             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6531            "$P_CLI server_name=nonesuch.example dtls=1" \
6532            1 \
6533            -s "parse ServerName extension" \
6534            -s "ssl_sni_wrapper() returned" \
6535            -s "mbedtls_ssl_handshake returned" \
6536            -c "mbedtls_ssl_handshake returned" \
6537            -c "SSL - A fatal alert message was received from our peer"
6538
6539requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6540run_test    "SNI: DTLS, client auth no override: optional" \
6541            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6542             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6543             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
6544            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6545            0 \
6546            -S "skip write certificate request" \
6547            -C "skip parse certificate request" \
6548            -c "got a certificate request" \
6549            -C "skip write certificate" \
6550            -C "skip write certificate verify" \
6551            -S "skip parse certificate verify"
6552
6553requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6554run_test    "SNI: DTLS, client auth override: none -> optional" \
6555            "$P_SRV debug_level=3 auth_mode=none dtls=1 \
6556             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6557             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
6558            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6559            0 \
6560            -S "skip write certificate request" \
6561            -C "skip parse certificate request" \
6562            -c "got a certificate request" \
6563            -C "skip write certificate" \
6564            -C "skip write certificate verify" \
6565            -S "skip parse certificate verify"
6566
6567requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6568run_test    "SNI: DTLS, client auth override: optional -> none" \
6569            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6570             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6571             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
6572            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6573            0 \
6574            -s "skip write certificate request" \
6575            -C "skip parse certificate request" \
6576            -c "got no certificate request" \
6577            -c "skip write certificate" \
6578            -c "skip write certificate verify" \
6579            -s "skip parse certificate verify"
6580
6581requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6582run_test    "SNI: DTLS, CA no override" \
6583            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6584             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6585             ca_file=data_files/test-ca.crt \
6586             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
6587            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6588             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6589            1 \
6590            -S "skip write certificate request" \
6591            -C "skip parse certificate request" \
6592            -c "got a certificate request" \
6593            -C "skip write certificate" \
6594            -C "skip write certificate verify" \
6595            -S "skip parse certificate verify" \
6596            -s "x509_verify_cert() returned" \
6597            -s "! The certificate is not correctly signed by the trusted CA" \
6598            -S "The certificate has been revoked (is on a CRL)"
6599
6600requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6601run_test    "SNI: DTLS, CA override" \
6602            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6603             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6604             ca_file=data_files/test-ca.crt \
6605             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
6606            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6607             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6608            0 \
6609            -S "skip write certificate request" \
6610            -C "skip parse certificate request" \
6611            -c "got a certificate request" \
6612            -C "skip write certificate" \
6613            -C "skip write certificate verify" \
6614            -S "skip parse certificate verify" \
6615            -S "x509_verify_cert() returned" \
6616            -S "! The certificate is not correctly signed by the trusted CA" \
6617            -S "The certificate has been revoked (is on a CRL)"
6618
6619requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6620run_test    "SNI: DTLS, CA override with CRL" \
6621            "$P_SRV debug_level=3 auth_mode=optional \
6622             crt_file=data_files/server5.crt key_file=data_files/server5.key dtls=1 \
6623             ca_file=data_files/test-ca.crt \
6624             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
6625            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6626             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6627            1 \
6628            -S "skip write certificate request" \
6629            -C "skip parse certificate request" \
6630            -c "got a certificate request" \
6631            -C "skip write certificate" \
6632            -C "skip write certificate verify" \
6633            -S "skip parse certificate verify" \
6634            -s "x509_verify_cert() returned" \
6635            -S "! The certificate is not correctly signed by the trusted CA" \
6636            -s "The certificate has been revoked (is on a CRL)"
6637
6638# Tests for non-blocking I/O: exercise a variety of handshake flows
6639
6640requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6641run_test    "Non-blocking I/O: basic handshake" \
6642            "$P_SRV nbio=2 tickets=0 auth_mode=none" \
6643            "$P_CLI nbio=2 tickets=0" \
6644            0 \
6645            -S "mbedtls_ssl_handshake returned" \
6646            -C "mbedtls_ssl_handshake returned" \
6647            -c "Read from server: .* bytes read"
6648
6649requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6650run_test    "Non-blocking I/O: client auth" \
6651            "$P_SRV nbio=2 tickets=0 auth_mode=required" \
6652            "$P_CLI nbio=2 tickets=0" \
6653            0 \
6654            -S "mbedtls_ssl_handshake returned" \
6655            -C "mbedtls_ssl_handshake returned" \
6656            -c "Read from server: .* bytes read"
6657
6658requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6659run_test    "Non-blocking I/O: ticket" \
6660            "$P_SRV nbio=2 tickets=1 auth_mode=none" \
6661            "$P_CLI nbio=2 tickets=1" \
6662            0 \
6663            -S "mbedtls_ssl_handshake returned" \
6664            -C "mbedtls_ssl_handshake returned" \
6665            -c "Read from server: .* bytes read"
6666
6667requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6668run_test    "Non-blocking I/O: ticket + client auth" \
6669            "$P_SRV nbio=2 tickets=1 auth_mode=required" \
6670            "$P_CLI nbio=2 tickets=1" \
6671            0 \
6672            -S "mbedtls_ssl_handshake returned" \
6673            -C "mbedtls_ssl_handshake returned" \
6674            -c "Read from server: .* bytes read"
6675
6676requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6677run_test    "Non-blocking I/O: TLS 1.2 + ticket + client auth + resume" \
6678            "$P_SRV nbio=2 tickets=1 auth_mode=required" \
6679            "$P_CLI force_version=tls12 nbio=2 tickets=1 reconnect=1" \
6680            0 \
6681            -S "mbedtls_ssl_handshake returned" \
6682            -C "mbedtls_ssl_handshake returned" \
6683            -c "Read from server: .* bytes read"
6684
6685requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
6686requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6687requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
6688run_test    "Non-blocking I/O: TLS 1.3 + ticket + client auth + resume" \
6689            "$P_SRV nbio=2 tickets=1 auth_mode=required" \
6690            "$P_CLI nbio=2 tickets=1 reconnect=1" \
6691            0 \
6692            -S "mbedtls_ssl_handshake returned" \
6693            -C "mbedtls_ssl_handshake returned" \
6694            -c "Read from server: .* bytes read"
6695
6696requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6697run_test    "Non-blocking I/O: TLS 1.2 + ticket + resume" \
6698            "$P_SRV nbio=2 tickets=1 auth_mode=none" \
6699            "$P_CLI force_version=tls12 nbio=2 tickets=1 reconnect=1" \
6700            0 \
6701            -S "mbedtls_ssl_handshake returned" \
6702            -C "mbedtls_ssl_handshake returned" \
6703            -c "Read from server: .* bytes read"
6704
6705requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
6706requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6707requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
6708run_test    "Non-blocking I/O: TLS 1.3 + ticket + resume" \
6709            "$P_SRV nbio=2 tickets=1 auth_mode=none" \
6710            "$P_CLI nbio=2 tickets=1 reconnect=1" \
6711            0 \
6712            -S "mbedtls_ssl_handshake returned" \
6713            -C "mbedtls_ssl_handshake returned" \
6714            -c "Read from server: .* bytes read"
6715
6716requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6717run_test    "Non-blocking I/O: session-id resume" \
6718            "$P_SRV nbio=2 tickets=0 auth_mode=none" \
6719            "$P_CLI force_version=tls12 nbio=2 tickets=0 reconnect=1" \
6720            0 \
6721            -S "mbedtls_ssl_handshake returned" \
6722            -C "mbedtls_ssl_handshake returned" \
6723            -c "Read from server: .* bytes read"
6724
6725# Tests for event-driven I/O: exercise a variety of handshake flows
6726
6727requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6728run_test    "Event-driven I/O: basic handshake" \
6729            "$P_SRV event=1 tickets=0 auth_mode=none" \
6730            "$P_CLI event=1 tickets=0" \
6731            0 \
6732            -S "mbedtls_ssl_handshake returned" \
6733            -C "mbedtls_ssl_handshake returned" \
6734            -c "Read from server: .* bytes read"
6735
6736requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6737run_test    "Event-driven I/O: client auth" \
6738            "$P_SRV event=1 tickets=0 auth_mode=required" \
6739            "$P_CLI event=1 tickets=0" \
6740            0 \
6741            -S "mbedtls_ssl_handshake returned" \
6742            -C "mbedtls_ssl_handshake returned" \
6743            -c "Read from server: .* bytes read"
6744
6745requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6746run_test    "Event-driven I/O: ticket" \
6747            "$P_SRV event=1 tickets=1 auth_mode=none" \
6748            "$P_CLI event=1 tickets=1" \
6749            0 \
6750            -S "mbedtls_ssl_handshake returned" \
6751            -C "mbedtls_ssl_handshake returned" \
6752            -c "Read from server: .* bytes read"
6753
6754requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6755run_test    "Event-driven I/O: ticket + client auth" \
6756            "$P_SRV event=1 tickets=1 auth_mode=required" \
6757            "$P_CLI event=1 tickets=1" \
6758            0 \
6759            -S "mbedtls_ssl_handshake returned" \
6760            -C "mbedtls_ssl_handshake returned" \
6761            -c "Read from server: .* bytes read"
6762
6763requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6764run_test    "Event-driven I/O: TLS 1.2 + ticket + client auth + resume" \
6765            "$P_SRV event=1 tickets=1 auth_mode=required" \
6766            "$P_CLI force_version=tls12 event=1 tickets=1 reconnect=1" \
6767            0 \
6768            -S "mbedtls_ssl_handshake returned" \
6769            -C "mbedtls_ssl_handshake returned" \
6770            -c "Read from server: .* bytes read"
6771
6772requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
6773requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6774requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
6775run_test    "Event-driven I/O: TLS 1.3 + ticket + client auth + resume" \
6776            "$P_SRV event=1 tickets=1 auth_mode=required" \
6777            "$P_CLI event=1 tickets=1 reconnect=1" \
6778            0 \
6779            -S "mbedtls_ssl_handshake returned" \
6780            -C "mbedtls_ssl_handshake returned" \
6781            -c "Read from server: .* bytes read"
6782
6783requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6784run_test    "Event-driven I/O: TLS 1.2 + ticket + resume" \
6785            "$P_SRV event=1 tickets=1 auth_mode=none" \
6786            "$P_CLI force_version=tls12 event=1 tickets=1 reconnect=1" \
6787            0 \
6788            -S "mbedtls_ssl_handshake returned" \
6789            -C "mbedtls_ssl_handshake returned" \
6790            -c "Read from server: .* bytes read"
6791
6792requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
6793requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6794requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
6795run_test    "Event-driven I/O: TLS 1.3 + ticket + resume" \
6796            "$P_SRV event=1 tickets=1 auth_mode=none" \
6797            "$P_CLI event=1 tickets=1 reconnect=1" \
6798            0 \
6799            -S "mbedtls_ssl_handshake returned" \
6800            -C "mbedtls_ssl_handshake returned" \
6801            -c "Read from server: .* bytes read"
6802
6803requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6804run_test    "Event-driven I/O: session-id resume" \
6805            "$P_SRV event=1 tickets=0 auth_mode=none" \
6806            "$P_CLI force_version=tls12 event=1 tickets=0 reconnect=1" \
6807            0 \
6808            -S "mbedtls_ssl_handshake returned" \
6809            -C "mbedtls_ssl_handshake returned" \
6810            -c "Read from server: .* bytes read"
6811
6812requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6813run_test    "Event-driven I/O, DTLS: basic handshake" \
6814            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
6815            "$P_CLI dtls=1 event=1 tickets=0" \
6816            0 \
6817            -c "Read from server: .* bytes read"
6818
6819requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6820run_test    "Event-driven I/O, DTLS: client auth" \
6821            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
6822            "$P_CLI dtls=1 event=1 tickets=0" \
6823            0 \
6824            -c "Read from server: .* bytes read"
6825
6826requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6827run_test    "Event-driven I/O, DTLS: ticket" \
6828            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
6829            "$P_CLI dtls=1 event=1 tickets=1" \
6830            0 \
6831            -c "Read from server: .* bytes read"
6832
6833requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6834run_test    "Event-driven I/O, DTLS: ticket + client auth" \
6835            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
6836            "$P_CLI dtls=1 event=1 tickets=1" \
6837            0 \
6838            -c "Read from server: .* bytes read"
6839
6840requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6841run_test    "Event-driven I/O, DTLS: ticket + client auth + resume" \
6842            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
6843            "$P_CLI dtls=1 event=1 tickets=1 reconnect=1 skip_close_notify=1" \
6844            0 \
6845            -c "Read from server: .* bytes read"
6846
6847requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6848run_test    "Event-driven I/O, DTLS: ticket + resume" \
6849            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
6850            "$P_CLI dtls=1 event=1 tickets=1 reconnect=1 skip_close_notify=1" \
6851            0 \
6852            -c "Read from server: .* bytes read"
6853
6854requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6855run_test    "Event-driven I/O, DTLS: session-id resume" \
6856            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
6857            "$P_CLI dtls=1 event=1 tickets=0 reconnect=1 skip_close_notify=1" \
6858            0 \
6859            -c "Read from server: .* bytes read"
6860
6861# This test demonstrates the need for the mbedtls_ssl_check_pending function.
6862# During session resumption, the client will send its ApplicationData record
6863# within the same datagram as the Finished messages. In this situation, the
6864# server MUST NOT idle on the underlying transport after handshake completion,
6865# because the ApplicationData request has already been queued internally.
6866requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6867run_test    "Event-driven I/O, DTLS: session-id resume, UDP packing" \
6868            -p "$P_PXY pack=50" \
6869            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
6870            "$P_CLI dtls=1 event=1 tickets=0 reconnect=1 skip_close_notify=1" \
6871            0 \
6872            -c "Read from server: .* bytes read"
6873
6874# Tests for version negotiation, MbedTLS client and server
6875
6876requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C
6877requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_3
6878requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6879run_test    "Version negotiation check m->m: 1.2 / 1.2 -> 1.2" \
6880            "$P_SRV" \
6881            "$P_CLI" \
6882            0 \
6883            -S "mbedtls_ssl_handshake returned" \
6884            -C "mbedtls_ssl_handshake returned" \
6885            -s "Protocol is TLSv1.2" \
6886            -c "Protocol is TLSv1.2"
6887
6888requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6889                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
6890requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6891run_test    "Version negotiation check m->m: 1.2 (max=1.2) / 1.2 (max=1.2) -> 1.2" \
6892            "$P_SRV max_version=tls12" \
6893            "$P_CLI max_version=tls12" \
6894            0 \
6895            -S "mbedtls_ssl_handshake returned" \
6896            -C "mbedtls_ssl_handshake returned" \
6897            -s "Protocol is TLSv1.2" \
6898            -c "Protocol is TLSv1.2"
6899
6900requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6901                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6902requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_2
6903run_test    "Version negotiation check m->m: 1.3 / 1.3 -> 1.3" \
6904            "$P_SRV" \
6905            "$P_CLI" \
6906            0 \
6907            -S "mbedtls_ssl_handshake returned" \
6908            -C "mbedtls_ssl_handshake returned" \
6909            -s "Protocol is TLSv1.3" \
6910            -c "Protocol is TLSv1.3"
6911
6912requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6913                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
6914                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6915run_test    "Version negotiation check m->m: 1.3 (min=1.3) / 1.3 (min=1.3) -> 1.3" \
6916            "$P_SRV min_version=tls13" \
6917            "$P_CLI min_version=tls13" \
6918            0 \
6919            -S "mbedtls_ssl_handshake returned" \
6920            -C "mbedtls_ssl_handshake returned" \
6921            -s "Protocol is TLSv1.3" \
6922            -c "Protocol is TLSv1.3"
6923
6924requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6925                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
6926                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6927run_test    "Version negotiation check m->m: 1.2+1.3 / 1.2+1.3 -> 1.3" \
6928            "$P_SRV" \
6929            "$P_CLI" \
6930            0 \
6931            -S "mbedtls_ssl_handshake returned" \
6932            -C "mbedtls_ssl_handshake returned" \
6933            -s "Protocol is TLSv1.3" \
6934            -c "Protocol is TLSv1.3"
6935
6936requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6937                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
6938                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6939run_test    "Version negotiation check m->m: 1.2+1.3 / 1.3 (min=1.3) -> 1.3" \
6940            "$P_SRV min_version=tls13" \
6941            "$P_CLI" \
6942            0 \
6943            -S "mbedtls_ssl_handshake returned" \
6944            -C "mbedtls_ssl_handshake returned" \
6945            -s "Protocol is TLSv1.3" \
6946            -c "Protocol is TLSv1.3"
6947
6948requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6949                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
6950requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6951run_test    "Version negotiation check m->m: 1.2+1.3 / 1.2 (max=1.2) -> 1.2" \
6952            "$P_SRV max_version=tls12" \
6953            "$P_CLI" \
6954            0 \
6955            -S "mbedtls_ssl_handshake returned" \
6956            -C "mbedtls_ssl_handshake returned" \
6957            -s "Protocol is TLSv1.2" \
6958            -c "Protocol is TLSv1.2"
6959
6960requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6961                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
6962requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6963run_test    "Version negotiation check m->m: 1.2 (max=1.2) / 1.2+1.3 -> 1.2" \
6964            "$P_SRV" \
6965            "$P_CLI max_version=tls12" \
6966            0 \
6967            -S "mbedtls_ssl_handshake returned" \
6968            -C "mbedtls_ssl_handshake returned" \
6969            -s "Protocol is TLSv1.2" \
6970            -c "Protocol is TLSv1.2"
6971
6972requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6973                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
6974                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6975run_test    "Version negotiation check m->m: 1.3 (min=1.3) / 1.2+1.3 -> 1.3" \
6976            "$P_SRV" \
6977            "$P_CLI min_version=tls13" \
6978            0 \
6979            -S "mbedtls_ssl_handshake returned" \
6980            -C "mbedtls_ssl_handshake returned" \
6981            -s "Protocol is TLSv1.3" \
6982            -c "Protocol is TLSv1.3"
6983
6984requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6985                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
6986run_test    "Not supported version check m->m: 1.2 (max=1.2) / 1.3 (min=1.3)" \
6987            "$P_SRV min_version=tls13" \
6988            "$P_CLI max_version=tls12" \
6989            1 \
6990            -s "Handshake protocol not within min/max boundaries" \
6991            -S "Protocol is TLSv1.2" \
6992            -C "Protocol is TLSv1.2" \
6993            -S "Protocol is TLSv1.3" \
6994            -C "Protocol is TLSv1.3"
6995
6996requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C \
6997                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
6998run_test    "Not supported version check m->m: 1.3 (min=1.3) / 1.2 (max=1.2)" \
6999            "$P_SRV max_version=tls12" \
7000            "$P_CLI min_version=tls13" \
7001            1 \
7002            -s "The handshake negotiation failed" \
7003            -S "Protocol is TLSv1.2" \
7004            -C "Protocol is TLSv1.2" \
7005            -S "Protocol is TLSv1.3" \
7006            -C "Protocol is TLSv1.3"
7007
7008# Tests of version negotiation on server side against GnuTLS client
7009
7010requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_2
7011requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7012run_test    "Server version nego check G->m: 1.2 / 1.2+(1.3) -> 1.2" \
7013            "$P_SRV" \
7014            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
7015            0 \
7016            -S "mbedtls_ssl_handshake returned" \
7017            -s "Protocol is TLSv1.2"
7018
7019requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7020                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7021requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7022run_test    "Server version nego check G->m: 1.2 / 1.2 (max=1.2) -> 1.2" \
7023            "$P_SRV max_version=tls12" \
7024            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
7025            0 \
7026            -S "mbedtls_ssl_handshake returned" \
7027            -s "Protocol is TLSv1.2"
7028
7029requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_3 \
7030                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7031                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7032run_test    "Server version nego check G->m: 1.3 / (1.2)+1.3 -> 1.3" \
7033            "$P_SRV" \
7034            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3" \
7035            0 \
7036            -S "mbedtls_ssl_handshake returned" \
7037            -s "Protocol is TLSv1.3"
7038
7039requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7040                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
7041                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7042                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7043run_test    "Server version nego check G->m: 1.3 / 1.3 (min=1.3) -> 1.3" \
7044            "$P_SRV min_version=tls13" \
7045            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3" \
7046            0 \
7047            -S "mbedtls_ssl_handshake returned" \
7048            -s "Protocol is TLSv1.3"
7049
7050requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_3 \
7051                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7052                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7053run_test    "Server version nego check G->m: 1.2+1.3 / (1.2)+1.3 -> 1.3" \
7054            "$P_SRV" \
7055            "$G_NEXT_CLI localhost --priority=NORMAL" \
7056            0 \
7057            -S "mbedtls_ssl_handshake returned" \
7058            -s "Protocol is TLSv1.3"
7059
7060requires_gnutls_next_disable_tls13_compat
7061requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_3 \
7062                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7063run_test    "Server version nego check G->m (no compat): 1.2+1.3 / (1.2)+1.3 -> 1.3" \
7064            "$P_SRV" \
7065            "$G_NEXT_CLI localhost --priority=NORMAL:%DISABLE_TLS13_COMPAT_MODE" \
7066            0 \
7067            -S "mbedtls_ssl_handshake returned" \
7068            -s "Protocol is TLSv1.3"
7069
7070# GnuTLS can be setup to send a ClientHello containing a supported versions
7071# extension proposing TLS 1.2 (preferred) and then TLS 1.3. In that case,
7072# a TLS 1.3 and TLS 1.2 capable server is supposed to negotiate TLS 1.2 and
7073# to indicate in the ServerHello that it downgrades from TLS 1.3. The GnuTLS
7074# client then detects the downgrade indication and aborts the handshake even
7075# if TLS 1.2 was its preferred version. Keeping the test even if the
7076# handshake fails eventually as it exercices parts of the Mbed TLS
7077# implementation that are otherwise not exercised.
7078requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7079                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
7080                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7081run_test    "Server version nego check G->m: [1.2]+1.3 / 1.2+1.3 -> 1.2" \
7082            "$P_SRV" \
7083            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:+VERS-TLS1.3" \
7084            1 \
7085            -c "Detected downgrade to TLS 1.2 from TLS 1.3"
7086
7087requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7088                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
7089                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7090                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7091run_test    "Server version nego check G->m: 1.2+1.3 / 1.3 (min=1.3) -> 1.3" \
7092            "$P_SRV min_version=tls13" \
7093            "$G_NEXT_CLI localhost --priority=NORMAL" \
7094            0 \
7095            -S "mbedtls_ssl_handshake returned" \
7096            -s "Protocol is TLSv1.3"
7097
7098requires_config_enabled MBEDTLS_SSL_SRV_C
7099requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_3
7100requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7101run_test    "Server version nego check G->m: 1.2+1.3 / 1.2 -> 1.2" \
7102            "$P_SRV" \
7103            "$G_NEXT_CLI localhost --priority=NORMAL" \
7104            0 \
7105            -S "mbedtls_ssl_handshake returned" \
7106            -s "Protocol is TLSv1.2"
7107
7108requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7109                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7110requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7111run_test    "Server version nego check G->m: 1.2+1.3 / 1.2 (max=1.2) -> 1.2" \
7112            "$P_SRV max_version=tls12" \
7113            "$G_NEXT_CLI localhost --priority=NORMAL" \
7114            0 \
7115            -S "mbedtls_ssl_handshake returned" \
7116            -s "Protocol is TLSv1.2"
7117
7118requires_config_enabled MBEDTLS_SSL_SRV_C
7119run_test    "Not supported version check G->m: 1.0 / (1.2)+(1.3)" \
7120            "$P_SRV" \
7121            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.0" \
7122            1 \
7123            -s "Handshake protocol not within min/max boundaries" \
7124            -S "Protocol is TLSv1.0"
7125
7126requires_config_enabled MBEDTLS_SSL_SRV_C
7127run_test    "Not supported version check G->m: 1.1 / (1.2)+(1.3)" \
7128            "$P_SRV" \
7129            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.1" \
7130            1 \
7131            -s "Handshake protocol not within min/max boundaries" \
7132            -S "Protocol is TLSv1.1"
7133
7134requires_config_enabled MBEDTLS_SSL_SRV_C
7135requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_2
7136run_test    "Not supported version check G->m: 1.2 / 1.3" \
7137            "$P_SRV" \
7138            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
7139            1 \
7140            -s "Handshake protocol not within min/max boundaries" \
7141            -S "Protocol is TLSv1.2"
7142
7143requires_config_enabled MBEDTLS_SSL_SRV_C
7144requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_3
7145run_test    "Not supported version check G->m: 1.3 / 1.2" \
7146            "$P_SRV" \
7147            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3" \
7148            1 \
7149            -S "Handshake protocol not within min/max boundaries" \
7150            -s "The handshake negotiation failed" \
7151            -S "Protocol is TLSv1.3"
7152
7153requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7154                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7155run_test    "Not supported version check G->m: 1.2 / 1.3 (min=1.3)" \
7156            "$P_SRV min_version=tls13" \
7157            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
7158            1 \
7159            -s "Handshake protocol not within min/max boundaries" \
7160            -S "Protocol is TLSv1.2"
7161
7162requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7163                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7164run_test    "Not supported version check G->m: 1.3 / 1.2 (max=1.2)" \
7165            "$P_SRV max_version=tls12" \
7166            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3" \
7167            1 \
7168            -S "Handshake protocol not within min/max boundaries" \
7169            -s "The handshake negotiation failed" \
7170            -S "Protocol is TLSv1.3"
7171
7172# Tests of version negotiation on server side against OpenSSL client
7173
7174requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_2
7175requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7176run_test    "Server version nego check O->m: 1.2 / 1.2+(1.3) -> 1.2" \
7177            "$P_SRV" \
7178            "$O_NEXT_CLI -tls1_2" \
7179            0 \
7180            -S "mbedtls_ssl_handshake returned" \
7181            -s "Protocol is TLSv1.2"
7182
7183requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7184                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7185requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7186run_test    "Server version nego check O->m: 1.2 / 1.2 (max=1.2) -> 1.2" \
7187            "$P_SRV max_version=tls12" \
7188            "$O_NEXT_CLI -tls1_2" \
7189            0 \
7190            -S "mbedtls_ssl_handshake returned" \
7191            -s "Protocol is TLSv1.2"
7192
7193requires_openssl_tls1_3_with_compatible_ephemeral
7194requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_3 \
7195                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7196                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7197run_test    "Server version nego check O->m: 1.3 / (1.2)+1.3 -> 1.3" \
7198            "$P_SRV" \
7199            "$O_NEXT_CLI -tls1_3" \
7200            0 \
7201            -S "mbedtls_ssl_handshake returned" \
7202            -s "Protocol is TLSv1.3"
7203
7204requires_openssl_tls1_3_with_compatible_ephemeral
7205requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7206                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
7207                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7208                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7209run_test    "Server version nego check O->m: 1.3 / 1.3 (min=1.3) -> 1.3" \
7210            "$P_SRV min_version=tls13" \
7211            "$O_NEXT_CLI -tls1_3" \
7212            0 \
7213            -S "mbedtls_ssl_handshake returned" \
7214            -s "Protocol is TLSv1.3"
7215
7216requires_openssl_tls1_3_with_compatible_ephemeral
7217requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_3 \
7218                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7219                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7220run_test    "Server version nego check O->m: 1.2+1.3 / (1.2)+1.3 -> 1.3" \
7221            "$P_SRV" \
7222            "$O_NEXT_CLI" \
7223            0 \
7224            -S "mbedtls_ssl_handshake returned" \
7225            -s "Protocol is TLSv1.3"
7226
7227requires_openssl_tls1_3_with_compatible_ephemeral
7228requires_all_configs_enabled MBEDTLS_SSL_SRV_C MBEDTLS_SSL_PROTO_TLS1_3 \
7229                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7230run_test    "Server version nego check O->m (no compat): 1.2+1.3 / (1.2)+1.3 -> 1.3" \
7231            "$P_SRV" \
7232            "$O_NEXT_CLI -no_middlebox" \
7233            0 \
7234            -S "mbedtls_ssl_handshake returned" \
7235            -s "Protocol is TLSv1.3"
7236
7237requires_openssl_tls1_3_with_compatible_ephemeral
7238requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7239                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3 \
7240                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
7241                             MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
7242run_test    "Server version nego check O->m: 1.2+1.3 / 1.3 (min=1.3) -> 1.3" \
7243            "$P_SRV min_version=tls13" \
7244            "$O_NEXT_CLI" \
7245            0 \
7246            -S "mbedtls_ssl_handshake returned" \
7247            -s "Protocol is TLSv1.3"
7248
7249requires_config_enabled MBEDTLS_SSL_SRV_C
7250requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_3
7251requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7252run_test    "Server version nego check O->m: 1.2+1.3 / 1.2 -> 1.2" \
7253            "$P_SRV" \
7254            "$O_NEXT_CLI" \
7255            0 \
7256            -S "mbedtls_ssl_handshake returned" \
7257            -s "Protocol is TLSv1.2"
7258
7259requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7260                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7261requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
7262run_test    "Server version nego check O->m: 1.2+1.3 / 1.2 (max=1.2) -> 1.2" \
7263            "$P_SRV max_version=tls12" \
7264            "$O_NEXT_CLI" \
7265            0 \
7266            -S "mbedtls_ssl_handshake returned" \
7267            -s "Protocol is TLSv1.2"
7268
7269requires_config_enabled MBEDTLS_SSL_SRV_C
7270run_test    "Not supported version check O->m: 1.0 / (1.2)+(1.3)" \
7271            "$P_SRV" \
7272            "$O_CLI -tls1" \
7273            1 \
7274            -s "Handshake protocol not within min/max boundaries" \
7275            -S "Protocol is TLSv1.0"
7276
7277requires_config_enabled MBEDTLS_SSL_SRV_C
7278run_test    "Not supported version check O->m: 1.1 / (1.2)+(1.3)" \
7279            "$P_SRV" \
7280            "$O_CLI -tls1_1" \
7281            1 \
7282            -s "Handshake protocol not within min/max boundaries" \
7283            -S "Protocol is TLSv1.1"
7284
7285requires_config_enabled MBEDTLS_SSL_SRV_C
7286requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_2
7287run_test    "Not supported version check O->m: 1.2 / 1.3" \
7288            "$P_SRV" \
7289            "$O_NEXT_CLI -tls1_2" \
7290            1 \
7291            -s "Handshake protocol not within min/max boundaries" \
7292            -S "Protocol is TLSv1.2"
7293
7294requires_config_enabled MBEDTLS_SSL_SRV_C
7295requires_config_disabled MBEDTLS_SSL_PROTO_TLS1_3
7296run_test    "Not supported version check O->m: 1.3 / 1.2" \
7297            "$P_SRV" \
7298            "$O_NEXT_CLI -tls1_3" \
7299            1 \
7300            -S "Handshake protocol not within min/max boundaries" \
7301            -s "The handshake negotiation failed" \
7302            -S "Protocol is TLSv1.3"
7303
7304requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7305                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7306run_test    "Not supported version check O->m: 1.2 / 1.3 (min=1.3)" \
7307            "$P_SRV min_version=tls13" \
7308            "$O_NEXT_CLI -tls1_2" \
7309            1 \
7310            -s "Handshake protocol not within min/max boundaries" \
7311            -S "Protocol is TLSv1.2"
7312
7313requires_all_configs_enabled MBEDTLS_SSL_SRV_C \
7314                             MBEDTLS_SSL_PROTO_TLS1_2 MBEDTLS_SSL_PROTO_TLS1_3
7315run_test    "Not supported version check O->m: 1.3 / 1.2 (max=1.2)" \
7316            "$P_SRV max_version=tls12" \
7317            "$O_NEXT_CLI -tls1_3" \
7318            1 \
7319            -S "Handshake protocol not within min/max boundaries" \
7320            -s "The handshake negotiation failed" \
7321            -S "Protocol is TLSv1.3"
7322
7323# Tests of version negotiation on client side against GnuTLS and OpenSSL server
7324
7325requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7326run_test    "Not supported version check: srv max TLS 1.0" \
7327            "$G_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0" \
7328            "$P_CLI" \
7329            1 \
7330            -s "Error in protocol version" \
7331            -c "Handshake protocol not within min/max boundaries" \
7332            -S "Version: TLS1.0" \
7333            -C "Protocol is TLSv1.0"
7334
7335requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7336run_test    "Not supported version check: srv max TLS 1.1" \
7337            "$G_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1" \
7338            "$P_CLI" \
7339            1 \
7340            -s "Error in protocol version" \
7341            -c "Handshake protocol not within min/max boundaries" \
7342            -S "Version: TLS1.1" \
7343            -C "Protocol is TLSv1.1"
7344
7345requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
7346requires_config_enabled MBEDTLS_DEBUG_C
7347requires_config_enabled MBEDTLS_SSL_CLI_C
7348skip_handshake_stage_check
7349requires_gnutls_tls1_3
7350run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.0" \
7351            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0 -d 4" \
7352            "$P_CLI debug_level=4" \
7353            1 \
7354            -s "Client's version: 3.3" \
7355            -S "Version: TLS1.0" \
7356            -C "Protocol is TLSv1.0"
7357
7358requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
7359requires_config_enabled MBEDTLS_DEBUG_C
7360requires_config_enabled MBEDTLS_SSL_CLI_C
7361skip_handshake_stage_check
7362requires_gnutls_tls1_3
7363run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.1" \
7364            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1 -d 4" \
7365            "$P_CLI debug_level=4" \
7366            1 \
7367            -s "Client's version: 3.3" \
7368            -S "Version: TLS1.1" \
7369            -C "Protocol is TLSv1.1"
7370
7371requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
7372requires_config_enabled MBEDTLS_DEBUG_C
7373requires_config_enabled MBEDTLS_SSL_CLI_C
7374skip_handshake_stage_check
7375requires_gnutls_tls1_3
7376run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.2" \
7377            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2 -d 4" \
7378            "$P_CLI force_version=tls13 debug_level=4" \
7379            1 \
7380            -s "Client's version: 3.3" \
7381            -c "is a fatal alert message (msg 40)" \
7382            -S "Version: TLS1.2" \
7383            -C "Protocol is TLSv1.2"
7384
7385requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
7386requires_config_enabled MBEDTLS_DEBUG_C
7387requires_config_enabled MBEDTLS_SSL_CLI_C
7388skip_handshake_stage_check
7389requires_openssl_next
7390run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.0" \
7391            "$O_NEXT_SRV -msg -tls1" \
7392            "$P_CLI debug_level=4" \
7393            1 \
7394            -s "fatal protocol_version" \
7395            -c "is a fatal alert message (msg 70)" \
7396            -S "Version: TLS1.0" \
7397            -C "Protocol  : TLSv1.0"
7398
7399requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
7400requires_config_enabled MBEDTLS_DEBUG_C
7401requires_config_enabled MBEDTLS_SSL_CLI_C
7402skip_handshake_stage_check
7403requires_openssl_next
7404run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.1" \
7405            "$O_NEXT_SRV -msg -tls1_1" \
7406            "$P_CLI debug_level=4" \
7407            1 \
7408            -s "fatal protocol_version" \
7409            -c "is a fatal alert message (msg 70)" \
7410            -S "Version: TLS1.1" \
7411            -C "Protocol  : TLSv1.1"
7412
7413requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
7414requires_config_enabled MBEDTLS_DEBUG_C
7415requires_config_enabled MBEDTLS_SSL_CLI_C
7416skip_handshake_stage_check
7417requires_openssl_next
7418run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.2" \
7419            "$O_NEXT_SRV -msg -tls1_2" \
7420            "$P_CLI force_version=tls13 debug_level=4" \
7421            1 \
7422            -s "fatal protocol_version" \
7423            -c "is a fatal alert message (msg 70)" \
7424            -S "Version: TLS1.2" \
7425            -C "Protocol  : TLSv1.2"
7426
7427# Tests for ALPN extension
7428
7429requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7430run_test    "ALPN: none" \
7431            "$P_SRV debug_level=3" \
7432            "$P_CLI debug_level=3" \
7433            0 \
7434            -C "client hello, adding alpn extension" \
7435            -S "found alpn extension" \
7436            -C "got an alert message, type: \\[2:120]" \
7437            -S "server side, adding alpn extension" \
7438            -C "found alpn extension " \
7439            -C "Application Layer Protocol is" \
7440            -S "Application Layer Protocol is"
7441
7442requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7443run_test    "ALPN: client only" \
7444            "$P_SRV debug_level=3" \
7445            "$P_CLI debug_level=3 alpn=abc,1234" \
7446            0 \
7447            -c "client hello, adding alpn extension" \
7448            -s "found alpn extension" \
7449            -C "got an alert message, type: \\[2:120]" \
7450            -S "server side, adding alpn extension" \
7451            -C "found alpn extension " \
7452            -c "Application Layer Protocol is (none)" \
7453            -S "Application Layer Protocol is"
7454
7455requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7456run_test    "ALPN: server only" \
7457            "$P_SRV debug_level=3 alpn=abc,1234" \
7458            "$P_CLI debug_level=3" \
7459            0 \
7460            -C "client hello, adding alpn extension" \
7461            -S "found alpn extension" \
7462            -C "got an alert message, type: \\[2:120]" \
7463            -S "server side, adding alpn extension" \
7464            -C "found alpn extension " \
7465            -C "Application Layer Protocol is" \
7466            -s "Application Layer Protocol is (none)"
7467
7468requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7469run_test    "ALPN: both, common cli1-srv1" \
7470            "$P_SRV debug_level=3 alpn=abc,1234" \
7471            "$P_CLI debug_level=3 alpn=abc,1234" \
7472            0 \
7473            -c "client hello, adding alpn extension" \
7474            -s "found alpn extension" \
7475            -C "got an alert message, type: \\[2:120]" \
7476            -s "server side, adding alpn extension" \
7477            -c "found alpn extension" \
7478            -c "Application Layer Protocol is abc" \
7479            -s "Application Layer Protocol is abc"
7480
7481requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7482run_test    "ALPN: both, common cli2-srv1" \
7483            "$P_SRV debug_level=3 alpn=abc,1234" \
7484            "$P_CLI debug_level=3 alpn=1234,abc" \
7485            0 \
7486            -c "client hello, adding alpn extension" \
7487            -s "found alpn extension" \
7488            -C "got an alert message, type: \\[2:120]" \
7489            -s "server side, adding alpn extension" \
7490            -c "found alpn extension" \
7491            -c "Application Layer Protocol is abc" \
7492            -s "Application Layer Protocol is abc"
7493
7494requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7495run_test    "ALPN: both, common cli1-srv2" \
7496            "$P_SRV debug_level=3 alpn=abc,1234" \
7497            "$P_CLI debug_level=3 alpn=1234,abcde" \
7498            0 \
7499            -c "client hello, adding alpn extension" \
7500            -s "found alpn extension" \
7501            -C "got an alert message, type: \\[2:120]" \
7502            -s "server side, adding alpn extension" \
7503            -c "found alpn extension" \
7504            -c "Application Layer Protocol is 1234" \
7505            -s "Application Layer Protocol is 1234"
7506
7507requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7508run_test    "ALPN: both, no common" \
7509            "$P_SRV debug_level=3 alpn=abc,123" \
7510            "$P_CLI debug_level=3 alpn=1234,abcde" \
7511            1 \
7512            -c "client hello, adding alpn extension" \
7513            -s "found alpn extension" \
7514            -c "got an alert message, type: \\[2:120]" \
7515            -S "server side, adding alpn extension" \
7516            -C "found alpn extension" \
7517            -C "Application Layer Protocol is 1234" \
7518            -S "Application Layer Protocol is 1234"
7519
7520
7521# Tests for keyUsage in leaf certificates, part 1:
7522# server-side certificate/suite selection
7523
7524run_test    "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
7525            "$P_SRV force_version=tls12 key_file=data_files/server2.key \
7526             crt_file=data_files/server2.ku-ds.crt" \
7527            "$P_CLI" \
7528            0 \
7529            -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
7530
7531run_test    "keyUsage srv: RSA, keyEncipherment -> RSA" \
7532            "$P_SRV force_version=tls12 key_file=data_files/server2.key \
7533             crt_file=data_files/server2.ku-ke.crt" \
7534            "$P_CLI" \
7535            0 \
7536            -c "Ciphersuite is TLS-RSA-WITH-"
7537
7538run_test    "keyUsage srv: RSA, keyAgreement -> fail" \
7539            "$P_SRV force_version=tls12 key_file=data_files/server2.key \
7540             crt_file=data_files/server2.ku-ka.crt" \
7541            "$P_CLI" \
7542            1 \
7543            -C "Ciphersuite is "
7544
7545requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
7546run_test    "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
7547            "$P_SRV force_version=tls12 key_file=data_files/server5.key \
7548             crt_file=data_files/server5.ku-ds.crt" \
7549            "$P_CLI" \
7550            0 \
7551            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
7552
7553
7554run_test    "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
7555            "$P_SRV force_version=tls12 key_file=data_files/server5.key \
7556             crt_file=data_files/server5.ku-ka.crt" \
7557            "$P_CLI" \
7558            0 \
7559            -c "Ciphersuite is TLS-ECDH-"
7560
7561run_test    "keyUsage srv: ECDSA, keyEncipherment -> fail" \
7562            "$P_SRV force_version=tls12 key_file=data_files/server5.key \
7563             crt_file=data_files/server5.ku-ke.crt" \
7564            "$P_CLI" \
7565            1 \
7566            -C "Ciphersuite is "
7567
7568# Tests for keyUsage in leaf certificates, part 2:
7569# client-side checking of server cert
7570
7571run_test    "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
7572            "$O_SRV -tls1_2 -key data_files/server2.key \
7573             -cert data_files/server2.ku-ds_ke.crt" \
7574            "$P_CLI debug_level=1 \
7575             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
7576            0 \
7577            -C "bad certificate (usage extensions)" \
7578            -C "Processing of the Certificate handshake message failed" \
7579            -c "Ciphersuite is TLS-"
7580
7581run_test    "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
7582            "$O_SRV -tls1_2 -key data_files/server2.key \
7583             -cert data_files/server2.ku-ds_ke.crt" \
7584            "$P_CLI debug_level=1 \
7585             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
7586            0 \
7587            -C "bad certificate (usage extensions)" \
7588            -C "Processing of the Certificate handshake message failed" \
7589            -c "Ciphersuite is TLS-"
7590
7591run_test    "keyUsage cli: KeyEncipherment, RSA: OK" \
7592            "$O_SRV -tls1_2 -key data_files/server2.key \
7593             -cert data_files/server2.ku-ke.crt" \
7594            "$P_CLI debug_level=1 \
7595             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
7596            0 \
7597            -C "bad certificate (usage extensions)" \
7598            -C "Processing of the Certificate handshake message failed" \
7599            -c "Ciphersuite is TLS-"
7600
7601run_test    "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
7602            "$O_SRV -tls1_2 -key data_files/server2.key \
7603             -cert data_files/server2.ku-ke.crt" \
7604            "$P_CLI debug_level=1 \
7605             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
7606            1 \
7607            -c "bad certificate (usage extensions)" \
7608            -c "Processing of the Certificate handshake message failed" \
7609            -C "Ciphersuite is TLS-"
7610
7611run_test    "keyUsage cli: KeyEncipherment, DHE-RSA: fail, soft" \
7612            "$O_SRV -tls1_2 -key data_files/server2.key \
7613             -cert data_files/server2.ku-ke.crt" \
7614            "$P_CLI debug_level=1 auth_mode=optional \
7615             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
7616            0 \
7617            -c "bad certificate (usage extensions)" \
7618            -C "Processing of the Certificate handshake message failed" \
7619            -c "Ciphersuite is TLS-" \
7620            -c "! Usage does not match the keyUsage extension"
7621
7622run_test    "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
7623            "$O_SRV -tls1_2 -key data_files/server2.key \
7624             -cert data_files/server2.ku-ds.crt" \
7625            "$P_CLI debug_level=1 \
7626             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
7627            0 \
7628            -C "bad certificate (usage extensions)" \
7629            -C "Processing of the Certificate handshake message failed" \
7630            -c "Ciphersuite is TLS-"
7631
7632run_test    "keyUsage cli: DigitalSignature, RSA: fail" \
7633            "$O_SRV -tls1_2 -key data_files/server2.key \
7634             -cert data_files/server2.ku-ds.crt" \
7635            "$P_CLI debug_level=1 \
7636             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
7637            1 \
7638            -c "bad certificate (usage extensions)" \
7639            -c "Processing of the Certificate handshake message failed" \
7640            -C "Ciphersuite is TLS-"
7641
7642run_test    "keyUsage cli: DigitalSignature, RSA: fail, soft" \
7643            "$O_SRV -tls1_2 -key data_files/server2.key \
7644             -cert data_files/server2.ku-ds.crt" \
7645            "$P_CLI debug_level=1 auth_mode=optional \
7646             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
7647            0 \
7648            -c "bad certificate (usage extensions)" \
7649            -C "Processing of the Certificate handshake message failed" \
7650            -c "Ciphersuite is TLS-" \
7651            -c "! Usage does not match the keyUsage extension"
7652
7653requires_openssl_tls1_3_with_compatible_ephemeral
7654requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7655                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7656run_test    "keyUsage cli 1.3: DigitalSignature+KeyEncipherment, RSA: OK" \
7657            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
7658             -cert data_files/server2.ku-ds_ke.crt" \
7659            "$P_CLI debug_level=3" \
7660            0 \
7661            -C "bad certificate (usage extensions)" \
7662            -C "Processing of the Certificate handshake message failed" \
7663            -c "Ciphersuite is"
7664
7665requires_openssl_tls1_3_with_compatible_ephemeral
7666requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7667                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7668run_test    "keyUsage cli 1.3: KeyEncipherment, RSA: fail" \
7669            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
7670             -cert data_files/server2.ku-ke.crt" \
7671            "$P_CLI debug_level=1" \
7672            1 \
7673            -c "bad certificate (usage extensions)" \
7674            -c "Processing of the Certificate handshake message failed" \
7675            -C "Ciphersuite is"
7676
7677requires_openssl_tls1_3_with_compatible_ephemeral
7678requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7679                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7680run_test    "keyUsage cli 1.3: KeyAgreement, RSA: fail" \
7681            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
7682             -cert data_files/server2.ku-ka.crt" \
7683            "$P_CLI debug_level=1" \
7684            1 \
7685            -c "bad certificate (usage extensions)" \
7686            -c "Processing of the Certificate handshake message failed" \
7687            -C "Ciphersuite is"
7688
7689requires_openssl_tls1_3_with_compatible_ephemeral
7690requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7691                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7692run_test    "keyUsage cli 1.3: DigitalSignature, ECDSA: OK" \
7693            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7694             -cert data_files/server5.ku-ds.crt" \
7695            "$P_CLI debug_level=3" \
7696            0 \
7697            -C "bad certificate (usage extensions)" \
7698            -C "Processing of the Certificate handshake message failed" \
7699            -c "Ciphersuite is"
7700
7701requires_openssl_tls1_3_with_compatible_ephemeral
7702requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7703                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7704run_test    "keyUsage cli 1.3: KeyEncipherment, ECDSA: fail" \
7705            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7706             -cert data_files/server5.ku-ke.crt" \
7707            "$P_CLI debug_level=1" \
7708            1 \
7709            -c "bad certificate (usage extensions)" \
7710            -c "Processing of the Certificate handshake message failed" \
7711            -C "Ciphersuite is"
7712
7713requires_openssl_tls1_3_with_compatible_ephemeral
7714requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7715                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7716run_test    "keyUsage cli 1.3: KeyAgreement, ECDSA: fail" \
7717            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7718             -cert data_files/server5.ku-ka.crt" \
7719            "$P_CLI debug_level=1" \
7720            1 \
7721            -c "bad certificate (usage extensions)" \
7722            -c "Processing of the Certificate handshake message failed" \
7723            -C "Ciphersuite is"
7724
7725# Tests for keyUsage in leaf certificates, part 3:
7726# server-side checking of client cert
7727
7728requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7729run_test    "keyUsage cli-auth: RSA, DigitalSignature: OK" \
7730            "$P_SRV debug_level=1 auth_mode=optional" \
7731            "$O_CLI -key data_files/server2.key \
7732             -cert data_files/server2.ku-ds.crt" \
7733            0 \
7734            -s "Verifying peer X.509 certificate... ok" \
7735            -S "bad certificate (usage extensions)" \
7736            -S "Processing of the Certificate handshake message failed"
7737
7738requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7739run_test    "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
7740            "$P_SRV debug_level=1 auth_mode=optional" \
7741            "$O_CLI -key data_files/server2.key \
7742             -cert data_files/server2.ku-ke.crt" \
7743            0 \
7744            -s "bad certificate (usage extensions)" \
7745            -S "Processing of the Certificate handshake message failed"
7746
7747requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7748run_test    "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
7749            "$P_SRV debug_level=1 auth_mode=required" \
7750            "$O_CLI -key data_files/server2.key \
7751             -cert data_files/server2.ku-ke.crt" \
7752            1 \
7753            -s "bad certificate (usage extensions)" \
7754            -s "Processing of the Certificate handshake message failed"
7755
7756requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7757run_test    "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
7758            "$P_SRV debug_level=1 auth_mode=optional" \
7759            "$O_CLI -key data_files/server5.key \
7760             -cert data_files/server5.ku-ds.crt" \
7761            0 \
7762            -s "Verifying peer X.509 certificate... ok" \
7763            -S "bad certificate (usage extensions)" \
7764            -S "Processing of the Certificate handshake message failed"
7765
7766requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7767run_test    "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
7768            "$P_SRV debug_level=1 auth_mode=optional" \
7769            "$O_CLI -key data_files/server5.key \
7770             -cert data_files/server5.ku-ka.crt" \
7771            0 \
7772            -s "bad certificate (usage extensions)" \
7773            -S "Processing of the Certificate handshake message failed"
7774
7775requires_openssl_tls1_3_with_compatible_ephemeral
7776requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7777                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7778run_test    "keyUsage cli-auth 1.3: RSA, DigitalSignature: OK" \
7779            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7780            "$O_NEXT_CLI_NO_CERT -key data_files/server2.key \
7781             -cert data_files/server2.ku-ds.crt" \
7782            0 \
7783            -s "Verifying peer X.509 certificate... ok" \
7784            -S "bad certificate (usage extensions)" \
7785            -S "Processing of the Certificate handshake message failed"
7786
7787requires_openssl_tls1_3_with_compatible_ephemeral
7788requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7789                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7790run_test    "keyUsage cli-auth 1.3: RSA, KeyEncipherment: fail (soft)" \
7791            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7792            "$O_NEXT_CLI_NO_CERT -key data_files/server2.key \
7793             -cert data_files/server2.ku-ke.crt" \
7794            0 \
7795            -s "bad certificate (usage extensions)" \
7796            -S "Processing of the Certificate handshake message failed"
7797
7798requires_openssl_tls1_3_with_compatible_ephemeral
7799requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7800                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7801run_test    "keyUsage cli-auth 1.3: ECDSA, DigitalSignature: OK" \
7802            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7803            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7804             -cert data_files/server5.ku-ds.crt" \
7805            0 \
7806            -s "Verifying peer X.509 certificate... ok" \
7807            -S "bad certificate (usage extensions)" \
7808            -S "Processing of the Certificate handshake message failed"
7809
7810requires_openssl_tls1_3_with_compatible_ephemeral
7811requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7812                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7813run_test    "keyUsage cli-auth 1.3: ECDSA, KeyAgreement: fail (soft)" \
7814            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7815            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7816             -cert data_files/server5.ku-ka.crt" \
7817            0 \
7818            -s "bad certificate (usage extensions)" \
7819            -S "Processing of the Certificate handshake message failed"
7820
7821# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
7822
7823requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7824run_test    "extKeyUsage srv: serverAuth -> OK" \
7825            "$P_SRV key_file=data_files/server5.key \
7826             crt_file=data_files/server5.eku-srv.crt" \
7827            "$P_CLI" \
7828            0
7829
7830requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7831run_test    "extKeyUsage srv: serverAuth,clientAuth -> OK" \
7832            "$P_SRV key_file=data_files/server5.key \
7833             crt_file=data_files/server5.eku-srv.crt" \
7834            "$P_CLI" \
7835            0
7836
7837requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7838run_test    "extKeyUsage srv: codeSign,anyEKU -> OK" \
7839            "$P_SRV key_file=data_files/server5.key \
7840             crt_file=data_files/server5.eku-cs_any.crt" \
7841            "$P_CLI" \
7842            0
7843
7844requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
7845run_test    "extKeyUsage srv: codeSign -> fail" \
7846            "$P_SRV key_file=data_files/server5.key \
7847             crt_file=data_files/server5.eku-cli.crt" \
7848            "$P_CLI" \
7849            1
7850
7851# Tests for extendedKeyUsage, part 2: client-side checking of server cert
7852
7853requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7854run_test    "extKeyUsage cli: serverAuth -> OK" \
7855            "$O_SRV -tls1_2 -key data_files/server5.key \
7856             -cert data_files/server5.eku-srv.crt" \
7857            "$P_CLI debug_level=1" \
7858            0 \
7859            -C "bad certificate (usage extensions)" \
7860            -C "Processing of the Certificate handshake message failed" \
7861            -c "Ciphersuite is TLS-"
7862
7863requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7864run_test    "extKeyUsage cli: serverAuth,clientAuth -> OK" \
7865            "$O_SRV -tls1_2 -key data_files/server5.key \
7866             -cert data_files/server5.eku-srv_cli.crt" \
7867            "$P_CLI debug_level=1" \
7868            0 \
7869            -C "bad certificate (usage extensions)" \
7870            -C "Processing of the Certificate handshake message failed" \
7871            -c "Ciphersuite is TLS-"
7872
7873requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7874run_test    "extKeyUsage cli: codeSign,anyEKU -> OK" \
7875            "$O_SRV -tls1_2 -key data_files/server5.key \
7876             -cert data_files/server5.eku-cs_any.crt" \
7877            "$P_CLI debug_level=1" \
7878            0 \
7879            -C "bad certificate (usage extensions)" \
7880            -C "Processing of the Certificate handshake message failed" \
7881            -c "Ciphersuite is TLS-"
7882
7883requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7884run_test    "extKeyUsage cli: codeSign -> fail" \
7885            "$O_SRV -tls1_2 -key data_files/server5.key \
7886             -cert data_files/server5.eku-cs.crt" \
7887            "$P_CLI debug_level=1" \
7888            1 \
7889            -c "bad certificate (usage extensions)" \
7890            -c "Processing of the Certificate handshake message failed" \
7891            -C "Ciphersuite is TLS-"
7892
7893requires_openssl_tls1_3_with_compatible_ephemeral
7894requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7895                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7896run_test    "extKeyUsage cli 1.3: serverAuth -> OK" \
7897            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7898             -cert data_files/server5.eku-srv.crt" \
7899            "$P_CLI debug_level=1" \
7900            0 \
7901            -C "bad certificate (usage extensions)" \
7902            -C "Processing of the Certificate handshake message failed" \
7903            -c "Ciphersuite is"
7904
7905requires_openssl_tls1_3_with_compatible_ephemeral
7906requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7907                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7908run_test    "extKeyUsage cli 1.3: serverAuth,clientAuth -> OK" \
7909            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7910             -cert data_files/server5.eku-srv_cli.crt" \
7911            "$P_CLI debug_level=1" \
7912            0 \
7913            -C "bad certificate (usage extensions)" \
7914            -C "Processing of the Certificate handshake message failed" \
7915            -c "Ciphersuite is"
7916
7917requires_openssl_tls1_3_with_compatible_ephemeral
7918requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7919                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7920run_test    "extKeyUsage cli 1.3: codeSign,anyEKU -> OK" \
7921            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7922             -cert data_files/server5.eku-cs_any.crt" \
7923            "$P_CLI debug_level=1" \
7924            0 \
7925            -C "bad certificate (usage extensions)" \
7926            -C "Processing of the Certificate handshake message failed" \
7927            -c "Ciphersuite is"
7928
7929requires_openssl_tls1_3_with_compatible_ephemeral
7930requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7931                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7932run_test    "extKeyUsage cli 1.3: codeSign -> fail" \
7933            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7934             -cert data_files/server5.eku-cs.crt" \
7935            "$P_CLI debug_level=1" \
7936            1 \
7937            -c "bad certificate (usage extensions)" \
7938            -c "Processing of the Certificate handshake message failed" \
7939            -C "Ciphersuite is"
7940
7941# Tests for extendedKeyUsage, part 3: server-side checking of client cert
7942
7943requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7944run_test    "extKeyUsage cli-auth: clientAuth -> OK" \
7945            "$P_SRV debug_level=1 auth_mode=optional" \
7946            "$O_CLI -key data_files/server5.key \
7947             -cert data_files/server5.eku-cli.crt" \
7948            0 \
7949            -S "bad certificate (usage extensions)" \
7950            -S "Processing of the Certificate handshake message failed"
7951
7952requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7953run_test    "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
7954            "$P_SRV debug_level=1 auth_mode=optional" \
7955            "$O_CLI -key data_files/server5.key \
7956             -cert data_files/server5.eku-srv_cli.crt" \
7957            0 \
7958            -S "bad certificate (usage extensions)" \
7959            -S "Processing of the Certificate handshake message failed"
7960
7961requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7962run_test    "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
7963            "$P_SRV debug_level=1 auth_mode=optional" \
7964            "$O_CLI -key data_files/server5.key \
7965             -cert data_files/server5.eku-cs_any.crt" \
7966            0 \
7967            -S "bad certificate (usage extensions)" \
7968            -S "Processing of the Certificate handshake message failed"
7969
7970requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7971run_test    "extKeyUsage cli-auth: codeSign -> fail (soft)" \
7972            "$P_SRV debug_level=1 auth_mode=optional" \
7973            "$O_CLI -key data_files/server5.key \
7974             -cert data_files/server5.eku-cs.crt" \
7975            0 \
7976            -s "bad certificate (usage extensions)" \
7977            -S "Processing of the Certificate handshake message failed"
7978
7979requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7980run_test    "extKeyUsage cli-auth: codeSign -> fail (hard)" \
7981            "$P_SRV debug_level=1 auth_mode=required" \
7982            "$O_CLI -key data_files/server5.key \
7983             -cert data_files/server5.eku-cs.crt" \
7984            1 \
7985            -s "bad certificate (usage extensions)" \
7986            -s "Processing of the Certificate handshake message failed"
7987
7988requires_openssl_tls1_3_with_compatible_ephemeral
7989requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7990                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7991run_test    "extKeyUsage cli-auth 1.3: clientAuth -> OK" \
7992            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7993            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7994             -cert data_files/server5.eku-cli.crt" \
7995            0 \
7996            -S "bad certificate (usage extensions)" \
7997            -S "Processing of the Certificate handshake message failed"
7998
7999requires_openssl_tls1_3_with_compatible_ephemeral
8000requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
8001                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8002run_test    "extKeyUsage cli-auth 1.3: serverAuth,clientAuth -> OK" \
8003            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
8004            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
8005             -cert data_files/server5.eku-srv_cli.crt" \
8006            0 \
8007            -S "bad certificate (usage extensions)" \
8008            -S "Processing of the Certificate handshake message failed"
8009
8010requires_openssl_tls1_3_with_compatible_ephemeral
8011requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
8012                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8013run_test    "extKeyUsage cli-auth 1.3: codeSign,anyEKU -> OK" \
8014            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
8015            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
8016             -cert data_files/server5.eku-cs_any.crt" \
8017            0 \
8018            -S "bad certificate (usage extensions)" \
8019            -S "Processing of the Certificate handshake message failed"
8020
8021requires_openssl_tls1_3_with_compatible_ephemeral
8022requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
8023                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8024run_test    "extKeyUsage cli-auth 1.3: codeSign -> fail (soft)" \
8025            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
8026            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
8027             -cert data_files/server5.eku-cs.crt" \
8028            0 \
8029            -s "bad certificate (usage extensions)" \
8030            -S "Processing of the Certificate handshake message failed"
8031
8032# Tests for DHM parameters loading
8033
8034run_test    "DHM parameters: reference" \
8035            "$P_SRV" \
8036            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8037                    debug_level=3" \
8038            0 \
8039            -c "value of 'DHM: P ' (2048 bits)" \
8040            -c "value of 'DHM: G ' (2 bits)"
8041
8042run_test    "DHM parameters: other parameters" \
8043            "$P_SRV dhm_file=data_files/dhparams.pem" \
8044            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8045                    debug_level=3" \
8046            0 \
8047            -c "value of 'DHM: P ' (1024 bits)" \
8048            -c "value of 'DHM: G ' (2 bits)"
8049
8050# Tests for DHM client-side size checking
8051
8052run_test    "DHM size: server default, client default, OK" \
8053            "$P_SRV" \
8054            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8055                    debug_level=1" \
8056            0 \
8057            -C "DHM prime too short:"
8058
8059run_test    "DHM size: server default, client 2048, OK" \
8060            "$P_SRV" \
8061            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8062                    debug_level=1 dhmlen=2048" \
8063            0 \
8064            -C "DHM prime too short:"
8065
8066run_test    "DHM size: server 1024, client default, OK" \
8067            "$P_SRV dhm_file=data_files/dhparams.pem" \
8068            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8069                    debug_level=1" \
8070            0 \
8071            -C "DHM prime too short:"
8072
8073run_test    "DHM size: server 999, client 999, OK" \
8074            "$P_SRV dhm_file=data_files/dh.999.pem" \
8075            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8076                    debug_level=1 dhmlen=999" \
8077            0 \
8078            -C "DHM prime too short:"
8079
8080run_test    "DHM size: server 1000, client 1000, OK" \
8081            "$P_SRV dhm_file=data_files/dh.1000.pem" \
8082            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8083                    debug_level=1 dhmlen=1000" \
8084            0 \
8085            -C "DHM prime too short:"
8086
8087run_test    "DHM size: server 1000, client default, rejected" \
8088            "$P_SRV dhm_file=data_files/dh.1000.pem" \
8089            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8090                    debug_level=1" \
8091            1 \
8092            -c "DHM prime too short:"
8093
8094run_test    "DHM size: server 1000, client 1001, rejected" \
8095            "$P_SRV dhm_file=data_files/dh.1000.pem" \
8096            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8097                    debug_level=1 dhmlen=1001" \
8098            1 \
8099            -c "DHM prime too short:"
8100
8101run_test    "DHM size: server 999, client 1000, rejected" \
8102            "$P_SRV dhm_file=data_files/dh.999.pem" \
8103            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8104                    debug_level=1 dhmlen=1000" \
8105            1 \
8106            -c "DHM prime too short:"
8107
8108run_test    "DHM size: server 998, client 999, rejected" \
8109            "$P_SRV dhm_file=data_files/dh.998.pem" \
8110            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8111                    debug_level=1 dhmlen=999" \
8112            1 \
8113            -c "DHM prime too short:"
8114
8115run_test    "DHM size: server default, client 2049, rejected" \
8116            "$P_SRV" \
8117            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
8118                    debug_level=1 dhmlen=2049" \
8119            1 \
8120            -c "DHM prime too short:"
8121
8122# Tests for PSK callback
8123
8124run_test    "PSK callback: psk, no callback" \
8125            "$P_SRV psk=abc123 psk_identity=foo" \
8126            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8127            psk_identity=foo psk=abc123" \
8128            0 \
8129            -S "SSL - The handshake negotiation failed" \
8130            -S "SSL - Unknown identity received" \
8131            -S "SSL - Verification of the message MAC failed"
8132
8133requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8134run_test    "PSK callback: opaque psk on client, no callback" \
8135            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8136            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8137            psk_identity=foo psk=abc123 psk_opaque=1" \
8138            0 \
8139            -C "session hash for extended master secret"\
8140            -S "session hash for extended master secret"\
8141            -S "SSL - The handshake negotiation failed" \
8142            -S "SSL - Unknown identity received" \
8143            -S "SSL - Verification of the message MAC failed"
8144
8145requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8146run_test    "PSK callback: opaque psk on client, no callback, SHA-384" \
8147            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8148            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
8149            psk_identity=foo psk=abc123 psk_opaque=1" \
8150            0 \
8151            -C "session hash for extended master secret"\
8152            -S "session hash for extended master secret"\
8153            -S "SSL - The handshake negotiation failed" \
8154            -S "SSL - Unknown identity received" \
8155            -S "SSL - Verification of the message MAC failed"
8156
8157requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8158run_test    "PSK callback: opaque psk on client, no callback, EMS" \
8159            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8160            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8161            psk_identity=foo psk=abc123 psk_opaque=1" \
8162            0 \
8163            -c "session hash for extended master secret"\
8164            -s "session hash for extended master secret"\
8165            -S "SSL - The handshake negotiation failed" \
8166            -S "SSL - Unknown identity received" \
8167            -S "SSL - Verification of the message MAC failed"
8168
8169requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8170run_test    "PSK callback: opaque psk on client, no callback, SHA-384, EMS" \
8171            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8172            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
8173            psk_identity=foo psk=abc123 psk_opaque=1" \
8174            0 \
8175            -c "session hash for extended master secret"\
8176            -s "session hash for extended master secret"\
8177            -S "SSL - The handshake negotiation failed" \
8178            -S "SSL - Unknown identity received" \
8179            -S "SSL - Verification of the message MAC failed"
8180
8181requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8182run_test    "PSK callback: opaque rsa-psk on client, no callback" \
8183            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8184            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256 \
8185            psk_identity=foo psk=abc123 psk_opaque=1" \
8186            0 \
8187            -C "session hash for extended master secret"\
8188            -S "session hash for extended master secret"\
8189            -S "SSL - The handshake negotiation failed" \
8190            -S "SSL - Unknown identity received" \
8191            -S "SSL - Verification of the message MAC failed"
8192
8193requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8194run_test    "PSK callback: opaque rsa-psk on client, no callback, SHA-384" \
8195            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8196            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
8197            psk_identity=foo psk=abc123 psk_opaque=1" \
8198            0 \
8199            -C "session hash for extended master secret"\
8200            -S "session hash for extended master secret"\
8201            -S "SSL - The handshake negotiation failed" \
8202            -S "SSL - Unknown identity received" \
8203            -S "SSL - Verification of the message MAC failed"
8204
8205requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8206run_test    "PSK callback: opaque rsa-psk on client, no callback, EMS" \
8207            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8208            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
8209            psk_identity=foo psk=abc123 psk_opaque=1" \
8210            0 \
8211            -c "session hash for extended master secret"\
8212            -s "session hash for extended master secret"\
8213            -S "SSL - The handshake negotiation failed" \
8214            -S "SSL - Unknown identity received" \
8215            -S "SSL - Verification of the message MAC failed"
8216
8217requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8218run_test    "PSK callback: opaque rsa-psk on client, no callback, SHA-384, EMS" \
8219            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8220            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
8221            psk_identity=foo psk=abc123 psk_opaque=1" \
8222            0 \
8223            -c "session hash for extended master secret"\
8224            -s "session hash for extended master secret"\
8225            -S "SSL - The handshake negotiation failed" \
8226            -S "SSL - Unknown identity received" \
8227            -S "SSL - Verification of the message MAC failed"
8228
8229requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8230run_test    "PSK callback: opaque ecdhe-psk on client, no callback" \
8231            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8232            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 \
8233            psk_identity=foo psk=abc123 psk_opaque=1" \
8234            0 \
8235            -C "session hash for extended master secret"\
8236            -S "session hash for extended master secret"\
8237            -S "SSL - The handshake negotiation failed" \
8238            -S "SSL - Unknown identity received" \
8239            -S "SSL - Verification of the message MAC failed"
8240
8241requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8242run_test    "PSK callback: opaque ecdhe-psk on client, no callback, SHA-384" \
8243            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8244            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
8245            psk_identity=foo psk=abc123 psk_opaque=1" \
8246            0 \
8247            -C "session hash for extended master secret"\
8248            -S "session hash for extended master secret"\
8249            -S "SSL - The handshake negotiation failed" \
8250            -S "SSL - Unknown identity received" \
8251            -S "SSL - Verification of the message MAC failed"
8252
8253requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8254run_test    "PSK callback: opaque ecdhe-psk on client, no callback, EMS" \
8255            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8256            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
8257            psk_identity=foo psk=abc123 psk_opaque=1" \
8258            0 \
8259            -c "session hash for extended master secret"\
8260            -s "session hash for extended master secret"\
8261            -S "SSL - The handshake negotiation failed" \
8262            -S "SSL - Unknown identity received" \
8263            -S "SSL - Verification of the message MAC failed"
8264
8265requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8266run_test    "PSK callback: opaque ecdhe-psk on client, no callback, SHA-384, EMS" \
8267            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8268            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
8269            psk_identity=foo psk=abc123 psk_opaque=1" \
8270            0 \
8271            -c "session hash for extended master secret"\
8272            -s "session hash for extended master secret"\
8273            -S "SSL - The handshake negotiation failed" \
8274            -S "SSL - Unknown identity received" \
8275            -S "SSL - Verification of the message MAC failed"
8276
8277requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8278run_test    "PSK callback: opaque dhe-psk on client, no callback" \
8279            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8280            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA256 \
8281            psk_identity=foo psk=abc123 psk_opaque=1" \
8282            0 \
8283            -C "session hash for extended master secret"\
8284            -S "session hash for extended master secret"\
8285            -S "SSL - The handshake negotiation failed" \
8286            -S "SSL - Unknown identity received" \
8287            -S "SSL - Verification of the message MAC failed"
8288
8289requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8290run_test    "PSK callback: opaque dhe-psk on client, no callback, SHA-384" \
8291            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
8292            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
8293            psk_identity=foo psk=abc123 psk_opaque=1" \
8294            0 \
8295            -C "session hash for extended master secret"\
8296            -S "session hash for extended master secret"\
8297            -S "SSL - The handshake negotiation failed" \
8298            -S "SSL - Unknown identity received" \
8299            -S "SSL - Verification of the message MAC failed"
8300
8301requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8302run_test    "PSK callback: opaque dhe-psk on client, no callback, EMS" \
8303            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8304            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
8305            psk_identity=foo psk=abc123 psk_opaque=1" \
8306            0 \
8307            -c "session hash for extended master secret"\
8308            -s "session hash for extended master secret"\
8309            -S "SSL - The handshake negotiation failed" \
8310            -S "SSL - Unknown identity received" \
8311            -S "SSL - Verification of the message MAC failed"
8312
8313requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8314run_test    "PSK callback: opaque dhe-psk on client, no callback, SHA-384, EMS" \
8315            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
8316            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
8317            psk_identity=foo psk=abc123 psk_opaque=1" \
8318            0 \
8319            -c "session hash for extended master secret"\
8320            -s "session hash for extended master secret"\
8321            -S "SSL - The handshake negotiation failed" \
8322            -S "SSL - Unknown identity received" \
8323            -S "SSL - Verification of the message MAC failed"
8324
8325requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8326run_test    "PSK callback: raw psk on client, static opaque on server, no callback" \
8327            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA" \
8328            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8329            psk_identity=foo psk=abc123" \
8330            0 \
8331            -C "session hash for extended master secret"\
8332            -S "session hash for extended master secret"\
8333            -S "SSL - The handshake negotiation failed" \
8334            -S "SSL - Unknown identity received" \
8335            -S "SSL - Verification of the message MAC failed"
8336
8337requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8338run_test    "PSK callback: raw psk on client, static opaque on server, no callback, SHA-384" \
8339            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384" \
8340            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
8341            psk_identity=foo psk=abc123" \
8342            0 \
8343            -C "session hash for extended master secret"\
8344            -S "session hash for extended master secret"\
8345            -S "SSL - The handshake negotiation failed" \
8346            -S "SSL - Unknown identity received" \
8347            -S "SSL - Verification of the message MAC failed"
8348
8349requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8350run_test    "PSK callback: raw psk on client, static opaque on server, no callback, EMS" \
8351            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8352            force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8353            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8354            psk_identity=foo psk=abc123 extended_ms=1" \
8355            0 \
8356            -c "session hash for extended master secret"\
8357            -s "session hash for extended master secret"\
8358            -S "SSL - The handshake negotiation failed" \
8359            -S "SSL - Unknown identity received" \
8360            -S "SSL - Verification of the message MAC failed"
8361
8362requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8363run_test    "PSK callback: raw psk on client, static opaque on server, no callback, EMS, SHA384" \
8364            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8365            force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8366            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
8367            psk_identity=foo psk=abc123 extended_ms=1" \
8368            0 \
8369            -c "session hash for extended master secret"\
8370            -s "session hash for extended master secret"\
8371            -S "SSL - The handshake negotiation failed" \
8372            -S "SSL - Unknown identity received" \
8373            -S "SSL - Verification of the message MAC failed"
8374
8375requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8376run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback" \
8377            "$P_SRV extended_ms=0 debug_level=5 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA" \
8378            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
8379            psk_identity=foo psk=abc123" \
8380            0 \
8381            -C "session hash for extended master secret"\
8382            -S "session hash for extended master secret"\
8383            -S "SSL - The handshake negotiation failed" \
8384            -S "SSL - Unknown identity received" \
8385            -S "SSL - Verification of the message MAC failed"
8386
8387requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8388run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, SHA-384" \
8389            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384" \
8390            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
8391            psk_identity=foo psk=abc123" \
8392            0 \
8393            -C "session hash for extended master secret"\
8394            -S "session hash for extended master secret"\
8395            -S "SSL - The handshake negotiation failed" \
8396            -S "SSL - Unknown identity received" \
8397            -S "SSL - Verification of the message MAC failed"
8398
8399requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8400run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, EMS" \
8401            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8402            force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8403            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
8404            psk_identity=foo psk=abc123 extended_ms=1" \
8405            0 \
8406            -c "session hash for extended master secret"\
8407            -s "session hash for extended master secret"\
8408            -S "SSL - The handshake negotiation failed" \
8409            -S "SSL - Unknown identity received" \
8410            -S "SSL - Verification of the message MAC failed"
8411
8412requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8413run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, EMS, SHA384" \
8414            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8415            force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8416            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
8417            psk_identity=foo psk=abc123 extended_ms=1" \
8418            0 \
8419            -c "session hash for extended master secret"\
8420            -s "session hash for extended master secret"\
8421            -S "SSL - The handshake negotiation failed" \
8422            -S "SSL - Unknown identity received" \
8423            -S "SSL - Verification of the message MAC failed"
8424
8425requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8426run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback" \
8427            "$P_SRV extended_ms=0 debug_level=5 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA" \
8428            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
8429            psk_identity=foo psk=abc123" \
8430            0 \
8431            -C "session hash for extended master secret"\
8432            -S "session hash for extended master secret"\
8433            -S "SSL - The handshake negotiation failed" \
8434            -S "SSL - Unknown identity received" \
8435            -S "SSL - Verification of the message MAC failed"
8436
8437requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8438run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, SHA-384" \
8439            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384" \
8440            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
8441            psk_identity=foo psk=abc123" \
8442            0 \
8443            -C "session hash for extended master secret"\
8444            -S "session hash for extended master secret"\
8445            -S "SSL - The handshake negotiation failed" \
8446            -S "SSL - Unknown identity received" \
8447            -S "SSL - Verification of the message MAC failed"
8448
8449requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8450run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, EMS" \
8451            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8452            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8453            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
8454            psk_identity=foo psk=abc123 extended_ms=1" \
8455            0 \
8456            -c "session hash for extended master secret"\
8457            -s "session hash for extended master secret"\
8458            -S "SSL - The handshake negotiation failed" \
8459            -S "SSL - Unknown identity received" \
8460            -S "SSL - Verification of the message MAC failed"
8461
8462requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8463run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, EMS, SHA384" \
8464            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8465            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8466            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
8467            psk_identity=foo psk=abc123 extended_ms=1" \
8468            0 \
8469            -c "session hash for extended master secret"\
8470            -s "session hash for extended master secret"\
8471            -S "SSL - The handshake negotiation failed" \
8472            -S "SSL - Unknown identity received" \
8473            -S "SSL - Verification of the message MAC failed"
8474
8475requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8476run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback" \
8477            "$P_SRV extended_ms=0 debug_level=5 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA" \
8478            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
8479            psk_identity=foo psk=abc123" \
8480            0 \
8481            -C "session hash for extended master secret"\
8482            -S "session hash for extended master secret"\
8483            -S "SSL - The handshake negotiation failed" \
8484            -S "SSL - Unknown identity received" \
8485            -S "SSL - Verification of the message MAC failed"
8486
8487requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8488run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, SHA-384" \
8489            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384" \
8490            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
8491            psk_identity=foo psk=abc123" \
8492            0 \
8493            -C "session hash for extended master secret"\
8494            -S "session hash for extended master secret"\
8495            -S "SSL - The handshake negotiation failed" \
8496            -S "SSL - Unknown identity received" \
8497            -S "SSL - Verification of the message MAC failed"
8498
8499requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8500run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, EMS" \
8501            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8502            force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8503            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
8504            psk_identity=foo psk=abc123 extended_ms=1" \
8505            0 \
8506            -c "session hash for extended master secret"\
8507            -s "session hash for extended master secret"\
8508            -S "SSL - The handshake negotiation failed" \
8509            -S "SSL - Unknown identity received" \
8510            -S "SSL - Verification of the message MAC failed"
8511
8512requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8513run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, EMS, SHA384" \
8514            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
8515            force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8516            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
8517            psk_identity=foo psk=abc123 extended_ms=1" \
8518            0 \
8519            -c "session hash for extended master secret"\
8520            -s "session hash for extended master secret"\
8521            -S "SSL - The handshake negotiation failed" \
8522            -S "SSL - Unknown identity received" \
8523            -S "SSL - Verification of the message MAC failed"
8524
8525requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8526run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback" \
8527            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA" \
8528            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8529            psk_identity=def psk=beef" \
8530            0 \
8531            -C "session hash for extended master secret"\
8532            -S "session hash for extended master secret"\
8533            -S "SSL - The handshake negotiation failed" \
8534            -S "SSL - Unknown identity received" \
8535            -S "SSL - Verification of the message MAC failed"
8536
8537requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8538run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, SHA-384" \
8539            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384" \
8540            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
8541            psk_identity=def psk=beef" \
8542            0 \
8543            -C "session hash for extended master secret"\
8544            -S "session hash for extended master secret"\
8545            -S "SSL - The handshake negotiation failed" \
8546            -S "SSL - Unknown identity received" \
8547            -S "SSL - Verification of the message MAC failed"
8548
8549requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8550run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, EMS" \
8551            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8552            force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8553            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8554            psk_identity=abc psk=dead extended_ms=1" \
8555            0 \
8556            -c "session hash for extended master secret"\
8557            -s "session hash for extended master secret"\
8558            -S "SSL - The handshake negotiation failed" \
8559            -S "SSL - Unknown identity received" \
8560            -S "SSL - Verification of the message MAC failed"
8561
8562requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8563run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, EMS, SHA384" \
8564            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8565            force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8566            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
8567            psk_identity=abc psk=dead extended_ms=1" \
8568            0 \
8569            -c "session hash for extended master secret"\
8570            -s "session hash for extended master secret"\
8571            -S "SSL - The handshake negotiation failed" \
8572            -S "SSL - Unknown identity received" \
8573            -S "SSL - Verification of the message MAC failed"
8574
8575requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8576run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback" \
8577            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA" \
8578            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
8579            psk_identity=def psk=beef" \
8580            0 \
8581            -C "session hash for extended master secret"\
8582            -S "session hash for extended master secret"\
8583            -S "SSL - The handshake negotiation failed" \
8584            -S "SSL - Unknown identity received" \
8585            -S "SSL - Verification of the message MAC failed"
8586
8587requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8588run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, SHA-384" \
8589            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384" \
8590            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
8591            psk_identity=def psk=beef" \
8592            0 \
8593            -C "session hash for extended master secret"\
8594            -S "session hash for extended master secret"\
8595            -S "SSL - The handshake negotiation failed" \
8596            -S "SSL - Unknown identity received" \
8597            -S "SSL - Verification of the message MAC failed"
8598
8599requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8600run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, EMS" \
8601            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8602            force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8603            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
8604            psk_identity=abc psk=dead extended_ms=1" \
8605            0 \
8606            -c "session hash for extended master secret"\
8607            -s "session hash for extended master secret"\
8608            -S "SSL - The handshake negotiation failed" \
8609            -S "SSL - Unknown identity received" \
8610            -S "SSL - Verification of the message MAC failed"
8611
8612requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8613run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, EMS, SHA384" \
8614            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8615            force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8616            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
8617            psk_identity=abc psk=dead extended_ms=1" \
8618            0 \
8619            -c "session hash for extended master secret"\
8620            -s "session hash for extended master secret"\
8621            -S "SSL - The handshake negotiation failed" \
8622            -S "SSL - Unknown identity received" \
8623            -S "SSL - Verification of the message MAC failed"
8624
8625requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8626run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback" \
8627            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA" \
8628            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
8629            psk_identity=def psk=beef" \
8630            0 \
8631            -C "session hash for extended master secret"\
8632            -S "session hash for extended master secret"\
8633            -S "SSL - The handshake negotiation failed" \
8634            -S "SSL - Unknown identity received" \
8635            -S "SSL - Verification of the message MAC failed"
8636
8637requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8638run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, SHA-384" \
8639            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384" \
8640            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
8641            psk_identity=def psk=beef" \
8642            0 \
8643            -C "session hash for extended master secret"\
8644            -S "session hash for extended master secret"\
8645            -S "SSL - The handshake negotiation failed" \
8646            -S "SSL - Unknown identity received" \
8647            -S "SSL - Verification of the message MAC failed"
8648
8649requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8650run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, EMS" \
8651            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8652            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8653            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
8654            psk_identity=abc psk=dead extended_ms=1" \
8655            0 \
8656            -c "session hash for extended master secret"\
8657            -s "session hash for extended master secret"\
8658            -S "SSL - The handshake negotiation failed" \
8659            -S "SSL - Unknown identity received" \
8660            -S "SSL - Verification of the message MAC failed"
8661
8662requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8663run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, EMS, SHA384" \
8664            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8665            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8666            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
8667            psk_identity=abc psk=dead extended_ms=1" \
8668            0 \
8669            -c "session hash for extended master secret"\
8670            -s "session hash for extended master secret"\
8671            -S "SSL - The handshake negotiation failed" \
8672            -S "SSL - Unknown identity received" \
8673            -S "SSL - Verification of the message MAC failed"
8674
8675requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8676run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback" \
8677            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA" \
8678            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
8679            psk_identity=def psk=beef" \
8680            0 \
8681            -C "session hash for extended master secret"\
8682            -S "session hash for extended master secret"\
8683            -S "SSL - The handshake negotiation failed" \
8684            -S "SSL - Unknown identity received" \
8685            -S "SSL - Verification of the message MAC failed"
8686
8687requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8688run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, SHA-384" \
8689            "$P_SRV extended_ms=0 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384" \
8690            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
8691            psk_identity=def psk=beef" \
8692            0 \
8693            -C "session hash for extended master secret"\
8694            -S "session hash for extended master secret"\
8695            -S "SSL - The handshake negotiation failed" \
8696            -S "SSL - Unknown identity received" \
8697            -S "SSL - Verification of the message MAC failed"
8698
8699requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8700run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, EMS" \
8701            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8702            force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
8703            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
8704            psk_identity=abc psk=dead extended_ms=1" \
8705            0 \
8706            -c "session hash for extended master secret"\
8707            -s "session hash for extended master secret"\
8708            -S "SSL - The handshake negotiation failed" \
8709            -S "SSL - Unknown identity received" \
8710            -S "SSL - Verification of the message MAC failed"
8711
8712requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8713run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, EMS, SHA384" \
8714            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
8715            force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
8716            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
8717            psk_identity=abc psk=dead extended_ms=1" \
8718            0 \
8719            -c "session hash for extended master secret"\
8720            -s "session hash for extended master secret"\
8721            -S "SSL - The handshake negotiation failed" \
8722            -S "SSL - Unknown identity received" \
8723            -S "SSL - Verification of the message MAC failed"
8724
8725requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8726run_test    "PSK callback: raw psk on client, mismatching static raw PSK on server, opaque PSK from callback" \
8727            "$P_SRV extended_ms=0 psk_identity=foo psk=abc123 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA" \
8728            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8729            psk_identity=def psk=beef" \
8730            0 \
8731            -C "session hash for extended master secret"\
8732            -S "session hash for extended master secret"\
8733            -S "SSL - The handshake negotiation failed" \
8734            -S "SSL - Unknown identity received" \
8735            -S "SSL - Verification of the message MAC failed"
8736
8737requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8738run_test    "PSK callback: raw psk on client, mismatching static opaque PSK on server, opaque PSK from callback" \
8739            "$P_SRV extended_ms=0 psk_opaque=1 psk_identity=foo psk=abc123 debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA" \
8740            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8741            psk_identity=def psk=beef" \
8742            0 \
8743            -C "session hash for extended master secret"\
8744            -S "session hash for extended master secret"\
8745            -S "SSL - The handshake negotiation failed" \
8746            -S "SSL - Unknown identity received" \
8747            -S "SSL - Verification of the message MAC failed"
8748
8749requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8750run_test    "PSK callback: raw psk on client, mismatching static opaque PSK on server, raw PSK from callback" \
8751            "$P_SRV extended_ms=0 psk_opaque=1 psk_identity=foo psk=abc123 debug_level=3 psk_list=abc,dead,def,beef min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA" \
8752            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8753            psk_identity=def psk=beef" \
8754            0 \
8755            -C "session hash for extended master secret"\
8756            -S "session hash for extended master secret"\
8757            -S "SSL - The handshake negotiation failed" \
8758            -S "SSL - Unknown identity received" \
8759            -S "SSL - Verification of the message MAC failed"
8760
8761requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8762run_test    "PSK callback: raw psk on client, id-matching but wrong raw PSK on server, opaque PSK from callback" \
8763            "$P_SRV extended_ms=0 psk_opaque=1 psk_identity=def psk=abc123 debug_level=3 psk_list=abc,dead,def,beef min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA" \
8764            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8765            psk_identity=def psk=beef" \
8766            0 \
8767            -C "session hash for extended master secret"\
8768            -S "session hash for extended master secret"\
8769            -S "SSL - The handshake negotiation failed" \
8770            -S "SSL - Unknown identity received" \
8771            -S "SSL - Verification of the message MAC failed"
8772
8773requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8774run_test    "PSK callback: raw psk on client, matching opaque PSK on server, wrong opaque PSK from callback" \
8775            "$P_SRV extended_ms=0 psk_opaque=1 psk_identity=def psk=beef debug_level=3 psk_list=abc,dead,def,abc123 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA" \
8776            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8777            psk_identity=def psk=beef" \
8778            1 \
8779            -s "SSL - Verification of the message MAC failed"
8780
8781run_test    "PSK callback: no psk, no callback" \
8782            "$P_SRV" \
8783            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8784            psk_identity=foo psk=abc123" \
8785            1 \
8786            -s "SSL - The handshake negotiation failed" \
8787            -S "SSL - Unknown identity received" \
8788            -S "SSL - Verification of the message MAC failed"
8789
8790run_test    "PSK callback: callback overrides other settings" \
8791            "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
8792            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8793            psk_identity=foo psk=abc123" \
8794            1 \
8795            -S "SSL - The handshake negotiation failed" \
8796            -s "SSL - Unknown identity received" \
8797            -S "SSL - Verification of the message MAC failed"
8798
8799run_test    "PSK callback: first id matches" \
8800            "$P_SRV psk_list=abc,dead,def,beef" \
8801            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8802            psk_identity=abc psk=dead" \
8803            0 \
8804            -S "SSL - The handshake negotiation failed" \
8805            -S "SSL - Unknown identity received" \
8806            -S "SSL - Verification of the message MAC failed"
8807
8808run_test    "PSK callback: second id matches" \
8809            "$P_SRV psk_list=abc,dead,def,beef" \
8810            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8811            psk_identity=def psk=beef" \
8812            0 \
8813            -S "SSL - The handshake negotiation failed" \
8814            -S "SSL - Unknown identity received" \
8815            -S "SSL - Verification of the message MAC failed"
8816
8817run_test    "PSK callback: no match" \
8818            "$P_SRV psk_list=abc,dead,def,beef" \
8819            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8820            psk_identity=ghi psk=beef" \
8821            1 \
8822            -S "SSL - The handshake negotiation failed" \
8823            -s "SSL - Unknown identity received" \
8824            -S "SSL - Verification of the message MAC failed"
8825
8826run_test    "PSK callback: wrong key" \
8827            "$P_SRV psk_list=abc,dead,def,beef" \
8828            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8829            psk_identity=abc psk=beef" \
8830            1 \
8831            -S "SSL - The handshake negotiation failed" \
8832            -S "SSL - Unknown identity received" \
8833            -s "SSL - Verification of the message MAC failed"
8834
8835# Tests for EC J-PAKE
8836
8837requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8838requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8839run_test    "ECJPAKE: client not configured" \
8840            "$P_SRV debug_level=3" \
8841            "$P_CLI debug_level=3" \
8842            0 \
8843            -C "add ciphersuite: 0xc0ff" \
8844            -C "adding ecjpake_kkpp extension" \
8845            -S "found ecjpake kkpp extension" \
8846            -S "skip ecjpake kkpp extension" \
8847            -S "ciphersuite mismatch: ecjpake not configured" \
8848            -S "server hello, ecjpake kkpp extension" \
8849            -C "found ecjpake_kkpp extension" \
8850            -S "SSL - The handshake negotiation failed"
8851
8852requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8853run_test    "ECJPAKE: server not configured" \
8854            "$P_SRV debug_level=3" \
8855            "$P_CLI debug_level=3 ecjpake_pw=bla \
8856             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8857            1 \
8858            -c "add ciphersuite: c0ff" \
8859            -c "adding ecjpake_kkpp extension" \
8860            -s "found ecjpake kkpp extension" \
8861            -s "skip ecjpake kkpp extension" \
8862            -s "ciphersuite mismatch: ecjpake not configured" \
8863            -S "server hello, ecjpake kkpp extension" \
8864            -C "found ecjpake_kkpp extension" \
8865            -s "SSL - The handshake negotiation failed"
8866
8867# Note: if the name of this test is changed, then please adjust the corresponding
8868#       filtering label in "test_tls1_2_ecjpake_compatibility" (in "all.sh")
8869requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8870run_test    "ECJPAKE: working, TLS" \
8871            "$P_SRV debug_level=3 ecjpake_pw=bla" \
8872            "$P_CLI debug_level=3 ecjpake_pw=bla \
8873             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8874            0 \
8875            -c "add ciphersuite: c0ff" \
8876            -c "adding ecjpake_kkpp extension" \
8877            -C "re-using cached ecjpake parameters" \
8878            -s "found ecjpake kkpp extension" \
8879            -S "skip ecjpake kkpp extension" \
8880            -S "ciphersuite mismatch: ecjpake not configured" \
8881            -s "server hello, ecjpake kkpp extension" \
8882            -c "found ecjpake_kkpp extension" \
8883            -S "SSL - The handshake negotiation failed" \
8884            -S "SSL - Verification of the message MAC failed"
8885
8886requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8887requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8888run_test    "ECJPAKE: opaque password client+server, working, TLS" \
8889            "$P_SRV debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1" \
8890            "$P_CLI debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1\
8891             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8892            0 \
8893            -c "add ciphersuite: c0ff" \
8894            -c "adding ecjpake_kkpp extension" \
8895            -c "using opaque password" \
8896            -s "using opaque password" \
8897            -C "re-using cached ecjpake parameters" \
8898            -s "found ecjpake kkpp extension" \
8899            -S "skip ecjpake kkpp extension" \
8900            -S "ciphersuite mismatch: ecjpake not configured" \
8901            -s "server hello, ecjpake kkpp extension" \
8902            -c "found ecjpake_kkpp extension" \
8903            -S "SSL - The handshake negotiation failed" \
8904            -S "SSL - Verification of the message MAC failed"
8905
8906# Note: if the name of this test is changed, then please adjust the corresponding
8907#       filtering label in "test_tls1_2_ecjpake_compatibility" (in "all.sh")
8908requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8909requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8910run_test    "ECJPAKE: opaque password client only, working, TLS" \
8911            "$P_SRV debug_level=3 ecjpake_pw=bla" \
8912            "$P_CLI debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1\
8913             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8914            0 \
8915            -c "add ciphersuite: c0ff" \
8916            -c "adding ecjpake_kkpp extension" \
8917            -c "using opaque password" \
8918            -S "using opaque password" \
8919            -C "re-using cached ecjpake parameters" \
8920            -s "found ecjpake kkpp extension" \
8921            -S "skip ecjpake kkpp extension" \
8922            -S "ciphersuite mismatch: ecjpake not configured" \
8923            -s "server hello, ecjpake kkpp extension" \
8924            -c "found ecjpake_kkpp extension" \
8925            -S "SSL - The handshake negotiation failed" \
8926            -S "SSL - Verification of the message MAC failed"
8927
8928# Note: if the name of this test is changed, then please adjust the corresponding
8929#       filtering label in "test_tls1_2_ecjpake_compatibility" (in "all.sh")
8930requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8931requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8932run_test    "ECJPAKE: opaque password server only, working, TLS" \
8933            "$P_SRV debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1" \
8934            "$P_CLI debug_level=3 ecjpake_pw=bla\
8935             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8936            0 \
8937            -c "add ciphersuite: c0ff" \
8938            -c "adding ecjpake_kkpp extension" \
8939            -C "using opaque password" \
8940            -s "using opaque password" \
8941            -C "re-using cached ecjpake parameters" \
8942            -s "found ecjpake kkpp extension" \
8943            -S "skip ecjpake kkpp extension" \
8944            -S "ciphersuite mismatch: ecjpake not configured" \
8945            -s "server hello, ecjpake kkpp extension" \
8946            -c "found ecjpake_kkpp extension" \
8947            -S "SSL - The handshake negotiation failed" \
8948            -S "SSL - Verification of the message MAC failed"
8949
8950server_needs_more_time 1
8951requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8952run_test    "ECJPAKE: password mismatch, TLS" \
8953            "$P_SRV debug_level=3 ecjpake_pw=bla" \
8954            "$P_CLI debug_level=3 ecjpake_pw=bad \
8955             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8956            1 \
8957            -C "re-using cached ecjpake parameters" \
8958            -s "SSL - Verification of the message MAC failed"
8959
8960server_needs_more_time 1
8961requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8962requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8963run_test    "ECJPAKE_OPAQUE_PW: opaque password mismatch, TLS" \
8964            "$P_SRV debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1" \
8965            "$P_CLI debug_level=3 ecjpake_pw=bad ecjpake_pw_opaque=1 \
8966             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8967            1 \
8968            -c "using opaque password" \
8969            -s "using opaque password" \
8970            -C "re-using cached ecjpake parameters" \
8971            -s "SSL - Verification of the message MAC failed"
8972
8973requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8974run_test    "ECJPAKE: working, DTLS" \
8975            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
8976            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
8977             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8978            0 \
8979            -c "re-using cached ecjpake parameters" \
8980            -S "SSL - Verification of the message MAC failed"
8981
8982requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8983run_test    "ECJPAKE: working, DTLS, no cookie" \
8984            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla cookies=0" \
8985            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
8986             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8987            0 \
8988            -C "re-using cached ecjpake parameters" \
8989            -S "SSL - Verification of the message MAC failed"
8990
8991server_needs_more_time 1
8992requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8993run_test    "ECJPAKE: password mismatch, DTLS" \
8994            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
8995            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bad \
8996             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8997            1 \
8998            -c "re-using cached ecjpake parameters" \
8999            -s "SSL - Verification of the message MAC failed"
9000
9001# for tests with configs/config-thread.h
9002requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
9003run_test    "ECJPAKE: working, DTLS, nolog" \
9004            "$P_SRV dtls=1 ecjpake_pw=bla" \
9005            "$P_CLI dtls=1 ecjpake_pw=bla \
9006             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
9007            0
9008
9009# Test for ClientHello without extensions
9010
9011requires_gnutls
9012run_test    "ClientHello without extensions" \
9013            "$P_SRV force_version=tls12 debug_level=3" \
9014            "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION localhost" \
9015            0 \
9016            -s "dumping 'client hello extensions' (0 bytes)"
9017
9018# Tests for mbedtls_ssl_get_bytes_avail()
9019
9020# The server first reads buffer_size-1 bytes, then reads the remainder.
9021requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9022run_test    "mbedtls_ssl_get_bytes_avail: no extra data" \
9023            "$P_SRV buffer_size=100" \
9024            "$P_CLI request_size=100" \
9025            0 \
9026            -s "Read from client: 100 bytes read$"
9027
9028requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9029run_test    "mbedtls_ssl_get_bytes_avail: extra data (+1)" \
9030            "$P_SRV buffer_size=100" \
9031            "$P_CLI request_size=101" \
9032            0 \
9033            -s "Read from client: 101 bytes read (100 + 1)"
9034
9035requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9036requires_max_content_len 200
9037run_test    "mbedtls_ssl_get_bytes_avail: extra data (*2)" \
9038            "$P_SRV buffer_size=100" \
9039            "$P_CLI request_size=200" \
9040            0 \
9041            -s "Read from client: 200 bytes read (100 + 100)"
9042
9043requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9044run_test    "mbedtls_ssl_get_bytes_avail: extra data (max)" \
9045            "$P_SRV buffer_size=100 force_version=tls12" \
9046            "$P_CLI request_size=$MAX_CONTENT_LEN" \
9047            0 \
9048            -s "Read from client: $MAX_CONTENT_LEN bytes read (100 + $((MAX_CONTENT_LEN - 100)))"
9049
9050# Tests for small client packets
9051
9052run_test    "Small client packet TLS 1.2 BlockCipher" \
9053            "$P_SRV force_version=tls12" \
9054            "$P_CLI request_size=1 \
9055             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9056            0 \
9057            -s "Read from client: 1 bytes read"
9058
9059run_test    "Small client packet TLS 1.2 BlockCipher, without EtM" \
9060            "$P_SRV force_version=tls12" \
9061            "$P_CLI request_size=1 \
9062             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
9063            0 \
9064            -s "Read from client: 1 bytes read"
9065
9066run_test    "Small client packet TLS 1.2 BlockCipher larger MAC" \
9067            "$P_SRV force_version=tls12" \
9068            "$P_CLI request_size=1 \
9069             force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
9070            0 \
9071            -s "Read from client: 1 bytes read"
9072
9073run_test    "Small client packet TLS 1.2 AEAD" \
9074            "$P_SRV force_version=tls12" \
9075            "$P_CLI request_size=1 \
9076             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
9077            0 \
9078            -s "Read from client: 1 bytes read"
9079
9080run_test    "Small client packet TLS 1.2 AEAD shorter tag" \
9081            "$P_SRV force_version=tls12" \
9082            "$P_CLI request_size=1 \
9083             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
9084            0 \
9085            -s "Read from client: 1 bytes read"
9086
9087requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9088run_test    "Small client packet TLS 1.3 AEAD" \
9089            "$P_SRV" \
9090            "$P_CLI request_size=1 \
9091             force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
9092            0 \
9093            -s "Read from client: 1 bytes read"
9094
9095requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9096run_test    "Small client packet TLS 1.3 AEAD shorter tag" \
9097            "$P_SRV" \
9098            "$P_CLI request_size=1 \
9099             force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
9100            0 \
9101            -s "Read from client: 1 bytes read"
9102
9103# Tests for small client packets in DTLS
9104
9105requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9106run_test    "Small client packet DTLS 1.2" \
9107            "$P_SRV dtls=1 force_version=dtls12" \
9108            "$P_CLI dtls=1 request_size=1 \
9109             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9110            0 \
9111            -s "Read from client: 1 bytes read"
9112
9113requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9114run_test    "Small client packet DTLS 1.2, without EtM" \
9115            "$P_SRV dtls=1 force_version=dtls12 etm=0" \
9116            "$P_CLI dtls=1 request_size=1 \
9117             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9118            0 \
9119            -s "Read from client: 1 bytes read"
9120
9121# Tests for small server packets
9122
9123run_test    "Small server packet TLS 1.2 BlockCipher" \
9124            "$P_SRV response_size=1 force_version=tls12" \
9125            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9126            0 \
9127            -c "Read from server: 1 bytes read"
9128
9129run_test    "Small server packet TLS 1.2 BlockCipher, without EtM" \
9130            "$P_SRV response_size=1 force_version=tls12" \
9131            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
9132            0 \
9133            -c "Read from server: 1 bytes read"
9134
9135run_test    "Small server packet TLS 1.2 BlockCipher larger MAC" \
9136            "$P_SRV response_size=1 force_version=tls12" \
9137            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
9138            0 \
9139            -c "Read from server: 1 bytes read"
9140
9141run_test    "Small server packet TLS 1.2 AEAD" \
9142            "$P_SRV response_size=1 force_version=tls12" \
9143            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
9144            0 \
9145            -c "Read from server: 1 bytes read"
9146
9147run_test    "Small server packet TLS 1.2 AEAD shorter tag" \
9148            "$P_SRV response_size=1 force_version=tls12" \
9149            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
9150            0 \
9151            -c "Read from server: 1 bytes read"
9152
9153requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9154run_test    "Small server packet TLS 1.3 AEAD" \
9155            "$P_SRV response_size=1" \
9156            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
9157            0 \
9158            -c "Read from server: 1 bytes read"
9159
9160requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9161run_test    "Small server packet TLS 1.3 AEAD shorter tag" \
9162            "$P_SRV response_size=1" \
9163            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
9164            0 \
9165            -c "Read from server: 1 bytes read"
9166
9167# Tests for small server packets in DTLS
9168
9169requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9170run_test    "Small server packet DTLS 1.2" \
9171            "$P_SRV dtls=1 response_size=1 force_version=dtls12" \
9172            "$P_CLI dtls=1 \
9173             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9174            0 \
9175            -c "Read from server: 1 bytes read"
9176
9177requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9178run_test    "Small server packet DTLS 1.2, without EtM" \
9179            "$P_SRV dtls=1 response_size=1 force_version=dtls12 etm=0" \
9180            "$P_CLI dtls=1 \
9181             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9182            0 \
9183            -c "Read from server: 1 bytes read"
9184
9185# Test for large client packets
9186
9187# How many fragments do we expect to write $1 bytes?
9188fragments_for_write() {
9189    echo "$(( ( $1 + $MAX_OUT_LEN - 1 ) / $MAX_OUT_LEN ))"
9190}
9191
9192run_test    "Large client packet TLS 1.2 BlockCipher" \
9193            "$P_SRV force_version=tls12" \
9194            "$P_CLI request_size=16384 \
9195             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9196            0 \
9197            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
9198            -s "Read from client: $MAX_CONTENT_LEN bytes read"
9199
9200run_test    "Large client packet TLS 1.2 BlockCipher, without EtM" \
9201            "$P_SRV force_version=tls12" \
9202            "$P_CLI request_size=16384 etm=0 \
9203             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9204            0 \
9205            -s "Read from client: $MAX_CONTENT_LEN bytes read"
9206
9207run_test    "Large client packet TLS 1.2 BlockCipher larger MAC" \
9208            "$P_SRV force_version=tls12" \
9209            "$P_CLI request_size=16384 \
9210             force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
9211            0 \
9212            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
9213            -s "Read from client: $MAX_CONTENT_LEN bytes read"
9214
9215run_test    "Large client packet TLS 1.2 AEAD" \
9216            "$P_SRV force_version=tls12" \
9217            "$P_CLI request_size=16384 \
9218             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
9219            0 \
9220            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
9221            -s "Read from client: $MAX_CONTENT_LEN bytes read"
9222
9223run_test    "Large client packet TLS 1.2 AEAD shorter tag" \
9224            "$P_SRV force_version=tls12" \
9225            "$P_CLI request_size=16384 \
9226             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
9227            0 \
9228            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
9229            -s "Read from client: $MAX_CONTENT_LEN bytes read"
9230
9231requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9232run_test    "Large client packet TLS 1.3 AEAD" \
9233            "$P_SRV" \
9234            "$P_CLI request_size=16383 \
9235             force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
9236            0 \
9237            -c "16383 bytes written in $(fragments_for_write 16383) fragments" \
9238            -s "Read from client: 16383 bytes read"
9239
9240requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9241run_test    "Large client packet TLS 1.3 AEAD shorter tag" \
9242            "$P_SRV" \
9243            "$P_CLI request_size=16383 \
9244             force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
9245            0 \
9246            -c "16383 bytes written in $(fragments_for_write 16383) fragments" \
9247            -s "Read from client: 16383 bytes read"
9248
9249# The tests below fail when the server's OUT_CONTENT_LEN is less than 16384.
9250run_test    "Large server packet TLS 1.2 BlockCipher" \
9251            "$P_SRV response_size=16384 force_version=tls12" \
9252            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9253            0 \
9254            -c "Read from server: 16384 bytes read"
9255
9256run_test    "Large server packet TLS 1.2 BlockCipher, without EtM" \
9257            "$P_SRV response_size=16384 force_version=tls12" \
9258            "$P_CLI etm=0 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
9259            0 \
9260            -s "16384 bytes written in 1 fragments" \
9261            -c "Read from server: 16384 bytes read"
9262
9263run_test    "Large server packet TLS 1.2 BlockCipher larger MAC" \
9264            "$P_SRV response_size=16384 force_version=tls12" \
9265            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
9266            0 \
9267            -c "Read from server: 16384 bytes read"
9268
9269run_test    "Large server packet TLS 1.2 BlockCipher, without EtM, truncated MAC" \
9270            "$P_SRV response_size=16384 trunc_hmac=1 force_version=tls12" \
9271            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
9272            0 \
9273            -s "16384 bytes written in 1 fragments" \
9274            -c "Read from server: 16384 bytes read"
9275
9276run_test    "Large server packet TLS 1.2 AEAD" \
9277            "$P_SRV response_size=16384 force_version=tls12" \
9278            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
9279            0 \
9280            -c "Read from server: 16384 bytes read"
9281
9282run_test    "Large server packet TLS 1.2 AEAD shorter tag" \
9283            "$P_SRV response_size=16384 force_version=tls12" \
9284            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
9285            0 \
9286            -c "Read from server: 16384 bytes read"
9287
9288requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9289run_test    "Large server packet TLS 1.3 AEAD" \
9290            "$P_SRV response_size=16383" \
9291            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
9292            0 \
9293            -c "Read from server: 16383 bytes read"
9294
9295requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
9296run_test    "Large server packet TLS 1.3 AEAD shorter tag" \
9297            "$P_SRV response_size=16383" \
9298            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
9299            0 \
9300            -c "Read from server: 16383 bytes read"
9301
9302# Tests for restartable ECC
9303
9304# Force the use of a curve that supports restartable ECC (secp256r1).
9305
9306requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9307requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9308run_test    "EC restart: TLS, default" \
9309            "$P_SRV groups=secp256r1 auth_mode=required" \
9310            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9311             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9312             debug_level=1" \
9313            0 \
9314            -C "x509_verify_cert.*4b00" \
9315            -C "mbedtls_pk_verify.*4b00" \
9316            -C "mbedtls_ecdh_make_public.*4b00" \
9317            -C "mbedtls_pk_sign.*4b00"
9318
9319requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9320requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9321run_test    "EC restart: TLS, max_ops=0" \
9322            "$P_SRV groups=secp256r1 auth_mode=required" \
9323            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9324             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9325             debug_level=1 ec_max_ops=0" \
9326            0 \
9327            -C "x509_verify_cert.*4b00" \
9328            -C "mbedtls_pk_verify.*4b00" \
9329            -C "mbedtls_ecdh_make_public.*4b00" \
9330            -C "mbedtls_pk_sign.*4b00"
9331
9332requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9333requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9334run_test    "EC restart: TLS, max_ops=65535" \
9335            "$P_SRV groups=secp256r1 auth_mode=required" \
9336            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9337             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9338             debug_level=1 ec_max_ops=65535" \
9339            0 \
9340            -C "x509_verify_cert.*4b00" \
9341            -C "mbedtls_pk_verify.*4b00" \
9342            -C "mbedtls_ecdh_make_public.*4b00" \
9343            -C "mbedtls_pk_sign.*4b00"
9344
9345# With USE_PSA disabled we expect full restartable behaviour.
9346requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9347requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9348requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
9349run_test    "EC restart: TLS, max_ops=1000 (no USE_PSA)" \
9350            "$P_SRV groups=secp256r1 auth_mode=required" \
9351            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9352             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9353             debug_level=1 ec_max_ops=1000" \
9354            0 \
9355            -c "x509_verify_cert.*4b00" \
9356            -c "mbedtls_pk_verify.*4b00" \
9357            -c "mbedtls_ecdh_make_public.*4b00" \
9358            -c "mbedtls_pk_sign.*4b00"
9359
9360# With USE_PSA enabled we expect only partial restartable behaviour:
9361# everything except ECDH (where TLS calls PSA directly).
9362requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9363requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9364requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
9365run_test    "EC restart: TLS, max_ops=1000 (USE_PSA)" \
9366            "$P_SRV groups=secp256r1 auth_mode=required" \
9367            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9368             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9369             debug_level=1 ec_max_ops=1000" \
9370            0 \
9371            -c "x509_verify_cert.*4b00" \
9372            -c "mbedtls_pk_verify.*4b00" \
9373            -C "mbedtls_ecdh_make_public.*4b00" \
9374            -c "mbedtls_pk_sign.*4b00"
9375
9376# This works the same with & without USE_PSA as we never get to ECDH:
9377# we abort as soon as we determined the cert is bad.
9378requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9379requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9380run_test    "EC restart: TLS, max_ops=1000, badsign" \
9381            "$P_SRV groups=secp256r1 auth_mode=required \
9382             crt_file=data_files/server5-badsign.crt \
9383             key_file=data_files/server5.key" \
9384            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9385             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9386             debug_level=1 ec_max_ops=1000" \
9387            1 \
9388            -c "x509_verify_cert.*4b00" \
9389            -C "mbedtls_pk_verify.*4b00" \
9390            -C "mbedtls_ecdh_make_public.*4b00" \
9391            -C "mbedtls_pk_sign.*4b00" \
9392            -c "! The certificate is not correctly signed by the trusted CA" \
9393            -c "! mbedtls_ssl_handshake returned" \
9394            -c "X509 - Certificate verification failed"
9395
9396# With USE_PSA disabled we expect full restartable behaviour.
9397requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9398requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9399requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
9400run_test    "EC restart: TLS, max_ops=1000, auth_mode=optional badsign (no USE_PSA)" \
9401            "$P_SRV groups=secp256r1 auth_mode=required \
9402             crt_file=data_files/server5-badsign.crt \
9403             key_file=data_files/server5.key" \
9404            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9405             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9406             debug_level=1 ec_max_ops=1000 auth_mode=optional" \
9407            0 \
9408            -c "x509_verify_cert.*4b00" \
9409            -c "mbedtls_pk_verify.*4b00" \
9410            -c "mbedtls_ecdh_make_public.*4b00" \
9411            -c "mbedtls_pk_sign.*4b00" \
9412            -c "! The certificate is not correctly signed by the trusted CA" \
9413            -C "! mbedtls_ssl_handshake returned" \
9414            -C "X509 - Certificate verification failed"
9415
9416# With USE_PSA enabled we expect only partial restartable behaviour:
9417# everything except ECDH (where TLS calls PSA directly).
9418requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9419requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9420requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
9421run_test    "EC restart: TLS, max_ops=1000, auth_mode=optional badsign (USE_PSA)" \
9422            "$P_SRV groups=secp256r1 auth_mode=required \
9423             crt_file=data_files/server5-badsign.crt \
9424             key_file=data_files/server5.key" \
9425            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9426             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9427             debug_level=1 ec_max_ops=1000 auth_mode=optional" \
9428            0 \
9429            -c "x509_verify_cert.*4b00" \
9430            -c "mbedtls_pk_verify.*4b00" \
9431            -C "mbedtls_ecdh_make_public.*4b00" \
9432            -c "mbedtls_pk_sign.*4b00" \
9433            -c "! The certificate is not correctly signed by the trusted CA" \
9434            -C "! mbedtls_ssl_handshake returned" \
9435            -C "X509 - Certificate verification failed"
9436
9437# With USE_PSA disabled we expect full restartable behaviour.
9438requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9439requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9440requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
9441run_test    "EC restart: TLS, max_ops=1000, auth_mode=none badsign (no USE_PSA)" \
9442            "$P_SRV groups=secp256r1 auth_mode=required \
9443             crt_file=data_files/server5-badsign.crt \
9444             key_file=data_files/server5.key" \
9445            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9446             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9447             debug_level=1 ec_max_ops=1000 auth_mode=none" \
9448            0 \
9449            -C "x509_verify_cert.*4b00" \
9450            -c "mbedtls_pk_verify.*4b00" \
9451            -c "mbedtls_ecdh_make_public.*4b00" \
9452            -c "mbedtls_pk_sign.*4b00" \
9453            -C "! The certificate is not correctly signed by the trusted CA" \
9454            -C "! mbedtls_ssl_handshake returned" \
9455            -C "X509 - Certificate verification failed"
9456
9457# With USE_PSA enabled we expect only partial restartable behaviour:
9458# everything except ECDH (where TLS calls PSA directly).
9459requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9460requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9461requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
9462run_test    "EC restart: TLS, max_ops=1000, auth_mode=none badsign (USE_PSA)" \
9463            "$P_SRV groups=secp256r1 auth_mode=required \
9464             crt_file=data_files/server5-badsign.crt \
9465             key_file=data_files/server5.key" \
9466            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9467             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9468             debug_level=1 ec_max_ops=1000 auth_mode=none" \
9469            0 \
9470            -C "x509_verify_cert.*4b00" \
9471            -c "mbedtls_pk_verify.*4b00" \
9472            -C "mbedtls_ecdh_make_public.*4b00" \
9473            -c "mbedtls_pk_sign.*4b00" \
9474            -C "! The certificate is not correctly signed by the trusted CA" \
9475            -C "! mbedtls_ssl_handshake returned" \
9476            -C "X509 - Certificate verification failed"
9477
9478# With USE_PSA disabled we expect full restartable behaviour.
9479requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9480requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9481requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
9482run_test    "EC restart: DTLS, max_ops=1000 (no USE_PSA)" \
9483            "$P_SRV groups=secp256r1 auth_mode=required dtls=1" \
9484            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9485             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9486             dtls=1 debug_level=1 ec_max_ops=1000" \
9487            0 \
9488            -c "x509_verify_cert.*4b00" \
9489            -c "mbedtls_pk_verify.*4b00" \
9490            -c "mbedtls_ecdh_make_public.*4b00" \
9491            -c "mbedtls_pk_sign.*4b00"
9492
9493# With USE_PSA enabled we expect only partial restartable behaviour:
9494# everything except ECDH (where TLS calls PSA directly).
9495requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9496requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9497requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
9498run_test    "EC restart: DTLS, max_ops=1000 (USE_PSA)" \
9499            "$P_SRV groups=secp256r1 auth_mode=required dtls=1" \
9500            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9501             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9502             dtls=1 debug_level=1 ec_max_ops=1000" \
9503            0 \
9504            -c "x509_verify_cert.*4b00" \
9505            -c "mbedtls_pk_verify.*4b00" \
9506            -C "mbedtls_ecdh_make_public.*4b00" \
9507            -c "mbedtls_pk_sign.*4b00"
9508
9509# With USE_PSA disabled we expect full restartable behaviour.
9510requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9511requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9512requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
9513run_test    "EC restart: TLS, max_ops=1000 no client auth (no USE_PSA)" \
9514            "$P_SRV groups=secp256r1" \
9515            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9516             debug_level=1 ec_max_ops=1000" \
9517            0 \
9518            -c "x509_verify_cert.*4b00" \
9519            -c "mbedtls_pk_verify.*4b00" \
9520            -c "mbedtls_ecdh_make_public.*4b00" \
9521            -C "mbedtls_pk_sign.*4b00"
9522
9523
9524# With USE_PSA enabled we expect only partial restartable behaviour:
9525# everything except ECDH (where TLS calls PSA directly).
9526requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9527requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9528requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
9529run_test    "EC restart: TLS, max_ops=1000 no client auth (USE_PSA)" \
9530            "$P_SRV groups=secp256r1" \
9531            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9532             debug_level=1 ec_max_ops=1000" \
9533            0 \
9534            -c "x509_verify_cert.*4b00" \
9535            -c "mbedtls_pk_verify.*4b00" \
9536            -C "mbedtls_ecdh_make_public.*4b00" \
9537            -C "mbedtls_pk_sign.*4b00"
9538
9539# Restartable is only for ECDHE-ECDSA, with another ciphersuite we expect no
9540# restartable behaviour at all (not even client auth).
9541# This is the same as "EC restart: TLS, max_ops=1000" except with ECDHE-RSA,
9542# and all 4 assertions negated.
9543requires_config_enabled MBEDTLS_ECP_RESTARTABLE
9544requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
9545run_test    "EC restart: TLS, max_ops=1000, ECDHE-RSA" \
9546            "$P_SRV groups=secp256r1 auth_mode=required" \
9547            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 \
9548             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
9549             debug_level=1 ec_max_ops=1000" \
9550            0 \
9551            -C "x509_verify_cert.*4b00" \
9552            -C "mbedtls_pk_verify.*4b00" \
9553            -C "mbedtls_ecdh_make_public.*4b00" \
9554            -C "mbedtls_pk_sign.*4b00"
9555
9556# Tests of asynchronous private key support in SSL
9557
9558requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9559run_test    "SSL async private: sign, delay=0" \
9560            "$P_SRV force_version=tls12 \
9561             async_operations=s async_private_delay1=0 async_private_delay2=0" \
9562            "$P_CLI" \
9563            0 \
9564            -s "Async sign callback: using key slot " \
9565            -s "Async resume (slot [0-9]): sign done, status=0"
9566
9567requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9568run_test    "SSL async private: sign, delay=1" \
9569            "$P_SRV force_version=tls12 \
9570             async_operations=s async_private_delay1=1 async_private_delay2=1" \
9571            "$P_CLI" \
9572            0 \
9573            -s "Async sign callback: using key slot " \
9574            -s "Async resume (slot [0-9]): call 0 more times." \
9575            -s "Async resume (slot [0-9]): sign done, status=0"
9576
9577requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9578run_test    "SSL async private: sign, delay=2" \
9579            "$P_SRV force_version=tls12 \
9580             async_operations=s async_private_delay1=2 async_private_delay2=2" \
9581            "$P_CLI" \
9582            0 \
9583            -s "Async sign callback: using key slot " \
9584            -U "Async sign callback: using key slot " \
9585            -s "Async resume (slot [0-9]): call 1 more times." \
9586            -s "Async resume (slot [0-9]): call 0 more times." \
9587            -s "Async resume (slot [0-9]): sign done, status=0"
9588
9589requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9590requires_config_disabled MBEDTLS_X509_REMOVE_INFO
9591run_test    "SSL async private: sign, SNI" \
9592            "$P_SRV force_version=tls12 debug_level=3 \
9593             async_operations=s async_private_delay1=0 async_private_delay2=0 \
9594             crt_file=data_files/server5.crt key_file=data_files/server5.key \
9595             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
9596            "$P_CLI server_name=polarssl.example" \
9597            0 \
9598            -s "Async sign callback: using key slot " \
9599            -s "Async resume (slot [0-9]): sign done, status=0" \
9600            -s "parse ServerName extension" \
9601            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
9602            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
9603
9604requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9605run_test    "SSL async private: decrypt, delay=0" \
9606            "$P_SRV \
9607             async_operations=d async_private_delay1=0 async_private_delay2=0" \
9608            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9609            0 \
9610            -s "Async decrypt callback: using key slot " \
9611            -s "Async resume (slot [0-9]): decrypt done, status=0"
9612
9613requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9614run_test    "SSL async private: decrypt, delay=1" \
9615            "$P_SRV \
9616             async_operations=d async_private_delay1=1 async_private_delay2=1" \
9617            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9618            0 \
9619            -s "Async decrypt callback: using key slot " \
9620            -s "Async resume (slot [0-9]): call 0 more times." \
9621            -s "Async resume (slot [0-9]): decrypt done, status=0"
9622
9623requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9624run_test    "SSL async private: decrypt RSA-PSK, delay=0" \
9625            "$P_SRV psk=abc123 \
9626             async_operations=d async_private_delay1=0 async_private_delay2=0" \
9627            "$P_CLI psk=abc123 \
9628             force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
9629            0 \
9630            -s "Async decrypt callback: using key slot " \
9631            -s "Async resume (slot [0-9]): decrypt done, status=0"
9632
9633requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9634run_test    "SSL async private: decrypt RSA-PSK, delay=1" \
9635            "$P_SRV psk=abc123 \
9636             async_operations=d async_private_delay1=1 async_private_delay2=1" \
9637            "$P_CLI psk=abc123 \
9638             force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
9639            0 \
9640            -s "Async decrypt callback: using key slot " \
9641            -s "Async resume (slot [0-9]): call 0 more times." \
9642            -s "Async resume (slot [0-9]): decrypt done, status=0"
9643
9644requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9645run_test    "SSL async private: sign callback not present" \
9646            "$P_SRV \
9647             async_operations=d async_private_delay1=1 async_private_delay2=1" \
9648            "$P_CLI force_version=tls12; [ \$? -eq 1 ] &&
9649             $P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9650            0 \
9651            -S "Async sign callback" \
9652            -s "! mbedtls_ssl_handshake returned" \
9653            -s "The own private key or pre-shared key is not set, but needed" \
9654            -s "Async resume (slot [0-9]): decrypt done, status=0" \
9655            -s "Successful connection"
9656
9657requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9658run_test    "SSL async private: decrypt callback not present" \
9659            "$P_SRV debug_level=1 \
9660             async_operations=s async_private_delay1=1 async_private_delay2=1" \
9661            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA;
9662             [ \$? -eq 1 ] && $P_CLI force_version=tls12" \
9663            0 \
9664            -S "Async decrypt callback" \
9665            -s "! mbedtls_ssl_handshake returned" \
9666            -s "got no RSA private key" \
9667            -s "Async resume (slot [0-9]): sign done, status=0" \
9668            -s "Successful connection"
9669
9670# key1: ECDSA, key2: RSA; use key1 from slot 0
9671requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9672run_test    "SSL async private: slot 0 used with key1" \
9673            "$P_SRV \
9674             async_operations=s async_private_delay1=1 \
9675             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9676             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
9677            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
9678            0 \
9679            -s "Async sign callback: using key slot 0," \
9680            -s "Async resume (slot 0): call 0 more times." \
9681            -s "Async resume (slot 0): sign done, status=0"
9682
9683# key1: ECDSA, key2: RSA; use key2 from slot 0
9684requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9685run_test    "SSL async private: slot 0 used with key2" \
9686            "$P_SRV \
9687             async_operations=s async_private_delay2=1 \
9688             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9689             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
9690            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
9691            0 \
9692            -s "Async sign callback: using key slot 0," \
9693            -s "Async resume (slot 0): call 0 more times." \
9694            -s "Async resume (slot 0): sign done, status=0"
9695
9696# key1: ECDSA, key2: RSA; use key2 from slot 1
9697requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9698run_test    "SSL async private: slot 1 used with key2" \
9699            "$P_SRV \
9700             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9701             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9702             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
9703            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
9704            0 \
9705            -s "Async sign callback: using key slot 1," \
9706            -s "Async resume (slot 1): call 0 more times." \
9707            -s "Async resume (slot 1): sign done, status=0"
9708
9709# key1: ECDSA, key2: RSA; use key2 directly
9710requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9711run_test    "SSL async private: fall back to transparent key" \
9712            "$P_SRV \
9713             async_operations=s async_private_delay1=1 \
9714             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9715             key_file2=data_files/server2.key crt_file2=data_files/server2.crt " \
9716            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
9717            0 \
9718            -s "Async sign callback: no key matches this certificate."
9719
9720requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9721run_test    "SSL async private: sign, error in start" \
9722            "$P_SRV force_version=tls12 \
9723             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9724             async_private_error=1" \
9725            "$P_CLI" \
9726            1 \
9727            -s "Async sign callback: injected error" \
9728            -S "Async resume" \
9729            -S "Async cancel" \
9730            -s "! mbedtls_ssl_handshake returned"
9731
9732requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9733run_test    "SSL async private: sign, cancel after start" \
9734            "$P_SRV force_version=tls12 \
9735             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9736             async_private_error=2" \
9737            "$P_CLI" \
9738            1 \
9739            -s "Async sign callback: using key slot " \
9740            -S "Async resume" \
9741            -s "Async cancel"
9742
9743requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9744run_test    "SSL async private: sign, error in resume" \
9745            "$P_SRV force_version=tls12 \
9746             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9747             async_private_error=3" \
9748            "$P_CLI" \
9749            1 \
9750            -s "Async sign callback: using key slot " \
9751            -s "Async resume callback: sign done but injected error" \
9752            -S "Async cancel" \
9753            -s "! mbedtls_ssl_handshake returned"
9754
9755requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9756run_test    "SSL async private: decrypt, error in start" \
9757            "$P_SRV \
9758             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9759             async_private_error=1" \
9760            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9761            1 \
9762            -s "Async decrypt callback: injected error" \
9763            -S "Async resume" \
9764            -S "Async cancel" \
9765            -s "! mbedtls_ssl_handshake returned"
9766
9767requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9768run_test    "SSL async private: decrypt, cancel after start" \
9769            "$P_SRV \
9770             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9771             async_private_error=2" \
9772            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9773            1 \
9774            -s "Async decrypt callback: using key slot " \
9775            -S "Async resume" \
9776            -s "Async cancel"
9777
9778requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9779run_test    "SSL async private: decrypt, error in resume" \
9780            "$P_SRV \
9781             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9782             async_private_error=3" \
9783            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9784            1 \
9785            -s "Async decrypt callback: using key slot " \
9786            -s "Async resume callback: decrypt done but injected error" \
9787            -S "Async cancel" \
9788            -s "! mbedtls_ssl_handshake returned"
9789
9790requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9791run_test    "SSL async private: cancel after start then operate correctly" \
9792            "$P_SRV force_version=tls12 \
9793             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9794             async_private_error=-2" \
9795            "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
9796            0 \
9797            -s "Async cancel" \
9798            -s "! mbedtls_ssl_handshake returned" \
9799            -s "Async resume" \
9800            -s "Successful connection"
9801
9802requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9803run_test    "SSL async private: error in resume then operate correctly" \
9804            "$P_SRV force_version=tls12 \
9805             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9806             async_private_error=-3" \
9807            "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
9808            0 \
9809            -s "! mbedtls_ssl_handshake returned" \
9810            -s "Async resume" \
9811            -s "Successful connection"
9812
9813# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
9814requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9815# Note: the function "detect_required_features()" is not able to detect more than
9816#       one "force_ciphersuite" per client/server and it only picks the 2nd one.
9817#       Therefore the 1st one is added explicitly here
9818requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9819run_test    "SSL async private: cancel after start then fall back to transparent key" \
9820            "$P_SRV \
9821             async_operations=s async_private_delay1=1 async_private_error=-2 \
9822             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9823             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
9824            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
9825             [ \$? -eq 1 ] &&
9826             $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
9827            0 \
9828            -s "Async sign callback: using key slot 0" \
9829            -S "Async resume" \
9830            -s "Async cancel" \
9831            -s "! mbedtls_ssl_handshake returned" \
9832            -s "Async sign callback: no key matches this certificate." \
9833            -s "Successful connection"
9834
9835# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
9836requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9837# Note: the function "detect_required_features()" is not able to detect more than
9838#       one "force_ciphersuite" per client/server and it only picks the 2nd one.
9839#       Therefore the 1st one is added explicitly here
9840requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9841run_test    "SSL async private: sign, error in resume then fall back to transparent key" \
9842            "$P_SRV \
9843             async_operations=s async_private_delay1=1 async_private_error=-3 \
9844             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9845             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
9846            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
9847             [ \$? -eq 1 ] &&
9848             $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
9849            0 \
9850            -s "Async resume" \
9851            -s "! mbedtls_ssl_handshake returned" \
9852            -s "Async sign callback: no key matches this certificate." \
9853            -s "Successful connection"
9854
9855requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9856requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9857run_test    "SSL async private: renegotiation: client-initiated, sign" \
9858            "$P_SRV force_version=tls12 \
9859             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9860             exchanges=2 renegotiation=1" \
9861            "$P_CLI exchanges=2 renegotiation=1 renegotiate=1" \
9862            0 \
9863            -s "Async sign callback: using key slot " \
9864            -s "Async resume (slot [0-9]): sign done, status=0"
9865
9866requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9867requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9868run_test    "SSL async private: renegotiation: server-initiated, sign" \
9869            "$P_SRV force_version=tls12 \
9870             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9871             exchanges=2 renegotiation=1 renegotiate=1" \
9872            "$P_CLI exchanges=2 renegotiation=1" \
9873            0 \
9874            -s "Async sign callback: using key slot " \
9875            -s "Async resume (slot [0-9]): sign done, status=0"
9876
9877requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9878requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9879run_test    "SSL async private: renegotiation: client-initiated, decrypt" \
9880            "$P_SRV \
9881             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9882             exchanges=2 renegotiation=1" \
9883            "$P_CLI exchanges=2 renegotiation=1 renegotiate=1 \
9884             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9885            0 \
9886            -s "Async decrypt callback: using key slot " \
9887            -s "Async resume (slot [0-9]): decrypt done, status=0"
9888
9889requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9890requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9891run_test    "SSL async private: renegotiation: server-initiated, decrypt" \
9892            "$P_SRV \
9893             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9894             exchanges=2 renegotiation=1 renegotiate=1" \
9895            "$P_CLI exchanges=2 renegotiation=1 \
9896             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9897            0 \
9898            -s "Async decrypt callback: using key slot " \
9899            -s "Async resume (slot [0-9]): decrypt done, status=0"
9900
9901# Tests for ECC extensions (rfc 4492)
9902
9903requires_hash_alg SHA_256
9904requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
9905run_test    "Force a non ECC ciphersuite in the client side" \
9906            "$P_SRV debug_level=3" \
9907            "$P_CLI debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
9908            0 \
9909            -C "client hello, adding supported_groups extension" \
9910            -C "client hello, adding supported_point_formats extension" \
9911            -S "found supported elliptic curves extension" \
9912            -S "found supported point formats extension"
9913
9914requires_hash_alg SHA_256
9915requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
9916run_test    "Force a non ECC ciphersuite in the server side" \
9917            "$P_SRV debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
9918            "$P_CLI debug_level=3" \
9919            0 \
9920            -C "found supported_point_formats extension" \
9921            -S "server hello, supported_point_formats extension"
9922
9923requires_hash_alg SHA_256
9924run_test    "Force an ECC ciphersuite in the client side" \
9925            "$P_SRV debug_level=3" \
9926            "$P_CLI debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
9927            0 \
9928            -c "client hello, adding supported_groups extension" \
9929            -c "client hello, adding supported_point_formats extension" \
9930            -s "found supported elliptic curves extension" \
9931            -s "found supported point formats extension"
9932
9933requires_hash_alg SHA_256
9934run_test    "Force an ECC ciphersuite in the server side" \
9935            "$P_SRV debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
9936            "$P_CLI debug_level=3" \
9937            0 \
9938            -c "found supported_point_formats extension" \
9939            -s "server hello, supported_point_formats extension"
9940
9941# Tests for DTLS HelloVerifyRequest
9942
9943requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9944run_test    "DTLS cookie: enabled" \
9945            "$P_SRV dtls=1 debug_level=2" \
9946            "$P_CLI dtls=1 debug_level=2" \
9947            0 \
9948            -s "cookie verification failed" \
9949            -s "cookie verification passed" \
9950            -S "cookie verification skipped" \
9951            -c "received hello verify request" \
9952            -s "hello verification requested" \
9953            -S "SSL - The requested feature is not available"
9954
9955requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9956run_test    "DTLS cookie: disabled" \
9957            "$P_SRV dtls=1 debug_level=2 cookies=0" \
9958            "$P_CLI dtls=1 debug_level=2" \
9959            0 \
9960            -S "cookie verification failed" \
9961            -S "cookie verification passed" \
9962            -s "cookie verification skipped" \
9963            -C "received hello verify request" \
9964            -S "hello verification requested" \
9965            -S "SSL - The requested feature is not available"
9966
9967requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9968run_test    "DTLS cookie: default (failing)" \
9969            "$P_SRV dtls=1 debug_level=2 cookies=-1" \
9970            "$P_CLI dtls=1 debug_level=2 hs_timeout=100-400" \
9971            1 \
9972            -s "cookie verification failed" \
9973            -S "cookie verification passed" \
9974            -S "cookie verification skipped" \
9975            -C "received hello verify request" \
9976            -S "hello verification requested" \
9977            -s "SSL - The requested feature is not available"
9978
9979requires_ipv6
9980requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9981run_test    "DTLS cookie: enabled, IPv6" \
9982            "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
9983            "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
9984            0 \
9985            -s "cookie verification failed" \
9986            -s "cookie verification passed" \
9987            -S "cookie verification skipped" \
9988            -c "received hello verify request" \
9989            -s "hello verification requested" \
9990            -S "SSL - The requested feature is not available"
9991
9992requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9993run_test    "DTLS cookie: enabled, nbio" \
9994            "$P_SRV dtls=1 nbio=2 debug_level=2" \
9995            "$P_CLI dtls=1 nbio=2 debug_level=2" \
9996            0 \
9997            -s "cookie verification failed" \
9998            -s "cookie verification passed" \
9999            -S "cookie verification skipped" \
10000            -c "received hello verify request" \
10001            -s "hello verification requested" \
10002            -S "SSL - The requested feature is not available"
10003
10004# Tests for client reconnecting from the same port with DTLS
10005
10006not_with_valgrind # spurious resend
10007requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10008run_test    "DTLS client reconnect from same port: reference" \
10009            "$P_SRV dtls=1 exchanges=2 read_timeout=20000 hs_timeout=10000-20000" \
10010            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=10000-20000" \
10011            0 \
10012            -C "resend" \
10013            -S "The operation timed out" \
10014            -S "Client initiated reconnection from same port"
10015
10016not_with_valgrind # spurious resend
10017requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10018run_test    "DTLS client reconnect from same port: reconnect" \
10019            "$P_SRV dtls=1 exchanges=2 read_timeout=20000 hs_timeout=10000-20000" \
10020            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=10000-20000 reconnect_hard=1" \
10021            0 \
10022            -C "resend" \
10023            -S "The operation timed out" \
10024            -s "Client initiated reconnection from same port"
10025
10026not_with_valgrind # server/client too slow to respond in time (next test has higher timeouts)
10027requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10028run_test    "DTLS client reconnect from same port: reconnect, nbio, no valgrind" \
10029            "$P_SRV dtls=1 exchanges=2 read_timeout=1000 nbio=2" \
10030            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000 reconnect_hard=1" \
10031            0 \
10032            -S "The operation timed out" \
10033            -s "Client initiated reconnection from same port"
10034
10035only_with_valgrind # Only with valgrind, do previous test but with higher read_timeout and hs_timeout
10036requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10037run_test    "DTLS client reconnect from same port: reconnect, nbio, valgrind" \
10038            "$P_SRV dtls=1 exchanges=2 read_timeout=2000 nbio=2 hs_timeout=1500-6000" \
10039            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=1500-3000 reconnect_hard=1" \
10040            0 \
10041            -S "The operation timed out" \
10042            -s "Client initiated reconnection from same port"
10043
10044requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10045run_test    "DTLS client reconnect from same port: no cookies" \
10046            "$P_SRV dtls=1 exchanges=2 read_timeout=1000 cookies=0" \
10047            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-8000 reconnect_hard=1" \
10048            0 \
10049            -s "The operation timed out" \
10050            -S "Client initiated reconnection from same port"
10051
10052requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10053run_test    "DTLS client reconnect from same port: attacker-injected" \
10054            -p "$P_PXY inject_clihlo=1" \
10055            "$P_SRV dtls=1 exchanges=2 debug_level=1" \
10056            "$P_CLI dtls=1 exchanges=2" \
10057            0 \
10058            -s "possible client reconnect from the same port" \
10059            -S "Client initiated reconnection from same port"
10060
10061# Tests for various cases of client authentication with DTLS
10062# (focused on handshake flows and message parsing)
10063
10064requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10065run_test    "DTLS client auth: required" \
10066            "$P_SRV dtls=1 auth_mode=required" \
10067            "$P_CLI dtls=1" \
10068            0 \
10069            -s "Verifying peer X.509 certificate... ok"
10070
10071requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10072run_test    "DTLS client auth: optional, client has no cert" \
10073            "$P_SRV dtls=1 auth_mode=optional" \
10074            "$P_CLI dtls=1 crt_file=none key_file=none" \
10075            0 \
10076            -s "! Certificate was missing"
10077
10078requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10079run_test    "DTLS client auth: none, client has no cert" \
10080            "$P_SRV dtls=1 auth_mode=none" \
10081            "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
10082            0 \
10083            -c "skip write certificate$" \
10084            -s "! Certificate verification was skipped"
10085
10086run_test    "DTLS wrong PSK: badmac alert" \
10087            "$P_SRV dtls=1 psk=abc123 force_ciphersuite=TLS-PSK-WITH-AES-128-GCM-SHA256" \
10088            "$P_CLI dtls=1 psk=abc124" \
10089            1 \
10090            -s "SSL - Verification of the message MAC failed" \
10091            -c "SSL - A fatal alert message was received from our peer"
10092
10093# Tests for receiving fragmented handshake messages with DTLS
10094
10095requires_gnutls
10096requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10097run_test    "DTLS reassembly: no fragmentation (gnutls server)" \
10098            "$G_SRV -u --mtu 2048 -a" \
10099            "$P_CLI dtls=1 debug_level=2" \
10100            0 \
10101            -C "found fragmented DTLS handshake message" \
10102            -C "error"
10103
10104requires_gnutls
10105requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10106run_test    "DTLS reassembly: some fragmentation (gnutls server)" \
10107            "$G_SRV -u --mtu 512" \
10108            "$P_CLI dtls=1 debug_level=2" \
10109            0 \
10110            -c "found fragmented DTLS handshake message" \
10111            -C "error"
10112
10113requires_gnutls
10114requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10115run_test    "DTLS reassembly: more fragmentation (gnutls server)" \
10116            "$G_SRV -u --mtu 128" \
10117            "$P_CLI dtls=1 debug_level=2" \
10118            0 \
10119            -c "found fragmented DTLS handshake message" \
10120            -C "error"
10121
10122requires_gnutls
10123requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10124run_test    "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
10125            "$G_SRV -u --mtu 128" \
10126            "$P_CLI dtls=1 nbio=2 debug_level=2" \
10127            0 \
10128            -c "found fragmented DTLS handshake message" \
10129            -C "error"
10130
10131requires_gnutls
10132requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10133requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10134run_test    "DTLS reassembly: fragmentation, renego (gnutls server)" \
10135            "$G_SRV -u --mtu 256" \
10136            "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
10137            0 \
10138            -c "found fragmented DTLS handshake message" \
10139            -c "client hello, adding renegotiation extension" \
10140            -c "found renegotiation extension" \
10141            -c "=> renegotiate" \
10142            -C "mbedtls_ssl_handshake returned" \
10143            -C "error" \
10144            -s "Extra-header:"
10145
10146requires_gnutls
10147requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10148requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10149run_test    "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
10150            "$G_SRV -u --mtu 256" \
10151            "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
10152            0 \
10153            -c "found fragmented DTLS handshake message" \
10154            -c "client hello, adding renegotiation extension" \
10155            -c "found renegotiation extension" \
10156            -c "=> renegotiate" \
10157            -C "mbedtls_ssl_handshake returned" \
10158            -C "error" \
10159            -s "Extra-header:"
10160
10161requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10162run_test    "DTLS reassembly: no fragmentation (openssl server)" \
10163            "$O_SRV -dtls -mtu 2048" \
10164            "$P_CLI dtls=1 debug_level=2" \
10165            0 \
10166            -C "found fragmented DTLS handshake message" \
10167            -C "error"
10168
10169requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10170run_test    "DTLS reassembly: some fragmentation (openssl server)" \
10171            "$O_SRV -dtls -mtu 256" \
10172            "$P_CLI dtls=1 debug_level=2" \
10173            0 \
10174            -c "found fragmented DTLS handshake message" \
10175            -C "error"
10176
10177requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10178run_test    "DTLS reassembly: more fragmentation (openssl server)" \
10179            "$O_SRV -dtls -mtu 256" \
10180            "$P_CLI dtls=1 debug_level=2" \
10181            0 \
10182            -c "found fragmented DTLS handshake message" \
10183            -C "error"
10184
10185requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10186run_test    "DTLS reassembly: fragmentation, nbio (openssl server)" \
10187            "$O_SRV -dtls -mtu 256" \
10188            "$P_CLI dtls=1 nbio=2 debug_level=2" \
10189            0 \
10190            -c "found fragmented DTLS handshake message" \
10191            -C "error"
10192
10193# Tests for sending fragmented handshake messages with DTLS
10194#
10195# Use client auth when we need the client to send large messages,
10196# and use large cert chains on both sides too (the long chains we have all use
10197# both RSA and ECDSA, but ideally we should have long chains with either).
10198# Sizes reached (UDP payload):
10199# - 2037B for server certificate
10200# - 1542B for client certificate
10201# - 1013B for newsessionticket
10202# - all others below 512B
10203# All those tests assume MAX_CONTENT_LEN is at least 2048
10204
10205requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10206requires_config_enabled MBEDTLS_RSA_C
10207requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
10208requires_max_content_len 4096
10209requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10210run_test    "DTLS fragmenting: none (for reference)" \
10211            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10212             crt_file=data_files/server7_int-ca.crt \
10213             key_file=data_files/server7.key \
10214             hs_timeout=2500-60000 \
10215             max_frag_len=4096" \
10216            "$P_CLI dtls=1 debug_level=2 \
10217             crt_file=data_files/server8_int-ca2.crt \
10218             key_file=data_files/server8.key \
10219             hs_timeout=2500-60000 \
10220             max_frag_len=4096" \
10221            0 \
10222            -S "found fragmented DTLS handshake message" \
10223            -C "found fragmented DTLS handshake message" \
10224            -C "error"
10225
10226requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10227requires_config_enabled MBEDTLS_RSA_C
10228requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
10229requires_max_content_len 2048
10230requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10231run_test    "DTLS fragmenting: server only (max_frag_len)" \
10232            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10233             crt_file=data_files/server7_int-ca.crt \
10234             key_file=data_files/server7.key \
10235             hs_timeout=2500-60000 \
10236             max_frag_len=1024" \
10237            "$P_CLI dtls=1 debug_level=2 \
10238             crt_file=data_files/server8_int-ca2.crt \
10239             key_file=data_files/server8.key \
10240             hs_timeout=2500-60000 \
10241             max_frag_len=2048" \
10242            0 \
10243            -S "found fragmented DTLS handshake message" \
10244            -c "found fragmented DTLS handshake message" \
10245            -C "error"
10246
10247# With the MFL extension, the server has no way of forcing
10248# the client to not exceed a certain MTU; hence, the following
10249# test can't be replicated with an MTU proxy such as the one
10250# `client-initiated, server only (max_frag_len)` below.
10251requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10252requires_config_enabled MBEDTLS_RSA_C
10253requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
10254requires_max_content_len 4096
10255requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10256run_test    "DTLS fragmenting: server only (more) (max_frag_len)" \
10257            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10258             crt_file=data_files/server7_int-ca.crt \
10259             key_file=data_files/server7.key \
10260             hs_timeout=2500-60000 \
10261             max_frag_len=512" \
10262            "$P_CLI dtls=1 debug_level=2 \
10263             crt_file=data_files/server8_int-ca2.crt \
10264             key_file=data_files/server8.key \
10265             hs_timeout=2500-60000 \
10266             max_frag_len=4096" \
10267            0 \
10268            -S "found fragmented DTLS handshake message" \
10269            -c "found fragmented DTLS handshake message" \
10270            -C "error"
10271
10272requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10273requires_config_enabled MBEDTLS_RSA_C
10274requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
10275requires_max_content_len 2048
10276requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10277run_test    "DTLS fragmenting: client-initiated, server only (max_frag_len)" \
10278            "$P_SRV dtls=1 debug_level=2 auth_mode=none \
10279             crt_file=data_files/server7_int-ca.crt \
10280             key_file=data_files/server7.key \
10281             hs_timeout=2500-60000 \
10282             max_frag_len=2048" \
10283            "$P_CLI dtls=1 debug_level=2 \
10284             crt_file=data_files/server8_int-ca2.crt \
10285             key_file=data_files/server8.key \
10286             hs_timeout=2500-60000 \
10287             max_frag_len=1024" \
10288             0 \
10289            -S "found fragmented DTLS handshake message" \
10290            -c "found fragmented DTLS handshake message" \
10291            -C "error"
10292
10293# While not required by the standard defining the MFL extension
10294# (according to which it only applies to records, not to datagrams),
10295# Mbed TLS will never send datagrams larger than MFL + { Max record expansion },
10296# as otherwise there wouldn't be any means to communicate MTU restrictions
10297# to the peer.
10298# The next test checks that no datagrams significantly larger than the
10299# negotiated MFL are sent.
10300requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10301requires_config_enabled MBEDTLS_RSA_C
10302requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
10303requires_max_content_len 2048
10304requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10305run_test    "DTLS fragmenting: client-initiated, server only (max_frag_len), proxy MTU" \
10306            -p "$P_PXY mtu=1110" \
10307            "$P_SRV dtls=1 debug_level=2 auth_mode=none \
10308             crt_file=data_files/server7_int-ca.crt \
10309             key_file=data_files/server7.key \
10310             hs_timeout=2500-60000 \
10311             max_frag_len=2048" \
10312            "$P_CLI dtls=1 debug_level=2 \
10313             crt_file=data_files/server8_int-ca2.crt \
10314             key_file=data_files/server8.key \
10315             hs_timeout=2500-60000 \
10316             max_frag_len=1024" \
10317            0 \
10318            -S "found fragmented DTLS handshake message" \
10319            -c "found fragmented DTLS handshake message" \
10320            -C "error"
10321
10322requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10323requires_config_enabled MBEDTLS_RSA_C
10324requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
10325requires_max_content_len 2048
10326requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10327run_test    "DTLS fragmenting: client-initiated, both (max_frag_len)" \
10328            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10329             crt_file=data_files/server7_int-ca.crt \
10330             key_file=data_files/server7.key \
10331             hs_timeout=2500-60000 \
10332             max_frag_len=2048" \
10333            "$P_CLI dtls=1 debug_level=2 \
10334             crt_file=data_files/server8_int-ca2.crt \
10335             key_file=data_files/server8.key \
10336             hs_timeout=2500-60000 \
10337             max_frag_len=1024" \
10338            0 \
10339            -s "found fragmented DTLS handshake message" \
10340            -c "found fragmented DTLS handshake message" \
10341            -C "error"
10342
10343# While not required by the standard defining the MFL extension
10344# (according to which it only applies to records, not to datagrams),
10345# Mbed TLS will never send datagrams larger than MFL + { Max record expansion },
10346# as otherwise there wouldn't be any means to communicate MTU restrictions
10347# to the peer.
10348# The next test checks that no datagrams significantly larger than the
10349# negotiated MFL are sent.
10350requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10351requires_config_enabled MBEDTLS_RSA_C
10352requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
10353requires_max_content_len 2048
10354requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10355run_test    "DTLS fragmenting: client-initiated, both (max_frag_len), proxy MTU" \
10356            -p "$P_PXY mtu=1110" \
10357            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10358             crt_file=data_files/server7_int-ca.crt \
10359             key_file=data_files/server7.key \
10360             hs_timeout=2500-60000 \
10361             max_frag_len=2048" \
10362            "$P_CLI dtls=1 debug_level=2 \
10363             crt_file=data_files/server8_int-ca2.crt \
10364             key_file=data_files/server8.key \
10365             hs_timeout=2500-60000 \
10366             max_frag_len=1024" \
10367            0 \
10368            -s "found fragmented DTLS handshake message" \
10369            -c "found fragmented DTLS handshake message" \
10370            -C "error"
10371
10372requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10373requires_config_enabled MBEDTLS_RSA_C
10374requires_max_content_len 4096
10375requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10376run_test    "DTLS fragmenting: none (for reference) (MTU)" \
10377            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10378             crt_file=data_files/server7_int-ca.crt \
10379             key_file=data_files/server7.key \
10380             hs_timeout=2500-60000 \
10381             mtu=4096" \
10382            "$P_CLI dtls=1 debug_level=2 \
10383             crt_file=data_files/server8_int-ca2.crt \
10384             key_file=data_files/server8.key \
10385             hs_timeout=2500-60000 \
10386             mtu=4096" \
10387            0 \
10388            -S "found fragmented DTLS handshake message" \
10389            -C "found fragmented DTLS handshake message" \
10390            -C "error"
10391
10392requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10393requires_config_enabled MBEDTLS_RSA_C
10394requires_max_content_len 4096
10395requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10396run_test    "DTLS fragmenting: client (MTU)" \
10397            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10398             crt_file=data_files/server7_int-ca.crt \
10399             key_file=data_files/server7.key \
10400             hs_timeout=3500-60000 \
10401             mtu=4096" \
10402            "$P_CLI dtls=1 debug_level=2 \
10403             crt_file=data_files/server8_int-ca2.crt \
10404             key_file=data_files/server8.key \
10405             hs_timeout=3500-60000 \
10406             mtu=1024" \
10407            0 \
10408            -s "found fragmented DTLS handshake message" \
10409            -C "found fragmented DTLS handshake message" \
10410            -C "error"
10411
10412requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10413requires_config_enabled MBEDTLS_RSA_C
10414requires_max_content_len 2048
10415requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10416run_test    "DTLS fragmenting: server (MTU)" \
10417            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10418             crt_file=data_files/server7_int-ca.crt \
10419             key_file=data_files/server7.key \
10420             hs_timeout=2500-60000 \
10421             mtu=512" \
10422            "$P_CLI dtls=1 debug_level=2 \
10423             crt_file=data_files/server8_int-ca2.crt \
10424             key_file=data_files/server8.key \
10425             hs_timeout=2500-60000 \
10426             mtu=2048" \
10427            0 \
10428            -S "found fragmented DTLS handshake message" \
10429            -c "found fragmented DTLS handshake message" \
10430            -C "error"
10431
10432requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10433requires_config_enabled MBEDTLS_RSA_C
10434requires_max_content_len 2048
10435requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10436run_test    "DTLS fragmenting: both (MTU=1024)" \
10437            -p "$P_PXY mtu=1024" \
10438            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10439             crt_file=data_files/server7_int-ca.crt \
10440             key_file=data_files/server7.key \
10441             hs_timeout=2500-60000 \
10442             mtu=1024" \
10443            "$P_CLI dtls=1 debug_level=2 \
10444             crt_file=data_files/server8_int-ca2.crt \
10445             key_file=data_files/server8.key \
10446             hs_timeout=2500-60000 \
10447             mtu=1024" \
10448            0 \
10449            -s "found fragmented DTLS handshake message" \
10450            -c "found fragmented DTLS handshake message" \
10451            -C "error"
10452
10453# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
10454requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10455requires_config_enabled MBEDTLS_RSA_C
10456requires_hash_alg SHA_256
10457requires_max_content_len 2048
10458run_test    "DTLS fragmenting: both (MTU=512)" \
10459            -p "$P_PXY mtu=512" \
10460            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10461             crt_file=data_files/server7_int-ca.crt \
10462             key_file=data_files/server7.key \
10463             hs_timeout=2500-60000 \
10464             mtu=512" \
10465            "$P_CLI dtls=1 debug_level=2 \
10466             crt_file=data_files/server8_int-ca2.crt \
10467             key_file=data_files/server8.key \
10468             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10469             hs_timeout=2500-60000 \
10470             mtu=512" \
10471            0 \
10472            -s "found fragmented DTLS handshake message" \
10473            -c "found fragmented DTLS handshake message" \
10474            -C "error"
10475
10476# Test for automatic MTU reduction on repeated resend.
10477# Forcing ciphersuite for this test to fit the MTU of 508 with full config.
10478# The ratio of max/min timeout should ideally equal 4 to accept two
10479# retransmissions, but in some cases (like both the server and client using
10480# fragmentation and auto-reduction) an extra retransmission might occur,
10481# hence the ratio of 8.
10482not_with_valgrind
10483requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10484requires_config_enabled MBEDTLS_RSA_C
10485requires_max_content_len 2048
10486run_test    "DTLS fragmenting: proxy MTU: auto-reduction (not valgrind)" \
10487            -p "$P_PXY mtu=508" \
10488            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10489             crt_file=data_files/server7_int-ca.crt \
10490             key_file=data_files/server7.key \
10491             hs_timeout=400-3200" \
10492            "$P_CLI dtls=1 debug_level=2 \
10493             crt_file=data_files/server8_int-ca2.crt \
10494             key_file=data_files/server8.key \
10495             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10496             hs_timeout=400-3200" \
10497            0 \
10498            -s "found fragmented DTLS handshake message" \
10499            -c "found fragmented DTLS handshake message" \
10500            -C "error"
10501
10502# Forcing ciphersuite for this test to fit the MTU of 508 with full config.
10503only_with_valgrind
10504requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10505requires_config_enabled MBEDTLS_RSA_C
10506requires_max_content_len 2048
10507run_test    "DTLS fragmenting: proxy MTU: auto-reduction (with valgrind)" \
10508            -p "$P_PXY mtu=508" \
10509            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10510             crt_file=data_files/server7_int-ca.crt \
10511             key_file=data_files/server7.key \
10512             hs_timeout=250-10000" \
10513            "$P_CLI dtls=1 debug_level=2 \
10514             crt_file=data_files/server8_int-ca2.crt \
10515             key_file=data_files/server8.key \
10516             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10517             hs_timeout=250-10000" \
10518            0 \
10519            -s "found fragmented DTLS handshake message" \
10520            -c "found fragmented DTLS handshake message" \
10521            -C "error"
10522
10523# the proxy shouldn't drop or mess up anything, so we shouldn't need to resend
10524# OTOH the client might resend if the server is to slow to reset after sending
10525# a HelloVerifyRequest, so only check for no retransmission server-side
10526not_with_valgrind # spurious autoreduction due to timeout
10527requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10528requires_config_enabled MBEDTLS_RSA_C
10529requires_max_content_len 2048
10530requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10531run_test    "DTLS fragmenting: proxy MTU, simple handshake (MTU=1024)" \
10532            -p "$P_PXY mtu=1024" \
10533            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10534             crt_file=data_files/server7_int-ca.crt \
10535             key_file=data_files/server7.key \
10536             hs_timeout=10000-60000 \
10537             mtu=1024" \
10538            "$P_CLI dtls=1 debug_level=2 \
10539             crt_file=data_files/server8_int-ca2.crt \
10540             key_file=data_files/server8.key \
10541             hs_timeout=10000-60000 \
10542             mtu=1024" \
10543            0 \
10544            -S "autoreduction" \
10545            -s "found fragmented DTLS handshake message" \
10546            -c "found fragmented DTLS handshake message" \
10547            -C "error"
10548
10549# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
10550# the proxy shouldn't drop or mess up anything, so we shouldn't need to resend
10551# OTOH the client might resend if the server is to slow to reset after sending
10552# a HelloVerifyRequest, so only check for no retransmission server-side
10553not_with_valgrind # spurious autoreduction due to timeout
10554requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10555requires_config_enabled MBEDTLS_RSA_C
10556requires_max_content_len 2048
10557run_test    "DTLS fragmenting: proxy MTU, simple handshake (MTU=512)" \
10558            -p "$P_PXY mtu=512" \
10559            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10560             crt_file=data_files/server7_int-ca.crt \
10561             key_file=data_files/server7.key \
10562             hs_timeout=10000-60000 \
10563             mtu=512" \
10564            "$P_CLI dtls=1 debug_level=2 \
10565             crt_file=data_files/server8_int-ca2.crt \
10566             key_file=data_files/server8.key \
10567             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10568             hs_timeout=10000-60000 \
10569             mtu=512" \
10570            0 \
10571            -S "autoreduction" \
10572            -s "found fragmented DTLS handshake message" \
10573            -c "found fragmented DTLS handshake message" \
10574            -C "error"
10575
10576not_with_valgrind # spurious autoreduction due to timeout
10577requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10578requires_config_enabled MBEDTLS_RSA_C
10579requires_max_content_len 2048
10580requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10581run_test    "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=1024)" \
10582            -p "$P_PXY mtu=1024" \
10583            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10584             crt_file=data_files/server7_int-ca.crt \
10585             key_file=data_files/server7.key \
10586             hs_timeout=10000-60000 \
10587             mtu=1024 nbio=2" \
10588            "$P_CLI dtls=1 debug_level=2 \
10589             crt_file=data_files/server8_int-ca2.crt \
10590             key_file=data_files/server8.key \
10591             hs_timeout=10000-60000 \
10592             mtu=1024 nbio=2" \
10593            0 \
10594            -S "autoreduction" \
10595            -s "found fragmented DTLS handshake message" \
10596            -c "found fragmented DTLS handshake message" \
10597            -C "error"
10598
10599# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
10600not_with_valgrind # spurious autoreduction due to timeout
10601requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10602requires_config_enabled MBEDTLS_RSA_C
10603requires_max_content_len 2048
10604run_test    "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=512)" \
10605            -p "$P_PXY mtu=512" \
10606            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10607             crt_file=data_files/server7_int-ca.crt \
10608             key_file=data_files/server7.key \
10609             hs_timeout=10000-60000 \
10610             mtu=512 nbio=2" \
10611            "$P_CLI dtls=1 debug_level=2 \
10612             crt_file=data_files/server8_int-ca2.crt \
10613             key_file=data_files/server8.key \
10614             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10615             hs_timeout=10000-60000 \
10616             mtu=512 nbio=2" \
10617            0 \
10618            -S "autoreduction" \
10619            -s "found fragmented DTLS handshake message" \
10620            -c "found fragmented DTLS handshake message" \
10621            -C "error"
10622
10623# Forcing ciphersuite for this test to fit the MTU of 1450 with full config.
10624# This ensures things still work after session_reset().
10625# It also exercises the "resumed handshake" flow.
10626# Since we don't support reading fragmented ClientHello yet,
10627# up the MTU to 1450 (larger than ClientHello with session ticket,
10628# but still smaller than client's Certificate to ensure fragmentation).
10629# An autoreduction on the client-side might happen if the server is
10630# slow to reset, therefore omitting '-C "autoreduction"' below.
10631# reco_delay avoids races where the client reconnects before the server has
10632# resumed listening, which would result in a spurious autoreduction.
10633not_with_valgrind # spurious autoreduction due to timeout
10634requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10635requires_config_enabled MBEDTLS_RSA_C
10636requires_max_content_len 2048
10637run_test    "DTLS fragmenting: proxy MTU, resumed handshake" \
10638            -p "$P_PXY mtu=1450" \
10639            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10640             crt_file=data_files/server7_int-ca.crt \
10641             key_file=data_files/server7.key \
10642             hs_timeout=10000-60000 \
10643             mtu=1450" \
10644            "$P_CLI dtls=1 debug_level=2 \
10645             crt_file=data_files/server8_int-ca2.crt \
10646             key_file=data_files/server8.key \
10647             hs_timeout=10000-60000 \
10648             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10649             mtu=1450 reconnect=1 skip_close_notify=1 reco_delay=1000" \
10650            0 \
10651            -S "autoreduction" \
10652            -s "found fragmented DTLS handshake message" \
10653            -c "found fragmented DTLS handshake message" \
10654            -C "error"
10655
10656# An autoreduction on the client-side might happen if the server is
10657# slow to reset, therefore omitting '-C "autoreduction"' below.
10658not_with_valgrind # spurious autoreduction due to timeout
10659requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10660requires_config_enabled MBEDTLS_RSA_C
10661requires_hash_alg SHA_256
10662requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10663requires_max_content_len 2048
10664run_test    "DTLS fragmenting: proxy MTU, ChachaPoly renego" \
10665            -p "$P_PXY mtu=512" \
10666            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10667             crt_file=data_files/server7_int-ca.crt \
10668             key_file=data_files/server7.key \
10669             exchanges=2 renegotiation=1 \
10670             hs_timeout=10000-60000 \
10671             mtu=512" \
10672            "$P_CLI dtls=1 debug_level=2 \
10673             crt_file=data_files/server8_int-ca2.crt \
10674             key_file=data_files/server8.key \
10675             exchanges=2 renegotiation=1 renegotiate=1 \
10676             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256 \
10677             hs_timeout=10000-60000 \
10678             mtu=512" \
10679            0 \
10680            -S "autoreduction" \
10681            -s "found fragmented DTLS handshake message" \
10682            -c "found fragmented DTLS handshake message" \
10683            -C "error"
10684
10685# An autoreduction on the client-side might happen if the server is
10686# slow to reset, therefore omitting '-C "autoreduction"' below.
10687not_with_valgrind # spurious autoreduction due to timeout
10688requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10689requires_config_enabled MBEDTLS_RSA_C
10690requires_hash_alg SHA_256
10691requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10692requires_max_content_len 2048
10693run_test    "DTLS fragmenting: proxy MTU, AES-GCM renego" \
10694            -p "$P_PXY mtu=512" \
10695            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10696             crt_file=data_files/server7_int-ca.crt \
10697             key_file=data_files/server7.key \
10698             exchanges=2 renegotiation=1 \
10699             hs_timeout=10000-60000 \
10700             mtu=512" \
10701            "$P_CLI dtls=1 debug_level=2 \
10702             crt_file=data_files/server8_int-ca2.crt \
10703             key_file=data_files/server8.key \
10704             exchanges=2 renegotiation=1 renegotiate=1 \
10705             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10706             hs_timeout=10000-60000 \
10707             mtu=512" \
10708            0 \
10709            -S "autoreduction" \
10710            -s "found fragmented DTLS handshake message" \
10711            -c "found fragmented DTLS handshake message" \
10712            -C "error"
10713
10714# An autoreduction on the client-side might happen if the server is
10715# slow to reset, therefore omitting '-C "autoreduction"' below.
10716not_with_valgrind # spurious autoreduction due to timeout
10717requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10718requires_config_enabled MBEDTLS_RSA_C
10719requires_hash_alg SHA_256
10720requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10721requires_max_content_len 2048
10722run_test    "DTLS fragmenting: proxy MTU, AES-CCM renego" \
10723            -p "$P_PXY mtu=1024" \
10724            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10725             crt_file=data_files/server7_int-ca.crt \
10726             key_file=data_files/server7.key \
10727             exchanges=2 renegotiation=1 \
10728             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8 \
10729             hs_timeout=10000-60000 \
10730             mtu=1024" \
10731            "$P_CLI dtls=1 debug_level=2 \
10732             crt_file=data_files/server8_int-ca2.crt \
10733             key_file=data_files/server8.key \
10734             exchanges=2 renegotiation=1 renegotiate=1 \
10735             hs_timeout=10000-60000 \
10736             mtu=1024" \
10737            0 \
10738            -S "autoreduction" \
10739            -s "found fragmented DTLS handshake message" \
10740            -c "found fragmented DTLS handshake message" \
10741            -C "error"
10742
10743# An autoreduction on the client-side might happen if the server is
10744# slow to reset, therefore omitting '-C "autoreduction"' below.
10745not_with_valgrind # spurious autoreduction due to timeout
10746requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10747requires_config_enabled MBEDTLS_RSA_C
10748requires_hash_alg SHA_256
10749requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10750requires_config_enabled MBEDTLS_SSL_ENCRYPT_THEN_MAC
10751requires_max_content_len 2048
10752run_test    "DTLS fragmenting: proxy MTU, AES-CBC EtM renego" \
10753            -p "$P_PXY mtu=1024" \
10754            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10755             crt_file=data_files/server7_int-ca.crt \
10756             key_file=data_files/server7.key \
10757             exchanges=2 renegotiation=1 \
10758             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 \
10759             hs_timeout=10000-60000 \
10760             mtu=1024" \
10761            "$P_CLI dtls=1 debug_level=2 \
10762             crt_file=data_files/server8_int-ca2.crt \
10763             key_file=data_files/server8.key \
10764             exchanges=2 renegotiation=1 renegotiate=1 \
10765             hs_timeout=10000-60000 \
10766             mtu=1024" \
10767            0 \
10768            -S "autoreduction" \
10769            -s "found fragmented DTLS handshake message" \
10770            -c "found fragmented DTLS handshake message" \
10771            -C "error"
10772
10773# An autoreduction on the client-side might happen if the server is
10774# slow to reset, therefore omitting '-C "autoreduction"' below.
10775not_with_valgrind # spurious autoreduction due to timeout
10776requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10777requires_config_enabled MBEDTLS_RSA_C
10778requires_hash_alg SHA_256
10779requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10780requires_max_content_len 2048
10781run_test    "DTLS fragmenting: proxy MTU, AES-CBC non-EtM renego" \
10782            -p "$P_PXY mtu=1024" \
10783            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10784             crt_file=data_files/server7_int-ca.crt \
10785             key_file=data_files/server7.key \
10786             exchanges=2 renegotiation=1 \
10787             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 etm=0 \
10788             hs_timeout=10000-60000 \
10789             mtu=1024" \
10790            "$P_CLI dtls=1 debug_level=2 \
10791             crt_file=data_files/server8_int-ca2.crt \
10792             key_file=data_files/server8.key \
10793             exchanges=2 renegotiation=1 renegotiate=1 \
10794             hs_timeout=10000-60000 \
10795             mtu=1024" \
10796            0 \
10797            -S "autoreduction" \
10798            -s "found fragmented DTLS handshake message" \
10799            -c "found fragmented DTLS handshake message" \
10800            -C "error"
10801
10802# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
10803requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10804requires_config_enabled MBEDTLS_RSA_C
10805client_needs_more_time 2
10806requires_max_content_len 2048
10807run_test    "DTLS fragmenting: proxy MTU + 3d" \
10808            -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
10809            "$P_SRV dgram_packing=0 dtls=1 debug_level=2 auth_mode=required \
10810             crt_file=data_files/server7_int-ca.crt \
10811             key_file=data_files/server7.key \
10812             hs_timeout=250-10000 mtu=512" \
10813            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10814             crt_file=data_files/server8_int-ca2.crt \
10815             key_file=data_files/server8.key \
10816             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10817             hs_timeout=250-10000 mtu=512" \
10818            0 \
10819            -s "found fragmented DTLS handshake message" \
10820            -c "found fragmented DTLS handshake message" \
10821            -C "error"
10822
10823# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
10824requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10825requires_config_enabled MBEDTLS_RSA_C
10826client_needs_more_time 2
10827requires_max_content_len 2048
10828run_test    "DTLS fragmenting: proxy MTU + 3d, nbio" \
10829            -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
10830            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10831             crt_file=data_files/server7_int-ca.crt \
10832             key_file=data_files/server7.key \
10833             hs_timeout=250-10000 mtu=512 nbio=2" \
10834            "$P_CLI dtls=1 debug_level=2 \
10835             crt_file=data_files/server8_int-ca2.crt \
10836             key_file=data_files/server8.key \
10837             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10838             hs_timeout=250-10000 mtu=512 nbio=2" \
10839            0 \
10840            -s "found fragmented DTLS handshake message" \
10841            -c "found fragmented DTLS handshake message" \
10842            -C "error"
10843
10844# interop tests for DTLS fragmentating with reliable connection
10845#
10846# here and below we just want to test that the we fragment in a way that
10847# pleases other implementations, so we don't need the peer to fragment
10848requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10849requires_config_enabled MBEDTLS_RSA_C
10850requires_gnutls
10851requires_max_content_len 2048
10852run_test    "DTLS fragmenting: gnutls server, DTLS 1.2" \
10853            "$G_SRV -u" \
10854            "$P_CLI dtls=1 debug_level=2 \
10855             crt_file=data_files/server8_int-ca2.crt \
10856             key_file=data_files/server8.key \
10857             mtu=512 force_version=dtls12" \
10858            0 \
10859            -c "fragmenting handshake message" \
10860            -C "error"
10861
10862# We use --insecure for the GnuTLS client because it expects
10863# the hostname / IP it connects to to be the name used in the
10864# certificate obtained from the server. Here, however, it
10865# connects to 127.0.0.1 while our test certificates use 'localhost'
10866# as the server name in the certificate. This will make the
10867# certificate validation fail, but passing --insecure makes
10868# GnuTLS continue the connection nonetheless.
10869requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10870requires_config_enabled MBEDTLS_RSA_C
10871requires_gnutls
10872requires_not_i686
10873requires_max_content_len 2048
10874run_test    "DTLS fragmenting: gnutls client, DTLS 1.2" \
10875            "$P_SRV dtls=1 debug_level=2 \
10876             crt_file=data_files/server7_int-ca.crt \
10877             key_file=data_files/server7.key \
10878             mtu=512 force_version=dtls12" \
10879            "$G_CLI -u --insecure 127.0.0.1" \
10880            0 \
10881            -s "fragmenting handshake message"
10882
10883requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10884requires_config_enabled MBEDTLS_RSA_C
10885requires_max_content_len 2048
10886run_test    "DTLS fragmenting: openssl server, DTLS 1.2" \
10887            "$O_SRV -dtls1_2 -verify 10" \
10888            "$P_CLI dtls=1 debug_level=2 \
10889             crt_file=data_files/server8_int-ca2.crt \
10890             key_file=data_files/server8.key \
10891             mtu=512 force_version=dtls12" \
10892            0 \
10893            -c "fragmenting handshake message" \
10894            -C "error"
10895
10896requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10897requires_config_enabled MBEDTLS_RSA_C
10898requires_max_content_len 2048
10899run_test    "DTLS fragmenting: openssl client, DTLS 1.2" \
10900            "$P_SRV dtls=1 debug_level=2 \
10901             crt_file=data_files/server7_int-ca.crt \
10902             key_file=data_files/server7.key \
10903             mtu=512 force_version=dtls12" \
10904            "$O_CLI -dtls1_2" \
10905            0 \
10906            -s "fragmenting handshake message"
10907
10908# interop tests for DTLS fragmentating with unreliable connection
10909#
10910# again we just want to test that the we fragment in a way that
10911# pleases other implementations, so we don't need the peer to fragment
10912requires_gnutls_next
10913requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10914requires_config_enabled MBEDTLS_RSA_C
10915client_needs_more_time 4
10916requires_max_content_len 2048
10917run_test    "DTLS fragmenting: 3d, gnutls server, DTLS 1.2" \
10918            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10919            "$G_NEXT_SRV -u" \
10920            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10921             crt_file=data_files/server8_int-ca2.crt \
10922             key_file=data_files/server8.key \
10923             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10924            0 \
10925            -c "fragmenting handshake message" \
10926            -C "error"
10927
10928requires_gnutls_next
10929requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10930requires_config_enabled MBEDTLS_RSA_C
10931client_needs_more_time 4
10932requires_max_content_len 2048
10933run_test    "DTLS fragmenting: 3d, gnutls client, DTLS 1.2" \
10934            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10935            "$P_SRV dtls=1 debug_level=2 \
10936             crt_file=data_files/server7_int-ca.crt \
10937             key_file=data_files/server7.key \
10938             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10939           "$G_NEXT_CLI -u --insecure 127.0.0.1" \
10940            0 \
10941            -s "fragmenting handshake message"
10942
10943## The test below requires 1.1.1a or higher version of openssl, otherwise
10944## it might trigger a bug due to openssl server (https://github.com/openssl/openssl/issues/6902)
10945requires_openssl_next
10946requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10947requires_config_enabled MBEDTLS_RSA_C
10948client_needs_more_time 4
10949requires_max_content_len 2048
10950run_test    "DTLS fragmenting: 3d, openssl server, DTLS 1.2" \
10951            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10952            "$O_NEXT_SRV -dtls1_2 -verify 10" \
10953            "$P_CLI dtls=1 debug_level=2 \
10954             crt_file=data_files/server8_int-ca2.crt \
10955             key_file=data_files/server8.key \
10956             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10957            0 \
10958            -c "fragmenting handshake message" \
10959            -C "error"
10960
10961## the test below will time out with certain seed.
10962## The cause is an openssl bug (https://github.com/openssl/openssl/issues/18887)
10963skip_next_test
10964requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10965requires_config_enabled MBEDTLS_RSA_C
10966client_needs_more_time 4
10967requires_max_content_len 2048
10968run_test    "DTLS fragmenting: 3d, openssl client, DTLS 1.2" \
10969            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10970            "$P_SRV dtls=1 debug_level=2 \
10971             crt_file=data_files/server7_int-ca.crt \
10972             key_file=data_files/server7.key \
10973             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10974            "$O_CLI -dtls1_2" \
10975            0 \
10976            -s "fragmenting handshake message"
10977
10978# Tests for DTLS-SRTP (RFC 5764)
10979requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10980requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10981run_test  "DTLS-SRTP all profiles supported" \
10982          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10983          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10984          0 \
10985          -s "found use_srtp extension" \
10986          -s "found srtp profile" \
10987          -s "selected srtp profile" \
10988          -s "server hello, adding use_srtp extension" \
10989          -s "DTLS-SRTP key material is"\
10990          -c "client hello, adding use_srtp extension" \
10991          -c "found use_srtp extension" \
10992          -c "found srtp profile" \
10993          -c "selected srtp profile" \
10994          -c "DTLS-SRTP key material is"\
10995          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10996          -C "error"
10997
10998
10999requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11000requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11001run_test  "DTLS-SRTP server supports all profiles. Client supports one profile." \
11002          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11003          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=5 debug_level=3" \
11004          0 \
11005          -s "found use_srtp extension" \
11006          -s "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
11007          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
11008          -s "server hello, adding use_srtp extension" \
11009          -s "DTLS-SRTP key material is"\
11010          -c "client hello, adding use_srtp extension" \
11011          -c "found use_srtp extension" \
11012          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
11013          -c "selected srtp profile" \
11014          -c "DTLS-SRTP key material is"\
11015          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11016          -C "error"
11017
11018requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11019requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11020run_test  "DTLS-SRTP server supports one profile. Client supports all profiles." \
11021          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
11022          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11023          0 \
11024          -s "found use_srtp extension" \
11025          -s "found srtp profile" \
11026          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
11027          -s "server hello, adding use_srtp extension" \
11028          -s "DTLS-SRTP key material is"\
11029          -c "client hello, adding use_srtp extension" \
11030          -c "found use_srtp extension" \
11031          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
11032          -c "selected srtp profile" \
11033          -c "DTLS-SRTP key material is"\
11034          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11035          -C "error"
11036
11037requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11038requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11039run_test  "DTLS-SRTP server and Client support only one matching profile." \
11040          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11041          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11042          0 \
11043          -s "found use_srtp extension" \
11044          -s "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11045          -s "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11046          -s "server hello, adding use_srtp extension" \
11047          -s "DTLS-SRTP key material is"\
11048          -c "client hello, adding use_srtp extension" \
11049          -c "found use_srtp extension" \
11050          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11051          -c "selected srtp profile" \
11052          -c "DTLS-SRTP key material is"\
11053          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11054          -C "error"
11055
11056requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11057requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11058run_test  "DTLS-SRTP server and Client support only one different profile." \
11059          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11060          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
11061          0 \
11062          -s "found use_srtp extension" \
11063          -s "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
11064          -S "selected srtp profile" \
11065          -S "server hello, adding use_srtp extension" \
11066          -S "DTLS-SRTP key material is"\
11067          -c "client hello, adding use_srtp extension" \
11068          -C "found use_srtp extension" \
11069          -C "found srtp profile" \
11070          -C "selected srtp profile" \
11071          -C "DTLS-SRTP key material is"\
11072          -C "error"
11073
11074requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11075requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11076run_test  "DTLS-SRTP server doesn't support use_srtp extension." \
11077          "$P_SRV dtls=1 debug_level=3" \
11078          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11079          0 \
11080          -s "found use_srtp extension" \
11081          -S "server hello, adding use_srtp extension" \
11082          -S "DTLS-SRTP key material is"\
11083          -c "client hello, adding use_srtp extension" \
11084          -C "found use_srtp extension" \
11085          -C "found srtp profile" \
11086          -C "selected srtp profile" \
11087          -C "DTLS-SRTP key material is"\
11088          -C "error"
11089
11090requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11091requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11092run_test  "DTLS-SRTP all profiles supported. mki used" \
11093          "$P_SRV dtls=1 use_srtp=1 support_mki=1 debug_level=3" \
11094          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
11095          0 \
11096          -s "found use_srtp extension" \
11097          -s "found srtp profile" \
11098          -s "selected srtp profile" \
11099          -s "server hello, adding use_srtp extension" \
11100          -s "dumping 'using mki' (8 bytes)" \
11101          -s "DTLS-SRTP key material is"\
11102          -c "client hello, adding use_srtp extension" \
11103          -c "found use_srtp extension" \
11104          -c "found srtp profile" \
11105          -c "selected srtp profile" \
11106          -c "dumping 'sending mki' (8 bytes)" \
11107          -c "dumping 'received mki' (8 bytes)" \
11108          -c "DTLS-SRTP key material is"\
11109          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11110          -g "find_in_both '^ *DTLS-SRTP mki value: [0-9A-F]*$'"\
11111          -C "error"
11112
11113requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11114requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11115run_test  "DTLS-SRTP all profiles supported. server doesn't support mki." \
11116          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11117          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
11118          0 \
11119          -s "found use_srtp extension" \
11120          -s "found srtp profile" \
11121          -s "selected srtp profile" \
11122          -s "server hello, adding use_srtp extension" \
11123          -s "DTLS-SRTP key material is"\
11124          -s "DTLS-SRTP no mki value negotiated"\
11125          -S "dumping 'using mki' (8 bytes)" \
11126          -c "client hello, adding use_srtp extension" \
11127          -c "found use_srtp extension" \
11128          -c "found srtp profile" \
11129          -c "selected srtp profile" \
11130          -c "DTLS-SRTP key material is"\
11131          -c "DTLS-SRTP no mki value negotiated"\
11132          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11133          -c "dumping 'sending mki' (8 bytes)" \
11134          -C "dumping 'received mki' (8 bytes)" \
11135          -C "error"
11136
11137requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11138requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11139run_test  "DTLS-SRTP all profiles supported. openssl client." \
11140          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11141          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11142          0 \
11143          -s "found use_srtp extension" \
11144          -s "found srtp profile" \
11145          -s "selected srtp profile" \
11146          -s "server hello, adding use_srtp extension" \
11147          -s "DTLS-SRTP key material is"\
11148          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11149          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_80"
11150
11151requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11152requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11153run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. openssl client." \
11154          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11155          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32:SRTP_AES128_CM_SHA1_80 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11156          0 \
11157          -s "found use_srtp extension" \
11158          -s "found srtp profile" \
11159          -s "selected srtp profile" \
11160          -s "server hello, adding use_srtp extension" \
11161          -s "DTLS-SRTP key material is"\
11162          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11163          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
11164
11165requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11166requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11167run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. openssl client." \
11168          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11169          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11170          0 \
11171          -s "found use_srtp extension" \
11172          -s "found srtp profile" \
11173          -s "selected srtp profile" \
11174          -s "server hello, adding use_srtp extension" \
11175          -s "DTLS-SRTP key material is"\
11176          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11177          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
11178
11179requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11180requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11181run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. openssl client." \
11182          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11183          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11184          0 \
11185          -s "found use_srtp extension" \
11186          -s "found srtp profile" \
11187          -s "selected srtp profile" \
11188          -s "server hello, adding use_srtp extension" \
11189          -s "DTLS-SRTP key material is"\
11190          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11191          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
11192
11193requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11194requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11195run_test  "DTLS-SRTP server and Client support only one matching profile. openssl client." \
11196          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11197          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11198          0 \
11199          -s "found use_srtp extension" \
11200          -s "found srtp profile" \
11201          -s "selected srtp profile" \
11202          -s "server hello, adding use_srtp extension" \
11203          -s "DTLS-SRTP key material is"\
11204          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
11205          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
11206
11207requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11208requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11209run_test  "DTLS-SRTP server and Client support only one different profile. openssl client." \
11210          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=1 debug_level=3" \
11211          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11212          0 \
11213          -s "found use_srtp extension" \
11214          -s "found srtp profile" \
11215          -S "selected srtp profile" \
11216          -S "server hello, adding use_srtp extension" \
11217          -S "DTLS-SRTP key material is"\
11218          -C "SRTP Extension negotiated, profile"
11219
11220requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11221requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11222run_test  "DTLS-SRTP server doesn't support use_srtp extension. openssl client" \
11223          "$P_SRV dtls=1 debug_level=3" \
11224          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11225          0 \
11226          -s "found use_srtp extension" \
11227          -S "server hello, adding use_srtp extension" \
11228          -S "DTLS-SRTP key material is"\
11229          -C "SRTP Extension negotiated, profile"
11230
11231requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11232requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11233run_test  "DTLS-SRTP all profiles supported. openssl server" \
11234          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11235          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11236          0 \
11237          -c "client hello, adding use_srtp extension" \
11238          -c "found use_srtp extension" \
11239          -c "found srtp profile" \
11240          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
11241          -c "DTLS-SRTP key material is"\
11242          -C "error"
11243
11244requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11245requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11246run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. openssl server." \
11247          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32:SRTP_AES128_CM_SHA1_80 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11248          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11249          0 \
11250          -c "client hello, adding use_srtp extension" \
11251          -c "found use_srtp extension" \
11252          -c "found srtp profile" \
11253          -c "selected srtp profile" \
11254          -c "DTLS-SRTP key material is"\
11255          -C "error"
11256
11257requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11258requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11259run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. openssl server." \
11260          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11261          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11262          0 \
11263          -c "client hello, adding use_srtp extension" \
11264          -c "found use_srtp extension" \
11265          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11266          -c "selected srtp profile" \
11267          -c "DTLS-SRTP key material is"\
11268          -C "error"
11269
11270requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11271requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11272run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. openssl server." \
11273          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11274          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11275          0 \
11276          -c "client hello, adding use_srtp extension" \
11277          -c "found use_srtp extension" \
11278          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11279          -c "selected srtp profile" \
11280          -c "DTLS-SRTP key material is"\
11281          -C "error"
11282
11283requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11284requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11285run_test  "DTLS-SRTP server and Client support only one matching profile. openssl server." \
11286          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11287          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11288          0 \
11289          -c "client hello, adding use_srtp extension" \
11290          -c "found use_srtp extension" \
11291          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11292          -c "selected srtp profile" \
11293          -c "DTLS-SRTP key material is"\
11294          -C "error"
11295
11296requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11297requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11298run_test  "DTLS-SRTP server and Client support only one different profile. openssl server." \
11299          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11300          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
11301          0 \
11302          -c "client hello, adding use_srtp extension" \
11303          -C "found use_srtp extension" \
11304          -C "found srtp profile" \
11305          -C "selected srtp profile" \
11306          -C "DTLS-SRTP key material is"\
11307          -C "error"
11308
11309requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11310requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11311run_test  "DTLS-SRTP server doesn't support use_srtp extension. openssl server" \
11312          "$O_SRV -dtls" \
11313          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11314          0 \
11315          -c "client hello, adding use_srtp extension" \
11316          -C "found use_srtp extension" \
11317          -C "found srtp profile" \
11318          -C "selected srtp profile" \
11319          -C "DTLS-SRTP key material is"\
11320          -C "error"
11321
11322requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11323requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11324run_test  "DTLS-SRTP all profiles supported. server doesn't support mki. openssl server." \
11325          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
11326          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
11327          0 \
11328          -c "client hello, adding use_srtp extension" \
11329          -c "found use_srtp extension" \
11330          -c "found srtp profile" \
11331          -c "selected srtp profile" \
11332          -c "DTLS-SRTP key material is"\
11333          -c "DTLS-SRTP no mki value negotiated"\
11334          -c "dumping 'sending mki' (8 bytes)" \
11335          -C "dumping 'received mki' (8 bytes)" \
11336          -C "error"
11337
11338requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11339requires_gnutls
11340requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11341run_test  "DTLS-SRTP all profiles supported. gnutls client." \
11342          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11343          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_80:SRTP_AES128_CM_HMAC_SHA1_32:SRTP_NULL_HMAC_SHA1_80:SRTP_NULL_SHA1_32 --insecure 127.0.0.1" \
11344          0 \
11345          -s "found use_srtp extension" \
11346          -s "found srtp profile" \
11347          -s "selected srtp profile" \
11348          -s "server hello, adding use_srtp extension" \
11349          -s "DTLS-SRTP key material is"\
11350          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_80"
11351
11352requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11353requires_gnutls
11354requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11355run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. gnutls client." \
11356          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11357          "$G_CLI -u --srtp-profiles=SRTP_NULL_HMAC_SHA1_80:SRTP_AES128_CM_HMAC_SHA1_80:SRTP_NULL_SHA1_32:SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
11358          0 \
11359          -s "found use_srtp extension" \
11360          -s "found srtp profile" \
11361          -s "selected srtp profile" \
11362          -s "server hello, adding use_srtp extension" \
11363          -s "DTLS-SRTP key material is"\
11364          -c "SRTP profile: SRTP_NULL_HMAC_SHA1_80"
11365
11366requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11367requires_gnutls
11368requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11369run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. gnutls client." \
11370          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
11371          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
11372          0 \
11373          -s "found use_srtp extension" \
11374          -s "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11375          -s "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11376          -s "server hello, adding use_srtp extension" \
11377          -s "DTLS-SRTP key material is"\
11378          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_32"
11379
11380requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11381requires_gnutls
11382requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11383run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. gnutls client." \
11384          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
11385          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_80:SRTP_AES128_CM_HMAC_SHA1_32:SRTP_NULL_HMAC_SHA1_80:SRTP_NULL_SHA1_32 --insecure 127.0.0.1" \
11386          0 \
11387          -s "found use_srtp extension" \
11388          -s "found srtp profile" \
11389          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
11390          -s "server hello, adding use_srtp extension" \
11391          -s "DTLS-SRTP key material is"\
11392          -c "SRTP profile: SRTP_NULL_SHA1_32"
11393
11394requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11395requires_gnutls
11396requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11397run_test  "DTLS-SRTP server and Client support only one matching profile. gnutls client." \
11398          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11399          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
11400          0 \
11401          -s "found use_srtp extension" \
11402          -s "found srtp profile" \
11403          -s "selected srtp profile" \
11404          -s "server hello, adding use_srtp extension" \
11405          -s "DTLS-SRTP key material is"\
11406          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_32"
11407
11408requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11409requires_gnutls
11410requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11411run_test  "DTLS-SRTP server and Client support only one different profile. gnutls client." \
11412          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=1 debug_level=3" \
11413          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
11414          0 \
11415          -s "found use_srtp extension" \
11416          -s "found srtp profile" \
11417          -S "selected srtp profile" \
11418          -S "server hello, adding use_srtp extension" \
11419          -S "DTLS-SRTP key material is"\
11420          -C "SRTP profile:"
11421
11422requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11423requires_gnutls
11424requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11425run_test  "DTLS-SRTP server doesn't support use_srtp extension. gnutls client" \
11426          "$P_SRV dtls=1 debug_level=3" \
11427          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_80:SRTP_AES128_CM_HMAC_SHA1_32:SRTP_NULL_HMAC_SHA1_80:SRTP_NULL_SHA1_32 --insecure 127.0.0.1" \
11428          0 \
11429          -s "found use_srtp extension" \
11430          -S "server hello, adding use_srtp extension" \
11431          -S "DTLS-SRTP key material is"\
11432          -C "SRTP profile:"
11433
11434requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11435requires_gnutls
11436requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11437run_test  "DTLS-SRTP all profiles supported. gnutls server" \
11438          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_80:SRTP_AES128_CM_HMAC_SHA1_32:SRTP_NULL_HMAC_SHA1_80:SRTP_NULL_SHA1_32" \
11439          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11440          0 \
11441          -c "client hello, adding use_srtp extension" \
11442          -c "found use_srtp extension" \
11443          -c "found srtp profile" \
11444          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
11445          -c "DTLS-SRTP key material is"\
11446          -C "error"
11447
11448requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11449requires_gnutls
11450requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11451run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. gnutls server." \
11452          "$G_SRV -u --srtp-profiles=SRTP_NULL_SHA1_32:SRTP_AES128_CM_HMAC_SHA1_32:SRTP_AES128_CM_HMAC_SHA1_80:SRTP_NULL_HMAC_SHA1_80:SRTP_NULL_SHA1_32" \
11453          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11454          0 \
11455          -c "client hello, adding use_srtp extension" \
11456          -c "found use_srtp extension" \
11457          -c "found srtp profile" \
11458          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
11459          -c "DTLS-SRTP key material is"\
11460          -C "error"
11461
11462requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11463requires_gnutls
11464requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11465run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. gnutls server." \
11466          "$G_SRV -u --srtp-profiles=SRTP_NULL_SHA1_32:SRTP_AES128_CM_HMAC_SHA1_32:SRTP_AES128_CM_HMAC_SHA1_80:SRTP_NULL_HMAC_SHA1_80:SRTP_NULL_SHA1_32" \
11467          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11468          0 \
11469          -c "client hello, adding use_srtp extension" \
11470          -c "found use_srtp extension" \
11471          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11472          -c "selected srtp profile" \
11473          -c "DTLS-SRTP key material is"\
11474          -C "error"
11475
11476requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11477requires_gnutls
11478requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11479run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. gnutls server." \
11480          "$G_SRV -u --srtp-profiles=SRTP_NULL_HMAC_SHA1_80" \
11481          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11482          0 \
11483          -c "client hello, adding use_srtp extension" \
11484          -c "found use_srtp extension" \
11485          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
11486          -c "selected srtp profile" \
11487          -c "DTLS-SRTP key material is"\
11488          -C "error"
11489
11490requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11491requires_gnutls
11492requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11493run_test  "DTLS-SRTP server and Client support only one matching profile. gnutls server." \
11494          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32" \
11495          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
11496          0 \
11497          -c "client hello, adding use_srtp extension" \
11498          -c "found use_srtp extension" \
11499          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
11500          -c "selected srtp profile" \
11501          -c "DTLS-SRTP key material is"\
11502          -C "error"
11503
11504requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11505requires_gnutls
11506requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11507run_test  "DTLS-SRTP server and Client support only one different profile. gnutls server." \
11508          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32" \
11509          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
11510          0 \
11511          -c "client hello, adding use_srtp extension" \
11512          -C "found use_srtp extension" \
11513          -C "found srtp profile" \
11514          -C "selected srtp profile" \
11515          -C "DTLS-SRTP key material is"\
11516          -C "error"
11517
11518requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11519requires_gnutls
11520requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11521run_test  "DTLS-SRTP server doesn't support use_srtp extension. gnutls server" \
11522          "$G_SRV -u" \
11523          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
11524          0 \
11525          -c "client hello, adding use_srtp extension" \
11526          -C "found use_srtp extension" \
11527          -C "found srtp profile" \
11528          -C "selected srtp profile" \
11529          -C "DTLS-SRTP key material is"\
11530          -C "error"
11531
11532requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
11533requires_gnutls
11534requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11535run_test  "DTLS-SRTP all profiles supported. mki used. gnutls server." \
11536          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_80:SRTP_AES128_CM_HMAC_SHA1_32:SRTP_NULL_HMAC_SHA1_80:SRTP_NULL_SHA1_32" \
11537          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
11538          0 \
11539          -c "client hello, adding use_srtp extension" \
11540          -c "found use_srtp extension" \
11541          -c "found srtp profile" \
11542          -c "selected srtp profile" \
11543          -c "DTLS-SRTP key material is"\
11544          -c "DTLS-SRTP mki value:"\
11545          -c "dumping 'sending mki' (8 bytes)" \
11546          -c "dumping 'received mki' (8 bytes)" \
11547          -C "error"
11548
11549# Tests for specific things with "unreliable" UDP connection
11550
11551not_with_valgrind # spurious resend due to timeout
11552requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11553run_test    "DTLS proxy: reference" \
11554            -p "$P_PXY" \
11555            "$P_SRV dtls=1 debug_level=2 hs_timeout=10000-20000" \
11556            "$P_CLI dtls=1 debug_level=2 hs_timeout=10000-20000" \
11557            0 \
11558            -C "replayed record" \
11559            -S "replayed record" \
11560            -C "Buffer record from epoch" \
11561            -S "Buffer record from epoch" \
11562            -C "ssl_buffer_message" \
11563            -S "ssl_buffer_message" \
11564            -C "discarding invalid record" \
11565            -S "discarding invalid record" \
11566            -S "resend" \
11567            -s "Extra-header:" \
11568            -c "HTTP/1.0 200 OK"
11569
11570not_with_valgrind # spurious resend due to timeout
11571requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11572run_test    "DTLS proxy: duplicate every packet" \
11573            -p "$P_PXY duplicate=1" \
11574            "$P_SRV dtls=1 dgram_packing=0 debug_level=2 hs_timeout=10000-20000" \
11575            "$P_CLI dtls=1 dgram_packing=0 debug_level=2 hs_timeout=10000-20000" \
11576            0 \
11577            -c "replayed record" \
11578            -s "replayed record" \
11579            -c "record from another epoch" \
11580            -s "record from another epoch" \
11581            -S "resend" \
11582            -s "Extra-header:" \
11583            -c "HTTP/1.0 200 OK"
11584
11585requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11586run_test    "DTLS proxy: duplicate every packet, server anti-replay off" \
11587            -p "$P_PXY duplicate=1" \
11588            "$P_SRV dtls=1 dgram_packing=0 debug_level=2 anti_replay=0" \
11589            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
11590            0 \
11591            -c "replayed record" \
11592            -S "replayed record" \
11593            -c "record from another epoch" \
11594            -s "record from another epoch" \
11595            -c "resend" \
11596            -s "resend" \
11597            -s "Extra-header:" \
11598            -c "HTTP/1.0 200 OK"
11599
11600requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11601run_test    "DTLS proxy: multiple records in same datagram" \
11602            -p "$P_PXY pack=50" \
11603            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
11604            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
11605            0 \
11606            -c "next record in same datagram" \
11607            -s "next record in same datagram"
11608
11609requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11610run_test    "DTLS proxy: multiple records in same datagram, duplicate every packet" \
11611            -p "$P_PXY pack=50 duplicate=1" \
11612            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
11613            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
11614            0 \
11615            -c "next record in same datagram" \
11616            -s "next record in same datagram"
11617
11618requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11619run_test    "DTLS proxy: inject invalid AD record, default badmac_limit" \
11620            -p "$P_PXY bad_ad=1" \
11621            "$P_SRV dtls=1 dgram_packing=0 debug_level=1" \
11622            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
11623            0 \
11624            -c "discarding invalid record (mac)" \
11625            -s "discarding invalid record (mac)" \
11626            -s "Extra-header:" \
11627            -c "HTTP/1.0 200 OK" \
11628            -S "too many records with bad MAC" \
11629            -S "Verification of the message MAC failed"
11630
11631requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11632run_test    "DTLS proxy: inject invalid AD record, badmac_limit 1" \
11633            -p "$P_PXY bad_ad=1" \
11634            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=1" \
11635            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
11636            1 \
11637            -C "discarding invalid record (mac)" \
11638            -S "discarding invalid record (mac)" \
11639            -S "Extra-header:" \
11640            -C "HTTP/1.0 200 OK" \
11641            -s "too many records with bad MAC" \
11642            -s "Verification of the message MAC failed"
11643
11644requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11645run_test    "DTLS proxy: inject invalid AD record, badmac_limit 2" \
11646            -p "$P_PXY bad_ad=1" \
11647            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=2" \
11648            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
11649            0 \
11650            -c "discarding invalid record (mac)" \
11651            -s "discarding invalid record (mac)" \
11652            -s "Extra-header:" \
11653            -c "HTTP/1.0 200 OK" \
11654            -S "too many records with bad MAC" \
11655            -S "Verification of the message MAC failed"
11656
11657requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11658run_test    "DTLS proxy: inject invalid AD record, badmac_limit 2, exchanges 2"\
11659            -p "$P_PXY bad_ad=1" \
11660            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=2 exchanges=2" \
11661            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100 exchanges=2" \
11662            1 \
11663            -c "discarding invalid record (mac)" \
11664            -s "discarding invalid record (mac)" \
11665            -s "Extra-header:" \
11666            -c "HTTP/1.0 200 OK" \
11667            -s "too many records with bad MAC" \
11668            -s "Verification of the message MAC failed"
11669
11670requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11671run_test    "DTLS proxy: delay ChangeCipherSpec" \
11672            -p "$P_PXY delay_ccs=1" \
11673            "$P_SRV dtls=1 debug_level=1 dgram_packing=0" \
11674            "$P_CLI dtls=1 debug_level=1 dgram_packing=0" \
11675            0 \
11676            -c "record from another epoch" \
11677            -s "record from another epoch" \
11678            -s "Extra-header:" \
11679            -c "HTTP/1.0 200 OK"
11680
11681# Tests for reordering support with DTLS
11682
11683requires_certificate_authentication
11684requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11685run_test    "DTLS reordering: Buffer out-of-order handshake message on client" \
11686            -p "$P_PXY delay_srv=ServerHello" \
11687            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11688            hs_timeout=2500-60000" \
11689            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11690            hs_timeout=2500-60000" \
11691            0 \
11692            -c "Buffering HS message" \
11693            -c "Next handshake message has been buffered - load"\
11694            -S "Buffering HS message" \
11695            -S "Next handshake message has been buffered - load"\
11696            -C "Injecting buffered CCS message" \
11697            -C "Remember CCS message" \
11698            -S "Injecting buffered CCS message" \
11699            -S "Remember CCS message"
11700
11701requires_certificate_authentication
11702requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11703run_test    "DTLS reordering: Buffer out-of-order handshake message fragment on client" \
11704            -p "$P_PXY delay_srv=ServerHello" \
11705            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11706            hs_timeout=2500-60000" \
11707            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11708            hs_timeout=2500-60000" \
11709            0 \
11710            -c "Buffering HS message" \
11711            -c "found fragmented DTLS handshake message"\
11712            -c "Next handshake message 1 not or only partially bufffered" \
11713            -c "Next handshake message has been buffered - load"\
11714            -S "Buffering HS message" \
11715            -S "Next handshake message has been buffered - load"\
11716            -C "Injecting buffered CCS message" \
11717            -C "Remember CCS message" \
11718            -S "Injecting buffered CCS message" \
11719            -S "Remember CCS message"
11720
11721# The client buffers the ServerKeyExchange before receiving the fragmented
11722# Certificate message; at the time of writing, together these are aroudn 1200b
11723# in size, so that the bound below ensures that the certificate can be reassembled
11724# while keeping the ServerKeyExchange.
11725requires_certificate_authentication
11726requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 1300
11727requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11728run_test    "DTLS reordering: Buffer out-of-order hs msg before reassembling next" \
11729            -p "$P_PXY delay_srv=Certificate delay_srv=Certificate" \
11730            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11731            hs_timeout=2500-60000" \
11732            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11733            hs_timeout=2500-60000" \
11734            0 \
11735            -c "Buffering HS message" \
11736            -c "Next handshake message has been buffered - load"\
11737            -C "attempt to make space by freeing buffered messages" \
11738            -S "Buffering HS message" \
11739            -S "Next handshake message has been buffered - load"\
11740            -C "Injecting buffered CCS message" \
11741            -C "Remember CCS message" \
11742            -S "Injecting buffered CCS message" \
11743            -S "Remember CCS message"
11744
11745# The size constraints ensure that the delayed certificate message can't
11746# be reassembled while keeping the ServerKeyExchange message, but it can
11747# when dropping it first.
11748requires_certificate_authentication
11749requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 900
11750requires_config_value_at_most "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 1299
11751requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11752run_test    "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg" \
11753            -p "$P_PXY delay_srv=Certificate delay_srv=Certificate" \
11754            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11755            hs_timeout=2500-60000" \
11756            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11757            hs_timeout=2500-60000" \
11758            0 \
11759            -c "Buffering HS message" \
11760            -c "attempt to make space by freeing buffered future messages" \
11761            -c "Enough space available after freeing buffered HS messages" \
11762            -S "Buffering HS message" \
11763            -S "Next handshake message has been buffered - load"\
11764            -C "Injecting buffered CCS message" \
11765            -C "Remember CCS message" \
11766            -S "Injecting buffered CCS message" \
11767            -S "Remember CCS message"
11768
11769requires_certificate_authentication
11770requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11771run_test    "DTLS reordering: Buffer out-of-order handshake message on server" \
11772            -p "$P_PXY delay_cli=Certificate" \
11773            "$P_SRV dgram_packing=0 auth_mode=required cookies=0 dtls=1 debug_level=2 \
11774            hs_timeout=2500-60000" \
11775            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11776            hs_timeout=2500-60000" \
11777            0 \
11778            -C "Buffering HS message" \
11779            -C "Next handshake message has been buffered - load"\
11780            -s "Buffering HS message" \
11781            -s "Next handshake message has been buffered - load" \
11782            -C "Injecting buffered CCS message" \
11783            -C "Remember CCS message" \
11784            -S "Injecting buffered CCS message" \
11785            -S "Remember CCS message"
11786
11787requires_certificate_authentication
11788requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11789run_test    "DTLS reordering: Buffer out-of-order CCS message on client"\
11790            -p "$P_PXY delay_srv=NewSessionTicket" \
11791            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11792            hs_timeout=2500-60000" \
11793            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11794            hs_timeout=2500-60000" \
11795            0 \
11796            -C "Buffering HS message" \
11797            -C "Next handshake message has been buffered - load"\
11798            -S "Buffering HS message" \
11799            -S "Next handshake message has been buffered - load" \
11800            -c "Injecting buffered CCS message" \
11801            -c "Remember CCS message" \
11802            -S "Injecting buffered CCS message" \
11803            -S "Remember CCS message"
11804
11805requires_certificate_authentication
11806requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11807run_test    "DTLS reordering: Buffer out-of-order CCS message on server"\
11808            -p "$P_PXY delay_cli=ClientKeyExchange" \
11809            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11810            hs_timeout=2500-60000" \
11811            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11812            hs_timeout=2500-60000" \
11813            0 \
11814            -C "Buffering HS message" \
11815            -C "Next handshake message has been buffered - load"\
11816            -S "Buffering HS message" \
11817            -S "Next handshake message has been buffered - load" \
11818            -C "Injecting buffered CCS message" \
11819            -C "Remember CCS message" \
11820            -s "Injecting buffered CCS message" \
11821            -s "Remember CCS message"
11822
11823requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11824run_test    "DTLS reordering: Buffer encrypted Finished message" \
11825            -p "$P_PXY delay_ccs=1" \
11826            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11827            hs_timeout=2500-60000" \
11828            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11829            hs_timeout=2500-60000" \
11830            0 \
11831            -s "Buffer record from epoch 1" \
11832            -s "Found buffered record from current epoch - load" \
11833            -c "Buffer record from epoch 1" \
11834            -c "Found buffered record from current epoch - load"
11835
11836# In this test, both the fragmented NewSessionTicket and the ChangeCipherSpec
11837# from the server are delayed, so that the encrypted Finished message
11838# is received and buffered. When the fragmented NewSessionTicket comes
11839# in afterwards, the encrypted Finished message must be freed in order
11840# to make space for the NewSessionTicket to be reassembled.
11841# This works only in very particular circumstances:
11842# - MBEDTLS_SSL_DTLS_MAX_BUFFERING must be large enough to allow buffering
11843#   of the NewSessionTicket, but small enough to also allow buffering of
11844#   the encrypted Finished message.
11845# - The MTU setting on the server must be so small that the NewSessionTicket
11846#   needs to be fragmented.
11847# - All messages sent by the server must be small enough to be either sent
11848#   without fragmentation or be reassembled within the bounds of
11849#   MBEDTLS_SSL_DTLS_MAX_BUFFERING. Achieve this by testing with a PSK-based
11850#   handshake, omitting CRTs.
11851requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 190
11852requires_config_value_at_most "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 230
11853run_test    "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket" \
11854            -p "$P_PXY delay_srv=NewSessionTicket delay_srv=NewSessionTicket delay_ccs=1" \
11855            "$P_SRV mtu=140 response_size=90 dgram_packing=0 psk=abc123 psk_identity=foo cookies=0 dtls=1 debug_level=2" \
11856            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 psk=abc123 psk_identity=foo" \
11857            0 \
11858            -s "Buffer record from epoch 1" \
11859            -s "Found buffered record from current epoch - load" \
11860            -c "Buffer record from epoch 1" \
11861            -C "Found buffered record from current epoch - load" \
11862            -c "Enough space available after freeing future epoch record"
11863
11864# Tests for "randomly unreliable connection": try a variety of flows and peers
11865
11866client_needs_more_time 2
11867run_test    "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
11868            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11869            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11870             psk=abc123" \
11871            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11872             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11873            0 \
11874            -s "Extra-header:" \
11875            -c "HTTP/1.0 200 OK"
11876
11877client_needs_more_time 2
11878run_test    "DTLS proxy: 3d, \"short\" RSA handshake" \
11879            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11880            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none" \
11881            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 \
11882             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
11883            0 \
11884            -s "Extra-header:" \
11885            -c "HTTP/1.0 200 OK"
11886
11887client_needs_more_time 2
11888requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11889run_test    "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
11890            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11891            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none" \
11892            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0" \
11893            0 \
11894            -s "Extra-header:" \
11895            -c "HTTP/1.0 200 OK"
11896
11897client_needs_more_time 2
11898requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11899run_test    "DTLS proxy: 3d, FS, client auth" \
11900            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11901            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=required" \
11902            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0" \
11903            0 \
11904            -s "Extra-header:" \
11905            -c "HTTP/1.0 200 OK"
11906
11907client_needs_more_time 2
11908requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11909run_test    "DTLS proxy: 3d, FS, ticket" \
11910            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11911            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1 auth_mode=none" \
11912            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1" \
11913            0 \
11914            -s "Extra-header:" \
11915            -c "HTTP/1.0 200 OK"
11916
11917client_needs_more_time 2
11918requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11919run_test    "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
11920            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11921            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1 auth_mode=required" \
11922            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1" \
11923            0 \
11924            -s "Extra-header:" \
11925            -c "HTTP/1.0 200 OK"
11926
11927client_needs_more_time 2
11928requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11929run_test    "DTLS proxy: 3d, max handshake, nbio" \
11930            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11931            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 nbio=2 tickets=1 \
11932             auth_mode=required" \
11933            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 nbio=2 tickets=1" \
11934            0 \
11935            -s "Extra-header:" \
11936            -c "HTTP/1.0 200 OK"
11937
11938client_needs_more_time 4
11939requires_config_enabled MBEDTLS_SSL_CACHE_C
11940run_test    "DTLS proxy: 3d, min handshake, resumption" \
11941            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11942            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11943             psk=abc123 debug_level=3" \
11944            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11945             debug_level=3 reconnect=1 skip_close_notify=1 read_timeout=1000 max_resend=10 \
11946             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11947            0 \
11948            -s "a session has been resumed" \
11949            -c "a session has been resumed" \
11950            -s "Extra-header:" \
11951            -c "HTTP/1.0 200 OK"
11952
11953client_needs_more_time 4
11954requires_config_enabled MBEDTLS_SSL_CACHE_C
11955run_test    "DTLS proxy: 3d, min handshake, resumption, nbio" \
11956            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11957            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11958             psk=abc123 debug_level=3 nbio=2" \
11959            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11960             debug_level=3 reconnect=1 skip_close_notify=1 read_timeout=1000 max_resend=10 \
11961             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
11962            0 \
11963            -s "a session has been resumed" \
11964            -c "a session has been resumed" \
11965            -s "Extra-header:" \
11966            -c "HTTP/1.0 200 OK"
11967
11968client_needs_more_time 4
11969requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11970run_test    "DTLS proxy: 3d, min handshake, client-initiated renego" \
11971            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11972            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11973             psk=abc123 renegotiation=1 debug_level=2" \
11974            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11975             renegotiate=1 debug_level=2 \
11976             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11977            0 \
11978            -c "=> renegotiate" \
11979            -s "=> renegotiate" \
11980            -s "Extra-header:" \
11981            -c "HTTP/1.0 200 OK"
11982
11983client_needs_more_time 4
11984requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11985run_test    "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
11986            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11987            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11988             psk=abc123 renegotiation=1 debug_level=2" \
11989            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11990             renegotiate=1 debug_level=2 \
11991             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11992            0 \
11993            -c "=> renegotiate" \
11994            -s "=> renegotiate" \
11995            -s "Extra-header:" \
11996            -c "HTTP/1.0 200 OK"
11997
11998client_needs_more_time 4
11999requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
12000run_test    "DTLS proxy: 3d, min handshake, server-initiated renego" \
12001            -p "$P_PXY drop=5 delay=5 duplicate=5" \
12002            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
12003             psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
12004             debug_level=2" \
12005            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
12006             renegotiation=1 exchanges=4 debug_level=2 \
12007             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
12008            0 \
12009            -c "=> renegotiate" \
12010            -s "=> renegotiate" \
12011            -s "Extra-header:" \
12012            -c "HTTP/1.0 200 OK"
12013
12014client_needs_more_time 4
12015requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
12016run_test    "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
12017            -p "$P_PXY drop=5 delay=5 duplicate=5" \
12018            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
12019             psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
12020             debug_level=2 nbio=2" \
12021            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
12022             renegotiation=1 exchanges=4 debug_level=2 nbio=2 \
12023             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
12024            0 \
12025            -c "=> renegotiate" \
12026            -s "=> renegotiate" \
12027            -s "Extra-header:" \
12028            -c "HTTP/1.0 200 OK"
12029
12030## The three tests below require 1.1.1a or higher version of openssl, otherwise
12031## it might trigger a bug due to openssl (https://github.com/openssl/openssl/issues/6902)
12032## Besides, openssl should use dtls1_2 or dtls, otherwise it will cause "SSL alert number 70" error
12033requires_openssl_next
12034client_needs_more_time 6
12035not_with_valgrind # risk of non-mbedtls peer timing out
12036requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12037run_test    "DTLS proxy: 3d, openssl server" \
12038            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
12039            "$O_NEXT_SRV -dtls1_2 -mtu 2048" \
12040            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 tickets=0" \
12041            0 \
12042            -c "HTTP/1.0 200 OK"
12043
12044requires_openssl_next
12045client_needs_more_time 8
12046not_with_valgrind # risk of non-mbedtls peer timing out
12047requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12048run_test    "DTLS proxy: 3d, openssl server, fragmentation" \
12049            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
12050            "$O_NEXT_SRV -dtls1_2 -mtu 768" \
12051            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 tickets=0" \
12052            0 \
12053            -c "HTTP/1.0 200 OK"
12054
12055requires_openssl_next
12056client_needs_more_time 8
12057not_with_valgrind # risk of non-mbedtls peer timing out
12058requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12059run_test    "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
12060            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
12061            "$O_NEXT_SRV -dtls1_2 -mtu 768" \
12062            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 nbio=2 tickets=0" \
12063            0 \
12064            -c "HTTP/1.0 200 OK"
12065
12066requires_gnutls
12067client_needs_more_time 6
12068not_with_valgrind # risk of non-mbedtls peer timing out
12069requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12070run_test    "DTLS proxy: 3d, gnutls server" \
12071            -p "$P_PXY drop=5 delay=5 duplicate=5" \
12072            "$G_SRV -u --mtu 2048 -a" \
12073            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000" \
12074            0 \
12075            -s "Extra-header:" \
12076            -c "Extra-header:"
12077
12078requires_gnutls_next
12079client_needs_more_time 8
12080not_with_valgrind # risk of non-mbedtls peer timing out
12081requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12082run_test    "DTLS proxy: 3d, gnutls server, fragmentation" \
12083            -p "$P_PXY drop=5 delay=5 duplicate=5" \
12084            "$G_NEXT_SRV -u --mtu 512" \
12085            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000" \
12086            0 \
12087            -s "Extra-header:" \
12088            -c "Extra-header:"
12089
12090requires_gnutls_next
12091client_needs_more_time 8
12092not_with_valgrind # risk of non-mbedtls peer timing out
12093requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12094run_test    "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
12095            -p "$P_PXY drop=5 delay=5 duplicate=5" \
12096            "$G_NEXT_SRV -u --mtu 512" \
12097            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 nbio=2" \
12098            0 \
12099            -s "Extra-header:" \
12100            -c "Extra-header:"
12101
12102requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12103run_test    "export keys functionality" \
12104            "$P_SRV eap_tls=1 debug_level=3" \
12105            "$P_CLI force_version=tls12 eap_tls=1 debug_level=3" \
12106            0 \
12107            -c "EAP-TLS key material is:"\
12108            -s "EAP-TLS key material is:"\
12109            -c "EAP-TLS IV is:" \
12110            -s "EAP-TLS IV is:"
12111
12112# openssl feature tests: check if tls1.3 exists.
12113requires_openssl_tls1_3
12114run_test    "TLS 1.3: Test openssl tls1_3 feature" \
12115            "$O_NEXT_SRV -tls1_3 -msg" \
12116            "$O_NEXT_CLI -tls1_3 -msg" \
12117            0 \
12118            -c "TLS 1.3" \
12119            -s "TLS 1.3"
12120
12121# gnutls feature tests: check if TLS 1.3 is supported as well as the NO_TICKETS and DISABLE_TLS13_COMPAT_MODE options.
12122requires_gnutls_tls1_3
12123requires_gnutls_next_no_ticket
12124requires_gnutls_next_disable_tls13_compat
12125run_test    "TLS 1.3: Test gnutls tls1_3 feature" \
12126            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert " \
12127            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12128            0 \
12129            -s "Version: TLS1.3" \
12130            -c "Version: TLS1.3"
12131
12132# TLS1.3 test cases
12133requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
12134requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12135requires_ciphersuite_enabled TLS1-3-CHACHA20-POLY1305-SHA256
12136requires_any_configs_enabled "PSA_WANT_ECC_MONTGOMERY_255"
12137requires_any_configs_enabled "PSA_WANT_ECC_SECP_R1_256"
12138run_test    "TLS 1.3: Default" \
12139            "$P_SRV allow_sha1=0 debug_level=3 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13" \
12140            "$P_CLI allow_sha1=0" \
12141            0 \
12142            -s "Protocol is TLSv1.3" \
12143            -s "Ciphersuite is TLS1-3-CHACHA20-POLY1305-SHA256" \
12144            -s "ECDH/FFDH group: " \
12145            -s "selected signature algorithm ecdsa_secp256r1_sha256"
12146
12147requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12148requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
12149requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12150requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
12151run_test    "Establish TLS 1.2 then TLS 1.3 session" \
12152            "$P_SRV" \
12153            "( $P_CLI force_version=tls12; \
12154               $P_CLI force_version=tls13 )" \
12155            0 \
12156            -s "Protocol is TLSv1.2" \
12157            -s "Protocol is TLSv1.3" \
12158
12159requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
12160requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
12161requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12162requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
12163run_test    "Establish TLS 1.3 then TLS 1.2 session" \
12164            "$P_SRV" \
12165            "( $P_CLI force_version=tls13; \
12166               $P_CLI force_version=tls12 )" \
12167            0 \
12168            -s "Protocol is TLSv1.3" \
12169            -s "Protocol is TLSv1.2" \
12170
12171requires_openssl_tls1_3_with_compatible_ephemeral
12172requires_config_enabled MBEDTLS_DEBUG_C
12173requires_config_enabled MBEDTLS_SSL_CLI_C
12174requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12175                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12176run_test    "TLS 1.3: minimal feature sets - openssl" \
12177            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12178            "$P_CLI debug_level=3" \
12179            0 \
12180            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
12181            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
12182            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12183            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12184            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12185            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12186            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
12187            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
12188            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
12189            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12190            -c "<= ssl_tls13_process_server_hello" \
12191            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
12192            -c "DHE group name: " \
12193            -c "=> ssl_tls13_process_server_hello" \
12194            -c "<= parse encrypted extensions" \
12195            -c "Certificate verification flags clear" \
12196            -c "=> parse certificate verify" \
12197            -c "<= parse certificate verify" \
12198            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
12199            -c "<= parse finished message" \
12200            -c "Protocol is TLSv1.3" \
12201            -c "HTTP/1.0 200 ok"
12202
12203requires_gnutls_tls1_3
12204requires_gnutls_next_no_ticket
12205requires_config_enabled MBEDTLS_DEBUG_C
12206requires_config_enabled MBEDTLS_SSL_CLI_C
12207requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12208                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12209run_test    "TLS 1.3: minimal feature sets - gnutls" \
12210            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
12211            "$P_CLI debug_level=3" \
12212            0 \
12213            -s "SERVER HELLO was queued" \
12214            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
12215            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
12216            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12217            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12218            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12219            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12220            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
12221            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
12222            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
12223            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12224            -c "<= ssl_tls13_process_server_hello" \
12225            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
12226            -c "DHE group name: " \
12227            -c "=> ssl_tls13_process_server_hello" \
12228            -c "<= parse encrypted extensions" \
12229            -c "Certificate verification flags clear" \
12230            -c "=> parse certificate verify" \
12231            -c "<= parse certificate verify" \
12232            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
12233            -c "<= parse finished message" \
12234            -c "Protocol is TLSv1.3" \
12235            -c "HTTP/1.0 200 OK"
12236
12237requires_openssl_tls1_3_with_compatible_ephemeral
12238requires_config_enabled MBEDTLS_DEBUG_C
12239requires_config_enabled MBEDTLS_SSL_CLI_C
12240requires_config_enabled MBEDTLS_SSL_ALPN
12241requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12242                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12243run_test    "TLS 1.3: alpn - openssl" \
12244            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -alpn h2" \
12245            "$P_CLI debug_level=3 alpn=h2" \
12246            0 \
12247            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
12248            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
12249            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12250            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12251            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12252            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12253            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
12254            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
12255            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
12256            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12257            -c "<= ssl_tls13_process_server_hello" \
12258            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
12259            -c "DHE group name: " \
12260            -c "=> ssl_tls13_process_server_hello" \
12261            -c "<= parse encrypted extensions" \
12262            -c "Certificate verification flags clear" \
12263            -c "=> parse certificate verify" \
12264            -c "<= parse certificate verify" \
12265            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
12266            -c "<= parse finished message" \
12267            -c "Protocol is TLSv1.3" \
12268            -c "HTTP/1.0 200 ok" \
12269            -c "Application Layer Protocol is h2"
12270
12271requires_gnutls_tls1_3
12272requires_gnutls_next_no_ticket
12273requires_config_enabled MBEDTLS_DEBUG_C
12274requires_config_enabled MBEDTLS_SSL_CLI_C
12275requires_config_enabled MBEDTLS_SSL_ALPN
12276requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12277                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12278run_test    "TLS 1.3: alpn - gnutls" \
12279            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert --alpn=h2" \
12280            "$P_CLI debug_level=3 alpn=h2" \
12281            0 \
12282            -s "SERVER HELLO was queued" \
12283            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
12284            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
12285            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12286            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12287            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12288            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12289            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
12290            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
12291            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
12292            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12293            -c "<= ssl_tls13_process_server_hello" \
12294            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
12295            -c "DHE group name: " \
12296            -c "=> ssl_tls13_process_server_hello" \
12297            -c "<= parse encrypted extensions" \
12298            -c "Certificate verification flags clear" \
12299            -c "=> parse certificate verify" \
12300            -c "<= parse certificate verify" \
12301            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
12302            -c "<= parse finished message" \
12303            -c "Protocol is TLSv1.3" \
12304            -c "HTTP/1.0 200 OK" \
12305            -c "Application Layer Protocol is h2"
12306
12307requires_openssl_tls1_3_with_compatible_ephemeral
12308requires_config_enabled MBEDTLS_DEBUG_C
12309requires_config_enabled MBEDTLS_SSL_SRV_C
12310requires_config_enabled MBEDTLS_SSL_ALPN
12311requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12312run_test    "TLS 1.3: server alpn - openssl" \
12313            "$P_SRV debug_level=3 tickets=0 crt_file=data_files/server5.crt key_file=data_files/server5.key alpn=h2" \
12314            "$O_NEXT_CLI -msg -tls1_3 -no_middlebox -alpn h2" \
12315            0 \
12316            -s "found alpn extension" \
12317            -s "server side, adding alpn extension" \
12318            -s "Protocol is TLSv1.3" \
12319            -s "HTTP/1.0 200 OK" \
12320            -s "Application Layer Protocol is h2"
12321
12322requires_gnutls_tls1_3
12323requires_config_enabled MBEDTLS_DEBUG_C
12324requires_config_enabled MBEDTLS_SSL_SRV_C
12325requires_config_enabled MBEDTLS_SSL_ALPN
12326requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12327run_test    "TLS 1.3: server alpn - gnutls" \
12328            "$P_SRV debug_level=3 tickets=0 crt_file=data_files/server5.crt key_file=data_files/server5.key alpn=h2" \
12329            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V --alpn h2" \
12330            0 \
12331            -s "found alpn extension" \
12332            -s "server side, adding alpn extension" \
12333            -s "Protocol is TLSv1.3" \
12334            -s "HTTP/1.0 200 OK" \
12335            -s "Application Layer Protocol is h2"
12336
12337requires_openssl_tls1_3_with_compatible_ephemeral
12338requires_config_enabled MBEDTLS_DEBUG_C
12339requires_config_enabled MBEDTLS_SSL_CLI_C
12340requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12341                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12342run_test    "TLS 1.3: Client authentication, no client certificate - openssl" \
12343            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -verify 10" \
12344            "$P_CLI debug_level=4 crt_file=none key_file=none" \
12345            0 \
12346            -c "got a certificate request" \
12347            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12348            -s "TLS 1.3" \
12349            -c "HTTP/1.0 200 ok" \
12350            -c "Protocol is TLSv1.3"
12351
12352requires_gnutls_tls1_3
12353requires_gnutls_next_no_ticket
12354requires_config_enabled MBEDTLS_DEBUG_C
12355requires_config_enabled MBEDTLS_SSL_CLI_C
12356requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12357                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12358run_test    "TLS 1.3: Client authentication, no client certificate - gnutls" \
12359            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --verify-client-cert" \
12360            "$P_CLI debug_level=3 crt_file=none key_file=none" \
12361            0 \
12362            -c "got a certificate request" \
12363            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE"\
12364            -s "Version: TLS1.3" \
12365            -c "HTTP/1.0 200 OK" \
12366            -c "Protocol is TLSv1.3"
12367
12368
12369requires_openssl_tls1_3_with_compatible_ephemeral
12370requires_config_enabled MBEDTLS_DEBUG_C
12371requires_config_enabled MBEDTLS_SSL_CLI_C
12372requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12373run_test    "TLS 1.3: Client authentication, no server middlebox compat - openssl" \
12374            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10 -no_middlebox" \
12375            "$P_CLI debug_level=4 crt_file=data_files/cli2.crt key_file=data_files/cli2.key" \
12376            0 \
12377            -c "got a certificate request" \
12378            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12379            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12380            -c "Protocol is TLSv1.3"
12381
12382requires_gnutls_tls1_3
12383requires_gnutls_next_no_ticket
12384requires_config_enabled MBEDTLS_DEBUG_C
12385requires_config_enabled MBEDTLS_SSL_CLI_C
12386requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12387run_test    "TLS 1.3: Client authentication, no server middlebox compat - gnutls" \
12388            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE" \
12389            "$P_CLI debug_level=3 crt_file=data_files/cli2.crt \
12390                    key_file=data_files/cli2.key" \
12391            0 \
12392            -c "got a certificate request" \
12393            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12394            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12395            -c "Protocol is TLSv1.3"
12396
12397requires_openssl_tls1_3_with_compatible_ephemeral
12398requires_config_enabled MBEDTLS_DEBUG_C
12399requires_config_enabled MBEDTLS_SSL_CLI_C
12400requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12401                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12402run_test    "TLS 1.3: Client authentication, ecdsa_secp256r1_sha256 - openssl" \
12403            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12404            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp256r1.crt \
12405                    key_file=data_files/ecdsa_secp256r1.key" \
12406            0 \
12407            -c "got a certificate request" \
12408            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12409            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12410            -c "Protocol is TLSv1.3"
12411
12412requires_gnutls_tls1_3
12413requires_gnutls_next_no_ticket
12414requires_config_enabled MBEDTLS_DEBUG_C
12415requires_config_enabled MBEDTLS_SSL_CLI_C
12416requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12417                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12418run_test    "TLS 1.3: Client authentication, ecdsa_secp256r1_sha256 - gnutls" \
12419            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12420            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp256r1.crt \
12421                    key_file=data_files/ecdsa_secp256r1.key" \
12422            0 \
12423            -c "got a certificate request" \
12424            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12425            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12426            -c "Protocol is TLSv1.3"
12427
12428requires_openssl_tls1_3_with_compatible_ephemeral
12429requires_config_enabled MBEDTLS_DEBUG_C
12430requires_config_enabled MBEDTLS_SSL_CLI_C
12431requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12432                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12433run_test    "TLS 1.3: Client authentication, ecdsa_secp384r1_sha384 - openssl" \
12434            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12435            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp384r1.crt \
12436                    key_file=data_files/ecdsa_secp384r1.key" \
12437            0 \
12438            -c "got a certificate request" \
12439            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12440            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12441            -c "Protocol is TLSv1.3"
12442
12443requires_gnutls_tls1_3
12444requires_gnutls_next_no_ticket
12445requires_config_enabled MBEDTLS_DEBUG_C
12446requires_config_enabled MBEDTLS_SSL_CLI_C
12447requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12448                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12449run_test    "TLS 1.3: Client authentication, ecdsa_secp384r1_sha384 - gnutls" \
12450            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12451            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp384r1.crt \
12452                    key_file=data_files/ecdsa_secp384r1.key" \
12453            0 \
12454            -c "got a certificate request" \
12455            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12456            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12457            -c "Protocol is TLSv1.3"
12458
12459requires_openssl_tls1_3_with_compatible_ephemeral
12460requires_config_enabled MBEDTLS_DEBUG_C
12461requires_config_enabled MBEDTLS_SSL_CLI_C
12462requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12463                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12464run_test    "TLS 1.3: Client authentication, ecdsa_secp521r1_sha512 - openssl" \
12465            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12466            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp521r1.crt \
12467                    key_file=data_files/ecdsa_secp521r1.key" \
12468            0 \
12469            -c "got a certificate request" \
12470            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12471            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12472            -c "Protocol is TLSv1.3"
12473
12474requires_gnutls_tls1_3
12475requires_gnutls_next_no_ticket
12476requires_config_enabled MBEDTLS_DEBUG_C
12477requires_config_enabled MBEDTLS_SSL_CLI_C
12478requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12479                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12480run_test    "TLS 1.3: Client authentication, ecdsa_secp521r1_sha512 - gnutls" \
12481            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12482            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12483                    key_file=data_files/ecdsa_secp521r1.key" \
12484            0 \
12485            -c "got a certificate request" \
12486            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12487            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12488            -c "Protocol is TLSv1.3"
12489
12490requires_openssl_tls1_3_with_compatible_ephemeral
12491requires_config_enabled MBEDTLS_DEBUG_C
12492requires_config_enabled MBEDTLS_SSL_CLI_C
12493requires_config_enabled MBEDTLS_RSA_C
12494requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12495                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12496run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha256 - openssl" \
12497            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12498            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
12499                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256" \
12500            0 \
12501            -c "got a certificate request" \
12502            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12503            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12504            -c "Protocol is TLSv1.3"
12505
12506requires_gnutls_tls1_3
12507requires_gnutls_next_no_ticket
12508requires_config_enabled MBEDTLS_DEBUG_C
12509requires_config_enabled MBEDTLS_SSL_CLI_C
12510requires_config_enabled MBEDTLS_RSA_C
12511requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12512                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12513run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha256 - gnutls" \
12514            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12515            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
12516                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256" \
12517            0 \
12518            -c "got a certificate request" \
12519            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12520            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12521            -c "Protocol is TLSv1.3"
12522
12523requires_openssl_tls1_3_with_compatible_ephemeral
12524requires_config_enabled MBEDTLS_DEBUG_C
12525requires_config_enabled MBEDTLS_SSL_CLI_C
12526requires_config_enabled MBEDTLS_RSA_C
12527requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12528                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12529run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha384 - openssl" \
12530            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12531            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
12532                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384" \
12533            0 \
12534            -c "got a certificate request" \
12535            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12536            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12537            -c "Protocol is TLSv1.3"
12538
12539requires_gnutls_tls1_3
12540requires_gnutls_next_no_ticket
12541requires_config_enabled MBEDTLS_DEBUG_C
12542requires_config_enabled MBEDTLS_SSL_CLI_C
12543requires_config_enabled MBEDTLS_RSA_C
12544requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12545                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12546run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha384 - gnutls" \
12547            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12548            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
12549                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384" \
12550            0 \
12551            -c "got a certificate request" \
12552            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12553            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12554            -c "Protocol is TLSv1.3"
12555
12556requires_openssl_tls1_3_with_compatible_ephemeral
12557requires_config_enabled MBEDTLS_DEBUG_C
12558requires_config_enabled MBEDTLS_SSL_CLI_C
12559requires_config_enabled MBEDTLS_RSA_C
12560requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12561                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12562run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha512 - openssl" \
12563            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12564            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
12565                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512" \
12566            0 \
12567            -c "got a certificate request" \
12568            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12569            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12570            -c "Protocol is TLSv1.3"
12571
12572requires_gnutls_tls1_3
12573requires_gnutls_next_no_ticket
12574requires_config_enabled MBEDTLS_DEBUG_C
12575requires_config_enabled MBEDTLS_SSL_CLI_C
12576requires_config_enabled MBEDTLS_RSA_C
12577requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12578                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12579run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha512 - gnutls" \
12580            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12581            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
12582                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512" \
12583            0 \
12584            -c "got a certificate request" \
12585            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12586            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12587            -c "Protocol is TLSv1.3"
12588
12589requires_openssl_tls1_3_with_compatible_ephemeral
12590requires_config_enabled MBEDTLS_DEBUG_C
12591requires_config_enabled MBEDTLS_SSL_CLI_C
12592requires_config_enabled MBEDTLS_RSA_C
12593requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12594                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12595run_test    "TLS 1.3: Client authentication, client alg not in server list - openssl" \
12596            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10
12597                -sigalgs ecdsa_secp256r1_sha256" \
12598            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12599                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512" \
12600            1 \
12601            -c "got a certificate request" \
12602            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12603            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12604            -c "no suitable signature algorithm"
12605
12606requires_gnutls_tls1_3
12607requires_gnutls_next_no_ticket
12608requires_config_enabled MBEDTLS_DEBUG_C
12609requires_config_enabled MBEDTLS_SSL_CLI_C
12610requires_config_enabled MBEDTLS_RSA_C
12611requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12612                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12613run_test    "TLS 1.3: Client authentication, client alg not in server list - gnutls" \
12614            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:-SIGN-ALL:+SIGN-ECDSA-SECP256R1-SHA256:%NO_TICKETS" \
12615            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12616                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512" \
12617            1 \
12618            -c "got a certificate request" \
12619            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12620            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12621            -c "no suitable signature algorithm"
12622
12623# Test using an opaque private key for client authentication
12624requires_openssl_tls1_3_with_compatible_ephemeral
12625requires_config_enabled MBEDTLS_DEBUG_C
12626requires_config_enabled MBEDTLS_SSL_CLI_C
12627requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12628requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12629run_test    "TLS 1.3: Client authentication - opaque key, no server middlebox compat - openssl" \
12630            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10 -no_middlebox" \
12631            "$P_CLI debug_level=4 crt_file=data_files/cli2.crt key_file=data_files/cli2.key key_opaque=1" \
12632            0 \
12633            -c "got a certificate request" \
12634            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12635            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12636            -c "Protocol is TLSv1.3"
12637
12638requires_gnutls_tls1_3
12639requires_gnutls_next_no_ticket
12640requires_config_enabled MBEDTLS_DEBUG_C
12641requires_config_enabled MBEDTLS_SSL_CLI_C
12642requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12643requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12644run_test    "TLS 1.3: Client authentication - opaque key, no server middlebox compat - gnutls" \
12645            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE" \
12646            "$P_CLI debug_level=3 crt_file=data_files/cli2.crt \
12647                    key_file=data_files/cli2.key key_opaque=1" \
12648            0 \
12649            -c "got a certificate request" \
12650            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12651            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12652            -c "Protocol is TLSv1.3"
12653
12654requires_openssl_tls1_3_with_compatible_ephemeral
12655requires_config_enabled MBEDTLS_DEBUG_C
12656requires_config_enabled MBEDTLS_SSL_CLI_C
12657requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12658requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12659                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12660run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp256r1_sha256 - openssl" \
12661            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12662            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp256r1.crt \
12663                    key_file=data_files/ecdsa_secp256r1.key key_opaque=1" \
12664            0 \
12665            -c "got a certificate request" \
12666            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12667            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12668            -c "Protocol is TLSv1.3"
12669
12670requires_gnutls_tls1_3
12671requires_gnutls_next_no_ticket
12672requires_config_enabled MBEDTLS_DEBUG_C
12673requires_config_enabled MBEDTLS_SSL_CLI_C
12674requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12675requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12676                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12677run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp256r1_sha256 - gnutls" \
12678            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12679            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp256r1.crt \
12680                    key_file=data_files/ecdsa_secp256r1.key key_opaque=1" \
12681            0 \
12682            -c "got a certificate request" \
12683            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12684            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12685            -c "Protocol is TLSv1.3"
12686
12687requires_openssl_tls1_3_with_compatible_ephemeral
12688requires_config_enabled MBEDTLS_DEBUG_C
12689requires_config_enabled MBEDTLS_SSL_CLI_C
12690requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12691requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12692                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12693run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp384r1_sha384 - openssl" \
12694            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12695            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp384r1.crt \
12696                    key_file=data_files/ecdsa_secp384r1.key key_opaque=1" \
12697            0 \
12698            -c "got a certificate request" \
12699            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12700            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12701            -c "Protocol is TLSv1.3"
12702
12703requires_gnutls_tls1_3
12704requires_gnutls_next_no_ticket
12705requires_config_enabled MBEDTLS_DEBUG_C
12706requires_config_enabled MBEDTLS_SSL_CLI_C
12707requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12708requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12709                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12710run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp384r1_sha384 - gnutls" \
12711            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12712            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp384r1.crt \
12713                    key_file=data_files/ecdsa_secp384r1.key key_opaque=1" \
12714            0 \
12715            -c "got a certificate request" \
12716            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12717            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12718            -c "Protocol is TLSv1.3"
12719
12720requires_openssl_tls1_3_with_compatible_ephemeral
12721requires_config_enabled MBEDTLS_DEBUG_C
12722requires_config_enabled MBEDTLS_SSL_CLI_C
12723requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12724requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12725                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12726run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp521r1_sha512 - openssl" \
12727            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12728            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp521r1.crt \
12729                    key_file=data_files/ecdsa_secp521r1.key key_opaque=1" \
12730            0 \
12731            -c "got a certificate request" \
12732            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12733            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12734            -c "Protocol is TLSv1.3"
12735
12736requires_gnutls_tls1_3
12737requires_gnutls_next_no_ticket
12738requires_config_enabled MBEDTLS_DEBUG_C
12739requires_config_enabled MBEDTLS_SSL_CLI_C
12740requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12741requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12742                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12743run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp521r1_sha512 - gnutls" \
12744            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12745            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12746                    key_file=data_files/ecdsa_secp521r1.key key_opaque=1" \
12747            0 \
12748            -c "got a certificate request" \
12749            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12750            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12751            -c "Protocol is TLSv1.3"
12752
12753requires_openssl_tls1_3_with_compatible_ephemeral
12754requires_config_enabled MBEDTLS_DEBUG_C
12755requires_config_enabled MBEDTLS_SSL_CLI_C
12756requires_config_enabled MBEDTLS_RSA_C
12757requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12758requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12759                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12760run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha256 - openssl" \
12761            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12762            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
12763                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256 key_opaque=1" \
12764            0 \
12765            -c "got a certificate request" \
12766            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12767            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12768            -c "Protocol is TLSv1.3"
12769
12770requires_gnutls_tls1_3
12771requires_gnutls_next_no_ticket
12772requires_config_enabled MBEDTLS_DEBUG_C
12773requires_config_enabled MBEDTLS_SSL_CLI_C
12774requires_config_enabled MBEDTLS_RSA_C
12775requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12776requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12777                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12778run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha256 - gnutls" \
12779            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12780            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
12781                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256 key_opaque=1" \
12782            0 \
12783            -c "got a certificate request" \
12784            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12785            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12786            -c "Protocol is TLSv1.3"
12787
12788requires_openssl_tls1_3_with_compatible_ephemeral
12789requires_config_enabled MBEDTLS_DEBUG_C
12790requires_config_enabled MBEDTLS_SSL_CLI_C
12791requires_config_enabled MBEDTLS_RSA_C
12792requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12793requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12794                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12795run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha384 - openssl" \
12796            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12797            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
12798                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384 key_opaque=1" \
12799            0 \
12800            -c "got a certificate request" \
12801            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12802            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12803            -c "Protocol is TLSv1.3"
12804
12805requires_gnutls_tls1_3
12806requires_gnutls_next_no_ticket
12807requires_config_enabled MBEDTLS_DEBUG_C
12808requires_config_enabled MBEDTLS_SSL_CLI_C
12809requires_config_enabled MBEDTLS_RSA_C
12810requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12811requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12812                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12813run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha384 - gnutls" \
12814            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12815            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
12816                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384 key_opaque=1" \
12817            0 \
12818            -c "got a certificate request" \
12819            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12820            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12821            -c "Protocol is TLSv1.3"
12822
12823requires_openssl_tls1_3_with_compatible_ephemeral
12824requires_config_enabled MBEDTLS_DEBUG_C
12825requires_config_enabled MBEDTLS_SSL_CLI_C
12826requires_config_enabled MBEDTLS_RSA_C
12827requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12828requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12829                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12830run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha512 - openssl" \
12831            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12832            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
12833                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512 key_opaque=1" \
12834            0 \
12835            -c "got a certificate request" \
12836            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12837            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12838            -c "Protocol is TLSv1.3"
12839
12840requires_gnutls_tls1_3
12841requires_gnutls_next_no_ticket
12842requires_config_enabled MBEDTLS_DEBUG_C
12843requires_config_enabled MBEDTLS_SSL_CLI_C
12844requires_config_enabled MBEDTLS_RSA_C
12845requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12846requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12847                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12848run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha512 - gnutls" \
12849            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12850            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
12851                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512 key_opaque=1" \
12852            0 \
12853            -c "got a certificate request" \
12854            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12855            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12856            -c "Protocol is TLSv1.3"
12857
12858requires_openssl_tls1_3_with_compatible_ephemeral
12859requires_config_enabled MBEDTLS_DEBUG_C
12860requires_config_enabled MBEDTLS_SSL_CLI_C
12861requires_config_enabled MBEDTLS_RSA_C
12862requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12863requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12864                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12865run_test    "TLS 1.3: Client authentication - opaque key, client alg not in server list - openssl" \
12866            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10
12867                -sigalgs ecdsa_secp256r1_sha256" \
12868            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12869                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512 key_opaque=1" \
12870            1 \
12871            -c "got a certificate request" \
12872            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12873            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12874            -c "no suitable signature algorithm"
12875
12876requires_gnutls_tls1_3
12877requires_gnutls_next_no_ticket
12878requires_config_enabled MBEDTLS_DEBUG_C
12879requires_config_enabled MBEDTLS_SSL_CLI_C
12880requires_config_enabled MBEDTLS_RSA_C
12881requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12882requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12883                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12884run_test    "TLS 1.3: Client authentication - opaque key, client alg not in server list - gnutls" \
12885            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:-SIGN-ALL:+SIGN-ECDSA-SECP256R1-SHA256:%NO_TICKETS" \
12886            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12887                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512 key_opaque=1" \
12888            1 \
12889            -c "got a certificate request" \
12890            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12891            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12892            -c "no suitable signature algorithm"
12893
12894requires_openssl_tls1_3_with_compatible_ephemeral
12895requires_config_enabled MBEDTLS_DEBUG_C
12896requires_config_enabled MBEDTLS_SSL_CLI_C
12897requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12898                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12899run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_128_GCM_SHA256 - openssl" \
12900            "$O_NEXT_SRV -ciphersuites TLS_AES_128_GCM_SHA256  -sigalgs ecdsa_secp256r1_sha256 -groups P-256 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12901            "$P_CLI debug_level=4" \
12902            0 \
12903            -c "received HelloRetryRequest message" \
12904            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12905            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12906            -c "Protocol is TLSv1.3" \
12907            -c "HTTP/1.0 200 ok"
12908
12909requires_openssl_tls1_3_with_compatible_ephemeral
12910requires_config_enabled MBEDTLS_DEBUG_C
12911requires_config_enabled MBEDTLS_SSL_CLI_C
12912requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12913                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12914run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_256_GCM_SHA384 - openssl" \
12915            "$O_NEXT_SRV -ciphersuites TLS_AES_256_GCM_SHA384  -sigalgs ecdsa_secp256r1_sha256 -groups P-256 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12916            "$P_CLI debug_level=4" \
12917            0 \
12918            -c "received HelloRetryRequest message" \
12919            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12920            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12921            -c "Protocol is TLSv1.3" \
12922            -c "HTTP/1.0 200 ok"
12923
12924requires_gnutls_tls1_3
12925requires_gnutls_next_no_ticket
12926requires_config_enabled MBEDTLS_DEBUG_C
12927requires_config_enabled MBEDTLS_SSL_CLI_C
12928requires_config_enabled PSA_WANT_ALG_ECDH
12929requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12930                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12931run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_128_GCM_SHA256 - gnutls" \
12932            "$G_NEXT_SRV -d 4 --priority=NONE:+GROUP-SECP256R1:+AES-128-GCM:+SHA256:+AEAD:+SIGN-ECDSA-SECP256R1-SHA256:+VERS-TLS1.3:%NO_TICKETS --disable-client-cert" \
12933            "$P_CLI debug_level=4" \
12934            0 \
12935            -c "received HelloRetryRequest message" \
12936            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12937            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12938            -c "Protocol is TLSv1.3" \
12939            -c "HTTP/1.0 200 OK"
12940
12941requires_gnutls_tls1_3
12942requires_gnutls_next_no_ticket
12943requires_config_enabled MBEDTLS_DEBUG_C
12944requires_config_enabled MBEDTLS_SSL_CLI_C
12945requires_config_enabled PSA_WANT_ALG_ECDH
12946requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12947                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12948run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_256_GCM_SHA384 - gnutls" \
12949            "$G_NEXT_SRV -d 4 --priority=NONE:+GROUP-SECP256R1:+AES-256-GCM:+SHA384:+AEAD:+SIGN-ECDSA-SECP256R1-SHA256:+VERS-TLS1.3:%NO_TICKETS --disable-client-cert" \
12950            "$P_CLI debug_level=4" \
12951            0 \
12952            -c "received HelloRetryRequest message" \
12953            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12954            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12955            -c "Protocol is TLSv1.3" \
12956            -c "HTTP/1.0 200 OK"
12957
12958requires_openssl_tls1_3_with_compatible_ephemeral
12959requires_config_enabled MBEDTLS_DEBUG_C
12960requires_config_enabled MBEDTLS_SSL_SRV_C
12961requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12962run_test    "TLS 1.3: Server side check - openssl" \
12963            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
12964            "$O_NEXT_CLI -msg -debug -tls1_3 -no_middlebox" \
12965            0 \
12966            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12967            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12968            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12969            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12970            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12971            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12972            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
12973            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP"
12974
12975requires_openssl_tls1_3_with_compatible_ephemeral
12976requires_config_enabled MBEDTLS_DEBUG_C
12977requires_config_enabled MBEDTLS_SSL_SRV_C
12978requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12979run_test    "TLS 1.3: Server side check - openssl with client authentication" \
12980            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
12981            "$O_NEXT_CLI -msg -debug -cert data_files/server5.crt -key data_files/server5.key -tls1_3 -no_middlebox" \
12982            0 \
12983            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12984            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12985            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12986            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12987            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12988            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12989            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12990            -s "=> write certificate request" \
12991            -s "=> parse client hello" \
12992            -s "<= parse client hello"
12993
12994requires_gnutls_tls1_3
12995requires_gnutls_next_no_ticket
12996requires_config_enabled MBEDTLS_DEBUG_C
12997requires_config_enabled MBEDTLS_SSL_SRV_C
12998requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12999run_test    "TLS 1.3: Server side check - gnutls" \
13000            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13001            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13002            0 \
13003            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
13004            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
13005            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13006            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
13007            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
13008            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
13009            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
13010            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
13011            -c "HTTP/1.0 200 OK"
13012
13013requires_gnutls_tls1_3
13014requires_gnutls_next_no_ticket
13015requires_config_enabled MBEDTLS_DEBUG_C
13016requires_config_enabled MBEDTLS_SSL_SRV_C
13017requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13018run_test    "TLS 1.3: Server side check - gnutls with client authentication" \
13019            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13020            "$G_NEXT_CLI localhost -d 4 --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13021            0 \
13022            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
13023            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
13024            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13025            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
13026            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
13027            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
13028            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
13029            -s "=> write certificate request" \
13030            -s "=> parse client hello" \
13031            -s "<= parse client hello"
13032
13033requires_config_enabled MBEDTLS_DEBUG_C
13034requires_config_enabled MBEDTLS_SSL_SRV_C
13035requires_config_enabled MBEDTLS_SSL_CLI_C
13036requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13037run_test    "TLS 1.3: Server side check - mbedtls" \
13038            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13039            "$P_CLI debug_level=4" \
13040            0 \
13041            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
13042            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
13043            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13044            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
13045            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
13046            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
13047            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
13048            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
13049            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
13050            -c "HTTP/1.0 200 OK"
13051
13052requires_config_enabled MBEDTLS_DEBUG_C
13053requires_config_enabled MBEDTLS_SSL_SRV_C
13054requires_config_enabled MBEDTLS_SSL_CLI_C
13055requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13056run_test    "TLS 1.3: Server side check - mbedtls with client authentication" \
13057            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13058            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key" \
13059            0 \
13060            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
13061            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
13062            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13063            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
13064            -s "=> write certificate request" \
13065            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
13066            -s "=> parse client hello" \
13067            -s "<= parse client hello"
13068
13069requires_config_enabled MBEDTLS_DEBUG_C
13070requires_config_enabled MBEDTLS_SSL_SRV_C
13071requires_config_enabled MBEDTLS_SSL_CLI_C
13072requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13073run_test    "TLS 1.3: Server side check - mbedtls with client empty certificate" \
13074            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13075            "$P_CLI debug_level=4 crt_file=none key_file=none" \
13076            1 \
13077            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
13078            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
13079            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13080            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
13081            -s "=> write certificate request" \
13082            -s "SSL - No client certification received from the client, but required by the authentication mode" \
13083            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
13084            -s "=> parse client hello" \
13085            -s "<= parse client hello"
13086
13087requires_config_enabled MBEDTLS_DEBUG_C
13088requires_config_enabled MBEDTLS_SSL_SRV_C
13089requires_config_enabled MBEDTLS_SSL_CLI_C
13090requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13091run_test    "TLS 1.3: Server side check - mbedtls with optional client authentication" \
13092            "$P_SRV debug_level=4 auth_mode=optional crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13093            "$P_CLI debug_level=4 crt_file=none key_file=none" \
13094            0 \
13095            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
13096            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
13097            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13098            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
13099            -s "=> write certificate request" \
13100            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
13101            -s "=> parse client hello" \
13102            -s "<= parse client hello"
13103
13104requires_config_enabled MBEDTLS_DEBUG_C
13105requires_config_enabled MBEDTLS_SSL_CLI_C
13106requires_config_enabled MBEDTLS_SSL_SRV_C
13107requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13108requires_config_enabled PSA_WANT_ALG_ECDH
13109run_test "TLS 1.3: server: HRR check - mbedtls" \
13110         "$P_SRV debug_level=4 groups=secp384r1" \
13111         "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13112         0 \
13113        -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
13114        -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
13115        -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13116        -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
13117        -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
13118        -s "selected_group: secp384r1" \
13119        -s "=> write hello retry request" \
13120        -s "<= write hello retry request"
13121
13122requires_config_enabled MBEDTLS_DEBUG_C
13123requires_config_enabled MBEDTLS_SSL_SRV_C
13124requires_config_enabled MBEDTLS_SSL_CLI_C
13125requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13126run_test    "TLS 1.3: Server side check, no server certificate available" \
13127            "$P_SRV debug_level=4 crt_file=none key_file=none" \
13128            "$P_CLI debug_level=4" \
13129            1 \
13130            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
13131            -s "No certificate available."
13132
13133requires_openssl_tls1_3_with_compatible_ephemeral
13134requires_config_enabled MBEDTLS_DEBUG_C
13135requires_config_enabled MBEDTLS_SSL_SRV_C
13136requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13137                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13138run_test    "TLS 1.3: Server side check - openssl with sni" \
13139            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0 \
13140             sni=localhost,data_files/server5.crt,data_files/server5.key,data_files/test-ca_cat12.crt,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
13141            "$O_NEXT_CLI -msg -debug -servername localhost -CAfile data_files/test-ca_cat12.crt -cert data_files/server5.crt -key data_files/server5.key -tls1_3" \
13142            0 \
13143            -s "parse ServerName extension" \
13144            -s "HTTP/1.0 200 OK"
13145
13146requires_gnutls_tls1_3
13147requires_config_enabled MBEDTLS_DEBUG_C
13148requires_config_enabled MBEDTLS_SSL_SRV_C
13149requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13150                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13151run_test    "TLS 1.3: Server side check - gnutls with sni" \
13152            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0 \
13153             sni=localhost,data_files/server5.crt,data_files/server5.key,data_files/test-ca_cat12.crt,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
13154            "$G_NEXT_CLI localhost -d 4 --sni-hostname=localhost --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS -V" \
13155            0 \
13156            -s "parse ServerName extension" \
13157            -s "HTTP/1.0 200 OK"
13158
13159requires_config_enabled MBEDTLS_DEBUG_C
13160requires_config_enabled MBEDTLS_SSL_SRV_C
13161requires_config_enabled MBEDTLS_SSL_CLI_C
13162requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13163                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13164run_test    "TLS 1.3: Server side check - mbedtls with sni" \
13165            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0 \
13166             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
13167            "$P_CLI debug_level=4 server_name=localhost crt_file=data_files/server5.crt key_file=data_files/server5.key" \
13168            0 \
13169            -s "parse ServerName extension" \
13170            -s "HTTP/1.0 200 OK"
13171
13172for i in opt-testcases/*.sh
13173do
13174    TEST_SUITE_NAME=${i##*/}
13175    TEST_SUITE_NAME=${TEST_SUITE_NAME%.*}
13176    . "$i"
13177done
13178unset TEST_SUITE_NAME
13179
13180# Test 1.3 compatibility mode
13181requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13182requires_config_enabled MBEDTLS_DEBUG_C
13183requires_config_enabled MBEDTLS_SSL_SRV_C
13184requires_config_enabled MBEDTLS_SSL_CLI_C
13185requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13186run_test    "TLS 1.3 m->m both peers do not support middlebox compatibility" \
13187            "$P_SRV debug_level=4 tickets=0" \
13188            "$P_CLI debug_level=4" \
13189            0 \
13190            -s "Protocol is TLSv1.3" \
13191            -c "Protocol is TLSv1.3" \
13192            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
13193            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13194
13195requires_config_enabled MBEDTLS_DEBUG_C
13196requires_config_enabled MBEDTLS_SSL_SRV_C
13197requires_config_enabled MBEDTLS_SSL_CLI_C
13198requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13199                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13200run_test    "TLS 1.3 m->m both with middlebox compat support" \
13201            "$P_SRV debug_level=4 tickets=0" \
13202            "$P_CLI debug_level=4" \
13203            0 \
13204            -s "Protocol is TLSv1.3" \
13205            -c "Protocol is TLSv1.3" \
13206            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
13207            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13208
13209requires_openssl_tls1_3_with_compatible_ephemeral
13210requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13211requires_config_enabled MBEDTLS_DEBUG_C
13212requires_config_enabled MBEDTLS_SSL_CLI_C
13213requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13214run_test    "TLS 1.3 m->O both peers do not support middlebox compatibility" \
13215            "$O_NEXT_SRV -msg -tls1_3 -no_middlebox -num_tickets 0 -no_resume_ephemeral -no_cache" \
13216            "$P_CLI debug_level=4" \
13217            0 \
13218            -c "Protocol is TLSv1.3" \
13219            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
13220            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13221
13222requires_openssl_tls1_3_with_compatible_ephemeral
13223requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13224requires_config_enabled MBEDTLS_DEBUG_C
13225requires_config_enabled MBEDTLS_SSL_CLI_C
13226requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13227run_test    "TLS 1.3 m->O server with middlebox compat support, not client" \
13228            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
13229            "$P_CLI debug_level=4" \
13230            1 \
13231            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
13232
13233requires_openssl_tls1_3_with_compatible_ephemeral
13234requires_config_enabled MBEDTLS_DEBUG_C
13235requires_config_enabled MBEDTLS_SSL_CLI_C
13236requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13237                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13238run_test    "TLS 1.3 m->O both with middlebox compat support" \
13239            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
13240            "$P_CLI debug_level=4" \
13241            0 \
13242            -c "Protocol is TLSv1.3" \
13243            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13244
13245requires_gnutls_tls1_3
13246requires_gnutls_next_no_ticket
13247requires_gnutls_next_disable_tls13_compat
13248requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13249requires_config_enabled MBEDTLS_DEBUG_C
13250requires_config_enabled MBEDTLS_SSL_CLI_C
13251requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13252run_test    "TLS 1.3 m->G both peers do not support middlebox compatibility" \
13253            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert" \
13254            "$P_CLI debug_level=4" \
13255            0 \
13256            -c "Protocol is TLSv1.3" \
13257            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
13258            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13259
13260requires_gnutls_tls1_3
13261requires_gnutls_next_no_ticket
13262requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13263requires_config_enabled MBEDTLS_DEBUG_C
13264requires_config_enabled MBEDTLS_SSL_CLI_C
13265requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13266run_test    "TLS 1.3 m->G server with middlebox compat support, not client" \
13267            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
13268            "$P_CLI debug_level=4" \
13269            1 \
13270            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
13271
13272requires_gnutls_tls1_3
13273requires_gnutls_next_no_ticket
13274requires_config_enabled MBEDTLS_DEBUG_C
13275requires_config_enabled MBEDTLS_SSL_CLI_C
13276requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13277                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13278run_test    "TLS 1.3 m->G both with middlebox compat support" \
13279            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
13280            "$P_CLI debug_level=4" \
13281            0 \
13282            -c "Protocol is TLSv1.3" \
13283            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13284
13285requires_openssl_tls1_3_with_compatible_ephemeral
13286requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13287requires_config_enabled MBEDTLS_DEBUG_C
13288requires_config_enabled MBEDTLS_SSL_SRV_C
13289requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13290run_test    "TLS 1.3 O->m both peers do not support middlebox compatibility" \
13291            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13292            "$O_NEXT_CLI -msg -debug -no_middlebox" \
13293            0 \
13294            -s "Protocol is TLSv1.3" \
13295            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
13296            -C "14 03 03 00 01"
13297
13298requires_openssl_tls1_3_with_compatible_ephemeral
13299requires_config_enabled MBEDTLS_DEBUG_C
13300requires_config_enabled MBEDTLS_SSL_SRV_C
13301requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13302                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13303run_test    "TLS 1.3 O->m server with middlebox compat support, not client" \
13304            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13305            "$O_NEXT_CLI -msg -debug -no_middlebox" \
13306            0 \
13307            -s "Protocol is TLSv1.3" \
13308            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO"
13309
13310requires_openssl_tls1_3_with_compatible_ephemeral
13311requires_config_enabled MBEDTLS_DEBUG_C
13312requires_config_enabled MBEDTLS_SSL_SRV_C
13313requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13314                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13315run_test    "TLS 1.3 O->m both with middlebox compat support" \
13316            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13317            "$O_NEXT_CLI -msg -debug" \
13318            0 \
13319            -s "Protocol is TLSv1.3" \
13320            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
13321            -c "14 03 03 00 01"
13322
13323requires_gnutls_tls1_3
13324requires_gnutls_next_no_ticket
13325requires_gnutls_next_disable_tls13_compat
13326requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13327requires_config_enabled MBEDTLS_DEBUG_C
13328requires_config_enabled MBEDTLS_SSL_SRV_C
13329requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13330run_test    "TLS 1.3 G->m both peers do not support middlebox compatibility" \
13331            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13332            "$G_NEXT_CLI localhost --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13333            0 \
13334            -s "Protocol is TLSv1.3" \
13335            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
13336            -C "SSL 3.3 ChangeCipherSpec packet received"
13337
13338requires_gnutls_tls1_3
13339requires_gnutls_next_no_ticket
13340requires_gnutls_next_disable_tls13_compat
13341requires_config_enabled MBEDTLS_DEBUG_C
13342requires_config_enabled MBEDTLS_SSL_SRV_C
13343requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13344                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13345run_test    "TLS 1.3 G->m server with middlebox compat support, not client" \
13346            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13347            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13348            0 \
13349            -s "Protocol is TLSv1.3" \
13350            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
13351            -c "SSL 3.3 ChangeCipherSpec packet received" \
13352            -c "discarding change cipher spec in TLS1.3"
13353
13354requires_gnutls_tls1_3
13355requires_gnutls_next_no_ticket
13356requires_gnutls_next_disable_tls13_compat
13357requires_config_enabled MBEDTLS_DEBUG_C
13358requires_config_enabled MBEDTLS_SSL_SRV_C
13359requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13360                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13361run_test    "TLS 1.3 G->m both with middlebox compat support" \
13362            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key tickets=0" \
13363            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13364            0 \
13365            -s "Protocol is TLSv1.3" \
13366            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
13367            -c "SSL 3.3 ChangeCipherSpec packet received"
13368
13369requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13370requires_config_enabled MBEDTLS_DEBUG_C
13371requires_config_enabled MBEDTLS_SSL_SRV_C
13372requires_config_enabled MBEDTLS_SSL_CLI_C
13373requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13374run_test    "TLS 1.3 m->m HRR both peers do not support middlebox compatibility" \
13375            "$P_SRV debug_level=4 groups=secp384r1 tickets=0" \
13376            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13377            0 \
13378            -s "Protocol is TLSv1.3" \
13379            -c "Protocol is TLSv1.3" \
13380            -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
13381            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13382            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13383
13384requires_config_enabled MBEDTLS_DEBUG_C
13385requires_config_enabled MBEDTLS_SSL_SRV_C
13386requires_config_enabled MBEDTLS_SSL_CLI_C
13387requires_config_enabled PSA_WANT_ALG_ECDH
13388requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13389                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13390run_test    "TLS 1.3 m->m HRR both with middlebox compat support" \
13391            "$P_SRV debug_level=4 groups=secp384r1 tickets=0" \
13392            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13393            0 \
13394            -s "Protocol is TLSv1.3" \
13395            -c "Protocol is TLSv1.3" \
13396            -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
13397            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13398            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13399
13400requires_openssl_tls1_3_with_compatible_ephemeral
13401requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13402requires_config_enabled MBEDTLS_DEBUG_C
13403requires_config_enabled MBEDTLS_SSL_CLI_C
13404requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13405run_test    "TLS 1.3 m->O HRR both peers do not support middlebox compatibility" \
13406            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -no_middlebox -num_tickets 0 -no_cache" \
13407            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13408            0 \
13409            -c "Protocol is TLSv1.3" \
13410            -c "received HelloRetryRequest message" \
13411            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
13412            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13413
13414requires_openssl_tls1_3_with_compatible_ephemeral
13415requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13416requires_config_enabled MBEDTLS_DEBUG_C
13417requires_config_enabled MBEDTLS_SSL_CLI_C
13418requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13419run_test    "TLS 1.3 m->O HRR server with middlebox compat support, not client" \
13420            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -num_tickets 0 -no_cache" \
13421            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13422            1 \
13423            -c "received HelloRetryRequest message" \
13424            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
13425
13426requires_openssl_tls1_3_with_compatible_ephemeral
13427requires_config_enabled MBEDTLS_DEBUG_C
13428requires_config_enabled MBEDTLS_SSL_CLI_C
13429requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13430                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13431run_test    "TLS 1.3 m->O HRR both with middlebox compat support" \
13432            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -num_tickets 0 -no_resume_ephemeral -no_cache" \
13433            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13434            0 \
13435            -c "Protocol is TLSv1.3" \
13436            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13437
13438requires_gnutls_tls1_3
13439requires_gnutls_next_no_ticket
13440requires_gnutls_next_disable_tls13_compat
13441requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13442requires_config_enabled MBEDTLS_DEBUG_C
13443requires_config_enabled MBEDTLS_SSL_CLI_C
13444requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13445run_test    "TLS 1.3 m->G HRR both peers do not support middlebox compatibility" \
13446            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert" \
13447            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13448            0 \
13449            -c "Protocol is TLSv1.3" \
13450            -c "received HelloRetryRequest message" \
13451            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
13452            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13453
13454requires_gnutls_tls1_3
13455requires_gnutls_next_no_ticket
13456requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13457requires_config_enabled MBEDTLS_DEBUG_C
13458requires_config_enabled MBEDTLS_SSL_CLI_C
13459requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13460run_test    "TLS 1.3 m->G HRR server with middlebox compat support, not client" \
13461            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS --disable-client-cert" \
13462            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13463            1 \
13464            -c "received HelloRetryRequest message" \
13465            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
13466
13467requires_gnutls_tls1_3
13468requires_gnutls_next_no_ticket
13469requires_config_enabled MBEDTLS_DEBUG_C
13470requires_config_enabled MBEDTLS_SSL_CLI_C
13471requires_config_enabled PSA_WANT_ALG_ECDH
13472requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13473                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13474run_test    "TLS 1.3 m->G HRR both with middlebox compat support" \
13475            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
13476            "$P_CLI debug_level=4 groups=secp256r1,secp384r1" \
13477            0 \
13478            -c "Protocol is TLSv1.3" \
13479            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
13480
13481requires_openssl_tls1_3_with_compatible_ephemeral
13482requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13483requires_config_enabled MBEDTLS_DEBUG_C
13484requires_config_enabled MBEDTLS_SSL_SRV_C
13485requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13486run_test    "TLS 1.3 O->m HRR both peers do not support middlebox compatibility" \
13487            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key groups=secp384r1 tickets=0" \
13488            "$O_NEXT_CLI -msg -debug -groups P-256:P-384 -no_middlebox" \
13489            0 \
13490            -s "Protocol is TLSv1.3" \
13491            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13492            -C "14 03 03 00 01"
13493
13494requires_openssl_tls1_3_with_compatible_ephemeral
13495requires_config_enabled MBEDTLS_DEBUG_C
13496requires_config_enabled MBEDTLS_SSL_SRV_C
13497requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13498                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13499run_test    "TLS 1.3 O->m HRR server with middlebox compat support, not client" \
13500            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key groups=secp384r1 tickets=0" \
13501            "$O_NEXT_CLI -msg -debug -groups P-256:P-384 -no_middlebox" \
13502            0 \
13503            -s "Protocol is TLSv1.3" \
13504            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13505
13506requires_openssl_tls1_3_with_compatible_ephemeral
13507requires_config_enabled MBEDTLS_DEBUG_C
13508requires_config_enabled MBEDTLS_SSL_SRV_C
13509requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13510                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13511run_test    "TLS 1.3 O->m HRR both with middlebox compat support" \
13512            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key groups=secp384r1 tickets=0" \
13513            "$O_NEXT_CLI -msg -debug -groups P-256:P-384" \
13514            0 \
13515            -s "Protocol is TLSv1.3" \
13516            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13517            -c "14 03 03 00 01"
13518
13519requires_gnutls_tls1_3
13520requires_gnutls_next_no_ticket
13521requires_gnutls_next_disable_tls13_compat
13522requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13523requires_config_enabled MBEDTLS_DEBUG_C
13524requires_config_enabled MBEDTLS_SSL_SRV_C
13525requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13526run_test    "TLS 1.3 G->m HRR both peers do not support middlebox compatibility" \
13527            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key groups=secp384r1 tickets=0" \
13528            "$G_NEXT_CLI localhost --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13529            0 \
13530            -s "Protocol is TLSv1.3" \
13531            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13532            -C "SSL 3.3 ChangeCipherSpec packet received"
13533
13534requires_gnutls_tls1_3
13535requires_gnutls_next_no_ticket
13536requires_gnutls_next_disable_tls13_compat
13537requires_config_enabled MBEDTLS_DEBUG_C
13538requires_config_enabled MBEDTLS_SSL_SRV_C
13539requires_config_enabled PSA_WANT_ALG_ECDH
13540requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13541                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13542run_test    "TLS 1.3 G->m HRR server with middlebox compat support, not client" \
13543            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key groups=secp384r1 tickets=0" \
13544            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13545            0 \
13546            -s "Protocol is TLSv1.3" \
13547            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13548            -c "SSL 3.3 ChangeCipherSpec packet received" \
13549            -c "discarding change cipher spec in TLS1.3"
13550
13551requires_gnutls_tls1_3
13552requires_gnutls_next_no_ticket
13553requires_gnutls_next_disable_tls13_compat
13554requires_config_enabled MBEDTLS_DEBUG_C
13555requires_config_enabled MBEDTLS_SSL_SRV_C
13556requires_config_enabled PSA_WANT_ALG_ECDH
13557requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13558                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13559run_test    "TLS 1.3 G->m HRR both with middlebox compat support" \
13560            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key groups=secp384r1 tickets=0" \
13561            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
13562            0 \
13563            -s "Protocol is TLSv1.3" \
13564            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
13565            -c "SSL 3.3 ChangeCipherSpec packet received"
13566
13567requires_openssl_tls1_3_with_compatible_ephemeral
13568requires_config_enabled MBEDTLS_DEBUG_C
13569requires_config_enabled MBEDTLS_SSL_CLI_C
13570requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13571                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13572run_test    "TLS 1.3: Check signature algorithm order, m->O" \
13573            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
13574                                 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache
13575                                 -Verify 10 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp256r1_sha256" \
13576            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
13577                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13578            0 \
13579            -c "Protocol is TLSv1.3" \
13580            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
13581            -c "HTTP/1.0 200 [Oo][Kk]"
13582
13583requires_gnutls_tls1_3
13584requires_config_enabled MBEDTLS_DEBUG_C
13585requires_config_enabled MBEDTLS_SSL_CLI_C
13586requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13587                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13588run_test    "TLS 1.3: Check signature algorithm order, m->G" \
13589            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
13590                    -d 4
13591                    --priority=NORMAL:-VERS-ALL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-RSA-PSS-RSAE-SHA384:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS " \
13592            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
13593                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13594            0 \
13595            -c "Protocol is TLSv1.3" \
13596            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
13597            -c "HTTP/1.0 200 [Oo][Kk]"
13598
13599requires_config_enabled MBEDTLS_DEBUG_C
13600requires_config_enabled MBEDTLS_SSL_SRV_C
13601requires_config_enabled MBEDTLS_SSL_CLI_C
13602requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13603                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13604run_test    "TLS 1.3: Check signature algorithm order, m->m" \
13605            "$P_SRV debug_level=4 auth_mode=required
13606                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13607                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13608                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13609            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
13610                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13611            0 \
13612            -c "Protocol is TLSv1.3" \
13613            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
13614            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
13615            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512" \
13616            -c "HTTP/1.0 200 [Oo][Kk]"
13617
13618requires_openssl_tls1_3_with_compatible_ephemeral
13619requires_config_enabled MBEDTLS_DEBUG_C
13620requires_config_enabled MBEDTLS_SSL_SRV_C
13621requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13622                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13623run_test    "TLS 1.3: Check signature algorithm order, O->m" \
13624            "$P_SRV debug_level=4 auth_mode=required
13625                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13626                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13627                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13628            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
13629                                 -cert data_files/server2-sha256.crt -key data_files/server2.key \
13630                                 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp256r1_sha256"  \
13631            0 \
13632            -c "TLSv1.3" \
13633            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
13634            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512"
13635
13636requires_gnutls_tls1_3
13637requires_config_enabled MBEDTLS_DEBUG_C
13638requires_config_enabled MBEDTLS_SSL_SRV_C
13639requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13640                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13641run_test    "TLS 1.3: Check signature algorithm order, G->m" \
13642            "$P_SRV debug_level=4 auth_mode=required
13643                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13644                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13645                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13646            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
13647                                 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key \
13648                                 --priority=NORMAL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-RSA-PSS-RSAE-SHA384"  \
13649            0 \
13650            -c "Negotiated version: 3.4" \
13651            -c "HTTP/1.0 200 [Oo][Kk]" \
13652            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
13653            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512"
13654
13655requires_gnutls_tls1_3
13656requires_config_enabled MBEDTLS_DEBUG_C
13657requires_config_enabled MBEDTLS_SSL_SRV_C
13658requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13659                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13660run_test    "TLS 1.3: Check server no suitable signature algorithm, G->m" \
13661            "$P_SRV debug_level=4 auth_mode=required
13662                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13663                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13664                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256 " \
13665            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
13666                                 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key \
13667                                 --priority=NORMAL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-ECDSA-SECP521R1-SHA512"  \
13668            1 \
13669            -S "ssl_tls13_pick_key_cert:check signature algorithm"
13670
13671requires_openssl_tls1_3_with_compatible_ephemeral
13672requires_config_enabled MBEDTLS_DEBUG_C
13673requires_config_enabled MBEDTLS_SSL_SRV_C
13674requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13675                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13676run_test    "TLS 1.3: Check server no suitable signature algorithm, O->m" \
13677            "$P_SRV debug_level=4 auth_mode=required
13678                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13679                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13680                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256" \
13681            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
13682                                 -cert data_files/server2-sha256.crt -key data_files/server2.key \
13683                                 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:ecdsa_secp521r1_sha512"  \
13684            1 \
13685            -S "ssl_tls13_pick_key_cert:check signature algorithm"
13686
13687requires_config_enabled MBEDTLS_DEBUG_C
13688requires_config_enabled MBEDTLS_SSL_SRV_C
13689requires_config_enabled MBEDTLS_SSL_CLI_C
13690requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13691                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13692run_test    "TLS 1.3: Check server no suitable signature algorithm, m->m" \
13693            "$P_SRV debug_level=4 auth_mode=required
13694                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13695                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13696                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256 " \
13697            "$P_CLI allow_sha1=0 debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
13698                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,ecdsa_secp521r1_sha512" \
13699            1 \
13700            -S "ssl_tls13_pick_key_cert:check signature algorithm"
13701
13702requires_gnutls_tls1_3
13703requires_config_enabled MBEDTLS_DEBUG_C
13704requires_config_enabled MBEDTLS_SSL_SRV_C
13705requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13706                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13707run_test    "TLS 1.3: Check server no suitable certificate, G->m" \
13708            "$P_SRV debug_level=4
13709                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13710                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13711            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
13712                                 --priority=NORMAL:-SIGN-ALL:+SIGN-ECDSA-SECP521R1-SHA512:+SIGN-ECDSA-SECP256R1-SHA256"  \
13713            1 \
13714            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
13715
13716requires_openssl_tls1_3_with_compatible_ephemeral
13717requires_config_enabled MBEDTLS_DEBUG_C
13718requires_config_enabled MBEDTLS_SSL_SRV_C
13719requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13720                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13721run_test    "TLS 1.3: Check server no suitable certificate, O->m" \
13722            "$P_SRV debug_level=4
13723                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13724                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13725            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
13726                                 -sigalgs ecdsa_secp521r1_sha512:ecdsa_secp256r1_sha256"  \
13727            1 \
13728            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
13729
13730requires_config_enabled MBEDTLS_DEBUG_C
13731requires_config_enabled MBEDTLS_SSL_SRV_C
13732requires_config_enabled MBEDTLS_SSL_CLI_C
13733requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13734                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13735run_test    "TLS 1.3: Check server no suitable certificate, m->m" \
13736            "$P_SRV debug_level=4
13737                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13738                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13739            "$P_CLI allow_sha1=0 debug_level=4 \
13740                    sig_algs=ecdsa_secp521r1_sha512,ecdsa_secp256r1_sha256" \
13741            1 \
13742            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
13743
13744requires_openssl_tls1_3_with_compatible_ephemeral
13745requires_config_enabled MBEDTLS_DEBUG_C
13746requires_config_enabled MBEDTLS_SSL_CLI_C
13747requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13748                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13749run_test    "TLS 1.3: Check client no signature algorithm, m->O" \
13750            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
13751                                 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache
13752                                 -Verify 10 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp521r1_sha512" \
13753            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
13754                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13755            1 \
13756            -c "no suitable signature algorithm"
13757
13758requires_gnutls_tls1_3
13759requires_config_enabled MBEDTLS_DEBUG_C
13760requires_config_enabled MBEDTLS_SSL_CLI_C
13761requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13762                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13763run_test    "TLS 1.3: Check client no signature algorithm, m->G" \
13764            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
13765                    -d 4
13766                    --priority=NORMAL:-VERS-ALL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-RSA-PSS-RSAE-SHA384:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS " \
13767            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
13768                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13769            1 \
13770            -c "no suitable signature algorithm"
13771
13772requires_config_enabled MBEDTLS_DEBUG_C
13773requires_config_enabled MBEDTLS_SSL_SRV_C
13774requires_config_enabled MBEDTLS_SSL_CLI_C
13775requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13776                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13777run_test    "TLS 1.3: Check client no signature algorithm, m->m" \
13778            "$P_SRV debug_level=4 auth_mode=required
13779                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13780                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13781                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp521r1_sha512" \
13782            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
13783                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13784            1 \
13785            -c "no suitable signature algorithm"
13786
13787requires_openssl_tls1_3_with_compatible_ephemeral
13788requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13789requires_config_enabled MBEDTLS_DEBUG_C
13790requires_config_enabled MBEDTLS_SSL_CLI_C
13791run_test    "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->O" \
13792            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
13793                                 -msg -tls1_2
13794                                 -Verify 10 " \
13795            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13796                    sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13797                    min_version=tls12 max_version=tls13 " \
13798            0 \
13799            -c "Protocol is TLSv1.2" \
13800            -c "HTTP/1.0 200 [Oo][Kk]"
13801
13802
13803requires_gnutls_tls1_3
13804requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13805requires_config_enabled MBEDTLS_DEBUG_C
13806requires_config_enabled MBEDTLS_SSL_CLI_C
13807run_test    "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->G" \
13808            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
13809                    -d 4
13810                    --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
13811            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13812                    sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13813                    min_version=tls12 max_version=tls13 " \
13814            0 \
13815            -c "Protocol is TLSv1.2" \
13816            -c "HTTP/1.0 200 [Oo][Kk]"
13817
13818requires_config_enabled MBEDTLS_SSL_SRV_C
13819requires_config_enabled MBEDTLS_DEBUG_C
13820requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13821requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13822requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13823requires_config_enabled PSA_WANT_ALG_FFDH
13824requires_config_enabled PSA_WANT_DH_RFC7919_3072
13825requires_gnutls_tls1_3
13826requires_gnutls_next_no_ticket
13827requires_gnutls_next_disable_tls13_compat
13828run_test "TLS 1.3 G->m: AES_128_GCM_SHA256,ffdhe3072,rsa_pss_rsae_sha256" \
13829         "$P_SRV crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe3072 tls13_kex_modes=ephemeral cookies=0 tickets=0" \
13830         "$G_NEXT_CLI_NO_CERT --debug=4 --single-key-share --x509cafile data_files/test-ca_cat12.crt --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE3072:+VERS-TLS1.3:%NO_TICKETS" \
13831         0 \
13832         -s "Protocol is TLSv1.3" \
13833         -s "server hello, chosen ciphersuite: TLS1-3-AES-128-GCM-SHA256 ( id=4865 )" \
13834         -s "received signature algorithm: 0x804" \
13835         -s "got named group: ffdhe3072(0101)" \
13836         -s "Certificate verification was skipped" \
13837         -C "received HelloRetryRequest message"
13838
13839
13840requires_gnutls_tls1_3
13841requires_gnutls_next_no_ticket
13842requires_gnutls_next_disable_tls13_compat
13843requires_config_enabled MBEDTLS_SSL_CLI_C
13844requires_config_enabled MBEDTLS_DEBUG_C
13845requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13846requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13847requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13848requires_config_enabled PSA_WANT_ALG_FFDH
13849requires_config_enabled PSA_WANT_DH_RFC7919_3072
13850run_test "TLS 1.3 m->G: AES_128_GCM_SHA256,ffdhe3072,rsa_pss_rsae_sha256" \
13851         "$G_NEXT_SRV_NO_CERT --http --disable-client-cert --debug=4 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE3072:+VERS-TLS1.3:%NO_TICKETS" \
13852         "$P_CLI ca_file=data_files/test-ca_cat12.crt debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe3072" \
13853         0 \
13854         -c "HTTP/1.0 200 OK" \
13855         -c "Protocol is TLSv1.3" \
13856         -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
13857         -c "Certificate Verify: Signature algorithm ( 0804 )" \
13858         -c "NamedGroup: ffdhe3072 ( 101 )" \
13859         -c "Verifying peer X.509 certificate... ok" \
13860         -C "received HelloRetryRequest message"
13861
13862requires_config_enabled MBEDTLS_SSL_SRV_C
13863requires_config_enabled MBEDTLS_DEBUG_C
13864requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13865requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13866requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13867requires_config_enabled PSA_WANT_ALG_FFDH
13868requires_config_enabled PSA_WANT_DH_RFC7919_4096
13869requires_gnutls_tls1_3
13870requires_gnutls_next_no_ticket
13871requires_gnutls_next_disable_tls13_compat
13872run_test "TLS 1.3 G->m: AES_128_GCM_SHA256,ffdhe4096,rsa_pss_rsae_sha256" \
13873         "$P_SRV crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe4096 tls13_kex_modes=ephemeral cookies=0 tickets=0" \
13874         "$G_NEXT_CLI_NO_CERT --debug=4 --single-key-share --x509cafile data_files/test-ca_cat12.crt --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE4096:+VERS-TLS1.3:%NO_TICKETS" \
13875         0 \
13876         -s "Protocol is TLSv1.3" \
13877         -s "server hello, chosen ciphersuite: TLS1-3-AES-128-GCM-SHA256 ( id=4865 )" \
13878         -s "received signature algorithm: 0x804" \
13879         -s "got named group: ffdhe4096(0102)" \
13880         -s "Certificate verification was skipped" \
13881         -C "received HelloRetryRequest message"
13882
13883
13884requires_gnutls_tls1_3
13885requires_gnutls_next_no_ticket
13886requires_gnutls_next_disable_tls13_compat
13887requires_config_enabled MBEDTLS_SSL_CLI_C
13888requires_config_enabled MBEDTLS_DEBUG_C
13889requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13890requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13891requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13892requires_config_enabled PSA_WANT_ALG_FFDH
13893requires_config_enabled PSA_WANT_DH_RFC7919_4096
13894run_test "TLS 1.3 m->G: AES_128_GCM_SHA256,ffdhe4096,rsa_pss_rsae_sha256" \
13895         "$G_NEXT_SRV_NO_CERT --http --disable-client-cert --debug=4 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE4096:+VERS-TLS1.3:%NO_TICKETS" \
13896         "$P_CLI ca_file=data_files/test-ca_cat12.crt debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe4096" \
13897         0 \
13898         -c "HTTP/1.0 200 OK" \
13899         -c "Protocol is TLSv1.3" \
13900         -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
13901         -c "Certificate Verify: Signature algorithm ( 0804 )" \
13902         -c "NamedGroup: ffdhe4096 ( 102 )" \
13903         -c "Verifying peer X.509 certificate... ok" \
13904         -C "received HelloRetryRequest message"
13905
13906requires_config_enabled MBEDTLS_SSL_SRV_C
13907requires_config_enabled MBEDTLS_DEBUG_C
13908requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13909requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13910requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13911requires_config_enabled PSA_WANT_ALG_FFDH
13912requires_config_enabled PSA_WANT_DH_RFC7919_6144
13913requires_gnutls_tls1_3
13914requires_gnutls_next_no_ticket
13915requires_gnutls_next_disable_tls13_compat
13916run_test "TLS 1.3 G->m: AES_128_GCM_SHA256,ffdhe6144,rsa_pss_rsae_sha256" \
13917         "$P_SRV crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe6144 tls13_kex_modes=ephemeral cookies=0 tickets=0" \
13918         "$G_NEXT_CLI_NO_CERT --debug=4 --single-key-share --x509cafile data_files/test-ca_cat12.crt --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE6144:+VERS-TLS1.3:%NO_TICKETS" \
13919         0 \
13920         -s "Protocol is TLSv1.3" \
13921         -s "server hello, chosen ciphersuite: TLS1-3-AES-128-GCM-SHA256 ( id=4865 )" \
13922         -s "received signature algorithm: 0x804" \
13923         -s "got named group: ffdhe6144(0103)" \
13924         -s "Certificate verification was skipped" \
13925         -C "received HelloRetryRequest message"
13926
13927requires_gnutls_tls1_3
13928requires_gnutls_next_no_ticket
13929requires_gnutls_next_disable_tls13_compat
13930requires_config_enabled MBEDTLS_SSL_CLI_C
13931requires_config_enabled MBEDTLS_DEBUG_C
13932requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13933requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13934requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13935requires_config_enabled PSA_WANT_ALG_FFDH
13936requires_config_enabled PSA_WANT_DH_RFC7919_6144
13937run_test "TLS 1.3 m->G: AES_128_GCM_SHA256,ffdhe6144,rsa_pss_rsae_sha256" \
13938         "$G_NEXT_SRV_NO_CERT --http --disable-client-cert --debug=4 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE6144:+VERS-TLS1.3:%NO_TICKETS" \
13939         "$P_CLI ca_file=data_files/test-ca_cat12.crt debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe6144" \
13940         0 \
13941         -c "HTTP/1.0 200 OK" \
13942         -c "Protocol is TLSv1.3" \
13943         -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
13944         -c "Certificate Verify: Signature algorithm ( 0804 )" \
13945         -c "NamedGroup: ffdhe6144 ( 103 )" \
13946         -c "Verifying peer X.509 certificate... ok" \
13947         -C "received HelloRetryRequest message"
13948
13949requires_config_enabled MBEDTLS_SSL_SRV_C
13950requires_config_enabled MBEDTLS_DEBUG_C
13951requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13952requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13953requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13954requires_config_enabled PSA_WANT_ALG_FFDH
13955requires_config_enabled PSA_WANT_DH_RFC7919_8192
13956requires_gnutls_tls1_3
13957requires_gnutls_next_no_ticket
13958requires_gnutls_next_disable_tls13_compat
13959client_needs_more_time 4
13960run_test "TLS 1.3 G->m: AES_128_GCM_SHA256,ffdhe8192,rsa_pss_rsae_sha256" \
13961         "$P_SRV crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe8192 tls13_kex_modes=ephemeral cookies=0 tickets=0" \
13962         "$G_NEXT_CLI_NO_CERT --debug=4 --single-key-share --x509cafile data_files/test-ca_cat12.crt --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE8192:+VERS-TLS1.3:%NO_TICKETS" \
13963         0 \
13964         -s "Protocol is TLSv1.3" \
13965         -s "server hello, chosen ciphersuite: TLS1-3-AES-128-GCM-SHA256 ( id=4865 )" \
13966         -s "received signature algorithm: 0x804" \
13967         -s "got named group: ffdhe8192(0104)" \
13968         -s "Certificate verification was skipped" \
13969         -C "received HelloRetryRequest message"
13970
13971requires_gnutls_tls1_3
13972requires_gnutls_next_no_ticket
13973requires_gnutls_next_disable_tls13_compat
13974requires_config_enabled MBEDTLS_SSL_CLI_C
13975requires_config_enabled MBEDTLS_DEBUG_C
13976requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13977requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
13978requires_config_enabled MBEDTLS_X509_RSASSA_PSS_SUPPORT
13979requires_config_enabled PSA_WANT_ALG_FFDH
13980requires_config_enabled PSA_WANT_DH_RFC7919_8192
13981client_needs_more_time 4
13982run_test "TLS 1.3 m->G: AES_128_GCM_SHA256,ffdhe8192,rsa_pss_rsae_sha256" \
13983         "$G_NEXT_SRV_NO_CERT --http --disable-client-cert --debug=4 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key --priority=NONE:+AES-128-GCM:+SHA256:+AEAD:+SIGN-RSA-PSS-RSAE-SHA256:+GROUP-FFDHE8192:+VERS-TLS1.3:%NO_TICKETS" \
13984         "$P_CLI ca_file=data_files/test-ca_cat12.crt debug_level=4 force_ciphersuite=TLS1-3-AES-128-GCM-SHA256 sig_algs=rsa_pss_rsae_sha256 groups=ffdhe8192" \
13985         0 \
13986         -c "HTTP/1.0 200 OK" \
13987         -c "Protocol is TLSv1.3" \
13988         -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
13989         -c "Certificate Verify: Signature algorithm ( 0804 )" \
13990         -c "NamedGroup: ffdhe8192 ( 104 )" \
13991         -c "Verifying peer X.509 certificate... ok" \
13992         -C "received HelloRetryRequest message"
13993
13994requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
13995requires_config_enabled MBEDTLS_SSL_SRV_C
13996requires_config_enabled MBEDTLS_SSL_CLI_C
13997requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
13998requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13999run_test    "TLS 1.3: no HRR in case of PSK key exchange mode" \
14000            "$P_SRV nbio=2 psk=010203 psk_identity=0a0b0c tls13_kex_modes=psk groups=none" \
14001            "$P_CLI nbio=2 debug_level=3 psk=010203 psk_identity=0a0b0c tls13_kex_modes=all" \
14002            0 \
14003            -C "received HelloRetryRequest message" \
14004            -c "Selected key exchange mode: psk$" \
14005            -c "HTTP/1.0 200 OK"
14006
14007# Test heap memory usage after handshake
14008requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
14009requires_config_enabled MBEDTLS_MEMORY_DEBUG
14010requires_config_enabled MBEDTLS_MEMORY_BUFFER_ALLOC_C
14011requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
14012requires_max_content_len 16384
14013run_tests_memory_after_hanshake
14014
14015if [ "$LIST_TESTS" -eq 0 ]; then
14016
14017    # Final report
14018
14019    echo "------------------------------------------------------------------------"
14020
14021    if [ $FAILS = 0 ]; then
14022        printf "PASSED"
14023    else
14024        printf "FAILED"
14025    fi
14026    PASSES=$(( $TESTS - $FAILS ))
14027    echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
14028
14029fi
14030
14031if [ $FAILS -gt 255 ]; then
14032    # Clamp at 255 as caller gets exit code & 0xFF
14033    # (so 256 would be 0, or success, etc)
14034    FAILS=255
14035fi
14036exit $FAILS
14037