1#!/bin/sh
2
3# ssl-opt.sh
4#
5# Copyright The Mbed TLS Contributors
6# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# Purpose
21#
22# Executes tests to prove various TLS/SSL options and extensions.
23#
24# The goal is not to cover every ciphersuite/version, but instead to cover
25# specific options (max fragment length, truncated hmac, etc) or procedures
26# (session resumption from cache or ticket, renego, etc).
27#
28# The tests assume a build with default options, with exceptions expressed
29# with a dependency.  The tests focus on functionality and do not consider
30# performance.
31#
32
33set -u
34
35# Limit the size of each log to 10 GiB, in case of failures with this script
36# where it may output seemingly unlimited length error logs.
37ulimit -f 20971520
38
39ORIGINAL_PWD=$PWD
40if ! cd "$(dirname "$0")"; then
41    exit 125
42fi
43
44# default values, can be overridden by the environment
45: ${P_SRV:=../programs/ssl/ssl_server2}
46: ${P_CLI:=../programs/ssl/ssl_client2}
47: ${P_PXY:=../programs/test/udp_proxy}
48: ${P_QUERY:=../programs/test/query_compile_time_config}
49: ${OPENSSL:=openssl}
50: ${GNUTLS_CLI:=gnutls-cli}
51: ${GNUTLS_SERV:=gnutls-serv}
52: ${PERL:=perl}
53
54# The OPENSSL variable used to be OPENSSL_CMD for historical reasons.
55# To help the migration, error out if the old variable is set,
56# but only if it has a different value than the new one.
57if [ "${OPENSSL_CMD+set}" = set ]; then
58    # the variable is set, we can now check its value
59    if [ "$OPENSSL_CMD" != "$OPENSSL" ]; then
60        echo "Please use OPENSSL instead of OPENSSL_CMD." >&2
61        exit 125
62    fi
63fi
64
65guess_config_name() {
66    if git diff --quiet ../include/mbedtls/mbedtls_config.h 2>/dev/null; then
67        echo "default"
68    else
69        echo "unknown"
70    fi
71}
72: ${MBEDTLS_TEST_OUTCOME_FILE=}
73: ${MBEDTLS_TEST_CONFIGURATION:="$(guess_config_name)"}
74: ${MBEDTLS_TEST_PLATFORM:="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
75
76O_SRV="$OPENSSL s_server -www -cert data_files/server5.crt -key data_files/server5.key"
77O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL s_client"
78G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
79G_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_CLI --x509cafile data_files/test-ca_cat12.crt"
80TCP_CLIENT="$PERL scripts/tcp_client.pl"
81
82# alternative versions of OpenSSL and GnuTLS (no default path)
83
84if [ -n "${OPENSSL_LEGACY:-}" ]; then
85    O_LEGACY_SRV="$OPENSSL_LEGACY s_server -www -cert data_files/server5.crt -key data_files/server5.key"
86    O_LEGACY_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_LEGACY s_client"
87else
88    O_LEGACY_SRV=false
89    O_LEGACY_CLI=false
90fi
91
92if [ -n "${OPENSSL_NEXT:-}" ]; then
93    O_NEXT_SRV="$OPENSSL_NEXT s_server -www -cert data_files/server5.crt -key data_files/server5.key"
94    O_NEXT_SRV_EARLY_DATA="$OPENSSL_NEXT s_server -early_data -cert data_files/server5.crt -key data_files/server5.key"
95    O_NEXT_SRV_NO_CERT="$OPENSSL_NEXT s_server -www "
96    O_NEXT_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client -CAfile data_files/test-ca_cat12.crt"
97    O_NEXT_CLI_NO_CERT="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client"
98else
99    O_NEXT_SRV=false
100    O_NEXT_SRV_NO_CERT=false
101    O_NEXT_SRV_EARLY_DATA=false
102    O_NEXT_CLI_NO_CERT=false
103    O_NEXT_CLI=false
104fi
105
106if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
107    G_NEXT_SRV="$GNUTLS_NEXT_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
108    G_NEXT_SRV_NO_CERT="$GNUTLS_NEXT_SERV"
109else
110    G_NEXT_SRV=false
111    G_NEXT_SRV_NO_CERT=false
112fi
113
114if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
115    G_NEXT_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_NEXT_CLI --x509cafile data_files/test-ca_cat12.crt"
116    G_NEXT_CLI_NO_CERT="echo 'GET / HTTP/1.0' | $GNUTLS_NEXT_CLI"
117else
118    G_NEXT_CLI=false
119    G_NEXT_CLI_NO_CERT=false
120fi
121
122TESTS=0
123FAILS=0
124SKIPS=0
125
126CONFIG_H='../include/mbedtls/mbedtls_config.h'
127
128MEMCHECK=0
129FILTER='.*'
130EXCLUDE='^$'
131
132SHOW_TEST_NUMBER=0
133RUN_TEST_NUMBER=''
134
135PRESERVE_LOGS=0
136
137# Pick a "unique" server port in the range 10000-19999, and a proxy
138# port which is this plus 10000. Each port number may be independently
139# overridden by a command line option.
140SRV_PORT=$(($$ % 10000 + 10000))
141PXY_PORT=$((SRV_PORT + 10000))
142
143print_usage() {
144    echo "Usage: $0 [options]"
145    printf "  -h|--help\tPrint this help.\n"
146    printf "  -m|--memcheck\tCheck memory leaks and errors.\n"
147    printf "  -f|--filter\tOnly matching tests are executed (substring or BRE)\n"
148    printf "  -e|--exclude\tMatching tests are excluded (substring or BRE)\n"
149    printf "  -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
150    printf "  -s|--show-numbers\tShow test numbers in front of test names\n"
151    printf "  -p|--preserve-logs\tPreserve logs of successful tests as well\n"
152    printf "     --outcome-file\tFile where test outcomes are written\n"
153    printf "                \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n"
154    printf "     --port     \tTCP/UDP port (default: randomish 1xxxx)\n"
155    printf "     --proxy-port\tTCP/UDP proxy port (default: randomish 2xxxx)\n"
156    printf "     --seed     \tInteger seed value to use for this test run\n"
157}
158
159get_options() {
160    while [ $# -gt 0 ]; do
161        case "$1" in
162            -f|--filter)
163                shift; FILTER=$1
164                ;;
165            -e|--exclude)
166                shift; EXCLUDE=$1
167                ;;
168            -m|--memcheck)
169                MEMCHECK=1
170                ;;
171            -n|--number)
172                shift; RUN_TEST_NUMBER=$1
173                ;;
174            -s|--show-numbers)
175                SHOW_TEST_NUMBER=1
176                ;;
177            -p|--preserve-logs)
178                PRESERVE_LOGS=1
179                ;;
180            --port)
181                shift; SRV_PORT=$1
182                ;;
183            --proxy-port)
184                shift; PXY_PORT=$1
185                ;;
186            --seed)
187                shift; SEED="$1"
188                ;;
189            -h|--help)
190                print_usage
191                exit 0
192                ;;
193            *)
194                echo "Unknown argument: '$1'"
195                print_usage
196                exit 1
197                ;;
198        esac
199        shift
200    done
201}
202
203# Make the outcome file path relative to the original directory, not
204# to .../tests
205case "$MBEDTLS_TEST_OUTCOME_FILE" in
206    [!/]*)
207        MBEDTLS_TEST_OUTCOME_FILE="$ORIGINAL_PWD/$MBEDTLS_TEST_OUTCOME_FILE"
208        ;;
209esac
210
211# Read boolean configuration options from mbedtls_config.h for easy and quick
212# testing. Skip non-boolean options (with something other than spaces
213# and a comment after "#define SYMBOL"). The variable contains a
214# space-separated list of symbols.
215CONFIGS_ENABLED=" $(echo `$P_QUERY -l` )"
216# Skip next test; use this macro to skip tests which are legitimate
217# in theory and expected to be re-introduced at some point, but
218# aren't expected to succeed at the moment due to problems outside
219# our control (such as bugs in other TLS implementations).
220skip_next_test() {
221    SKIP_NEXT="YES"
222}
223
224# Check if the required configuration ($1) is enabled
225is_config_enabled()
226{
227    case $CONFIGS_ENABLED in
228        *" $1"[\ =]*) return 0;;
229        *) return 1;;
230    esac
231}
232
233# skip next test if the flag is not enabled in mbedtls_config.h
234requires_config_enabled() {
235    case $CONFIGS_ENABLED in
236        *" $1"[\ =]*) :;;
237        *) SKIP_NEXT="YES";;
238    esac
239}
240
241# skip next test if the flag is enabled in mbedtls_config.h
242requires_config_disabled() {
243    case $CONFIGS_ENABLED in
244        *" $1"[\ =]*) SKIP_NEXT="YES";;
245    esac
246}
247
248requires_all_configs_enabled() {
249    if ! $P_QUERY -all $*
250    then
251        SKIP_NEXT="YES"
252    fi
253}
254
255requires_all_configs_disabled() {
256    if $P_QUERY -any $*
257    then
258        SKIP_NEXT="YES"
259    fi
260}
261
262requires_any_configs_enabled() {
263    if ! $P_QUERY -any $*
264    then
265        SKIP_NEXT="YES"
266    fi
267}
268
269requires_any_configs_disabled() {
270    if $P_QUERY -all $*
271    then
272        SKIP_NEXT="YES"
273    fi
274}
275
276TLS1_2_KEY_EXCHANGES_WITH_CERT="MBEDTLS_KEY_EXCHANGE_RSA_ENABLED \
277                                MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED \
278                                MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED \
279                                MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED \
280                                MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED \
281                                MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED \
282                                MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED"
283
284TLS1_2_KEY_EXCHANGES_WITH_ECDSA_CERT="MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED \
285                                      MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_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    ${P_SRV} "query_config=${1}"
306}
307
308requires_config_value_at_least() {
309    VAL="$( get_config_value_or_default "$1" )"
310    if [ -z "$VAL" ]; then
311        # Should never happen
312        echo "Mbed TLS configuration $1 is not defined"
313        exit 1
314    elif [ "$VAL" -lt "$2" ]; then
315       SKIP_NEXT="YES"
316    fi
317}
318
319requires_config_value_at_most() {
320    VAL=$( get_config_value_or_default "$1" )
321    if [ -z "$VAL" ]; then
322        # Should never happen
323        echo "Mbed TLS configuration $1 is not defined"
324        exit 1
325    elif [ "$VAL" -gt "$2" ]; then
326       SKIP_NEXT="YES"
327    fi
328}
329
330requires_config_value_equals() {
331    VAL=$( get_config_value_or_default "$1" )
332    if [ -z "$VAL" ]; then
333        # Should never happen
334        echo "Mbed TLS configuration $1 is not defined"
335        exit 1
336    elif [ "$VAL" -ne "$2" ]; then
337       SKIP_NEXT="YES"
338    fi
339}
340
341# Require Mbed TLS to support the given protocol version.
342#
343# Inputs:
344# * $1: protocol version in mbedtls syntax (argument to force_version=)
345requires_protocol_version() {
346    # Support for DTLS is detected separately in detect_dtls().
347    case "$1" in
348        tls12|dtls12) requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2;;
349        tls13|dtls13) requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3;;
350        *) echo "Unknown required protocol version: $1"; exit 1;;
351    esac
352}
353
354# Space-separated list of ciphersuites supported by this build of
355# Mbed TLS.
356P_CIPHERSUITES=" $($P_CLI --help 2>/dev/null |
357                   grep 'TLS-\|TLS1-3' |
358                   tr -s ' \n' ' ')"
359requires_ciphersuite_enabled() {
360    case $P_CIPHERSUITES in
361        *" $1 "*) :;;
362        *) SKIP_NEXT="YES";;
363    esac
364}
365
366# Automatically detect required features based on command line parameters.
367# Parameters are:
368# - $1 = command line (call to a TLS client or server program)
369# - $2 = client/server
370# - $3 = TLS version (TLS12 or TLS13)
371# - $4 = run test options
372detect_required_features() {
373    case "$1" in
374        *\ force_version=*)
375            tmp="${1##*\ force_version=}"
376            tmp="${tmp%%[!-0-9A-Z_a-z]*}"
377            requires_protocol_version "$tmp";;
378    esac
379
380    case "$1" in
381        *\ force_ciphersuite=*)
382            tmp="${1##*\ force_ciphersuite=}"
383            tmp="${tmp%%[!-0-9A-Z_a-z]*}"
384            requires_ciphersuite_enabled "$tmp";;
385    esac
386
387    case " $1 " in
388        *[-_\ =]tickets=[^0]*)
389            requires_config_enabled MBEDTLS_SSL_TICKET_C;;
390    esac
391    case " $1 " in
392        *[-_\ =]alpn=*)
393            requires_config_enabled MBEDTLS_SSL_ALPN;;
394    esac
395
396    case "$1" in
397        *server5*|\
398        *server7*|\
399        *dir-maxpath*)
400            if [ "$3" = "TLS13" ]; then
401                # In case of TLS13 the support for ECDSA is enough
402                requires_pk_alg "ECDSA"
403            else
404                # For TLS12 requirements are different between server and client
405                if [ "$2" = "server" ]; then
406                    # If the server uses "server5*" certificates, then an ECDSA based
407                    # key exchange is required
408                    requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_ECDSA_CERT
409                elif [ "$2" = "client" ]; then
410                    # Otherwise for the client it is enough to have any certificate
411                    # based authentication + support for ECDSA
412                    requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
413                    requires_pk_alg "ECDSA"
414                fi
415            fi
416            ;;
417    esac
418
419    unset tmp
420}
421
422requires_certificate_authentication () {
423    if [ "$PSK_ONLY" = "YES" ]; then
424        SKIP_NEXT="YES"
425    fi
426}
427
428adapt_cmd_for_psk () {
429    case "$2" in
430        *openssl*) s='-psk abc123 -nocert';;
431        *gnutls-*) s='--pskkey=abc123';;
432        *) s='psk=abc123';;
433    esac
434    eval $1='"$2 $s"'
435    unset s
436}
437
438# maybe_adapt_for_psk [RUN_TEST_OPTION...]
439# If running in a PSK-only build, maybe adapt the test to use a pre-shared key.
440#
441# If not running in a PSK-only build, do nothing.
442# If the test looks like it doesn't use a pre-shared key but can run with a
443# pre-shared key, pass a pre-shared key. If the test looks like it can't run
444# with a pre-shared key, skip it. If the test looks like it's already using
445# a pre-shared key, do nothing.
446#
447# This code does not consider builds with ECDHE-PSK or RSA-PSK.
448#
449# Inputs:
450# * $CLI_CMD, $SRV_CMD, $PXY_CMD: client/server/proxy commands.
451# * $PSK_ONLY: YES if running in a PSK-only build (no asymmetric key exchanges).
452# * "$@": options passed to run_test.
453#
454# Outputs:
455# * $CLI_CMD, $SRV_CMD: may be modified to add PSK-relevant arguments.
456# * $SKIP_NEXT: set to YES if the test can't run with PSK.
457maybe_adapt_for_psk() {
458    if [ "$PSK_ONLY" != "YES" ]; then
459        return
460    fi
461    if [ "$SKIP_NEXT" = "YES" ]; then
462        return
463    fi
464    case "$CLI_CMD $SRV_CMD" in
465        *[-_\ =]psk*|*[-_\ =]PSK*)
466            return;;
467        *force_ciphersuite*)
468            # The test case forces a non-PSK cipher suite. In some cases, a
469            # PSK cipher suite could be substituted, but we're not ready for
470            # that yet.
471            SKIP_NEXT="YES"
472            return;;
473        *\ auth_mode=*|*[-_\ =]crt[_=]*)
474            # The test case involves certificates. PSK won't do.
475            SKIP_NEXT="YES"
476            return;;
477    esac
478    adapt_cmd_for_psk CLI_CMD "$CLI_CMD"
479    adapt_cmd_for_psk SRV_CMD "$SRV_CMD"
480}
481
482case " $CONFIGS_ENABLED " in
483    *\ MBEDTLS_KEY_EXCHANGE_[^P]*) PSK_ONLY="NO";;
484    *\ MBEDTLS_KEY_EXCHANGE_P[^S]*) PSK_ONLY="NO";;
485    *\ MBEDTLS_KEY_EXCHANGE_PS[^K]*) PSK_ONLY="NO";;
486    *\ MBEDTLS_KEY_EXCHANGE_PSK[^_]*) PSK_ONLY="NO";;
487    *\ MBEDTLS_KEY_EXCHANGE_PSK_ENABLED\ *) PSK_ONLY="YES";;
488    *) PSK_ONLY="NO";;
489esac
490
491HAS_ALG_SHA_1="NO"
492HAS_ALG_SHA_224="NO"
493HAS_ALG_SHA_256="NO"
494HAS_ALG_SHA_384="NO"
495HAS_ALG_SHA_512="NO"
496
497check_for_hash_alg()
498{
499    CURR_ALG="INVALID";
500    USE_PSA="NO"
501    if is_config_enabled "MBEDTLS_USE_PSA_CRYPTO"; then
502        USE_PSA="YES";
503    fi
504    if [ $USE_PSA = "YES" ]; then
505        CURR_ALG=PSA_WANT_ALG_${1}
506    else
507        CURR_ALG=MBEDTLS_${1}_C
508        # Remove the second underscore to match MBEDTLS_* naming convention
509        CURR_ALG=$(echo "$CURR_ALG" | sed 's/_//2')
510    fi
511
512    case $CONFIGS_ENABLED in
513        *" $CURR_ALG"[\ =]*)
514            return 0
515        ;;
516        *) :;;
517    esac
518    return 1
519}
520
521populate_enabled_hash_algs()
522{
523    for hash_alg in SHA_1 SHA_224 SHA_256 SHA_384 SHA_512; do
524        if check_for_hash_alg "$hash_alg"; then
525            hash_alg_variable=HAS_ALG_${hash_alg}
526            eval ${hash_alg_variable}=YES
527        fi
528    done
529}
530
531# skip next test if the given hash alg is not supported
532requires_hash_alg() {
533    HASH_DEFINE="Invalid"
534    HAS_HASH_ALG="NO"
535    case $1 in
536        SHA_1):;;
537        SHA_224):;;
538        SHA_256):;;
539        SHA_384):;;
540        SHA_512):;;
541      *)
542            echo "Unsupported hash alg - $1"
543            exit 1
544        ;;
545    esac
546
547    HASH_DEFINE=HAS_ALG_${1}
548    eval "HAS_HASH_ALG=\${${HASH_DEFINE}}"
549    if [ "$HAS_HASH_ALG" = "NO" ]
550    then
551        SKIP_NEXT="YES"
552    fi
553}
554
555# Skip next test if the given pk alg is not enabled
556requires_pk_alg() {
557    case $1 in
558        ECDSA)
559            if is_config_enabled MBEDTLS_USE_PSA_CRYPTO; then
560                requires_config_enabled PSA_WANT_ALG_ECDSA
561            else
562                requires_config_enabled MBEDTLS_ECDSA_C
563            fi
564            ;;
565        *)
566            echo "Unknown/unimplemented case $1 in requires_pk_alg"
567            exit 1
568            ;;
569    esac
570}
571
572# skip next test if OpenSSL doesn't support FALLBACK_SCSV
573requires_openssl_with_fallback_scsv() {
574    if [ -z "${OPENSSL_HAS_FBSCSV:-}" ]; then
575        if $OPENSSL s_client -help 2>&1 | grep fallback_scsv >/dev/null
576        then
577            OPENSSL_HAS_FBSCSV="YES"
578        else
579            OPENSSL_HAS_FBSCSV="NO"
580        fi
581    fi
582    if [ "$OPENSSL_HAS_FBSCSV" = "NO" ]; then
583        SKIP_NEXT="YES"
584    fi
585}
586
587# skip next test if either IN_CONTENT_LEN or MAX_CONTENT_LEN are below a value
588requires_max_content_len() {
589    requires_config_value_at_least "MBEDTLS_SSL_IN_CONTENT_LEN" $1
590    requires_config_value_at_least "MBEDTLS_SSL_OUT_CONTENT_LEN" $1
591}
592
593# skip next test if GnuTLS isn't available
594requires_gnutls() {
595    if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
596        if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null 2>&1; then
597            GNUTLS_AVAILABLE="YES"
598        else
599            GNUTLS_AVAILABLE="NO"
600        fi
601    fi
602    if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
603        SKIP_NEXT="YES"
604    fi
605}
606
607# skip next test if GnuTLS-next isn't available
608requires_gnutls_next() {
609    if [ -z "${GNUTLS_NEXT_AVAILABLE:-}" ]; then
610        if ( which "${GNUTLS_NEXT_CLI:-}" && which "${GNUTLS_NEXT_SERV:-}" ) >/dev/null 2>&1; then
611            GNUTLS_NEXT_AVAILABLE="YES"
612        else
613            GNUTLS_NEXT_AVAILABLE="NO"
614        fi
615    fi
616    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
617        SKIP_NEXT="YES"
618    fi
619}
620
621# skip next test if OpenSSL-legacy isn't available
622requires_openssl_legacy() {
623    if [ -z "${OPENSSL_LEGACY_AVAILABLE:-}" ]; then
624        if which "${OPENSSL_LEGACY:-}" >/dev/null 2>&1; then
625            OPENSSL_LEGACY_AVAILABLE="YES"
626        else
627            OPENSSL_LEGACY_AVAILABLE="NO"
628        fi
629    fi
630    if [ "$OPENSSL_LEGACY_AVAILABLE" = "NO" ]; then
631        SKIP_NEXT="YES"
632    fi
633}
634
635requires_openssl_next() {
636    if [ -z "${OPENSSL_NEXT_AVAILABLE:-}" ]; then
637        if which "${OPENSSL_NEXT:-}" >/dev/null 2>&1; then
638            OPENSSL_NEXT_AVAILABLE="YES"
639        else
640            OPENSSL_NEXT_AVAILABLE="NO"
641        fi
642    fi
643    if [ "$OPENSSL_NEXT_AVAILABLE" = "NO" ]; then
644        SKIP_NEXT="YES"
645    fi
646}
647
648# skip next test if tls1_3 is not available
649requires_openssl_tls1_3() {
650    requires_openssl_next
651    if [ "$OPENSSL_NEXT_AVAILABLE" = "NO" ]; then
652        OPENSSL_TLS1_3_AVAILABLE="NO"
653    fi
654    if [ -z "${OPENSSL_TLS1_3_AVAILABLE:-}" ]; then
655        if $OPENSSL_NEXT s_client -help 2>&1 | grep tls1_3 >/dev/null
656        then
657            OPENSSL_TLS1_3_AVAILABLE="YES"
658        else
659            OPENSSL_TLS1_3_AVAILABLE="NO"
660        fi
661    fi
662    if [ "$OPENSSL_TLS1_3_AVAILABLE" = "NO" ]; then
663        SKIP_NEXT="YES"
664    fi
665}
666
667# skip next test if tls1_3 is not available
668requires_gnutls_tls1_3() {
669    requires_gnutls_next
670    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
671        GNUTLS_TLS1_3_AVAILABLE="NO"
672    fi
673    if [ -z "${GNUTLS_TLS1_3_AVAILABLE:-}" ]; then
674        if $GNUTLS_NEXT_CLI -l 2>&1 | grep VERS-TLS1.3 >/dev/null
675        then
676            GNUTLS_TLS1_3_AVAILABLE="YES"
677        else
678            GNUTLS_TLS1_3_AVAILABLE="NO"
679        fi
680    fi
681    if [ "$GNUTLS_TLS1_3_AVAILABLE" = "NO" ]; then
682        SKIP_NEXT="YES"
683    fi
684}
685
686# Check %NO_TICKETS option
687requires_gnutls_next_no_ticket() {
688    requires_gnutls_next
689    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
690        GNUTLS_NO_TICKETS_AVAILABLE="NO"
691    fi
692    if [ -z "${GNUTLS_NO_TICKETS_AVAILABLE:-}" ]; then
693        if $GNUTLS_NEXT_CLI --priority-list 2>&1 | grep NO_TICKETS >/dev/null
694        then
695            GNUTLS_NO_TICKETS_AVAILABLE="YES"
696        else
697            GNUTLS_NO_TICKETS_AVAILABLE="NO"
698        fi
699    fi
700    if [ "$GNUTLS_NO_TICKETS_AVAILABLE" = "NO" ]; then
701        SKIP_NEXT="YES"
702    fi
703}
704
705# Check %DISABLE_TLS13_COMPAT_MODE option
706requires_gnutls_next_disable_tls13_compat() {
707    requires_gnutls_next
708    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
709        GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="NO"
710    fi
711    if [ -z "${GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE:-}" ]; then
712        if $GNUTLS_NEXT_CLI --priority-list 2>&1 | grep DISABLE_TLS13_COMPAT_MODE >/dev/null
713        then
714            GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="YES"
715        else
716            GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="NO"
717        fi
718    fi
719    if [ "$GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE" = "NO" ]; then
720        SKIP_NEXT="YES"
721    fi
722}
723
724# skip next test if GnuTLS does not support the record size limit extension
725requires_gnutls_record_size_limit() {
726    requires_gnutls_next
727    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
728        GNUTLS_RECORD_SIZE_LIMIT_AVAILABLE="NO"
729    else
730        GNUTLS_RECORD_SIZE_LIMIT_AVAILABLE="YES"
731    fi
732    if [ "$GNUTLS_RECORD_SIZE_LIMIT_AVAILABLE" = "NO" ]; then
733        SKIP_NEXT="YES"
734    fi
735}
736
737# skip next test if IPv6 isn't available on this host
738requires_ipv6() {
739    if [ -z "${HAS_IPV6:-}" ]; then
740        $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
741        SRV_PID=$!
742        sleep 1
743        kill $SRV_PID >/dev/null 2>&1
744        if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
745            HAS_IPV6="NO"
746        else
747            HAS_IPV6="YES"
748        fi
749        rm -r $SRV_OUT
750    fi
751
752    if [ "$HAS_IPV6" = "NO" ]; then
753        SKIP_NEXT="YES"
754    fi
755}
756
757# skip next test if it's i686 or uname is not available
758requires_not_i686() {
759    if [ -z "${IS_I686:-}" ]; then
760        IS_I686="YES"
761        if which "uname" >/dev/null 2>&1; then
762            if [ -z "$(uname -a | grep i686)" ]; then
763                IS_I686="NO"
764            fi
765        fi
766    fi
767    if [ "$IS_I686" = "YES" ]; then
768        SKIP_NEXT="YES"
769    fi
770}
771
772# Calculate the input & output maximum content lengths set in the config
773MAX_CONTENT_LEN=16384
774MAX_IN_LEN=$( get_config_value_or_default "MBEDTLS_SSL_IN_CONTENT_LEN" )
775MAX_OUT_LEN=$( get_config_value_or_default "MBEDTLS_SSL_OUT_CONTENT_LEN" )
776
777# Calculate the maximum content length that fits both
778if [ "$MAX_IN_LEN" -lt "$MAX_CONTENT_LEN" ]; then
779    MAX_CONTENT_LEN="$MAX_IN_LEN"
780fi
781if [ "$MAX_OUT_LEN" -lt "$MAX_CONTENT_LEN" ]; then
782    MAX_CONTENT_LEN="$MAX_OUT_LEN"
783fi
784
785# skip the next test if the SSL output buffer is less than 16KB
786requires_full_size_output_buffer() {
787    if [ "$MAX_OUT_LEN" -ne 16384 ]; then
788        SKIP_NEXT="YES"
789    fi
790}
791
792# skip the next test if valgrind is in use
793not_with_valgrind() {
794    if [ "$MEMCHECK" -gt 0 ]; then
795        SKIP_NEXT="YES"
796    fi
797}
798
799# skip the next test if valgrind is NOT in use
800only_with_valgrind() {
801    if [ "$MEMCHECK" -eq 0 ]; then
802        SKIP_NEXT="YES"
803    fi
804}
805
806# multiply the client timeout delay by the given factor for the next test
807client_needs_more_time() {
808    CLI_DELAY_FACTOR=$1
809}
810
811# wait for the given seconds after the client finished in the next test
812server_needs_more_time() {
813    SRV_DELAY_SECONDS=$1
814}
815
816# print_name <name>
817print_name() {
818    TESTS=$(( $TESTS + 1 ))
819    LINE=""
820
821    if [ "$SHOW_TEST_NUMBER" -gt 0 ]; then
822        LINE="$TESTS "
823    fi
824
825    LINE="$LINE$1"
826    printf "%s " "$LINE"
827    LEN=$(( 72 - `echo "$LINE" | wc -c` ))
828    for i in `seq 1 $LEN`; do printf '.'; done
829    printf ' '
830
831}
832
833# record_outcome <outcome> [<failure-reason>]
834# The test name must be in $NAME.
835# Use $TEST_SUITE_NAME as the test suite name if set.
836record_outcome() {
837    echo "$1"
838    if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
839        printf '%s;%s;%s;%s;%s;%s\n' \
840               "$MBEDTLS_TEST_PLATFORM" "$MBEDTLS_TEST_CONFIGURATION" \
841               "${TEST_SUITE_NAME:-ssl-opt}" "$NAME" \
842               "$1" "${2-}" \
843               >>"$MBEDTLS_TEST_OUTCOME_FILE"
844    fi
845}
846unset TEST_SUITE_NAME
847
848# True if the presence of the given pattern in a log definitely indicates
849# that the test has failed. False if the presence is inconclusive.
850#
851# Inputs:
852# * $1: pattern found in the logs
853# * $TIMES_LEFT: >0 if retrying is an option
854#
855# Outputs:
856# * $outcome: set to a retry reason if the pattern is inconclusive,
857#             unchanged otherwise.
858# * Return value: 1 if the pattern is inconclusive,
859#                 0 if the failure is definitive.
860log_pattern_presence_is_conclusive() {
861    # If we've run out of attempts, then don't retry no matter what.
862    if [ $TIMES_LEFT -eq 0 ]; then
863        return 0
864    fi
865    case $1 in
866        "resend")
867            # An undesired resend may have been caused by the OS dropping or
868            # delaying a packet at an inopportune time.
869            outcome="RETRY(resend)"
870            return 1;;
871    esac
872}
873
874# fail <message>
875fail() {
876    record_outcome "FAIL" "$1"
877    echo "  ! $1"
878
879    mv $SRV_OUT o-srv-${TESTS}.log
880    mv $CLI_OUT o-cli-${TESTS}.log
881    if [ -n "$PXY_CMD" ]; then
882        mv $PXY_OUT o-pxy-${TESTS}.log
883    fi
884    echo "  ! outputs saved to o-XXX-${TESTS}.log"
885
886    if [ "${LOG_FAILURE_ON_STDOUT:-0}" != 0 ]; then
887        echo "  ! server output:"
888        cat o-srv-${TESTS}.log
889        echo "  ! ========================================================"
890        echo "  ! client output:"
891        cat o-cli-${TESTS}.log
892        if [ -n "$PXY_CMD" ]; then
893            echo "  ! ========================================================"
894            echo "  ! proxy output:"
895            cat o-pxy-${TESTS}.log
896        fi
897        echo ""
898    fi
899
900    FAILS=$(( $FAILS + 1 ))
901}
902
903# is_polar <cmd_line>
904is_polar() {
905    case "$1" in
906        *ssl_client2*) true;;
907        *ssl_server2*) true;;
908        *) false;;
909    esac
910}
911
912# openssl s_server doesn't have -www with DTLS
913check_osrv_dtls() {
914    case "$SRV_CMD" in
915        *s_server*-dtls*)
916            NEEDS_INPUT=1
917            SRV_CMD="$( echo $SRV_CMD | sed s/-www// )";;
918        *) NEEDS_INPUT=0;;
919    esac
920}
921
922# provide input to commands that need it
923provide_input() {
924    if [ $NEEDS_INPUT -eq 0 ]; then
925        return
926    fi
927
928    while true; do
929        echo "HTTP/1.0 200 OK"
930        sleep 1
931    done
932}
933
934# has_mem_err <log_file_name>
935has_mem_err() {
936    if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
937         grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
938    then
939        return 1 # false: does not have errors
940    else
941        return 0 # true: has errors
942    fi
943}
944
945# Wait for process $2 named $3 to be listening on port $1. Print error to $4.
946if type lsof >/dev/null 2>/dev/null; then
947    wait_app_start() {
948        newline='
949'
950        START_TIME=$(date +%s)
951        if [ "$DTLS" -eq 1 ]; then
952            proto=UDP
953        else
954            proto=TCP
955        fi
956        # Make a tight loop, server normally takes less than 1s to start.
957        while true; do
958              SERVER_PIDS=$(lsof -a -n -b -i "$proto:$1" -t)
959              # When we use a proxy, it will be listening on the same port we
960              # are checking for as well as the server and lsof will list both.
961             case ${newline}${SERVER_PIDS}${newline} in
962                  *${newline}${2}${newline}*) break;;
963              esac
964              if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then
965                  echo "$3 START TIMEOUT"
966                  echo "$3 START TIMEOUT" >> $4
967                  break
968              fi
969              # Linux and *BSD support decimal arguments to sleep. On other
970              # OSes this may be a tight loop.
971              sleep 0.1 2>/dev/null || true
972        done
973    }
974else
975    echo "Warning: lsof not available, wait_app_start = sleep"
976    wait_app_start() {
977        sleep "$START_DELAY"
978    }
979fi
980
981# Wait for server process $2 to be listening on port $1.
982wait_server_start() {
983    wait_app_start $1 $2 "SERVER" $SRV_OUT
984}
985
986# Wait for proxy process $2 to be listening on port $1.
987wait_proxy_start() {
988    wait_app_start $1 $2 "PROXY" $PXY_OUT
989}
990
991# Given the client or server debug output, parse the unix timestamp that is
992# included in the first 4 bytes of the random bytes and check that it's within
993# acceptable bounds
994check_server_hello_time() {
995    # Extract the time from the debug (lvl 3) output of the client
996    SERVER_HELLO_TIME="$(sed -n 's/.*server hello, current time: //p' < "$1")"
997    # Get the Unix timestamp for now
998    CUR_TIME=$(date +'%s')
999    THRESHOLD_IN_SECS=300
1000
1001    # Check if the ServerHello time was printed
1002    if [ -z "$SERVER_HELLO_TIME" ]; then
1003        return 1
1004    fi
1005
1006    # Check the time in ServerHello is within acceptable bounds
1007    if [ $SERVER_HELLO_TIME -lt $(( $CUR_TIME - $THRESHOLD_IN_SECS )) ]; then
1008        # The time in ServerHello is at least 5 minutes before now
1009        return 1
1010    elif [ $SERVER_HELLO_TIME -gt $(( $CUR_TIME + $THRESHOLD_IN_SECS )) ]; then
1011        # The time in ServerHello is at least 5 minutes later than now
1012        return 1
1013    else
1014        return 0
1015    fi
1016}
1017
1018# Get handshake memory usage from server or client output and put it into the variable specified by the first argument
1019handshake_memory_get() {
1020    OUTPUT_VARIABLE="$1"
1021    OUTPUT_FILE="$2"
1022
1023    # Get memory usage from a pattern like "Heap memory usage after handshake: 23112 bytes. Peak memory usage was 33112"
1024    MEM_USAGE=$(sed -n 's/.*Heap memory usage after handshake: //p' < "$OUTPUT_FILE" | grep -o "[0-9]*" | head -1)
1025
1026    # Check if memory usage was read
1027    if [ -z "$MEM_USAGE" ]; then
1028        echo "Error: Can not read the value of handshake memory usage"
1029        return 1
1030    else
1031        eval "$OUTPUT_VARIABLE=$MEM_USAGE"
1032        return 0
1033    fi
1034}
1035
1036# Get handshake memory usage from server or client output and check if this value
1037# is not higher than the maximum given by the first argument
1038handshake_memory_check() {
1039    MAX_MEMORY="$1"
1040    OUTPUT_FILE="$2"
1041
1042    # Get memory usage
1043    if ! handshake_memory_get "MEMORY_USAGE" "$OUTPUT_FILE"; then
1044        return 1
1045    fi
1046
1047    # Check if memory usage is below max value
1048    if [ "$MEMORY_USAGE" -gt "$MAX_MEMORY" ]; then
1049        echo "\nFailed: Handshake memory usage was $MEMORY_USAGE bytes," \
1050             "but should be below $MAX_MEMORY bytes"
1051        return 1
1052    else
1053        return 0
1054    fi
1055}
1056
1057# wait for client to terminate and set CLI_EXIT
1058# must be called right after starting the client
1059wait_client_done() {
1060    CLI_PID=$!
1061
1062    CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
1063    CLI_DELAY_FACTOR=1
1064
1065    ( sleep $CLI_DELAY; echo "===CLIENT_TIMEOUT===" >> $CLI_OUT; kill $CLI_PID ) &
1066    DOG_PID=$!
1067
1068    # For Ubuntu 22.04, `Terminated` message is outputed by wait command.
1069    # To remove it from stdout, redirect stdout/stderr to CLI_OUT
1070    wait $CLI_PID >> $CLI_OUT 2>&1
1071    CLI_EXIT=$?
1072
1073    kill $DOG_PID >/dev/null 2>&1
1074    wait $DOG_PID >> $CLI_OUT 2>&1
1075
1076    echo "EXIT: $CLI_EXIT" >> $CLI_OUT
1077
1078    sleep $SRV_DELAY_SECONDS
1079    SRV_DELAY_SECONDS=0
1080}
1081
1082# check if the given command uses dtls and sets global variable DTLS
1083detect_dtls() {
1084    case "$1" in
1085        *dtls=1*|*-dtls*|*-u*) DTLS=1;;
1086        *) DTLS=0;;
1087    esac
1088}
1089
1090# check if the given command uses gnutls and sets global variable CMD_IS_GNUTLS
1091is_gnutls() {
1092    case "$1" in
1093    *gnutls-cli*)
1094        CMD_IS_GNUTLS=1
1095        ;;
1096    *gnutls-serv*)
1097        CMD_IS_GNUTLS=1
1098        ;;
1099    *)
1100        CMD_IS_GNUTLS=0
1101        ;;
1102    esac
1103}
1104
1105# Generate random psk_list argument for ssl_server2
1106get_srv_psk_list ()
1107{
1108    case $(( TESTS % 3 )) in
1109        0) echo "psk_list=abc,dead,def,beef,Client_identity,6162636465666768696a6b6c6d6e6f70";;
1110        1) echo "psk_list=abc,dead,Client_identity,6162636465666768696a6b6c6d6e6f70,def,beef";;
1111        2) echo "psk_list=Client_identity,6162636465666768696a6b6c6d6e6f70,abc,dead,def,beef";;
1112    esac
1113}
1114
1115# Determine what calc_verify trace is to be expected, if any.
1116#
1117# calc_verify is only called for two things: to calculate the
1118# extended master secret, and to process client authentication.
1119#
1120# Warning: the current implementation assumes that extended_ms is not
1121#          disabled on the client or on the server.
1122#
1123# Inputs:
1124# * $1: the value of the server auth_mode parameter.
1125#       'required' if client authentication is expected,
1126#       'none' or absent if not.
1127# * $CONFIGS_ENABLED
1128#
1129# Outputs:
1130# * $maybe_calc_verify: set to a trace expected in the debug logs
1131set_maybe_calc_verify() {
1132    maybe_calc_verify=
1133    case $CONFIGS_ENABLED in
1134        *\ MBEDTLS_SSL_EXTENDED_MASTER_SECRET\ *) :;;
1135        *)
1136            case ${1-} in
1137                ''|none) return;;
1138                required) :;;
1139                *) echo "Bad parameter 1 to set_maybe_calc_verify: $1"; exit 1;;
1140            esac
1141    esac
1142    case $CONFIGS_ENABLED in
1143        *\ MBEDTLS_USE_PSA_CRYPTO\ *) maybe_calc_verify="PSA calc verify";;
1144        *) maybe_calc_verify="<= calc verify";;
1145    esac
1146}
1147
1148# Compare file content
1149# Usage: find_in_both pattern file1 file2
1150# extract from file1 the first line matching the pattern
1151# check in file2 that the same line can be found
1152find_in_both() {
1153        srv_pattern=$(grep -m 1 "$1" "$2");
1154        if [ -z "$srv_pattern" ]; then
1155                return 1;
1156        fi
1157
1158        if grep "$srv_pattern" $3 >/dev/null; then :
1159                return 0;
1160        else
1161                return 1;
1162        fi
1163}
1164
1165SKIP_HANDSHAKE_CHECK="NO"
1166skip_handshake_stage_check() {
1167    SKIP_HANDSHAKE_CHECK="YES"
1168}
1169
1170# Analyze the commands that will be used in a test.
1171#
1172# Analyze and possibly instrument $PXY_CMD, $CLI_CMD, $SRV_CMD to pass
1173# extra arguments or go through wrappers.
1174#
1175# Inputs:
1176# * $@: supplemental options to run_test() (after the mandatory arguments).
1177# * $CLI_CMD, $PXY_CMD, $SRV_CMD: the client, proxy and server commands.
1178# * $DTLS: 1 if DTLS, otherwise 0.
1179#
1180# Outputs:
1181# * $CLI_CMD, $PXY_CMD, $SRV_CMD: may be tweaked.
1182analyze_test_commands() {
1183    # if the test uses DTLS but no custom proxy, add a simple proxy
1184    # as it provides timing info that's useful to debug failures
1185    if [ -z "$PXY_CMD" ] && [ "$DTLS" -eq 1 ]; then
1186        PXY_CMD="$P_PXY"
1187        case " $SRV_CMD " in
1188            *' server_addr=::1 '*)
1189                PXY_CMD="$PXY_CMD server_addr=::1 listen_addr=::1";;
1190        esac
1191    fi
1192
1193    # update CMD_IS_GNUTLS variable
1194    is_gnutls "$SRV_CMD"
1195
1196    # if the server uses gnutls but doesn't set priority, explicitly
1197    # set the default priority
1198    if [ "$CMD_IS_GNUTLS" -eq 1 ]; then
1199        case "$SRV_CMD" in
1200              *--priority*) :;;
1201              *) SRV_CMD="$SRV_CMD --priority=NORMAL";;
1202        esac
1203    fi
1204
1205    # update CMD_IS_GNUTLS variable
1206    is_gnutls "$CLI_CMD"
1207
1208    # if the client uses gnutls but doesn't set priority, explicitly
1209    # set the default priority
1210    if [ "$CMD_IS_GNUTLS" -eq 1 ]; then
1211        case "$CLI_CMD" in
1212              *--priority*) :;;
1213              *) CLI_CMD="$CLI_CMD --priority=NORMAL";;
1214        esac
1215    fi
1216
1217    # fix client port
1218    if [ -n "$PXY_CMD" ]; then
1219        CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
1220    else
1221        CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
1222    fi
1223
1224    # prepend valgrind to our commands if active
1225    if [ "$MEMCHECK" -gt 0 ]; then
1226        if is_polar "$SRV_CMD"; then
1227            SRV_CMD="valgrind --leak-check=full $SRV_CMD"
1228        fi
1229        if is_polar "$CLI_CMD"; then
1230            CLI_CMD="valgrind --leak-check=full $CLI_CMD"
1231        fi
1232    fi
1233}
1234
1235# Check for failure conditions after a test case.
1236#
1237# Inputs from run_test:
1238# * positional parameters: test options (see run_test documentation)
1239# * $CLI_EXIT: client return code
1240# * $CLI_EXPECT: expected client return code
1241# * $SRV_RET: server return code
1242# * $CLI_OUT, $SRV_OUT, $PXY_OUT: files containing client/server/proxy logs
1243# * $TIMES_LEFT: if nonzero, a RETRY outcome is allowed
1244#
1245# Outputs:
1246# * $outcome: one of PASS/RETRY*/FAIL
1247check_test_failure() {
1248    outcome=FAIL
1249
1250    if [ $TIMES_LEFT -gt 0 ] &&
1251       grep '===CLIENT_TIMEOUT===' $CLI_OUT >/dev/null
1252    then
1253        outcome="RETRY(client-timeout)"
1254        return
1255    fi
1256
1257    # check if the client and server went at least to the handshake stage
1258    # (useful to avoid tests with only negative assertions and non-zero
1259    # expected client exit to incorrectly succeed in case of catastrophic
1260    # failure)
1261    if [ "X$SKIP_HANDSHAKE_CHECK" != "XYES" ]
1262    then
1263        if is_polar "$SRV_CMD"; then
1264            if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
1265            else
1266                fail "server or client failed to reach handshake stage"
1267                return
1268            fi
1269        fi
1270        if is_polar "$CLI_CMD"; then
1271            if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
1272            else
1273                fail "server or client failed to reach handshake stage"
1274                return
1275            fi
1276        fi
1277    fi
1278
1279    SKIP_HANDSHAKE_CHECK="NO"
1280    # Check server exit code (only for Mbed TLS: GnuTLS and OpenSSL don't
1281    # exit with status 0 when interrupted by a signal, and we don't really
1282    # care anyway), in case e.g. the server reports a memory leak.
1283    if [ $SRV_RET != 0 ] && is_polar "$SRV_CMD"; then
1284        fail "Server exited with status $SRV_RET"
1285        return
1286    fi
1287
1288    # check client exit code
1289    if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
1290         \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
1291    then
1292        fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
1293        return
1294    fi
1295
1296    # check other assertions
1297    # lines beginning with == are added by valgrind, ignore them
1298    # lines with 'Serious error when reading debug info', are valgrind issues as well
1299    while [ $# -gt 0 ]
1300    do
1301        case $1 in
1302            "-s")
1303                if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
1304                    fail "pattern '$2' MUST be present in the Server output"
1305                    return
1306                fi
1307                ;;
1308
1309            "-c")
1310                if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
1311                    fail "pattern '$2' MUST be present in the Client output"
1312                    return
1313                fi
1314                ;;
1315
1316            "-S")
1317                if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
1318                    if log_pattern_presence_is_conclusive "$2"; then
1319                        fail "pattern '$2' MUST NOT be present in the Server output"
1320                    fi
1321                    return
1322                fi
1323                ;;
1324
1325            "-C")
1326                if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
1327                    if log_pattern_presence_is_conclusive "$2"; then
1328                        fail "pattern '$2' MUST NOT be present in the Client output"
1329                    fi
1330                    return
1331                fi
1332                ;;
1333
1334                # The filtering in the following two options (-u and -U) do the following
1335                #   - ignore valgrind output
1336                #   - filter out everything but lines right after the pattern occurrences
1337                #   - keep one of each non-unique line
1338                #   - count how many lines remain
1339                # A line with '--' will remain in the result from previous outputs, so the number of lines in the result will be 1
1340                # if there were no duplicates.
1341            "-U")
1342                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
1343                    fail "lines following pattern '$2' must be unique in Server output"
1344                    return
1345                fi
1346                ;;
1347
1348            "-u")
1349                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
1350                    fail "lines following pattern '$2' must be unique in Client output"
1351                    return
1352                fi
1353                ;;
1354            "-F")
1355                if ! $2 "$SRV_OUT"; then
1356                    fail "function call to '$2' failed on Server output"
1357                    return
1358                fi
1359                ;;
1360            "-f")
1361                if ! $2 "$CLI_OUT"; then
1362                    fail "function call to '$2' failed on Client output"
1363                    return
1364                fi
1365                ;;
1366            "-g")
1367                if ! eval "$2 '$SRV_OUT' '$CLI_OUT'"; then
1368                    fail "function call to '$2' failed on Server and Client output"
1369                    return
1370                fi
1371                ;;
1372
1373            *)
1374                echo "Unknown test: $1" >&2
1375                exit 1
1376        esac
1377        shift 2
1378    done
1379
1380    # check valgrind's results
1381    if [ "$MEMCHECK" -gt 0 ]; then
1382        if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
1383            fail "Server has memory errors"
1384            return
1385        fi
1386        if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
1387            fail "Client has memory errors"
1388            return
1389        fi
1390    fi
1391
1392    # if we're here, everything is ok
1393    outcome=PASS
1394}
1395
1396# Run the current test case: start the server and if applicable the proxy, run
1397# the client, wait for all processes to finish or time out.
1398#
1399# Inputs:
1400# * $NAME: test case name
1401# * $CLI_CMD, $SRV_CMD, $PXY_CMD: commands to run
1402# * $CLI_OUT, $SRV_OUT, $PXY_OUT: files to contain client/server/proxy logs
1403#
1404# Outputs:
1405# * $CLI_EXIT: client return code
1406# * $SRV_RET: server return code
1407do_run_test_once() {
1408    # run the commands
1409    if [ -n "$PXY_CMD" ]; then
1410        printf "# %s\n%s\n" "$NAME" "$PXY_CMD" > $PXY_OUT
1411        $PXY_CMD >> $PXY_OUT 2>&1 &
1412        PXY_PID=$!
1413        wait_proxy_start "$PXY_PORT" "$PXY_PID"
1414    fi
1415
1416    check_osrv_dtls
1417    printf '# %s\n%s\n' "$NAME" "$SRV_CMD" > $SRV_OUT
1418    provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
1419    SRV_PID=$!
1420    wait_server_start "$SRV_PORT" "$SRV_PID"
1421
1422    printf '# %s\n%s\n' "$NAME" "$CLI_CMD" > $CLI_OUT
1423    # The client must be a subprocess of the script in order for killing it to
1424    # work properly, that's why the ampersand is placed inside the eval command,
1425    # not at the end of the line: the latter approach will spawn eval as a
1426    # subprocess, and the $CLI_CMD as a grandchild.
1427    eval "$CLI_CMD &" >> $CLI_OUT 2>&1
1428    wait_client_done
1429
1430    sleep 0.05
1431
1432    # terminate the server (and the proxy)
1433    kill $SRV_PID
1434    # For Ubuntu 22.04, `Terminated` message is outputed by wait command.
1435    # To remove it from stdout, redirect stdout/stderr to SRV_OUT
1436    wait $SRV_PID >> $SRV_OUT 2>&1
1437    SRV_RET=$?
1438
1439    if [ -n "$PXY_CMD" ]; then
1440        kill $PXY_PID >/dev/null 2>&1
1441        wait $PXY_PID >> $PXY_OUT 2>&1
1442    fi
1443}
1444
1445# Detect if the current test is going to use TLS 1.3.
1446# $1 and $2 contain the server and client command lines, respectively.
1447#
1448# Note: this function only provides some guess about TLS version by simply
1449#       looking at the server/client command lines. Even thought this works
1450#       for the sake of tests' filtering (especially in conjunction with the
1451#       detect_required_features() function), it does NOT guarantee that the
1452#       result is accurate. It does not check other conditions, such as:
1453#       - MBEDTLS_SSL_PROTO_TLS1_x can be disabled to selectively remove
1454#         TLS 1.2/1.3 support
1455#       - we can force a ciphersuite which contains "WITH" in its name, meaning
1456#         that we are going to use TLS 1.2
1457#       - etc etc
1458get_tls_version() {
1459    case $1 in
1460        *tls1_3*|*tls13*)
1461            echo "TLS13"
1462            return;;
1463    esac
1464    case $2 in
1465        *tls1_3*|*tls13*)
1466            echo "TLS13"
1467            return;;
1468    esac
1469    echo "TLS12"
1470}
1471
1472# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
1473# Options:  -s pattern  pattern that must be present in server output
1474#           -c pattern  pattern that must be present in client output
1475#           -u pattern  lines after pattern must be unique in client output
1476#           -f call shell function on client output
1477#           -S pattern  pattern that must be absent in server output
1478#           -C pattern  pattern that must be absent in client output
1479#           -U pattern  lines after pattern must be unique in server output
1480#           -F call shell function on server output
1481#           -g call shell function on server and client output
1482run_test() {
1483    NAME="$1"
1484    shift 1
1485
1486    if is_excluded "$NAME"; then
1487        SKIP_NEXT="NO"
1488        # There was no request to run the test, so don't record its outcome.
1489        return
1490    fi
1491
1492    print_name "$NAME"
1493
1494    # Do we only run numbered tests?
1495    if [ -n "$RUN_TEST_NUMBER" ]; then
1496        case ",$RUN_TEST_NUMBER," in
1497            *",$TESTS,"*) :;;
1498            *) SKIP_NEXT="YES";;
1499        esac
1500    fi
1501
1502    # does this test use a proxy?
1503    if [ "X$1" = "X-p" ]; then
1504        PXY_CMD="$2"
1505        shift 2
1506    else
1507        PXY_CMD=""
1508    fi
1509
1510    # get commands and client output
1511    SRV_CMD="$1"
1512    CLI_CMD="$2"
1513    CLI_EXPECT="$3"
1514    shift 3
1515
1516    # Check if test uses files
1517    case "$SRV_CMD $CLI_CMD" in
1518        *data_files/*)
1519            requires_config_enabled MBEDTLS_FS_IO;;
1520    esac
1521
1522    # Check if the test uses DTLS.
1523    detect_dtls "$SRV_CMD"
1524    if [ "$DTLS" -eq 1 ]; then
1525        requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
1526    fi
1527
1528    # If the client or server requires certain features that can be detected
1529    # from their command-line arguments, check that they're enabled.
1530    TLS_VERSION=$(get_tls_version "$SRV_CMD" "$CLI_CMD")
1531    detect_required_features "$SRV_CMD" "server" "$TLS_VERSION" "$@"
1532    detect_required_features "$CLI_CMD" "client" "$TLS_VERSION" "$@"
1533
1534    # If we're in a PSK-only build and the test can be adapted to PSK, do that.
1535    maybe_adapt_for_psk "$@"
1536
1537    # should we skip?
1538    if [ "X$SKIP_NEXT" = "XYES" ]; then
1539        SKIP_NEXT="NO"
1540        record_outcome "SKIP"
1541        SKIPS=$(( $SKIPS + 1 ))
1542        return
1543    fi
1544
1545    analyze_test_commands "$@"
1546
1547    # One regular run and two retries
1548    TIMES_LEFT=3
1549    while [ $TIMES_LEFT -gt 0 ]; do
1550        TIMES_LEFT=$(( $TIMES_LEFT - 1 ))
1551
1552        do_run_test_once
1553
1554        check_test_failure "$@"
1555        case $outcome in
1556            PASS) break;;
1557            RETRY*) printf "$outcome ";;
1558            FAIL) return;;
1559        esac
1560    done
1561
1562    # If we get this far, the test case passed.
1563    record_outcome "PASS"
1564    if [ "$PRESERVE_LOGS" -gt 0 ]; then
1565        mv $SRV_OUT o-srv-${TESTS}.log
1566        mv $CLI_OUT o-cli-${TESTS}.log
1567        if [ -n "$PXY_CMD" ]; then
1568            mv $PXY_OUT o-pxy-${TESTS}.log
1569        fi
1570    fi
1571
1572    rm -f $SRV_OUT $CLI_OUT $PXY_OUT
1573}
1574
1575run_test_psa() {
1576    requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1577    set_maybe_calc_verify none
1578    run_test    "PSA-supported ciphersuite: $1" \
1579                "$P_SRV debug_level=3 force_version=tls12" \
1580                "$P_CLI debug_level=3 force_ciphersuite=$1" \
1581                0 \
1582                -c "$maybe_calc_verify" \
1583                -c "calc PSA finished" \
1584                -s "$maybe_calc_verify" \
1585                -s "calc PSA finished" \
1586                -s "Protocol is TLSv1.2" \
1587                -c "Perform PSA-based ECDH computation."\
1588                -c "Perform PSA-based computation of digest of ServerKeyExchange" \
1589                -S "error" \
1590                -C "error"
1591    unset maybe_calc_verify
1592}
1593
1594run_test_psa_force_curve() {
1595    requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1596    set_maybe_calc_verify none
1597    run_test    "PSA - ECDH with $1" \
1598                "$P_SRV debug_level=4 force_version=tls12 curves=$1" \
1599                "$P_CLI debug_level=4 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 curves=$1" \
1600                0 \
1601                -c "$maybe_calc_verify" \
1602                -c "calc PSA finished" \
1603                -s "$maybe_calc_verify" \
1604                -s "calc PSA finished" \
1605                -s "Protocol is TLSv1.2" \
1606                -c "Perform PSA-based ECDH computation."\
1607                -c "Perform PSA-based computation of digest of ServerKeyExchange" \
1608                -S "error" \
1609                -C "error"
1610    unset maybe_calc_verify
1611}
1612
1613# Test that the server's memory usage after a handshake is reduced when a client specifies
1614# a maximum fragment length.
1615#  first argument ($1) is MFL for SSL client
1616#  second argument ($2) is memory usage for SSL client with default MFL (16k)
1617run_test_memory_after_hanshake_with_mfl()
1618{
1619    # The test passes if the difference is around 2*(16k-MFL)
1620    MEMORY_USAGE_LIMIT="$(( $2 - ( 2 * ( 16384 - $1 )) ))"
1621
1622    # Leave some margin for robustness
1623    MEMORY_USAGE_LIMIT="$(( ( MEMORY_USAGE_LIMIT * 110 ) / 100 ))"
1624
1625    run_test    "Handshake memory usage (MFL $1)" \
1626                "$P_SRV debug_level=3 auth_mode=required force_version=tls12" \
1627                "$P_CLI debug_level=3 \
1628                    crt_file=data_files/server5.crt key_file=data_files/server5.key \
1629                    force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM max_frag_len=$1" \
1630                0 \
1631                -F "handshake_memory_check $MEMORY_USAGE_LIMIT"
1632}
1633
1634
1635# Test that the server's memory usage after a handshake is reduced when a client specifies
1636# different values of Maximum Fragment Length: default (16k), 4k, 2k, 1k and 512 bytes
1637run_tests_memory_after_hanshake()
1638{
1639    # all tests in this sequence requires the same configuration (see requires_config_enabled())
1640    SKIP_THIS_TESTS="$SKIP_NEXT"
1641
1642    # first test with default MFU is to get reference memory usage
1643    MEMORY_USAGE_MFL_16K=0
1644    run_test    "Handshake memory usage initial (MFL 16384 - default)" \
1645                "$P_SRV debug_level=3 auth_mode=required force_version=tls12" \
1646                "$P_CLI debug_level=3 \
1647                    crt_file=data_files/server5.crt key_file=data_files/server5.key \
1648                    force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM" \
1649                0 \
1650                -F "handshake_memory_get MEMORY_USAGE_MFL_16K"
1651
1652    SKIP_NEXT="$SKIP_THIS_TESTS"
1653    run_test_memory_after_hanshake_with_mfl 4096 "$MEMORY_USAGE_MFL_16K"
1654
1655    SKIP_NEXT="$SKIP_THIS_TESTS"
1656    run_test_memory_after_hanshake_with_mfl 2048 "$MEMORY_USAGE_MFL_16K"
1657
1658    SKIP_NEXT="$SKIP_THIS_TESTS"
1659    run_test_memory_after_hanshake_with_mfl 1024 "$MEMORY_USAGE_MFL_16K"
1660
1661    SKIP_NEXT="$SKIP_THIS_TESTS"
1662    run_test_memory_after_hanshake_with_mfl 512 "$MEMORY_USAGE_MFL_16K"
1663}
1664
1665cleanup() {
1666    rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
1667    rm -f context_srv.txt
1668    rm -f context_cli.txt
1669    test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
1670    test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
1671    test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
1672    test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
1673    exit 1
1674}
1675
1676#
1677# MAIN
1678#
1679
1680get_options "$@"
1681
1682populate_enabled_hash_algs
1683
1684# Optimize filters: if $FILTER and $EXCLUDE can be expressed as shell
1685# patterns rather than regular expressions, use a case statement instead
1686# of calling grep. To keep the optimizer simple, it is incomplete and only
1687# detects simple cases: plain substring, everything, nothing.
1688#
1689# As an exception, the character '.' is treated as an ordinary character
1690# if it is the only special character in the string. This is because it's
1691# rare to need "any one character", but needing a literal '.' is common
1692# (e.g. '-f "DTLS 1.2"').
1693need_grep=
1694case "$FILTER" in
1695    '^$') simple_filter=;;
1696    '.*') simple_filter='*';;
1697    *[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
1698        need_grep=1;;
1699    *) # No regexp or shell-pattern special character
1700        simple_filter="*$FILTER*";;
1701esac
1702case "$EXCLUDE" in
1703    '^$') simple_exclude=;;
1704    '.*') simple_exclude='*';;
1705    *[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
1706        need_grep=1;;
1707    *) # No regexp or shell-pattern special character
1708        simple_exclude="*$EXCLUDE*";;
1709esac
1710if [ -n "$need_grep" ]; then
1711    is_excluded () {
1712        ! echo "$1" | grep "$FILTER" | grep -q -v "$EXCLUDE"
1713    }
1714else
1715    is_excluded () {
1716        case "$1" in
1717            $simple_exclude) true;;
1718            $simple_filter) false;;
1719            *) true;;
1720        esac
1721    }
1722fi
1723
1724# sanity checks, avoid an avalanche of errors
1725P_SRV_BIN="${P_SRV%%[  ]*}"
1726P_CLI_BIN="${P_CLI%%[  ]*}"
1727P_PXY_BIN="${P_PXY%%[  ]*}"
1728if [ ! -x "$P_SRV_BIN" ]; then
1729    echo "Command '$P_SRV_BIN' is not an executable file"
1730    exit 1
1731fi
1732if [ ! -x "$P_CLI_BIN" ]; then
1733    echo "Command '$P_CLI_BIN' is not an executable file"
1734    exit 1
1735fi
1736if [ ! -x "$P_PXY_BIN" ]; then
1737    echo "Command '$P_PXY_BIN' is not an executable file"
1738    exit 1
1739fi
1740if [ "$MEMCHECK" -gt 0 ]; then
1741    if which valgrind >/dev/null 2>&1; then :; else
1742        echo "Memcheck not possible. Valgrind not found"
1743        exit 1
1744    fi
1745fi
1746if which $OPENSSL >/dev/null 2>&1; then :; else
1747    echo "Command '$OPENSSL' not found"
1748    exit 1
1749fi
1750
1751# used by watchdog
1752MAIN_PID="$$"
1753
1754# We use somewhat arbitrary delays for tests:
1755# - how long do we wait for the server to start (when lsof not available)?
1756# - how long do we allow for the client to finish?
1757#   (not to check performance, just to avoid waiting indefinitely)
1758# Things are slower with valgrind, so give extra time here.
1759#
1760# Note: without lsof, there is a trade-off between the running time of this
1761# script and the risk of spurious errors because we didn't wait long enough.
1762# The watchdog delay on the other hand doesn't affect normal running time of
1763# the script, only the case where a client or server gets stuck.
1764if [ "$MEMCHECK" -gt 0 ]; then
1765    START_DELAY=6
1766    DOG_DELAY=60
1767else
1768    START_DELAY=2
1769    DOG_DELAY=20
1770fi
1771
1772# some particular tests need more time:
1773# - for the client, we multiply the usual watchdog limit by a factor
1774# - for the server, we sleep for a number of seconds after the client exits
1775# see client_need_more_time() and server_needs_more_time()
1776CLI_DELAY_FACTOR=1
1777SRV_DELAY_SECONDS=0
1778
1779# fix commands to use this port, force IPv4 while at it
1780# +SRV_PORT will be replaced by either $SRV_PORT or $PXY_PORT later
1781# Note: Using 'localhost' rather than 127.0.0.1 here is unwise, as on many
1782# machines that will resolve to ::1, and we don't want ipv6 here.
1783P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
1784P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
1785P_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"}"
1786O_SRV="$O_SRV -accept $SRV_PORT"
1787O_CLI="$O_CLI -connect 127.0.0.1:+SRV_PORT"
1788G_SRV="$G_SRV -p $SRV_PORT"
1789G_CLI="$G_CLI -p +SRV_PORT"
1790
1791if [ -n "${OPENSSL_LEGACY:-}" ]; then
1792    O_LEGACY_SRV="$O_LEGACY_SRV -accept $SRV_PORT -dhparam data_files/dhparams.pem"
1793    O_LEGACY_CLI="$O_LEGACY_CLI -connect 127.0.0.1:+SRV_PORT"
1794fi
1795
1796# Newer versions of OpenSSL have a syntax to enable all "ciphers", even
1797# low-security ones. This covers not just cipher suites but also protocol
1798# versions. It is necessary, for example, to use (D)TLS 1.0/1.1 on
1799# OpenSSL 1.1.1f from Ubuntu 20.04. The syntax was only introduced in
1800# OpenSSL 1.1.0 (21e0c1d23afff48601eb93135defddae51f7e2e3) and I can't find
1801# a way to discover it from -help, so check the openssl version.
1802case $($OPENSSL version) in
1803    "OpenSSL 0"*|"OpenSSL 1.0"*) :;;
1804    *)
1805        O_CLI="$O_CLI -cipher ALL@SECLEVEL=0"
1806        O_SRV="$O_SRV -cipher ALL@SECLEVEL=0"
1807        ;;
1808esac
1809
1810if [ -n "${OPENSSL_NEXT:-}" ]; then
1811    O_NEXT_SRV="$O_NEXT_SRV -accept $SRV_PORT"
1812    O_NEXT_SRV_NO_CERT="$O_NEXT_SRV_NO_CERT -accept $SRV_PORT"
1813    O_NEXT_SRV_EARLY_DATA="$O_NEXT_SRV_EARLY_DATA -accept $SRV_PORT"
1814    O_NEXT_CLI="$O_NEXT_CLI -connect 127.0.0.1:+SRV_PORT"
1815    O_NEXT_CLI_NO_CERT="$O_NEXT_CLI_NO_CERT -connect 127.0.0.1:+SRV_PORT"
1816fi
1817
1818if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
1819    G_NEXT_SRV="$G_NEXT_SRV -p $SRV_PORT"
1820    G_NEXT_SRV_NO_CERT="$G_NEXT_SRV_NO_CERT -p $SRV_PORT"
1821fi
1822
1823if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
1824    G_NEXT_CLI="$G_NEXT_CLI -p +SRV_PORT"
1825    G_NEXT_CLI_NO_CERT="$G_NEXT_CLI_NO_CERT -p +SRV_PORT localhost"
1826fi
1827
1828# Allow SHA-1, because many of our test certificates use it
1829P_SRV="$P_SRV allow_sha1=1"
1830P_CLI="$P_CLI allow_sha1=1"
1831
1832# Also pick a unique name for intermediate files
1833SRV_OUT="srv_out.$$"
1834CLI_OUT="cli_out.$$"
1835PXY_OUT="pxy_out.$$"
1836SESSION="session.$$"
1837
1838SKIP_NEXT="NO"
1839
1840trap cleanup INT TERM HUP
1841
1842# Basic test
1843
1844# Checks that:
1845# - things work with all ciphersuites active (used with config-full in all.sh)
1846# - the expected parameters are selected
1847requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1848requires_ciphersuite_enabled TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256
1849requires_hash_alg SHA_512 # "signature_algorithm ext: 6"
1850requires_config_enabled MBEDTLS_ECP_DP_CURVE25519_ENABLED
1851run_test    "Default" \
1852            "$P_SRV debug_level=3" \
1853            "$P_CLI" \
1854            0 \
1855            -s "Protocol is TLSv1.2" \
1856            -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256" \
1857            -s "client hello v3, signature_algorithm ext: 6" \
1858            -s "ECDHE curve: x25519" \
1859            -S "error" \
1860            -C "error"
1861
1862requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1863requires_ciphersuite_enabled TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256
1864run_test    "Default, DTLS" \
1865            "$P_SRV dtls=1" \
1866            "$P_CLI dtls=1" \
1867            0 \
1868            -s "Protocol is DTLSv1.2" \
1869            -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256"
1870
1871requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1872run_test    "TLS client auth: required" \
1873            "$P_SRV auth_mode=required" \
1874            "$P_CLI" \
1875            0 \
1876            -s "Verifying peer X.509 certificate... ok"
1877
1878requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1879run_test    "key size: TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
1880            "$P_SRV" \
1881            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
1882            0 \
1883            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
1884            -c "Key size is 256"
1885
1886requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1887run_test    "key size: TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
1888            "$P_SRV" \
1889            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
1890            0 \
1891            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
1892            -c "Key size is 128"
1893
1894requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1895requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1896requires_hash_alg SHA_256
1897run_test    "TLS: password protected client key" \
1898            "$P_SRV auth_mode=required" \
1899            "$P_CLI crt_file=data_files/server5.crt key_file=data_files/server5.key.enc key_pwd=PolarSSLTest" \
1900            0
1901
1902requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1903requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1904requires_hash_alg SHA_256
1905run_test    "TLS: password protected server key" \
1906            "$P_SRV crt_file=data_files/server5.crt key_file=data_files/server5.key.enc key_pwd=PolarSSLTest" \
1907            "$P_CLI" \
1908            0
1909
1910requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1911requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1912requires_config_enabled MBEDTLS_RSA_C
1913requires_hash_alg SHA_256
1914run_test    "TLS: password protected server key, two certificates" \
1915            "$P_SRV \
1916              key_file=data_files/server5.key.enc key_pwd=PolarSSLTest crt_file=data_files/server5.crt \
1917              key_file2=data_files/server2.key.enc key_pwd2=PolarSSLTest crt_file2=data_files/server2.crt" \
1918            "$P_CLI" \
1919            0
1920
1921requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1922requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1923run_test    "CA callback on client" \
1924            "$P_SRV debug_level=3" \
1925            "$P_CLI ca_callback=1 debug_level=3 " \
1926            0 \
1927            -c "use CA callback for X.509 CRT verification" \
1928            -S "error" \
1929            -C "error"
1930
1931requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1932requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1933requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1934requires_hash_alg SHA_256
1935run_test    "CA callback on server" \
1936            "$P_SRV auth_mode=required" \
1937            "$P_CLI ca_callback=1 debug_level=3 crt_file=data_files/server5.crt \
1938             key_file=data_files/server5.key" \
1939            0 \
1940            -c "use CA callback for X.509 CRT verification" \
1941            -s "Verifying peer X.509 certificate... ok" \
1942            -S "error" \
1943            -C "error"
1944
1945# Test using an EC opaque private key for client authentication
1946requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1947requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1948requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1949requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1950requires_hash_alg SHA_256
1951run_test    "Opaque key for client authentication: ECDHE-ECDSA" \
1952            "$P_SRV auth_mode=required crt_file=data_files/server5.crt \
1953             key_file=data_files/server5.key" \
1954            "$P_CLI key_opaque=1 crt_file=data_files/server5.crt \
1955             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
1956            0 \
1957            -c "key type: Opaque" \
1958            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
1959            -s "Verifying peer X.509 certificate... ok" \
1960            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
1961            -S "error" \
1962            -C "error"
1963
1964# Test using a RSA opaque private key for client authentication
1965requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1966requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1967requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1968requires_config_enabled MBEDTLS_RSA_C
1969requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1970requires_hash_alg SHA_256
1971run_test    "Opaque key for client authentication: ECDHE-RSA" \
1972            "$P_SRV auth_mode=required crt_file=data_files/server2-sha256.crt \
1973             key_file=data_files/server2.key" \
1974            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
1975             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
1976            0 \
1977            -c "key type: Opaque" \
1978            -c "Ciphersuite is TLS-ECDHE-RSA" \
1979            -s "Verifying peer X.509 certificate... ok" \
1980            -s "Ciphersuite is TLS-ECDHE-RSA" \
1981            -S "error" \
1982            -C "error"
1983
1984requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1985requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1986requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1987requires_config_enabled MBEDTLS_RSA_C
1988requires_hash_alg SHA_256
1989run_test    "Opaque key for client authentication: DHE-RSA" \
1990            "$P_SRV auth_mode=required crt_file=data_files/server2-sha256.crt \
1991             key_file=data_files/server2.key" \
1992            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
1993             key_file=data_files/server2.key force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1994             key_opaque_algs=rsa-sign-pkcs1,none" \
1995            0 \
1996            -c "key type: Opaque" \
1997            -c "Ciphersuite is TLS-DHE-RSA" \
1998            -s "Verifying peer X.509 certificate... ok" \
1999            -s "Ciphersuite is TLS-DHE-RSA" \
2000            -S "error" \
2001            -C "error"
2002
2003# Test using an EC opaque private key for server authentication
2004requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2005requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2006requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2007requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2008requires_hash_alg SHA_256
2009run_test    "Opaque key for server authentication: ECDHE-ECDSA" \
2010            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2011             key_file=data_files/server5.key  key_opaque_algs=ecdsa-sign,none" \
2012            "$P_CLI" \
2013            0 \
2014            -c "Verifying peer X.509 certificate... ok" \
2015            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2016            -s "key types: Opaque, none" \
2017            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2018            -S "error" \
2019            -C "error"
2020
2021requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2022requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2023requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2024requires_hash_alg SHA_256
2025run_test    "Opaque key for server authentication: ECDH-" \
2026            "$P_SRV force_version=tls12 auth_mode=required key_opaque=1\
2027             crt_file=data_files/server5.ku-ka.crt\
2028             key_file=data_files/server5.key key_opaque_algs=ecdh,none" \
2029            "$P_CLI" \
2030            0 \
2031            -c "Verifying peer X.509 certificate... ok" \
2032            -c "Ciphersuite is TLS-ECDH-" \
2033            -s "key types: Opaque, none" \
2034            -s "Ciphersuite is TLS-ECDH-" \
2035            -S "error" \
2036            -C "error"
2037
2038requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2039requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2040requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2041requires_config_disabled MBEDTLS_SSL_ASYNC_PRIVATE
2042requires_hash_alg SHA_256
2043run_test    "Opaque key for server authentication: invalid key: decrypt with ECC key, no async" \
2044            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2045             key_file=data_files/server5.key key_opaque_algs=rsa-decrypt,none \
2046             debug_level=1" \
2047            "$P_CLI" \
2048            1 \
2049            -s "key types: Opaque, none" \
2050            -s "error" \
2051            -c "error" \
2052            -c "Public key type mismatch"
2053
2054requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2055requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2056requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2057requires_config_enabled MBEDTLS_ECDSA_C
2058requires_config_enabled MBEDTLS_RSA_C
2059requires_config_disabled MBEDTLS_SSL_ASYNC_PRIVATE
2060requires_hash_alg SHA_256
2061run_test    "Opaque key for server authentication: invalid key: ecdh with RSA key, no async" \
2062            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2063             key_file=data_files/server2.key key_opaque_algs=ecdh,none \
2064             debug_level=1" \
2065            "$P_CLI" \
2066            1 \
2067            -s "key types: Opaque, none" \
2068            -s "error" \
2069            -c "error" \
2070            -c "Public key type mismatch"
2071
2072requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2073requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2074requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2075requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
2076requires_hash_alg SHA_256
2077run_test    "Opaque key for server authentication: invalid alg: decrypt with ECC key, async" \
2078            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2079             key_file=data_files/server5.key key_opaque_algs=rsa-decrypt,none \
2080             debug_level=1" \
2081            "$P_CLI" \
2082            1 \
2083            -s "key types: Opaque, none" \
2084            -s "got ciphersuites in common, but none of them usable" \
2085            -s "error" \
2086            -c "error"
2087
2088requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2089requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2090requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2091requires_config_enabled MBEDTLS_RSA_C
2092requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
2093requires_hash_alg SHA_256
2094run_test    "Opaque key for server authentication: invalid alg: ecdh with RSA key, async" \
2095            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2096             key_file=data_files/server2.key key_opaque_algs=ecdh,none \
2097             debug_level=1" \
2098            "$P_CLI" \
2099            1 \
2100            -s "key types: Opaque, none" \
2101            -s "got ciphersuites in common, but none of them usable" \
2102            -s "error" \
2103            -c "error"
2104
2105requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2106requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2107requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2108requires_hash_alg SHA_256
2109requires_config_enabled MBEDTLS_CCM_C
2110run_test    "Opaque key for server authentication: invalid alg: ECDHE-ECDSA with ecdh" \
2111            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2112             key_file=data_files/server5.key key_opaque_algs=ecdh,none \
2113             debug_level=1" \
2114            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-CCM" \
2115            1 \
2116            -s "key types: Opaque, none" \
2117            -s "got ciphersuites in common, but none of them usable" \
2118            -s "error" \
2119            -c "error"
2120
2121requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2122requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2123requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2124requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2125requires_hash_alg SHA_256
2126requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2127run_test    "Opaque keys for server authentication: EC keys with different algs, force ECDHE-ECDSA" \
2128            "$P_SRV key_opaque=1 crt_file=data_files/server7.crt \
2129             key_file=data_files/server7.key key_opaque_algs=ecdh,none \
2130             crt_file2=data_files/server5.crt key_file2=data_files/server5.key \
2131             key_opaque_algs2=ecdsa-sign,none" \
2132            "$P_CLI" \
2133            0 \
2134            -c "Verifying peer X.509 certificate... ok" \
2135            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2136            -c "CN=Polarssl Test EC CA" \
2137            -s "key types: Opaque, Opaque" \
2138            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2139            -S "error" \
2140            -C "error"
2141
2142requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2143requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2144requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2145requires_hash_alg SHA_384
2146requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2147run_test    "Opaque keys for server authentication: EC keys with different algs, force ECDH-ECDSA" \
2148            "$P_SRV key_opaque=1 crt_file=data_files/server7.crt \
2149             key_file=data_files/server7.key key_opaque_algs=ecdsa-sign,none \
2150             crt_file2=data_files/server5.crt key_file2=data_files/server5.key \
2151             key_opaque_algs2=ecdh,none debug_level=3" \
2152            "$P_CLI force_ciphersuite=TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384" \
2153            0 \
2154            -c "Verifying peer X.509 certificate... ok" \
2155            -c "Ciphersuite is TLS-ECDH-ECDSA" \
2156            -c "CN=Polarssl Test EC CA" \
2157            -s "key types: Opaque, Opaque" \
2158            -s "Ciphersuite is TLS-ECDH-ECDSA" \
2159            -S "error" \
2160            -C "error"
2161
2162requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2163requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2164requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2165requires_hash_alg SHA_384
2166requires_config_enabled MBEDTLS_CCM_C
2167requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2168run_test    "Opaque keys for server authentication: EC + RSA, force ECDHE-ECDSA" \
2169            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2170             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none \
2171             crt_file2=data_files/server2-sha256.crt \
2172             key_file2=data_files/server2.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2173            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-CCM" \
2174            0 \
2175            -c "Verifying peer X.509 certificate... ok" \
2176            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2177            -c "CN=Polarssl Test EC CA" \
2178            -s "key types: Opaque, Opaque" \
2179            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2180            -S "error" \
2181            -C "error"
2182
2183requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2184requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2185requires_config_enabled MBEDTLS_RSA_C
2186requires_config_enabled MBEDTLS_SSL_SRV_C
2187requires_config_enabled MBEDTLS_SSL_CLI_C
2188run_test    "TLS 1.3 opaque key: no suitable algorithm found" \
2189            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required key_opaque=1 key_opaque_algs=rsa-decrypt,none" \
2190            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2191            1 \
2192            -s "The SSL configuration is tls13 only" \
2193            -c "key type: Opaque" \
2194            -s "key types: Opaque, Opaque" \
2195            -c "error" \
2196            -s "no suitable signature algorithm"
2197
2198requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2199requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2200requires_config_enabled MBEDTLS_RSA_C
2201requires_config_enabled MBEDTLS_SSL_SRV_C
2202requires_config_enabled MBEDTLS_SSL_CLI_C
2203run_test    "TLS 1.3 opaque key: suitable algorithm found" \
2204            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2205            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2206            0 \
2207            -s "The SSL configuration is tls13 only" \
2208            -c "key type: Opaque" \
2209            -s "key types: Opaque, Opaque" \
2210            -C "error" \
2211            -S "error"
2212
2213requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2214requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2215requires_config_enabled MBEDTLS_RSA_C
2216requires_config_enabled MBEDTLS_SSL_SRV_C
2217requires_config_enabled MBEDTLS_SSL_CLI_C
2218run_test    "TLS 1.3 opaque key: first client sig alg not suitable" \
2219            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required key_opaque=1 key_opaque_algs=rsa-sign-pss-sha512,none" \
2220            "$P_CLI debug_level=4 sig_algs=rsa_pss_rsae_sha256,rsa_pss_rsae_sha512" \
2221            0 \
2222            -s "The SSL configuration is tls13 only" \
2223            -s "key types: Opaque, Opaque" \
2224            -s "CertificateVerify signature failed with rsa_pss_rsae_sha256" \
2225            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
2226            -C "error" \
2227            -S "error" \
2228
2229requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2230requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2231requires_config_enabled MBEDTLS_RSA_C
2232requires_config_enabled MBEDTLS_SSL_SRV_C
2233requires_config_enabled MBEDTLS_SSL_CLI_C
2234run_test    "TLS 1.3 opaque key: 2 keys on server, suitable algorithm found" \
2235            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required key_opaque=1 key_opaque_algs2=ecdsa-sign,none key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2236            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2237            0 \
2238            -s "The SSL configuration is tls13 only" \
2239            -c "key type: Opaque" \
2240            -s "key types: Opaque, Opaque" \
2241            -C "error" \
2242            -S "error" \
2243
2244# Test using a RSA opaque private key for server authentication
2245requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2246requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2247requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2248requires_config_enabled MBEDTLS_RSA_C
2249requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2250requires_hash_alg SHA_256
2251run_test    "Opaque key for server authentication: ECDHE-RSA" \
2252            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2253             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
2254            "$P_CLI" \
2255            0 \
2256            -c "Verifying peer X.509 certificate... ok" \
2257            -c "Ciphersuite is TLS-ECDHE-RSA" \
2258            -s "key types: Opaque, none" \
2259            -s "Ciphersuite is TLS-ECDHE-RSA" \
2260            -S "error" \
2261            -C "error"
2262
2263requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2264requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2265requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2266requires_config_enabled MBEDTLS_RSA_C
2267requires_hash_alg SHA_256
2268run_test    "Opaque key for server authentication: DHE-RSA" \
2269            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2270             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
2271            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2272            0 \
2273            -c "Verifying peer X.509 certificate... ok" \
2274            -c "Ciphersuite is TLS-DHE-RSA" \
2275            -s "key types: Opaque, none" \
2276            -s "Ciphersuite is TLS-DHE-RSA" \
2277            -S "error" \
2278            -C "error"
2279
2280requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2281requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2282requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2283requires_config_enabled MBEDTLS_RSA_C
2284requires_hash_alg SHA_256
2285run_test    "Opaque key for server authentication: RSA-PSK" \
2286            "$P_SRV debug_level=1 key_opaque=1 key_opaque_algs=rsa-decrypt,none \
2287             psk=abc123 psk_identity=foo" \
2288            "$P_CLI force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256 \
2289             psk=abc123 psk_identity=foo" \
2290            0 \
2291            -c "Verifying peer X.509 certificate... ok" \
2292            -c "Ciphersuite is TLS-RSA-PSK-" \
2293            -s "key types: Opaque, Opaque" \
2294            -s "Ciphersuite is TLS-RSA-PSK-" \
2295            -S "error" \
2296            -C "error"
2297
2298requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2299requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2300requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2301requires_config_enabled MBEDTLS_RSA_C
2302requires_hash_alg SHA_256
2303run_test    "Opaque key for server authentication: RSA-" \
2304            "$P_SRV debug_level=3 key_opaque=1 key_opaque_algs=rsa-decrypt,none " \
2305            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA256" \
2306            0 \
2307            -c "Verifying peer X.509 certificate... ok" \
2308            -c "Ciphersuite is TLS-RSA-" \
2309            -s "key types: Opaque, Opaque" \
2310            -s "Ciphersuite is TLS-RSA-" \
2311            -S "error" \
2312            -C "error"
2313
2314requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2315requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2316requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2317requires_config_enabled MBEDTLS_RSA_C
2318requires_hash_alg SHA_256
2319run_test    "Opaque key for server authentication: DHE-RSA, PSS instead of PKCS1" \
2320            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2321             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pss,none debug_level=1" \
2322            "$P_CLI crt_file=data_files/server2-sha256.crt \
2323             key_file=data_files/server2.key force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2324            1 \
2325            -s "key types: Opaque, none" \
2326            -s "got ciphersuites in common, but none of them usable" \
2327            -s "error" \
2328            -c "error"
2329
2330requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2331requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2332requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2333requires_config_enabled MBEDTLS_RSA_C
2334requires_hash_alg SHA_256
2335requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2336requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2337run_test    "Opaque keys for server authentication: RSA keys with different algs" \
2338            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2339             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pss,none \
2340             crt_file2=data_files/server4.crt \
2341             key_file2=data_files/server4.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2342            "$P_CLI" \
2343            0 \
2344            -c "Verifying peer X.509 certificate... ok" \
2345            -c "Ciphersuite is TLS-ECDHE-RSA" \
2346            -c "CN=Polarssl Test EC CA" \
2347            -s "key types: Opaque, Opaque" \
2348            -s "Ciphersuite is TLS-ECDHE-RSA" \
2349            -S "error" \
2350            -C "error"
2351
2352requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2353requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2354requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2355requires_config_enabled MBEDTLS_RSA_C
2356requires_hash_alg SHA_384
2357requires_config_enabled MBEDTLS_GCM_C
2358requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2359run_test    "Opaque keys for server authentication: EC + RSA, force DHE-RSA" \
2360            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server5.crt \
2361             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none \
2362             crt_file2=data_files/server4.crt \
2363             key_file2=data_files/server4.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2364            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2365            0 \
2366            -c "Verifying peer X.509 certificate... ok" \
2367            -c "Ciphersuite is TLS-DHE-RSA" \
2368            -c "CN=Polarssl Test EC CA" \
2369            -s "key types: Opaque, Opaque" \
2370            -s "Ciphersuite is TLS-DHE-RSA" \
2371            -S "error" \
2372            -C "error"
2373
2374# Test using an EC opaque private key for client/server authentication
2375requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2376requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2377requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2378requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2379requires_hash_alg SHA_256
2380run_test    "Opaque key for client/server authentication: ECDHE-ECDSA" \
2381            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server5.crt \
2382             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
2383            "$P_CLI key_opaque=1 crt_file=data_files/server5.crt \
2384             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
2385            0 \
2386            -c "key type: Opaque" \
2387            -c "Verifying peer X.509 certificate... ok" \
2388            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2389            -s "key types: Opaque, none" \
2390            -s "Verifying peer X.509 certificate... ok" \
2391            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2392            -S "error" \
2393            -C "error"
2394
2395# Test using a RSA opaque private key for client/server authentication
2396requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2397requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2398requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2399requires_config_enabled MBEDTLS_RSA_C
2400requires_hash_alg SHA_256
2401requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2402run_test    "Opaque key for client/server authentication: ECDHE-RSA" \
2403            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2404             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2405            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
2406             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2407            0 \
2408            -c "key type: Opaque" \
2409            -c "Verifying peer X.509 certificate... ok" \
2410            -c "Ciphersuite is TLS-ECDHE-RSA" \
2411            -s "key types: Opaque, none" \
2412            -s "Verifying peer X.509 certificate... ok" \
2413            -s "Ciphersuite is TLS-ECDHE-RSA" \
2414            -S "error" \
2415            -C "error"
2416
2417requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2418requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2419requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2420requires_config_enabled MBEDTLS_RSA_C
2421requires_hash_alg SHA_256
2422run_test    "Opaque key for client/server authentication: DHE-RSA" \
2423            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2424             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2425            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
2426             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none \
2427             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2428            0 \
2429            -c "key type: Opaque" \
2430            -c "Verifying peer X.509 certificate... ok" \
2431            -c "Ciphersuite is TLS-DHE-RSA" \
2432            -s "key types: Opaque, none" \
2433            -s "Verifying peer X.509 certificate... ok" \
2434            -s "Ciphersuite is TLS-DHE-RSA" \
2435            -S "error" \
2436            -C "error"
2437
2438
2439# Test ciphersuites which we expect to be fully supported by PSA Crypto
2440# and check that we don't fall back to Mbed TLS' internal crypto primitives.
2441run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CCM
2442run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8
2443run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CCM
2444run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CCM-8
2445run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
2446run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384
2447run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA
2448run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256
2449run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384
2450
2451requires_config_enabled MBEDTLS_ECP_DP_SECP521R1_ENABLED
2452run_test_psa_force_curve "secp521r1"
2453requires_config_enabled MBEDTLS_ECP_DP_BP512R1_ENABLED
2454run_test_psa_force_curve "brainpoolP512r1"
2455requires_config_enabled MBEDTLS_ECP_DP_SECP384R1_ENABLED
2456run_test_psa_force_curve "secp384r1"
2457requires_config_enabled MBEDTLS_ECP_DP_BP384R1_ENABLED
2458run_test_psa_force_curve "brainpoolP384r1"
2459requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
2460run_test_psa_force_curve "secp256r1"
2461requires_config_enabled MBEDTLS_ECP_DP_SECP256K1_ENABLED
2462run_test_psa_force_curve "secp256k1"
2463requires_config_enabled MBEDTLS_ECP_DP_BP256R1_ENABLED
2464run_test_psa_force_curve "brainpoolP256r1"
2465requires_config_enabled MBEDTLS_ECP_DP_SECP224R1_ENABLED
2466run_test_psa_force_curve "secp224r1"
2467## SECP224K1 is buggy via the PSA API
2468## (https://github.com/Mbed-TLS/mbedtls/issues/3541),
2469## so it is disabled in PSA even when it's enabled in Mbed TLS.
2470## The proper dependency would be on PSA_WANT_ECC_SECP_K1_224 but
2471## dependencies on PSA symbols in ssl-opt.sh are not implemented yet.
2472#requires_config_enabled MBEDTLS_ECP_DP_SECP224K1_ENABLED
2473#run_test_psa_force_curve "secp224k1"
2474requires_config_enabled MBEDTLS_ECP_DP_SECP192R1_ENABLED
2475run_test_psa_force_curve "secp192r1"
2476requires_config_enabled MBEDTLS_ECP_DP_SECP192K1_ENABLED
2477run_test_psa_force_curve "secp192k1"
2478
2479# Test current time in ServerHello
2480requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2481requires_config_enabled MBEDTLS_HAVE_TIME
2482run_test    "ServerHello contains gmt_unix_time" \
2483            "$P_SRV debug_level=3" \
2484            "$P_CLI debug_level=3" \
2485            0 \
2486            -f "check_server_hello_time" \
2487            -F "check_server_hello_time"
2488
2489# Test for uniqueness of IVs in AEAD ciphersuites
2490requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2491run_test    "Unique IV in GCM" \
2492            "$P_SRV exchanges=20 debug_level=4" \
2493            "$P_CLI exchanges=20 debug_level=4 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
2494            0 \
2495            -u "IV used" \
2496            -U "IV used"
2497
2498# Test for correctness of sent single supported algorithm
2499requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
2500requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2501requires_config_enabled MBEDTLS_DEBUG_C
2502requires_config_enabled MBEDTLS_SSL_CLI_C
2503requires_config_enabled MBEDTLS_SSL_SRV_C
2504requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
2505requires_pk_alg "ECDSA"
2506requires_hash_alg SHA_256
2507run_test    "Single supported algorithm sending: mbedtls client" \
2508            "$P_SRV sig_algs=ecdsa_secp256r1_sha256 auth_mode=required" \
2509            "$P_CLI sig_algs=ecdsa_secp256r1_sha256 debug_level=3" \
2510            0 \
2511            -c "Supported Signature Algorithm found: 04 03"
2512
2513requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2514requires_config_enabled MBEDTLS_SSL_SRV_C
2515requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
2516requires_hash_alg SHA_256
2517run_test    "Single supported algorithm sending: openssl client" \
2518            "$P_SRV sig_algs=ecdsa_secp256r1_sha256 auth_mode=required" \
2519            "$O_CLI -cert data_files/server6.crt \
2520                    -key data_files/server6.key" \
2521            0
2522
2523# Tests for certificate verification callback
2524requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2525run_test    "Configuration-specific CRT verification callback" \
2526            "$P_SRV debug_level=3" \
2527            "$P_CLI context_crt_cb=0 debug_level=3" \
2528            0 \
2529            -S "error" \
2530            -c "Verify requested for " \
2531            -c "Use configuration-specific verification callback" \
2532            -C "Use context-specific verification callback" \
2533            -C "error"
2534
2535requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2536run_test    "Context-specific CRT verification callback" \
2537            "$P_SRV debug_level=3" \
2538            "$P_CLI context_crt_cb=1 debug_level=3" \
2539            0 \
2540            -S "error" \
2541            -c "Verify requested for " \
2542            -c "Use context-specific verification callback" \
2543            -C "Use configuration-specific verification callback" \
2544            -C "error"
2545
2546# Tests for SHA-1 support
2547requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2548run_test    "SHA-1 forbidden by default in server certificate" \
2549            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
2550            "$P_CLI debug_level=2 allow_sha1=0" \
2551            1 \
2552            -c "The certificate is signed with an unacceptable hash"
2553
2554requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2555run_test    "SHA-1 explicitly allowed in server certificate" \
2556            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
2557            "$P_CLI allow_sha1=1" \
2558            0
2559
2560requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2561run_test    "SHA-256 allowed by default in server certificate" \
2562            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2-sha256.crt" \
2563            "$P_CLI allow_sha1=0" \
2564            0
2565
2566requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2567run_test    "SHA-1 forbidden by default in client certificate" \
2568            "$P_SRV auth_mode=required allow_sha1=0" \
2569            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
2570            1 \
2571            -s "The certificate is signed with an unacceptable hash"
2572
2573requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2574run_test    "SHA-1 explicitly allowed in client certificate" \
2575            "$P_SRV auth_mode=required allow_sha1=1" \
2576            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
2577            0
2578
2579requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2580run_test    "SHA-256 allowed by default in client certificate" \
2581            "$P_SRV auth_mode=required allow_sha1=0" \
2582            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha256.crt" \
2583            0
2584
2585# Dummy TLS 1.3 test
2586# Currently only checking that passing TLS 1.3 key exchange modes to
2587# ssl_client2/ssl_server2 example programs works.
2588requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2589requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2590requires_config_enabled MBEDTLS_SSL_CLI_C
2591requires_config_enabled MBEDTLS_SSL_SRV_C
2592run_test    "TLS 1.3: key exchange mode parameter passing: PSK only" \
2593            "$P_SRV tls13_kex_modes=psk debug_level=4" \
2594            "$P_CLI tls13_kex_modes=psk debug_level=4" \
2595            0
2596
2597requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2598requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2599requires_config_enabled MBEDTLS_SSL_CLI_C
2600requires_config_enabled MBEDTLS_SSL_SRV_C
2601run_test    "TLS 1.3: key exchange mode parameter passing: PSK-ephemeral only" \
2602            "$P_SRV tls13_kex_modes=psk_ephemeral" \
2603            "$P_CLI tls13_kex_modes=psk_ephemeral" \
2604            0
2605
2606requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2607requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2608requires_config_enabled MBEDTLS_SSL_CLI_C
2609requires_config_enabled MBEDTLS_SSL_SRV_C
2610run_test    "TLS 1.3: key exchange mode parameter passing: Pure-ephemeral only" \
2611            "$P_SRV tls13_kex_modes=ephemeral" \
2612            "$P_CLI tls13_kex_modes=ephemeral" \
2613            0
2614
2615requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2616requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2617requires_config_enabled MBEDTLS_SSL_CLI_C
2618requires_config_enabled MBEDTLS_SSL_SRV_C
2619run_test    "TLS 1.3: key exchange mode parameter passing: All ephemeral" \
2620            "$P_SRV tls13_kex_modes=ephemeral_all" \
2621            "$P_CLI tls13_kex_modes=ephemeral_all" \
2622            0
2623
2624requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2625requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2626requires_config_enabled MBEDTLS_SSL_CLI_C
2627requires_config_enabled MBEDTLS_SSL_SRV_C
2628run_test    "TLS 1.3: key exchange mode parameter passing: All PSK" \
2629            "$P_SRV tls13_kex_modes=psk_all" \
2630            "$P_CLI tls13_kex_modes=psk_all" \
2631            0
2632
2633requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2634requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2635requires_config_enabled MBEDTLS_SSL_CLI_C
2636requires_config_enabled MBEDTLS_SSL_SRV_C
2637run_test    "TLS 1.3: key exchange mode parameter passing: All" \
2638            "$P_SRV tls13_kex_modes=all" \
2639            "$P_CLI tls13_kex_modes=all" \
2640            0
2641
2642# Tests for datagram packing
2643requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2644run_test    "DTLS: multiple records in same datagram, client and server" \
2645            "$P_SRV dtls=1 dgram_packing=1 debug_level=2" \
2646            "$P_CLI dtls=1 dgram_packing=1 debug_level=2" \
2647            0 \
2648            -c "next record in same datagram" \
2649            -s "next record in same datagram"
2650
2651requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2652run_test    "DTLS: multiple records in same datagram, client only" \
2653            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
2654            "$P_CLI dtls=1 dgram_packing=1 debug_level=2" \
2655            0 \
2656            -s "next record in same datagram" \
2657            -C "next record in same datagram"
2658
2659requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2660run_test    "DTLS: multiple records in same datagram, server only" \
2661            "$P_SRV dtls=1 dgram_packing=1 debug_level=2" \
2662            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
2663            0 \
2664            -S "next record in same datagram" \
2665            -c "next record in same datagram"
2666
2667requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2668run_test    "DTLS: multiple records in same datagram, neither client nor server" \
2669            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
2670            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
2671            0 \
2672            -S "next record in same datagram" \
2673            -C "next record in same datagram"
2674
2675# Tests for Context serialization
2676
2677requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2678requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2679run_test    "Context serialization, client serializes, CCM" \
2680            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2681            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2682            0 \
2683            -c "Deserializing connection..." \
2684            -S "Deserializing connection..."
2685
2686requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2687requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2688run_test    "Context serialization, client serializes, ChaChaPoly" \
2689            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2690            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2691            0 \
2692            -c "Deserializing connection..." \
2693            -S "Deserializing connection..."
2694
2695requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2696requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2697run_test    "Context serialization, client serializes, GCM" \
2698            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2699            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2700            0 \
2701            -c "Deserializing connection..." \
2702            -S "Deserializing connection..."
2703
2704requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2705requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2706requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2707run_test    "Context serialization, client serializes, with CID" \
2708            "$P_SRV dtls=1 serialize=0 exchanges=2 cid=1 cid_val=dead" \
2709            "$P_CLI dtls=1 serialize=1 exchanges=2 cid=1 cid_val=beef" \
2710            0 \
2711            -c "Deserializing connection..." \
2712            -S "Deserializing connection..."
2713
2714requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2715run_test    "Context serialization, server serializes, CCM" \
2716            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2717            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2718            0 \
2719            -C "Deserializing connection..." \
2720            -s "Deserializing connection..."
2721
2722requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2723requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2724run_test    "Context serialization, server serializes, ChaChaPoly" \
2725            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2726            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2727            0 \
2728            -C "Deserializing connection..." \
2729            -s "Deserializing connection..."
2730
2731requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2732requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2733run_test    "Context serialization, server serializes, GCM" \
2734            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2735            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2736            0 \
2737            -C "Deserializing connection..." \
2738            -s "Deserializing connection..."
2739
2740requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2741requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2742requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2743run_test    "Context serialization, server serializes, with CID" \
2744            "$P_SRV dtls=1 serialize=1 exchanges=2 cid=1 cid_val=dead" \
2745            "$P_CLI dtls=1 serialize=0 exchanges=2 cid=1 cid_val=beef" \
2746            0 \
2747            -C "Deserializing connection..." \
2748            -s "Deserializing connection..."
2749
2750requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2751requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2752run_test    "Context serialization, both serialize, CCM" \
2753            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2754            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2755            0 \
2756            -c "Deserializing connection..." \
2757            -s "Deserializing connection..."
2758
2759requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2760requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2761run_test    "Context serialization, both serialize, ChaChaPoly" \
2762            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2763            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2764            0 \
2765            -c "Deserializing connection..." \
2766            -s "Deserializing connection..."
2767
2768requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2769requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2770run_test    "Context serialization, both serialize, GCM" \
2771            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2772            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2773            0 \
2774            -c "Deserializing connection..." \
2775            -s "Deserializing connection..."
2776
2777requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2778requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2779requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2780run_test    "Context serialization, both serialize, with CID" \
2781            "$P_SRV dtls=1 serialize=1 exchanges=2 cid=1 cid_val=dead" \
2782            "$P_CLI dtls=1 serialize=1 exchanges=2 cid=1 cid_val=beef" \
2783            0 \
2784            -c "Deserializing connection..." \
2785            -s "Deserializing connection..."
2786
2787requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2788run_test    "Context serialization, re-init, client serializes, CCM" \
2789            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2790            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2791            0 \
2792            -c "Deserializing connection..." \
2793            -S "Deserializing connection..."
2794
2795requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2796requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2797run_test    "Context serialization, re-init, client serializes, ChaChaPoly" \
2798            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2799            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2800            0 \
2801            -c "Deserializing connection..." \
2802            -S "Deserializing connection..."
2803
2804requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2805requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2806run_test    "Context serialization, re-init, client serializes, GCM" \
2807            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2808            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2809            0 \
2810            -c "Deserializing connection..." \
2811            -S "Deserializing connection..."
2812
2813requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2814requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2815requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2816run_test    "Context serialization, re-init, client serializes, with CID" \
2817            "$P_SRV dtls=1 serialize=0 exchanges=2 cid=1 cid_val=dead" \
2818            "$P_CLI dtls=1 serialize=2 exchanges=2 cid=1 cid_val=beef" \
2819            0 \
2820            -c "Deserializing connection..." \
2821            -S "Deserializing connection..."
2822
2823requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2824run_test    "Context serialization, re-init, server serializes, CCM" \
2825            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2826            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2827            0 \
2828            -C "Deserializing connection..." \
2829            -s "Deserializing connection..."
2830
2831requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2832requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2833run_test    "Context serialization, re-init, server serializes, ChaChaPoly" \
2834            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2835            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2836            0 \
2837            -C "Deserializing connection..." \
2838            -s "Deserializing connection..."
2839
2840requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2841requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2842run_test    "Context serialization, re-init, server serializes, GCM" \
2843            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2844            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2845            0 \
2846            -C "Deserializing connection..." \
2847            -s "Deserializing connection..."
2848
2849requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2850requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2851requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2852run_test    "Context serialization, re-init, server serializes, with CID" \
2853            "$P_SRV dtls=1 serialize=2 exchanges=2 cid=1 cid_val=dead" \
2854            "$P_CLI dtls=1 serialize=0 exchanges=2 cid=1 cid_val=beef" \
2855            0 \
2856            -C "Deserializing connection..." \
2857            -s "Deserializing connection..."
2858
2859requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2860requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2861run_test    "Context serialization, re-init, both serialize, CCM" \
2862            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2863            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2864            0 \
2865            -c "Deserializing connection..." \
2866            -s "Deserializing connection..."
2867
2868requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2869requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2870run_test    "Context serialization, re-init, both serialize, ChaChaPoly" \
2871            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2872            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2873            0 \
2874            -c "Deserializing connection..." \
2875            -s "Deserializing connection..."
2876
2877requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2878requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2879run_test    "Context serialization, re-init, both serialize, GCM" \
2880            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2881            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2882            0 \
2883            -c "Deserializing connection..." \
2884            -s "Deserializing connection..."
2885
2886requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2887requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2888requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2889run_test    "Context serialization, re-init, both serialize, with CID" \
2890            "$P_SRV dtls=1 serialize=2 exchanges=2 cid=1 cid_val=dead" \
2891            "$P_CLI dtls=1 serialize=2 exchanges=2 cid=1 cid_val=beef" \
2892            0 \
2893            -c "Deserializing connection..." \
2894            -s "Deserializing connection..."
2895
2896requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2897requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2898run_test    "Saving the serialized context to a file" \
2899            "$P_SRV dtls=1 serialize=1 context_file=context_srv.txt" \
2900            "$P_CLI dtls=1 serialize=1 context_file=context_cli.txt" \
2901            0 \
2902            -s "Save serialized context to a file... ok" \
2903            -c "Save serialized context to a file... ok"
2904rm -f context_srv.txt
2905rm -f context_cli.txt
2906
2907# Tests for DTLS Connection ID extension
2908
2909# So far, the CID API isn't implemented, so we can't
2910# grep for output witnessing its use. This needs to be
2911# changed once the CID extension is implemented.
2912
2913requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2914requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2915run_test    "Connection ID: Cli enabled, Srv disabled" \
2916            "$P_SRV debug_level=3 dtls=1 cid=0" \
2917            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
2918            0 \
2919            -s "Disable use of CID extension." \
2920            -s "found CID extension"           \
2921            -s "Client sent CID extension, but CID disabled" \
2922            -c "Enable use of CID extension."  \
2923            -c "client hello, adding CID extension" \
2924            -S "server hello, adding CID extension" \
2925            -C "found CID extension" \
2926            -S "Copy CIDs into SSL transform" \
2927            -C "Copy CIDs into SSL transform" \
2928            -c "Use of Connection ID was rejected by the server"
2929
2930requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2931requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2932run_test    "Connection ID: Cli disabled, Srv enabled" \
2933            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
2934            "$P_CLI debug_level=3 dtls=1 cid=0" \
2935            0 \
2936            -c "Disable use of CID extension." \
2937            -C "client hello, adding CID extension"           \
2938            -S "found CID extension"           \
2939            -s "Enable use of CID extension." \
2940            -S "server hello, adding CID extension" \
2941            -C "found CID extension" \
2942            -S "Copy CIDs into SSL transform" \
2943            -C "Copy CIDs into SSL transform"  \
2944            -s "Use of Connection ID was not offered by client"
2945
2946requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2947requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2948run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty" \
2949            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
2950            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef" \
2951            0 \
2952            -c "Enable use of CID extension." \
2953            -s "Enable use of CID extension." \
2954            -c "client hello, adding CID extension" \
2955            -s "found CID extension"           \
2956            -s "Use of CID extension negotiated" \
2957            -s "server hello, adding CID extension" \
2958            -c "found CID extension" \
2959            -c "Use of CID extension negotiated" \
2960            -s "Copy CIDs into SSL transform" \
2961            -c "Copy CIDs into SSL transform" \
2962            -c "Peer CID (length 2 Bytes): de ad" \
2963            -s "Peer CID (length 2 Bytes): be ef" \
2964            -s "Use of Connection ID has been negotiated" \
2965            -c "Use of Connection ID has been negotiated"
2966
2967requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2968requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2969run_test    "Connection ID, 3D: Cli+Srv enabled, Cli+Srv CID nonempty" \
2970            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
2971            "$P_SRV debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=dead" \
2972            "$P_CLI debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=beef" \
2973            0 \
2974            -c "Enable use of CID extension." \
2975            -s "Enable use of CID extension." \
2976            -c "client hello, adding CID extension" \
2977            -s "found CID extension"           \
2978            -s "Use of CID extension negotiated" \
2979            -s "server hello, adding CID extension" \
2980            -c "found CID extension" \
2981            -c "Use of CID extension negotiated" \
2982            -s "Copy CIDs into SSL transform" \
2983            -c "Copy CIDs into SSL transform" \
2984            -c "Peer CID (length 2 Bytes): de ad" \
2985            -s "Peer CID (length 2 Bytes): be ef" \
2986            -s "Use of Connection ID has been negotiated" \
2987            -c "Use of Connection ID has been negotiated" \
2988            -c "ignoring unexpected CID" \
2989            -s "ignoring unexpected CID"
2990
2991requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2992requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2993run_test    "Connection ID, MTU: Cli+Srv enabled, Cli+Srv CID nonempty" \
2994            -p "$P_PXY mtu=800" \
2995            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead" \
2996            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef" \
2997            0 \
2998            -c "Enable use of CID extension." \
2999            -s "Enable use of CID extension." \
3000            -c "client hello, adding CID extension" \
3001            -s "found CID extension"           \
3002            -s "Use of CID extension negotiated" \
3003            -s "server hello, adding CID extension" \
3004            -c "found CID extension" \
3005            -c "Use of CID extension negotiated" \
3006            -s "Copy CIDs into SSL transform" \
3007            -c "Copy CIDs into SSL transform" \
3008            -c "Peer CID (length 2 Bytes): de ad" \
3009            -s "Peer CID (length 2 Bytes): be ef" \
3010            -s "Use of Connection ID has been negotiated" \
3011            -c "Use of Connection ID has been negotiated"
3012
3013requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3014requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3015run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, Cli+Srv CID nonempty" \
3016            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3017            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead" \
3018            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef" \
3019            0 \
3020            -c "Enable use of CID extension." \
3021            -s "Enable use of CID extension." \
3022            -c "client hello, adding CID extension" \
3023            -s "found CID extension"           \
3024            -s "Use of CID extension negotiated" \
3025            -s "server hello, adding CID extension" \
3026            -c "found CID extension" \
3027            -c "Use of CID extension negotiated" \
3028            -s "Copy CIDs into SSL transform" \
3029            -c "Copy CIDs into SSL transform" \
3030            -c "Peer CID (length 2 Bytes): de ad" \
3031            -s "Peer CID (length 2 Bytes): be ef" \
3032            -s "Use of Connection ID has been negotiated" \
3033            -c "Use of Connection ID has been negotiated" \
3034            -c "ignoring unexpected CID" \
3035            -s "ignoring unexpected CID"
3036
3037requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3038requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3039run_test    "Connection ID: Cli+Srv enabled, Cli CID empty" \
3040            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3041            "$P_CLI debug_level=3 dtls=1 cid=1" \
3042            0 \
3043            -c "Enable use of CID extension." \
3044            -s "Enable use of CID extension." \
3045            -c "client hello, adding CID extension" \
3046            -s "found CID extension"           \
3047            -s "Use of CID extension negotiated" \
3048            -s "server hello, adding CID extension" \
3049            -c "found CID extension" \
3050            -c "Use of CID extension negotiated" \
3051            -s "Copy CIDs into SSL transform" \
3052            -c "Copy CIDs into SSL transform" \
3053            -c "Peer CID (length 4 Bytes): de ad be ef" \
3054            -s "Peer CID (length 0 Bytes):" \
3055            -s "Use of Connection ID has been negotiated" \
3056            -c "Use of Connection ID has been negotiated"
3057
3058requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3059requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3060run_test    "Connection ID: Cli+Srv enabled, Srv CID empty" \
3061            "$P_SRV debug_level=3 dtls=1 cid=1" \
3062            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3063            0 \
3064            -c "Enable use of CID extension." \
3065            -s "Enable use of CID extension." \
3066            -c "client hello, adding CID extension" \
3067            -s "found CID extension"           \
3068            -s "Use of CID extension negotiated" \
3069            -s "server hello, adding CID extension" \
3070            -c "found CID extension" \
3071            -c "Use of CID extension negotiated" \
3072            -s "Copy CIDs into SSL transform" \
3073            -c "Copy CIDs into SSL transform" \
3074            -s "Peer CID (length 4 Bytes): de ad be ef" \
3075            -c "Peer CID (length 0 Bytes):" \
3076            -s "Use of Connection ID has been negotiated" \
3077            -c "Use of Connection ID has been negotiated"
3078
3079requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3080requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3081run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty" \
3082            "$P_SRV debug_level=3 dtls=1 cid=1" \
3083            "$P_CLI debug_level=3 dtls=1 cid=1" \
3084            0 \
3085            -c "Enable use of CID extension." \
3086            -s "Enable use of CID extension." \
3087            -c "client hello, adding CID extension" \
3088            -s "found CID extension"           \
3089            -s "Use of CID extension negotiated" \
3090            -s "server hello, adding CID extension" \
3091            -c "found CID extension" \
3092            -c "Use of CID extension negotiated" \
3093            -s "Copy CIDs into SSL transform" \
3094            -c "Copy CIDs into SSL transform" \
3095            -S "Use of Connection ID has been negotiated" \
3096            -C "Use of Connection ID has been negotiated"
3097
3098requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3099requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3100run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty, AES-128-CCM-8" \
3101            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
3102            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3103            0 \
3104            -c "Enable use of CID extension." \
3105            -s "Enable use of CID extension." \
3106            -c "client hello, adding CID extension" \
3107            -s "found CID extension"           \
3108            -s "Use of CID extension negotiated" \
3109            -s "server hello, adding CID extension" \
3110            -c "found CID extension" \
3111            -c "Use of CID extension negotiated" \
3112            -s "Copy CIDs into SSL transform" \
3113            -c "Copy CIDs into SSL transform" \
3114            -c "Peer CID (length 2 Bytes): de ad" \
3115            -s "Peer CID (length 2 Bytes): be ef" \
3116            -s "Use of Connection ID has been negotiated" \
3117            -c "Use of Connection ID has been negotiated"
3118
3119requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3120requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3121run_test    "Connection ID: Cli+Srv enabled, Cli CID empty, AES-128-CCM-8" \
3122            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3123            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3124            0 \
3125            -c "Enable use of CID extension." \
3126            -s "Enable use of CID extension." \
3127            -c "client hello, adding CID extension" \
3128            -s "found CID extension"           \
3129            -s "Use of CID extension negotiated" \
3130            -s "server hello, adding CID extension" \
3131            -c "found CID extension" \
3132            -c "Use of CID extension negotiated" \
3133            -s "Copy CIDs into SSL transform" \
3134            -c "Copy CIDs into SSL transform" \
3135            -c "Peer CID (length 4 Bytes): de ad be ef" \
3136            -s "Peer CID (length 0 Bytes):" \
3137            -s "Use of Connection ID has been negotiated" \
3138            -c "Use of Connection ID has been negotiated"
3139
3140requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3141requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3142run_test    "Connection ID: Cli+Srv enabled, Srv CID empty, AES-128-CCM-8" \
3143            "$P_SRV debug_level=3 dtls=1 cid=1" \
3144            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3145            0 \
3146            -c "Enable use of CID extension." \
3147            -s "Enable use of CID extension." \
3148            -c "client hello, adding CID extension" \
3149            -s "found CID extension"           \
3150            -s "Use of CID extension negotiated" \
3151            -s "server hello, adding CID extension" \
3152            -c "found CID extension" \
3153            -c "Use of CID extension negotiated" \
3154            -s "Copy CIDs into SSL transform" \
3155            -c "Copy CIDs into SSL transform" \
3156            -s "Peer CID (length 4 Bytes): de ad be ef" \
3157            -c "Peer CID (length 0 Bytes):" \
3158            -s "Use of Connection ID has been negotiated" \
3159            -c "Use of Connection ID has been negotiated"
3160
3161requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3162requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3163run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty, AES-128-CCM-8" \
3164            "$P_SRV debug_level=3 dtls=1 cid=1" \
3165            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3166            0 \
3167            -c "Enable use of CID extension." \
3168            -s "Enable use of CID extension." \
3169            -c "client hello, adding CID extension" \
3170            -s "found CID extension"           \
3171            -s "Use of CID extension negotiated" \
3172            -s "server hello, adding CID extension" \
3173            -c "found CID extension" \
3174            -c "Use of CID extension negotiated" \
3175            -s "Copy CIDs into SSL transform" \
3176            -c "Copy CIDs into SSL transform" \
3177            -S "Use of Connection ID has been negotiated" \
3178            -C "Use of Connection ID has been negotiated"
3179
3180requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3181requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3182run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty, AES-128-CBC" \
3183            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
3184            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3185            0 \
3186            -c "Enable use of CID extension." \
3187            -s "Enable use of CID extension." \
3188            -c "client hello, adding CID extension" \
3189            -s "found CID extension"           \
3190            -s "Use of CID extension negotiated" \
3191            -s "server hello, adding CID extension" \
3192            -c "found CID extension" \
3193            -c "Use of CID extension negotiated" \
3194            -s "Copy CIDs into SSL transform" \
3195            -c "Copy CIDs into SSL transform" \
3196            -c "Peer CID (length 2 Bytes): de ad" \
3197            -s "Peer CID (length 2 Bytes): be ef" \
3198            -s "Use of Connection ID has been negotiated" \
3199            -c "Use of Connection ID has been negotiated"
3200
3201requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3202requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3203run_test    "Connection ID: Cli+Srv enabled, Cli CID empty, AES-128-CBC" \
3204            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3205            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3206            0 \
3207            -c "Enable use of CID extension." \
3208            -s "Enable use of CID extension." \
3209            -c "client hello, adding CID extension" \
3210            -s "found CID extension"           \
3211            -s "Use of CID extension negotiated" \
3212            -s "server hello, adding CID extension" \
3213            -c "found CID extension" \
3214            -c "Use of CID extension negotiated" \
3215            -s "Copy CIDs into SSL transform" \
3216            -c "Copy CIDs into SSL transform" \
3217            -c "Peer CID (length 4 Bytes): de ad be ef" \
3218            -s "Peer CID (length 0 Bytes):" \
3219            -s "Use of Connection ID has been negotiated" \
3220            -c "Use of Connection ID has been negotiated"
3221
3222requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3223requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3224run_test    "Connection ID: Cli+Srv enabled, Srv CID empty, AES-128-CBC" \
3225            "$P_SRV debug_level=3 dtls=1 cid=1" \
3226            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3227            0 \
3228            -c "Enable use of CID extension." \
3229            -s "Enable use of CID extension." \
3230            -c "client hello, adding CID extension" \
3231            -s "found CID extension"           \
3232            -s "Use of CID extension negotiated" \
3233            -s "server hello, adding CID extension" \
3234            -c "found CID extension" \
3235            -c "Use of CID extension negotiated" \
3236            -s "Copy CIDs into SSL transform" \
3237            -c "Copy CIDs into SSL transform" \
3238            -s "Peer CID (length 4 Bytes): de ad be ef" \
3239            -c "Peer CID (length 0 Bytes):" \
3240            -s "Use of Connection ID has been negotiated" \
3241            -c "Use of Connection ID has been negotiated"
3242
3243requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3244requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3245run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty, AES-128-CBC" \
3246            "$P_SRV debug_level=3 dtls=1 cid=1" \
3247            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3248            0 \
3249            -c "Enable use of CID extension." \
3250            -s "Enable use of CID extension." \
3251            -c "client hello, adding CID extension" \
3252            -s "found CID extension"           \
3253            -s "Use of CID extension negotiated" \
3254            -s "server hello, adding CID extension" \
3255            -c "found CID extension" \
3256            -c "Use of CID extension negotiated" \
3257            -s "Copy CIDs into SSL transform" \
3258            -c "Copy CIDs into SSL transform" \
3259            -S "Use of Connection ID has been negotiated" \
3260            -C "Use of Connection ID has been negotiated"
3261
3262requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3263requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3264requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3265run_test    "Connection ID: Cli+Srv enabled, renegotiate without change of CID" \
3266            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3267            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3268            0 \
3269            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3270            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3271            -s "(initial handshake) Use of Connection ID has been negotiated" \
3272            -c "(initial handshake) Use of Connection ID has been negotiated" \
3273            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3274            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3275            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3276            -c "(after renegotiation) Use of Connection ID has been negotiated"
3277
3278requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3279requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3280requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3281run_test    "Connection ID: Cli+Srv enabled, renegotiate with different CID" \
3282            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_val_renego=beef renegotiation=1" \
3283            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3284            0 \
3285            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3286            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3287            -s "(initial handshake) Use of Connection ID has been negotiated" \
3288            -c "(initial handshake) Use of Connection ID has been negotiated" \
3289            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3290            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3291            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3292            -c "(after renegotiation) Use of Connection ID has been negotiated"
3293
3294requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3295requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3296requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3297run_test    "Connection ID, no packing: Cli+Srv enabled, renegotiate with different CID" \
3298            "$P_SRV debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=dead cid_val_renego=beef renegotiation=1" \
3299            "$P_CLI debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3300            0 \
3301            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3302            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3303            -s "(initial handshake) Use of Connection ID has been negotiated" \
3304            -c "(initial handshake) Use of Connection ID has been negotiated" \
3305            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3306            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3307            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3308            -c "(after renegotiation) Use of Connection ID has been negotiated"
3309
3310requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3311requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3312requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3313run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, renegotiate with different CID" \
3314            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3315            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead cid_val_renego=beef renegotiation=1" \
3316            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3317            0 \
3318            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3319            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3320            -s "(initial handshake) Use of Connection ID has been negotiated" \
3321            -c "(initial handshake) Use of Connection ID has been negotiated" \
3322            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3323            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3324            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3325            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3326            -c "ignoring unexpected CID" \
3327            -s "ignoring unexpected CID"
3328
3329requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3330requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3331requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3332run_test    "Connection ID: Cli+Srv enabled, renegotiate without CID" \
3333            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3334            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3335            0 \
3336            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3337            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3338            -s "(initial handshake) Use of Connection ID has been negotiated" \
3339            -c "(initial handshake) Use of Connection ID has been negotiated" \
3340            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3341            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3342            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3343            -S "(after renegotiation) Use of Connection ID has been negotiated"
3344
3345requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3346requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3347requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3348run_test    "Connection ID, no packing: Cli+Srv enabled, renegotiate without CID" \
3349            "$P_SRV debug_level=3 dtls=1 dgram_packing=0 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3350            "$P_CLI debug_level=3 dtls=1 dgram_packing=0 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3351            0 \
3352            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3353            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3354            -s "(initial handshake) Use of Connection ID has been negotiated" \
3355            -c "(initial handshake) Use of Connection ID has been negotiated" \
3356            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3357            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3358            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3359            -S "(after renegotiation) Use of Connection ID has been negotiated"
3360
3361requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3362requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3363requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3364run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, renegotiate without CID" \
3365            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3366            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3367            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3368            0 \
3369            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3370            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3371            -s "(initial handshake) Use of Connection ID has been negotiated" \
3372            -c "(initial handshake) Use of Connection ID has been negotiated" \
3373            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3374            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3375            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3376            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3377            -c "ignoring unexpected CID" \
3378            -s "ignoring unexpected CID"
3379
3380requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3381requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3382requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3383run_test    "Connection ID: Cli+Srv enabled, CID on renegotiation" \
3384            "$P_SRV debug_level=3 dtls=1 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3385            "$P_CLI debug_level=3 dtls=1 cid=0 cid_renego=1 cid_val_renego=beef renegotiation=1 renegotiate=1" \
3386            0 \
3387            -S "(initial handshake) Use of Connection ID has been negotiated" \
3388            -C "(initial handshake) Use of Connection ID has been negotiated" \
3389            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3390            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3391            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3392            -s "(after renegotiation) Use of Connection ID has been negotiated"
3393
3394requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3395requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3396requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3397run_test    "Connection ID, no packing: Cli+Srv enabled, CID on renegotiation" \
3398            "$P_SRV debug_level=3 dtls=1 dgram_packing=0 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3399            "$P_CLI debug_level=3 dtls=1 dgram_packing=0 cid=0 cid_renego=1 cid_val_renego=beef renegotiation=1 renegotiate=1" \
3400            0 \
3401            -S "(initial handshake) Use of Connection ID has been negotiated" \
3402            -C "(initial handshake) Use of Connection ID has been negotiated" \
3403            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3404            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3405            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3406            -s "(after renegotiation) Use of Connection ID has been negotiated"
3407
3408requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3409requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3410requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3411run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, CID on renegotiation" \
3412            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3413            "$P_SRV debug_level=3 mtu=800 dtls=1 dgram_packing=1 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3414            "$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" \
3415            0 \
3416            -S "(initial handshake) Use of Connection ID has been negotiated" \
3417            -C "(initial handshake) Use of Connection ID has been negotiated" \
3418            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3419            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3420            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3421            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3422            -c "ignoring unexpected CID" \
3423            -s "ignoring unexpected CID"
3424
3425requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3426requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3427requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3428run_test    "Connection ID: Cli+Srv enabled, Cli disables on renegotiation" \
3429            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3430            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3431            0 \
3432            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3433            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3434            -s "(initial handshake) Use of Connection ID has been negotiated" \
3435            -c "(initial handshake) Use of Connection ID has been negotiated" \
3436            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3437            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3438            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3439            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3440            -s "(after renegotiation) Use of Connection ID was not offered by client"
3441
3442requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3443requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3444requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3445run_test    "Connection ID, 3D: Cli+Srv enabled, Cli disables on renegotiation" \
3446            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3447            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3448            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3449            0 \
3450            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3451            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3452            -s "(initial handshake) Use of Connection ID has been negotiated" \
3453            -c "(initial handshake) Use of Connection ID has been negotiated" \
3454            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3455            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3456            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3457            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3458            -s "(after renegotiation) Use of Connection ID was not offered by client" \
3459            -c "ignoring unexpected CID" \
3460            -s "ignoring unexpected CID"
3461
3462requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3463requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3464requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3465run_test    "Connection ID: Cli+Srv enabled, Srv disables on renegotiation" \
3466            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3467            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3468            0 \
3469            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3470            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3471            -s "(initial handshake) Use of Connection ID has been negotiated" \
3472            -c "(initial handshake) Use of Connection ID has been negotiated" \
3473            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3474            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3475            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3476            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3477            -c "(after renegotiation) Use of Connection ID was rejected by the server"
3478
3479requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3480requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3481requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3482run_test    "Connection ID, 3D: Cli+Srv enabled, Srv disables on renegotiation" \
3483            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3484            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3485            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3486            0 \
3487            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3488            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3489            -s "(initial handshake) Use of Connection ID has been negotiated" \
3490            -c "(initial handshake) Use of Connection ID has been negotiated" \
3491            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3492            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3493            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3494            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3495            -c "(after renegotiation) Use of Connection ID was rejected by the server" \
3496            -c "ignoring unexpected CID" \
3497            -s "ignoring unexpected CID"
3498
3499# This and the test below it require MAX_CONTENT_LEN to be at least MFL+1, because the
3500# tests check that the buffer contents are reallocated when the message is
3501# larger than the buffer.
3502requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3503requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3504requires_config_enabled MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3505requires_max_content_len 513
3506run_test    "Connection ID: Cli+Srv enabled, variable buffer lengths, MFL=512" \
3507            "$P_SRV dtls=1 cid=1 cid_val=dead debug_level=2" \
3508            "$P_CLI force_ciphersuite="TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" max_frag_len=512 dtls=1 cid=1 cid_val=beef" \
3509            0 \
3510            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3511            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3512            -s "(initial handshake) Use of Connection ID has been negotiated" \
3513            -c "(initial handshake) Use of Connection ID has been negotiated" \
3514            -s "Reallocating in_buf" \
3515            -s "Reallocating out_buf"
3516
3517requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3518requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3519requires_config_enabled MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3520requires_max_content_len 1025
3521run_test    "Connection ID: Cli+Srv enabled, variable buffer lengths, MFL=1024" \
3522            "$P_SRV dtls=1 cid=1 cid_val=dead debug_level=2" \
3523            "$P_CLI force_ciphersuite="TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" max_frag_len=1024 dtls=1 cid=1 cid_val=beef" \
3524            0 \
3525            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3526            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3527            -s "(initial handshake) Use of Connection ID has been negotiated" \
3528            -c "(initial handshake) Use of Connection ID has been negotiated" \
3529            -s "Reallocating in_buf" \
3530            -s "Reallocating out_buf"
3531
3532# Tests for Encrypt-then-MAC extension
3533
3534requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3535run_test    "Encrypt then MAC: default" \
3536            "$P_SRV debug_level=3 \
3537             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3538            "$P_CLI debug_level=3" \
3539            0 \
3540            -c "client hello, adding encrypt_then_mac extension" \
3541            -s "found encrypt then mac extension" \
3542            -s "server hello, adding encrypt then mac extension" \
3543            -c "found encrypt_then_mac extension" \
3544            -c "using encrypt then mac" \
3545            -s "using encrypt then mac"
3546
3547requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3548run_test    "Encrypt then MAC: client enabled, server disabled" \
3549            "$P_SRV debug_level=3 etm=0 \
3550             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3551            "$P_CLI debug_level=3 etm=1" \
3552            0 \
3553            -c "client hello, adding encrypt_then_mac extension" \
3554            -s "found encrypt then mac extension" \
3555            -S "server hello, adding encrypt then mac extension" \
3556            -C "found encrypt_then_mac extension" \
3557            -C "using encrypt then mac" \
3558            -S "using encrypt then mac"
3559
3560requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3561run_test    "Encrypt then MAC: client enabled, aead cipher" \
3562            "$P_SRV debug_level=3 etm=1 \
3563             force_ciphersuite=TLS-RSA-WITH-AES-128-GCM-SHA256" \
3564            "$P_CLI debug_level=3 etm=1" \
3565            0 \
3566            -c "client hello, adding encrypt_then_mac extension" \
3567            -s "found encrypt then mac extension" \
3568            -S "server hello, adding encrypt then mac extension" \
3569            -C "found encrypt_then_mac extension" \
3570            -C "using encrypt then mac" \
3571            -S "using encrypt then mac"
3572
3573requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3574run_test    "Encrypt then MAC: client disabled, server enabled" \
3575            "$P_SRV debug_level=3 etm=1 \
3576             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3577            "$P_CLI debug_level=3 etm=0" \
3578            0 \
3579            -C "client hello, adding encrypt_then_mac extension" \
3580            -S "found encrypt then mac extension" \
3581            -S "server hello, adding encrypt then mac extension" \
3582            -C "found encrypt_then_mac extension" \
3583            -C "using encrypt then mac" \
3584            -S "using encrypt then mac"
3585
3586# Tests for Extended Master Secret extension
3587
3588requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3589requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3590run_test    "Extended Master Secret: default" \
3591            "$P_SRV debug_level=3" \
3592            "$P_CLI debug_level=3" \
3593            0 \
3594            -c "client hello, adding extended_master_secret extension" \
3595            -s "found extended master secret extension" \
3596            -s "server hello, adding extended master secret extension" \
3597            -c "found extended_master_secret extension" \
3598            -c "session hash for extended master secret" \
3599            -s "session hash for extended master secret"
3600
3601requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3602requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3603run_test    "Extended Master Secret: client enabled, server disabled" \
3604            "$P_SRV debug_level=3 extended_ms=0" \
3605            "$P_CLI debug_level=3 extended_ms=1" \
3606            0 \
3607            -c "client hello, adding extended_master_secret extension" \
3608            -s "found extended master secret extension" \
3609            -S "server hello, adding extended master secret extension" \
3610            -C "found extended_master_secret extension" \
3611            -C "session hash for extended master secret" \
3612            -S "session hash for extended master secret"
3613
3614requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3615requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3616run_test    "Extended Master Secret: client disabled, server enabled" \
3617            "$P_SRV debug_level=3 extended_ms=1" \
3618            "$P_CLI debug_level=3 extended_ms=0" \
3619            0 \
3620            -C "client hello, adding extended_master_secret extension" \
3621            -S "found extended master secret extension" \
3622            -S "server hello, adding extended master secret extension" \
3623            -C "found extended_master_secret extension" \
3624            -C "session hash for extended master secret" \
3625            -S "session hash for extended master secret"
3626
3627# Test sending and receiving empty application data records
3628
3629requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3630run_test    "Encrypt then MAC: empty application data record" \
3631            "$P_SRV auth_mode=none debug_level=4 etm=1" \
3632            "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA" \
3633            0 \
3634            -S "0000:  0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
3635            -s "dumping 'input payload after decrypt' (0 bytes)" \
3636            -c "0 bytes written in 1 fragments"
3637
3638requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3639run_test    "Encrypt then MAC: disabled, empty application data record" \
3640            "$P_SRV auth_mode=none debug_level=4 etm=0" \
3641            "$P_CLI auth_mode=none etm=0 request_size=0" \
3642            0 \
3643            -s "dumping 'input payload after decrypt' (0 bytes)" \
3644            -c "0 bytes written in 1 fragments"
3645
3646requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3647run_test    "Encrypt then MAC, DTLS: empty application data record" \
3648            "$P_SRV auth_mode=none debug_level=4 etm=1 dtls=1" \
3649            "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA dtls=1" \
3650            0 \
3651            -S "0000:  0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
3652            -s "dumping 'input payload after decrypt' (0 bytes)" \
3653            -c "0 bytes written in 1 fragments"
3654
3655requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3656run_test    "Encrypt then MAC, DTLS: disabled, empty application data record" \
3657            "$P_SRV auth_mode=none debug_level=4 etm=0 dtls=1" \
3658            "$P_CLI auth_mode=none etm=0 request_size=0 dtls=1" \
3659            0 \
3660            -s "dumping 'input payload after decrypt' (0 bytes)" \
3661            -c "0 bytes written in 1 fragments"
3662
3663# Tests for CBC 1/n-1 record splitting
3664
3665run_test    "CBC Record splitting: TLS 1.2, no splitting" \
3666            "$P_SRV force_version=tls12" \
3667            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
3668             request_size=123" \
3669            0 \
3670            -s "Read from client: 123 bytes read" \
3671            -S "Read from client: 1 bytes read" \
3672            -S "122 bytes read"
3673
3674# Tests for Session Tickets
3675
3676requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3677run_test    "Session resume using tickets: basic" \
3678            "$P_SRV debug_level=3 tickets=1" \
3679            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3680            0 \
3681            -c "client hello, adding session ticket extension" \
3682            -s "found session ticket extension" \
3683            -s "server hello, adding session ticket extension" \
3684            -c "found session_ticket extension" \
3685            -c "parse new session ticket" \
3686            -S "session successfully restored from cache" \
3687            -s "session successfully restored from ticket" \
3688            -s "a session has been resumed" \
3689            -c "a session has been resumed"
3690
3691requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3692run_test    "Session resume using tickets: manual rotation" \
3693            "$P_SRV debug_level=3 tickets=1 ticket_rotate=1" \
3694            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3695            0 \
3696            -c "client hello, adding session ticket extension" \
3697            -s "found session ticket extension" \
3698            -s "server hello, adding session ticket extension" \
3699            -c "found session_ticket extension" \
3700            -c "parse new session ticket" \
3701            -S "session successfully restored from cache" \
3702            -s "session successfully restored from ticket" \
3703            -s "a session has been resumed" \
3704            -c "a session has been resumed"
3705
3706requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3707run_test    "Session resume using tickets: cache disabled" \
3708            "$P_SRV debug_level=3 tickets=1 cache_max=0" \
3709            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3710            0 \
3711            -c "client hello, adding session ticket extension" \
3712            -s "found session ticket extension" \
3713            -s "server hello, adding session ticket extension" \
3714            -c "found session_ticket extension" \
3715            -c "parse new session ticket" \
3716            -S "session successfully restored from cache" \
3717            -s "session successfully restored from ticket" \
3718            -s "a session has been resumed" \
3719            -c "a session has been resumed"
3720
3721requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3722run_test    "Session resume using tickets: timeout" \
3723            "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
3724            "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2000" \
3725            0 \
3726            -c "client hello, adding session ticket extension" \
3727            -s "found session ticket extension" \
3728            -s "server hello, adding session ticket extension" \
3729            -c "found session_ticket extension" \
3730            -c "parse new session ticket" \
3731            -S "session successfully restored from cache" \
3732            -S "session successfully restored from ticket" \
3733            -S "a session has been resumed" \
3734            -C "a session has been resumed"
3735
3736requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3737run_test    "Session resume using tickets: session copy" \
3738            "$P_SRV debug_level=3 tickets=1 cache_max=0" \
3739            "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_mode=0" \
3740            0 \
3741            -c "client hello, adding session ticket extension" \
3742            -s "found session ticket extension" \
3743            -s "server hello, adding session ticket extension" \
3744            -c "found session_ticket extension" \
3745            -c "parse new session ticket" \
3746            -S "session successfully restored from cache" \
3747            -s "session successfully restored from ticket" \
3748            -s "a session has been resumed" \
3749            -c "a session has been resumed"
3750
3751requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3752run_test    "Session resume using tickets: openssl server" \
3753            "$O_SRV -tls1_2" \
3754            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3755            0 \
3756            -c "client hello, adding session ticket extension" \
3757            -c "found session_ticket extension" \
3758            -c "parse new session ticket" \
3759            -c "a session has been resumed"
3760
3761requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3762run_test    "Session resume using tickets: openssl client" \
3763            "$P_SRV debug_level=3 tickets=1" \
3764            "( $O_CLI -sess_out $SESSION; \
3765               $O_CLI -sess_in $SESSION; \
3766               rm -f $SESSION )" \
3767            0 \
3768            -s "found session ticket extension" \
3769            -s "server hello, adding session ticket extension" \
3770            -S "session successfully restored from cache" \
3771            -s "session successfully restored from ticket" \
3772            -s "a session has been resumed"
3773
3774requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3775run_test    "Session resume using tickets: AES-128-GCM" \
3776            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-128-GCM" \
3777            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3778            0 \
3779            -c "client hello, adding session ticket extension" \
3780            -s "found session ticket extension" \
3781            -s "server hello, adding session ticket extension" \
3782            -c "found session_ticket extension" \
3783            -c "parse new session ticket" \
3784            -S "session successfully restored from cache" \
3785            -s "session successfully restored from ticket" \
3786            -s "a session has been resumed" \
3787            -c "a session has been resumed"
3788
3789requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3790run_test    "Session resume using tickets: AES-192-GCM" \
3791            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-192-GCM" \
3792            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
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: AES-128-CCM" \
3806            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-128-CCM" \
3807            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3808            0 \
3809            -c "client hello, adding session ticket extension" \
3810            -s "found session ticket extension" \
3811            -s "server hello, adding session ticket extension" \
3812            -c "found session_ticket extension" \
3813            -c "parse new session ticket" \
3814            -S "session successfully restored from cache" \
3815            -s "session successfully restored from ticket" \
3816            -s "a session has been resumed" \
3817            -c "a session has been resumed"
3818
3819requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3820run_test    "Session resume using tickets: AES-192-CCM" \
3821            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-192-CCM" \
3822            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3823            0 \
3824            -c "client hello, adding session ticket extension" \
3825            -s "found session ticket extension" \
3826            -s "server hello, adding session ticket extension" \
3827            -c "found session_ticket extension" \
3828            -c "parse new session ticket" \
3829            -S "session successfully restored from cache" \
3830            -s "session successfully restored from ticket" \
3831            -s "a session has been resumed" \
3832            -c "a session has been resumed"
3833
3834requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3835run_test    "Session resume using tickets: AES-256-CCM" \
3836            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-256-CCM" \
3837            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3838            0 \
3839            -c "client hello, adding session ticket extension" \
3840            -s "found session ticket extension" \
3841            -s "server hello, adding session ticket extension" \
3842            -c "found session_ticket extension" \
3843            -c "parse new session ticket" \
3844            -S "session successfully restored from cache" \
3845            -s "session successfully restored from ticket" \
3846            -s "a session has been resumed" \
3847            -c "a session has been resumed"
3848
3849requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3850run_test    "Session resume using tickets: CAMELLIA-128-CCM" \
3851            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-128-CCM" \
3852            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3853            0 \
3854            -c "client hello, adding session ticket extension" \
3855            -s "found session ticket extension" \
3856            -s "server hello, adding session ticket extension" \
3857            -c "found session_ticket extension" \
3858            -c "parse new session ticket" \
3859            -S "session successfully restored from cache" \
3860            -s "session successfully restored from ticket" \
3861            -s "a session has been resumed" \
3862            -c "a session has been resumed"
3863
3864requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3865run_test    "Session resume using tickets: CAMELLIA-192-CCM" \
3866            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-192-CCM" \
3867            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3868            0 \
3869            -c "client hello, adding session ticket extension" \
3870            -s "found session ticket extension" \
3871            -s "server hello, adding session ticket extension" \
3872            -c "found session_ticket extension" \
3873            -c "parse new session ticket" \
3874            -S "session successfully restored from cache" \
3875            -s "session successfully restored from ticket" \
3876            -s "a session has been resumed" \
3877            -c "a session has been resumed"
3878
3879requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3880run_test    "Session resume using tickets: CAMELLIA-256-CCM" \
3881            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-256-CCM" \
3882            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3883            0 \
3884            -c "client hello, adding session ticket extension" \
3885            -s "found session ticket extension" \
3886            -s "server hello, adding session ticket extension" \
3887            -c "found session_ticket extension" \
3888            -c "parse new session ticket" \
3889            -S "session successfully restored from cache" \
3890            -s "session successfully restored from ticket" \
3891            -s "a session has been resumed" \
3892            -c "a session has been resumed"
3893
3894requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3895run_test    "Session resume using tickets: ARIA-128-GCM" \
3896            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-128-GCM" \
3897            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3898            0 \
3899            -c "client hello, adding session ticket extension" \
3900            -s "found session ticket extension" \
3901            -s "server hello, adding session ticket extension" \
3902            -c "found session_ticket extension" \
3903            -c "parse new session ticket" \
3904            -S "session successfully restored from cache" \
3905            -s "session successfully restored from ticket" \
3906            -s "a session has been resumed" \
3907            -c "a session has been resumed"
3908
3909requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3910run_test    "Session resume using tickets: ARIA-192-GCM" \
3911            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-192-GCM" \
3912            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3913            0 \
3914            -c "client hello, adding session ticket extension" \
3915            -s "found session ticket extension" \
3916            -s "server hello, adding session ticket extension" \
3917            -c "found session_ticket extension" \
3918            -c "parse new session ticket" \
3919            -S "session successfully restored from cache" \
3920            -s "session successfully restored from ticket" \
3921            -s "a session has been resumed" \
3922            -c "a session has been resumed"
3923
3924requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3925run_test    "Session resume using tickets: ARIA-256-GCM" \
3926            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-256-GCM" \
3927            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3928            0 \
3929            -c "client hello, adding session ticket extension" \
3930            -s "found session ticket extension" \
3931            -s "server hello, adding session ticket extension" \
3932            -c "found session_ticket extension" \
3933            -c "parse new session ticket" \
3934            -S "session successfully restored from cache" \
3935            -s "session successfully restored from ticket" \
3936            -s "a session has been resumed" \
3937            -c "a session has been resumed"
3938
3939requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3940run_test    "Session resume using tickets: ARIA-128-CCM" \
3941            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-128-CCM" \
3942            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3943            0 \
3944            -c "client hello, adding session ticket extension" \
3945            -s "found session ticket extension" \
3946            -s "server hello, adding session ticket extension" \
3947            -c "found session_ticket extension" \
3948            -c "parse new session ticket" \
3949            -S "session successfully restored from cache" \
3950            -s "session successfully restored from ticket" \
3951            -s "a session has been resumed" \
3952            -c "a session has been resumed"
3953
3954requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3955run_test    "Session resume using tickets: ARIA-192-CCM" \
3956            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-192-CCM" \
3957            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3958            0 \
3959            -c "client hello, adding session ticket extension" \
3960            -s "found session ticket extension" \
3961            -s "server hello, adding session ticket extension" \
3962            -c "found session_ticket extension" \
3963            -c "parse new session ticket" \
3964            -S "session successfully restored from cache" \
3965            -s "session successfully restored from ticket" \
3966            -s "a session has been resumed" \
3967            -c "a session has been resumed"
3968
3969requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3970run_test    "Session resume using tickets: ARIA-256-CCM" \
3971            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-256-CCM" \
3972            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3973            0 \
3974            -c "client hello, adding session ticket extension" \
3975            -s "found session ticket extension" \
3976            -s "server hello, adding session ticket extension" \
3977            -c "found session_ticket extension" \
3978            -c "parse new session ticket" \
3979            -S "session successfully restored from cache" \
3980            -s "session successfully restored from ticket" \
3981            -s "a session has been resumed" \
3982            -c "a session has been resumed"
3983
3984requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3985run_test    "Session resume using tickets: CHACHA20-POLY1305" \
3986            "$P_SRV debug_level=3 tickets=1 ticket_aead=CHACHA20-POLY1305" \
3987            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3988            0 \
3989            -c "client hello, adding session ticket extension" \
3990            -s "found session ticket extension" \
3991            -s "server hello, adding session ticket extension" \
3992            -c "found session_ticket extension" \
3993            -c "parse new session ticket" \
3994            -S "session successfully restored from cache" \
3995            -s "session successfully restored from ticket" \
3996            -s "a session has been resumed" \
3997            -c "a session has been resumed"
3998
3999# Tests for Session Tickets with DTLS
4000
4001requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4002run_test    "Session resume using tickets, DTLS: basic" \
4003            "$P_SRV debug_level=3 dtls=1 tickets=1" \
4004            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1" \
4005            0 \
4006            -c "client hello, adding session ticket extension" \
4007            -s "found session ticket extension" \
4008            -s "server hello, adding session ticket extension" \
4009            -c "found session_ticket extension" \
4010            -c "parse new session ticket" \
4011            -S "session successfully restored from cache" \
4012            -s "session successfully restored from ticket" \
4013            -s "a session has been resumed" \
4014            -c "a session has been resumed"
4015
4016requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4017run_test    "Session resume using tickets, DTLS: cache disabled" \
4018            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0" \
4019            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1" \
4020            0 \
4021            -c "client hello, adding session ticket extension" \
4022            -s "found session ticket extension" \
4023            -s "server hello, adding session ticket extension" \
4024            -c "found session_ticket extension" \
4025            -c "parse new session ticket" \
4026            -S "session successfully restored from cache" \
4027            -s "session successfully restored from ticket" \
4028            -s "a session has been resumed" \
4029            -c "a session has been resumed"
4030
4031requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4032run_test    "Session resume using tickets, DTLS: timeout" \
4033            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0 ticket_timeout=1" \
4034            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1 reco_delay=2000" \
4035            0 \
4036            -c "client hello, adding session ticket extension" \
4037            -s "found session ticket extension" \
4038            -s "server hello, adding session ticket extension" \
4039            -c "found session_ticket extension" \
4040            -c "parse new session ticket" \
4041            -S "session successfully restored from cache" \
4042            -S "session successfully restored from ticket" \
4043            -S "a session has been resumed" \
4044            -C "a session has been resumed"
4045
4046requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4047run_test    "Session resume using tickets, DTLS: session copy" \
4048            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0" \
4049            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1 reco_mode=0" \
4050            0 \
4051            -c "client hello, adding session ticket extension" \
4052            -s "found session ticket extension" \
4053            -s "server hello, adding session ticket extension" \
4054            -c "found session_ticket extension" \
4055            -c "parse new session ticket" \
4056            -S "session successfully restored from cache" \
4057            -s "session successfully restored from ticket" \
4058            -s "a session has been resumed" \
4059            -c "a session has been resumed"
4060
4061requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4062run_test    "Session resume using tickets, DTLS: openssl server" \
4063            "$O_SRV -dtls" \
4064            "$P_CLI dtls=1 debug_level=3 tickets=1 reconnect=1" \
4065            0 \
4066            -c "client hello, adding session ticket extension" \
4067            -c "found session_ticket extension" \
4068            -c "parse new session ticket" \
4069            -c "a session has been resumed"
4070
4071# For reasons that aren't fully understood, this test randomly fails with high
4072# probability with OpenSSL 1.0.2g on the CI, see #5012.
4073requires_openssl_next
4074requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4075run_test    "Session resume using tickets, DTLS: openssl client" \
4076            "$P_SRV dtls=1 debug_level=3 tickets=1" \
4077            "( $O_NEXT_CLI -dtls -sess_out $SESSION; \
4078               $O_NEXT_CLI -dtls -sess_in $SESSION; \
4079               rm -f $SESSION )" \
4080            0 \
4081            -s "found session ticket extension" \
4082            -s "server hello, adding session ticket extension" \
4083            -S "session successfully restored from cache" \
4084            -s "session successfully restored from ticket" \
4085            -s "a session has been resumed"
4086
4087# Tests for Session Resume based on session-ID and cache
4088
4089requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4090requires_config_enabled MBEDTLS_SSL_CACHE_C
4091run_test    "Session resume using cache: tickets enabled on client" \
4092            "$P_SRV debug_level=3 tickets=0" \
4093            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
4094            0 \
4095            -c "client hello, adding session ticket extension" \
4096            -s "found session ticket extension" \
4097            -S "server hello, adding session ticket extension" \
4098            -C "found session_ticket extension" \
4099            -C "parse new session ticket" \
4100            -s "session successfully restored from cache" \
4101            -S "session successfully restored from ticket" \
4102            -s "a session has been resumed" \
4103            -c "a session has been resumed"
4104
4105requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4106requires_config_enabled MBEDTLS_SSL_CACHE_C
4107run_test    "Session resume using cache: tickets enabled on server" \
4108            "$P_SRV debug_level=3 tickets=1" \
4109            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4110            0 \
4111            -C "client hello, adding session ticket extension" \
4112            -S "found session ticket extension" \
4113            -S "server hello, adding session ticket extension" \
4114            -C "found session_ticket extension" \
4115            -C "parse new session ticket" \
4116            -s "session successfully restored from cache" \
4117            -S "session successfully restored from ticket" \
4118            -s "a session has been resumed" \
4119            -c "a session has been resumed"
4120
4121requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4122requires_config_enabled MBEDTLS_SSL_CACHE_C
4123run_test    "Session resume using cache: cache_max=0" \
4124            "$P_SRV debug_level=3 tickets=0 cache_max=0" \
4125            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4126            0 \
4127            -S "session successfully restored from cache" \
4128            -S "session successfully restored from ticket" \
4129            -S "a session has been resumed" \
4130            -C "a session has been resumed"
4131
4132requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4133requires_config_enabled MBEDTLS_SSL_CACHE_C
4134run_test    "Session resume using cache: cache_max=1" \
4135            "$P_SRV debug_level=3 tickets=0 cache_max=1" \
4136            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4137            0 \
4138            -s "session successfully restored from cache" \
4139            -S "session successfully restored from ticket" \
4140            -s "a session has been resumed" \
4141            -c "a session has been resumed"
4142
4143requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4144requires_config_enabled MBEDTLS_SSL_CACHE_C
4145run_test    "Session resume using cache: cache removed" \
4146            "$P_SRV debug_level=3 tickets=0 cache_remove=1" \
4147            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4148            0 \
4149            -C "client hello, adding session ticket extension" \
4150            -S "found session ticket extension" \
4151            -S "server hello, adding session ticket extension" \
4152            -C "found session_ticket extension" \
4153            -C "parse new session ticket" \
4154            -S "session successfully restored from cache" \
4155            -S "session successfully restored from ticket" \
4156            -S "a session has been resumed" \
4157            -C "a session has been resumed"
4158
4159requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4160requires_config_enabled MBEDTLS_SSL_CACHE_C
4161run_test    "Session resume using cache: timeout > delay" \
4162            "$P_SRV debug_level=3 tickets=0" \
4163            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
4164            0 \
4165            -s "session successfully restored from cache" \
4166            -S "session successfully restored from ticket" \
4167            -s "a session has been resumed" \
4168            -c "a session has been resumed"
4169
4170requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4171requires_config_enabled MBEDTLS_SSL_CACHE_C
4172run_test    "Session resume using cache: timeout < delay" \
4173            "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
4174            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2000" \
4175            0 \
4176            -S "session successfully restored from cache" \
4177            -S "session successfully restored from ticket" \
4178            -S "a session has been resumed" \
4179            -C "a session has been resumed"
4180
4181requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4182requires_config_enabled MBEDTLS_SSL_CACHE_C
4183run_test    "Session resume using cache: no timeout" \
4184            "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
4185            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2000" \
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_PROTO_TLS1_2
4193requires_config_enabled MBEDTLS_SSL_CACHE_C
4194run_test    "Session resume using cache: session copy" \
4195            "$P_SRV debug_level=3 tickets=0" \
4196            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_mode=0" \
4197            0 \
4198            -s "session successfully restored from cache" \
4199            -S "session successfully restored from ticket" \
4200            -s "a session has been resumed" \
4201            -c "a session has been resumed"
4202
4203requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4204requires_config_enabled MBEDTLS_SSL_CACHE_C
4205run_test    "Session resume using cache: openssl client" \
4206            "$P_SRV debug_level=3 tickets=0" \
4207            "( $O_CLI -sess_out $SESSION; \
4208               $O_CLI -sess_in $SESSION; \
4209               rm -f $SESSION )" \
4210            0 \
4211            -s "found session ticket extension" \
4212            -S "server hello, adding session ticket extension" \
4213            -s "session successfully restored from cache" \
4214            -S "session successfully restored from ticket" \
4215            -s "a session has been resumed"
4216
4217requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4218requires_config_enabled MBEDTLS_SSL_CACHE_C
4219run_test    "Session resume using cache: openssl server" \
4220            "$O_SRV -tls1_2" \
4221            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4222            0 \
4223            -C "found session_ticket extension" \
4224            -C "parse new session ticket" \
4225            -c "a session has been resumed"
4226
4227# Tests for Session resume and extensions
4228
4229requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4230requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
4231run_test    "Session resume and connection ID" \
4232            "$P_SRV debug_level=3 cid=1 cid_val=dead dtls=1 tickets=0" \
4233            "$P_CLI debug_level=3 cid=1 cid_val=beef dtls=1 tickets=0 reconnect=1" \
4234            0 \
4235            -c "Enable use of CID extension." \
4236            -s "Enable use of CID extension." \
4237            -c "client hello, adding CID extension" \
4238            -s "found CID extension"           \
4239            -s "Use of CID extension negotiated" \
4240            -s "server hello, adding CID extension" \
4241            -c "found CID extension" \
4242            -c "Use of CID extension negotiated" \
4243            -s "Copy CIDs into SSL transform" \
4244            -c "Copy CIDs into SSL transform" \
4245            -c "Peer CID (length 2 Bytes): de ad" \
4246            -s "Peer CID (length 2 Bytes): be ef" \
4247            -s "Use of Connection ID has been negotiated" \
4248            -c "Use of Connection ID has been negotiated"
4249
4250# Tests for Session Resume based on session-ID and cache, DTLS
4251
4252requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4253requires_config_enabled MBEDTLS_SSL_CACHE_C
4254run_test    "Session resume using cache, DTLS: tickets enabled on client" \
4255            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4256            "$P_CLI dtls=1 debug_level=3 tickets=1 reconnect=1 skip_close_notify=1" \
4257            0 \
4258            -c "client hello, adding session ticket extension" \
4259            -s "found session ticket extension" \
4260            -S "server hello, adding session ticket extension" \
4261            -C "found session_ticket extension" \
4262            -C "parse new session ticket" \
4263            -s "session successfully restored from cache" \
4264            -S "session successfully restored from ticket" \
4265            -s "a session has been resumed" \
4266            -c "a session has been resumed"
4267
4268requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4269requires_config_enabled MBEDTLS_SSL_CACHE_C
4270run_test    "Session resume using cache, DTLS: tickets enabled on server" \
4271            "$P_SRV dtls=1 debug_level=3 tickets=1" \
4272            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4273            0 \
4274            -C "client hello, adding session ticket extension" \
4275            -S "found session ticket extension" \
4276            -S "server hello, adding session ticket extension" \
4277            -C "found session_ticket extension" \
4278            -C "parse new session ticket" \
4279            -s "session successfully restored from cache" \
4280            -S "session successfully restored from ticket" \
4281            -s "a session has been resumed" \
4282            -c "a session has been resumed"
4283
4284requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4285requires_config_enabled MBEDTLS_SSL_CACHE_C
4286run_test    "Session resume using cache, DTLS: cache_max=0" \
4287            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_max=0" \
4288            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4289            0 \
4290            -S "session successfully restored from cache" \
4291            -S "session successfully restored from ticket" \
4292            -S "a session has been resumed" \
4293            -C "a session has been resumed"
4294
4295requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4296requires_config_enabled MBEDTLS_SSL_CACHE_C
4297run_test    "Session resume using cache, DTLS: cache_max=1" \
4298            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_max=1" \
4299            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4300            0 \
4301            -s "session successfully restored from cache" \
4302            -S "session successfully restored from ticket" \
4303            -s "a session has been resumed" \
4304            -c "a session has been resumed"
4305
4306requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4307requires_config_enabled MBEDTLS_SSL_CACHE_C
4308run_test    "Session resume using cache, DTLS: timeout > delay" \
4309            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4310            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=0" \
4311            0 \
4312            -s "session successfully restored from cache" \
4313            -S "session successfully restored from ticket" \
4314            -s "a session has been resumed" \
4315            -c "a session has been resumed"
4316
4317requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4318requires_config_enabled MBEDTLS_SSL_CACHE_C
4319run_test    "Session resume using cache, DTLS: timeout < delay" \
4320            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_timeout=1" \
4321            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=2000" \
4322            0 \
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: no timeout" \
4331            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_timeout=0" \
4332            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=2000" \
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: session copy" \
4342            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4343            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_mode=0" \
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
4350# For reasons that aren't fully understood, this test randomly fails with high
4351# probability with OpenSSL 1.0.2g on the CI, see #5012.
4352requires_openssl_next
4353requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4354requires_config_enabled MBEDTLS_SSL_CACHE_C
4355run_test    "Session resume using cache, DTLS: openssl client" \
4356            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4357            "( $O_NEXT_CLI -dtls -sess_out $SESSION; \
4358               $O_NEXT_CLI -dtls -sess_in $SESSION; \
4359               rm -f $SESSION )" \
4360            0 \
4361            -s "found session ticket extension" \
4362            -S "server hello, adding session ticket extension" \
4363            -s "session successfully restored from cache" \
4364            -S "session successfully restored from ticket" \
4365            -s "a session has been resumed"
4366
4367requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4368requires_config_enabled MBEDTLS_SSL_CACHE_C
4369run_test    "Session resume using cache, DTLS: openssl server" \
4370            "$O_SRV -dtls" \
4371            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1" \
4372            0 \
4373            -C "found session_ticket extension" \
4374            -C "parse new session ticket" \
4375            -c "a session has been resumed"
4376
4377# Tests for Max Fragment Length extension
4378
4379requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4380requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4381run_test    "Max fragment length: enabled, default" \
4382            "$P_SRV debug_level=3" \
4383            "$P_CLI debug_level=3" \
4384            0 \
4385            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4386            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4387            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4388            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4389            -C "client hello, adding max_fragment_length extension" \
4390            -S "found max fragment length extension" \
4391            -S "server hello, max_fragment_length extension" \
4392            -C "found max_fragment_length extension"
4393
4394requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4395requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4396run_test    "Max fragment length: enabled, default, larger message" \
4397            "$P_SRV debug_level=3" \
4398            "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4399            0 \
4400            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4401            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4402            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4403            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4404            -C "client hello, adding max_fragment_length extension" \
4405            -S "found max fragment length extension" \
4406            -S "server hello, max_fragment_length extension" \
4407            -C "found max_fragment_length extension" \
4408            -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
4409            -s "$MAX_CONTENT_LEN bytes read" \
4410            -s "1 bytes read"
4411
4412requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4413requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4414run_test    "Max fragment length, DTLS: enabled, default, larger message" \
4415            "$P_SRV debug_level=3 dtls=1" \
4416            "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4417            1 \
4418            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4419            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4420            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4421            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4422            -C "client hello, adding max_fragment_length extension" \
4423            -S "found max fragment length extension" \
4424            -S "server hello, max_fragment_length extension" \
4425            -C "found max_fragment_length extension" \
4426            -c "fragment larger than.*maximum "
4427
4428# Run some tests with MBEDTLS_SSL_MAX_FRAGMENT_LENGTH disabled
4429# (session fragment length will be 16384 regardless of mbedtls
4430# content length configuration.)
4431
4432requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4433requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4434run_test    "Max fragment length: disabled, larger message" \
4435            "$P_SRV debug_level=3" \
4436            "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4437            0 \
4438            -C "Maximum incoming record payload length is 16384" \
4439            -C "Maximum outgoing record payload length is 16384" \
4440            -S "Maximum incoming record payload length is 16384" \
4441            -S "Maximum outgoing record payload length is 16384" \
4442            -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
4443            -s "$MAX_CONTENT_LEN bytes read" \
4444            -s "1 bytes read"
4445
4446requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4447requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4448run_test    "Max fragment length, DTLS: disabled, larger message" \
4449            "$P_SRV debug_level=3 dtls=1" \
4450            "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4451            1 \
4452            -C "Maximum incoming record payload length is 16384" \
4453            -C "Maximum outgoing record payload length is 16384" \
4454            -S "Maximum incoming record payload length is 16384" \
4455            -S "Maximum outgoing record payload length is 16384" \
4456            -c "fragment larger than.*maximum "
4457
4458requires_max_content_len 4096
4459requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4460requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4461run_test    "Max fragment length: used by client" \
4462            "$P_SRV debug_level=3" \
4463            "$P_CLI debug_level=3 max_frag_len=4096" \
4464            0 \
4465            -c "Maximum incoming record payload length is 4096" \
4466            -c "Maximum outgoing record payload length is 4096" \
4467            -s "Maximum incoming record payload length is 4096" \
4468            -s "Maximum outgoing record payload length is 4096" \
4469            -c "client hello, adding max_fragment_length extension" \
4470            -s "found max fragment length extension" \
4471            -s "server hello, max_fragment_length extension" \
4472            -c "found max_fragment_length extension"
4473
4474requires_max_content_len 1024
4475requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4476requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4477run_test    "Max fragment length: client 512, server 1024" \
4478            "$P_SRV debug_level=3 max_frag_len=1024" \
4479            "$P_CLI debug_level=3 max_frag_len=512" \
4480            0 \
4481            -c "Maximum incoming record payload length is 512" \
4482            -c "Maximum outgoing record payload length is 512" \
4483            -s "Maximum incoming record payload length is 512" \
4484            -s "Maximum outgoing record payload length is 512" \
4485            -c "client hello, adding max_fragment_length extension" \
4486            -s "found max fragment length extension" \
4487            -s "server hello, max_fragment_length extension" \
4488            -c "found max_fragment_length extension"
4489
4490requires_max_content_len 2048
4491requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4492requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4493run_test    "Max fragment length: client 512, server 2048" \
4494            "$P_SRV debug_level=3 max_frag_len=2048" \
4495            "$P_CLI debug_level=3 max_frag_len=512" \
4496            0 \
4497            -c "Maximum incoming record payload length is 512" \
4498            -c "Maximum outgoing record payload length is 512" \
4499            -s "Maximum incoming record payload length is 512" \
4500            -s "Maximum outgoing record payload length is 512" \
4501            -c "client hello, adding max_fragment_length extension" \
4502            -s "found max fragment length extension" \
4503            -s "server hello, max_fragment_length extension" \
4504            -c "found max_fragment_length extension"
4505
4506requires_max_content_len 4096
4507requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4508requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4509run_test    "Max fragment length: client 512, server 4096" \
4510            "$P_SRV debug_level=3 max_frag_len=4096" \
4511            "$P_CLI debug_level=3 max_frag_len=512" \
4512            0 \
4513            -c "Maximum incoming record payload length is 512" \
4514            -c "Maximum outgoing record payload length is 512" \
4515            -s "Maximum incoming record payload length is 512" \
4516            -s "Maximum outgoing record payload length is 512" \
4517            -c "client hello, adding max_fragment_length extension" \
4518            -s "found max fragment length extension" \
4519            -s "server hello, max_fragment_length extension" \
4520            -c "found max_fragment_length extension"
4521
4522requires_max_content_len 1024
4523requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4524requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4525run_test    "Max fragment length: client 1024, server 512" \
4526            "$P_SRV debug_level=3 max_frag_len=512" \
4527            "$P_CLI debug_level=3 max_frag_len=1024" \
4528            0 \
4529            -c "Maximum incoming record payload length is 1024" \
4530            -c "Maximum outgoing record payload length is 1024" \
4531            -s "Maximum incoming record payload length is 1024" \
4532            -s "Maximum outgoing record payload length is 512" \
4533            -c "client hello, adding max_fragment_length extension" \
4534            -s "found max fragment length extension" \
4535            -s "server hello, max_fragment_length extension" \
4536            -c "found max_fragment_length extension"
4537
4538requires_max_content_len 2048
4539requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4540requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4541run_test    "Max fragment length: client 1024, server 2048" \
4542            "$P_SRV debug_level=3 max_frag_len=2048" \
4543            "$P_CLI debug_level=3 max_frag_len=1024" \
4544            0 \
4545            -c "Maximum incoming record payload length is 1024" \
4546            -c "Maximum outgoing record payload length is 1024" \
4547            -s "Maximum incoming record payload length is 1024" \
4548            -s "Maximum outgoing record payload length is 1024" \
4549            -c "client hello, adding max_fragment_length extension" \
4550            -s "found max fragment length extension" \
4551            -s "server hello, max_fragment_length extension" \
4552            -c "found max_fragment_length extension"
4553
4554requires_max_content_len 4096
4555requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4556requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4557run_test    "Max fragment length: client 1024, server 4096" \
4558            "$P_SRV debug_level=3 max_frag_len=4096" \
4559            "$P_CLI debug_level=3 max_frag_len=1024" \
4560            0 \
4561            -c "Maximum incoming record payload length is 1024" \
4562            -c "Maximum outgoing record payload length is 1024" \
4563            -s "Maximum incoming record payload length is 1024" \
4564            -s "Maximum outgoing record payload length is 1024" \
4565            -c "client hello, adding max_fragment_length extension" \
4566            -s "found max fragment length extension" \
4567            -s "server hello, max_fragment_length extension" \
4568            -c "found max_fragment_length extension"
4569
4570requires_max_content_len 2048
4571requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4572requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4573run_test    "Max fragment length: client 2048, server 512" \
4574            "$P_SRV debug_level=3 max_frag_len=512" \
4575            "$P_CLI debug_level=3 max_frag_len=2048" \
4576            0 \
4577            -c "Maximum incoming record payload length is 2048" \
4578            -c "Maximum outgoing record payload length is 2048" \
4579            -s "Maximum incoming record payload length is 2048" \
4580            -s "Maximum outgoing record payload length is 512" \
4581            -c "client hello, adding max_fragment_length extension" \
4582            -s "found max fragment length extension" \
4583            -s "server hello, max_fragment_length extension" \
4584            -c "found max_fragment_length extension"
4585
4586requires_max_content_len 2048
4587requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4588requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4589run_test    "Max fragment length: client 2048, server 1024" \
4590            "$P_SRV debug_level=3 max_frag_len=1024" \
4591            "$P_CLI debug_level=3 max_frag_len=2048" \
4592            0 \
4593            -c "Maximum incoming record payload length is 2048" \
4594            -c "Maximum outgoing record payload length is 2048" \
4595            -s "Maximum incoming record payload length is 2048" \
4596            -s "Maximum outgoing record payload length is 1024" \
4597            -c "client hello, adding max_fragment_length extension" \
4598            -s "found max fragment length extension" \
4599            -s "server hello, max_fragment_length extension" \
4600            -c "found max_fragment_length extension"
4601
4602requires_max_content_len 4096
4603requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4604requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4605run_test    "Max fragment length: client 2048, server 4096" \
4606            "$P_SRV debug_level=3 max_frag_len=4096" \
4607            "$P_CLI debug_level=3 max_frag_len=2048" \
4608            0 \
4609            -c "Maximum incoming record payload length is 2048" \
4610            -c "Maximum outgoing record payload length is 2048" \
4611            -s "Maximum incoming record payload length is 2048" \
4612            -s "Maximum outgoing record payload length is 2048" \
4613            -c "client hello, adding max_fragment_length extension" \
4614            -s "found max fragment length extension" \
4615            -s "server hello, max_fragment_length extension" \
4616            -c "found max_fragment_length extension"
4617
4618requires_max_content_len 4096
4619requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4620requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4621run_test    "Max fragment length: client 4096, server 512" \
4622            "$P_SRV debug_level=3 max_frag_len=512" \
4623            "$P_CLI debug_level=3 max_frag_len=4096" \
4624            0 \
4625            -c "Maximum incoming record payload length is 4096" \
4626            -c "Maximum outgoing record payload length is 4096" \
4627            -s "Maximum incoming record payload length is 4096" \
4628            -s "Maximum outgoing record payload length is 512" \
4629            -c "client hello, adding max_fragment_length extension" \
4630            -s "found max fragment length extension" \
4631            -s "server hello, max_fragment_length extension" \
4632            -c "found max_fragment_length extension"
4633
4634requires_max_content_len 4096
4635requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4636requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4637run_test    "Max fragment length: client 4096, server 1024" \
4638            "$P_SRV debug_level=3 max_frag_len=1024" \
4639            "$P_CLI debug_level=3 max_frag_len=4096" \
4640            0 \
4641            -c "Maximum incoming record payload length is 4096" \
4642            -c "Maximum outgoing record payload length is 4096" \
4643            -s "Maximum incoming record payload length is 4096" \
4644            -s "Maximum outgoing record payload length is 1024" \
4645            -c "client hello, adding max_fragment_length extension" \
4646            -s "found max fragment length extension" \
4647            -s "server hello, max_fragment_length extension" \
4648            -c "found max_fragment_length extension"
4649
4650requires_max_content_len 4096
4651requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4652requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4653run_test    "Max fragment length: client 4096, server 2048" \
4654            "$P_SRV debug_level=3 max_frag_len=2048" \
4655            "$P_CLI debug_level=3 max_frag_len=4096" \
4656            0 \
4657            -c "Maximum incoming record payload length is 4096" \
4658            -c "Maximum outgoing record payload length is 4096" \
4659            -s "Maximum incoming record payload length is 4096" \
4660            -s "Maximum outgoing record payload length is 2048" \
4661            -c "client hello, adding max_fragment_length extension" \
4662            -s "found max fragment length extension" \
4663            -s "server hello, max_fragment_length extension" \
4664            -c "found max_fragment_length extension"
4665
4666requires_max_content_len 4096
4667requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4668requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4669run_test    "Max fragment length: used by server" \
4670            "$P_SRV debug_level=3 max_frag_len=4096" \
4671            "$P_CLI debug_level=3" \
4672            0 \
4673            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4674            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4675            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4676            -s "Maximum outgoing record payload length is 4096" \
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
4684requires_gnutls
4685requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4686run_test    "Max fragment length: gnutls server" \
4687            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
4688            "$P_CLI debug_level=3 max_frag_len=4096" \
4689            0 \
4690            -c "Maximum incoming record payload length is 4096" \
4691            -c "Maximum outgoing record payload length is 4096" \
4692            -c "client hello, adding max_fragment_length extension" \
4693            -c "found max_fragment_length extension"
4694
4695requires_max_content_len 2048
4696requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4697requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4698run_test    "Max fragment length: client, message just fits" \
4699            "$P_SRV debug_level=3" \
4700            "$P_CLI debug_level=3 max_frag_len=2048 request_size=2048" \
4701            0 \
4702            -c "Maximum incoming record payload length is 2048" \
4703            -c "Maximum outgoing record payload length is 2048" \
4704            -s "Maximum incoming record payload length is 2048" \
4705            -s "Maximum outgoing record payload length is 2048" \
4706            -c "client hello, adding max_fragment_length extension" \
4707            -s "found max fragment length extension" \
4708            -s "server hello, max_fragment_length extension" \
4709            -c "found max_fragment_length extension" \
4710            -c "2048 bytes written in 1 fragments" \
4711            -s "2048 bytes read"
4712
4713requires_max_content_len 2048
4714requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4715requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4716run_test    "Max fragment length: client, larger message" \
4717            "$P_SRV debug_level=3" \
4718            "$P_CLI debug_level=3 max_frag_len=2048 request_size=2345" \
4719            0 \
4720            -c "Maximum incoming record payload length is 2048" \
4721            -c "Maximum outgoing record payload length is 2048" \
4722            -s "Maximum incoming record payload length is 2048" \
4723            -s "Maximum outgoing record payload length is 2048" \
4724            -c "client hello, adding max_fragment_length extension" \
4725            -s "found max fragment length extension" \
4726            -s "server hello, max_fragment_length extension" \
4727            -c "found max_fragment_length extension" \
4728            -c "2345 bytes written in 2 fragments" \
4729            -s "2048 bytes read" \
4730            -s "297 bytes read"
4731
4732requires_max_content_len 2048
4733requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4734requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4735run_test    "Max fragment length: DTLS client, larger message" \
4736            "$P_SRV debug_level=3 dtls=1" \
4737            "$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
4738            1 \
4739            -c "Maximum incoming record payload length is 2048" \
4740            -c "Maximum outgoing record payload length is 2048" \
4741            -s "Maximum incoming record payload length is 2048" \
4742            -s "Maximum outgoing record payload length is 2048" \
4743            -c "client hello, adding max_fragment_length extension" \
4744            -s "found max fragment length extension" \
4745            -s "server hello, max_fragment_length extension" \
4746            -c "found max_fragment_length extension" \
4747            -c "fragment larger than.*maximum"
4748
4749# Tests for Record Size Limit extension
4750
4751requires_gnutls_tls1_3
4752requires_gnutls_record_size_limit
4753requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4754run_test    "Record Size Limit: TLS 1.3: Server-side parsing, debug output and fatal alert" \
4755            "$P_SRV debug_level=3 force_version=tls13" \
4756            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4" \
4757            1 \
4758            -c "Preparing extension (Record Size Limit/28) for 'client hello'" \
4759            -c "Sending extension Record Size Limit/28 (2 bytes)" \
4760            -s "ClientHello: record_size_limit(28) extension received."\
4761            -s "found record_size_limit extension" \
4762            -s "RecordSizeLimit: 16385 Bytes" \
4763            -c "Received alert \[110]: An unsupported extension was sent"
4764
4765requires_gnutls_tls1_3
4766requires_gnutls_record_size_limit
4767requires_gnutls_next_disable_tls13_compat
4768requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT
4769run_test    "Record Size Limit: TLS 1.3: Client-side parsing, debug output and fatal alert" \
4770            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert -d 4" \
4771            "$P_CLI debug_level=4 force_version=tls13" \
4772            0 \
4773            -s "Preparing extension (Record Size Limit/28) for 'encrypted extensions'"
4774# The P_CLI can not yet send the Record Size Limit extension. Thus, the G_NEXT_SRV does not send
4775# a response in its EncryptedExtensions record.
4776#            -s "Parsing extension 'Record Size Limit/28 (2 bytes)" \
4777#            -s "Sending extension Record Size Limit/28 (2 bytes)" \
4778#            -c "EncryptedExtensions: record_size_limit(28) extension received."\
4779#            -c "found record_size_limit extension" \
4780#            -c "RecordSizeLimit: 16385 Bytes" \
4781#            -s "Received alert \[110]: An unsupported extension was sent"
4782
4783# Tests for renegotiation
4784
4785# Renegotiation SCSV always added, regardless of SSL_RENEGOTIATION
4786requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4787run_test    "Renegotiation: none, for reference" \
4788            "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \
4789            "$P_CLI debug_level=3 exchanges=2" \
4790            0 \
4791            -C "client hello, adding renegotiation extension" \
4792            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4793            -S "found renegotiation extension" \
4794            -s "server hello, secure renegotiation extension" \
4795            -c "found renegotiation extension" \
4796            -C "=> renegotiate" \
4797            -S "=> renegotiate" \
4798            -S "write hello request"
4799
4800requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4801requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4802run_test    "Renegotiation: client-initiated" \
4803            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
4804            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4805            0 \
4806            -c "client hello, adding renegotiation extension" \
4807            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4808            -s "found renegotiation extension" \
4809            -s "server hello, secure renegotiation extension" \
4810            -c "found renegotiation extension" \
4811            -c "=> renegotiate" \
4812            -s "=> renegotiate" \
4813            -S "write hello request"
4814
4815requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4816requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4817run_test    "Renegotiation: server-initiated" \
4818            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
4819            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
4820            0 \
4821            -c "client hello, adding renegotiation extension" \
4822            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4823            -s "found renegotiation extension" \
4824            -s "server hello, secure renegotiation extension" \
4825            -c "found renegotiation extension" \
4826            -c "=> renegotiate" \
4827            -s "=> renegotiate" \
4828            -s "write hello request"
4829
4830# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
4831# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
4832# algorithm stronger than SHA-1 is enabled in mbedtls_config.h
4833requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4834requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4835run_test    "Renegotiation: Signature Algorithms parsing, client-initiated" \
4836            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
4837            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4838            0 \
4839            -c "client hello, adding renegotiation extension" \
4840            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4841            -s "found renegotiation extension" \
4842            -s "server hello, secure renegotiation extension" \
4843            -c "found renegotiation extension" \
4844            -c "=> renegotiate" \
4845            -s "=> renegotiate" \
4846            -S "write hello request" \
4847            -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
4848
4849# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
4850# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
4851# algorithm stronger than SHA-1 is enabled in mbedtls_config.h
4852requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4853requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4854run_test    "Renegotiation: Signature Algorithms parsing, server-initiated" \
4855            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
4856            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
4857            0 \
4858            -c "client hello, adding renegotiation extension" \
4859            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4860            -s "found renegotiation extension" \
4861            -s "server hello, secure renegotiation extension" \
4862            -c "found renegotiation extension" \
4863            -c "=> renegotiate" \
4864            -s "=> renegotiate" \
4865            -s "write hello request" \
4866            -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
4867
4868requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4869requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4870run_test    "Renegotiation: double" \
4871            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
4872            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4873            0 \
4874            -c "client hello, adding renegotiation extension" \
4875            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4876            -s "found renegotiation extension" \
4877            -s "server hello, secure renegotiation extension" \
4878            -c "found renegotiation extension" \
4879            -c "=> renegotiate" \
4880            -s "=> renegotiate" \
4881            -s "write hello request"
4882
4883requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4884requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4885requires_max_content_len 2048
4886requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4887run_test    "Renegotiation with max fragment length: client 2048, server 512" \
4888            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1 max_frag_len=512" \
4889            "$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" \
4890            0 \
4891            -c "Maximum incoming record payload length is 2048" \
4892            -c "Maximum outgoing record payload length is 2048" \
4893            -s "Maximum incoming record payload length is 2048" \
4894            -s "Maximum outgoing record payload length is 512" \
4895            -c "client hello, adding max_fragment_length extension" \
4896            -s "found max fragment length extension" \
4897            -s "server hello, max_fragment_length extension" \
4898            -c "found max_fragment_length extension" \
4899            -c "client hello, adding renegotiation extension" \
4900            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4901            -s "found renegotiation extension" \
4902            -s "server hello, secure renegotiation extension" \
4903            -c "found renegotiation extension" \
4904            -c "=> renegotiate" \
4905            -s "=> renegotiate" \
4906            -s "write hello request"
4907
4908requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4909requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4910run_test    "Renegotiation: client-initiated, server-rejected" \
4911            "$P_SRV debug_level=3 exchanges=2 renegotiation=0 auth_mode=optional" \
4912            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4913            1 \
4914            -c "client hello, adding renegotiation extension" \
4915            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4916            -S "found renegotiation extension" \
4917            -s "server hello, secure renegotiation extension" \
4918            -c "found renegotiation extension" \
4919            -c "=> renegotiate" \
4920            -S "=> renegotiate" \
4921            -S "write hello request" \
4922            -c "SSL - Unexpected message at ServerHello in renegotiation" \
4923            -c "failed"
4924
4925requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4926requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4927run_test    "Renegotiation: server-initiated, client-rejected, default" \
4928            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
4929            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
4930            0 \
4931            -C "client hello, adding renegotiation extension" \
4932            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4933            -S "found renegotiation extension" \
4934            -s "server hello, secure renegotiation extension" \
4935            -c "found renegotiation extension" \
4936            -C "=> renegotiate" \
4937            -S "=> renegotiate" \
4938            -s "write hello request" \
4939            -S "SSL - An unexpected message was received from our peer" \
4940            -S "failed"
4941
4942requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4943requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4944run_test    "Renegotiation: server-initiated, client-rejected, not enforced" \
4945            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
4946             renego_delay=-1 auth_mode=optional" \
4947            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
4948            0 \
4949            -C "client hello, adding renegotiation extension" \
4950            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4951            -S "found renegotiation extension" \
4952            -s "server hello, secure renegotiation extension" \
4953            -c "found renegotiation extension" \
4954            -C "=> renegotiate" \
4955            -S "=> renegotiate" \
4956            -s "write hello request" \
4957            -S "SSL - An unexpected message was received from our peer" \
4958            -S "failed"
4959
4960# delay 2 for 1 alert record + 1 application data record
4961requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4962requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4963run_test    "Renegotiation: server-initiated, client-rejected, delay 2" \
4964            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
4965             renego_delay=2 auth_mode=optional" \
4966            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
4967            0 \
4968            -C "client hello, adding renegotiation extension" \
4969            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4970            -S "found renegotiation extension" \
4971            -s "server hello, secure renegotiation extension" \
4972            -c "found renegotiation extension" \
4973            -C "=> renegotiate" \
4974            -S "=> renegotiate" \
4975            -s "write hello request" \
4976            -S "SSL - An unexpected message was received from our peer" \
4977            -S "failed"
4978
4979requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4980requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4981run_test    "Renegotiation: server-initiated, client-rejected, delay 0" \
4982            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
4983             renego_delay=0 auth_mode=optional" \
4984            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
4985            0 \
4986            -C "client hello, adding renegotiation extension" \
4987            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4988            -S "found renegotiation extension" \
4989            -s "server hello, secure renegotiation extension" \
4990            -c "found renegotiation extension" \
4991            -C "=> renegotiate" \
4992            -S "=> renegotiate" \
4993            -s "write hello request" \
4994            -s "SSL - An unexpected message was received from our peer"
4995
4996requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4997requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4998run_test    "Renegotiation: server-initiated, client-accepted, delay 0" \
4999            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
5000             renego_delay=0 auth_mode=optional" \
5001            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
5002            0 \
5003            -c "client hello, adding renegotiation extension" \
5004            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5005            -s "found renegotiation extension" \
5006            -s "server hello, secure renegotiation extension" \
5007            -c "found renegotiation extension" \
5008            -c "=> renegotiate" \
5009            -s "=> renegotiate" \
5010            -s "write hello request" \
5011            -S "SSL - An unexpected message was received from our peer" \
5012            -S "failed"
5013
5014requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5015requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5016run_test    "Renegotiation: periodic, just below period" \
5017            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
5018            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
5019            0 \
5020            -C "client hello, adding renegotiation extension" \
5021            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5022            -S "found renegotiation extension" \
5023            -s "server hello, secure renegotiation extension" \
5024            -c "found renegotiation extension" \
5025            -S "record counter limit reached: renegotiate" \
5026            -C "=> renegotiate" \
5027            -S "=> renegotiate" \
5028            -S "write hello request" \
5029            -S "SSL - An unexpected message was received from our peer" \
5030            -S "failed"
5031
5032# one extra exchange to be able to complete renego
5033requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5034requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5035run_test    "Renegotiation: periodic, just above period" \
5036            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
5037            "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
5038            0 \
5039            -c "client hello, adding renegotiation extension" \
5040            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5041            -s "found renegotiation extension" \
5042            -s "server hello, secure renegotiation extension" \
5043            -c "found renegotiation extension" \
5044            -s "record counter limit reached: renegotiate" \
5045            -c "=> renegotiate" \
5046            -s "=> renegotiate" \
5047            -s "write hello request" \
5048            -S "SSL - An unexpected message was received from our peer" \
5049            -S "failed"
5050
5051requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5052requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5053run_test    "Renegotiation: periodic, two times period" \
5054            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
5055            "$P_CLI debug_level=3 exchanges=7 renegotiation=1" \
5056            0 \
5057            -c "client hello, adding renegotiation extension" \
5058            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5059            -s "found renegotiation extension" \
5060            -s "server hello, secure renegotiation extension" \
5061            -c "found renegotiation extension" \
5062            -s "record counter limit reached: renegotiate" \
5063            -c "=> renegotiate" \
5064            -s "=> renegotiate" \
5065            -s "write hello request" \
5066            -S "SSL - An unexpected message was received from our peer" \
5067            -S "failed"
5068
5069requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5070requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5071run_test    "Renegotiation: periodic, above period, disabled" \
5072            "$P_SRV debug_level=3 exchanges=9 renegotiation=0 renego_period=3 auth_mode=optional" \
5073            "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
5074            0 \
5075            -C "client hello, adding renegotiation extension" \
5076            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5077            -S "found renegotiation extension" \
5078            -s "server hello, secure renegotiation extension" \
5079            -c "found renegotiation extension" \
5080            -S "record counter limit reached: renegotiate" \
5081            -C "=> renegotiate" \
5082            -S "=> renegotiate" \
5083            -S "write hello request" \
5084            -S "SSL - An unexpected message was received from our peer" \
5085            -S "failed"
5086
5087requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5088requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5089run_test    "Renegotiation: nbio, client-initiated" \
5090            "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 auth_mode=optional" \
5091            "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
5092            0 \
5093            -c "client hello, adding renegotiation extension" \
5094            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5095            -s "found renegotiation extension" \
5096            -s "server hello, secure renegotiation extension" \
5097            -c "found renegotiation extension" \
5098            -c "=> renegotiate" \
5099            -s "=> renegotiate" \
5100            -S "write hello request"
5101
5102requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5103requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5104run_test    "Renegotiation: nbio, server-initiated" \
5105            "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
5106            "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
5107            0 \
5108            -c "client hello, adding renegotiation extension" \
5109            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5110            -s "found renegotiation extension" \
5111            -s "server hello, secure renegotiation extension" \
5112            -c "found renegotiation extension" \
5113            -c "=> renegotiate" \
5114            -s "=> renegotiate" \
5115            -s "write hello request"
5116
5117requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5118requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5119run_test    "Renegotiation: openssl server, client-initiated" \
5120            "$O_SRV -www -tls1_2" \
5121            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
5122            0 \
5123            -c "client hello, adding renegotiation extension" \
5124            -c "found renegotiation extension" \
5125            -c "=> renegotiate" \
5126            -C "ssl_hanshake() returned" \
5127            -C "error" \
5128            -c "HTTP/1.0 200 [Oo][Kk]"
5129
5130requires_gnutls
5131requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5132requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5133run_test    "Renegotiation: gnutls server strict, client-initiated" \
5134            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \
5135            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
5136            0 \
5137            -c "client hello, adding renegotiation extension" \
5138            -c "found renegotiation extension" \
5139            -c "=> renegotiate" \
5140            -C "ssl_hanshake() returned" \
5141            -C "error" \
5142            -c "HTTP/1.0 200 [Oo][Kk]"
5143
5144requires_gnutls
5145requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5146requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5147run_test    "Renegotiation: gnutls server unsafe, client-initiated default" \
5148            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5149            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
5150            1 \
5151            -c "client hello, adding renegotiation extension" \
5152            -C "found renegotiation extension" \
5153            -c "=> renegotiate" \
5154            -c "mbedtls_ssl_handshake() returned" \
5155            -c "error" \
5156            -C "HTTP/1.0 200 [Oo][Kk]"
5157
5158requires_gnutls
5159requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5160requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5161run_test    "Renegotiation: gnutls server unsafe, client-inititated no legacy" \
5162            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5163            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
5164             allow_legacy=0" \
5165            1 \
5166            -c "client hello, adding renegotiation extension" \
5167            -C "found renegotiation extension" \
5168            -c "=> renegotiate" \
5169            -c "mbedtls_ssl_handshake() returned" \
5170            -c "error" \
5171            -C "HTTP/1.0 200 [Oo][Kk]"
5172
5173requires_gnutls
5174requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5175requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5176run_test    "Renegotiation: gnutls server unsafe, client-inititated legacy" \
5177            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5178            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
5179             allow_legacy=1" \
5180            0 \
5181            -c "client hello, adding renegotiation extension" \
5182            -C "found renegotiation extension" \
5183            -c "=> renegotiate" \
5184            -C "ssl_hanshake() returned" \
5185            -C "error" \
5186            -c "HTTP/1.0 200 [Oo][Kk]"
5187
5188requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5189requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5190run_test    "Renegotiation: DTLS, client-initiated" \
5191            "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
5192            "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
5193            0 \
5194            -c "client hello, adding renegotiation extension" \
5195            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5196            -s "found renegotiation extension" \
5197            -s "server hello, secure renegotiation extension" \
5198            -c "found renegotiation extension" \
5199            -c "=> renegotiate" \
5200            -s "=> renegotiate" \
5201            -S "write hello request"
5202
5203requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5204requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5205run_test    "Renegotiation: DTLS, server-initiated" \
5206            "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
5207            "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
5208             read_timeout=1000 max_resend=2" \
5209            0 \
5210            -c "client hello, adding renegotiation extension" \
5211            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5212            -s "found renegotiation extension" \
5213            -s "server hello, secure renegotiation extension" \
5214            -c "found renegotiation extension" \
5215            -c "=> renegotiate" \
5216            -s "=> renegotiate" \
5217            -s "write hello request"
5218
5219requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5220requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5221run_test    "Renegotiation: DTLS, renego_period overflow" \
5222            "$P_SRV debug_level=3 dtls=1 exchanges=4 renegotiation=1 renego_period=18446462598732840962 auth_mode=optional" \
5223            "$P_CLI debug_level=3 dtls=1 exchanges=4 renegotiation=1" \
5224            0 \
5225            -c "client hello, adding renegotiation extension" \
5226            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5227            -s "found renegotiation extension" \
5228            -s "server hello, secure renegotiation extension" \
5229            -s "record counter limit reached: renegotiate" \
5230            -c "=> renegotiate" \
5231            -s "=> renegotiate" \
5232            -s "write hello request"
5233
5234requires_gnutls
5235requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5236requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5237run_test    "Renegotiation: DTLS, gnutls server, client-initiated" \
5238            "$G_SRV -u --mtu 4096" \
5239            "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
5240            0 \
5241            -c "client hello, adding renegotiation extension" \
5242            -c "found renegotiation extension" \
5243            -c "=> renegotiate" \
5244            -C "mbedtls_ssl_handshake returned" \
5245            -C "error" \
5246            -s "Extra-header:"
5247
5248# Test for the "secure renegotiation" extension only (no actual renegotiation)
5249
5250requires_gnutls
5251requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5252run_test    "Renego ext: gnutls server strict, client default" \
5253            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \
5254            "$P_CLI debug_level=3" \
5255            0 \
5256            -c "found renegotiation extension" \
5257            -C "error" \
5258            -c "HTTP/1.0 200 [Oo][Kk]"
5259
5260requires_gnutls
5261requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5262run_test    "Renego ext: gnutls server unsafe, client default" \
5263            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5264            "$P_CLI debug_level=3" \
5265            0 \
5266            -C "found renegotiation extension" \
5267            -C "error" \
5268            -c "HTTP/1.0 200 [Oo][Kk]"
5269
5270requires_gnutls
5271requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5272run_test    "Renego ext: gnutls server unsafe, client break legacy" \
5273            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5274            "$P_CLI debug_level=3 allow_legacy=-1" \
5275            1 \
5276            -C "found renegotiation extension" \
5277            -c "error" \
5278            -C "HTTP/1.0 200 [Oo][Kk]"
5279
5280requires_gnutls
5281requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5282run_test    "Renego ext: gnutls client strict, server default" \
5283            "$P_SRV debug_level=3" \
5284            "$G_CLI --priority=NORMAL:%SAFE_RENEGOTIATION localhost" \
5285            0 \
5286            -s "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5287            -s "server hello, secure renegotiation extension"
5288
5289requires_gnutls
5290requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5291run_test    "Renego ext: gnutls client unsafe, server default" \
5292            "$P_SRV debug_level=3" \
5293            "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION localhost" \
5294            0 \
5295            -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5296            -S "server hello, secure renegotiation extension"
5297
5298requires_gnutls
5299requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5300run_test    "Renego ext: gnutls client unsafe, server break legacy" \
5301            "$P_SRV debug_level=3 allow_legacy=-1" \
5302            "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION localhost" \
5303            1 \
5304            -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5305            -S "server hello, secure renegotiation extension"
5306
5307# Tests for silently dropping trailing extra bytes in .der certificates
5308
5309requires_gnutls
5310requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5311run_test    "DER format: no trailing bytes" \
5312            "$P_SRV crt_file=data_files/server5-der0.crt \
5313             key_file=data_files/server5.key" \
5314            "$G_CLI localhost" \
5315            0 \
5316            -c "Handshake was completed" \
5317
5318requires_gnutls
5319requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5320run_test    "DER format: with a trailing zero byte" \
5321            "$P_SRV crt_file=data_files/server5-der1a.crt \
5322             key_file=data_files/server5.key" \
5323            "$G_CLI localhost" \
5324            0 \
5325            -c "Handshake was completed" \
5326
5327requires_gnutls
5328requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5329run_test    "DER format: with a trailing random byte" \
5330            "$P_SRV crt_file=data_files/server5-der1b.crt \
5331             key_file=data_files/server5.key" \
5332            "$G_CLI localhost" \
5333            0 \
5334            -c "Handshake was completed" \
5335
5336requires_gnutls
5337requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5338run_test    "DER format: with 2 trailing random bytes" \
5339            "$P_SRV crt_file=data_files/server5-der2.crt \
5340             key_file=data_files/server5.key" \
5341            "$G_CLI localhost" \
5342            0 \
5343            -c "Handshake was completed" \
5344
5345requires_gnutls
5346requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5347run_test    "DER format: with 4 trailing random bytes" \
5348            "$P_SRV crt_file=data_files/server5-der4.crt \
5349             key_file=data_files/server5.key" \
5350            "$G_CLI localhost" \
5351            0 \
5352            -c "Handshake was completed" \
5353
5354requires_gnutls
5355requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5356run_test    "DER format: with 8 trailing random bytes" \
5357            "$P_SRV crt_file=data_files/server5-der8.crt \
5358             key_file=data_files/server5.key" \
5359            "$G_CLI localhost" \
5360            0 \
5361            -c "Handshake was completed" \
5362
5363requires_gnutls
5364requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5365run_test    "DER format: with 9 trailing random bytes" \
5366            "$P_SRV crt_file=data_files/server5-der9.crt \
5367             key_file=data_files/server5.key" \
5368            "$G_CLI localhost" \
5369            0 \
5370            -c "Handshake was completed" \
5371
5372# Tests for auth_mode, there are duplicated tests using ca callback for authentication
5373# When updating these tests, modify the matching authentication tests accordingly
5374
5375requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5376run_test    "Authentication: server badcert, client required" \
5377            "$P_SRV crt_file=data_files/server5-badsign.crt \
5378             key_file=data_files/server5.key" \
5379            "$P_CLI debug_level=1 auth_mode=required" \
5380            1 \
5381            -c "x509_verify_cert() returned" \
5382            -c "! The certificate is not correctly signed by the trusted CA" \
5383            -c "! mbedtls_ssl_handshake returned" \
5384            -c "X509 - Certificate verification failed"
5385
5386requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5387run_test    "Authentication: server badcert, client optional" \
5388            "$P_SRV crt_file=data_files/server5-badsign.crt \
5389             key_file=data_files/server5.key" \
5390            "$P_CLI debug_level=1 auth_mode=optional" \
5391            0 \
5392            -c "x509_verify_cert() returned" \
5393            -c "! The certificate is not correctly signed by the trusted CA" \
5394            -C "! mbedtls_ssl_handshake returned" \
5395            -C "X509 - Certificate verification failed"
5396
5397requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5398requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5399run_test    "Authentication: server goodcert, client optional, no trusted CA" \
5400            "$P_SRV" \
5401            "$P_CLI debug_level=3 auth_mode=optional ca_file=none ca_path=none" \
5402            0 \
5403            -c "x509_verify_cert() returned" \
5404            -c "! The certificate is not correctly signed by the trusted CA" \
5405            -c "! Certificate verification flags"\
5406            -C "! mbedtls_ssl_handshake returned" \
5407            -C "X509 - Certificate verification failed" \
5408            -C "SSL - No CA Chain is set, but required to operate"
5409
5410requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5411run_test    "Authentication: server goodcert, client required, no trusted CA" \
5412            "$P_SRV" \
5413            "$P_CLI debug_level=3 auth_mode=required ca_file=none ca_path=none" \
5414            1 \
5415            -c "x509_verify_cert() returned" \
5416            -c "! The certificate is not correctly signed by the trusted CA" \
5417            -c "! Certificate verification flags"\
5418            -c "! mbedtls_ssl_handshake returned" \
5419            -c "SSL - No CA Chain is set, but required to operate"
5420
5421# The purpose of the next two tests is to test the client's behaviour when receiving a server
5422# certificate with an unsupported elliptic curve. This should usually not happen because
5423# the client informs the server about the supported curves - it does, though, in the
5424# corner case of a static ECDH suite, because the server doesn't check the curve on that
5425# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
5426# different means to have the server ignoring the client's supported curve list.
5427
5428requires_config_enabled MBEDTLS_ECP_C
5429requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5430run_test    "Authentication: server ECDH p256v1, client required, p256v1 unsupported" \
5431            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5432             crt_file=data_files/server5.ku-ka.crt" \
5433            "$P_CLI debug_level=3 auth_mode=required curves=secp521r1" \
5434            1 \
5435            -c "bad certificate (EC key curve)"\
5436            -c "! Certificate verification flags"\
5437            -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
5438
5439requires_config_enabled MBEDTLS_ECP_C
5440requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5441run_test    "Authentication: server ECDH p256v1, client optional, p256v1 unsupported" \
5442            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5443             crt_file=data_files/server5.ku-ka.crt" \
5444            "$P_CLI debug_level=3 auth_mode=optional curves=secp521r1" \
5445            1 \
5446            -c "bad certificate (EC key curve)"\
5447            -c "! Certificate verification flags"\
5448            -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
5449
5450requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5451run_test    "Authentication: server badcert, client none" \
5452            "$P_SRV crt_file=data_files/server5-badsign.crt \
5453             key_file=data_files/server5.key" \
5454            "$P_CLI debug_level=1 auth_mode=none" \
5455            0 \
5456            -C "x509_verify_cert() returned" \
5457            -C "! The certificate is not correctly signed by the trusted CA" \
5458            -C "! mbedtls_ssl_handshake returned" \
5459            -C "X509 - Certificate verification failed"
5460
5461requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5462requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5463run_test    "Authentication: client SHA256, server required" \
5464            "$P_SRV auth_mode=required" \
5465            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5466             key_file=data_files/server6.key \
5467             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
5468            0 \
5469            -c "Supported Signature Algorithm found: 04 " \
5470            -c "Supported Signature Algorithm found: 05 "
5471
5472requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5473requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5474run_test    "Authentication: client SHA384, server required" \
5475            "$P_SRV auth_mode=required" \
5476            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5477             key_file=data_files/server6.key \
5478             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
5479            0 \
5480            -c "Supported Signature Algorithm found: 04 " \
5481            -c "Supported Signature Algorithm found: 05 "
5482
5483requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5484run_test    "Authentication: client has no cert, server required (TLS)" \
5485            "$P_SRV debug_level=3 auth_mode=required" \
5486            "$P_CLI debug_level=3 crt_file=none \
5487             key_file=data_files/server5.key" \
5488            1 \
5489            -S "skip write certificate request" \
5490            -C "skip parse certificate request" \
5491            -c "got a certificate request" \
5492            -c "= write certificate$" \
5493            -C "skip write certificate$" \
5494            -S "x509_verify_cert() returned" \
5495            -s "peer has no certificate" \
5496            -s "! mbedtls_ssl_handshake returned" \
5497            -s "No client certification received from the client, but required by the authentication mode"
5498
5499requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5500run_test    "Authentication: client badcert, server required" \
5501            "$P_SRV debug_level=3 auth_mode=required" \
5502            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5503             key_file=data_files/server5.key" \
5504            1 \
5505            -S "skip write certificate request" \
5506            -C "skip parse certificate request" \
5507            -c "got a certificate request" \
5508            -C "skip write certificate" \
5509            -C "skip write certificate verify" \
5510            -S "skip parse certificate verify" \
5511            -s "x509_verify_cert() returned" \
5512            -s "! The certificate is not correctly signed by the trusted CA" \
5513            -s "! mbedtls_ssl_handshake returned" \
5514            -s "send alert level=2 message=48" \
5515            -s "X509 - Certificate verification failed"
5516# We don't check that the client receives the alert because it might
5517# detect that its write end of the connection is closed and abort
5518# before reading the alert message.
5519
5520requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5521run_test    "Authentication: client cert self-signed and trusted, server required" \
5522            "$P_SRV debug_level=3 auth_mode=required ca_file=data_files/server5-selfsigned.crt" \
5523            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5524             key_file=data_files/server5.key" \
5525            0 \
5526            -S "skip write certificate request" \
5527            -C "skip parse certificate request" \
5528            -c "got a certificate request" \
5529            -C "skip write certificate" \
5530            -C "skip write certificate verify" \
5531            -S "skip parse certificate verify" \
5532            -S "x509_verify_cert() returned" \
5533            -S "! The certificate is not correctly signed" \
5534            -S "X509 - Certificate verification failed"
5535
5536requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5537run_test    "Authentication: client cert not trusted, server required" \
5538            "$P_SRV debug_level=3 auth_mode=required" \
5539            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5540             key_file=data_files/server5.key" \
5541            1 \
5542            -S "skip write certificate request" \
5543            -C "skip parse certificate request" \
5544            -c "got a certificate request" \
5545            -C "skip write certificate" \
5546            -C "skip write certificate verify" \
5547            -S "skip parse certificate verify" \
5548            -s "x509_verify_cert() returned" \
5549            -s "! The certificate is not correctly signed by the trusted CA" \
5550            -s "! mbedtls_ssl_handshake returned" \
5551            -s "X509 - Certificate verification failed"
5552
5553requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5554run_test    "Authentication: client badcert, server optional" \
5555            "$P_SRV debug_level=3 auth_mode=optional" \
5556            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5557             key_file=data_files/server5.key" \
5558            0 \
5559            -S "skip write certificate request" \
5560            -C "skip parse certificate request" \
5561            -c "got a certificate request" \
5562            -C "skip write certificate" \
5563            -C "skip write certificate verify" \
5564            -S "skip parse certificate verify" \
5565            -s "x509_verify_cert() returned" \
5566            -s "! The certificate is not correctly signed by the trusted CA" \
5567            -S "! mbedtls_ssl_handshake returned" \
5568            -C "! mbedtls_ssl_handshake returned" \
5569            -S "X509 - Certificate verification failed"
5570
5571requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5572run_test    "Authentication: client badcert, server none" \
5573            "$P_SRV debug_level=3 auth_mode=none" \
5574            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5575             key_file=data_files/server5.key" \
5576            0 \
5577            -s "skip write certificate request" \
5578            -C "skip parse certificate request" \
5579            -c "got no certificate request" \
5580            -c "skip write certificate" \
5581            -c "skip write certificate verify" \
5582            -s "skip parse certificate verify" \
5583            -S "x509_verify_cert() returned" \
5584            -S "! The certificate is not correctly signed by the trusted CA" \
5585            -S "! mbedtls_ssl_handshake returned" \
5586            -C "! mbedtls_ssl_handshake returned" \
5587            -S "X509 - Certificate verification failed"
5588
5589requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5590run_test    "Authentication: client no cert, server optional" \
5591            "$P_SRV debug_level=3 auth_mode=optional" \
5592            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5593            0 \
5594            -S "skip write certificate request" \
5595            -C "skip parse certificate request" \
5596            -c "got a certificate request" \
5597            -C "skip write certificate$" \
5598            -C "got no certificate to send" \
5599            -c "skip write certificate verify" \
5600            -s "skip parse certificate verify" \
5601            -s "! Certificate was missing" \
5602            -S "! mbedtls_ssl_handshake returned" \
5603            -C "! mbedtls_ssl_handshake returned" \
5604            -S "X509 - Certificate verification failed"
5605
5606requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5607run_test    "Authentication: openssl client no cert, server optional" \
5608            "$P_SRV debug_level=3 auth_mode=optional" \
5609            "$O_CLI" \
5610            0 \
5611            -S "skip write certificate request" \
5612            -s "skip parse certificate verify" \
5613            -s "! Certificate was missing" \
5614            -S "! mbedtls_ssl_handshake returned" \
5615            -S "X509 - Certificate verification failed"
5616
5617requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5618run_test    "Authentication: client no cert, openssl server optional" \
5619            "$O_SRV -verify 10 -tls1_2" \
5620            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5621            0 \
5622            -C "skip parse certificate request" \
5623            -c "got a certificate request" \
5624            -C "skip write certificate$" \
5625            -c "skip write certificate verify" \
5626            -C "! mbedtls_ssl_handshake returned"
5627
5628requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5629run_test    "Authentication: client no cert, openssl server required" \
5630            "$O_SRV -Verify 10 -tls1_2" \
5631            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5632            1 \
5633            -C "skip parse certificate request" \
5634            -c "got a certificate request" \
5635            -C "skip write certificate$" \
5636            -c "skip write certificate verify" \
5637            -c "! mbedtls_ssl_handshake returned"
5638
5639# This script assumes that MBEDTLS_X509_MAX_INTERMEDIATE_CA has its default
5640# value, defined here as MAX_IM_CA. Some test cases will be skipped if the
5641# library is configured with a different value.
5642
5643MAX_IM_CA='8'
5644
5645# The tests for the max_int tests can pass with any number higher than MAX_IM_CA
5646# because only a chain of MAX_IM_CA length is tested. Equally, the max_int+1
5647# tests can pass with any number less than MAX_IM_CA. However, stricter preconditions
5648# are in place so that the semantics are consistent with the test description.
5649requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5650requires_full_size_output_buffer
5651run_test    "Authentication: server max_int chain, client default" \
5652            "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
5653                    key_file=data_files/dir-maxpath/09.key" \
5654            "$P_CLI server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
5655            0 \
5656            -C "X509 - A fatal error occurred"
5657
5658requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5659requires_full_size_output_buffer
5660run_test    "Authentication: server max_int+1 chain, client default" \
5661            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5662                    key_file=data_files/dir-maxpath/10.key" \
5663            "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
5664            1 \
5665            -c "X509 - A fatal error occurred"
5666
5667requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5668requires_full_size_output_buffer
5669run_test    "Authentication: server max_int+1 chain, client optional" \
5670            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5671                    key_file=data_files/dir-maxpath/10.key" \
5672            "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
5673                    auth_mode=optional" \
5674            1 \
5675            -c "X509 - A fatal error occurred"
5676
5677requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5678requires_full_size_output_buffer
5679run_test    "Authentication: server max_int+1 chain, client none" \
5680            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5681                    key_file=data_files/dir-maxpath/10.key" \
5682            "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
5683                    auth_mode=none" \
5684            0 \
5685            -C "X509 - A fatal error occurred"
5686
5687requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5688requires_full_size_output_buffer
5689run_test    "Authentication: client max_int+1 chain, server default" \
5690            "$P_SRV ca_file=data_files/dir-maxpath/00.crt" \
5691            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5692                    key_file=data_files/dir-maxpath/10.key" \
5693            0 \
5694            -S "X509 - A fatal error occurred"
5695
5696requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5697requires_full_size_output_buffer
5698run_test    "Authentication: client max_int+1 chain, server optional" \
5699            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
5700            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5701                    key_file=data_files/dir-maxpath/10.key" \
5702            1 \
5703            -s "X509 - A fatal error occurred"
5704
5705requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5706requires_full_size_output_buffer
5707run_test    "Authentication: client max_int+1 chain, server required" \
5708            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
5709            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5710                    key_file=data_files/dir-maxpath/10.key" \
5711            1 \
5712            -s "X509 - A fatal error occurred"
5713
5714requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5715requires_full_size_output_buffer
5716run_test    "Authentication: client max_int chain, server required" \
5717            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
5718            "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
5719                    key_file=data_files/dir-maxpath/09.key" \
5720            0 \
5721            -S "X509 - A fatal error occurred"
5722
5723# Tests for CA list in CertificateRequest messages
5724
5725requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5726requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5727run_test    "Authentication: send CA list in CertificateRequest  (default)" \
5728            "$P_SRV debug_level=3 auth_mode=required" \
5729            "$P_CLI crt_file=data_files/server6.crt \
5730             key_file=data_files/server6.key" \
5731            0 \
5732            -s "requested DN"
5733
5734requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5735requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5736run_test    "Authentication: do not send CA list in CertificateRequest" \
5737            "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
5738            "$P_CLI crt_file=data_files/server6.crt \
5739             key_file=data_files/server6.key" \
5740            0 \
5741            -S "requested DN"
5742
5743requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5744run_test    "Authentication: send CA list in CertificateRequest, client self signed" \
5745            "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
5746            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5747             key_file=data_files/server5.key" \
5748            1 \
5749            -S "requested DN" \
5750            -s "x509_verify_cert() returned" \
5751            -s "! The certificate is not correctly signed by the trusted CA" \
5752            -s "! mbedtls_ssl_handshake returned" \
5753            -c "! mbedtls_ssl_handshake returned" \
5754            -s "X509 - Certificate verification failed"
5755
5756requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5757requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5758run_test    "Authentication: send alt conf DN hints in CertificateRequest" \
5759            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=2 \
5760             crt_file2=data_files/server1.crt \
5761             key_file2=data_files/server1.key" \
5762            "$P_CLI debug_level=3 auth_mode=optional \
5763             crt_file=data_files/server6.crt \
5764             key_file=data_files/server6.key" \
5765            0 \
5766            -c "DN hint: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
5767
5768requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5769requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5770run_test    "Authentication: send alt conf DN hints in CertificateRequest (2)" \
5771            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=2 \
5772             crt_file2=data_files/server2.crt \
5773             key_file2=data_files/server2.key" \
5774            "$P_CLI debug_level=3 auth_mode=optional \
5775             crt_file=data_files/server6.crt \
5776             key_file=data_files/server6.key" \
5777            0 \
5778            -c "DN hint: C=NL, O=PolarSSL, CN=localhost"
5779
5780requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5781requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5782run_test    "Authentication: send alt hs DN hints in CertificateRequest" \
5783            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=3 \
5784             crt_file2=data_files/server1.crt \
5785             key_file2=data_files/server1.key" \
5786            "$P_CLI debug_level=3 auth_mode=optional \
5787             crt_file=data_files/server6.crt \
5788             key_file=data_files/server6.key" \
5789            0 \
5790            -c "DN hint: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
5791
5792# Tests for auth_mode, using CA callback, these are duplicated from the authentication tests
5793# When updating these tests, modify the matching authentication tests accordingly
5794
5795requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5796requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5797run_test    "Authentication, CA callback: server badcert, client required" \
5798            "$P_SRV crt_file=data_files/server5-badsign.crt \
5799             key_file=data_files/server5.key" \
5800            "$P_CLI ca_callback=1 debug_level=3 auth_mode=required" \
5801            1 \
5802            -c "use CA callback for X.509 CRT verification" \
5803            -c "x509_verify_cert() returned" \
5804            -c "! The certificate is not correctly signed by the trusted CA" \
5805            -c "! mbedtls_ssl_handshake returned" \
5806            -c "X509 - Certificate verification failed"
5807
5808requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5809requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5810run_test    "Authentication, CA callback: server badcert, client optional" \
5811            "$P_SRV crt_file=data_files/server5-badsign.crt \
5812             key_file=data_files/server5.key" \
5813            "$P_CLI ca_callback=1 debug_level=3 auth_mode=optional" \
5814            0 \
5815            -c "use CA callback for X.509 CRT verification" \
5816            -c "x509_verify_cert() returned" \
5817            -c "! The certificate is not correctly signed by the trusted CA" \
5818            -C "! mbedtls_ssl_handshake returned" \
5819            -C "X509 - Certificate verification failed"
5820
5821# The purpose of the next two tests is to test the client's behaviour when receiving a server
5822# certificate with an unsupported elliptic curve. This should usually not happen because
5823# the client informs the server about the supported curves - it does, though, in the
5824# corner case of a static ECDH suite, because the server doesn't check the curve on that
5825# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
5826# different means to have the server ignoring the client's supported curve list.
5827
5828requires_config_enabled MBEDTLS_ECP_C
5829requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5830requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5831run_test    "Authentication, CA callback: server ECDH p256v1, client required, p256v1 unsupported" \
5832            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5833             crt_file=data_files/server5.ku-ka.crt" \
5834            "$P_CLI ca_callback=1 debug_level=3 auth_mode=required curves=secp521r1" \
5835            1 \
5836            -c "use CA callback for X.509 CRT verification" \
5837            -c "bad certificate (EC key curve)" \
5838            -c "! Certificate verification flags" \
5839            -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
5840
5841requires_config_enabled MBEDTLS_ECP_C
5842requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5843requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5844run_test    "Authentication, CA callback: server ECDH p256v1, client optional, p256v1 unsupported" \
5845            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5846             crt_file=data_files/server5.ku-ka.crt" \
5847            "$P_CLI ca_callback=1 debug_level=3 auth_mode=optional curves=secp521r1" \
5848            1 \
5849            -c "use CA callback for X.509 CRT verification" \
5850            -c "bad certificate (EC key curve)"\
5851            -c "! Certificate verification flags"\
5852            -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
5853
5854requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5855requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5856requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5857run_test    "Authentication, CA callback: client SHA256, server required" \
5858            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5859            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5860             key_file=data_files/server6.key \
5861             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
5862            0 \
5863            -s "use CA callback for X.509 CRT verification" \
5864            -c "Supported Signature Algorithm found: 04 " \
5865            -c "Supported Signature Algorithm found: 05 "
5866
5867requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5868requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5869requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5870run_test    "Authentication, CA callback: client SHA384, server required" \
5871            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5872            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5873             key_file=data_files/server6.key \
5874             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
5875            0 \
5876            -s "use CA callback for X.509 CRT verification" \
5877            -c "Supported Signature Algorithm found: 04 " \
5878            -c "Supported Signature Algorithm found: 05 "
5879
5880requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5881requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5882run_test    "Authentication, CA callback: client badcert, server required" \
5883            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5884            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5885             key_file=data_files/server5.key" \
5886            1 \
5887            -s "use CA callback for X.509 CRT verification" \
5888            -S "skip write certificate request" \
5889            -C "skip parse certificate request" \
5890            -c "got a certificate request" \
5891            -C "skip write certificate" \
5892            -C "skip write certificate verify" \
5893            -S "skip parse certificate verify" \
5894            -s "x509_verify_cert() returned" \
5895            -s "! The certificate is not correctly signed by the trusted CA" \
5896            -s "! mbedtls_ssl_handshake returned" \
5897            -s "send alert level=2 message=48" \
5898            -c "! mbedtls_ssl_handshake returned" \
5899            -s "X509 - Certificate verification failed"
5900# We don't check that the client receives the alert because it might
5901# detect that its write end of the connection is closed and abort
5902# before reading the alert message.
5903
5904requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5905requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5906run_test    "Authentication, CA callback: client cert not trusted, server required" \
5907            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5908            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5909             key_file=data_files/server5.key" \
5910            1 \
5911            -s "use CA callback for X.509 CRT verification" \
5912            -S "skip write certificate request" \
5913            -C "skip parse certificate request" \
5914            -c "got a 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_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5925requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5926run_test    "Authentication, CA callback: client badcert, server optional" \
5927            "$P_SRV ca_callback=1 debug_level=3 auth_mode=optional" \
5928            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5929             key_file=data_files/server5.key" \
5930            0 \
5931            -s "use CA callback for X.509 CRT verification" \
5932            -S "skip write certificate request" \
5933            -C "skip parse certificate request" \
5934            -c "got a certificate request" \
5935            -C "skip write certificate" \
5936            -C "skip write certificate verify" \
5937            -S "skip parse certificate verify" \
5938            -s "x509_verify_cert() returned" \
5939            -s "! The certificate is not correctly signed by the trusted CA" \
5940            -S "! mbedtls_ssl_handshake returned" \
5941            -C "! mbedtls_ssl_handshake returned" \
5942            -S "X509 - Certificate verification failed"
5943
5944requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5945requires_full_size_output_buffer
5946requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5947run_test    "Authentication, CA callback: server max_int chain, client default" \
5948            "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
5949                    key_file=data_files/dir-maxpath/09.key" \
5950            "$P_CLI ca_callback=1 debug_level=3 server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
5951            0 \
5952            -c "use CA callback for X.509 CRT verification" \
5953            -C "X509 - A fatal error occurred"
5954
5955requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5956requires_full_size_output_buffer
5957requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5958run_test    "Authentication, CA callback: server max_int+1 chain, client default" \
5959            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5960                    key_file=data_files/dir-maxpath/10.key" \
5961            "$P_CLI debug_level=3 ca_callback=1 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
5962            1 \
5963            -c "use CA callback for X.509 CRT verification" \
5964            -c "X509 - A fatal error occurred"
5965
5966requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5967requires_full_size_output_buffer
5968requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5969run_test    "Authentication, CA callback: server max_int+1 chain, client optional" \
5970            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5971                    key_file=data_files/dir-maxpath/10.key" \
5972            "$P_CLI ca_callback=1 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
5973                    debug_level=3 auth_mode=optional" \
5974            1 \
5975            -c "use CA callback for X.509 CRT verification" \
5976            -c "X509 - A fatal error occurred"
5977
5978requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5979requires_full_size_output_buffer
5980requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5981run_test    "Authentication, CA callback: client max_int+1 chain, server optional" \
5982            "$P_SRV ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
5983            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5984                    key_file=data_files/dir-maxpath/10.key" \
5985            1 \
5986            -s "use CA callback for X.509 CRT verification" \
5987            -s "X509 - A fatal error occurred"
5988
5989requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5990requires_full_size_output_buffer
5991requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5992run_test    "Authentication, CA callback: client max_int+1 chain, server required" \
5993            "$P_SRV ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
5994            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5995                    key_file=data_files/dir-maxpath/10.key" \
5996            1 \
5997            -s "use CA callback for X.509 CRT verification" \
5998            -s "X509 - A fatal error occurred"
5999
6000requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
6001requires_full_size_output_buffer
6002requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
6003run_test    "Authentication, CA callback: client max_int chain, server required" \
6004            "$P_SRV ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
6005            "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
6006                    key_file=data_files/dir-maxpath/09.key" \
6007            0 \
6008            -s "use CA callback for X.509 CRT verification" \
6009            -S "X509 - A fatal error occurred"
6010
6011# Tests for certificate selection based on SHA version
6012
6013requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6014run_test    "Certificate hash: client TLS 1.2 -> SHA-2" \
6015            "$P_SRV force_version=tls12 crt_file=data_files/server5.crt \
6016                    key_file=data_files/server5.key \
6017                    crt_file2=data_files/server5-sha1.crt \
6018                    key_file2=data_files/server5.key" \
6019            "$P_CLI" \
6020            0 \
6021            -c "signed using.*ECDSA with SHA256" \
6022            -C "signed using.*ECDSA with SHA1"
6023
6024# tests for SNI
6025
6026requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6027requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6028run_test    "SNI: no SNI callback" \
6029            "$P_SRV debug_level=3 \
6030             crt_file=data_files/server5.crt key_file=data_files/server5.key" \
6031            "$P_CLI server_name=localhost" \
6032            0 \
6033            -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
6034            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6035
6036requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6037requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6038run_test    "SNI: matching cert 1" \
6039            "$P_SRV debug_level=3 \
6040             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6041             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6042            "$P_CLI server_name=localhost" \
6043            0 \
6044            -s "parse ServerName extension" \
6045            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6046            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6047
6048requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6049requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6050run_test    "SNI: matching cert 2" \
6051            "$P_SRV debug_level=3 \
6052             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6053             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6054            "$P_CLI server_name=polarssl.example" \
6055            0 \
6056            -s "parse ServerName extension" \
6057            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6058            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
6059
6060requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6061requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6062run_test    "SNI: no matching cert" \
6063            "$P_SRV debug_level=3 \
6064             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6065             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6066            "$P_CLI server_name=nonesuch.example" \
6067            1 \
6068            -s "parse ServerName extension" \
6069            -s "ssl_sni_wrapper() returned" \
6070            -s "mbedtls_ssl_handshake returned" \
6071            -c "mbedtls_ssl_handshake returned" \
6072            -c "SSL - A fatal alert message was received from our peer"
6073
6074requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6075run_test    "SNI: client auth no override: optional" \
6076            "$P_SRV debug_level=3 auth_mode=optional \
6077             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6078             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
6079            "$P_CLI debug_level=3 server_name=localhost" \
6080            0 \
6081            -S "skip write certificate request" \
6082            -C "skip parse certificate request" \
6083            -c "got a certificate request" \
6084            -C "skip write certificate" \
6085            -C "skip write certificate verify" \
6086            -S "skip parse certificate verify"
6087
6088requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6089run_test    "SNI: client auth override: none -> optional" \
6090            "$P_SRV debug_level=3 auth_mode=none \
6091             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6092             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
6093            "$P_CLI debug_level=3 server_name=localhost" \
6094            0 \
6095            -S "skip write certificate request" \
6096            -C "skip parse certificate request" \
6097            -c "got a certificate request" \
6098            -C "skip write certificate" \
6099            -C "skip write certificate verify" \
6100            -S "skip parse certificate verify"
6101
6102requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6103run_test    "SNI: client auth override: optional -> none" \
6104            "$P_SRV debug_level=3 auth_mode=optional \
6105             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6106             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
6107            "$P_CLI debug_level=3 server_name=localhost" \
6108            0 \
6109            -s "skip write certificate request" \
6110            -C "skip parse certificate request" \
6111            -c "got no certificate request" \
6112            -c "skip write certificate"
6113
6114requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6115run_test    "SNI: CA no override" \
6116            "$P_SRV debug_level=3 auth_mode=optional \
6117             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6118             ca_file=data_files/test-ca.crt \
6119             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
6120            "$P_CLI debug_level=3 server_name=localhost \
6121             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6122            1 \
6123            -S "skip write certificate request" \
6124            -C "skip parse certificate request" \
6125            -c "got a certificate request" \
6126            -C "skip write certificate" \
6127            -C "skip write certificate verify" \
6128            -S "skip parse certificate verify" \
6129            -s "x509_verify_cert() returned" \
6130            -s "! The certificate is not correctly signed by the trusted CA" \
6131            -S "The certificate has been revoked (is on a CRL)"
6132
6133requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6134run_test    "SNI: CA override" \
6135            "$P_SRV debug_level=3 auth_mode=optional \
6136             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6137             ca_file=data_files/test-ca.crt \
6138             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
6139            "$P_CLI debug_level=3 server_name=localhost \
6140             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6141            0 \
6142            -S "skip write certificate request" \
6143            -C "skip parse certificate request" \
6144            -c "got a certificate request" \
6145            -C "skip write certificate" \
6146            -C "skip write certificate verify" \
6147            -S "skip parse certificate verify" \
6148            -S "x509_verify_cert() returned" \
6149            -S "! The certificate is not correctly signed by the trusted CA" \
6150            -S "The certificate has been revoked (is on a CRL)"
6151
6152requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6153run_test    "SNI: CA override with CRL" \
6154            "$P_SRV debug_level=3 auth_mode=optional \
6155             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6156             ca_file=data_files/test-ca.crt \
6157             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
6158            "$P_CLI debug_level=3 server_name=localhost \
6159             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6160            1 \
6161            -S "skip write certificate request" \
6162            -C "skip parse certificate request" \
6163            -c "got a certificate request" \
6164            -C "skip write certificate" \
6165            -C "skip write certificate verify" \
6166            -S "skip parse certificate verify" \
6167            -s "x509_verify_cert() returned" \
6168            -S "! The certificate is not correctly signed by the trusted CA" \
6169            -s "The certificate has been revoked (is on a CRL)"
6170
6171# Tests for SNI and DTLS
6172
6173requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6174requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6175run_test    "SNI: DTLS, no SNI callback" \
6176            "$P_SRV debug_level=3 dtls=1 \
6177             crt_file=data_files/server5.crt key_file=data_files/server5.key" \
6178            "$P_CLI server_name=localhost dtls=1" \
6179            0 \
6180            -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
6181            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6182
6183requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6184requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6185run_test    "SNI: DTLS, matching cert 1" \
6186            "$P_SRV debug_level=3 dtls=1 \
6187             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6188             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6189            "$P_CLI server_name=localhost dtls=1" \
6190            0 \
6191            -s "parse ServerName extension" \
6192            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6193            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6194
6195requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6196requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6197run_test    "SNI: DTLS, matching cert 2" \
6198            "$P_SRV debug_level=3 dtls=1 \
6199             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6200             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6201            "$P_CLI server_name=polarssl.example dtls=1" \
6202            0 \
6203            -s "parse ServerName extension" \
6204            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6205            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
6206
6207requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6208run_test    "SNI: DTLS, no matching cert" \
6209            "$P_SRV debug_level=3 dtls=1 \
6210             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6211             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6212            "$P_CLI server_name=nonesuch.example dtls=1" \
6213            1 \
6214            -s "parse ServerName extension" \
6215            -s "ssl_sni_wrapper() returned" \
6216            -s "mbedtls_ssl_handshake returned" \
6217            -c "mbedtls_ssl_handshake returned" \
6218            -c "SSL - A fatal alert message was received from our peer"
6219
6220requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6221run_test    "SNI: DTLS, client auth no override: optional" \
6222            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6223             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6224             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
6225            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6226            0 \
6227            -S "skip write certificate request" \
6228            -C "skip parse certificate request" \
6229            -c "got a certificate request" \
6230            -C "skip write certificate" \
6231            -C "skip write certificate verify" \
6232            -S "skip parse certificate verify"
6233
6234requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6235run_test    "SNI: DTLS, client auth override: none -> optional" \
6236            "$P_SRV debug_level=3 auth_mode=none dtls=1 \
6237             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6238             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
6239            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6240            0 \
6241            -S "skip write certificate request" \
6242            -C "skip parse certificate request" \
6243            -c "got a certificate request" \
6244            -C "skip write certificate" \
6245            -C "skip write certificate verify" \
6246            -S "skip parse certificate verify"
6247
6248requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6249run_test    "SNI: DTLS, client auth override: optional -> none" \
6250            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6251             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6252             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
6253            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6254            0 \
6255            -s "skip write certificate request" \
6256            -C "skip parse certificate request" \
6257            -c "got no certificate request" \
6258            -c "skip write certificate" \
6259            -c "skip write certificate verify" \
6260            -s "skip parse certificate verify"
6261
6262requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6263run_test    "SNI: DTLS, CA no override" \
6264            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6265             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6266             ca_file=data_files/test-ca.crt \
6267             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
6268            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6269             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6270            1 \
6271            -S "skip write certificate request" \
6272            -C "skip parse certificate request" \
6273            -c "got a certificate request" \
6274            -C "skip write certificate" \
6275            -C "skip write certificate verify" \
6276            -S "skip parse certificate verify" \
6277            -s "x509_verify_cert() returned" \
6278            -s "! The certificate is not correctly signed by the trusted CA" \
6279            -S "The certificate has been revoked (is on a CRL)"
6280
6281requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6282run_test    "SNI: DTLS, CA override" \
6283            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6284             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6285             ca_file=data_files/test-ca.crt \
6286             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
6287            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6288             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6289            0 \
6290            -S "skip write certificate request" \
6291            -C "skip parse certificate request" \
6292            -c "got a certificate request" \
6293            -C "skip write certificate" \
6294            -C "skip write certificate verify" \
6295            -S "skip parse certificate verify" \
6296            -S "x509_verify_cert() returned" \
6297            -S "! The certificate is not correctly signed by the trusted CA" \
6298            -S "The certificate has been revoked (is on a CRL)"
6299
6300requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6301run_test    "SNI: DTLS, CA override with CRL" \
6302            "$P_SRV debug_level=3 auth_mode=optional \
6303             crt_file=data_files/server5.crt key_file=data_files/server5.key dtls=1 \
6304             ca_file=data_files/test-ca.crt \
6305             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
6306            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6307             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6308            1 \
6309            -S "skip write certificate request" \
6310            -C "skip parse certificate request" \
6311            -c "got a certificate request" \
6312            -C "skip write certificate" \
6313            -C "skip write certificate verify" \
6314            -S "skip parse certificate verify" \
6315            -s "x509_verify_cert() returned" \
6316            -S "! The certificate is not correctly signed by the trusted CA" \
6317            -s "The certificate has been revoked (is on a CRL)"
6318
6319# Tests for non-blocking I/O: exercise a variety of handshake flows
6320
6321requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6322run_test    "Non-blocking I/O: basic handshake" \
6323            "$P_SRV nbio=2 tickets=0 auth_mode=none" \
6324            "$P_CLI nbio=2 tickets=0" \
6325            0 \
6326            -S "mbedtls_ssl_handshake returned" \
6327            -C "mbedtls_ssl_handshake returned" \
6328            -c "Read from server: .* bytes read"
6329
6330requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6331run_test    "Non-blocking I/O: client auth" \
6332            "$P_SRV nbio=2 tickets=0 auth_mode=required" \
6333            "$P_CLI nbio=2 tickets=0" \
6334            0 \
6335            -S "mbedtls_ssl_handshake returned" \
6336            -C "mbedtls_ssl_handshake returned" \
6337            -c "Read from server: .* bytes read"
6338
6339requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6340requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6341run_test    "Non-blocking I/O: ticket" \
6342            "$P_SRV nbio=2 tickets=1 auth_mode=none" \
6343            "$P_CLI nbio=2 tickets=1" \
6344            0 \
6345            -S "mbedtls_ssl_handshake returned" \
6346            -C "mbedtls_ssl_handshake returned" \
6347            -c "Read from server: .* bytes read"
6348
6349requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6350requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6351run_test    "Non-blocking I/O: ticket + client auth" \
6352            "$P_SRV nbio=2 tickets=1 auth_mode=required" \
6353            "$P_CLI nbio=2 tickets=1" \
6354            0 \
6355            -S "mbedtls_ssl_handshake returned" \
6356            -C "mbedtls_ssl_handshake returned" \
6357            -c "Read from server: .* bytes read"
6358
6359requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6360requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6361run_test    "Non-blocking I/O: ticket + client auth + resume" \
6362            "$P_SRV nbio=2 tickets=1 auth_mode=required" \
6363            "$P_CLI nbio=2 tickets=1 reconnect=1" \
6364            0 \
6365            -S "mbedtls_ssl_handshake returned" \
6366            -C "mbedtls_ssl_handshake returned" \
6367            -c "Read from server: .* bytes read"
6368
6369requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6370requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6371run_test    "Non-blocking I/O: ticket + resume" \
6372            "$P_SRV nbio=2 tickets=1 auth_mode=none" \
6373            "$P_CLI nbio=2 tickets=1 reconnect=1" \
6374            0 \
6375            -S "mbedtls_ssl_handshake returned" \
6376            -C "mbedtls_ssl_handshake returned" \
6377            -c "Read from server: .* bytes read"
6378
6379requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6380requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6381run_test    "Non-blocking I/O: session-id resume" \
6382            "$P_SRV nbio=2 tickets=0 auth_mode=none" \
6383            "$P_CLI nbio=2 tickets=0 reconnect=1" \
6384            0 \
6385            -S "mbedtls_ssl_handshake returned" \
6386            -C "mbedtls_ssl_handshake returned" \
6387            -c "Read from server: .* bytes read"
6388
6389# Tests for event-driven I/O: exercise a variety of handshake flows
6390
6391requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6392run_test    "Event-driven I/O: basic handshake" \
6393            "$P_SRV event=1 tickets=0 auth_mode=none" \
6394            "$P_CLI event=1 tickets=0" \
6395            0 \
6396            -S "mbedtls_ssl_handshake returned" \
6397            -C "mbedtls_ssl_handshake returned" \
6398            -c "Read from server: .* bytes read"
6399
6400requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6401run_test    "Event-driven I/O: client auth" \
6402            "$P_SRV event=1 tickets=0 auth_mode=required" \
6403            "$P_CLI event=1 tickets=0" \
6404            0 \
6405            -S "mbedtls_ssl_handshake returned" \
6406            -C "mbedtls_ssl_handshake returned" \
6407            -c "Read from server: .* bytes read"
6408
6409requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6410requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6411run_test    "Event-driven I/O: ticket" \
6412            "$P_SRV event=1 tickets=1 auth_mode=none" \
6413            "$P_CLI event=1 tickets=1" \
6414            0 \
6415            -S "mbedtls_ssl_handshake returned" \
6416            -C "mbedtls_ssl_handshake returned" \
6417            -c "Read from server: .* bytes read"
6418
6419requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6420requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6421run_test    "Event-driven I/O: ticket + client auth" \
6422            "$P_SRV event=1 tickets=1 auth_mode=required" \
6423            "$P_CLI event=1 tickets=1" \
6424            0 \
6425            -S "mbedtls_ssl_handshake returned" \
6426            -C "mbedtls_ssl_handshake returned" \
6427            -c "Read from server: .* bytes read"
6428
6429requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6430requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6431run_test    "Event-driven I/O: ticket + client auth + resume" \
6432            "$P_SRV event=1 tickets=1 auth_mode=required" \
6433            "$P_CLI event=1 tickets=1 reconnect=1" \
6434            0 \
6435            -S "mbedtls_ssl_handshake returned" \
6436            -C "mbedtls_ssl_handshake returned" \
6437            -c "Read from server: .* bytes read"
6438
6439requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6440requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6441run_test    "Event-driven I/O: ticket + resume" \
6442            "$P_SRV event=1 tickets=1 auth_mode=none" \
6443            "$P_CLI event=1 tickets=1 reconnect=1" \
6444            0 \
6445            -S "mbedtls_ssl_handshake returned" \
6446            -C "mbedtls_ssl_handshake returned" \
6447            -c "Read from server: .* bytes read"
6448
6449requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6450requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6451run_test    "Event-driven I/O: session-id resume" \
6452            "$P_SRV event=1 tickets=0 auth_mode=none" \
6453            "$P_CLI event=1 tickets=0 reconnect=1" \
6454            0 \
6455            -S "mbedtls_ssl_handshake returned" \
6456            -C "mbedtls_ssl_handshake returned" \
6457            -c "Read from server: .* bytes read"
6458
6459requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6460run_test    "Event-driven I/O, DTLS: basic handshake" \
6461            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
6462            "$P_CLI dtls=1 event=1 tickets=0" \
6463            0 \
6464            -c "Read from server: .* bytes read"
6465
6466requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6467run_test    "Event-driven I/O, DTLS: client auth" \
6468            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
6469            "$P_CLI dtls=1 event=1 tickets=0" \
6470            0 \
6471            -c "Read from server: .* bytes read"
6472
6473requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6474run_test    "Event-driven I/O, DTLS: ticket" \
6475            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
6476            "$P_CLI dtls=1 event=1 tickets=1" \
6477            0 \
6478            -c "Read from server: .* bytes read"
6479
6480requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6481run_test    "Event-driven I/O, DTLS: ticket + client auth" \
6482            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
6483            "$P_CLI dtls=1 event=1 tickets=1" \
6484            0 \
6485            -c "Read from server: .* bytes read"
6486
6487requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6488run_test    "Event-driven I/O, DTLS: ticket + client auth + resume" \
6489            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
6490            "$P_CLI dtls=1 event=1 tickets=1 reconnect=1 skip_close_notify=1" \
6491            0 \
6492            -c "Read from server: .* bytes read"
6493
6494requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6495run_test    "Event-driven I/O, DTLS: ticket + resume" \
6496            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
6497            "$P_CLI dtls=1 event=1 tickets=1 reconnect=1 skip_close_notify=1" \
6498            0 \
6499            -c "Read from server: .* bytes read"
6500
6501requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6502run_test    "Event-driven I/O, DTLS: session-id resume" \
6503            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
6504            "$P_CLI dtls=1 event=1 tickets=0 reconnect=1 skip_close_notify=1" \
6505            0 \
6506            -c "Read from server: .* bytes read"
6507
6508# This test demonstrates the need for the mbedtls_ssl_check_pending function.
6509# During session resumption, the client will send its ApplicationData record
6510# within the same datagram as the Finished messages. In this situation, the
6511# server MUST NOT idle on the underlying transport after handshake completion,
6512# because the ApplicationData request has already been queued internally.
6513requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6514run_test    "Event-driven I/O, DTLS: session-id resume, UDP packing" \
6515            -p "$P_PXY pack=50" \
6516            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
6517            "$P_CLI dtls=1 event=1 tickets=0 reconnect=1 skip_close_notify=1" \
6518            0 \
6519            -c "Read from server: .* bytes read"
6520
6521# Tests for version negotiation
6522
6523requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6524run_test    "Version check: all -> 1.2" \
6525            "$P_SRV" \
6526            "$P_CLI" \
6527            0 \
6528            -S "mbedtls_ssl_handshake returned" \
6529            -C "mbedtls_ssl_handshake returned" \
6530            -s "Protocol is TLSv1.2" \
6531            -c "Protocol is TLSv1.2"
6532
6533requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6534run_test    "Not supported version check: cli TLS 1.0" \
6535            "$P_SRV" \
6536            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.0" \
6537            1 \
6538            -s "Handshake protocol not within min/max boundaries" \
6539            -c "Error in protocol version" \
6540            -S "Protocol is TLSv1.0" \
6541            -C "Handshake was completed"
6542
6543requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6544run_test    "Not supported version check: cli TLS 1.1" \
6545            "$P_SRV" \
6546            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.1" \
6547            1 \
6548            -s "Handshake protocol not within min/max boundaries" \
6549            -c "Error in protocol version" \
6550            -S "Protocol is TLSv1.1" \
6551            -C "Handshake was completed"
6552
6553requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6554run_test    "Not supported version check: srv max TLS 1.0" \
6555            "$G_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0" \
6556            "$P_CLI" \
6557            1 \
6558            -s "Error in protocol version" \
6559            -c "Handshake protocol not within min/max boundaries" \
6560            -S "Version: TLS1.0" \
6561            -C "Protocol is TLSv1.0"
6562
6563requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6564run_test    "Not supported version check: srv max TLS 1.1" \
6565            "$G_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1" \
6566            "$P_CLI" \
6567            1 \
6568            -s "Error in protocol version" \
6569            -c "Handshake protocol not within min/max boundaries" \
6570            -S "Version: TLS1.1" \
6571            -C "Protocol is TLSv1.1"
6572
6573# Tests for ALPN extension
6574
6575requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6576run_test    "ALPN: none" \
6577            "$P_SRV debug_level=3" \
6578            "$P_CLI debug_level=3" \
6579            0 \
6580            -C "client hello, adding alpn extension" \
6581            -S "found alpn extension" \
6582            -C "got an alert message, type: \\[2:120]" \
6583            -S "server side, adding alpn extension" \
6584            -C "found alpn extension " \
6585            -C "Application Layer Protocol is" \
6586            -S "Application Layer Protocol is"
6587
6588requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6589run_test    "ALPN: client only" \
6590            "$P_SRV debug_level=3" \
6591            "$P_CLI debug_level=3 alpn=abc,1234" \
6592            0 \
6593            -c "client hello, adding alpn extension" \
6594            -s "found alpn extension" \
6595            -C "got an alert message, type: \\[2:120]" \
6596            -S "server side, adding alpn extension" \
6597            -C "found alpn extension " \
6598            -c "Application Layer Protocol is (none)" \
6599            -S "Application Layer Protocol is"
6600
6601requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6602run_test    "ALPN: server only" \
6603            "$P_SRV debug_level=3 alpn=abc,1234" \
6604            "$P_CLI debug_level=3" \
6605            0 \
6606            -C "client hello, adding alpn extension" \
6607            -S "found alpn extension" \
6608            -C "got an alert message, type: \\[2:120]" \
6609            -S "server side, adding alpn extension" \
6610            -C "found alpn extension " \
6611            -C "Application Layer Protocol is" \
6612            -s "Application Layer Protocol is (none)"
6613
6614requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6615run_test    "ALPN: both, common cli1-srv1" \
6616            "$P_SRV debug_level=3 alpn=abc,1234" \
6617            "$P_CLI debug_level=3 alpn=abc,1234" \
6618            0 \
6619            -c "client hello, adding alpn extension" \
6620            -s "found alpn extension" \
6621            -C "got an alert message, type: \\[2:120]" \
6622            -s "server side, adding alpn extension" \
6623            -c "found alpn extension" \
6624            -c "Application Layer Protocol is abc" \
6625            -s "Application Layer Protocol is abc"
6626
6627requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6628run_test    "ALPN: both, common cli2-srv1" \
6629            "$P_SRV debug_level=3 alpn=abc,1234" \
6630            "$P_CLI debug_level=3 alpn=1234,abc" \
6631            0 \
6632            -c "client hello, adding alpn extension" \
6633            -s "found alpn extension" \
6634            -C "got an alert message, type: \\[2:120]" \
6635            -s "server side, adding alpn extension" \
6636            -c "found alpn extension" \
6637            -c "Application Layer Protocol is abc" \
6638            -s "Application Layer Protocol is abc"
6639
6640requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6641run_test    "ALPN: both, common cli1-srv2" \
6642            "$P_SRV debug_level=3 alpn=abc,1234" \
6643            "$P_CLI debug_level=3 alpn=1234,abcde" \
6644            0 \
6645            -c "client hello, adding alpn extension" \
6646            -s "found alpn extension" \
6647            -C "got an alert message, type: \\[2:120]" \
6648            -s "server side, adding alpn extension" \
6649            -c "found alpn extension" \
6650            -c "Application Layer Protocol is 1234" \
6651            -s "Application Layer Protocol is 1234"
6652
6653requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6654run_test    "ALPN: both, no common" \
6655            "$P_SRV debug_level=3 alpn=abc,123" \
6656            "$P_CLI debug_level=3 alpn=1234,abcde" \
6657            1 \
6658            -c "client hello, adding alpn extension" \
6659            -s "found alpn extension" \
6660            -c "got an alert message, type: \\[2:120]" \
6661            -S "server side, adding alpn extension" \
6662            -C "found alpn extension" \
6663            -C "Application Layer Protocol is 1234" \
6664            -S "Application Layer Protocol is 1234"
6665
6666
6667# Tests for keyUsage in leaf certificates, part 1:
6668# server-side certificate/suite selection
6669
6670requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6671run_test    "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
6672            "$P_SRV key_file=data_files/server2.key \
6673             crt_file=data_files/server2.ku-ds.crt" \
6674            "$P_CLI" \
6675            0 \
6676            -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
6677
6678requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6679run_test    "keyUsage srv: RSA, keyEncipherment -> RSA" \
6680            "$P_SRV key_file=data_files/server2.key \
6681             crt_file=data_files/server2.ku-ke.crt" \
6682            "$P_CLI" \
6683            0 \
6684            -c "Ciphersuite is TLS-RSA-WITH-"
6685
6686requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6687run_test    "keyUsage srv: RSA, keyAgreement -> fail" \
6688            "$P_SRV key_file=data_files/server2.key \
6689             crt_file=data_files/server2.ku-ka.crt" \
6690            "$P_CLI" \
6691            1 \
6692            -C "Ciphersuite is "
6693
6694requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6695requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
6696run_test    "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
6697            "$P_SRV key_file=data_files/server5.key \
6698             crt_file=data_files/server5.ku-ds.crt" \
6699            "$P_CLI" \
6700            0 \
6701            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
6702
6703
6704requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6705run_test    "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
6706            "$P_SRV key_file=data_files/server5.key \
6707             crt_file=data_files/server5.ku-ka.crt" \
6708            "$P_CLI" \
6709            0 \
6710            -c "Ciphersuite is TLS-ECDH-"
6711
6712requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6713run_test    "keyUsage srv: ECDSA, keyEncipherment -> fail" \
6714            "$P_SRV key_file=data_files/server5.key \
6715             crt_file=data_files/server5.ku-ke.crt" \
6716            "$P_CLI" \
6717            1 \
6718            -C "Ciphersuite is "
6719
6720# Tests for keyUsage in leaf certificates, part 2:
6721# client-side checking of server cert
6722
6723requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6724run_test    "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
6725            "$O_SRV -tls1_2 -key data_files/server2.key \
6726             -cert data_files/server2.ku-ds_ke.crt" \
6727            "$P_CLI debug_level=1 \
6728             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6729            0 \
6730            -C "bad certificate (usage extensions)" \
6731            -C "Processing of the Certificate handshake message failed" \
6732            -c "Ciphersuite is TLS-"
6733
6734requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6735run_test    "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
6736            "$O_SRV -tls1_2 -key data_files/server2.key \
6737             -cert data_files/server2.ku-ds_ke.crt" \
6738            "$P_CLI debug_level=1 \
6739             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6740            0 \
6741            -C "bad certificate (usage extensions)" \
6742            -C "Processing of the Certificate handshake message failed" \
6743            -c "Ciphersuite is TLS-"
6744
6745requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6746run_test    "keyUsage cli: KeyEncipherment, RSA: OK" \
6747            "$O_SRV -tls1_2 -key data_files/server2.key \
6748             -cert data_files/server2.ku-ke.crt" \
6749            "$P_CLI debug_level=1 \
6750             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6751            0 \
6752            -C "bad certificate (usage extensions)" \
6753            -C "Processing of the Certificate handshake message failed" \
6754            -c "Ciphersuite is TLS-"
6755
6756requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6757run_test    "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
6758            "$O_SRV -tls1_2 -key data_files/server2.key \
6759             -cert data_files/server2.ku-ke.crt" \
6760            "$P_CLI debug_level=1 \
6761             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6762            1 \
6763            -c "bad certificate (usage extensions)" \
6764            -c "Processing of the Certificate handshake message failed" \
6765            -C "Ciphersuite is TLS-"
6766
6767requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6768run_test    "keyUsage cli: KeyEncipherment, DHE-RSA: fail, soft" \
6769            "$O_SRV -tls1_2 -key data_files/server2.key \
6770             -cert data_files/server2.ku-ke.crt" \
6771            "$P_CLI debug_level=1 auth_mode=optional \
6772             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6773            0 \
6774            -c "bad certificate (usage extensions)" \
6775            -C "Processing of the Certificate handshake message failed" \
6776            -c "Ciphersuite is TLS-" \
6777            -c "! Usage does not match the keyUsage extension"
6778
6779requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6780run_test    "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
6781            "$O_SRV -tls1_2 -key data_files/server2.key \
6782             -cert data_files/server2.ku-ds.crt" \
6783            "$P_CLI debug_level=1 \
6784             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6785            0 \
6786            -C "bad certificate (usage extensions)" \
6787            -C "Processing of the Certificate handshake message failed" \
6788            -c "Ciphersuite is TLS-"
6789
6790requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6791run_test    "keyUsage cli: DigitalSignature, RSA: fail" \
6792            "$O_SRV -tls1_2 -key data_files/server2.key \
6793             -cert data_files/server2.ku-ds.crt" \
6794            "$P_CLI debug_level=1 \
6795             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6796            1 \
6797            -c "bad certificate (usage extensions)" \
6798            -c "Processing of the Certificate handshake message failed" \
6799            -C "Ciphersuite is TLS-"
6800
6801requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6802run_test    "keyUsage cli: DigitalSignature, RSA: fail, soft" \
6803            "$O_SRV -tls1_2 -key data_files/server2.key \
6804             -cert data_files/server2.ku-ds.crt" \
6805            "$P_CLI debug_level=1 auth_mode=optional \
6806             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6807            0 \
6808            -c "bad certificate (usage extensions)" \
6809            -C "Processing of the Certificate handshake message failed" \
6810            -c "Ciphersuite is TLS-" \
6811            -c "! Usage does not match the keyUsage extension"
6812
6813requires_openssl_tls1_3
6814requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6815                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6816run_test    "keyUsage cli 1.3: DigitalSignature+KeyEncipherment, RSA: OK" \
6817            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
6818             -cert data_files/server2.ku-ds_ke.crt" \
6819            "$P_CLI debug_level=3" \
6820            0 \
6821            -C "bad certificate (usage extensions)" \
6822            -C "Processing of the Certificate handshake message failed" \
6823            -c "Ciphersuite is"
6824
6825requires_openssl_tls1_3
6826requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6827                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6828run_test    "keyUsage cli 1.3: KeyEncipherment, RSA: fail" \
6829            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
6830             -cert data_files/server2.ku-ke.crt" \
6831            "$P_CLI debug_level=1" \
6832            1 \
6833            -c "bad certificate (usage extensions)" \
6834            -c "Processing of the Certificate handshake message failed" \
6835            -C "Ciphersuite is"
6836
6837requires_openssl_tls1_3
6838requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6839                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6840run_test    "keyUsage cli 1.3: KeyAgreement, RSA: fail" \
6841            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
6842             -cert data_files/server2.ku-ka.crt" \
6843            "$P_CLI debug_level=1" \
6844            1 \
6845            -c "bad certificate (usage extensions)" \
6846            -c "Processing of the Certificate handshake message failed" \
6847            -C "Ciphersuite is"
6848
6849requires_openssl_tls1_3
6850requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6851                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6852run_test    "keyUsage cli 1.3: DigitalSignature, ECDSA: OK" \
6853            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6854             -cert data_files/server5.ku-ds.crt" \
6855            "$P_CLI debug_level=3" \
6856            0 \
6857            -C "bad certificate (usage extensions)" \
6858            -C "Processing of the Certificate handshake message failed" \
6859            -c "Ciphersuite is"
6860
6861requires_openssl_tls1_3
6862requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6863                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6864run_test    "keyUsage cli 1.3: KeyEncipherment, ECDSA: fail" \
6865            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6866             -cert data_files/server5.ku-ke.crt" \
6867            "$P_CLI debug_level=1" \
6868            1 \
6869            -c "bad certificate (usage extensions)" \
6870            -c "Processing of the Certificate handshake message failed" \
6871            -C "Ciphersuite is"
6872
6873requires_openssl_tls1_3
6874requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6875                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6876run_test    "keyUsage cli 1.3: KeyAgreement, ECDSA: fail" \
6877            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6878             -cert data_files/server5.ku-ka.crt" \
6879            "$P_CLI debug_level=1" \
6880            1 \
6881            -c "bad certificate (usage extensions)" \
6882            -c "Processing of the Certificate handshake message failed" \
6883            -C "Ciphersuite is"
6884
6885# Tests for keyUsage in leaf certificates, part 3:
6886# server-side checking of client cert
6887
6888requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6889run_test    "keyUsage cli-auth: RSA, DigitalSignature: OK" \
6890            "$P_SRV debug_level=1 auth_mode=optional" \
6891            "$O_CLI -key data_files/server2.key \
6892             -cert data_files/server2.ku-ds.crt" \
6893            0 \
6894            -s "Verifying peer X.509 certificate... ok" \
6895            -S "bad certificate (usage extensions)" \
6896            -S "Processing of the Certificate handshake message failed"
6897
6898requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6899run_test    "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
6900            "$P_SRV debug_level=1 auth_mode=optional" \
6901            "$O_CLI -key data_files/server2.key \
6902             -cert data_files/server2.ku-ke.crt" \
6903            0 \
6904            -s "bad certificate (usage extensions)" \
6905            -S "Processing of the Certificate handshake message failed"
6906
6907requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6908run_test    "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
6909            "$P_SRV debug_level=1 auth_mode=required" \
6910            "$O_CLI -key data_files/server2.key \
6911             -cert data_files/server2.ku-ke.crt" \
6912            1 \
6913            -s "bad certificate (usage extensions)" \
6914            -s "Processing of the Certificate handshake message failed"
6915
6916requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6917run_test    "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
6918            "$P_SRV debug_level=1 auth_mode=optional" \
6919            "$O_CLI -key data_files/server5.key \
6920             -cert data_files/server5.ku-ds.crt" \
6921            0 \
6922            -s "Verifying peer X.509 certificate... ok" \
6923            -S "bad certificate (usage extensions)" \
6924            -S "Processing of the Certificate handshake message failed"
6925
6926requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6927run_test    "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
6928            "$P_SRV debug_level=1 auth_mode=optional" \
6929            "$O_CLI -key data_files/server5.key \
6930             -cert data_files/server5.ku-ka.crt" \
6931            0 \
6932            -s "bad certificate (usage extensions)" \
6933            -S "Processing of the Certificate handshake message failed"
6934
6935requires_openssl_tls1_3
6936requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6937                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6938run_test    "keyUsage cli-auth 1.3: RSA, DigitalSignature: OK" \
6939            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6940            "$O_NEXT_CLI_NO_CERT -key data_files/server2.key \
6941             -cert data_files/server2.ku-ds.crt" \
6942            0 \
6943            -s "Verifying peer X.509 certificate... ok" \
6944            -S "bad certificate (usage extensions)" \
6945            -S "Processing of the Certificate handshake message failed"
6946
6947requires_openssl_tls1_3
6948requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6949                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6950run_test    "keyUsage cli-auth 1.3: RSA, KeyEncipherment: fail (soft)" \
6951            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6952            "$O_NEXT_CLI_NO_CERT -key data_files/server2.key \
6953             -cert data_files/server2.ku-ke.crt" \
6954            0 \
6955            -s "bad certificate (usage extensions)" \
6956            -S "Processing of the Certificate handshake message failed"
6957
6958requires_openssl_tls1_3
6959requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6960                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6961run_test    "keyUsage cli-auth 1.3: ECDSA, DigitalSignature: OK" \
6962            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6963            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
6964             -cert data_files/server5.ku-ds.crt" \
6965            0 \
6966            -s "Verifying peer X.509 certificate... ok" \
6967            -S "bad certificate (usage extensions)" \
6968            -S "Processing of the Certificate handshake message failed"
6969
6970requires_openssl_tls1_3
6971requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6972                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6973run_test    "keyUsage cli-auth 1.3: ECDSA, KeyAgreement: fail (soft)" \
6974            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6975            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
6976             -cert data_files/server5.ku-ka.crt" \
6977            0 \
6978            -s "bad certificate (usage extensions)" \
6979            -S "Processing of the Certificate handshake message failed"
6980
6981# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
6982
6983requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6984run_test    "extKeyUsage srv: serverAuth -> OK" \
6985            "$P_SRV key_file=data_files/server5.key \
6986             crt_file=data_files/server5.eku-srv.crt" \
6987            "$P_CLI" \
6988            0
6989
6990requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6991run_test    "extKeyUsage srv: serverAuth,clientAuth -> OK" \
6992            "$P_SRV key_file=data_files/server5.key \
6993             crt_file=data_files/server5.eku-srv.crt" \
6994            "$P_CLI" \
6995            0
6996
6997requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6998run_test    "extKeyUsage srv: codeSign,anyEKU -> OK" \
6999            "$P_SRV key_file=data_files/server5.key \
7000             crt_file=data_files/server5.eku-cs_any.crt" \
7001            "$P_CLI" \
7002            0
7003
7004requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7005run_test    "extKeyUsage srv: codeSign -> fail" \
7006            "$P_SRV key_file=data_files/server5.key \
7007             crt_file=data_files/server5.eku-cli.crt" \
7008            "$P_CLI" \
7009            1
7010
7011# Tests for extendedKeyUsage, part 2: client-side checking of server cert
7012
7013requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7014run_test    "extKeyUsage cli: serverAuth -> OK" \
7015            "$O_SRV -tls1_2 -key data_files/server5.key \
7016             -cert data_files/server5.eku-srv.crt" \
7017            "$P_CLI debug_level=1" \
7018            0 \
7019            -C "bad certificate (usage extensions)" \
7020            -C "Processing of the Certificate handshake message failed" \
7021            -c "Ciphersuite is TLS-"
7022
7023requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7024run_test    "extKeyUsage cli: serverAuth,clientAuth -> OK" \
7025            "$O_SRV -tls1_2 -key data_files/server5.key \
7026             -cert data_files/server5.eku-srv_cli.crt" \
7027            "$P_CLI debug_level=1" \
7028            0 \
7029            -C "bad certificate (usage extensions)" \
7030            -C "Processing of the Certificate handshake message failed" \
7031            -c "Ciphersuite is TLS-"
7032
7033requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7034run_test    "extKeyUsage cli: codeSign,anyEKU -> OK" \
7035            "$O_SRV -tls1_2 -key data_files/server5.key \
7036             -cert data_files/server5.eku-cs_any.crt" \
7037            "$P_CLI debug_level=1" \
7038            0 \
7039            -C "bad certificate (usage extensions)" \
7040            -C "Processing of the Certificate handshake message failed" \
7041            -c "Ciphersuite is TLS-"
7042
7043requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7044run_test    "extKeyUsage cli: codeSign -> fail" \
7045            "$O_SRV -tls1_2 -key data_files/server5.key \
7046             -cert data_files/server5.eku-cs.crt" \
7047            "$P_CLI debug_level=1" \
7048            1 \
7049            -c "bad certificate (usage extensions)" \
7050            -c "Processing of the Certificate handshake message failed" \
7051            -C "Ciphersuite is TLS-"
7052
7053requires_openssl_tls1_3
7054requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7055                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7056run_test    "extKeyUsage cli 1.3: serverAuth -> OK" \
7057            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7058             -cert data_files/server5.eku-srv.crt" \
7059            "$P_CLI debug_level=1" \
7060            0 \
7061            -C "bad certificate (usage extensions)" \
7062            -C "Processing of the Certificate handshake message failed" \
7063            -c "Ciphersuite is"
7064
7065requires_openssl_tls1_3
7066requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7067                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7068run_test    "extKeyUsage cli 1.3: serverAuth,clientAuth -> OK" \
7069            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7070             -cert data_files/server5.eku-srv_cli.crt" \
7071            "$P_CLI debug_level=1" \
7072            0 \
7073            -C "bad certificate (usage extensions)" \
7074            -C "Processing of the Certificate handshake message failed" \
7075            -c "Ciphersuite is"
7076
7077requires_openssl_tls1_3
7078requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7079                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7080run_test    "extKeyUsage cli 1.3: codeSign,anyEKU -> OK" \
7081            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7082             -cert data_files/server5.eku-cs_any.crt" \
7083            "$P_CLI debug_level=1" \
7084            0 \
7085            -C "bad certificate (usage extensions)" \
7086            -C "Processing of the Certificate handshake message failed" \
7087            -c "Ciphersuite is"
7088
7089requires_openssl_tls1_3
7090requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7091                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7092run_test    "extKeyUsage cli 1.3: codeSign -> fail" \
7093            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
7094             -cert data_files/server5.eku-cs.crt" \
7095            "$P_CLI debug_level=1" \
7096            1 \
7097            -c "bad certificate (usage extensions)" \
7098            -c "Processing of the Certificate handshake message failed" \
7099            -C "Ciphersuite is"
7100
7101# Tests for extendedKeyUsage, part 3: server-side checking of client cert
7102
7103requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7104run_test    "extKeyUsage cli-auth: clientAuth -> OK" \
7105            "$P_SRV debug_level=1 auth_mode=optional" \
7106            "$O_CLI -key data_files/server5.key \
7107             -cert data_files/server5.eku-cli.crt" \
7108            0 \
7109            -S "bad certificate (usage extensions)" \
7110            -S "Processing of the Certificate handshake message failed"
7111
7112requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7113run_test    "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
7114            "$P_SRV debug_level=1 auth_mode=optional" \
7115            "$O_CLI -key data_files/server5.key \
7116             -cert data_files/server5.eku-srv_cli.crt" \
7117            0 \
7118            -S "bad certificate (usage extensions)" \
7119            -S "Processing of the Certificate handshake message failed"
7120
7121requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7122run_test    "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
7123            "$P_SRV debug_level=1 auth_mode=optional" \
7124            "$O_CLI -key data_files/server5.key \
7125             -cert data_files/server5.eku-cs_any.crt" \
7126            0 \
7127            -S "bad certificate (usage extensions)" \
7128            -S "Processing of the Certificate handshake message failed"
7129
7130requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7131run_test    "extKeyUsage cli-auth: codeSign -> fail (soft)" \
7132            "$P_SRV debug_level=1 auth_mode=optional" \
7133            "$O_CLI -key data_files/server5.key \
7134             -cert data_files/server5.eku-cs.crt" \
7135            0 \
7136            -s "bad certificate (usage extensions)" \
7137            -S "Processing of the Certificate handshake message failed"
7138
7139requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7140run_test    "extKeyUsage cli-auth: codeSign -> fail (hard)" \
7141            "$P_SRV debug_level=1 auth_mode=required" \
7142            "$O_CLI -key data_files/server5.key \
7143             -cert data_files/server5.eku-cs.crt" \
7144            1 \
7145            -s "bad certificate (usage extensions)" \
7146            -s "Processing of the Certificate handshake message failed"
7147
7148requires_openssl_tls1_3
7149requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7150                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7151run_test    "extKeyUsage cli-auth 1.3: clientAuth -> OK" \
7152            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7153            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7154             -cert data_files/server5.eku-cli.crt" \
7155            0 \
7156            -S "bad certificate (usage extensions)" \
7157            -S "Processing of the Certificate handshake message failed"
7158
7159requires_openssl_tls1_3
7160requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7161                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7162run_test    "extKeyUsage cli-auth 1.3: serverAuth,clientAuth -> OK" \
7163            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7164            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7165             -cert data_files/server5.eku-srv_cli.crt" \
7166            0 \
7167            -S "bad certificate (usage extensions)" \
7168            -S "Processing of the Certificate handshake message failed"
7169
7170requires_openssl_tls1_3
7171requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7172                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7173run_test    "extKeyUsage cli-auth 1.3: codeSign,anyEKU -> OK" \
7174            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7175            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7176             -cert data_files/server5.eku-cs_any.crt" \
7177            0 \
7178            -S "bad certificate (usage extensions)" \
7179            -S "Processing of the Certificate handshake message failed"
7180
7181requires_openssl_tls1_3
7182requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7183                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7184run_test    "extKeyUsage cli-auth 1.3: codeSign -> fail (soft)" \
7185            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7186            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7187             -cert data_files/server5.eku-cs.crt" \
7188            0 \
7189            -s "bad certificate (usage extensions)" \
7190            -S "Processing of the Certificate handshake message failed"
7191
7192# Tests for DHM parameters loading
7193
7194requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7195run_test    "DHM parameters: reference" \
7196            "$P_SRV" \
7197            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7198                    debug_level=3" \
7199            0 \
7200            -c "value of 'DHM: P ' (2048 bits)" \
7201            -c "value of 'DHM: G ' (2 bits)"
7202
7203requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7204run_test    "DHM parameters: other parameters" \
7205            "$P_SRV dhm_file=data_files/dhparams.pem" \
7206            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7207                    debug_level=3" \
7208            0 \
7209            -c "value of 'DHM: P ' (1024 bits)" \
7210            -c "value of 'DHM: G ' (2 bits)"
7211
7212# Tests for DHM client-side size checking
7213
7214requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7215run_test    "DHM size: server default, client default, OK" \
7216            "$P_SRV" \
7217            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7218                    debug_level=1" \
7219            0 \
7220            -C "DHM prime too short:"
7221
7222requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7223run_test    "DHM size: server default, client 2048, OK" \
7224            "$P_SRV" \
7225            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7226                    debug_level=1 dhmlen=2048" \
7227            0 \
7228            -C "DHM prime too short:"
7229
7230requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7231run_test    "DHM size: server 1024, client default, OK" \
7232            "$P_SRV dhm_file=data_files/dhparams.pem" \
7233            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7234                    debug_level=1" \
7235            0 \
7236            -C "DHM prime too short:"
7237
7238requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7239run_test    "DHM size: server 999, client 999, OK" \
7240            "$P_SRV dhm_file=data_files/dh.999.pem" \
7241            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7242                    debug_level=1 dhmlen=999" \
7243            0 \
7244            -C "DHM prime too short:"
7245
7246requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7247run_test    "DHM size: server 1000, client 1000, OK" \
7248            "$P_SRV dhm_file=data_files/dh.1000.pem" \
7249            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7250                    debug_level=1 dhmlen=1000" \
7251            0 \
7252            -C "DHM prime too short:"
7253
7254requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7255run_test    "DHM size: server 1000, client default, rejected" \
7256            "$P_SRV dhm_file=data_files/dh.1000.pem" \
7257            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7258                    debug_level=1" \
7259            1 \
7260            -c "DHM prime too short:"
7261
7262requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7263run_test    "DHM size: server 1000, client 1001, rejected" \
7264            "$P_SRV dhm_file=data_files/dh.1000.pem" \
7265            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7266                    debug_level=1 dhmlen=1001" \
7267            1 \
7268            -c "DHM prime too short:"
7269
7270requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7271run_test    "DHM size: server 999, client 1000, rejected" \
7272            "$P_SRV dhm_file=data_files/dh.999.pem" \
7273            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7274                    debug_level=1 dhmlen=1000" \
7275            1 \
7276            -c "DHM prime too short:"
7277
7278requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7279run_test    "DHM size: server 998, client 999, rejected" \
7280            "$P_SRV dhm_file=data_files/dh.998.pem" \
7281            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7282                    debug_level=1 dhmlen=999" \
7283            1 \
7284            -c "DHM prime too short:"
7285
7286requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7287run_test    "DHM size: server default, client 2049, rejected" \
7288            "$P_SRV" \
7289            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7290                    debug_level=1 dhmlen=2049" \
7291            1 \
7292            -c "DHM prime too short:"
7293
7294# Tests for PSK callback
7295
7296requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7297run_test    "PSK callback: psk, no callback" \
7298            "$P_SRV psk=abc123 psk_identity=foo" \
7299            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7300            psk_identity=foo psk=abc123" \
7301            0 \
7302            -S "SSL - The handshake negotiation failed" \
7303            -S "SSL - Unknown identity received" \
7304            -S "SSL - Verification of the message MAC failed"
7305
7306requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7307requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7308run_test    "PSK callback: opaque psk on client, no callback" \
7309            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7310            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7311            psk_identity=foo psk=abc123 psk_opaque=1" \
7312            0 \
7313            -C "session hash for extended master secret"\
7314            -S "session hash for extended master secret"\
7315            -S "SSL - The handshake negotiation failed" \
7316            -S "SSL - Unknown identity received" \
7317            -S "SSL - Verification of the message MAC failed"
7318
7319requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7320requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7321run_test    "PSK callback: opaque psk on client, no callback, SHA-384" \
7322            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7323            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7324            psk_identity=foo psk=abc123 psk_opaque=1" \
7325            0 \
7326            -C "session hash for extended master secret"\
7327            -S "session hash for extended master secret"\
7328            -S "SSL - The handshake negotiation failed" \
7329            -S "SSL - Unknown identity received" \
7330            -S "SSL - Verification of the message MAC failed"
7331
7332requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7333requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7334run_test    "PSK callback: opaque psk on client, no callback, EMS" \
7335            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7336            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7337            psk_identity=foo psk=abc123 psk_opaque=1" \
7338            0 \
7339            -c "session hash for extended master secret"\
7340            -s "session hash for extended master secret"\
7341            -S "SSL - The handshake negotiation failed" \
7342            -S "SSL - Unknown identity received" \
7343            -S "SSL - Verification of the message MAC failed"
7344
7345requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7346requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7347run_test    "PSK callback: opaque psk on client, no callback, SHA-384, EMS" \
7348            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7349            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7350            psk_identity=foo psk=abc123 psk_opaque=1" \
7351            0 \
7352            -c "session hash for extended master secret"\
7353            -s "session hash for extended master secret"\
7354            -S "SSL - The handshake negotiation failed" \
7355            -S "SSL - Unknown identity received" \
7356            -S "SSL - Verification of the message MAC failed"
7357
7358requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7359requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7360run_test    "PSK callback: opaque rsa-psk on client, no callback" \
7361            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7362            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256 \
7363            psk_identity=foo psk=abc123 psk_opaque=1" \
7364            0 \
7365            -C "session hash for extended master secret"\
7366            -S "session hash for extended master secret"\
7367            -S "SSL - The handshake negotiation failed" \
7368            -S "SSL - Unknown identity received" \
7369            -S "SSL - Verification of the message MAC failed"
7370
7371requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7372requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7373run_test    "PSK callback: opaque rsa-psk on client, no callback, SHA-384" \
7374            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7375            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7376            psk_identity=foo psk=abc123 psk_opaque=1" \
7377            0 \
7378            -C "session hash for extended master secret"\
7379            -S "session hash for extended master secret"\
7380            -S "SSL - The handshake negotiation failed" \
7381            -S "SSL - Unknown identity received" \
7382            -S "SSL - Verification of the message MAC failed"
7383
7384requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7385requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7386run_test    "PSK callback: opaque rsa-psk on client, no callback, EMS" \
7387            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7388            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7389            psk_identity=foo psk=abc123 psk_opaque=1" \
7390            0 \
7391            -c "session hash for extended master secret"\
7392            -s "session hash for extended master secret"\
7393            -S "SSL - The handshake negotiation failed" \
7394            -S "SSL - Unknown identity received" \
7395            -S "SSL - Verification of the message MAC failed"
7396
7397requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7398requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7399run_test    "PSK callback: opaque rsa-psk on client, no callback, SHA-384, EMS" \
7400            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7401            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7402            psk_identity=foo psk=abc123 psk_opaque=1" \
7403            0 \
7404            -c "session hash for extended master secret"\
7405            -s "session hash for extended master secret"\
7406            -S "SSL - The handshake negotiation failed" \
7407            -S "SSL - Unknown identity received" \
7408            -S "SSL - Verification of the message MAC failed"
7409
7410requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7411requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7412run_test    "PSK callback: opaque ecdhe-psk on client, no callback" \
7413            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7414            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 \
7415            psk_identity=foo psk=abc123 psk_opaque=1" \
7416            0 \
7417            -C "session hash for extended master secret"\
7418            -S "session hash for extended master secret"\
7419            -S "SSL - The handshake negotiation failed" \
7420            -S "SSL - Unknown identity received" \
7421            -S "SSL - Verification of the message MAC failed"
7422
7423requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7424requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7425run_test    "PSK callback: opaque ecdhe-psk on client, no callback, SHA-384" \
7426            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7427            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7428            psk_identity=foo psk=abc123 psk_opaque=1" \
7429            0 \
7430            -C "session hash for extended master secret"\
7431            -S "session hash for extended master secret"\
7432            -S "SSL - The handshake negotiation failed" \
7433            -S "SSL - Unknown identity received" \
7434            -S "SSL - Verification of the message MAC failed"
7435
7436requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7437requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7438run_test    "PSK callback: opaque ecdhe-psk on client, no callback, EMS" \
7439            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7440            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7441            psk_identity=foo psk=abc123 psk_opaque=1" \
7442            0 \
7443            -c "session hash for extended master secret"\
7444            -s "session hash for extended master secret"\
7445            -S "SSL - The handshake negotiation failed" \
7446            -S "SSL - Unknown identity received" \
7447            -S "SSL - Verification of the message MAC failed"
7448
7449requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7450requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7451run_test    "PSK callback: opaque ecdhe-psk on client, no callback, SHA-384, EMS" \
7452            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7453            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7454            psk_identity=foo psk=abc123 psk_opaque=1" \
7455            0 \
7456            -c "session hash for extended master secret"\
7457            -s "session hash for extended master secret"\
7458            -S "SSL - The handshake negotiation failed" \
7459            -S "SSL - Unknown identity received" \
7460            -S "SSL - Verification of the message MAC failed"
7461
7462requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7463requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7464run_test    "PSK callback: opaque dhe-psk on client, no callback" \
7465            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7466            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA256 \
7467            psk_identity=foo psk=abc123 psk_opaque=1" \
7468            0 \
7469            -C "session hash for extended master secret"\
7470            -S "session hash for extended master secret"\
7471            -S "SSL - The handshake negotiation failed" \
7472            -S "SSL - Unknown identity received" \
7473            -S "SSL - Verification of the message MAC failed"
7474
7475requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7476requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7477run_test    "PSK callback: opaque dhe-psk on client, no callback, SHA-384" \
7478            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7479            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7480            psk_identity=foo psk=abc123 psk_opaque=1" \
7481            0 \
7482            -C "session hash for extended master secret"\
7483            -S "session hash for extended master secret"\
7484            -S "SSL - The handshake negotiation failed" \
7485            -S "SSL - Unknown identity received" \
7486            -S "SSL - Verification of the message MAC failed"
7487
7488requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7489requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7490run_test    "PSK callback: opaque dhe-psk on client, no callback, EMS" \
7491            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7492            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7493            psk_identity=foo psk=abc123 psk_opaque=1" \
7494            0 \
7495            -c "session hash for extended master secret"\
7496            -s "session hash for extended master secret"\
7497            -S "SSL - The handshake negotiation failed" \
7498            -S "SSL - Unknown identity received" \
7499            -S "SSL - Verification of the message MAC failed"
7500
7501requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7502requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7503run_test    "PSK callback: opaque dhe-psk on client, no callback, SHA-384, EMS" \
7504            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7505            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7506            psk_identity=foo psk=abc123 psk_opaque=1" \
7507            0 \
7508            -c "session hash for extended master secret"\
7509            -s "session hash for extended master secret"\
7510            -S "SSL - The handshake negotiation failed" \
7511            -S "SSL - Unknown identity received" \
7512            -S "SSL - Verification of the message MAC failed"
7513
7514requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7515requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7516run_test    "PSK callback: raw psk on client, static opaque on server, no callback" \
7517            "$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" \
7518            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7519            psk_identity=foo psk=abc123" \
7520            0 \
7521            -C "session hash for extended master secret"\
7522            -S "session hash for extended master secret"\
7523            -S "SSL - The handshake negotiation failed" \
7524            -S "SSL - Unknown identity received" \
7525            -S "SSL - Verification of the message MAC failed"
7526
7527requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7528requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7529run_test    "PSK callback: raw psk on client, static opaque on server, no callback, SHA-384" \
7530            "$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" \
7531            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7532            psk_identity=foo psk=abc123" \
7533            0 \
7534            -C "session hash for extended master secret"\
7535            -S "session hash for extended master secret"\
7536            -S "SSL - The handshake negotiation failed" \
7537            -S "SSL - Unknown identity received" \
7538            -S "SSL - Verification of the message MAC failed"
7539
7540requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7541requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7542run_test    "PSK callback: raw psk on client, static opaque on server, no callback, EMS" \
7543            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7544            force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7545            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7546            psk_identity=foo psk=abc123 extended_ms=1" \
7547            0 \
7548            -c "session hash for extended master secret"\
7549            -s "session hash for extended master secret"\
7550            -S "SSL - The handshake negotiation failed" \
7551            -S "SSL - Unknown identity received" \
7552            -S "SSL - Verification of the message MAC failed"
7553
7554requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7555requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7556run_test    "PSK callback: raw psk on client, static opaque on server, no callback, EMS, SHA384" \
7557            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7558            force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7559            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7560            psk_identity=foo psk=abc123 extended_ms=1" \
7561            0 \
7562            -c "session hash for extended master secret"\
7563            -s "session hash for extended master secret"\
7564            -S "SSL - The handshake negotiation failed" \
7565            -S "SSL - Unknown identity received" \
7566            -S "SSL - Verification of the message MAC failed"
7567
7568requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7569requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7570run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback" \
7571            "$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" \
7572            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7573            psk_identity=foo psk=abc123" \
7574            0 \
7575            -C "session hash for extended master secret"\
7576            -S "session hash for extended master secret"\
7577            -S "SSL - The handshake negotiation failed" \
7578            -S "SSL - Unknown identity received" \
7579            -S "SSL - Verification of the message MAC failed"
7580
7581requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7582requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7583run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, SHA-384" \
7584            "$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" \
7585            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7586            psk_identity=foo psk=abc123" \
7587            0 \
7588            -C "session hash for extended master secret"\
7589            -S "session hash for extended master secret"\
7590            -S "SSL - The handshake negotiation failed" \
7591            -S "SSL - Unknown identity received" \
7592            -S "SSL - Verification of the message MAC failed"
7593
7594requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7595requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7596run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, EMS" \
7597            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7598            force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7599            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7600            psk_identity=foo psk=abc123 extended_ms=1" \
7601            0 \
7602            -c "session hash for extended master secret"\
7603            -s "session hash for extended master secret"\
7604            -S "SSL - The handshake negotiation failed" \
7605            -S "SSL - Unknown identity received" \
7606            -S "SSL - Verification of the message MAC failed"
7607
7608requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7609requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7610run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, EMS, SHA384" \
7611            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7612            force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7613            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7614            psk_identity=foo psk=abc123 extended_ms=1" \
7615            0 \
7616            -c "session hash for extended master secret"\
7617            -s "session hash for extended master secret"\
7618            -S "SSL - The handshake negotiation failed" \
7619            -S "SSL - Unknown identity received" \
7620            -S "SSL - Verification of the message MAC failed"
7621
7622requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7623requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7624run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback" \
7625            "$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" \
7626            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7627            psk_identity=foo psk=abc123" \
7628            0 \
7629            -C "session hash for extended master secret"\
7630            -S "session hash for extended master secret"\
7631            -S "SSL - The handshake negotiation failed" \
7632            -S "SSL - Unknown identity received" \
7633            -S "SSL - Verification of the message MAC failed"
7634
7635requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7636requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7637run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, SHA-384" \
7638            "$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" \
7639            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7640            psk_identity=foo psk=abc123" \
7641            0 \
7642            -C "session hash for extended master secret"\
7643            -S "session hash for extended master secret"\
7644            -S "SSL - The handshake negotiation failed" \
7645            -S "SSL - Unknown identity received" \
7646            -S "SSL - Verification of the message MAC failed"
7647
7648requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7649requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7650run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, EMS" \
7651            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7652            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7653            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7654            psk_identity=foo psk=abc123 extended_ms=1" \
7655            0 \
7656            -c "session hash for extended master secret"\
7657            -s "session hash for extended master secret"\
7658            -S "SSL - The handshake negotiation failed" \
7659            -S "SSL - Unknown identity received" \
7660            -S "SSL - Verification of the message MAC failed"
7661
7662requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7663requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7664run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, EMS, SHA384" \
7665            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7666            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7667            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7668            psk_identity=foo psk=abc123 extended_ms=1" \
7669            0 \
7670            -c "session hash for extended master secret"\
7671            -s "session hash for extended master secret"\
7672            -S "SSL - The handshake negotiation failed" \
7673            -S "SSL - Unknown identity received" \
7674            -S "SSL - Verification of the message MAC failed"
7675
7676requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7677requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7678run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback" \
7679            "$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" \
7680            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7681            psk_identity=foo psk=abc123" \
7682            0 \
7683            -C "session hash for extended master secret"\
7684            -S "session hash for extended master secret"\
7685            -S "SSL - The handshake negotiation failed" \
7686            -S "SSL - Unknown identity received" \
7687            -S "SSL - Verification of the message MAC failed"
7688
7689requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7690requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7691run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, SHA-384" \
7692            "$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" \
7693            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7694            psk_identity=foo psk=abc123" \
7695            0 \
7696            -C "session hash for extended master secret"\
7697            -S "session hash for extended master secret"\
7698            -S "SSL - The handshake negotiation failed" \
7699            -S "SSL - Unknown identity received" \
7700            -S "SSL - Verification of the message MAC failed"
7701
7702requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7703requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7704run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, EMS" \
7705            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7706            force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7707            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7708            psk_identity=foo psk=abc123 extended_ms=1" \
7709            0 \
7710            -c "session hash for extended master secret"\
7711            -s "session hash for extended master secret"\
7712            -S "SSL - The handshake negotiation failed" \
7713            -S "SSL - Unknown identity received" \
7714            -S "SSL - Verification of the message MAC failed"
7715
7716requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7717requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7718run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, EMS, SHA384" \
7719            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7720            force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7721            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7722            psk_identity=foo psk=abc123 extended_ms=1" \
7723            0 \
7724            -c "session hash for extended master secret"\
7725            -s "session hash for extended master secret"\
7726            -S "SSL - The handshake negotiation failed" \
7727            -S "SSL - Unknown identity received" \
7728            -S "SSL - Verification of the message MAC failed"
7729
7730requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7731requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7732run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback" \
7733            "$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" \
7734            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7735            psk_identity=def psk=beef" \
7736            0 \
7737            -C "session hash for extended master secret"\
7738            -S "session hash for extended master secret"\
7739            -S "SSL - The handshake negotiation failed" \
7740            -S "SSL - Unknown identity received" \
7741            -S "SSL - Verification of the message MAC failed"
7742
7743requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7744requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7745run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, SHA-384" \
7746            "$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" \
7747            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7748            psk_identity=def psk=beef" \
7749            0 \
7750            -C "session hash for extended master secret"\
7751            -S "session hash for extended master secret"\
7752            -S "SSL - The handshake negotiation failed" \
7753            -S "SSL - Unknown identity received" \
7754            -S "SSL - Verification of the message MAC failed"
7755
7756requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7757requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7758run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, EMS" \
7759            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7760            force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7761            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7762            psk_identity=abc psk=dead extended_ms=1" \
7763            0 \
7764            -c "session hash for extended master secret"\
7765            -s "session hash for extended master secret"\
7766            -S "SSL - The handshake negotiation failed" \
7767            -S "SSL - Unknown identity received" \
7768            -S "SSL - Verification of the message MAC failed"
7769
7770requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7771requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7772run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, EMS, SHA384" \
7773            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7774            force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7775            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7776            psk_identity=abc psk=dead extended_ms=1" \
7777            0 \
7778            -c "session hash for extended master secret"\
7779            -s "session hash for extended master secret"\
7780            -S "SSL - The handshake negotiation failed" \
7781            -S "SSL - Unknown identity received" \
7782            -S "SSL - Verification of the message MAC failed"
7783
7784requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7785requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7786run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback" \
7787            "$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" \
7788            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7789            psk_identity=def psk=beef" \
7790            0 \
7791            -C "session hash for extended master secret"\
7792            -S "session hash for extended master secret"\
7793            -S "SSL - The handshake negotiation failed" \
7794            -S "SSL - Unknown identity received" \
7795            -S "SSL - Verification of the message MAC failed"
7796
7797requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7798requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7799run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, SHA-384" \
7800            "$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" \
7801            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7802            psk_identity=def psk=beef" \
7803            0 \
7804            -C "session hash for extended master secret"\
7805            -S "session hash for extended master secret"\
7806            -S "SSL - The handshake negotiation failed" \
7807            -S "SSL - Unknown identity received" \
7808            -S "SSL - Verification of the message MAC failed"
7809
7810requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7811requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7812run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, EMS" \
7813            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7814            force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7815            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7816            psk_identity=abc psk=dead extended_ms=1" \
7817            0 \
7818            -c "session hash for extended master secret"\
7819            -s "session hash for extended master secret"\
7820            -S "SSL - The handshake negotiation failed" \
7821            -S "SSL - Unknown identity received" \
7822            -S "SSL - Verification of the message MAC failed"
7823
7824requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7825requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7826run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, EMS, SHA384" \
7827            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7828            force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7829            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7830            psk_identity=abc psk=dead extended_ms=1" \
7831            0 \
7832            -c "session hash for extended master secret"\
7833            -s "session hash for extended master secret"\
7834            -S "SSL - The handshake negotiation failed" \
7835            -S "SSL - Unknown identity received" \
7836            -S "SSL - Verification of the message MAC failed"
7837
7838requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7839requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7840run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback" \
7841            "$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" \
7842            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7843            psk_identity=def psk=beef" \
7844            0 \
7845            -C "session hash for extended master secret"\
7846            -S "session hash for extended master secret"\
7847            -S "SSL - The handshake negotiation failed" \
7848            -S "SSL - Unknown identity received" \
7849            -S "SSL - Verification of the message MAC failed"
7850
7851requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7852requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7853run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, SHA-384" \
7854            "$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" \
7855            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7856            psk_identity=def psk=beef" \
7857            0 \
7858            -C "session hash for extended master secret"\
7859            -S "session hash for extended master secret"\
7860            -S "SSL - The handshake negotiation failed" \
7861            -S "SSL - Unknown identity received" \
7862            -S "SSL - Verification of the message MAC failed"
7863
7864requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7865requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7866run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, EMS" \
7867            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7868            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7869            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7870            psk_identity=abc psk=dead extended_ms=1" \
7871            0 \
7872            -c "session hash for extended master secret"\
7873            -s "session hash for extended master secret"\
7874            -S "SSL - The handshake negotiation failed" \
7875            -S "SSL - Unknown identity received" \
7876            -S "SSL - Verification of the message MAC failed"
7877
7878requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7879requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7880run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, EMS, SHA384" \
7881            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7882            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7883            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7884            psk_identity=abc psk=dead extended_ms=1" \
7885            0 \
7886            -c "session hash for extended master secret"\
7887            -s "session hash for extended master secret"\
7888            -S "SSL - The handshake negotiation failed" \
7889            -S "SSL - Unknown identity received" \
7890            -S "SSL - Verification of the message MAC failed"
7891
7892requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7893requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7894run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback" \
7895            "$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" \
7896            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7897            psk_identity=def psk=beef" \
7898            0 \
7899            -C "session hash for extended master secret"\
7900            -S "session hash for extended master secret"\
7901            -S "SSL - The handshake negotiation failed" \
7902            -S "SSL - Unknown identity received" \
7903            -S "SSL - Verification of the message MAC failed"
7904
7905requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7906requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7907run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, SHA-384" \
7908            "$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" \
7909            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7910            psk_identity=def psk=beef" \
7911            0 \
7912            -C "session hash for extended master secret"\
7913            -S "session hash for extended master secret"\
7914            -S "SSL - The handshake negotiation failed" \
7915            -S "SSL - Unknown identity received" \
7916            -S "SSL - Verification of the message MAC failed"
7917
7918requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7919requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7920run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, EMS" \
7921            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7922            force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7923            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7924            psk_identity=abc psk=dead extended_ms=1" \
7925            0 \
7926            -c "session hash for extended master secret"\
7927            -s "session hash for extended master secret"\
7928            -S "SSL - The handshake negotiation failed" \
7929            -S "SSL - Unknown identity received" \
7930            -S "SSL - Verification of the message MAC failed"
7931
7932requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7933requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7934run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, EMS, SHA384" \
7935            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7936            force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7937            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7938            psk_identity=abc psk=dead extended_ms=1" \
7939            0 \
7940            -c "session hash for extended master secret"\
7941            -s "session hash for extended master secret"\
7942            -S "SSL - The handshake negotiation failed" \
7943            -S "SSL - Unknown identity received" \
7944            -S "SSL - Verification of the message MAC failed"
7945
7946requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7947requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7948run_test    "PSK callback: raw psk on client, mismatching static raw PSK on server, opaque PSK from callback" \
7949            "$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" \
7950            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7951            psk_identity=def psk=beef" \
7952            0 \
7953            -C "session hash for extended master secret"\
7954            -S "session hash for extended master secret"\
7955            -S "SSL - The handshake negotiation failed" \
7956            -S "SSL - Unknown identity received" \
7957            -S "SSL - Verification of the message MAC failed"
7958
7959requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7960requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7961run_test    "PSK callback: raw psk on client, mismatching static opaque PSK on server, opaque PSK from callback" \
7962            "$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" \
7963            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7964            psk_identity=def psk=beef" \
7965            0 \
7966            -C "session hash for extended master secret"\
7967            -S "session hash for extended master secret"\
7968            -S "SSL - The handshake negotiation failed" \
7969            -S "SSL - Unknown identity received" \
7970            -S "SSL - Verification of the message MAC failed"
7971
7972requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7973requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7974run_test    "PSK callback: raw psk on client, mismatching static opaque PSK on server, raw PSK from callback" \
7975            "$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" \
7976            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7977            psk_identity=def psk=beef" \
7978            0 \
7979            -C "session hash for extended master secret"\
7980            -S "session hash for extended master secret"\
7981            -S "SSL - The handshake negotiation failed" \
7982            -S "SSL - Unknown identity received" \
7983            -S "SSL - Verification of the message MAC failed"
7984
7985requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7986requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7987run_test    "PSK callback: raw psk on client, id-matching but wrong raw PSK on server, opaque PSK from callback" \
7988            "$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" \
7989            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7990            psk_identity=def psk=beef" \
7991            0 \
7992            -C "session hash for extended master secret"\
7993            -S "session hash for extended master secret"\
7994            -S "SSL - The handshake negotiation failed" \
7995            -S "SSL - Unknown identity received" \
7996            -S "SSL - Verification of the message MAC failed"
7997
7998requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7999requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8000run_test    "PSK callback: raw psk on client, matching opaque PSK on server, wrong opaque PSK from callback" \
8001            "$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" \
8002            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8003            psk_identity=def psk=beef" \
8004            1 \
8005            -s "SSL - Verification of the message MAC failed"
8006
8007requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8008run_test    "PSK callback: no psk, no callback" \
8009            "$P_SRV" \
8010            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8011            psk_identity=foo psk=abc123" \
8012            1 \
8013            -s "SSL - The handshake negotiation failed" \
8014            -S "SSL - Unknown identity received" \
8015            -S "SSL - Verification of the message MAC failed"
8016
8017requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8018run_test    "PSK callback: callback overrides other settings" \
8019            "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
8020            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8021            psk_identity=foo psk=abc123" \
8022            1 \
8023            -S "SSL - The handshake negotiation failed" \
8024            -s "SSL - Unknown identity received" \
8025            -S "SSL - Verification of the message MAC failed"
8026
8027requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8028run_test    "PSK callback: first id matches" \
8029            "$P_SRV psk_list=abc,dead,def,beef" \
8030            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8031            psk_identity=abc psk=dead" \
8032            0 \
8033            -S "SSL - The handshake negotiation failed" \
8034            -S "SSL - Unknown identity received" \
8035            -S "SSL - Verification of the message MAC failed"
8036
8037requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8038run_test    "PSK callback: second id matches" \
8039            "$P_SRV psk_list=abc,dead,def,beef" \
8040            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8041            psk_identity=def psk=beef" \
8042            0 \
8043            -S "SSL - The handshake negotiation failed" \
8044            -S "SSL - Unknown identity received" \
8045            -S "SSL - Verification of the message MAC failed"
8046
8047requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8048run_test    "PSK callback: no match" \
8049            "$P_SRV psk_list=abc,dead,def,beef" \
8050            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8051            psk_identity=ghi psk=beef" \
8052            1 \
8053            -S "SSL - The handshake negotiation failed" \
8054            -s "SSL - Unknown identity received" \
8055            -S "SSL - Verification of the message MAC failed"
8056
8057requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8058run_test    "PSK callback: wrong key" \
8059            "$P_SRV psk_list=abc,dead,def,beef" \
8060            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
8061            psk_identity=abc psk=beef" \
8062            1 \
8063            -S "SSL - The handshake negotiation failed" \
8064            -S "SSL - Unknown identity received" \
8065            -s "SSL - Verification of the message MAC failed"
8066
8067# Tests for EC J-PAKE
8068
8069requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8070requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8071run_test    "ECJPAKE: client not configured" \
8072            "$P_SRV debug_level=3" \
8073            "$P_CLI debug_level=3" \
8074            0 \
8075            -C "add ciphersuite: 0xc0ff" \
8076            -C "adding ecjpake_kkpp extension" \
8077            -S "found ecjpake kkpp extension" \
8078            -S "skip ecjpake kkpp extension" \
8079            -S "ciphersuite mismatch: ecjpake not configured" \
8080            -S "server hello, ecjpake kkpp extension" \
8081            -C "found ecjpake_kkpp extension" \
8082            -S "SSL - The handshake negotiation failed"
8083
8084requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8085requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8086run_test    "ECJPAKE: server not configured" \
8087            "$P_SRV debug_level=3" \
8088            "$P_CLI debug_level=3 ecjpake_pw=bla \
8089             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8090            1 \
8091            -c "add ciphersuite: c0ff" \
8092            -c "adding ecjpake_kkpp extension" \
8093            -s "found ecjpake kkpp extension" \
8094            -s "skip ecjpake kkpp extension" \
8095            -s "ciphersuite mismatch: ecjpake not configured" \
8096            -S "server hello, ecjpake kkpp extension" \
8097            -C "found ecjpake_kkpp extension" \
8098            -s "SSL - The handshake negotiation failed"
8099
8100# Note: if the name of this test is changed, then please adjust the corresponding
8101#       filtering label in "test_tls1_2_ecjpake_compatibility" (in "all.sh")
8102requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8103requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8104run_test    "ECJPAKE: working, TLS" \
8105            "$P_SRV debug_level=3 ecjpake_pw=bla" \
8106            "$P_CLI debug_level=3 ecjpake_pw=bla \
8107             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8108            0 \
8109            -c "add ciphersuite: c0ff" \
8110            -c "adding ecjpake_kkpp extension" \
8111            -C "re-using cached ecjpake parameters" \
8112            -s "found ecjpake kkpp extension" \
8113            -S "skip ecjpake kkpp extension" \
8114            -S "ciphersuite mismatch: ecjpake not configured" \
8115            -s "server hello, ecjpake kkpp extension" \
8116            -c "found ecjpake_kkpp extension" \
8117            -S "SSL - The handshake negotiation failed" \
8118            -S "SSL - Verification of the message MAC failed"
8119
8120requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8121requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8122requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8123run_test    "ECJPAKE: opaque password client+server, working, TLS" \
8124            "$P_SRV debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1" \
8125            "$P_CLI debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1\
8126             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8127            0 \
8128            -c "add ciphersuite: c0ff" \
8129            -c "adding ecjpake_kkpp extension" \
8130            -c "using opaque password" \
8131            -s "using opaque password" \
8132            -C "re-using cached ecjpake parameters" \
8133            -s "found ecjpake kkpp extension" \
8134            -S "skip ecjpake kkpp extension" \
8135            -S "ciphersuite mismatch: ecjpake not configured" \
8136            -s "server hello, ecjpake kkpp extension" \
8137            -c "found ecjpake_kkpp extension" \
8138            -S "SSL - The handshake negotiation failed" \
8139            -S "SSL - Verification of the message MAC failed"
8140
8141# Note: if the name of this test is changed, then please adjust the corresponding
8142#       filtering label in "test_tls1_2_ecjpake_compatibility" (in "all.sh")
8143requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8144requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8145requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8146run_test    "ECJPAKE: opaque password client only, working, TLS" \
8147            "$P_SRV debug_level=3 ecjpake_pw=bla" \
8148            "$P_CLI debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1\
8149             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8150            0 \
8151            -c "add ciphersuite: c0ff" \
8152            -c "adding ecjpake_kkpp extension" \
8153            -c "using opaque password" \
8154            -S "using opaque password" \
8155            -C "re-using cached ecjpake parameters" \
8156            -s "found ecjpake kkpp extension" \
8157            -S "skip ecjpake kkpp extension" \
8158            -S "ciphersuite mismatch: ecjpake not configured" \
8159            -s "server hello, ecjpake kkpp extension" \
8160            -c "found ecjpake_kkpp extension" \
8161            -S "SSL - The handshake negotiation failed" \
8162            -S "SSL - Verification of the message MAC failed"
8163
8164# Note: if the name of this test is changed, then please adjust the corresponding
8165#       filtering label in "test_tls1_2_ecjpake_compatibility" (in "all.sh")
8166requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8167requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8168requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8169run_test    "ECJPAKE: opaque password server only, working, TLS" \
8170            "$P_SRV debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1" \
8171            "$P_CLI debug_level=3 ecjpake_pw=bla\
8172             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8173            0 \
8174            -c "add ciphersuite: c0ff" \
8175            -c "adding ecjpake_kkpp extension" \
8176            -C "using opaque password" \
8177            -s "using opaque password" \
8178            -C "re-using cached ecjpake parameters" \
8179            -s "found ecjpake kkpp extension" \
8180            -S "skip ecjpake kkpp extension" \
8181            -S "ciphersuite mismatch: ecjpake not configured" \
8182            -s "server hello, ecjpake kkpp extension" \
8183            -c "found ecjpake_kkpp extension" \
8184            -S "SSL - The handshake negotiation failed" \
8185            -S "SSL - Verification of the message MAC failed"
8186
8187server_needs_more_time 1
8188requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8189requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8190run_test    "ECJPAKE: password mismatch, TLS" \
8191            "$P_SRV debug_level=3 ecjpake_pw=bla" \
8192            "$P_CLI debug_level=3 ecjpake_pw=bad \
8193             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8194            1 \
8195            -C "re-using cached ecjpake parameters" \
8196            -s "SSL - Verification of the message MAC failed"
8197
8198server_needs_more_time 1
8199requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8200requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8201requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8202run_test    "ECJPAKE_OPAQUE_PW: opaque password mismatch, TLS" \
8203            "$P_SRV debug_level=3 ecjpake_pw=bla ecjpake_pw_opaque=1" \
8204            "$P_CLI debug_level=3 ecjpake_pw=bad ecjpake_pw_opaque=1 \
8205             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8206            1 \
8207            -c "using opaque password" \
8208            -s "using opaque password" \
8209            -C "re-using cached ecjpake parameters" \
8210            -s "SSL - Verification of the message MAC failed"
8211
8212requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8213requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8214run_test    "ECJPAKE: working, DTLS" \
8215            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
8216            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
8217             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8218            0 \
8219            -c "re-using cached ecjpake parameters" \
8220            -S "SSL - Verification of the message MAC failed"
8221
8222requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8223requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8224run_test    "ECJPAKE: working, DTLS, no cookie" \
8225            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla cookies=0" \
8226            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
8227             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8228            0 \
8229            -C "re-using cached ecjpake parameters" \
8230            -S "SSL - Verification of the message MAC failed"
8231
8232server_needs_more_time 1
8233requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8234requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8235run_test    "ECJPAKE: password mismatch, DTLS" \
8236            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
8237            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bad \
8238             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8239            1 \
8240            -c "re-using cached ecjpake parameters" \
8241            -s "SSL - Verification of the message MAC failed"
8242
8243# for tests with configs/config-thread.h
8244requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8245requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8246run_test    "ECJPAKE: working, DTLS, nolog" \
8247            "$P_SRV dtls=1 ecjpake_pw=bla" \
8248            "$P_CLI dtls=1 ecjpake_pw=bla \
8249             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8250            0
8251
8252# Test for ClientHello without extensions
8253
8254requires_gnutls
8255requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8256run_test    "ClientHello without extensions" \
8257            "$P_SRV debug_level=3" \
8258            "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION localhost" \
8259            0 \
8260            -s "dumping 'client hello extensions' (0 bytes)"
8261
8262# Tests for mbedtls_ssl_get_bytes_avail()
8263
8264# The server first reads buffer_size-1 bytes, then reads the remainder.
8265requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8266run_test    "mbedtls_ssl_get_bytes_avail: no extra data" \
8267            "$P_SRV buffer_size=100" \
8268            "$P_CLI request_size=100" \
8269            0 \
8270            -s "Read from client: 100 bytes read$"
8271
8272requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8273run_test    "mbedtls_ssl_get_bytes_avail: extra data (+1)" \
8274            "$P_SRV buffer_size=100" \
8275            "$P_CLI request_size=101" \
8276            0 \
8277            -s "Read from client: 101 bytes read (100 + 1)"
8278
8279requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8280requires_max_content_len 200
8281run_test    "mbedtls_ssl_get_bytes_avail: extra data (*2)" \
8282            "$P_SRV buffer_size=100" \
8283            "$P_CLI request_size=200" \
8284            0 \
8285            -s "Read from client: 200 bytes read (100 + 100)"
8286
8287requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8288run_test    "mbedtls_ssl_get_bytes_avail: extra data (max)" \
8289            "$P_SRV buffer_size=100" \
8290            "$P_CLI request_size=$MAX_CONTENT_LEN" \
8291            0 \
8292            -s "Read from client: $MAX_CONTENT_LEN bytes read (100 + $((MAX_CONTENT_LEN - 100)))"
8293
8294# Tests for small client packets
8295
8296run_test    "Small client packet TLS 1.2 BlockCipher" \
8297            "$P_SRV force_version=tls12" \
8298            "$P_CLI request_size=1 \
8299             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8300            0 \
8301            -s "Read from client: 1 bytes read"
8302
8303run_test    "Small client packet TLS 1.2 BlockCipher, without EtM" \
8304            "$P_SRV force_version=tls12" \
8305            "$P_CLI request_size=1 \
8306             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
8307            0 \
8308            -s "Read from client: 1 bytes read"
8309
8310run_test    "Small client packet TLS 1.2 BlockCipher larger MAC" \
8311            "$P_SRV force_version=tls12" \
8312            "$P_CLI request_size=1 \
8313             force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8314            0 \
8315            -s "Read from client: 1 bytes read"
8316
8317run_test    "Small client packet TLS 1.2 AEAD" \
8318            "$P_SRV force_version=tls12" \
8319            "$P_CLI request_size=1 \
8320             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8321            0 \
8322            -s "Read from client: 1 bytes read"
8323
8324run_test    "Small client packet TLS 1.2 AEAD shorter tag" \
8325            "$P_SRV force_version=tls12" \
8326            "$P_CLI request_size=1 \
8327             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8328            0 \
8329            -s "Read from client: 1 bytes read"
8330
8331requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8332run_test    "Small client packet TLS 1.3 AEAD" \
8333            "$P_SRV force_version=tls13" \
8334            "$P_CLI request_size=1 \
8335             force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8336            0 \
8337            -s "Read from client: 1 bytes read"
8338
8339requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8340run_test    "Small client packet TLS 1.3 AEAD shorter tag" \
8341            "$P_SRV force_version=tls13" \
8342            "$P_CLI request_size=1 \
8343             force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8344            0 \
8345            -s "Read from client: 1 bytes read"
8346
8347# Tests for small client packets in DTLS
8348
8349requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8350run_test    "Small client packet DTLS 1.2" \
8351            "$P_SRV dtls=1 force_version=dtls12" \
8352            "$P_CLI dtls=1 request_size=1 \
8353             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8354            0 \
8355            -s "Read from client: 1 bytes read"
8356
8357requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8358run_test    "Small client packet DTLS 1.2, without EtM" \
8359            "$P_SRV dtls=1 force_version=dtls12 etm=0" \
8360            "$P_CLI dtls=1 request_size=1 \
8361             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8362            0 \
8363            -s "Read from client: 1 bytes read"
8364
8365# Tests for small server packets
8366
8367run_test    "Small server packet TLS 1.2 BlockCipher" \
8368            "$P_SRV response_size=1 force_version=tls12" \
8369            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8370            0 \
8371            -c "Read from server: 1 bytes read"
8372
8373run_test    "Small server packet TLS 1.2 BlockCipher, without EtM" \
8374            "$P_SRV response_size=1 force_version=tls12" \
8375            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
8376            0 \
8377            -c "Read from server: 1 bytes read"
8378
8379run_test    "Small server packet TLS 1.2 BlockCipher larger MAC" \
8380            "$P_SRV response_size=1 force_version=tls12" \
8381            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8382            0 \
8383            -c "Read from server: 1 bytes read"
8384
8385run_test    "Small server packet TLS 1.2 AEAD" \
8386            "$P_SRV response_size=1 force_version=tls12" \
8387            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8388            0 \
8389            -c "Read from server: 1 bytes read"
8390
8391run_test    "Small server packet TLS 1.2 AEAD shorter tag" \
8392            "$P_SRV response_size=1 force_version=tls12" \
8393            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8394            0 \
8395            -c "Read from server: 1 bytes read"
8396
8397requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8398run_test    "Small server packet TLS 1.3 AEAD" \
8399            "$P_SRV response_size=1 force_version=tls13" \
8400            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8401            0 \
8402            -c "Read from server: 1 bytes read"
8403
8404requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8405run_test    "Small server packet TLS 1.3 AEAD shorter tag" \
8406            "$P_SRV response_size=1 force_version=tls13" \
8407            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8408            0 \
8409            -c "Read from server: 1 bytes read"
8410
8411# Tests for small server packets in DTLS
8412
8413requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8414run_test    "Small server packet DTLS 1.2" \
8415            "$P_SRV dtls=1 response_size=1 force_version=dtls12" \
8416            "$P_CLI dtls=1 \
8417             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8418            0 \
8419            -c "Read from server: 1 bytes read"
8420
8421requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8422run_test    "Small server packet DTLS 1.2, without EtM" \
8423            "$P_SRV dtls=1 response_size=1 force_version=dtls12 etm=0" \
8424            "$P_CLI dtls=1 \
8425             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8426            0 \
8427            -c "Read from server: 1 bytes read"
8428
8429# Test for large client packets
8430
8431# How many fragments do we expect to write $1 bytes?
8432fragments_for_write() {
8433    echo "$(( ( $1 + $MAX_OUT_LEN - 1 ) / $MAX_OUT_LEN ))"
8434}
8435
8436run_test    "Large client packet TLS 1.2 BlockCipher" \
8437            "$P_SRV force_version=tls12" \
8438            "$P_CLI request_size=16384 \
8439             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8440            0 \
8441            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8442            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8443
8444run_test    "Large client packet TLS 1.2 BlockCipher, without EtM" \
8445            "$P_SRV force_version=tls12" \
8446            "$P_CLI request_size=16384 etm=0 \
8447             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8448            0 \
8449            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8450
8451run_test    "Large client packet TLS 1.2 BlockCipher larger MAC" \
8452            "$P_SRV force_version=tls12" \
8453            "$P_CLI request_size=16384 \
8454             force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8455            0 \
8456            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8457            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8458
8459run_test    "Large client packet TLS 1.2 AEAD" \
8460            "$P_SRV force_version=tls12" \
8461            "$P_CLI request_size=16384 \
8462             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8463            0 \
8464            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8465            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8466
8467run_test    "Large client packet TLS 1.2 AEAD shorter tag" \
8468            "$P_SRV force_version=tls12" \
8469            "$P_CLI request_size=16384 \
8470             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8471            0 \
8472            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8473            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8474
8475requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8476run_test    "Large client packet TLS 1.3 AEAD" \
8477            "$P_SRV force_version=tls13" \
8478            "$P_CLI request_size=16384 \
8479             force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8480            0 \
8481            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8482            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8483
8484requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8485run_test    "Large client packet TLS 1.3 AEAD shorter tag" \
8486            "$P_SRV force_version=tls13" \
8487            "$P_CLI request_size=16384 \
8488             force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8489            0 \
8490            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8491            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8492
8493# The tests below fail when the server's OUT_CONTENT_LEN is less than 16384.
8494run_test    "Large server packet TLS 1.2 BlockCipher" \
8495            "$P_SRV response_size=16384 force_version=tls12" \
8496            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8497            0 \
8498            -c "Read from server: 16384 bytes read"
8499
8500run_test    "Large server packet TLS 1.2 BlockCipher, without EtM" \
8501            "$P_SRV response_size=16384 force_version=tls12" \
8502            "$P_CLI etm=0 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8503            0 \
8504            -s "16384 bytes written in 1 fragments" \
8505            -c "Read from server: 16384 bytes read"
8506
8507run_test    "Large server packet TLS 1.2 BlockCipher larger MAC" \
8508            "$P_SRV response_size=16384 force_version=tls12" \
8509            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8510            0 \
8511            -c "Read from server: 16384 bytes read"
8512
8513run_test    "Large server packet TLS 1.2 BlockCipher, without EtM, truncated MAC" \
8514            "$P_SRV response_size=16384 trunc_hmac=1 force_version=tls12" \
8515            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
8516            0 \
8517            -s "16384 bytes written in 1 fragments" \
8518            -c "Read from server: 16384 bytes read"
8519
8520run_test    "Large server packet TLS 1.2 AEAD" \
8521            "$P_SRV response_size=16384 force_version=tls12" \
8522            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8523            0 \
8524            -c "Read from server: 16384 bytes read"
8525
8526run_test    "Large server packet TLS 1.2 AEAD shorter tag" \
8527            "$P_SRV response_size=16384 force_version=tls12" \
8528            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8529            0 \
8530            -c "Read from server: 16384 bytes read"
8531
8532requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8533run_test    "Large server packet TLS 1.3 AEAD" \
8534            "$P_SRV response_size=16384 force_version=tls13" \
8535            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8536            0 \
8537            -c "Read from server: 16384 bytes read"
8538
8539requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8540run_test    "Large server packet TLS 1.3 AEAD shorter tag" \
8541            "$P_SRV response_size=16384 force_version=tls13" \
8542            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8543            0 \
8544            -c "Read from server: 16384 bytes read"
8545
8546# Tests for restartable ECC
8547
8548# Force the use of a curve that supports restartable ECC (secp256r1).
8549
8550requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8551requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8552requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8553run_test    "EC restart: TLS, default" \
8554            "$P_SRV curves=secp256r1 auth_mode=required" \
8555            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8556             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8557             debug_level=1" \
8558            0 \
8559            -C "x509_verify_cert.*4b00" \
8560            -C "mbedtls_pk_verify.*4b00" \
8561            -C "mbedtls_ecdh_make_public.*4b00" \
8562            -C "mbedtls_pk_sign.*4b00"
8563
8564requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8565requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8566requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8567run_test    "EC restart: TLS, max_ops=0" \
8568            "$P_SRV curves=secp256r1 auth_mode=required" \
8569            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8570             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8571             debug_level=1 ec_max_ops=0" \
8572            0 \
8573            -C "x509_verify_cert.*4b00" \
8574            -C "mbedtls_pk_verify.*4b00" \
8575            -C "mbedtls_ecdh_make_public.*4b00" \
8576            -C "mbedtls_pk_sign.*4b00"
8577
8578requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8579requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8580requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8581run_test    "EC restart: TLS, max_ops=65535" \
8582            "$P_SRV curves=secp256r1 auth_mode=required" \
8583            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8584             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8585             debug_level=1 ec_max_ops=65535" \
8586            0 \
8587            -C "x509_verify_cert.*4b00" \
8588            -C "mbedtls_pk_verify.*4b00" \
8589            -C "mbedtls_ecdh_make_public.*4b00" \
8590            -C "mbedtls_pk_sign.*4b00"
8591
8592# With USE_PSA disabled we expect full restartable behaviour.
8593requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8594requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8595requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8596requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
8597run_test    "EC restart: TLS, max_ops=1000 (no USE_PSA)" \
8598            "$P_SRV curves=secp256r1 auth_mode=required" \
8599            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8600             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8601             debug_level=1 ec_max_ops=1000" \
8602            0 \
8603            -c "x509_verify_cert.*4b00" \
8604            -c "mbedtls_pk_verify.*4b00" \
8605            -c "mbedtls_ecdh_make_public.*4b00" \
8606            -c "mbedtls_pk_sign.*4b00"
8607
8608# With USE_PSA enabled we expect only partial restartable behaviour:
8609# everything except ECDH (where TLS calls PSA directly).
8610requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8611requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8612requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8613requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8614run_test    "EC restart: TLS, max_ops=1000 (USE_PSA)" \
8615            "$P_SRV curves=secp256r1 auth_mode=required" \
8616            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8617             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8618             debug_level=1 ec_max_ops=1000" \
8619            0 \
8620            -c "x509_verify_cert.*4b00" \
8621            -c "mbedtls_pk_verify.*4b00" \
8622            -C "mbedtls_ecdh_make_public.*4b00" \
8623            -c "mbedtls_pk_sign.*4b00"
8624
8625# This works the same with & without USE_PSA as we never get to ECDH:
8626# we abort as soon as we determined the cert is bad.
8627requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8628requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8629requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8630run_test    "EC restart: TLS, max_ops=1000, badsign" \
8631            "$P_SRV curves=secp256r1 auth_mode=required \
8632             crt_file=data_files/server5-badsign.crt \
8633             key_file=data_files/server5.key" \
8634            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8635             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8636             debug_level=1 ec_max_ops=1000" \
8637            1 \
8638            -c "x509_verify_cert.*4b00" \
8639            -C "mbedtls_pk_verify.*4b00" \
8640            -C "mbedtls_ecdh_make_public.*4b00" \
8641            -C "mbedtls_pk_sign.*4b00" \
8642            -c "! The certificate is not correctly signed by the trusted CA" \
8643            -c "! mbedtls_ssl_handshake returned" \
8644            -c "X509 - Certificate verification failed"
8645
8646# With USE_PSA disabled we expect full restartable behaviour.
8647requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8648requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8649requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8650requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
8651run_test    "EC restart: TLS, max_ops=1000, auth_mode=optional badsign (no USE_PSA)" \
8652            "$P_SRV curves=secp256r1 auth_mode=required \
8653             crt_file=data_files/server5-badsign.crt \
8654             key_file=data_files/server5.key" \
8655            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8656             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8657             debug_level=1 ec_max_ops=1000 auth_mode=optional" \
8658            0 \
8659            -c "x509_verify_cert.*4b00" \
8660            -c "mbedtls_pk_verify.*4b00" \
8661            -c "mbedtls_ecdh_make_public.*4b00" \
8662            -c "mbedtls_pk_sign.*4b00" \
8663            -c "! The certificate is not correctly signed by the trusted CA" \
8664            -C "! mbedtls_ssl_handshake returned" \
8665            -C "X509 - Certificate verification failed"
8666
8667# With USE_PSA enabled we expect only partial restartable behaviour:
8668# everything except ECDH (where TLS calls PSA directly).
8669requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8670requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8671requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8672requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8673run_test    "EC restart: TLS, max_ops=1000, auth_mode=optional badsign (USE_PSA)" \
8674            "$P_SRV curves=secp256r1 auth_mode=required \
8675             crt_file=data_files/server5-badsign.crt \
8676             key_file=data_files/server5.key" \
8677            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8678             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8679             debug_level=1 ec_max_ops=1000 auth_mode=optional" \
8680            0 \
8681            -c "x509_verify_cert.*4b00" \
8682            -c "mbedtls_pk_verify.*4b00" \
8683            -C "mbedtls_ecdh_make_public.*4b00" \
8684            -c "mbedtls_pk_sign.*4b00" \
8685            -c "! The certificate is not correctly signed by the trusted CA" \
8686            -C "! mbedtls_ssl_handshake returned" \
8687            -C "X509 - Certificate verification failed"
8688
8689# With USE_PSA disabled we expect full restartable behaviour.
8690requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8691requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8692requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8693requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
8694run_test    "EC restart: TLS, max_ops=1000, auth_mode=none badsign (no USE_PSA)" \
8695            "$P_SRV curves=secp256r1 auth_mode=required \
8696             crt_file=data_files/server5-badsign.crt \
8697             key_file=data_files/server5.key" \
8698            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8699             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8700             debug_level=1 ec_max_ops=1000 auth_mode=none" \
8701            0 \
8702            -C "x509_verify_cert.*4b00" \
8703            -c "mbedtls_pk_verify.*4b00" \
8704            -c "mbedtls_ecdh_make_public.*4b00" \
8705            -c "mbedtls_pk_sign.*4b00" \
8706            -C "! The certificate is not correctly signed by the trusted CA" \
8707            -C "! mbedtls_ssl_handshake returned" \
8708            -C "X509 - Certificate verification failed"
8709
8710# With USE_PSA enabled we expect only partial restartable behaviour:
8711# everything except ECDH (where TLS calls PSA directly).
8712requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8713requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8714requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8715requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8716run_test    "EC restart: TLS, max_ops=1000, auth_mode=none badsign (USE_PSA)" \
8717            "$P_SRV curves=secp256r1 auth_mode=required \
8718             crt_file=data_files/server5-badsign.crt \
8719             key_file=data_files/server5.key" \
8720            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8721             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8722             debug_level=1 ec_max_ops=1000 auth_mode=none" \
8723            0 \
8724            -C "x509_verify_cert.*4b00" \
8725            -c "mbedtls_pk_verify.*4b00" \
8726            -C "mbedtls_ecdh_make_public.*4b00" \
8727            -c "mbedtls_pk_sign.*4b00" \
8728            -C "! The certificate is not correctly signed by the trusted CA" \
8729            -C "! mbedtls_ssl_handshake returned" \
8730            -C "X509 - Certificate verification failed"
8731
8732# With USE_PSA disabled we expect full restartable behaviour.
8733requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8734requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8735requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8736requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
8737run_test    "EC restart: DTLS, max_ops=1000 (no USE_PSA)" \
8738            "$P_SRV curves=secp256r1 auth_mode=required dtls=1" \
8739            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8740             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8741             dtls=1 debug_level=1 ec_max_ops=1000" \
8742            0 \
8743            -c "x509_verify_cert.*4b00" \
8744            -c "mbedtls_pk_verify.*4b00" \
8745            -c "mbedtls_ecdh_make_public.*4b00" \
8746            -c "mbedtls_pk_sign.*4b00"
8747
8748# With USE_PSA enabled we expect only partial restartable behaviour:
8749# everything except ECDH (where TLS calls PSA directly).
8750requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8751requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8752requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8753requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8754run_test    "EC restart: DTLS, max_ops=1000 (USE_PSA)" \
8755            "$P_SRV curves=secp256r1 auth_mode=required dtls=1" \
8756            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8757             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8758             dtls=1 debug_level=1 ec_max_ops=1000" \
8759            0 \
8760            -c "x509_verify_cert.*4b00" \
8761            -c "mbedtls_pk_verify.*4b00" \
8762            -C "mbedtls_ecdh_make_public.*4b00" \
8763            -c "mbedtls_pk_sign.*4b00"
8764
8765# With USE_PSA disabled we expect full restartable behaviour.
8766requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8767requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8768requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8769requires_config_disabled MBEDTLS_USE_PSA_CRYPTO
8770run_test    "EC restart: TLS, max_ops=1000 no client auth (no USE_PSA)" \
8771            "$P_SRV curves=secp256r1" \
8772            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8773             debug_level=1 ec_max_ops=1000" \
8774            0 \
8775            -c "x509_verify_cert.*4b00" \
8776            -c "mbedtls_pk_verify.*4b00" \
8777            -c "mbedtls_ecdh_make_public.*4b00" \
8778            -C "mbedtls_pk_sign.*4b00"
8779
8780
8781# With USE_PSA enabled we expect only partial restartable behaviour:
8782# everything except ECDH (where TLS calls PSA directly).
8783requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8784requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8785requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8786requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
8787run_test    "EC restart: TLS, max_ops=1000 no client auth (USE_PSA)" \
8788            "$P_SRV curves=secp256r1" \
8789            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8790             debug_level=1 ec_max_ops=1000" \
8791            0 \
8792            -c "x509_verify_cert.*4b00" \
8793            -c "mbedtls_pk_verify.*4b00" \
8794            -C "mbedtls_ecdh_make_public.*4b00" \
8795            -C "mbedtls_pk_sign.*4b00"
8796
8797# Restartable is only for ECDHE-ECDSA, with another ciphersuite we expect no
8798# restartable behaviour at all (not even client auth).
8799# This is the same as "EC restart: TLS, max_ops=1000" except with ECDHE-RSA,
8800# and all 4 assertions negated.
8801requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8802requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8803requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8804run_test    "EC restart: TLS, max_ops=1000, ECDHE-RSA" \
8805            "$P_SRV curves=secp256r1 auth_mode=required" \
8806            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 \
8807             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8808             debug_level=1 ec_max_ops=1000" \
8809            0 \
8810            -C "x509_verify_cert.*4b00" \
8811            -C "mbedtls_pk_verify.*4b00" \
8812            -C "mbedtls_ecdh_make_public.*4b00" \
8813            -C "mbedtls_pk_sign.*4b00"
8814
8815# Tests of asynchronous private key support in SSL
8816
8817requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8818requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8819run_test    "SSL async private: sign, delay=0" \
8820            "$P_SRV \
8821             async_operations=s async_private_delay1=0 async_private_delay2=0" \
8822            "$P_CLI" \
8823            0 \
8824            -s "Async sign callback: using key slot " \
8825            -s "Async resume (slot [0-9]): sign done, status=0"
8826
8827requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8828requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8829run_test    "SSL async private: sign, delay=1" \
8830            "$P_SRV \
8831             async_operations=s async_private_delay1=1 async_private_delay2=1" \
8832            "$P_CLI" \
8833            0 \
8834            -s "Async sign callback: using key slot " \
8835            -s "Async resume (slot [0-9]): call 0 more times." \
8836            -s "Async resume (slot [0-9]): sign done, status=0"
8837
8838requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8839requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8840run_test    "SSL async private: sign, delay=2" \
8841            "$P_SRV \
8842             async_operations=s async_private_delay1=2 async_private_delay2=2" \
8843            "$P_CLI" \
8844            0 \
8845            -s "Async sign callback: using key slot " \
8846            -U "Async sign callback: using key slot " \
8847            -s "Async resume (slot [0-9]): call 1 more times." \
8848            -s "Async resume (slot [0-9]): call 0 more times." \
8849            -s "Async resume (slot [0-9]): sign done, status=0"
8850
8851requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8852requires_config_disabled MBEDTLS_X509_REMOVE_INFO
8853requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8854run_test    "SSL async private: sign, SNI" \
8855            "$P_SRV debug_level=3 \
8856             async_operations=s async_private_delay1=0 async_private_delay2=0 \
8857             crt_file=data_files/server5.crt key_file=data_files/server5.key \
8858             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
8859            "$P_CLI server_name=polarssl.example" \
8860            0 \
8861            -s "Async sign callback: using key slot " \
8862            -s "Async resume (slot [0-9]): sign done, status=0" \
8863            -s "parse ServerName extension" \
8864            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
8865            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
8866
8867requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8868requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8869run_test    "SSL async private: decrypt, delay=0" \
8870            "$P_SRV \
8871             async_operations=d async_private_delay1=0 async_private_delay2=0" \
8872            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8873            0 \
8874            -s "Async decrypt callback: using key slot " \
8875            -s "Async resume (slot [0-9]): decrypt done, status=0"
8876
8877requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8878requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8879run_test    "SSL async private: decrypt, delay=1" \
8880            "$P_SRV \
8881             async_operations=d async_private_delay1=1 async_private_delay2=1" \
8882            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8883            0 \
8884            -s "Async decrypt callback: using key slot " \
8885            -s "Async resume (slot [0-9]): call 0 more times." \
8886            -s "Async resume (slot [0-9]): decrypt done, status=0"
8887
8888requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8889requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8890run_test    "SSL async private: decrypt RSA-PSK, delay=0" \
8891            "$P_SRV psk=abc123 \
8892             async_operations=d async_private_delay1=0 async_private_delay2=0" \
8893            "$P_CLI psk=abc123 \
8894             force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
8895            0 \
8896            -s "Async decrypt callback: using key slot " \
8897            -s "Async resume (slot [0-9]): decrypt done, status=0"
8898
8899requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8900requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8901run_test    "SSL async private: decrypt RSA-PSK, delay=1" \
8902            "$P_SRV psk=abc123 \
8903             async_operations=d async_private_delay1=1 async_private_delay2=1" \
8904            "$P_CLI psk=abc123 \
8905             force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
8906            0 \
8907            -s "Async decrypt callback: using key slot " \
8908            -s "Async resume (slot [0-9]): call 0 more times." \
8909            -s "Async resume (slot [0-9]): decrypt done, status=0"
8910
8911requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8912requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8913run_test    "SSL async private: sign callback not present" \
8914            "$P_SRV \
8915             async_operations=d async_private_delay1=1 async_private_delay2=1" \
8916            "$P_CLI; [ \$? -eq 1 ] &&
8917             $P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8918            0 \
8919            -S "Async sign callback" \
8920            -s "! mbedtls_ssl_handshake returned" \
8921            -s "The own private key or pre-shared key is not set, but needed" \
8922            -s "Async resume (slot [0-9]): decrypt done, status=0" \
8923            -s "Successful connection"
8924
8925requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8926requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8927run_test    "SSL async private: decrypt callback not present" \
8928            "$P_SRV debug_level=1 \
8929             async_operations=s async_private_delay1=1 async_private_delay2=1" \
8930            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA;
8931             [ \$? -eq 1 ] && $P_CLI" \
8932            0 \
8933            -S "Async decrypt callback" \
8934            -s "! mbedtls_ssl_handshake returned" \
8935            -s "got no RSA private key" \
8936            -s "Async resume (slot [0-9]): sign done, status=0" \
8937            -s "Successful connection"
8938
8939# key1: ECDSA, key2: RSA; use key1 from slot 0
8940requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8941requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8942run_test    "SSL async private: slot 0 used with key1" \
8943            "$P_SRV \
8944             async_operations=s async_private_delay1=1 \
8945             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8946             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8947            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
8948            0 \
8949            -s "Async sign callback: using key slot 0," \
8950            -s "Async resume (slot 0): call 0 more times." \
8951            -s "Async resume (slot 0): sign done, status=0"
8952
8953# key1: ECDSA, key2: RSA; use key2 from slot 0
8954requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8955requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8956run_test    "SSL async private: slot 0 used with key2" \
8957            "$P_SRV \
8958             async_operations=s async_private_delay2=1 \
8959             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8960             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8961            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8962            0 \
8963            -s "Async sign callback: using key slot 0," \
8964            -s "Async resume (slot 0): call 0 more times." \
8965            -s "Async resume (slot 0): sign done, status=0"
8966
8967# key1: ECDSA, key2: RSA; use key2 from slot 1
8968requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8969requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8970run_test    "SSL async private: slot 1 used with key2" \
8971            "$P_SRV \
8972             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8973             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8974             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8975            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8976            0 \
8977            -s "Async sign callback: using key slot 1," \
8978            -s "Async resume (slot 1): call 0 more times." \
8979            -s "Async resume (slot 1): sign done, status=0"
8980
8981# key1: ECDSA, key2: RSA; use key2 directly
8982requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8983requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8984run_test    "SSL async private: fall back to transparent key" \
8985            "$P_SRV \
8986             async_operations=s async_private_delay1=1 \
8987             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8988             key_file2=data_files/server2.key crt_file2=data_files/server2.crt " \
8989            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8990            0 \
8991            -s "Async sign callback: no key matches this certificate."
8992
8993requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8994requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8995run_test    "SSL async private: sign, error in start" \
8996            "$P_SRV \
8997             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8998             async_private_error=1" \
8999            "$P_CLI" \
9000            1 \
9001            -s "Async sign callback: injected error" \
9002            -S "Async resume" \
9003            -S "Async cancel" \
9004            -s "! mbedtls_ssl_handshake returned"
9005
9006requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9007requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9008run_test    "SSL async private: sign, cancel after start" \
9009            "$P_SRV \
9010             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9011             async_private_error=2" \
9012            "$P_CLI" \
9013            1 \
9014            -s "Async sign callback: using key slot " \
9015            -S "Async resume" \
9016            -s "Async cancel"
9017
9018requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9019requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9020run_test    "SSL async private: sign, error in resume" \
9021            "$P_SRV \
9022             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9023             async_private_error=3" \
9024            "$P_CLI" \
9025            1 \
9026            -s "Async sign callback: using key slot " \
9027            -s "Async resume callback: sign done but injected error" \
9028            -S "Async cancel" \
9029            -s "! mbedtls_ssl_handshake returned"
9030
9031requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9032requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9033run_test    "SSL async private: decrypt, error in start" \
9034            "$P_SRV \
9035             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9036             async_private_error=1" \
9037            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9038            1 \
9039            -s "Async decrypt callback: injected error" \
9040            -S "Async resume" \
9041            -S "Async cancel" \
9042            -s "! mbedtls_ssl_handshake returned"
9043
9044requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9045requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9046run_test    "SSL async private: decrypt, cancel after start" \
9047            "$P_SRV \
9048             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9049             async_private_error=2" \
9050            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9051            1 \
9052            -s "Async decrypt callback: using key slot " \
9053            -S "Async resume" \
9054            -s "Async cancel"
9055
9056requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9057requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9058run_test    "SSL async private: decrypt, error in resume" \
9059            "$P_SRV \
9060             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9061             async_private_error=3" \
9062            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9063            1 \
9064            -s "Async decrypt callback: using key slot " \
9065            -s "Async resume callback: decrypt done but injected error" \
9066            -S "Async cancel" \
9067            -s "! mbedtls_ssl_handshake returned"
9068
9069requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9070requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9071run_test    "SSL async private: cancel after start then operate correctly" \
9072            "$P_SRV \
9073             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9074             async_private_error=-2" \
9075            "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
9076            0 \
9077            -s "Async cancel" \
9078            -s "! mbedtls_ssl_handshake returned" \
9079            -s "Async resume" \
9080            -s "Successful connection"
9081
9082requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9083requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9084run_test    "SSL async private: error in resume then operate correctly" \
9085            "$P_SRV \
9086             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9087             async_private_error=-3" \
9088            "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
9089            0 \
9090            -s "! mbedtls_ssl_handshake returned" \
9091            -s "Async resume" \
9092            -s "Successful connection"
9093
9094# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
9095requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9096requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9097# Note: the function "detect_required_features()" is not able to detect more than
9098#       one "force_ciphersuite" per client/server and it only picks the 2nd one.
9099#       Therefore the 1st one is added explicitly here
9100requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9101run_test    "SSL async private: cancel after start then fall back to transparent key" \
9102            "$P_SRV \
9103             async_operations=s async_private_delay1=1 async_private_error=-2 \
9104             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9105             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
9106            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
9107             [ \$? -eq 1 ] &&
9108             $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
9109            0 \
9110            -s "Async sign callback: using key slot 0" \
9111            -S "Async resume" \
9112            -s "Async cancel" \
9113            -s "! mbedtls_ssl_handshake returned" \
9114            -s "Async sign callback: no key matches this certificate." \
9115            -s "Successful connection"
9116
9117# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
9118requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9119requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9120# Note: the function "detect_required_features()" is not able to detect more than
9121#       one "force_ciphersuite" per client/server and it only picks the 2nd one.
9122#       Therefore the 1st one is added explicitly here
9123requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9124run_test    "SSL async private: sign, error in resume then fall back to transparent key" \
9125            "$P_SRV \
9126             async_operations=s async_private_delay1=1 async_private_error=-3 \
9127             key_file=data_files/server5.key crt_file=data_files/server5.crt \
9128             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
9129            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
9130             [ \$? -eq 1 ] &&
9131             $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
9132            0 \
9133            -s "Async resume" \
9134            -s "! mbedtls_ssl_handshake returned" \
9135            -s "Async sign callback: no key matches this certificate." \
9136            -s "Successful connection"
9137
9138requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9139requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9140requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9141run_test    "SSL async private: renegotiation: client-initiated, sign" \
9142            "$P_SRV \
9143             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9144             exchanges=2 renegotiation=1" \
9145            "$P_CLI exchanges=2 renegotiation=1 renegotiate=1" \
9146            0 \
9147            -s "Async sign callback: using key slot " \
9148            -s "Async resume (slot [0-9]): sign done, status=0"
9149
9150requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9151requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9152requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9153run_test    "SSL async private: renegotiation: server-initiated, sign" \
9154            "$P_SRV \
9155             async_operations=s async_private_delay1=1 async_private_delay2=1 \
9156             exchanges=2 renegotiation=1 renegotiate=1" \
9157            "$P_CLI exchanges=2 renegotiation=1" \
9158            0 \
9159            -s "Async sign callback: using key slot " \
9160            -s "Async resume (slot [0-9]): sign done, status=0"
9161
9162requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9163requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9164requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9165run_test    "SSL async private: renegotiation: client-initiated, decrypt" \
9166            "$P_SRV \
9167             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9168             exchanges=2 renegotiation=1" \
9169            "$P_CLI exchanges=2 renegotiation=1 renegotiate=1 \
9170             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9171            0 \
9172            -s "Async decrypt callback: using key slot " \
9173            -s "Async resume (slot [0-9]): decrypt done, status=0"
9174
9175requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
9176requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9177requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9178run_test    "SSL async private: renegotiation: server-initiated, decrypt" \
9179            "$P_SRV \
9180             async_operations=d async_private_delay1=1 async_private_delay2=1 \
9181             exchanges=2 renegotiation=1 renegotiate=1" \
9182            "$P_CLI exchanges=2 renegotiation=1 \
9183             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
9184            0 \
9185            -s "Async decrypt callback: using key slot " \
9186            -s "Async resume (slot [0-9]): decrypt done, status=0"
9187
9188# Tests for ECC extensions (rfc 4492)
9189
9190requires_config_enabled MBEDTLS_AES_C
9191requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
9192requires_hash_alg SHA_256
9193requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
9194requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9195run_test    "Force a non ECC ciphersuite in the client side" \
9196            "$P_SRV debug_level=3" \
9197            "$P_CLI debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
9198            0 \
9199            -C "client hello, adding supported_groups extension" \
9200            -C "client hello, adding supported_point_formats extension" \
9201            -S "found supported elliptic curves extension" \
9202            -S "found supported point formats extension"
9203
9204requires_config_enabled MBEDTLS_AES_C
9205requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
9206requires_hash_alg SHA_256
9207requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
9208requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9209run_test    "Force a non ECC ciphersuite in the server side" \
9210            "$P_SRV debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
9211            "$P_CLI debug_level=3" \
9212            0 \
9213            -C "found supported_point_formats extension" \
9214            -S "server hello, supported_point_formats extension"
9215
9216requires_config_enabled MBEDTLS_AES_C
9217requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
9218requires_hash_alg SHA_256
9219requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9220run_test    "Force an ECC ciphersuite in the client side" \
9221            "$P_SRV debug_level=3" \
9222            "$P_CLI debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
9223            0 \
9224            -c "client hello, adding supported_groups extension" \
9225            -c "client hello, adding supported_point_formats extension" \
9226            -s "found supported elliptic curves extension" \
9227            -s "found supported point formats extension"
9228
9229requires_config_enabled MBEDTLS_AES_C
9230requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
9231requires_hash_alg SHA_256
9232requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9233run_test    "Force an ECC ciphersuite in the server side" \
9234            "$P_SRV debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
9235            "$P_CLI debug_level=3" \
9236            0 \
9237            -c "found supported_point_formats extension" \
9238            -s "server hello, supported_point_formats extension"
9239
9240# Tests for DTLS HelloVerifyRequest
9241
9242requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9243run_test    "DTLS cookie: enabled" \
9244            "$P_SRV dtls=1 debug_level=2" \
9245            "$P_CLI dtls=1 debug_level=2" \
9246            0 \
9247            -s "cookie verification failed" \
9248            -s "cookie verification passed" \
9249            -S "cookie verification skipped" \
9250            -c "received hello verify request" \
9251            -s "hello verification requested" \
9252            -S "SSL - The requested feature is not available"
9253
9254requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9255run_test    "DTLS cookie: disabled" \
9256            "$P_SRV dtls=1 debug_level=2 cookies=0" \
9257            "$P_CLI dtls=1 debug_level=2" \
9258            0 \
9259            -S "cookie verification failed" \
9260            -S "cookie verification passed" \
9261            -s "cookie verification skipped" \
9262            -C "received hello verify request" \
9263            -S "hello verification requested" \
9264            -S "SSL - The requested feature is not available"
9265
9266requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9267run_test    "DTLS cookie: default (failing)" \
9268            "$P_SRV dtls=1 debug_level=2 cookies=-1" \
9269            "$P_CLI dtls=1 debug_level=2 hs_timeout=100-400" \
9270            1 \
9271            -s "cookie verification failed" \
9272            -S "cookie verification passed" \
9273            -S "cookie verification skipped" \
9274            -C "received hello verify request" \
9275            -S "hello verification requested" \
9276            -s "SSL - The requested feature is not available"
9277
9278requires_ipv6
9279requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9280run_test    "DTLS cookie: enabled, IPv6" \
9281            "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
9282            "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
9283            0 \
9284            -s "cookie verification failed" \
9285            -s "cookie verification passed" \
9286            -S "cookie verification skipped" \
9287            -c "received hello verify request" \
9288            -s "hello verification requested" \
9289            -S "SSL - The requested feature is not available"
9290
9291requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9292run_test    "DTLS cookie: enabled, nbio" \
9293            "$P_SRV dtls=1 nbio=2 debug_level=2" \
9294            "$P_CLI dtls=1 nbio=2 debug_level=2" \
9295            0 \
9296            -s "cookie verification failed" \
9297            -s "cookie verification passed" \
9298            -S "cookie verification skipped" \
9299            -c "received hello verify request" \
9300            -s "hello verification requested" \
9301            -S "SSL - The requested feature is not available"
9302
9303# Tests for client reconnecting from the same port with DTLS
9304
9305not_with_valgrind # spurious resend
9306requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9307run_test    "DTLS client reconnect from same port: reference" \
9308            "$P_SRV dtls=1 exchanges=2 read_timeout=20000 hs_timeout=10000-20000" \
9309            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=10000-20000" \
9310            0 \
9311            -C "resend" \
9312            -S "The operation timed out" \
9313            -S "Client initiated reconnection from same port"
9314
9315not_with_valgrind # spurious resend
9316requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9317run_test    "DTLS client reconnect from same port: reconnect" \
9318            "$P_SRV dtls=1 exchanges=2 read_timeout=20000 hs_timeout=10000-20000" \
9319            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=10000-20000 reconnect_hard=1" \
9320            0 \
9321            -C "resend" \
9322            -S "The operation timed out" \
9323            -s "Client initiated reconnection from same port"
9324
9325not_with_valgrind # server/client too slow to respond in time (next test has higher timeouts)
9326requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9327run_test    "DTLS client reconnect from same port: reconnect, nbio, no valgrind" \
9328            "$P_SRV dtls=1 exchanges=2 read_timeout=1000 nbio=2" \
9329            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000 reconnect_hard=1" \
9330            0 \
9331            -S "The operation timed out" \
9332            -s "Client initiated reconnection from same port"
9333
9334only_with_valgrind # Only with valgrind, do previous test but with higher read_timeout and hs_timeout
9335requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9336run_test    "DTLS client reconnect from same port: reconnect, nbio, valgrind" \
9337            "$P_SRV dtls=1 exchanges=2 read_timeout=2000 nbio=2 hs_timeout=1500-6000" \
9338            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=1500-3000 reconnect_hard=1" \
9339            0 \
9340            -S "The operation timed out" \
9341            -s "Client initiated reconnection from same port"
9342
9343requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9344run_test    "DTLS client reconnect from same port: no cookies" \
9345            "$P_SRV dtls=1 exchanges=2 read_timeout=1000 cookies=0" \
9346            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-8000 reconnect_hard=1" \
9347            0 \
9348            -s "The operation timed out" \
9349            -S "Client initiated reconnection from same port"
9350
9351requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9352run_test    "DTLS client reconnect from same port: attacker-injected" \
9353            -p "$P_PXY inject_clihlo=1" \
9354            "$P_SRV dtls=1 exchanges=2 debug_level=1" \
9355            "$P_CLI dtls=1 exchanges=2" \
9356            0 \
9357            -s "possible client reconnect from the same port" \
9358            -S "Client initiated reconnection from same port"
9359
9360# Tests for various cases of client authentication with DTLS
9361# (focused on handshake flows and message parsing)
9362
9363requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9364run_test    "DTLS client auth: required" \
9365            "$P_SRV dtls=1 auth_mode=required" \
9366            "$P_CLI dtls=1" \
9367            0 \
9368            -s "Verifying peer X.509 certificate... ok"
9369
9370requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9371run_test    "DTLS client auth: optional, client has no cert" \
9372            "$P_SRV dtls=1 auth_mode=optional" \
9373            "$P_CLI dtls=1 crt_file=none key_file=none" \
9374            0 \
9375            -s "! Certificate was missing"
9376
9377requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9378run_test    "DTLS client auth: none, client has no cert" \
9379            "$P_SRV dtls=1 auth_mode=none" \
9380            "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
9381            0 \
9382            -c "skip write certificate$" \
9383            -s "! Certificate verification was skipped"
9384
9385requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9386run_test    "DTLS wrong PSK: badmac alert" \
9387            "$P_SRV dtls=1 psk=abc123 force_ciphersuite=TLS-PSK-WITH-AES-128-GCM-SHA256" \
9388            "$P_CLI dtls=1 psk=abc124" \
9389            1 \
9390            -s "SSL - Verification of the message MAC failed" \
9391            -c "SSL - A fatal alert message was received from our peer"
9392
9393# Tests for receiving fragmented handshake messages with DTLS
9394
9395requires_gnutls
9396requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9397run_test    "DTLS reassembly: no fragmentation (gnutls server)" \
9398            "$G_SRV -u --mtu 2048 -a" \
9399            "$P_CLI dtls=1 debug_level=2" \
9400            0 \
9401            -C "found fragmented DTLS handshake message" \
9402            -C "error"
9403
9404requires_gnutls
9405requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9406run_test    "DTLS reassembly: some fragmentation (gnutls server)" \
9407            "$G_SRV -u --mtu 512" \
9408            "$P_CLI dtls=1 debug_level=2" \
9409            0 \
9410            -c "found fragmented DTLS handshake message" \
9411            -C "error"
9412
9413requires_gnutls
9414requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9415run_test    "DTLS reassembly: more fragmentation (gnutls server)" \
9416            "$G_SRV -u --mtu 128" \
9417            "$P_CLI dtls=1 debug_level=2" \
9418            0 \
9419            -c "found fragmented DTLS handshake message" \
9420            -C "error"
9421
9422requires_gnutls
9423requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9424run_test    "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
9425            "$G_SRV -u --mtu 128" \
9426            "$P_CLI dtls=1 nbio=2 debug_level=2" \
9427            0 \
9428            -c "found fragmented DTLS handshake message" \
9429            -C "error"
9430
9431requires_gnutls
9432requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9433requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9434run_test    "DTLS reassembly: fragmentation, renego (gnutls server)" \
9435            "$G_SRV -u --mtu 256" \
9436            "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
9437            0 \
9438            -c "found fragmented DTLS handshake message" \
9439            -c "client hello, adding renegotiation extension" \
9440            -c "found renegotiation extension" \
9441            -c "=> renegotiate" \
9442            -C "mbedtls_ssl_handshake returned" \
9443            -C "error" \
9444            -s "Extra-header:"
9445
9446requires_gnutls
9447requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9448requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9449run_test    "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
9450            "$G_SRV -u --mtu 256" \
9451            "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
9452            0 \
9453            -c "found fragmented DTLS handshake message" \
9454            -c "client hello, adding renegotiation extension" \
9455            -c "found renegotiation extension" \
9456            -c "=> renegotiate" \
9457            -C "mbedtls_ssl_handshake returned" \
9458            -C "error" \
9459            -s "Extra-header:"
9460
9461requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9462run_test    "DTLS reassembly: no fragmentation (openssl server)" \
9463            "$O_SRV -dtls -mtu 2048" \
9464            "$P_CLI dtls=1 debug_level=2" \
9465            0 \
9466            -C "found fragmented DTLS handshake message" \
9467            -C "error"
9468
9469requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9470run_test    "DTLS reassembly: some fragmentation (openssl server)" \
9471            "$O_SRV -dtls -mtu 768" \
9472            "$P_CLI dtls=1 debug_level=2" \
9473            0 \
9474            -c "found fragmented DTLS handshake message" \
9475            -C "error"
9476
9477requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9478run_test    "DTLS reassembly: more fragmentation (openssl server)" \
9479            "$O_SRV -dtls -mtu 256" \
9480            "$P_CLI dtls=1 debug_level=2" \
9481            0 \
9482            -c "found fragmented DTLS handshake message" \
9483            -C "error"
9484
9485requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9486run_test    "DTLS reassembly: fragmentation, nbio (openssl server)" \
9487            "$O_SRV -dtls -mtu 256" \
9488            "$P_CLI dtls=1 nbio=2 debug_level=2" \
9489            0 \
9490            -c "found fragmented DTLS handshake message" \
9491            -C "error"
9492
9493# Tests for sending fragmented handshake messages with DTLS
9494#
9495# Use client auth when we need the client to send large messages,
9496# and use large cert chains on both sides too (the long chains we have all use
9497# both RSA and ECDSA, but ideally we should have long chains with either).
9498# Sizes reached (UDP payload):
9499# - 2037B for server certificate
9500# - 1542B for client certificate
9501# - 1013B for newsessionticket
9502# - all others below 512B
9503# All those tests assume MAX_CONTENT_LEN is at least 2048
9504
9505requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9506requires_config_enabled MBEDTLS_RSA_C
9507requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9508requires_max_content_len 4096
9509requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9510run_test    "DTLS fragmenting: none (for reference)" \
9511            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9512             crt_file=data_files/server7_int-ca.crt \
9513             key_file=data_files/server7.key \
9514             hs_timeout=2500-60000 \
9515             max_frag_len=4096" \
9516            "$P_CLI dtls=1 debug_level=2 \
9517             crt_file=data_files/server8_int-ca2.crt \
9518             key_file=data_files/server8.key \
9519             hs_timeout=2500-60000 \
9520             max_frag_len=4096" \
9521            0 \
9522            -S "found fragmented DTLS handshake message" \
9523            -C "found fragmented DTLS handshake message" \
9524            -C "error"
9525
9526requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9527requires_config_enabled MBEDTLS_RSA_C
9528requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9529requires_max_content_len 2048
9530requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9531run_test    "DTLS fragmenting: server only (max_frag_len)" \
9532            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9533             crt_file=data_files/server7_int-ca.crt \
9534             key_file=data_files/server7.key \
9535             hs_timeout=2500-60000 \
9536             max_frag_len=1024" \
9537            "$P_CLI dtls=1 debug_level=2 \
9538             crt_file=data_files/server8_int-ca2.crt \
9539             key_file=data_files/server8.key \
9540             hs_timeout=2500-60000 \
9541             max_frag_len=2048" \
9542            0 \
9543            -S "found fragmented DTLS handshake message" \
9544            -c "found fragmented DTLS handshake message" \
9545            -C "error"
9546
9547# With the MFL extension, the server has no way of forcing
9548# the client to not exceed a certain MTU; hence, the following
9549# test can't be replicated with an MTU proxy such as the one
9550# `client-initiated, server only (max_frag_len)` below.
9551requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9552requires_config_enabled MBEDTLS_RSA_C
9553requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9554requires_max_content_len 4096
9555requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9556run_test    "DTLS fragmenting: server only (more) (max_frag_len)" \
9557            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9558             crt_file=data_files/server7_int-ca.crt \
9559             key_file=data_files/server7.key \
9560             hs_timeout=2500-60000 \
9561             max_frag_len=512" \
9562            "$P_CLI dtls=1 debug_level=2 \
9563             crt_file=data_files/server8_int-ca2.crt \
9564             key_file=data_files/server8.key \
9565             hs_timeout=2500-60000 \
9566             max_frag_len=4096" \
9567            0 \
9568            -S "found fragmented DTLS handshake message" \
9569            -c "found fragmented DTLS handshake message" \
9570            -C "error"
9571
9572requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9573requires_config_enabled MBEDTLS_RSA_C
9574requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9575requires_max_content_len 2048
9576requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9577run_test    "DTLS fragmenting: client-initiated, server only (max_frag_len)" \
9578            "$P_SRV dtls=1 debug_level=2 auth_mode=none \
9579             crt_file=data_files/server7_int-ca.crt \
9580             key_file=data_files/server7.key \
9581             hs_timeout=2500-60000 \
9582             max_frag_len=2048" \
9583            "$P_CLI dtls=1 debug_level=2 \
9584             crt_file=data_files/server8_int-ca2.crt \
9585             key_file=data_files/server8.key \
9586             hs_timeout=2500-60000 \
9587             max_frag_len=1024" \
9588             0 \
9589            -S "found fragmented DTLS handshake message" \
9590            -c "found fragmented DTLS handshake message" \
9591            -C "error"
9592
9593# While not required by the standard defining the MFL extension
9594# (according to which it only applies to records, not to datagrams),
9595# Mbed TLS will never send datagrams larger than MFL + { Max record expansion },
9596# as otherwise there wouldn't be any means to communicate MTU restrictions
9597# to the peer.
9598# The next test checks that no datagrams significantly larger than the
9599# negotiated MFL are sent.
9600requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9601requires_config_enabled MBEDTLS_RSA_C
9602requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9603requires_max_content_len 2048
9604requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9605run_test    "DTLS fragmenting: client-initiated, server only (max_frag_len), proxy MTU" \
9606            -p "$P_PXY mtu=1110" \
9607            "$P_SRV dtls=1 debug_level=2 auth_mode=none \
9608             crt_file=data_files/server7_int-ca.crt \
9609             key_file=data_files/server7.key \
9610             hs_timeout=2500-60000 \
9611             max_frag_len=2048" \
9612            "$P_CLI dtls=1 debug_level=2 \
9613             crt_file=data_files/server8_int-ca2.crt \
9614             key_file=data_files/server8.key \
9615             hs_timeout=2500-60000 \
9616             max_frag_len=1024" \
9617            0 \
9618            -S "found fragmented DTLS handshake message" \
9619            -c "found fragmented DTLS handshake message" \
9620            -C "error"
9621
9622requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9623requires_config_enabled MBEDTLS_RSA_C
9624requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9625requires_max_content_len 2048
9626requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9627run_test    "DTLS fragmenting: client-initiated, both (max_frag_len)" \
9628            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9629             crt_file=data_files/server7_int-ca.crt \
9630             key_file=data_files/server7.key \
9631             hs_timeout=2500-60000 \
9632             max_frag_len=2048" \
9633            "$P_CLI dtls=1 debug_level=2 \
9634             crt_file=data_files/server8_int-ca2.crt \
9635             key_file=data_files/server8.key \
9636             hs_timeout=2500-60000 \
9637             max_frag_len=1024" \
9638            0 \
9639            -s "found fragmented DTLS handshake message" \
9640            -c "found fragmented DTLS handshake message" \
9641            -C "error"
9642
9643# While not required by the standard defining the MFL extension
9644# (according to which it only applies to records, not to datagrams),
9645# Mbed TLS will never send datagrams larger than MFL + { Max record expansion },
9646# as otherwise there wouldn't be any means to communicate MTU restrictions
9647# to the peer.
9648# The next test checks that no datagrams significantly larger than the
9649# negotiated MFL are sent.
9650requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9651requires_config_enabled MBEDTLS_RSA_C
9652requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9653requires_max_content_len 2048
9654requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9655run_test    "DTLS fragmenting: client-initiated, both (max_frag_len), proxy MTU" \
9656            -p "$P_PXY mtu=1110" \
9657            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9658             crt_file=data_files/server7_int-ca.crt \
9659             key_file=data_files/server7.key \
9660             hs_timeout=2500-60000 \
9661             max_frag_len=2048" \
9662            "$P_CLI dtls=1 debug_level=2 \
9663             crt_file=data_files/server8_int-ca2.crt \
9664             key_file=data_files/server8.key \
9665             hs_timeout=2500-60000 \
9666             max_frag_len=1024" \
9667            0 \
9668            -s "found fragmented DTLS handshake message" \
9669            -c "found fragmented DTLS handshake message" \
9670            -C "error"
9671
9672requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9673requires_config_enabled MBEDTLS_RSA_C
9674requires_max_content_len 4096
9675requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9676run_test    "DTLS fragmenting: none (for reference) (MTU)" \
9677            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9678             crt_file=data_files/server7_int-ca.crt \
9679             key_file=data_files/server7.key \
9680             hs_timeout=2500-60000 \
9681             mtu=4096" \
9682            "$P_CLI dtls=1 debug_level=2 \
9683             crt_file=data_files/server8_int-ca2.crt \
9684             key_file=data_files/server8.key \
9685             hs_timeout=2500-60000 \
9686             mtu=4096" \
9687            0 \
9688            -S "found fragmented DTLS handshake message" \
9689            -C "found fragmented DTLS handshake message" \
9690            -C "error"
9691
9692requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9693requires_config_enabled MBEDTLS_RSA_C
9694requires_max_content_len 4096
9695requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9696run_test    "DTLS fragmenting: client (MTU)" \
9697            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9698             crt_file=data_files/server7_int-ca.crt \
9699             key_file=data_files/server7.key \
9700             hs_timeout=3500-60000 \
9701             mtu=4096" \
9702            "$P_CLI dtls=1 debug_level=2 \
9703             crt_file=data_files/server8_int-ca2.crt \
9704             key_file=data_files/server8.key \
9705             hs_timeout=3500-60000 \
9706             mtu=1024" \
9707            0 \
9708            -s "found fragmented DTLS handshake message" \
9709            -C "found fragmented DTLS handshake message" \
9710            -C "error"
9711
9712requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9713requires_config_enabled MBEDTLS_RSA_C
9714requires_max_content_len 2048
9715requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9716run_test    "DTLS fragmenting: server (MTU)" \
9717            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9718             crt_file=data_files/server7_int-ca.crt \
9719             key_file=data_files/server7.key \
9720             hs_timeout=2500-60000 \
9721             mtu=512" \
9722            "$P_CLI dtls=1 debug_level=2 \
9723             crt_file=data_files/server8_int-ca2.crt \
9724             key_file=data_files/server8.key \
9725             hs_timeout=2500-60000 \
9726             mtu=2048" \
9727            0 \
9728            -S "found fragmented DTLS handshake message" \
9729            -c "found fragmented DTLS handshake message" \
9730            -C "error"
9731
9732requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9733requires_config_enabled MBEDTLS_RSA_C
9734requires_max_content_len 2048
9735requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9736run_test    "DTLS fragmenting: both (MTU=1024)" \
9737            -p "$P_PXY mtu=1024" \
9738            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9739             crt_file=data_files/server7_int-ca.crt \
9740             key_file=data_files/server7.key \
9741             hs_timeout=2500-60000 \
9742             mtu=1024" \
9743            "$P_CLI dtls=1 debug_level=2 \
9744             crt_file=data_files/server8_int-ca2.crt \
9745             key_file=data_files/server8.key \
9746             hs_timeout=2500-60000 \
9747             mtu=1024" \
9748            0 \
9749            -s "found fragmented DTLS handshake message" \
9750            -c "found fragmented DTLS handshake message" \
9751            -C "error"
9752
9753# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9754requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9755requires_config_enabled MBEDTLS_RSA_C
9756requires_hash_alg SHA_256
9757requires_config_enabled MBEDTLS_AES_C
9758requires_config_enabled MBEDTLS_GCM_C
9759requires_max_content_len 2048
9760requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9761run_test    "DTLS fragmenting: both (MTU=512)" \
9762            -p "$P_PXY mtu=512" \
9763            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9764             crt_file=data_files/server7_int-ca.crt \
9765             key_file=data_files/server7.key \
9766             hs_timeout=2500-60000 \
9767             mtu=512" \
9768            "$P_CLI dtls=1 debug_level=2 \
9769             crt_file=data_files/server8_int-ca2.crt \
9770             key_file=data_files/server8.key \
9771             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9772             hs_timeout=2500-60000 \
9773             mtu=512" \
9774            0 \
9775            -s "found fragmented DTLS handshake message" \
9776            -c "found fragmented DTLS handshake message" \
9777            -C "error"
9778
9779# Test for automatic MTU reduction on repeated resend.
9780# Forcing ciphersuite for this test to fit the MTU of 508 with full config.
9781# The ratio of max/min timeout should ideally equal 4 to accept two
9782# retransmissions, but in some cases (like both the server and client using
9783# fragmentation and auto-reduction) an extra retransmission might occur,
9784# hence the ratio of 8.
9785not_with_valgrind
9786requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9787requires_config_enabled MBEDTLS_RSA_C
9788requires_config_enabled MBEDTLS_AES_C
9789requires_config_enabled MBEDTLS_GCM_C
9790requires_max_content_len 2048
9791requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9792run_test    "DTLS fragmenting: proxy MTU: auto-reduction (not valgrind)" \
9793            -p "$P_PXY mtu=508" \
9794            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9795             crt_file=data_files/server7_int-ca.crt \
9796             key_file=data_files/server7.key \
9797             hs_timeout=400-3200" \
9798            "$P_CLI dtls=1 debug_level=2 \
9799             crt_file=data_files/server8_int-ca2.crt \
9800             key_file=data_files/server8.key \
9801             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9802             hs_timeout=400-3200" \
9803            0 \
9804            -s "found fragmented DTLS handshake message" \
9805            -c "found fragmented DTLS handshake message" \
9806            -C "error"
9807
9808# Forcing ciphersuite for this test to fit the MTU of 508 with full config.
9809only_with_valgrind
9810requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9811requires_config_enabled MBEDTLS_RSA_C
9812requires_config_enabled MBEDTLS_AES_C
9813requires_config_enabled MBEDTLS_GCM_C
9814requires_max_content_len 2048
9815requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9816run_test    "DTLS fragmenting: proxy MTU: auto-reduction (with valgrind)" \
9817            -p "$P_PXY mtu=508" \
9818            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9819             crt_file=data_files/server7_int-ca.crt \
9820             key_file=data_files/server7.key \
9821             hs_timeout=250-10000" \
9822            "$P_CLI dtls=1 debug_level=2 \
9823             crt_file=data_files/server8_int-ca2.crt \
9824             key_file=data_files/server8.key \
9825             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9826             hs_timeout=250-10000" \
9827            0 \
9828            -s "found fragmented DTLS handshake message" \
9829            -c "found fragmented DTLS handshake message" \
9830            -C "error"
9831
9832# the proxy shouldn't drop or mess up anything, so we shouldn't need to resend
9833# OTOH the client might resend if the server is to slow to reset after sending
9834# a HelloVerifyRequest, so only check for no retransmission server-side
9835not_with_valgrind # spurious autoreduction due to timeout
9836requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9837requires_config_enabled MBEDTLS_RSA_C
9838requires_max_content_len 2048
9839requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9840run_test    "DTLS fragmenting: proxy MTU, simple handshake (MTU=1024)" \
9841            -p "$P_PXY mtu=1024" \
9842            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9843             crt_file=data_files/server7_int-ca.crt \
9844             key_file=data_files/server7.key \
9845             hs_timeout=10000-60000 \
9846             mtu=1024" \
9847            "$P_CLI dtls=1 debug_level=2 \
9848             crt_file=data_files/server8_int-ca2.crt \
9849             key_file=data_files/server8.key \
9850             hs_timeout=10000-60000 \
9851             mtu=1024" \
9852            0 \
9853            -S "autoreduction" \
9854            -s "found fragmented DTLS handshake message" \
9855            -c "found fragmented DTLS handshake message" \
9856            -C "error"
9857
9858# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9859# the proxy shouldn't drop or mess up anything, so we shouldn't need to resend
9860# OTOH the client might resend if the server is to slow to reset after sending
9861# a HelloVerifyRequest, so only check for no retransmission server-side
9862not_with_valgrind # spurious autoreduction due to timeout
9863requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9864requires_config_enabled MBEDTLS_RSA_C
9865requires_config_enabled MBEDTLS_AES_C
9866requires_config_enabled MBEDTLS_GCM_C
9867requires_max_content_len 2048
9868requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9869run_test    "DTLS fragmenting: proxy MTU, simple handshake (MTU=512)" \
9870            -p "$P_PXY mtu=512" \
9871            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9872             crt_file=data_files/server7_int-ca.crt \
9873             key_file=data_files/server7.key \
9874             hs_timeout=10000-60000 \
9875             mtu=512" \
9876            "$P_CLI dtls=1 debug_level=2 \
9877             crt_file=data_files/server8_int-ca2.crt \
9878             key_file=data_files/server8.key \
9879             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9880             hs_timeout=10000-60000 \
9881             mtu=512" \
9882            0 \
9883            -S "autoreduction" \
9884            -s "found fragmented DTLS handshake message" \
9885            -c "found fragmented DTLS handshake message" \
9886            -C "error"
9887
9888not_with_valgrind # spurious autoreduction due to timeout
9889requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9890requires_config_enabled MBEDTLS_RSA_C
9891requires_max_content_len 2048
9892requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9893run_test    "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=1024)" \
9894            -p "$P_PXY mtu=1024" \
9895            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9896             crt_file=data_files/server7_int-ca.crt \
9897             key_file=data_files/server7.key \
9898             hs_timeout=10000-60000 \
9899             mtu=1024 nbio=2" \
9900            "$P_CLI dtls=1 debug_level=2 \
9901             crt_file=data_files/server8_int-ca2.crt \
9902             key_file=data_files/server8.key \
9903             hs_timeout=10000-60000 \
9904             mtu=1024 nbio=2" \
9905            0 \
9906            -S "autoreduction" \
9907            -s "found fragmented DTLS handshake message" \
9908            -c "found fragmented DTLS handshake message" \
9909            -C "error"
9910
9911# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9912not_with_valgrind # spurious autoreduction due to timeout
9913requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9914requires_config_enabled MBEDTLS_RSA_C
9915requires_config_enabled MBEDTLS_AES_C
9916requires_config_enabled MBEDTLS_GCM_C
9917requires_max_content_len 2048
9918requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9919run_test    "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=512)" \
9920            -p "$P_PXY mtu=512" \
9921            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9922             crt_file=data_files/server7_int-ca.crt \
9923             key_file=data_files/server7.key \
9924             hs_timeout=10000-60000 \
9925             mtu=512 nbio=2" \
9926            "$P_CLI dtls=1 debug_level=2 \
9927             crt_file=data_files/server8_int-ca2.crt \
9928             key_file=data_files/server8.key \
9929             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9930             hs_timeout=10000-60000 \
9931             mtu=512 nbio=2" \
9932            0 \
9933            -S "autoreduction" \
9934            -s "found fragmented DTLS handshake message" \
9935            -c "found fragmented DTLS handshake message" \
9936            -C "error"
9937
9938# Forcing ciphersuite for this test to fit the MTU of 1450 with full config.
9939# This ensures things still work after session_reset().
9940# It also exercises the "resumed handshake" flow.
9941# Since we don't support reading fragmented ClientHello yet,
9942# up the MTU to 1450 (larger than ClientHello with session ticket,
9943# but still smaller than client's Certificate to ensure fragmentation).
9944# An autoreduction on the client-side might happen if the server is
9945# slow to reset, therefore omitting '-C "autoreduction"' below.
9946# reco_delay avoids races where the client reconnects before the server has
9947# resumed listening, which would result in a spurious autoreduction.
9948not_with_valgrind # spurious autoreduction due to timeout
9949requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9950requires_config_enabled MBEDTLS_RSA_C
9951requires_config_enabled MBEDTLS_AES_C
9952requires_config_enabled MBEDTLS_GCM_C
9953requires_max_content_len 2048
9954requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9955run_test    "DTLS fragmenting: proxy MTU, resumed handshake" \
9956            -p "$P_PXY mtu=1450" \
9957            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9958             crt_file=data_files/server7_int-ca.crt \
9959             key_file=data_files/server7.key \
9960             hs_timeout=10000-60000 \
9961             mtu=1450" \
9962            "$P_CLI dtls=1 debug_level=2 \
9963             crt_file=data_files/server8_int-ca2.crt \
9964             key_file=data_files/server8.key \
9965             hs_timeout=10000-60000 \
9966             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9967             mtu=1450 reconnect=1 skip_close_notify=1 reco_delay=1000" \
9968            0 \
9969            -S "autoreduction" \
9970            -s "found fragmented DTLS handshake message" \
9971            -c "found fragmented DTLS handshake message" \
9972            -C "error"
9973
9974# An autoreduction on the client-side might happen if the server is
9975# slow to reset, therefore omitting '-C "autoreduction"' below.
9976not_with_valgrind # spurious autoreduction due to timeout
9977requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9978requires_config_enabled MBEDTLS_RSA_C
9979requires_hash_alg SHA_256
9980requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9981requires_config_enabled MBEDTLS_CHACHAPOLY_C
9982requires_max_content_len 2048
9983requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9984run_test    "DTLS fragmenting: proxy MTU, ChachaPoly renego" \
9985            -p "$P_PXY mtu=512" \
9986            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9987             crt_file=data_files/server7_int-ca.crt \
9988             key_file=data_files/server7.key \
9989             exchanges=2 renegotiation=1 \
9990             hs_timeout=10000-60000 \
9991             mtu=512" \
9992            "$P_CLI dtls=1 debug_level=2 \
9993             crt_file=data_files/server8_int-ca2.crt \
9994             key_file=data_files/server8.key \
9995             exchanges=2 renegotiation=1 renegotiate=1 \
9996             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9997             hs_timeout=10000-60000 \
9998             mtu=512" \
9999            0 \
10000            -S "autoreduction" \
10001            -s "found fragmented DTLS handshake message" \
10002            -c "found fragmented DTLS handshake message" \
10003            -C "error"
10004
10005# An autoreduction on the client-side might happen if the server is
10006# slow to reset, therefore omitting '-C "autoreduction"' below.
10007not_with_valgrind # spurious autoreduction due to timeout
10008requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10009requires_config_enabled MBEDTLS_RSA_C
10010requires_hash_alg SHA_256
10011requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10012requires_config_enabled MBEDTLS_AES_C
10013requires_config_enabled MBEDTLS_GCM_C
10014requires_max_content_len 2048
10015requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10016run_test    "DTLS fragmenting: proxy MTU, AES-GCM renego" \
10017            -p "$P_PXY mtu=512" \
10018            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10019             crt_file=data_files/server7_int-ca.crt \
10020             key_file=data_files/server7.key \
10021             exchanges=2 renegotiation=1 \
10022             hs_timeout=10000-60000 \
10023             mtu=512" \
10024            "$P_CLI dtls=1 debug_level=2 \
10025             crt_file=data_files/server8_int-ca2.crt \
10026             key_file=data_files/server8.key \
10027             exchanges=2 renegotiation=1 renegotiate=1 \
10028             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10029             hs_timeout=10000-60000 \
10030             mtu=512" \
10031            0 \
10032            -S "autoreduction" \
10033            -s "found fragmented DTLS handshake message" \
10034            -c "found fragmented DTLS handshake message" \
10035            -C "error"
10036
10037# An autoreduction on the client-side might happen if the server is
10038# slow to reset, therefore omitting '-C "autoreduction"' below.
10039not_with_valgrind # spurious autoreduction due to timeout
10040requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10041requires_config_enabled MBEDTLS_RSA_C
10042requires_hash_alg SHA_256
10043requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10044requires_config_enabled MBEDTLS_AES_C
10045requires_config_enabled MBEDTLS_CCM_C
10046requires_max_content_len 2048
10047requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10048run_test    "DTLS fragmenting: proxy MTU, AES-CCM renego" \
10049            -p "$P_PXY mtu=1024" \
10050            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10051             crt_file=data_files/server7_int-ca.crt \
10052             key_file=data_files/server7.key \
10053             exchanges=2 renegotiation=1 \
10054             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8 \
10055             hs_timeout=10000-60000 \
10056             mtu=1024" \
10057            "$P_CLI dtls=1 debug_level=2 \
10058             crt_file=data_files/server8_int-ca2.crt \
10059             key_file=data_files/server8.key \
10060             exchanges=2 renegotiation=1 renegotiate=1 \
10061             hs_timeout=10000-60000 \
10062             mtu=1024" \
10063            0 \
10064            -S "autoreduction" \
10065            -s "found fragmented DTLS handshake message" \
10066            -c "found fragmented DTLS handshake message" \
10067            -C "error"
10068
10069# An autoreduction on the client-side might happen if the server is
10070# slow to reset, therefore omitting '-C "autoreduction"' below.
10071not_with_valgrind # spurious autoreduction due to timeout
10072requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10073requires_config_enabled MBEDTLS_RSA_C
10074requires_hash_alg SHA_256
10075requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10076requires_config_enabled MBEDTLS_AES_C
10077requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
10078requires_config_enabled MBEDTLS_SSL_ENCRYPT_THEN_MAC
10079requires_max_content_len 2048
10080requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10081run_test    "DTLS fragmenting: proxy MTU, AES-CBC EtM renego" \
10082            -p "$P_PXY mtu=1024" \
10083            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10084             crt_file=data_files/server7_int-ca.crt \
10085             key_file=data_files/server7.key \
10086             exchanges=2 renegotiation=1 \
10087             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 \
10088             hs_timeout=10000-60000 \
10089             mtu=1024" \
10090            "$P_CLI dtls=1 debug_level=2 \
10091             crt_file=data_files/server8_int-ca2.crt \
10092             key_file=data_files/server8.key \
10093             exchanges=2 renegotiation=1 renegotiate=1 \
10094             hs_timeout=10000-60000 \
10095             mtu=1024" \
10096            0 \
10097            -S "autoreduction" \
10098            -s "found fragmented DTLS handshake message" \
10099            -c "found fragmented DTLS handshake message" \
10100            -C "error"
10101
10102# An autoreduction on the client-side might happen if the server is
10103# slow to reset, therefore omitting '-C "autoreduction"' below.
10104not_with_valgrind # spurious autoreduction due to timeout
10105requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10106requires_config_enabled MBEDTLS_RSA_C
10107requires_hash_alg SHA_256
10108requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
10109requires_config_enabled MBEDTLS_AES_C
10110requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
10111requires_max_content_len 2048
10112requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10113run_test    "DTLS fragmenting: proxy MTU, AES-CBC non-EtM renego" \
10114            -p "$P_PXY mtu=1024" \
10115            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10116             crt_file=data_files/server7_int-ca.crt \
10117             key_file=data_files/server7.key \
10118             exchanges=2 renegotiation=1 \
10119             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 etm=0 \
10120             hs_timeout=10000-60000 \
10121             mtu=1024" \
10122            "$P_CLI dtls=1 debug_level=2 \
10123             crt_file=data_files/server8_int-ca2.crt \
10124             key_file=data_files/server8.key \
10125             exchanges=2 renegotiation=1 renegotiate=1 \
10126             hs_timeout=10000-60000 \
10127             mtu=1024" \
10128            0 \
10129            -S "autoreduction" \
10130            -s "found fragmented DTLS handshake message" \
10131            -c "found fragmented DTLS handshake message" \
10132            -C "error"
10133
10134# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
10135requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10136requires_config_enabled MBEDTLS_RSA_C
10137requires_config_enabled MBEDTLS_AES_C
10138requires_config_enabled MBEDTLS_GCM_C
10139client_needs_more_time 2
10140requires_max_content_len 2048
10141requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10142run_test    "DTLS fragmenting: proxy MTU + 3d" \
10143            -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
10144            "$P_SRV dgram_packing=0 dtls=1 debug_level=2 auth_mode=required \
10145             crt_file=data_files/server7_int-ca.crt \
10146             key_file=data_files/server7.key \
10147             hs_timeout=250-10000 mtu=512" \
10148            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10149             crt_file=data_files/server8_int-ca2.crt \
10150             key_file=data_files/server8.key \
10151             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10152             hs_timeout=250-10000 mtu=512" \
10153            0 \
10154            -s "found fragmented DTLS handshake message" \
10155            -c "found fragmented DTLS handshake message" \
10156            -C "error"
10157
10158# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
10159requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10160requires_config_enabled MBEDTLS_RSA_C
10161requires_config_enabled MBEDTLS_AES_C
10162requires_config_enabled MBEDTLS_GCM_C
10163client_needs_more_time 2
10164requires_max_content_len 2048
10165requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10166run_test    "DTLS fragmenting: proxy MTU + 3d, nbio" \
10167            -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
10168            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
10169             crt_file=data_files/server7_int-ca.crt \
10170             key_file=data_files/server7.key \
10171             hs_timeout=250-10000 mtu=512 nbio=2" \
10172            "$P_CLI dtls=1 debug_level=2 \
10173             crt_file=data_files/server8_int-ca2.crt \
10174             key_file=data_files/server8.key \
10175             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
10176             hs_timeout=250-10000 mtu=512 nbio=2" \
10177            0 \
10178            -s "found fragmented DTLS handshake message" \
10179            -c "found fragmented DTLS handshake message" \
10180            -C "error"
10181
10182# interop tests for DTLS fragmentating with reliable connection
10183#
10184# here and below we just want to test that the we fragment in a way that
10185# pleases other implementations, so we don't need the peer to fragment
10186requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10187requires_config_enabled MBEDTLS_RSA_C
10188requires_gnutls
10189requires_max_content_len 2048
10190run_test    "DTLS fragmenting: gnutls server, DTLS 1.2" \
10191            "$G_SRV -u" \
10192            "$P_CLI dtls=1 debug_level=2 \
10193             crt_file=data_files/server8_int-ca2.crt \
10194             key_file=data_files/server8.key \
10195             mtu=512 force_version=dtls12" \
10196            0 \
10197            -c "fragmenting handshake message" \
10198            -C "error"
10199
10200# We use --insecure for the GnuTLS client because it expects
10201# the hostname / IP it connects to to be the name used in the
10202# certificate obtained from the server. Here, however, it
10203# connects to 127.0.0.1 while our test certificates use 'localhost'
10204# as the server name in the certificate. This will make the
10205# certificate validation fail, but passing --insecure makes
10206# GnuTLS continue the connection nonetheless.
10207requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10208requires_config_enabled MBEDTLS_RSA_C
10209requires_gnutls
10210requires_not_i686
10211requires_max_content_len 2048
10212run_test    "DTLS fragmenting: gnutls client, DTLS 1.2" \
10213            "$P_SRV dtls=1 debug_level=2 \
10214             crt_file=data_files/server7_int-ca.crt \
10215             key_file=data_files/server7.key \
10216             mtu=512 force_version=dtls12" \
10217            "$G_CLI -u --insecure 127.0.0.1" \
10218            0 \
10219            -s "fragmenting handshake message"
10220
10221requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10222requires_config_enabled MBEDTLS_RSA_C
10223requires_max_content_len 2048
10224run_test    "DTLS fragmenting: openssl server, DTLS 1.2" \
10225            "$O_SRV -dtls1_2 -verify 10" \
10226            "$P_CLI dtls=1 debug_level=2 \
10227             crt_file=data_files/server8_int-ca2.crt \
10228             key_file=data_files/server8.key \
10229             mtu=512 force_version=dtls12" \
10230            0 \
10231            -c "fragmenting handshake message" \
10232            -C "error"
10233
10234requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10235requires_config_enabled MBEDTLS_RSA_C
10236requires_max_content_len 2048
10237run_test    "DTLS fragmenting: openssl client, DTLS 1.2" \
10238            "$P_SRV dtls=1 debug_level=2 \
10239             crt_file=data_files/server7_int-ca.crt \
10240             key_file=data_files/server7.key \
10241             mtu=512 force_version=dtls12" \
10242            "$O_CLI -dtls1_2" \
10243            0 \
10244            -s "fragmenting handshake message"
10245
10246# interop tests for DTLS fragmentating with unreliable connection
10247#
10248# again we just want to test that the we fragment in a way that
10249# pleases other implementations, so we don't need the peer to fragment
10250requires_gnutls_next
10251requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10252requires_config_enabled MBEDTLS_RSA_C
10253client_needs_more_time 4
10254requires_max_content_len 2048
10255run_test    "DTLS fragmenting: 3d, gnutls server, DTLS 1.2" \
10256            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10257            "$G_NEXT_SRV -u" \
10258            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10259             crt_file=data_files/server8_int-ca2.crt \
10260             key_file=data_files/server8.key \
10261             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10262            0 \
10263            -c "fragmenting handshake message" \
10264            -C "error"
10265
10266requires_gnutls_next
10267requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10268requires_config_enabled MBEDTLS_RSA_C
10269client_needs_more_time 4
10270requires_max_content_len 2048
10271run_test    "DTLS fragmenting: 3d, gnutls client, DTLS 1.2" \
10272            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10273            "$P_SRV dtls=1 debug_level=2 \
10274             crt_file=data_files/server7_int-ca.crt \
10275             key_file=data_files/server7.key \
10276             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10277           "$G_NEXT_CLI -u --insecure 127.0.0.1" \
10278            0 \
10279            -s "fragmenting handshake message"
10280
10281## The test below requires 1.1.1a or higher version of openssl, otherwise
10282## it might trigger a bug due to openssl server (https://github.com/openssl/openssl/issues/6902)
10283requires_openssl_next
10284requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10285requires_config_enabled MBEDTLS_RSA_C
10286client_needs_more_time 4
10287requires_max_content_len 2048
10288run_test    "DTLS fragmenting: 3d, openssl server, DTLS 1.2" \
10289            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10290            "$O_NEXT_SRV -dtls1_2 -verify 10" \
10291            "$P_CLI dtls=1 debug_level=2 \
10292             crt_file=data_files/server8_int-ca2.crt \
10293             key_file=data_files/server8.key \
10294             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10295            0 \
10296            -c "fragmenting handshake message" \
10297            -C "error"
10298
10299## the test below will time out with certain seed.
10300## The cause is an openssl bug (https://github.com/openssl/openssl/issues/18887)
10301skip_next_test
10302requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10303requires_config_enabled MBEDTLS_RSA_C
10304client_needs_more_time 4
10305requires_max_content_len 2048
10306run_test    "DTLS fragmenting: 3d, openssl client, DTLS 1.2" \
10307            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10308            "$P_SRV dtls=1 debug_level=2 \
10309             crt_file=data_files/server7_int-ca.crt \
10310             key_file=data_files/server7.key \
10311             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10312            "$O_CLI -dtls1_2" \
10313            0 \
10314            -s "fragmenting handshake message"
10315
10316# Tests for DTLS-SRTP (RFC 5764)
10317requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10318requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10319run_test  "DTLS-SRTP all profiles supported" \
10320          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10321          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10322          0 \
10323          -s "found use_srtp extension" \
10324          -s "found srtp profile" \
10325          -s "selected srtp profile" \
10326          -s "server hello, adding use_srtp extension" \
10327          -s "DTLS-SRTP key material is"\
10328          -c "client hello, adding use_srtp extension" \
10329          -c "found use_srtp extension" \
10330          -c "found srtp profile" \
10331          -c "selected srtp profile" \
10332          -c "DTLS-SRTP key material is"\
10333          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10334          -C "error"
10335
10336
10337requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10338requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10339run_test  "DTLS-SRTP server supports all profiles. Client supports one profile." \
10340          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10341          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=5 debug_level=3" \
10342          0 \
10343          -s "found use_srtp extension" \
10344          -s "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10345          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10346          -s "server hello, adding use_srtp extension" \
10347          -s "DTLS-SRTP key material is"\
10348          -c "client hello, adding use_srtp extension" \
10349          -c "found use_srtp extension" \
10350          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10351          -c "selected srtp profile" \
10352          -c "DTLS-SRTP key material is"\
10353          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10354          -C "error"
10355
10356requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10357requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10358run_test  "DTLS-SRTP server supports one profile. Client supports all profiles." \
10359          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10360          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10361          0 \
10362          -s "found use_srtp extension" \
10363          -s "found srtp profile" \
10364          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10365          -s "server hello, adding use_srtp extension" \
10366          -s "DTLS-SRTP key material is"\
10367          -c "client hello, adding use_srtp extension" \
10368          -c "found use_srtp extension" \
10369          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10370          -c "selected srtp profile" \
10371          -c "DTLS-SRTP key material is"\
10372          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10373          -C "error"
10374
10375requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10376requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10377run_test  "DTLS-SRTP server and Client support only one matching profile." \
10378          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10379          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10380          0 \
10381          -s "found use_srtp extension" \
10382          -s "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10383          -s "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10384          -s "server hello, adding use_srtp extension" \
10385          -s "DTLS-SRTP key material is"\
10386          -c "client hello, adding use_srtp extension" \
10387          -c "found use_srtp extension" \
10388          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10389          -c "selected srtp profile" \
10390          -c "DTLS-SRTP key material is"\
10391          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10392          -C "error"
10393
10394requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10395requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10396run_test  "DTLS-SRTP server and Client support only one different profile." \
10397          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10398          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10399          0 \
10400          -s "found use_srtp extension" \
10401          -s "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10402          -S "selected srtp profile" \
10403          -S "server hello, adding use_srtp extension" \
10404          -S "DTLS-SRTP key material is"\
10405          -c "client hello, adding use_srtp extension" \
10406          -C "found use_srtp extension" \
10407          -C "found srtp profile" \
10408          -C "selected srtp profile" \
10409          -C "DTLS-SRTP key material is"\
10410          -C "error"
10411
10412requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10413requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10414run_test  "DTLS-SRTP server doesn't support use_srtp extension." \
10415          "$P_SRV dtls=1 debug_level=3" \
10416          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10417          0 \
10418          -s "found use_srtp extension" \
10419          -S "server hello, adding use_srtp extension" \
10420          -S "DTLS-SRTP key material is"\
10421          -c "client hello, adding use_srtp extension" \
10422          -C "found use_srtp extension" \
10423          -C "found srtp profile" \
10424          -C "selected srtp profile" \
10425          -C "DTLS-SRTP key material is"\
10426          -C "error"
10427
10428requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10429requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10430run_test  "DTLS-SRTP all profiles supported. mki used" \
10431          "$P_SRV dtls=1 use_srtp=1 support_mki=1 debug_level=3" \
10432          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10433          0 \
10434          -s "found use_srtp extension" \
10435          -s "found srtp profile" \
10436          -s "selected srtp profile" \
10437          -s "server hello, adding use_srtp extension" \
10438          -s "dumping 'using mki' (8 bytes)" \
10439          -s "DTLS-SRTP key material is"\
10440          -c "client hello, adding use_srtp extension" \
10441          -c "found use_srtp extension" \
10442          -c "found srtp profile" \
10443          -c "selected srtp profile" \
10444          -c "dumping 'sending mki' (8 bytes)" \
10445          -c "dumping 'received mki' (8 bytes)" \
10446          -c "DTLS-SRTP key material is"\
10447          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10448          -g "find_in_both '^ *DTLS-SRTP mki value: [0-9A-F]*$'"\
10449          -C "error"
10450
10451requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10452requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10453run_test  "DTLS-SRTP all profiles supported. server doesn't support mki." \
10454          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10455          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10456          0 \
10457          -s "found use_srtp extension" \
10458          -s "found srtp profile" \
10459          -s "selected srtp profile" \
10460          -s "server hello, adding use_srtp extension" \
10461          -s "DTLS-SRTP key material is"\
10462          -s "DTLS-SRTP no mki value negotiated"\
10463          -S "dumping 'using mki' (8 bytes)" \
10464          -c "client hello, adding use_srtp extension" \
10465          -c "found use_srtp extension" \
10466          -c "found srtp profile" \
10467          -c "selected srtp profile" \
10468          -c "DTLS-SRTP key material is"\
10469          -c "DTLS-SRTP no mki value negotiated"\
10470          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10471          -c "dumping 'sending mki' (8 bytes)" \
10472          -C "dumping 'received mki' (8 bytes)" \
10473          -C "error"
10474
10475requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10476requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10477run_test  "DTLS-SRTP all profiles supported. openssl client." \
10478          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10479          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10480          0 \
10481          -s "found use_srtp extension" \
10482          -s "found srtp profile" \
10483          -s "selected srtp profile" \
10484          -s "server hello, adding use_srtp extension" \
10485          -s "DTLS-SRTP key material is"\
10486          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10487          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_80"
10488
10489requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10490requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10491run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. openssl client." \
10492          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10493          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32:SRTP_AES128_CM_SHA1_80 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10494          0 \
10495          -s "found use_srtp extension" \
10496          -s "found srtp profile" \
10497          -s "selected srtp profile" \
10498          -s "server hello, adding use_srtp extension" \
10499          -s "DTLS-SRTP key material is"\
10500          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10501          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10502
10503requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10504requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10505run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. openssl client." \
10506          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10507          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10508          0 \
10509          -s "found use_srtp extension" \
10510          -s "found srtp profile" \
10511          -s "selected srtp profile" \
10512          -s "server hello, adding use_srtp extension" \
10513          -s "DTLS-SRTP key material is"\
10514          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10515          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10516
10517requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10518requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10519run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. openssl client." \
10520          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10521          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10522          0 \
10523          -s "found use_srtp extension" \
10524          -s "found srtp profile" \
10525          -s "selected srtp profile" \
10526          -s "server hello, adding use_srtp extension" \
10527          -s "DTLS-SRTP key material is"\
10528          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10529          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10530
10531requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10532requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10533run_test  "DTLS-SRTP server and Client support only one matching profile. openssl client." \
10534          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10535          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10536          0 \
10537          -s "found use_srtp extension" \
10538          -s "found srtp profile" \
10539          -s "selected srtp profile" \
10540          -s "server hello, adding use_srtp extension" \
10541          -s "DTLS-SRTP key material is"\
10542          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10543          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10544
10545requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10546requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10547run_test  "DTLS-SRTP server and Client support only one different profile. openssl client." \
10548          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=1 debug_level=3" \
10549          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10550          0 \
10551          -s "found use_srtp extension" \
10552          -s "found srtp profile" \
10553          -S "selected srtp profile" \
10554          -S "server hello, adding use_srtp extension" \
10555          -S "DTLS-SRTP key material is"\
10556          -C "SRTP Extension negotiated, profile"
10557
10558requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10559requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10560run_test  "DTLS-SRTP server doesn't support use_srtp extension. openssl client" \
10561          "$P_SRV dtls=1 debug_level=3" \
10562          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10563          0 \
10564          -s "found use_srtp extension" \
10565          -S "server hello, adding use_srtp extension" \
10566          -S "DTLS-SRTP key material is"\
10567          -C "SRTP Extension negotiated, profile"
10568
10569requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10570requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10571run_test  "DTLS-SRTP all profiles supported. openssl server" \
10572          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10573          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10574          0 \
10575          -c "client hello, adding use_srtp extension" \
10576          -c "found use_srtp extension" \
10577          -c "found srtp profile" \
10578          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
10579          -c "DTLS-SRTP key material is"\
10580          -C "error"
10581
10582requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10583requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10584run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. openssl server." \
10585          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32:SRTP_AES128_CM_SHA1_80 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10586          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10587          0 \
10588          -c "client hello, adding use_srtp extension" \
10589          -c "found use_srtp extension" \
10590          -c "found srtp profile" \
10591          -c "selected srtp profile" \
10592          -c "DTLS-SRTP key material is"\
10593          -C "error"
10594
10595requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10596requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10597run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. openssl server." \
10598          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10599          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10600          0 \
10601          -c "client hello, adding use_srtp extension" \
10602          -c "found use_srtp extension" \
10603          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10604          -c "selected srtp profile" \
10605          -c "DTLS-SRTP key material is"\
10606          -C "error"
10607
10608requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10609requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10610run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. openssl server." \
10611          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10612          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10613          0 \
10614          -c "client hello, adding use_srtp extension" \
10615          -c "found use_srtp extension" \
10616          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10617          -c "selected srtp profile" \
10618          -c "DTLS-SRTP key material is"\
10619          -C "error"
10620
10621requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10622requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10623run_test  "DTLS-SRTP server and Client support only one matching profile. openssl server." \
10624          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10625          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10626          0 \
10627          -c "client hello, adding use_srtp extension" \
10628          -c "found use_srtp extension" \
10629          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10630          -c "selected srtp profile" \
10631          -c "DTLS-SRTP key material is"\
10632          -C "error"
10633
10634requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10635requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10636run_test  "DTLS-SRTP server and Client support only one different profile. openssl server." \
10637          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10638          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10639          0 \
10640          -c "client hello, adding use_srtp extension" \
10641          -C "found use_srtp extension" \
10642          -C "found srtp profile" \
10643          -C "selected srtp profile" \
10644          -C "DTLS-SRTP key material is"\
10645          -C "error"
10646
10647requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10648requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10649run_test  "DTLS-SRTP server doesn't support use_srtp extension. openssl server" \
10650          "$O_SRV -dtls" \
10651          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10652          0 \
10653          -c "client hello, adding use_srtp extension" \
10654          -C "found use_srtp extension" \
10655          -C "found srtp profile" \
10656          -C "selected srtp profile" \
10657          -C "DTLS-SRTP key material is"\
10658          -C "error"
10659
10660requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10661requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10662run_test  "DTLS-SRTP all profiles supported. server doesn't support mki. openssl server." \
10663          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10664          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10665          0 \
10666          -c "client hello, adding use_srtp extension" \
10667          -c "found use_srtp extension" \
10668          -c "found srtp profile" \
10669          -c "selected srtp profile" \
10670          -c "DTLS-SRTP key material is"\
10671          -c "DTLS-SRTP no mki value negotiated"\
10672          -c "dumping 'sending mki' (8 bytes)" \
10673          -C "dumping 'received mki' (8 bytes)" \
10674          -C "error"
10675
10676requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10677requires_gnutls
10678requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10679run_test  "DTLS-SRTP all profiles supported. gnutls client." \
10680          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10681          "$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" \
10682          0 \
10683          -s "found use_srtp extension" \
10684          -s "found srtp profile" \
10685          -s "selected srtp profile" \
10686          -s "server hello, adding use_srtp extension" \
10687          -s "DTLS-SRTP key material is"\
10688          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_80"
10689
10690requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10691requires_gnutls
10692requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10693run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. gnutls client." \
10694          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10695          "$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" \
10696          0 \
10697          -s "found use_srtp extension" \
10698          -s "found srtp profile" \
10699          -s "selected srtp profile" \
10700          -s "server hello, adding use_srtp extension" \
10701          -s "DTLS-SRTP key material is"\
10702          -c "SRTP profile: SRTP_NULL_HMAC_SHA1_80"
10703
10704requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10705requires_gnutls
10706requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10707run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. gnutls client." \
10708          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10709          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
10710          0 \
10711          -s "found use_srtp extension" \
10712          -s "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10713          -s "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10714          -s "server hello, adding use_srtp extension" \
10715          -s "DTLS-SRTP key material is"\
10716          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_32"
10717
10718requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10719requires_gnutls
10720requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10721run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. gnutls client." \
10722          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10723          "$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" \
10724          0 \
10725          -s "found use_srtp extension" \
10726          -s "found srtp profile" \
10727          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10728          -s "server hello, adding use_srtp extension" \
10729          -s "DTLS-SRTP key material is"\
10730          -c "SRTP profile: SRTP_NULL_SHA1_32"
10731
10732requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10733requires_gnutls
10734requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10735run_test  "DTLS-SRTP server and Client support only one matching profile. gnutls client." \
10736          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10737          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
10738          0 \
10739          -s "found use_srtp extension" \
10740          -s "found srtp profile" \
10741          -s "selected srtp profile" \
10742          -s "server hello, adding use_srtp extension" \
10743          -s "DTLS-SRTP key material is"\
10744          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_32"
10745
10746requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10747requires_gnutls
10748requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10749run_test  "DTLS-SRTP server and Client support only one different profile. gnutls client." \
10750          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=1 debug_level=3" \
10751          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
10752          0 \
10753          -s "found use_srtp extension" \
10754          -s "found srtp profile" \
10755          -S "selected srtp profile" \
10756          -S "server hello, adding use_srtp extension" \
10757          -S "DTLS-SRTP key material is"\
10758          -C "SRTP profile:"
10759
10760requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10761requires_gnutls
10762requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10763run_test  "DTLS-SRTP server doesn't support use_srtp extension. gnutls client" \
10764          "$P_SRV dtls=1 debug_level=3" \
10765          "$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" \
10766          0 \
10767          -s "found use_srtp extension" \
10768          -S "server hello, adding use_srtp extension" \
10769          -S "DTLS-SRTP key material is"\
10770          -C "SRTP profile:"
10771
10772requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10773requires_gnutls
10774requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10775run_test  "DTLS-SRTP all profiles supported. gnutls server" \
10776          "$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" \
10777          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10778          0 \
10779          -c "client hello, adding use_srtp extension" \
10780          -c "found use_srtp extension" \
10781          -c "found srtp profile" \
10782          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
10783          -c "DTLS-SRTP key material is"\
10784          -C "error"
10785
10786requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10787requires_gnutls
10788requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10789run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. gnutls server." \
10790          "$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" \
10791          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10792          0 \
10793          -c "client hello, adding use_srtp extension" \
10794          -c "found use_srtp extension" \
10795          -c "found srtp profile" \
10796          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
10797          -c "DTLS-SRTP key material is"\
10798          -C "error"
10799
10800requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10801requires_gnutls
10802requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10803run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. gnutls server." \
10804          "$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" \
10805          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10806          0 \
10807          -c "client hello, adding use_srtp extension" \
10808          -c "found use_srtp extension" \
10809          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10810          -c "selected srtp profile" \
10811          -c "DTLS-SRTP key material is"\
10812          -C "error"
10813
10814requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10815requires_gnutls
10816requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10817run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. gnutls server." \
10818          "$G_SRV -u --srtp-profiles=SRTP_NULL_HMAC_SHA1_80" \
10819          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10820          0 \
10821          -c "client hello, adding use_srtp extension" \
10822          -c "found use_srtp extension" \
10823          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10824          -c "selected srtp profile" \
10825          -c "DTLS-SRTP key material is"\
10826          -C "error"
10827
10828requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10829requires_gnutls
10830requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10831run_test  "DTLS-SRTP server and Client support only one matching profile. gnutls server." \
10832          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32" \
10833          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10834          0 \
10835          -c "client hello, adding use_srtp extension" \
10836          -c "found use_srtp extension" \
10837          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10838          -c "selected srtp profile" \
10839          -c "DTLS-SRTP key material is"\
10840          -C "error"
10841
10842requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10843requires_gnutls
10844requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10845run_test  "DTLS-SRTP server and Client support only one different profile. gnutls server." \
10846          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32" \
10847          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10848          0 \
10849          -c "client hello, adding use_srtp extension" \
10850          -C "found use_srtp extension" \
10851          -C "found srtp profile" \
10852          -C "selected srtp profile" \
10853          -C "DTLS-SRTP key material is"\
10854          -C "error"
10855
10856requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10857requires_gnutls
10858requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10859run_test  "DTLS-SRTP server doesn't support use_srtp extension. gnutls server" \
10860          "$G_SRV -u" \
10861          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10862          0 \
10863          -c "client hello, adding use_srtp extension" \
10864          -C "found use_srtp extension" \
10865          -C "found srtp profile" \
10866          -C "selected srtp profile" \
10867          -C "DTLS-SRTP key material is"\
10868          -C "error"
10869
10870requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10871requires_gnutls
10872requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10873run_test  "DTLS-SRTP all profiles supported. mki used. gnutls server." \
10874          "$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" \
10875          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10876          0 \
10877          -c "client hello, adding use_srtp extension" \
10878          -c "found use_srtp extension" \
10879          -c "found srtp profile" \
10880          -c "selected srtp profile" \
10881          -c "DTLS-SRTP key material is"\
10882          -c "DTLS-SRTP mki value:"\
10883          -c "dumping 'sending mki' (8 bytes)" \
10884          -c "dumping 'received mki' (8 bytes)" \
10885          -C "error"
10886
10887# Tests for specific things with "unreliable" UDP connection
10888
10889not_with_valgrind # spurious resend due to timeout
10890requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10891run_test    "DTLS proxy: reference" \
10892            -p "$P_PXY" \
10893            "$P_SRV dtls=1 debug_level=2 hs_timeout=10000-20000" \
10894            "$P_CLI dtls=1 debug_level=2 hs_timeout=10000-20000" \
10895            0 \
10896            -C "replayed record" \
10897            -S "replayed record" \
10898            -C "Buffer record from epoch" \
10899            -S "Buffer record from epoch" \
10900            -C "ssl_buffer_message" \
10901            -S "ssl_buffer_message" \
10902            -C "discarding invalid record" \
10903            -S "discarding invalid record" \
10904            -S "resend" \
10905            -s "Extra-header:" \
10906            -c "HTTP/1.0 200 OK"
10907
10908not_with_valgrind # spurious resend due to timeout
10909requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10910run_test    "DTLS proxy: duplicate every packet" \
10911            -p "$P_PXY duplicate=1" \
10912            "$P_SRV dtls=1 dgram_packing=0 debug_level=2 hs_timeout=10000-20000" \
10913            "$P_CLI dtls=1 dgram_packing=0 debug_level=2 hs_timeout=10000-20000" \
10914            0 \
10915            -c "replayed record" \
10916            -s "replayed record" \
10917            -c "record from another epoch" \
10918            -s "record from another epoch" \
10919            -S "resend" \
10920            -s "Extra-header:" \
10921            -c "HTTP/1.0 200 OK"
10922
10923requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10924run_test    "DTLS proxy: duplicate every packet, server anti-replay off" \
10925            -p "$P_PXY duplicate=1" \
10926            "$P_SRV dtls=1 dgram_packing=0 debug_level=2 anti_replay=0" \
10927            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
10928            0 \
10929            -c "replayed record" \
10930            -S "replayed record" \
10931            -c "record from another epoch" \
10932            -s "record from another epoch" \
10933            -c "resend" \
10934            -s "resend" \
10935            -s "Extra-header:" \
10936            -c "HTTP/1.0 200 OK"
10937
10938requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10939run_test    "DTLS proxy: multiple records in same datagram" \
10940            -p "$P_PXY pack=50" \
10941            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
10942            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
10943            0 \
10944            -c "next record in same datagram" \
10945            -s "next record in same datagram"
10946
10947requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10948run_test    "DTLS proxy: multiple records in same datagram, duplicate every packet" \
10949            -p "$P_PXY pack=50 duplicate=1" \
10950            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
10951            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
10952            0 \
10953            -c "next record in same datagram" \
10954            -s "next record in same datagram"
10955
10956requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10957run_test    "DTLS proxy: inject invalid AD record, default badmac_limit" \
10958            -p "$P_PXY bad_ad=1" \
10959            "$P_SRV dtls=1 dgram_packing=0 debug_level=1" \
10960            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
10961            0 \
10962            -c "discarding invalid record (mac)" \
10963            -s "discarding invalid record (mac)" \
10964            -s "Extra-header:" \
10965            -c "HTTP/1.0 200 OK" \
10966            -S "too many records with bad MAC" \
10967            -S "Verification of the message MAC failed"
10968
10969requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10970run_test    "DTLS proxy: inject invalid AD record, badmac_limit 1" \
10971            -p "$P_PXY bad_ad=1" \
10972            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=1" \
10973            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
10974            1 \
10975            -C "discarding invalid record (mac)" \
10976            -S "discarding invalid record (mac)" \
10977            -S "Extra-header:" \
10978            -C "HTTP/1.0 200 OK" \
10979            -s "too many records with bad MAC" \
10980            -s "Verification of the message MAC failed"
10981
10982requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10983run_test    "DTLS proxy: inject invalid AD record, badmac_limit 2" \
10984            -p "$P_PXY bad_ad=1" \
10985            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=2" \
10986            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
10987            0 \
10988            -c "discarding invalid record (mac)" \
10989            -s "discarding invalid record (mac)" \
10990            -s "Extra-header:" \
10991            -c "HTTP/1.0 200 OK" \
10992            -S "too many records with bad MAC" \
10993            -S "Verification of the message MAC failed"
10994
10995requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10996run_test    "DTLS proxy: inject invalid AD record, badmac_limit 2, exchanges 2"\
10997            -p "$P_PXY bad_ad=1" \
10998            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=2 exchanges=2" \
10999            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100 exchanges=2" \
11000            1 \
11001            -c "discarding invalid record (mac)" \
11002            -s "discarding invalid record (mac)" \
11003            -s "Extra-header:" \
11004            -c "HTTP/1.0 200 OK" \
11005            -s "too many records with bad MAC" \
11006            -s "Verification of the message MAC failed"
11007
11008requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11009run_test    "DTLS proxy: delay ChangeCipherSpec" \
11010            -p "$P_PXY delay_ccs=1" \
11011            "$P_SRV dtls=1 debug_level=1 dgram_packing=0" \
11012            "$P_CLI dtls=1 debug_level=1 dgram_packing=0" \
11013            0 \
11014            -c "record from another epoch" \
11015            -s "record from another epoch" \
11016            -s "Extra-header:" \
11017            -c "HTTP/1.0 200 OK"
11018
11019# Tests for reordering support with DTLS
11020
11021requires_certificate_authentication
11022requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11023run_test    "DTLS reordering: Buffer out-of-order handshake message on client" \
11024            -p "$P_PXY delay_srv=ServerHello" \
11025            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11026            hs_timeout=2500-60000" \
11027            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11028            hs_timeout=2500-60000" \
11029            0 \
11030            -c "Buffering HS message" \
11031            -c "Next handshake message has been buffered - load"\
11032            -S "Buffering HS message" \
11033            -S "Next handshake message has been buffered - load"\
11034            -C "Injecting buffered CCS message" \
11035            -C "Remember CCS message" \
11036            -S "Injecting buffered CCS message" \
11037            -S "Remember CCS message"
11038
11039requires_certificate_authentication
11040requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11041run_test    "DTLS reordering: Buffer out-of-order handshake message fragment on client" \
11042            -p "$P_PXY delay_srv=ServerHello" \
11043            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11044            hs_timeout=2500-60000" \
11045            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11046            hs_timeout=2500-60000" \
11047            0 \
11048            -c "Buffering HS message" \
11049            -c "found fragmented DTLS handshake message"\
11050            -c "Next handshake message 1 not or only partially bufffered" \
11051            -c "Next handshake message has been buffered - load"\
11052            -S "Buffering HS message" \
11053            -S "Next handshake message has been buffered - load"\
11054            -C "Injecting buffered CCS message" \
11055            -C "Remember CCS message" \
11056            -S "Injecting buffered CCS message" \
11057            -S "Remember CCS message"
11058
11059# The client buffers the ServerKeyExchange before receiving the fragmented
11060# Certificate message; at the time of writing, together these are aroudn 1200b
11061# in size, so that the bound below ensures that the certificate can be reassembled
11062# while keeping the ServerKeyExchange.
11063requires_certificate_authentication
11064requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 1300
11065requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11066run_test    "DTLS reordering: Buffer out-of-order hs msg before reassembling next" \
11067            -p "$P_PXY delay_srv=Certificate delay_srv=Certificate" \
11068            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11069            hs_timeout=2500-60000" \
11070            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11071            hs_timeout=2500-60000" \
11072            0 \
11073            -c "Buffering HS message" \
11074            -c "Next handshake message has been buffered - load"\
11075            -C "attempt to make space by freeing buffered messages" \
11076            -S "Buffering HS message" \
11077            -S "Next handshake message has been buffered - load"\
11078            -C "Injecting buffered CCS message" \
11079            -C "Remember CCS message" \
11080            -S "Injecting buffered CCS message" \
11081            -S "Remember CCS message"
11082
11083# The size constraints ensure that the delayed certificate message can't
11084# be reassembled while keeping the ServerKeyExchange message, but it can
11085# when dropping it first.
11086requires_certificate_authentication
11087requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 900
11088requires_config_value_at_most "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 1299
11089requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11090run_test    "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg" \
11091            -p "$P_PXY delay_srv=Certificate delay_srv=Certificate" \
11092            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11093            hs_timeout=2500-60000" \
11094            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11095            hs_timeout=2500-60000" \
11096            0 \
11097            -c "Buffering HS message" \
11098            -c "attempt to make space by freeing buffered future messages" \
11099            -c "Enough space available after freeing buffered HS messages" \
11100            -S "Buffering HS message" \
11101            -S "Next handshake message has been buffered - load"\
11102            -C "Injecting buffered CCS message" \
11103            -C "Remember CCS message" \
11104            -S "Injecting buffered CCS message" \
11105            -S "Remember CCS message"
11106
11107requires_certificate_authentication
11108requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11109run_test    "DTLS reordering: Buffer out-of-order handshake message on server" \
11110            -p "$P_PXY delay_cli=Certificate" \
11111            "$P_SRV dgram_packing=0 auth_mode=required cookies=0 dtls=1 debug_level=2 \
11112            hs_timeout=2500-60000" \
11113            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11114            hs_timeout=2500-60000" \
11115            0 \
11116            -C "Buffering HS message" \
11117            -C "Next handshake message has been buffered - load"\
11118            -s "Buffering HS message" \
11119            -s "Next handshake message has been buffered - load" \
11120            -C "Injecting buffered CCS message" \
11121            -C "Remember CCS message" \
11122            -S "Injecting buffered CCS message" \
11123            -S "Remember CCS message"
11124
11125requires_certificate_authentication
11126requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11127run_test    "DTLS reordering: Buffer out-of-order CCS message on client"\
11128            -p "$P_PXY delay_srv=NewSessionTicket" \
11129            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11130            hs_timeout=2500-60000" \
11131            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11132            hs_timeout=2500-60000" \
11133            0 \
11134            -C "Buffering HS message" \
11135            -C "Next handshake message has been buffered - load"\
11136            -S "Buffering HS message" \
11137            -S "Next handshake message has been buffered - load" \
11138            -c "Injecting buffered CCS message" \
11139            -c "Remember CCS message" \
11140            -S "Injecting buffered CCS message" \
11141            -S "Remember CCS message"
11142
11143requires_certificate_authentication
11144requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11145run_test    "DTLS reordering: Buffer out-of-order CCS message on server"\
11146            -p "$P_PXY delay_cli=ClientKeyExchange" \
11147            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11148            hs_timeout=2500-60000" \
11149            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11150            hs_timeout=2500-60000" \
11151            0 \
11152            -C "Buffering HS message" \
11153            -C "Next handshake message has been buffered - load"\
11154            -S "Buffering HS message" \
11155            -S "Next handshake message has been buffered - load" \
11156            -C "Injecting buffered CCS message" \
11157            -C "Remember CCS message" \
11158            -s "Injecting buffered CCS message" \
11159            -s "Remember CCS message"
11160
11161requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11162run_test    "DTLS reordering: Buffer encrypted Finished message" \
11163            -p "$P_PXY delay_ccs=1" \
11164            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
11165            hs_timeout=2500-60000" \
11166            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
11167            hs_timeout=2500-60000" \
11168            0 \
11169            -s "Buffer record from epoch 1" \
11170            -s "Found buffered record from current epoch - load" \
11171            -c "Buffer record from epoch 1" \
11172            -c "Found buffered record from current epoch - load"
11173
11174# In this test, both the fragmented NewSessionTicket and the ChangeCipherSpec
11175# from the server are delayed, so that the encrypted Finished message
11176# is received and buffered. When the fragmented NewSessionTicket comes
11177# in afterwards, the encrypted Finished message must be freed in order
11178# to make space for the NewSessionTicket to be reassembled.
11179# This works only in very particular circumstances:
11180# - MBEDTLS_SSL_DTLS_MAX_BUFFERING must be large enough to allow buffering
11181#   of the NewSessionTicket, but small enough to also allow buffering of
11182#   the encrypted Finished message.
11183# - The MTU setting on the server must be so small that the NewSessionTicket
11184#   needs to be fragmented.
11185# - All messages sent by the server must be small enough to be either sent
11186#   without fragmentation or be reassembled within the bounds of
11187#   MBEDTLS_SSL_DTLS_MAX_BUFFERING. Achieve this by testing with a PSK-based
11188#   handshake, omitting CRTs.
11189requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 190
11190requires_config_value_at_most "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 230
11191requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11192run_test    "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket" \
11193            -p "$P_PXY delay_srv=NewSessionTicket delay_srv=NewSessionTicket delay_ccs=1" \
11194            "$P_SRV mtu=140 response_size=90 dgram_packing=0 psk=abc123 psk_identity=foo cookies=0 dtls=1 debug_level=2" \
11195            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 psk=abc123 psk_identity=foo" \
11196            0 \
11197            -s "Buffer record from epoch 1" \
11198            -s "Found buffered record from current epoch - load" \
11199            -c "Buffer record from epoch 1" \
11200            -C "Found buffered record from current epoch - load" \
11201            -c "Enough space available after freeing future epoch record"
11202
11203# Tests for "randomly unreliable connection": try a variety of flows and peers
11204
11205client_needs_more_time 2
11206requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11207run_test    "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
11208            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11209            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11210             psk=abc123" \
11211            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11212             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11213            0 \
11214            -s "Extra-header:" \
11215            -c "HTTP/1.0 200 OK"
11216
11217client_needs_more_time 2
11218requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11219run_test    "DTLS proxy: 3d, \"short\" RSA handshake" \
11220            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11221            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none" \
11222            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 \
11223             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
11224            0 \
11225            -s "Extra-header:" \
11226            -c "HTTP/1.0 200 OK"
11227
11228client_needs_more_time 2
11229requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11230run_test    "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
11231            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11232            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none" \
11233            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0" \
11234            0 \
11235            -s "Extra-header:" \
11236            -c "HTTP/1.0 200 OK"
11237
11238client_needs_more_time 2
11239requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11240run_test    "DTLS proxy: 3d, FS, client auth" \
11241            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11242            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=required" \
11243            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0" \
11244            0 \
11245            -s "Extra-header:" \
11246            -c "HTTP/1.0 200 OK"
11247
11248client_needs_more_time 2
11249requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11250run_test    "DTLS proxy: 3d, FS, ticket" \
11251            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11252            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1 auth_mode=none" \
11253            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1" \
11254            0 \
11255            -s "Extra-header:" \
11256            -c "HTTP/1.0 200 OK"
11257
11258client_needs_more_time 2
11259requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11260run_test    "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
11261            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11262            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1 auth_mode=required" \
11263            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1" \
11264            0 \
11265            -s "Extra-header:" \
11266            -c "HTTP/1.0 200 OK"
11267
11268client_needs_more_time 2
11269requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11270run_test    "DTLS proxy: 3d, max handshake, nbio" \
11271            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11272            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 nbio=2 tickets=1 \
11273             auth_mode=required" \
11274            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 nbio=2 tickets=1" \
11275            0 \
11276            -s "Extra-header:" \
11277            -c "HTTP/1.0 200 OK"
11278
11279client_needs_more_time 4
11280requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11281requires_config_enabled MBEDTLS_SSL_CACHE_C
11282run_test    "DTLS proxy: 3d, min handshake, resumption" \
11283            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11284            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11285             psk=abc123 debug_level=3" \
11286            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11287             debug_level=3 reconnect=1 skip_close_notify=1 read_timeout=1000 max_resend=10 \
11288             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11289            0 \
11290            -s "a session has been resumed" \
11291            -c "a session has been resumed" \
11292            -s "Extra-header:" \
11293            -c "HTTP/1.0 200 OK"
11294
11295client_needs_more_time 4
11296requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11297requires_config_enabled MBEDTLS_SSL_CACHE_C
11298run_test    "DTLS proxy: 3d, min handshake, resumption, nbio" \
11299            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11300            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11301             psk=abc123 debug_level=3 nbio=2" \
11302            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11303             debug_level=3 reconnect=1 skip_close_notify=1 read_timeout=1000 max_resend=10 \
11304             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
11305            0 \
11306            -s "a session has been resumed" \
11307            -c "a session has been resumed" \
11308            -s "Extra-header:" \
11309            -c "HTTP/1.0 200 OK"
11310
11311client_needs_more_time 4
11312requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11313requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11314run_test    "DTLS proxy: 3d, min handshake, client-initiated renego" \
11315            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11316            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11317             psk=abc123 renegotiation=1 debug_level=2" \
11318            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11319             renegotiate=1 debug_level=2 \
11320             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11321            0 \
11322            -c "=> renegotiate" \
11323            -s "=> renegotiate" \
11324            -s "Extra-header:" \
11325            -c "HTTP/1.0 200 OK"
11326
11327client_needs_more_time 4
11328requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11329requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11330run_test    "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
11331            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11332            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11333             psk=abc123 renegotiation=1 debug_level=2" \
11334            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11335             renegotiate=1 debug_level=2 \
11336             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11337            0 \
11338            -c "=> renegotiate" \
11339            -s "=> renegotiate" \
11340            -s "Extra-header:" \
11341            -c "HTTP/1.0 200 OK"
11342
11343client_needs_more_time 4
11344requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11345requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11346run_test    "DTLS proxy: 3d, min handshake, server-initiated renego" \
11347            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11348            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11349             psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
11350             debug_level=2" \
11351            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11352             renegotiation=1 exchanges=4 debug_level=2 \
11353             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11354            0 \
11355            -c "=> renegotiate" \
11356            -s "=> renegotiate" \
11357            -s "Extra-header:" \
11358            -c "HTTP/1.0 200 OK"
11359
11360client_needs_more_time 4
11361requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11362requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11363run_test    "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
11364            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11365            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11366             psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
11367             debug_level=2 nbio=2" \
11368            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11369             renegotiation=1 exchanges=4 debug_level=2 nbio=2 \
11370             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11371            0 \
11372            -c "=> renegotiate" \
11373            -s "=> renegotiate" \
11374            -s "Extra-header:" \
11375            -c "HTTP/1.0 200 OK"
11376
11377## The three tests below require 1.1.1a or higher version of openssl, otherwise
11378## it might trigger a bug due to openssl (https://github.com/openssl/openssl/issues/6902)
11379## Besides, openssl should use dtls1_2 or dtls, otherwise it will cause "SSL alert number 70" error
11380requires_openssl_next
11381client_needs_more_time 6
11382not_with_valgrind # risk of non-mbedtls peer timing out
11383requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11384run_test    "DTLS proxy: 3d, openssl server" \
11385            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
11386            "$O_NEXT_SRV -dtls1_2 -mtu 2048" \
11387            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 tickets=0" \
11388            0 \
11389            -c "HTTP/1.0 200 OK"
11390
11391requires_openssl_next
11392client_needs_more_time 8
11393not_with_valgrind # risk of non-mbedtls peer timing out
11394requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11395run_test    "DTLS proxy: 3d, openssl server, fragmentation" \
11396            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
11397            "$O_NEXT_SRV -dtls1_2 -mtu 768" \
11398            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 tickets=0" \
11399            0 \
11400            -c "HTTP/1.0 200 OK"
11401
11402requires_openssl_next
11403client_needs_more_time 8
11404not_with_valgrind # risk of non-mbedtls peer timing out
11405requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11406run_test    "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
11407            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
11408            "$O_NEXT_SRV -dtls1_2 -mtu 768" \
11409            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 nbio=2 tickets=0" \
11410            0 \
11411            -c "HTTP/1.0 200 OK"
11412
11413requires_gnutls
11414client_needs_more_time 6
11415not_with_valgrind # risk of non-mbedtls peer timing out
11416requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11417run_test    "DTLS proxy: 3d, gnutls server" \
11418            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11419            "$G_SRV -u --mtu 2048 -a" \
11420            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000" \
11421            0 \
11422            -s "Extra-header:" \
11423            -c "Extra-header:"
11424
11425requires_gnutls_next
11426client_needs_more_time 8
11427not_with_valgrind # risk of non-mbedtls peer timing out
11428requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11429run_test    "DTLS proxy: 3d, gnutls server, fragmentation" \
11430            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11431            "$G_NEXT_SRV -u --mtu 512" \
11432            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000" \
11433            0 \
11434            -s "Extra-header:" \
11435            -c "Extra-header:"
11436
11437requires_gnutls_next
11438client_needs_more_time 8
11439not_with_valgrind # risk of non-mbedtls peer timing out
11440requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11441run_test    "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
11442            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11443            "$G_NEXT_SRV -u --mtu 512" \
11444            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 nbio=2" \
11445            0 \
11446            -s "Extra-header:" \
11447            -c "Extra-header:"
11448
11449requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11450run_test    "export keys functionality" \
11451            "$P_SRV eap_tls=1 debug_level=3" \
11452            "$P_CLI eap_tls=1 debug_level=3" \
11453            0 \
11454            -c "EAP-TLS key material is:"\
11455            -s "EAP-TLS key material is:"\
11456            -c "EAP-TLS IV is:" \
11457            -s "EAP-TLS IV is:"
11458
11459# openssl feature tests: check if tls1.3 exists.
11460requires_openssl_tls1_3
11461run_test    "TLS 1.3: Test openssl tls1_3 feature" \
11462            "$O_NEXT_SRV -tls1_3 -msg" \
11463            "$O_NEXT_CLI -tls1_3 -msg" \
11464            0 \
11465            -c "TLS 1.3" \
11466            -s "TLS 1.3"
11467
11468# gnutls feature tests: check if TLS 1.3 is supported as well as the NO_TICKETS and DISABLE_TLS13_COMPAT_MODE options.
11469requires_gnutls_tls1_3
11470requires_gnutls_next_no_ticket
11471requires_gnutls_next_disable_tls13_compat
11472run_test    "TLS 1.3: Test gnutls tls1_3 feature" \
11473            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert " \
11474            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
11475            0 \
11476            -s "Version: TLS1.3" \
11477            -c "Version: TLS1.3"
11478
11479# TLS1.3 test cases
11480requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11481requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11482requires_ciphersuite_enabled TLS1-3-CHACHA20-POLY1305-SHA256
11483requires_config_enabled MBEDTLS_ECP_DP_CURVE25519_ENABLED
11484requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
11485run_test    "TLS 1.3: Default" \
11486            "$P_SRV allow_sha1=0 debug_level=3 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13" \
11487            "$P_CLI allow_sha1=0" \
11488            0 \
11489            -s "Protocol is TLSv1.3" \
11490            -s "Ciphersuite is TLS1-3-CHACHA20-POLY1305-SHA256" \
11491            -s "ECDH group: x25519" \
11492            -s "selected signature algorithm ecdsa_secp256r1_sha256"
11493
11494requires_openssl_tls1_3
11495requires_config_enabled MBEDTLS_DEBUG_C
11496requires_config_enabled MBEDTLS_SSL_CLI_C
11497requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11498                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11499run_test    "TLS 1.3: minimal feature sets - openssl" \
11500            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
11501            "$P_CLI debug_level=3" \
11502            0 \
11503            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11504            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11505            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11506            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11507            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11508            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11509            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11510            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11511            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11512            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11513            -c "<= ssl_tls13_process_server_hello" \
11514            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
11515            -c "ECDH curve: x25519" \
11516            -c "=> ssl_tls13_process_server_hello" \
11517            -c "<= parse encrypted extensions" \
11518            -c "Certificate verification flags clear" \
11519            -c "=> parse certificate verify" \
11520            -c "<= parse certificate verify" \
11521            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11522            -c "<= parse finished message" \
11523            -c "Protocol is TLSv1.3" \
11524            -c "HTTP/1.0 200 ok"
11525
11526requires_gnutls_tls1_3
11527requires_gnutls_next_no_ticket
11528requires_config_enabled MBEDTLS_DEBUG_C
11529requires_config_enabled MBEDTLS_SSL_CLI_C
11530requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11531                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11532run_test    "TLS 1.3: minimal feature sets - gnutls" \
11533            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
11534            "$P_CLI debug_level=3" \
11535            0 \
11536            -s "SERVER HELLO was queued" \
11537            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11538            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11539            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11540            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11541            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11542            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11543            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11544            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11545            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11546            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11547            -c "<= ssl_tls13_process_server_hello" \
11548            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
11549            -c "ECDH curve: x25519" \
11550            -c "=> ssl_tls13_process_server_hello" \
11551            -c "<= parse encrypted extensions" \
11552            -c "Certificate verification flags clear" \
11553            -c "=> parse certificate verify" \
11554            -c "<= parse certificate verify" \
11555            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11556            -c "<= parse finished message" \
11557            -c "Protocol is TLSv1.3" \
11558            -c "HTTP/1.0 200 OK"
11559
11560requires_openssl_tls1_3
11561requires_config_enabled MBEDTLS_DEBUG_C
11562requires_config_enabled MBEDTLS_SSL_CLI_C
11563requires_config_enabled MBEDTLS_SSL_ALPN
11564requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11565                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11566run_test    "TLS 1.3: alpn - openssl" \
11567            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -alpn h2" \
11568            "$P_CLI debug_level=3 alpn=h2" \
11569            0 \
11570            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11571            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11572            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11573            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11574            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11575            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11576            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11577            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11578            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11579            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11580            -c "<= ssl_tls13_process_server_hello" \
11581            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
11582            -c "ECDH curve: x25519" \
11583            -c "=> ssl_tls13_process_server_hello" \
11584            -c "<= parse encrypted extensions" \
11585            -c "Certificate verification flags clear" \
11586            -c "=> parse certificate verify" \
11587            -c "<= parse certificate verify" \
11588            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11589            -c "<= parse finished message" \
11590            -c "Protocol is TLSv1.3" \
11591            -c "HTTP/1.0 200 ok" \
11592            -c "Application Layer Protocol is h2"
11593
11594requires_gnutls_tls1_3
11595requires_gnutls_next_no_ticket
11596requires_config_enabled MBEDTLS_DEBUG_C
11597requires_config_enabled MBEDTLS_SSL_CLI_C
11598requires_config_enabled MBEDTLS_SSL_ALPN
11599requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11600                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11601run_test    "TLS 1.3: alpn - gnutls" \
11602            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert --alpn=h2" \
11603            "$P_CLI debug_level=3 alpn=h2" \
11604            0 \
11605            -s "SERVER HELLO was queued" \
11606            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11607            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11608            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11609            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11610            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11611            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11612            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11613            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11614            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11615            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11616            -c "<= ssl_tls13_process_server_hello" \
11617            -c "server hello, chosen ciphersuite: ( 1303 ) - TLS1-3-CHACHA20-POLY1305-SHA256" \
11618            -c "ECDH curve: x25519" \
11619            -c "=> ssl_tls13_process_server_hello" \
11620            -c "<= parse encrypted extensions" \
11621            -c "Certificate verification flags clear" \
11622            -c "=> parse certificate verify" \
11623            -c "<= parse certificate verify" \
11624            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11625            -c "<= parse finished message" \
11626            -c "Protocol is TLSv1.3" \
11627            -c "HTTP/1.0 200 OK" \
11628            -c "Application Layer Protocol is h2"
11629
11630requires_openssl_tls1_3
11631requires_config_enabled MBEDTLS_DEBUG_C
11632requires_config_enabled MBEDTLS_SSL_SRV_C
11633requires_config_enabled MBEDTLS_SSL_ALPN
11634requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11635run_test    "TLS 1.3: server alpn - openssl" \
11636            "$P_SRV debug_level=3 tickets=0 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 alpn=h2" \
11637            "$O_NEXT_CLI -msg -tls1_3 -no_middlebox -alpn h2" \
11638            0 \
11639            -s "found alpn extension" \
11640            -s "server side, adding alpn extension" \
11641            -s "Protocol is TLSv1.3" \
11642            -s "HTTP/1.0 200 OK" \
11643            -s "Application Layer Protocol is h2"
11644
11645requires_gnutls_tls1_3
11646requires_config_enabled MBEDTLS_DEBUG_C
11647requires_config_enabled MBEDTLS_SSL_SRV_C
11648requires_config_enabled MBEDTLS_SSL_ALPN
11649requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11650run_test    "TLS 1.3: server alpn - gnutls" \
11651            "$P_SRV debug_level=3 tickets=0 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 alpn=h2" \
11652            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V --alpn h2" \
11653            0 \
11654            -s "found alpn extension" \
11655            -s "server side, adding alpn extension" \
11656            -s "Protocol is TLSv1.3" \
11657            -s "HTTP/1.0 200 OK" \
11658            -s "Application Layer Protocol is h2"
11659
11660requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11661requires_config_enabled MBEDTLS_DEBUG_C
11662requires_config_enabled MBEDTLS_SSL_CLI_C
11663skip_handshake_stage_check
11664requires_gnutls_tls1_3
11665run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.0" \
11666            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0 -d 4" \
11667            "$P_CLI debug_level=4" \
11668            1 \
11669            -s "Client's version: 3.3" \
11670            -S "Version: TLS1.0" \
11671            -C "Protocol is TLSv1.0"
11672
11673requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11674requires_config_enabled MBEDTLS_DEBUG_C
11675requires_config_enabled MBEDTLS_SSL_CLI_C
11676skip_handshake_stage_check
11677requires_gnutls_tls1_3
11678run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.1" \
11679            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1 -d 4" \
11680            "$P_CLI debug_level=4" \
11681            1 \
11682            -s "Client's version: 3.3" \
11683            -S "Version: TLS1.1" \
11684            -C "Protocol is TLSv1.1"
11685
11686requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11687requires_config_enabled MBEDTLS_DEBUG_C
11688requires_config_enabled MBEDTLS_SSL_CLI_C
11689skip_handshake_stage_check
11690requires_gnutls_tls1_3
11691run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.2" \
11692            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2 -d 4" \
11693            "$P_CLI force_version=tls13 debug_level=4" \
11694            1 \
11695            -s "Client's version: 3.3" \
11696            -c "is a fatal alert message (msg 40)" \
11697            -S "Version: TLS1.2" \
11698            -C "Protocol is TLSv1.2"
11699
11700requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11701requires_config_enabled MBEDTLS_DEBUG_C
11702requires_config_enabled MBEDTLS_SSL_CLI_C
11703skip_handshake_stage_check
11704requires_openssl_next
11705run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.0" \
11706            "$O_NEXT_SRV -msg -tls1" \
11707            "$P_CLI debug_level=4" \
11708            1 \
11709            -s "fatal protocol_version" \
11710            -c "is a fatal alert message (msg 70)" \
11711            -S "Version: TLS1.0" \
11712            -C "Protocol  : TLSv1.0"
11713
11714requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11715requires_config_enabled MBEDTLS_DEBUG_C
11716requires_config_enabled MBEDTLS_SSL_CLI_C
11717skip_handshake_stage_check
11718requires_openssl_next
11719run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.1" \
11720            "$O_NEXT_SRV -msg -tls1_1" \
11721            "$P_CLI debug_level=4" \
11722            1 \
11723            -s "fatal protocol_version" \
11724            -c "is a fatal alert message (msg 70)" \
11725            -S "Version: TLS1.1" \
11726            -C "Protocol  : TLSv1.1"
11727
11728requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11729requires_config_enabled MBEDTLS_DEBUG_C
11730requires_config_enabled MBEDTLS_SSL_CLI_C
11731skip_handshake_stage_check
11732requires_openssl_next
11733run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.2" \
11734            "$O_NEXT_SRV -msg -tls1_2" \
11735            "$P_CLI force_version=tls13 debug_level=4" \
11736            1 \
11737            -s "fatal protocol_version" \
11738            -c "is a fatal alert message (msg 70)" \
11739            -S "Version: TLS1.2" \
11740            -C "Protocol  : TLSv1.2"
11741
11742requires_openssl_tls1_3
11743requires_config_enabled MBEDTLS_DEBUG_C
11744requires_config_enabled MBEDTLS_SSL_CLI_C
11745requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11746                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11747run_test    "TLS 1.3: Client authentication, no client certificate - openssl" \
11748            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -verify 10" \
11749            "$P_CLI debug_level=4 crt_file=none key_file=none" \
11750            0 \
11751            -c "got a certificate request" \
11752            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11753            -s "TLS 1.3" \
11754            -c "HTTP/1.0 200 ok" \
11755            -c "Protocol is TLSv1.3"
11756
11757requires_gnutls_tls1_3
11758requires_gnutls_next_no_ticket
11759requires_config_enabled MBEDTLS_DEBUG_C
11760requires_config_enabled MBEDTLS_SSL_CLI_C
11761requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11762                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11763run_test    "TLS 1.3: Client authentication, no client certificate - gnutls" \
11764            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --verify-client-cert" \
11765            "$P_CLI debug_level=3 crt_file=none key_file=none" \
11766            0 \
11767            -c "got a certificate request" \
11768            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE"\
11769            -s "Version: TLS1.3" \
11770            -c "HTTP/1.0 200 OK" \
11771            -c "Protocol is TLSv1.3"
11772
11773
11774requires_openssl_tls1_3
11775requires_config_enabled MBEDTLS_DEBUG_C
11776requires_config_enabled MBEDTLS_SSL_CLI_C
11777requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11778run_test    "TLS 1.3: Client authentication, no server middlebox compat - openssl" \
11779            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10 -no_middlebox" \
11780            "$P_CLI debug_level=4 crt_file=data_files/cli2.crt key_file=data_files/cli2.key" \
11781            0 \
11782            -c "got a certificate request" \
11783            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11784            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11785            -c "Protocol is TLSv1.3"
11786
11787requires_gnutls_tls1_3
11788requires_gnutls_next_no_ticket
11789requires_config_enabled MBEDTLS_DEBUG_C
11790requires_config_enabled MBEDTLS_SSL_CLI_C
11791requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11792run_test    "TLS 1.3: Client authentication, no server middlebox compat - gnutls" \
11793            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE" \
11794            "$P_CLI debug_level=3 crt_file=data_files/cli2.crt \
11795                    key_file=data_files/cli2.key" \
11796            0 \
11797            -c "got a certificate request" \
11798            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11799            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11800            -c "Protocol is TLSv1.3"
11801
11802requires_openssl_tls1_3
11803requires_config_enabled MBEDTLS_DEBUG_C
11804requires_config_enabled MBEDTLS_SSL_CLI_C
11805requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11806                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11807run_test    "TLS 1.3: Client authentication, ecdsa_secp256r1_sha256 - openssl" \
11808            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11809            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp256r1.crt \
11810                    key_file=data_files/ecdsa_secp256r1.key" \
11811            0 \
11812            -c "got a certificate request" \
11813            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11814            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11815            -c "Protocol is TLSv1.3"
11816
11817requires_gnutls_tls1_3
11818requires_gnutls_next_no_ticket
11819requires_config_enabled MBEDTLS_DEBUG_C
11820requires_config_enabled MBEDTLS_SSL_CLI_C
11821requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11822                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11823run_test    "TLS 1.3: Client authentication, ecdsa_secp256r1_sha256 - gnutls" \
11824            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11825            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp256r1.crt \
11826                    key_file=data_files/ecdsa_secp256r1.key" \
11827            0 \
11828            -c "got a certificate request" \
11829            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11830            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11831            -c "Protocol is TLSv1.3"
11832
11833requires_openssl_tls1_3
11834requires_config_enabled MBEDTLS_DEBUG_C
11835requires_config_enabled MBEDTLS_SSL_CLI_C
11836requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11837                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11838run_test    "TLS 1.3: Client authentication, ecdsa_secp384r1_sha384 - openssl" \
11839            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11840            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp384r1.crt \
11841                    key_file=data_files/ecdsa_secp384r1.key" \
11842            0 \
11843            -c "got a certificate request" \
11844            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11845            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11846            -c "Protocol is TLSv1.3"
11847
11848requires_gnutls_tls1_3
11849requires_gnutls_next_no_ticket
11850requires_config_enabled MBEDTLS_DEBUG_C
11851requires_config_enabled MBEDTLS_SSL_CLI_C
11852requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11853                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11854run_test    "TLS 1.3: Client authentication, ecdsa_secp384r1_sha384 - gnutls" \
11855            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11856            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp384r1.crt \
11857                    key_file=data_files/ecdsa_secp384r1.key" \
11858            0 \
11859            -c "got a certificate request" \
11860            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11861            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11862            -c "Protocol is TLSv1.3"
11863
11864requires_openssl_tls1_3
11865requires_config_enabled MBEDTLS_DEBUG_C
11866requires_config_enabled MBEDTLS_SSL_CLI_C
11867requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11868                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11869run_test    "TLS 1.3: Client authentication, ecdsa_secp521r1_sha512 - openssl" \
11870            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11871            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp521r1.crt \
11872                    key_file=data_files/ecdsa_secp521r1.key" \
11873            0 \
11874            -c "got a certificate request" \
11875            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11876            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11877            -c "Protocol is TLSv1.3"
11878
11879requires_gnutls_tls1_3
11880requires_gnutls_next_no_ticket
11881requires_config_enabled MBEDTLS_DEBUG_C
11882requires_config_enabled MBEDTLS_SSL_CLI_C
11883requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11884                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11885run_test    "TLS 1.3: Client authentication, ecdsa_secp521r1_sha512 - gnutls" \
11886            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11887            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
11888                    key_file=data_files/ecdsa_secp521r1.key" \
11889            0 \
11890            -c "got a certificate request" \
11891            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11892            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11893            -c "Protocol is TLSv1.3"
11894
11895requires_openssl_tls1_3
11896requires_config_enabled MBEDTLS_DEBUG_C
11897requires_config_enabled MBEDTLS_SSL_CLI_C
11898requires_config_enabled MBEDTLS_RSA_C
11899requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11900                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11901run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha256 - openssl" \
11902            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11903            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
11904                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256" \
11905            0 \
11906            -c "got a certificate request" \
11907            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11908            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11909            -c "Protocol is TLSv1.3"
11910
11911requires_gnutls_tls1_3
11912requires_gnutls_next_no_ticket
11913requires_config_enabled MBEDTLS_DEBUG_C
11914requires_config_enabled MBEDTLS_SSL_CLI_C
11915requires_config_enabled MBEDTLS_RSA_C
11916requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11917                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11918run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha256 - gnutls" \
11919            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11920            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
11921                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256" \
11922            0 \
11923            -c "got a certificate request" \
11924            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11925            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11926            -c "Protocol is TLSv1.3"
11927
11928requires_openssl_tls1_3
11929requires_config_enabled MBEDTLS_DEBUG_C
11930requires_config_enabled MBEDTLS_SSL_CLI_C
11931requires_config_enabled MBEDTLS_RSA_C
11932requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11933                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11934run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha384 - openssl" \
11935            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11936            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
11937                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384" \
11938            0 \
11939            -c "got a certificate request" \
11940            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11941            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11942            -c "Protocol is TLSv1.3"
11943
11944requires_gnutls_tls1_3
11945requires_gnutls_next_no_ticket
11946requires_config_enabled MBEDTLS_DEBUG_C
11947requires_config_enabled MBEDTLS_SSL_CLI_C
11948requires_config_enabled MBEDTLS_RSA_C
11949requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11950                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11951run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha384 - gnutls" \
11952            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11953            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
11954                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384" \
11955            0 \
11956            -c "got a certificate request" \
11957            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11958            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11959            -c "Protocol is TLSv1.3"
11960
11961requires_openssl_tls1_3
11962requires_config_enabled MBEDTLS_DEBUG_C
11963requires_config_enabled MBEDTLS_SSL_CLI_C
11964requires_config_enabled MBEDTLS_RSA_C
11965requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11966                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11967run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha512 - openssl" \
11968            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11969            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
11970                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512" \
11971            0 \
11972            -c "got a certificate request" \
11973            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11974            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11975            -c "Protocol is TLSv1.3"
11976
11977requires_gnutls_tls1_3
11978requires_gnutls_next_no_ticket
11979requires_config_enabled MBEDTLS_DEBUG_C
11980requires_config_enabled MBEDTLS_SSL_CLI_C
11981requires_config_enabled MBEDTLS_RSA_C
11982requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11983                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11984run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha512 - gnutls" \
11985            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11986            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
11987                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512" \
11988            0 \
11989            -c "got a certificate request" \
11990            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11991            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11992            -c "Protocol is TLSv1.3"
11993
11994requires_openssl_tls1_3
11995requires_config_enabled MBEDTLS_DEBUG_C
11996requires_config_enabled MBEDTLS_SSL_CLI_C
11997requires_config_enabled MBEDTLS_RSA_C
11998requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11999                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12000run_test    "TLS 1.3: Client authentication, client alg not in server list - openssl" \
12001            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10
12002                -sigalgs ecdsa_secp256r1_sha256" \
12003            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12004                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512" \
12005            1 \
12006            -c "got a certificate request" \
12007            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12008            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12009            -c "no suitable signature algorithm" \
12010            -C "unknown pk type"
12011
12012requires_gnutls_tls1_3
12013requires_gnutls_next_no_ticket
12014requires_config_enabled MBEDTLS_DEBUG_C
12015requires_config_enabled MBEDTLS_SSL_CLI_C
12016requires_config_enabled MBEDTLS_RSA_C
12017requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12018                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12019run_test    "TLS 1.3: Client authentication, client alg not in server list - gnutls" \
12020            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:-SIGN-ALL:+SIGN-ECDSA-SECP256R1-SHA256:%NO_TICKETS" \
12021            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12022                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512" \
12023            1 \
12024            -c "got a certificate request" \
12025            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12026            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12027            -c "no suitable signature algorithm" \
12028            -C "unknown pk type"
12029
12030# Test using an opaque private key for client authentication
12031requires_openssl_tls1_3
12032requires_config_enabled MBEDTLS_DEBUG_C
12033requires_config_enabled MBEDTLS_SSL_CLI_C
12034requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12035requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12036run_test    "TLS 1.3: Client authentication - opaque key, no server middlebox compat - openssl" \
12037            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10 -no_middlebox" \
12038            "$P_CLI debug_level=4 crt_file=data_files/cli2.crt key_file=data_files/cli2.key key_opaque=1" \
12039            0 \
12040            -c "got a certificate request" \
12041            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12042            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12043            -c "Protocol is TLSv1.3"
12044
12045requires_gnutls_tls1_3
12046requires_gnutls_next_no_ticket
12047requires_config_enabled MBEDTLS_DEBUG_C
12048requires_config_enabled MBEDTLS_SSL_CLI_C
12049requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12050requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12051run_test    "TLS 1.3: Client authentication - opaque key, no server middlebox compat - gnutls" \
12052            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE" \
12053            "$P_CLI debug_level=3 crt_file=data_files/cli2.crt \
12054                    key_file=data_files/cli2.key key_opaque=1" \
12055            0 \
12056            -c "got a certificate request" \
12057            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12058            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12059            -c "Protocol is TLSv1.3"
12060
12061requires_openssl_tls1_3
12062requires_config_enabled MBEDTLS_DEBUG_C
12063requires_config_enabled MBEDTLS_SSL_CLI_C
12064requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12065requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12066                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12067run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp256r1_sha256 - openssl" \
12068            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12069            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp256r1.crt \
12070                    key_file=data_files/ecdsa_secp256r1.key key_opaque=1" \
12071            0 \
12072            -c "got a certificate request" \
12073            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12074            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12075            -c "Protocol is TLSv1.3"
12076
12077requires_gnutls_tls1_3
12078requires_gnutls_next_no_ticket
12079requires_config_enabled MBEDTLS_DEBUG_C
12080requires_config_enabled MBEDTLS_SSL_CLI_C
12081requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12082requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12083                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12084run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp256r1_sha256 - gnutls" \
12085            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12086            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp256r1.crt \
12087                    key_file=data_files/ecdsa_secp256r1.key key_opaque=1" \
12088            0 \
12089            -c "got a certificate request" \
12090            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12091            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12092            -c "Protocol is TLSv1.3"
12093
12094requires_openssl_tls1_3
12095requires_config_enabled MBEDTLS_DEBUG_C
12096requires_config_enabled MBEDTLS_SSL_CLI_C
12097requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12098requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12099                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12100run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp384r1_sha384 - openssl" \
12101            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12102            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp384r1.crt \
12103                    key_file=data_files/ecdsa_secp384r1.key key_opaque=1" \
12104            0 \
12105            -c "got a certificate request" \
12106            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12107            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12108            -c "Protocol is TLSv1.3"
12109
12110requires_gnutls_tls1_3
12111requires_gnutls_next_no_ticket
12112requires_config_enabled MBEDTLS_DEBUG_C
12113requires_config_enabled MBEDTLS_SSL_CLI_C
12114requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12115requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12116                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12117run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp384r1_sha384 - gnutls" \
12118            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12119            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp384r1.crt \
12120                    key_file=data_files/ecdsa_secp384r1.key key_opaque=1" \
12121            0 \
12122            -c "got a certificate request" \
12123            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12124            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12125            -c "Protocol is TLSv1.3"
12126
12127requires_openssl_tls1_3
12128requires_config_enabled MBEDTLS_DEBUG_C
12129requires_config_enabled MBEDTLS_SSL_CLI_C
12130requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12131requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12132                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12133run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp521r1_sha512 - openssl" \
12134            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12135            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp521r1.crt \
12136                    key_file=data_files/ecdsa_secp521r1.key key_opaque=1" \
12137            0 \
12138            -c "got a certificate request" \
12139            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12140            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12141            -c "Protocol is TLSv1.3"
12142
12143requires_gnutls_tls1_3
12144requires_gnutls_next_no_ticket
12145requires_config_enabled MBEDTLS_DEBUG_C
12146requires_config_enabled MBEDTLS_SSL_CLI_C
12147requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12148requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12149                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12150run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp521r1_sha512 - gnutls" \
12151            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12152            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12153                    key_file=data_files/ecdsa_secp521r1.key key_opaque=1" \
12154            0 \
12155            -c "got a certificate request" \
12156            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12157            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12158            -c "Protocol is TLSv1.3"
12159
12160requires_openssl_tls1_3
12161requires_config_enabled MBEDTLS_DEBUG_C
12162requires_config_enabled MBEDTLS_SSL_CLI_C
12163requires_config_enabled MBEDTLS_RSA_C
12164requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12165requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12166                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12167run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha256 - openssl" \
12168            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12169            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
12170                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256 key_opaque=1" \
12171            0 \
12172            -c "got a certificate request" \
12173            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12174            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12175            -c "Protocol is TLSv1.3"
12176
12177requires_gnutls_tls1_3
12178requires_gnutls_next_no_ticket
12179requires_config_enabled MBEDTLS_DEBUG_C
12180requires_config_enabled MBEDTLS_SSL_CLI_C
12181requires_config_enabled MBEDTLS_RSA_C
12182requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12183requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12184                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12185run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha256 - gnutls" \
12186            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12187            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
12188                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256 key_opaque=1" \
12189            0 \
12190            -c "got a certificate request" \
12191            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12192            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12193            -c "Protocol is TLSv1.3"
12194
12195requires_openssl_tls1_3
12196requires_config_enabled MBEDTLS_DEBUG_C
12197requires_config_enabled MBEDTLS_SSL_CLI_C
12198requires_config_enabled MBEDTLS_RSA_C
12199requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12200requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12201                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12202run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha384 - openssl" \
12203            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12204            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
12205                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384 key_opaque=1" \
12206            0 \
12207            -c "got a certificate request" \
12208            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12209            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12210            -c "Protocol is TLSv1.3"
12211
12212requires_gnutls_tls1_3
12213requires_gnutls_next_no_ticket
12214requires_config_enabled MBEDTLS_DEBUG_C
12215requires_config_enabled MBEDTLS_SSL_CLI_C
12216requires_config_enabled MBEDTLS_RSA_C
12217requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12218requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12219                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12220run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha384 - gnutls" \
12221            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12222            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
12223                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384 key_opaque=1" \
12224            0 \
12225            -c "got a certificate request" \
12226            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12227            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12228            -c "Protocol is TLSv1.3"
12229
12230requires_openssl_tls1_3
12231requires_config_enabled MBEDTLS_DEBUG_C
12232requires_config_enabled MBEDTLS_SSL_CLI_C
12233requires_config_enabled MBEDTLS_RSA_C
12234requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12235requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12236                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12237run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha512 - openssl" \
12238            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
12239            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
12240                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512 key_opaque=1" \
12241            0 \
12242            -c "got a certificate request" \
12243            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12244            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12245            -c "Protocol is TLSv1.3"
12246
12247requires_gnutls_tls1_3
12248requires_gnutls_next_no_ticket
12249requires_config_enabled MBEDTLS_DEBUG_C
12250requires_config_enabled MBEDTLS_SSL_CLI_C
12251requires_config_enabled MBEDTLS_RSA_C
12252requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12253requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12254                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12255run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha512 - gnutls" \
12256            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
12257            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
12258                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512 key_opaque=1" \
12259            0 \
12260            -c "got a certificate request" \
12261            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12262            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12263            -c "Protocol is TLSv1.3"
12264
12265requires_openssl_tls1_3
12266requires_config_enabled MBEDTLS_DEBUG_C
12267requires_config_enabled MBEDTLS_SSL_CLI_C
12268requires_config_enabled MBEDTLS_RSA_C
12269requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12270requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12271                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12272run_test    "TLS 1.3: Client authentication - opaque key, client alg not in server list - openssl" \
12273            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10
12274                -sigalgs ecdsa_secp256r1_sha256" \
12275            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12276                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512 key_opaque=1" \
12277            1 \
12278            -c "got a certificate request" \
12279            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12280            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12281            -c "no suitable signature algorithm" \
12282            -C "unkown pk type"
12283
12284requires_gnutls_tls1_3
12285requires_gnutls_next_no_ticket
12286requires_config_enabled MBEDTLS_DEBUG_C
12287requires_config_enabled MBEDTLS_SSL_CLI_C
12288requires_config_enabled MBEDTLS_RSA_C
12289requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12290requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12291                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12292run_test    "TLS 1.3: Client authentication - opaque key, client alg not in server list - gnutls" \
12293            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:-SIGN-ALL:+SIGN-ECDSA-SECP256R1-SHA256:%NO_TICKETS" \
12294            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12295                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512 key_opaque=1" \
12296            1 \
12297            -c "got a certificate request" \
12298            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12299            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12300            -c "no suitable signature algorithm" \
12301            -C "unkown pk type"
12302
12303requires_openssl_tls1_3
12304requires_config_enabled MBEDTLS_DEBUG_C
12305requires_config_enabled MBEDTLS_SSL_CLI_C
12306requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12307                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12308run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_128_GCM_SHA256 - openssl" \
12309            "$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" \
12310            "$P_CLI debug_level=4" \
12311            0 \
12312            -c "received HelloRetryRequest message" \
12313            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12314            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12315            -c "Protocol is TLSv1.3" \
12316            -c "HTTP/1.0 200 ok"
12317
12318requires_openssl_tls1_3
12319requires_config_enabled MBEDTLS_DEBUG_C
12320requires_config_enabled MBEDTLS_SSL_CLI_C
12321requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12322                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12323run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_256_GCM_SHA384 - openssl" \
12324            "$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" \
12325            "$P_CLI debug_level=4" \
12326            0 \
12327            -c "received HelloRetryRequest message" \
12328            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12329            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12330            -c "Protocol is TLSv1.3" \
12331            -c "HTTP/1.0 200 ok"
12332
12333requires_gnutls_tls1_3
12334requires_gnutls_next_no_ticket
12335requires_config_enabled MBEDTLS_DEBUG_C
12336requires_config_enabled MBEDTLS_SSL_CLI_C
12337requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12338                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12339run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_128_GCM_SHA256 - gnutls" \
12340            "$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" \
12341            "$P_CLI debug_level=4" \
12342            0 \
12343            -c "received HelloRetryRequest message" \
12344            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12345            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12346            -c "Protocol is TLSv1.3" \
12347            -c "HTTP/1.0 200 OK"
12348
12349requires_gnutls_tls1_3
12350requires_gnutls_next_no_ticket
12351requires_config_enabled MBEDTLS_DEBUG_C
12352requires_config_enabled MBEDTLS_SSL_CLI_C
12353requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12354                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12355run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_256_GCM_SHA384 - gnutls" \
12356            "$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" \
12357            "$P_CLI debug_level=4" \
12358            0 \
12359            -c "received HelloRetryRequest message" \
12360            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12361            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12362            -c "Protocol is TLSv1.3" \
12363            -c "HTTP/1.0 200 OK"
12364
12365requires_openssl_tls1_3
12366requires_config_enabled MBEDTLS_DEBUG_C
12367requires_config_enabled MBEDTLS_SSL_SRV_C
12368requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12369run_test    "TLS 1.3: Server side check - openssl" \
12370            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12371            "$O_NEXT_CLI -msg -debug -tls1_3 -no_middlebox" \
12372            0 \
12373            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12374            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12375            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12376            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12377            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12378            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12379            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
12380            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP"
12381
12382requires_openssl_tls1_3
12383requires_config_enabled MBEDTLS_DEBUG_C
12384requires_config_enabled MBEDTLS_SSL_SRV_C
12385requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12386run_test    "TLS 1.3: Server side check - openssl with client authentication" \
12387            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12388            "$O_NEXT_CLI -msg -debug -cert data_files/server5.crt -key data_files/server5.key -tls1_3 -no_middlebox" \
12389            0 \
12390            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12391            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12392            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12393            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12394            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12395            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12396            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12397            -s "=> write certificate request" \
12398            -s "=> parse client hello" \
12399            -s "<= parse client hello"
12400
12401requires_gnutls_tls1_3
12402requires_gnutls_next_no_ticket
12403requires_config_enabled MBEDTLS_DEBUG_C
12404requires_config_enabled MBEDTLS_SSL_SRV_C
12405requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12406run_test    "TLS 1.3: Server side check - gnutls" \
12407            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12408            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12409            0 \
12410            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12411            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12412            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12413            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12414            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12415            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12416            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
12417            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12418            -c "HTTP/1.0 200 OK"
12419
12420requires_gnutls_tls1_3
12421requires_gnutls_next_no_ticket
12422requires_config_enabled MBEDTLS_DEBUG_C
12423requires_config_enabled MBEDTLS_SSL_SRV_C
12424requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12425run_test    "TLS 1.3: Server side check - gnutls with client authentication" \
12426            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12427            "$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" \
12428            0 \
12429            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12430            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12431            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12432            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12433            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12434            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12435            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12436            -s "=> write certificate request" \
12437            -s "=> parse client hello" \
12438            -s "<= parse client hello"
12439
12440requires_config_enabled MBEDTLS_DEBUG_C
12441requires_config_enabled MBEDTLS_SSL_SRV_C
12442requires_config_enabled MBEDTLS_SSL_CLI_C
12443requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12444run_test    "TLS 1.3: Server side check - mbedtls" \
12445            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12446            "$P_CLI debug_level=4 force_version=tls13" \
12447            0 \
12448            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12449            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12450            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12451            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12452            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12453            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12454            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12455            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
12456            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12457            -c "HTTP/1.0 200 OK"
12458
12459requires_config_enabled MBEDTLS_DEBUG_C
12460requires_config_enabled MBEDTLS_SSL_SRV_C
12461requires_config_enabled MBEDTLS_SSL_CLI_C
12462requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12463run_test    "TLS 1.3: Server side check - mbedtls with client authentication" \
12464            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12465            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13" \
12466            0 \
12467            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12468            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12469            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12470            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12471            -s "=> write certificate request" \
12472            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12473            -s "=> parse client hello" \
12474            -s "<= parse client hello"
12475
12476requires_config_enabled MBEDTLS_DEBUG_C
12477requires_config_enabled MBEDTLS_SSL_SRV_C
12478requires_config_enabled MBEDTLS_SSL_CLI_C
12479requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12480run_test    "TLS 1.3: Server side check - mbedtls with client empty certificate" \
12481            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12482            "$P_CLI debug_level=4 crt_file=none key_file=none force_version=tls13" \
12483            1 \
12484            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12485            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12486            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12487            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12488            -s "=> write certificate request" \
12489            -s "SSL - No client certification received from the client, but required by the authentication mode" \
12490            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12491            -s "=> parse client hello" \
12492            -s "<= parse client hello"
12493
12494requires_config_enabled MBEDTLS_DEBUG_C
12495requires_config_enabled MBEDTLS_SSL_SRV_C
12496requires_config_enabled MBEDTLS_SSL_CLI_C
12497requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12498run_test    "TLS 1.3: Server side check - mbedtls with optional client authentication" \
12499            "$P_SRV debug_level=4 auth_mode=optional crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12500            "$P_CLI debug_level=4 force_version=tls13 crt_file=none key_file=none" \
12501            0 \
12502            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12503            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12504            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12505            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12506            -s "=> write certificate request" \
12507            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12508            -s "=> parse client hello" \
12509            -s "<= parse client hello"
12510
12511requires_config_enabled MBEDTLS_DEBUG_C
12512requires_config_enabled MBEDTLS_SSL_CLI_C
12513requires_config_enabled MBEDTLS_SSL_SRV_C
12514requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12515run_test "TLS 1.3: server: HRR check - mbedtls" \
12516         "$P_SRV debug_level=4 force_version=tls13 curves=secp384r1" \
12517         "$P_CLI debug_level=4 force_version=tls13 curves=secp256r1,secp384r1" \
12518         0 \
12519        -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12520        -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12521        -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12522        -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
12523        -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12524        -s "selected_group: secp384r1" \
12525        -s "=> write hello retry request" \
12526        -s "<= write hello retry request"
12527
12528requires_config_enabled MBEDTLS_DEBUG_C
12529requires_config_enabled MBEDTLS_SSL_SRV_C
12530requires_config_enabled MBEDTLS_SSL_CLI_C
12531requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12532run_test    "TLS 1.3: Server side check, no server certificate available" \
12533            "$P_SRV debug_level=4 crt_file=none key_file=none force_version=tls13" \
12534            "$P_CLI debug_level=4 force_version=tls13" \
12535            1 \
12536            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12537            -s "No certificate available."
12538
12539requires_openssl_tls1_3
12540requires_config_enabled MBEDTLS_DEBUG_C
12541requires_config_enabled MBEDTLS_SSL_SRV_C
12542requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12543                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12544run_test    "TLS 1.3: Server side check - openssl with sni" \
12545            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0 \
12546             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,-,-,-" \
12547            "$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" \
12548            0 \
12549            -s "parse ServerName extension" \
12550            -s "HTTP/1.0 200 OK"
12551
12552requires_gnutls_tls1_3
12553requires_config_enabled MBEDTLS_DEBUG_C
12554requires_config_enabled MBEDTLS_SSL_SRV_C
12555requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12556                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12557run_test    "TLS 1.3: Server side check - gnutls with sni" \
12558            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0 \
12559             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,-,-,-" \
12560            "$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" \
12561            0 \
12562            -s "parse ServerName extension" \
12563            -s "HTTP/1.0 200 OK"
12564
12565requires_config_enabled MBEDTLS_DEBUG_C
12566requires_config_enabled MBEDTLS_SSL_SRV_C
12567requires_config_enabled MBEDTLS_SSL_CLI_C
12568requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12569                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12570run_test    "TLS 1.3: Server side check - mbedtls with sni" \
12571            "$P_SRV debug_level=4 auth_mode=required crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0 \
12572             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
12573            "$P_CLI debug_level=4 server_name=localhost crt_file=data_files/server5.crt key_file=data_files/server5.key \
12574            force_version=tls13" \
12575            0 \
12576            -s "parse ServerName extension" \
12577            -s "HTTP/1.0 200 OK"
12578
12579for i in opt-testcases/*.sh
12580do
12581    TEST_SUITE_NAME=${i##*/}
12582    TEST_SUITE_NAME=${TEST_SUITE_NAME%.*}
12583    . "$i"
12584done
12585unset TEST_SUITE_NAME
12586
12587# Test 1.3 compatibility mode
12588requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12589requires_config_enabled MBEDTLS_DEBUG_C
12590requires_config_enabled MBEDTLS_SSL_SRV_C
12591requires_config_enabled MBEDTLS_SSL_CLI_C
12592requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12593run_test    "TLS 1.3 m->m both peers do not support middlebox compatibility" \
12594            "$P_SRV debug_level=4 force_version=tls13 tickets=0" \
12595            "$P_CLI debug_level=4" \
12596            0 \
12597            -s "Protocol is TLSv1.3" \
12598            -c "Protocol is TLSv1.3" \
12599            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12600            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12601
12602requires_config_enabled MBEDTLS_DEBUG_C
12603requires_config_enabled MBEDTLS_SSL_SRV_C
12604requires_config_enabled MBEDTLS_SSL_CLI_C
12605requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12606                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12607run_test    "TLS 1.3 m->m both with middlebox compat support" \
12608            "$P_SRV debug_level=4 force_version=tls13 tickets=0" \
12609            "$P_CLI debug_level=4" \
12610            0 \
12611            -s "Protocol is TLSv1.3" \
12612            -c "Protocol is TLSv1.3" \
12613            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12614            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12615
12616requires_openssl_tls1_3
12617requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12618requires_config_enabled MBEDTLS_DEBUG_C
12619requires_config_enabled MBEDTLS_SSL_CLI_C
12620requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12621run_test    "TLS 1.3 m->O both peers do not support middlebox compatibility" \
12622            "$O_NEXT_SRV -msg -tls1_3 -no_middlebox -num_tickets 0 -no_resume_ephemeral -no_cache" \
12623            "$P_CLI debug_level=4" \
12624            0 \
12625            -c "Protocol is TLSv1.3" \
12626            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12627            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12628
12629requires_openssl_tls1_3
12630requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12631requires_config_enabled MBEDTLS_DEBUG_C
12632requires_config_enabled MBEDTLS_SSL_CLI_C
12633requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12634run_test    "TLS 1.3 m->O server with middlebox compat support, not client" \
12635            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12636            "$P_CLI debug_level=4" \
12637            1 \
12638            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12639
12640requires_openssl_tls1_3
12641requires_config_enabled MBEDTLS_DEBUG_C
12642requires_config_enabled MBEDTLS_SSL_CLI_C
12643requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12644                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12645run_test    "TLS 1.3 m->O both with middlebox compat support" \
12646            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12647            "$P_CLI debug_level=4" \
12648            0 \
12649            -c "Protocol is TLSv1.3" \
12650            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12651
12652requires_gnutls_tls1_3
12653requires_gnutls_next_no_ticket
12654requires_gnutls_next_disable_tls13_compat
12655requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12656requires_config_enabled MBEDTLS_DEBUG_C
12657requires_config_enabled MBEDTLS_SSL_CLI_C
12658requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12659run_test    "TLS 1.3 m->G both peers do not support middlebox compatibility" \
12660            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert" \
12661            "$P_CLI debug_level=4" \
12662            0 \
12663            -c "Protocol is TLSv1.3" \
12664            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12665            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12666
12667requires_gnutls_tls1_3
12668requires_gnutls_next_no_ticket
12669requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12670requires_config_enabled MBEDTLS_DEBUG_C
12671requires_config_enabled MBEDTLS_SSL_CLI_C
12672requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12673run_test    "TLS 1.3 m->G server with middlebox compat support, not client" \
12674            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
12675            "$P_CLI debug_level=4" \
12676            1 \
12677            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12678
12679requires_gnutls_tls1_3
12680requires_gnutls_next_no_ticket
12681requires_config_enabled MBEDTLS_DEBUG_C
12682requires_config_enabled MBEDTLS_SSL_CLI_C
12683requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12684                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12685run_test    "TLS 1.3 m->G both with middlebox compat support" \
12686            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
12687            "$P_CLI debug_level=4" \
12688            0 \
12689            -c "Protocol is TLSv1.3" \
12690            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12691
12692requires_openssl_tls1_3
12693requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12694requires_config_enabled MBEDTLS_DEBUG_C
12695requires_config_enabled MBEDTLS_SSL_SRV_C
12696requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12697run_test    "TLS 1.3 O->m both peers do not support middlebox compatibility" \
12698            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12699            "$O_NEXT_CLI -msg -debug -no_middlebox" \
12700            0 \
12701            -s "Protocol is TLSv1.3" \
12702            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12703            -C "14 03 03 00 01"
12704
12705requires_openssl_tls1_3
12706requires_config_enabled MBEDTLS_DEBUG_C
12707requires_config_enabled MBEDTLS_SSL_SRV_C
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 O->m server with middlebox compat support, not client" \
12711            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12712            "$O_NEXT_CLI -msg -debug -no_middlebox" \
12713            0 \
12714            -s "Protocol is TLSv1.3" \
12715            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO"
12716
12717requires_openssl_tls1_3
12718requires_config_enabled MBEDTLS_DEBUG_C
12719requires_config_enabled MBEDTLS_SSL_SRV_C
12720requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12721                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12722run_test    "TLS 1.3 O->m both with middlebox compat support" \
12723            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12724            "$O_NEXT_CLI -msg -debug" \
12725            0 \
12726            -s "Protocol is TLSv1.3" \
12727            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12728            -c "14 03 03 00 01"
12729
12730requires_gnutls_tls1_3
12731requires_gnutls_next_no_ticket
12732requires_gnutls_next_disable_tls13_compat
12733requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12734requires_config_enabled MBEDTLS_DEBUG_C
12735requires_config_enabled MBEDTLS_SSL_SRV_C
12736requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12737run_test    "TLS 1.3 G->m both peers do not support middlebox compatibility" \
12738            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12739            "$G_NEXT_CLI localhost --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12740            0 \
12741            -s "Protocol is TLSv1.3" \
12742            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12743            -C "SSL 3.3 ChangeCipherSpec packet received"
12744
12745requires_gnutls_tls1_3
12746requires_gnutls_next_no_ticket
12747requires_gnutls_next_disable_tls13_compat
12748requires_config_enabled MBEDTLS_DEBUG_C
12749requires_config_enabled MBEDTLS_SSL_SRV_C
12750requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12751                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12752run_test    "TLS 1.3 G->m server with middlebox compat support, not client" \
12753            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12754            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12755            0 \
12756            -s "Protocol is TLSv1.3" \
12757            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12758            -c "SSL 3.3 ChangeCipherSpec packet received" \
12759            -c "discarding change cipher spec in TLS1.3"
12760
12761requires_gnutls_tls1_3
12762requires_gnutls_next_no_ticket
12763requires_gnutls_next_disable_tls13_compat
12764requires_config_enabled MBEDTLS_DEBUG_C
12765requires_config_enabled MBEDTLS_SSL_SRV_C
12766requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12767                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12768run_test    "TLS 1.3 G->m both with middlebox compat support" \
12769            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12770            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12771            0 \
12772            -s "Protocol is TLSv1.3" \
12773            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12774            -c "SSL 3.3 ChangeCipherSpec packet received"
12775
12776requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12777requires_config_enabled MBEDTLS_DEBUG_C
12778requires_config_enabled MBEDTLS_SSL_SRV_C
12779requires_config_enabled MBEDTLS_SSL_CLI_C
12780requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12781run_test    "TLS 1.3 m->m HRR both peers do not support middlebox compatibility" \
12782            "$P_SRV debug_level=4 force_version=tls13 curves=secp384r1 tickets=0" \
12783            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12784            0 \
12785            -s "Protocol is TLSv1.3" \
12786            -c "Protocol is TLSv1.3" \
12787            -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
12788            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12789            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12790
12791requires_config_enabled MBEDTLS_DEBUG_C
12792requires_config_enabled MBEDTLS_SSL_SRV_C
12793requires_config_enabled MBEDTLS_SSL_CLI_C
12794requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12795                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12796run_test    "TLS 1.3 m->m HRR both with middlebox compat support" \
12797            "$P_SRV debug_level=4 force_version=tls13 curves=secp384r1 tickets=0" \
12798            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12799            0 \
12800            -s "Protocol is TLSv1.3" \
12801            -c "Protocol is TLSv1.3" \
12802            -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
12803            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12804            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12805
12806requires_openssl_tls1_3
12807requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12808requires_config_enabled MBEDTLS_DEBUG_C
12809requires_config_enabled MBEDTLS_SSL_CLI_C
12810requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12811run_test    "TLS 1.3 m->O HRR both peers do not support middlebox compatibility" \
12812            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -no_middlebox -num_tickets 0 -no_cache" \
12813            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12814            0 \
12815            -c "Protocol is TLSv1.3" \
12816            -c "received HelloRetryRequest message" \
12817            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12818            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12819
12820requires_openssl_tls1_3
12821requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12822requires_config_enabled MBEDTLS_DEBUG_C
12823requires_config_enabled MBEDTLS_SSL_CLI_C
12824requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12825run_test    "TLS 1.3 m->O HRR server with middlebox compat support, not client" \
12826            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -num_tickets 0 -no_cache" \
12827            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12828            1 \
12829            -c "received HelloRetryRequest message" \
12830            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12831
12832requires_openssl_tls1_3
12833requires_config_enabled MBEDTLS_DEBUG_C
12834requires_config_enabled MBEDTLS_SSL_CLI_C
12835requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12836                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12837run_test    "TLS 1.3 m->O HRR both with middlebox compat support" \
12838            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12839            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12840            0 \
12841            -c "Protocol is TLSv1.3" \
12842            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12843
12844requires_gnutls_tls1_3
12845requires_gnutls_next_no_ticket
12846requires_gnutls_next_disable_tls13_compat
12847requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12848requires_config_enabled MBEDTLS_DEBUG_C
12849requires_config_enabled MBEDTLS_SSL_CLI_C
12850requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12851run_test    "TLS 1.3 m->G HRR both peers do not support middlebox compatibility" \
12852            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert" \
12853            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12854            0 \
12855            -c "Protocol is TLSv1.3" \
12856            -c "received HelloRetryRequest message" \
12857            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12858            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12859
12860requires_gnutls_tls1_3
12861requires_gnutls_next_no_ticket
12862requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12863requires_config_enabled MBEDTLS_DEBUG_C
12864requires_config_enabled MBEDTLS_SSL_CLI_C
12865requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12866run_test    "TLS 1.3 m->G HRR server with middlebox compat support, not client" \
12867            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS --disable-client-cert" \
12868            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12869            1 \
12870            -c "received HelloRetryRequest message" \
12871            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12872
12873requires_gnutls_tls1_3
12874requires_gnutls_next_no_ticket
12875requires_config_enabled MBEDTLS_DEBUG_C
12876requires_config_enabled MBEDTLS_SSL_CLI_C
12877requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12878                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12879run_test    "TLS 1.3 m->G HRR both with middlebox compat support" \
12880            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
12881            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12882            0 \
12883            -c "Protocol is TLSv1.3" \
12884            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12885
12886requires_openssl_tls1_3
12887requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12888requires_config_enabled MBEDTLS_DEBUG_C
12889requires_config_enabled MBEDTLS_SSL_SRV_C
12890requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12891run_test    "TLS 1.3 O->m HRR both peers do not support middlebox compatibility" \
12892            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12893            "$O_NEXT_CLI -msg -debug -groups P-256:P-384 -no_middlebox" \
12894            0 \
12895            -s "Protocol is TLSv1.3" \
12896            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12897            -C "14 03 03 00 01"
12898
12899requires_openssl_tls1_3
12900requires_config_enabled MBEDTLS_DEBUG_C
12901requires_config_enabled MBEDTLS_SSL_SRV_C
12902requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12903                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12904run_test    "TLS 1.3 O->m HRR server with middlebox compat support, not client" \
12905            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12906            "$O_NEXT_CLI -msg -debug -groups P-256:P-384 -no_middlebox" \
12907            0 \
12908            -s "Protocol is TLSv1.3" \
12909            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12910
12911requires_openssl_tls1_3
12912requires_config_enabled MBEDTLS_DEBUG_C
12913requires_config_enabled MBEDTLS_SSL_SRV_C
12914requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12915                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12916run_test    "TLS 1.3 O->m HRR both with middlebox compat support" \
12917            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12918            "$O_NEXT_CLI -msg -debug -groups P-256:P-384" \
12919            0 \
12920            -s "Protocol is TLSv1.3" \
12921            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12922            -c "14 03 03 00 01"
12923
12924requires_gnutls_tls1_3
12925requires_gnutls_next_no_ticket
12926requires_gnutls_next_disable_tls13_compat
12927requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12928requires_config_enabled MBEDTLS_DEBUG_C
12929requires_config_enabled MBEDTLS_SSL_SRV_C
12930requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12931run_test    "TLS 1.3 G->m HRR both peers do not support middlebox compatibility" \
12932            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12933            "$G_NEXT_CLI localhost --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12934            0 \
12935            -s "Protocol is TLSv1.3" \
12936            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12937            -C "SSL 3.3 ChangeCipherSpec packet received"
12938
12939requires_gnutls_tls1_3
12940requires_gnutls_next_no_ticket
12941requires_gnutls_next_disable_tls13_compat
12942requires_config_enabled MBEDTLS_DEBUG_C
12943requires_config_enabled MBEDTLS_SSL_SRV_C
12944requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12945                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12946run_test    "TLS 1.3 G->m HRR server with middlebox compat support, not client" \
12947            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12948            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12949            0 \
12950            -s "Protocol is TLSv1.3" \
12951            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12952            -c "SSL 3.3 ChangeCipherSpec packet received" \
12953            -c "discarding change cipher spec in TLS1.3"
12954
12955requires_gnutls_tls1_3
12956requires_gnutls_next_no_ticket
12957requires_gnutls_next_disable_tls13_compat
12958requires_config_enabled MBEDTLS_DEBUG_C
12959requires_config_enabled MBEDTLS_SSL_SRV_C
12960requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12961                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12962run_test    "TLS 1.3 G->m HRR both with middlebox compat support" \
12963            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12964            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12965            0 \
12966            -s "Protocol is TLSv1.3" \
12967            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12968            -c "SSL 3.3 ChangeCipherSpec packet received"
12969
12970requires_openssl_tls1_3
12971requires_config_enabled MBEDTLS_DEBUG_C
12972requires_config_enabled MBEDTLS_SSL_CLI_C
12973requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12974                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12975run_test    "TLS 1.3: Check signature algorithm order, m->O" \
12976            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
12977                                 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache
12978                                 -Verify 10 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp256r1_sha256" \
12979            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
12980                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12981            0 \
12982            -c "Protocol is TLSv1.3" \
12983            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
12984            -c "HTTP/1.0 200 [Oo][Kk]"
12985
12986requires_gnutls_tls1_3
12987requires_config_enabled MBEDTLS_DEBUG_C
12988requires_config_enabled MBEDTLS_SSL_CLI_C
12989requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12990                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12991run_test    "TLS 1.3: Check signature algorithm order, m->G" \
12992            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
12993                    -d 4
12994                    --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 " \
12995            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
12996                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12997            0 \
12998            -c "Protocol is TLSv1.3" \
12999            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
13000            -c "HTTP/1.0 200 [Oo][Kk]"
13001
13002requires_config_enabled MBEDTLS_DEBUG_C
13003requires_config_enabled MBEDTLS_SSL_SRV_C
13004requires_config_enabled MBEDTLS_SSL_CLI_C
13005requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13006                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13007run_test    "TLS 1.3: Check signature algorithm order, m->m" \
13008            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
13009                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13010                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13011                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13012            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
13013                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13014            0 \
13015            -c "Protocol is TLSv1.3" \
13016            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
13017            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
13018            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512" \
13019            -c "HTTP/1.0 200 [Oo][Kk]"
13020
13021requires_openssl_tls1_3
13022requires_config_enabled MBEDTLS_DEBUG_C
13023requires_config_enabled MBEDTLS_SSL_SRV_C
13024requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13025                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13026run_test    "TLS 1.3: Check signature algorithm order, O->m" \
13027            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
13028                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13029                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13030                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13031            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
13032                                 -cert data_files/server2-sha256.crt -key data_files/server2.key \
13033                                 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp256r1_sha256"  \
13034            0 \
13035            -c "TLSv1.3" \
13036            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
13037            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512"
13038
13039requires_gnutls_tls1_3
13040requires_config_enabled MBEDTLS_DEBUG_C
13041requires_config_enabled MBEDTLS_SSL_SRV_C
13042requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13043                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13044run_test    "TLS 1.3: Check signature algorithm order, G->m" \
13045            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
13046                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13047                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13048                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13049            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
13050                                 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key \
13051                                 --priority=NORMAL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-RSA-PSS-RSAE-SHA384"  \
13052            0 \
13053            -c "Negotiated version: 3.4" \
13054            -c "HTTP/1.0 200 [Oo][Kk]" \
13055            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
13056            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512"
13057
13058requires_gnutls_tls1_3
13059requires_config_enabled MBEDTLS_DEBUG_C
13060requires_config_enabled MBEDTLS_SSL_SRV_C
13061requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13062                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13063run_test    "TLS 1.3: Check server no suitable signature algorithm, G->m" \
13064            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
13065                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13066                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13067                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256 " \
13068            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
13069                                 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key \
13070                                 --priority=NORMAL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-ECDSA-SECP521R1-SHA512"  \
13071            1 \
13072            -S "ssl_tls13_pick_key_cert:check signature algorithm"
13073
13074requires_openssl_tls1_3
13075requires_config_enabled MBEDTLS_DEBUG_C
13076requires_config_enabled MBEDTLS_SSL_SRV_C
13077requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13078                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13079run_test    "TLS 1.3: Check server no suitable signature algorithm, O->m" \
13080            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
13081                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13082                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13083                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256" \
13084            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
13085                                 -cert data_files/server2-sha256.crt -key data_files/server2.key \
13086                                 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:ecdsa_secp521r1_sha512"  \
13087            1 \
13088            -S "ssl_tls13_pick_key_cert:check signature algorithm"
13089
13090requires_config_enabled MBEDTLS_DEBUG_C
13091requires_config_enabled MBEDTLS_SSL_SRV_C
13092requires_config_enabled MBEDTLS_SSL_CLI_C
13093requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13094                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13095run_test    "TLS 1.3: Check server no suitable signature algorithm, m->m" \
13096            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
13097                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13098                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13099                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256 " \
13100            "$P_CLI allow_sha1=0 debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
13101                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,ecdsa_secp521r1_sha512" \
13102            1 \
13103            -S "ssl_tls13_pick_key_cert:check signature algorithm"
13104
13105requires_gnutls_tls1_3
13106requires_config_enabled MBEDTLS_DEBUG_C
13107requires_config_enabled MBEDTLS_SSL_SRV_C
13108requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13109                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13110run_test    "TLS 1.3: Check server no suitable certificate, G->m" \
13111            "$P_SRV debug_level=4 force_version=tls13
13112                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13113                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13114            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
13115                                 --priority=NORMAL:-SIGN-ALL:+SIGN-ECDSA-SECP521R1-SHA512:+SIGN-ECDSA-SECP256R1-SHA256"  \
13116            1 \
13117            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
13118
13119requires_openssl_tls1_3
13120requires_config_enabled MBEDTLS_DEBUG_C
13121requires_config_enabled MBEDTLS_SSL_SRV_C
13122requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13123                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13124run_test    "TLS 1.3: Check server no suitable certificate, O->m" \
13125            "$P_SRV debug_level=4 force_version=tls13
13126                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13127                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13128            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
13129                                 -sigalgs ecdsa_secp521r1_sha512:ecdsa_secp256r1_sha256"  \
13130            1 \
13131            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
13132
13133requires_config_enabled MBEDTLS_DEBUG_C
13134requires_config_enabled MBEDTLS_SSL_SRV_C
13135requires_config_enabled MBEDTLS_SSL_CLI_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: Check server no suitable certificate, m->m" \
13139            "$P_SRV debug_level=4 force_version=tls13
13140                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13141                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
13142            "$P_CLI allow_sha1=0 debug_level=4 \
13143                    sig_algs=ecdsa_secp521r1_sha512,ecdsa_secp256r1_sha256" \
13144            1 \
13145            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
13146
13147requires_openssl_tls1_3
13148requires_config_enabled MBEDTLS_DEBUG_C
13149requires_config_enabled MBEDTLS_SSL_CLI_C
13150requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13151                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13152run_test    "TLS 1.3: Check client no signature algorithm, m->O" \
13153            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
13154                                 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache
13155                                 -Verify 10 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp521r1_sha512" \
13156            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
13157                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13158            1 \
13159            -c "no suitable signature algorithm"
13160
13161requires_gnutls_tls1_3
13162requires_config_enabled MBEDTLS_DEBUG_C
13163requires_config_enabled MBEDTLS_SSL_CLI_C
13164requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13165                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13166run_test    "TLS 1.3: Check client no signature algorithm, m->G" \
13167            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
13168                    -d 4
13169                    --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 " \
13170            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
13171                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13172            1 \
13173            -c "no suitable signature algorithm"
13174
13175requires_config_enabled MBEDTLS_DEBUG_C
13176requires_config_enabled MBEDTLS_SSL_SRV_C
13177requires_config_enabled MBEDTLS_SSL_CLI_C
13178requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13179                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
13180run_test    "TLS 1.3: Check client no signature algorithm, m->m" \
13181            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
13182                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
13183                    crt_file=data_files/server5.crt key_file=data_files/server5.key
13184                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp521r1_sha512" \
13185            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
13186                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
13187            1 \
13188            -c "no suitable signature algorithm"
13189
13190requires_openssl_tls1_3
13191requires_config_enabled MBEDTLS_DEBUG_C
13192requires_config_enabled MBEDTLS_SSL_CLI_C
13193requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13194                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13195                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13196run_test    "TLS 1.3: NewSessionTicket: Basic check, m->O" \
13197            "$O_NEXT_SRV -msg -tls1_3 -no_resume_ephemeral -no_cache --num_tickets 4" \
13198            "$P_CLI debug_level=1 reco_mode=1 reconnect=1" \
13199            0 \
13200            -c "Protocol is TLSv1.3" \
13201            -c "got new session ticket." \
13202            -c "Saving session for reuse... ok" \
13203            -c "Reconnecting with saved session" \
13204            -c "HTTP/1.0 200 ok"
13205
13206requires_gnutls_tls1_3
13207requires_config_enabled MBEDTLS_DEBUG_C
13208requires_config_enabled MBEDTLS_SSL_CLI_C
13209requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13210                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13211                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13212run_test    "TLS 1.3: NewSessionTicket: Basic check, m->G" \
13213            "$G_NEXT_SRV -d 10 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 --disable-client-cert" \
13214            "$P_CLI debug_level=1 reco_mode=1 reconnect=1" \
13215            0 \
13216            -c "Protocol is TLSv1.3" \
13217            -c "got new session ticket." \
13218            -c "Saving session for reuse... ok" \
13219            -c "Reconnecting with saved session" \
13220            -c "HTTP/1.0 200 OK" \
13221            -s "This is a resumed session"
13222
13223requires_openssl_tls1_3
13224requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13225requires_config_enabled MBEDTLS_SSL_SRV_C
13226requires_config_enabled MBEDTLS_DEBUG_C
13227requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13228                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13229                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13230# https://github.com/openssl/openssl/issues/10714
13231# Until now, OpenSSL client does not support reconnect.
13232skip_next_test
13233run_test    "TLS 1.3: NewSessionTicket: Basic check, O->m" \
13234            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4" \
13235            "$O_NEXT_CLI -msg -debug -tls1_3 -reconnect" \
13236            0 \
13237            -s "=> write NewSessionTicket msg" \
13238            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13239            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH"
13240
13241requires_gnutls_tls1_3
13242requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13243requires_config_enabled MBEDTLS_SSL_SRV_C
13244requires_config_enabled MBEDTLS_DEBUG_C
13245requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13246                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13247                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13248run_test    "TLS 1.3: NewSessionTicket: Basic check, G->m" \
13249            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4" \
13250            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -r" \
13251            0 \
13252            -c "Connecting again- trying to resume previous session" \
13253            -c "NEW SESSION TICKET (4) was received" \
13254            -s "=> write NewSessionTicket msg" \
13255            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13256            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" \
13257            -s "key exchange mode: ephemeral" \
13258            -s "key exchange mode: psk_ephemeral" \
13259            -s "found pre_shared_key extension"
13260
13261requires_gnutls_tls1_3
13262requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13263requires_config_enabled MBEDTLS_SSL_SRV_C
13264requires_config_enabled MBEDTLS_DEBUG_C
13265requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13266                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13267                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13268# Test the session resumption when the cipher suite for the original session is
13269# TLS1-3-AES-256-GCM-SHA384. In that case, the PSK is 384 bits long and not
13270# 256 bits long as with all the other TLS 1.3 cipher suites.
13271requires_ciphersuite_enabled TLS1-3-AES-256-GCM-SHA384
13272run_test    "TLS 1.3: NewSessionTicket: Basic check with AES-256-GCM only, G->m" \
13273            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4" \
13274            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:-CIPHER-ALL:+AES-256-GCM -V -r" \
13275            0 \
13276            -c "Connecting again- trying to resume previous session" \
13277            -c "NEW SESSION TICKET (4) was received" \
13278            -s "Ciphersuite is TLS1-3-AES-256-GCM-SHA384" \
13279            -s "=> write NewSessionTicket msg" \
13280            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13281            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" \
13282            -s "key exchange mode: ephemeral" \
13283            -s "key exchange mode: psk_ephemeral" \
13284            -s "found pre_shared_key extension"
13285
13286requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13287requires_config_enabled MBEDTLS_SSL_SRV_C
13288requires_config_enabled MBEDTLS_SSL_CLI_C
13289requires_config_enabled MBEDTLS_DEBUG_C
13290requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13291                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13292                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13293run_test    "TLS 1.3: NewSessionTicket: Basic check, m->m" \
13294            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4" \
13295            "$P_CLI debug_level=4 reco_mode=1 reconnect=1" \
13296            0 \
13297            -c "Protocol is TLSv1.3" \
13298            -c "got new session ticket ( 3 )" \
13299            -c "Saving session for reuse... ok" \
13300            -c "Reconnecting with saved session" \
13301            -c "HTTP/1.0 200 OK"    \
13302            -s "=> write NewSessionTicket msg" \
13303            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13304            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" \
13305            -s "key exchange mode: ephemeral" \
13306            -s "key exchange mode: psk_ephemeral" \
13307            -s "found pre_shared_key extension"
13308
13309requires_openssl_tls1_3
13310requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13311requires_config_enabled MBEDTLS_DEBUG_C
13312requires_config_enabled MBEDTLS_SSL_CLI_C
13313run_test    "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->O" \
13314            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
13315                                 -msg -tls1_2
13316                                 -Verify 10 " \
13317            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13318                    sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13319                    min_version=tls12 max_version=tls13 " \
13320            0 \
13321            -c "Protocol is TLSv1.2" \
13322            -c "HTTP/1.0 200 [Oo][Kk]"
13323
13324
13325requires_gnutls_tls1_3
13326requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13327requires_config_enabled MBEDTLS_DEBUG_C
13328requires_config_enabled MBEDTLS_SSL_CLI_C
13329run_test    "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->G" \
13330            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
13331                    -d 4
13332                    --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
13333            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13334                    sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13335                    min_version=tls12 max_version=tls13 " \
13336            0 \
13337            -c "Protocol is TLSv1.2" \
13338            -c "HTTP/1.0 200 [Oo][Kk]"
13339
13340requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13341requires_config_enabled MBEDTLS_SSL_SRV_C
13342requires_config_enabled MBEDTLS_SSL_CLI_C
13343requires_config_enabled MBEDTLS_DEBUG_C
13344requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13345                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13346                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13347run_test    "TLS 1.3: NewSessionTicket: servername check, m->m" \
13348            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4 \
13349            sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
13350            "$P_CLI debug_level=4 server_name=localhost reco_mode=1 reconnect=1" \
13351            0 \
13352            -c "Protocol is TLSv1.3" \
13353            -c "got new session ticket." \
13354            -c "Saving session for reuse... ok" \
13355            -c "Reconnecting with saved session" \
13356            -c "HTTP/1.0 200 OK"    \
13357            -s "=> write NewSessionTicket msg" \
13358            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13359            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" \
13360            -s "key exchange mode: ephemeral" \
13361            -s "key exchange mode: psk_ephemeral" \
13362            -s "found pre_shared_key extension"
13363
13364requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13365requires_config_enabled MBEDTLS_SSL_SRV_C
13366requires_config_enabled MBEDTLS_SSL_CLI_C
13367requires_config_enabled MBEDTLS_DEBUG_C
13368requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13369                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13370                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13371run_test    "TLS 1.3: NewSessionTicket: servername negative check, m->m" \
13372            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4 \
13373            sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
13374            "$P_CLI debug_level=4 server_name=localhost reco_server_name=remote reco_mode=1 reconnect=1" \
13375            1 \
13376            -c "Protocol is TLSv1.3" \
13377            -c "got new session ticket." \
13378            -c "Saving session for reuse... ok" \
13379            -c "Reconnecting with saved session" \
13380            -c "Hostname mismatch the session ticket, disable session resumption."    \
13381            -s "=> write NewSessionTicket msg" \
13382            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13383            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH"
13384
13385# Test heap memory usage after handshake
13386requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13387requires_config_enabled MBEDTLS_MEMORY_DEBUG
13388requires_config_enabled MBEDTLS_MEMORY_BUFFER_ALLOC_C
13389requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
13390requires_max_content_len 16384
13391run_tests_memory_after_hanshake
13392
13393# Final report
13394
13395echo "------------------------------------------------------------------------"
13396
13397if [ $FAILS = 0 ]; then
13398    printf "PASSED"
13399else
13400    printf "FAILED"
13401fi
13402PASSES=$(( $TESTS - $FAILS ))
13403echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
13404
13405if [ $FAILS -gt 255 ]; then
13406    # Clamp at 255 as caller gets exit code & 0xFF
13407    # (so 256 would be 0, or success, etc)
13408    FAILS=255
13409fi
13410exit $FAILS
13411