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_CMD:=openssl} # OPENSSL would conflict with the build system
50: ${GNUTLS_CLI:=gnutls-cli}
51: ${GNUTLS_SERV:=gnutls-serv}
52: ${PERL:=perl}
53
54guess_config_name() {
55    if git diff --quiet ../include/mbedtls/mbedtls_config.h 2>/dev/null; then
56        echo "default"
57    else
58        echo "unknown"
59    fi
60}
61: ${MBEDTLS_TEST_OUTCOME_FILE=}
62: ${MBEDTLS_TEST_CONFIGURATION:="$(guess_config_name)"}
63: ${MBEDTLS_TEST_PLATFORM:="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
64
65O_SRV="$OPENSSL_CMD s_server -www -cert data_files/server5.crt -key data_files/server5.key"
66O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
67G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
68G_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_CLI --x509cafile data_files/test-ca_cat12.crt"
69TCP_CLIENT="$PERL scripts/tcp_client.pl"
70
71# alternative versions of OpenSSL and GnuTLS (no default path)
72
73if [ -n "${OPENSSL_LEGACY:-}" ]; then
74    O_LEGACY_SRV="$OPENSSL_LEGACY s_server -www -cert data_files/server5.crt -key data_files/server5.key"
75    O_LEGACY_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_LEGACY s_client"
76else
77    O_LEGACY_SRV=false
78    O_LEGACY_CLI=false
79fi
80
81if [ -n "${OPENSSL_NEXT:-}" ]; then
82    O_NEXT_SRV="$OPENSSL_NEXT s_server -www -cert data_files/server5.crt -key data_files/server5.key"
83    O_NEXT_SRV_EARLY_DATA="$OPENSSL_NEXT s_server -early_data -cert data_files/server5.crt -key data_files/server5.key"
84    O_NEXT_SRV_NO_CERT="$OPENSSL_NEXT s_server -www "
85    O_NEXT_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client -CAfile data_files/test-ca_cat12.crt"
86    O_NEXT_CLI_NO_CERT="echo 'GET / HTTP/1.0' | $OPENSSL_NEXT s_client"
87else
88    O_NEXT_SRV=false
89    O_NEXT_SRV_NO_CERT=false
90    O_NEXT_SRV_EARLY_DATA=false
91    O_NEXT_CLI_NO_CERT=false
92    O_NEXT_CLI=false
93fi
94
95if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
96    G_NEXT_SRV="$GNUTLS_NEXT_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
97    G_NEXT_SRV_NO_CERT="$GNUTLS_NEXT_SERV"
98else
99    G_NEXT_SRV=false
100    G_NEXT_SRV_NO_CERT=false
101fi
102
103if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
104    G_NEXT_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_NEXT_CLI --x509cafile data_files/test-ca_cat12.crt"
105    G_NEXT_CLI_NO_CERT="echo 'GET / HTTP/1.0' | $GNUTLS_NEXT_CLI"
106else
107    G_NEXT_CLI=false
108    G_NEXT_CLI_NO_CERT=false
109fi
110
111TESTS=0
112FAILS=0
113SKIPS=0
114
115CONFIG_H='../include/mbedtls/mbedtls_config.h'
116
117MEMCHECK=0
118FILTER='.*'
119EXCLUDE='^$'
120
121SHOW_TEST_NUMBER=0
122RUN_TEST_NUMBER=''
123
124PRESERVE_LOGS=0
125
126# Pick a "unique" server port in the range 10000-19999, and a proxy
127# port which is this plus 10000. Each port number may be independently
128# overridden by a command line option.
129SRV_PORT=$(($$ % 10000 + 10000))
130PXY_PORT=$((SRV_PORT + 10000))
131
132print_usage() {
133    echo "Usage: $0 [options]"
134    printf "  -h|--help\tPrint this help.\n"
135    printf "  -m|--memcheck\tCheck memory leaks and errors.\n"
136    printf "  -f|--filter\tOnly matching tests are executed (substring or BRE)\n"
137    printf "  -e|--exclude\tMatching tests are excluded (substring or BRE)\n"
138    printf "  -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
139    printf "  -s|--show-numbers\tShow test numbers in front of test names\n"
140    printf "  -p|--preserve-logs\tPreserve logs of successful tests as well\n"
141    printf "     --outcome-file\tFile where test outcomes are written\n"
142    printf "                \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n"
143    printf "     --port     \tTCP/UDP port (default: randomish 1xxxx)\n"
144    printf "     --proxy-port\tTCP/UDP proxy port (default: randomish 2xxxx)\n"
145    printf "     --seed     \tInteger seed value to use for this test run\n"
146}
147
148get_options() {
149    while [ $# -gt 0 ]; do
150        case "$1" in
151            -f|--filter)
152                shift; FILTER=$1
153                ;;
154            -e|--exclude)
155                shift; EXCLUDE=$1
156                ;;
157            -m|--memcheck)
158                MEMCHECK=1
159                ;;
160            -n|--number)
161                shift; RUN_TEST_NUMBER=$1
162                ;;
163            -s|--show-numbers)
164                SHOW_TEST_NUMBER=1
165                ;;
166            -p|--preserve-logs)
167                PRESERVE_LOGS=1
168                ;;
169            --port)
170                shift; SRV_PORT=$1
171                ;;
172            --proxy-port)
173                shift; PXY_PORT=$1
174                ;;
175            --seed)
176                shift; SEED="$1"
177                ;;
178            -h|--help)
179                print_usage
180                exit 0
181                ;;
182            *)
183                echo "Unknown argument: '$1'"
184                print_usage
185                exit 1
186                ;;
187        esac
188        shift
189    done
190}
191
192# Make the outcome file path relative to the original directory, not
193# to .../tests
194case "$MBEDTLS_TEST_OUTCOME_FILE" in
195    [!/]*)
196        MBEDTLS_TEST_OUTCOME_FILE="$ORIGINAL_PWD/$MBEDTLS_TEST_OUTCOME_FILE"
197        ;;
198esac
199
200# Read boolean configuration options from mbedtls_config.h for easy and quick
201# testing. Skip non-boolean options (with something other than spaces
202# and a comment after "#define SYMBOL"). The variable contains a
203# space-separated list of symbols.
204CONFIGS_ENABLED=" $(echo `$P_QUERY -l` )"
205# Skip next test; use this macro to skip tests which are legitimate
206# in theory and expected to be re-introduced at some point, but
207# aren't expected to succeed at the moment due to problems outside
208# our control (such as bugs in other TLS implementations).
209skip_next_test() {
210    SKIP_NEXT="YES"
211}
212
213# skip next test if the flag is not enabled in mbedtls_config.h
214requires_config_enabled() {
215    case $CONFIGS_ENABLED in
216        *" $1"[\ =]*) :;;
217        *) SKIP_NEXT="YES";;
218    esac
219}
220
221# skip next test if the flag is enabled in mbedtls_config.h
222requires_config_disabled() {
223    case $CONFIGS_ENABLED in
224        *" $1"[\ =]*) SKIP_NEXT="YES";;
225    esac
226}
227
228requires_all_configs_enabled() {
229    if ! $P_QUERY -all $*
230    then
231        SKIP_NEXT="YES"
232    fi
233}
234
235requires_all_configs_disabled() {
236    if $P_QUERY -any $*
237    then
238        SKIP_NEXT="YES"
239    fi
240}
241
242requires_any_configs_enabled() {
243    if ! $P_QUERY -any $*
244    then
245        SKIP_NEXT="YES"
246    fi
247}
248
249requires_any_configs_disabled() {
250    if $P_QUERY -all $*
251    then
252        SKIP_NEXT="YES"
253    fi
254}
255
256TLS1_2_KEY_EXCHANGES_WITH_CERT="MBEDTLS_KEY_EXCHANGE_RSA_ENABLED \
257                                MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED \
258                                MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED \
259                                MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED \
260                                MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED \
261                                MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED \
262                                MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED"
263
264requires_key_exchange_with_cert_in_tls12_or_tls13_enabled() {
265    if $P_QUERY -all MBEDTLS_SSL_PROTO_TLS1_2
266    then
267        requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
268    elif ! $P_QUERY -all MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
269    then
270        SKIP_NEXT="YES"
271    fi
272}
273
274get_config_value_or_default() {
275    # This function uses the query_config command line option to query the
276    # required Mbed TLS compile time configuration from the ssl_server2
277    # program. The command will always return a success value if the
278    # configuration is defined and the value will be printed to stdout.
279    #
280    # Note that if the configuration is not defined or is defined to nothing,
281    # the output of this function will be an empty string.
282    ${P_SRV} "query_config=${1}"
283}
284
285requires_config_value_at_least() {
286    VAL="$( get_config_value_or_default "$1" )"
287    if [ -z "$VAL" ]; then
288        # Should never happen
289        echo "Mbed TLS configuration $1 is not defined"
290        exit 1
291    elif [ "$VAL" -lt "$2" ]; then
292       SKIP_NEXT="YES"
293    fi
294}
295
296requires_config_value_at_most() {
297    VAL=$( get_config_value_or_default "$1" )
298    if [ -z "$VAL" ]; then
299        # Should never happen
300        echo "Mbed TLS configuration $1 is not defined"
301        exit 1
302    elif [ "$VAL" -gt "$2" ]; then
303       SKIP_NEXT="YES"
304    fi
305}
306
307requires_config_value_equals() {
308    VAL=$( get_config_value_or_default "$1" )
309    if [ -z "$VAL" ]; then
310        # Should never happen
311        echo "Mbed TLS configuration $1 is not defined"
312        exit 1
313    elif [ "$VAL" -ne "$2" ]; then
314       SKIP_NEXT="YES"
315    fi
316}
317
318# Require Mbed TLS to support the given protocol version.
319#
320# Inputs:
321# * $1: protocol version in mbedtls syntax (argument to force_version=)
322requires_protocol_version() {
323    # Support for DTLS is detected separately in detect_dtls().
324    case "$1" in
325        tls12|dtls12) requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2;;
326        tls13|dtls13) requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3;;
327        *) echo "Unknown required protocol version: $1"; exit 1;;
328    esac
329}
330
331# Space-separated list of ciphersuites supported by this build of
332# Mbed TLS.
333P_CIPHERSUITES=" $($P_CLI --help 2>/dev/null |
334                   grep 'TLS-\|TLS1-3' |
335                   tr -s ' \n' ' ')"
336requires_ciphersuite_enabled() {
337    case $P_CIPHERSUITES in
338        *" $1 "*) :;;
339        *) SKIP_NEXT="YES";;
340    esac
341}
342
343# detect_required_features CMD [RUN_TEST_OPTION...]
344# If CMD (call to a TLS client or server program) requires certain features,
345# arrange to only run the following test case if those features are enabled.
346detect_required_features() {
347    case "$1" in
348        *\ force_version=*)
349            tmp="${1##*\ force_version=}"
350            tmp="${tmp%%[!-0-9A-Z_a-z]*}"
351            requires_protocol_version "$tmp";;
352    esac
353
354    case "$1" in
355        *\ force_ciphersuite=*)
356            tmp="${1##*\ force_ciphersuite=}"
357            tmp="${tmp%%[!-0-9A-Z_a-z]*}"
358            requires_ciphersuite_enabled "$tmp";;
359    esac
360
361    case " $1 " in
362        *[-_\ =]tickets=[^0]*)
363            requires_config_enabled MBEDTLS_SSL_TICKET_C;;
364    esac
365    case " $1 " in
366        *[-_\ =]alpn=*)
367            requires_config_enabled MBEDTLS_SSL_ALPN;;
368    esac
369
370    unset tmp
371}
372
373requires_certificate_authentication () {
374    if [ "$PSK_ONLY" = "YES" ]; then
375        SKIP_NEXT="YES"
376    fi
377}
378
379adapt_cmd_for_psk () {
380    case "$2" in
381        *openssl*) s='-psk abc123 -nocert';;
382        *gnutls-*) s='--pskkey=abc123';;
383        *) s='psk=abc123';;
384    esac
385    eval $1='"$2 $s"'
386    unset s
387}
388
389# maybe_adapt_for_psk [RUN_TEST_OPTION...]
390# If running in a PSK-only build, maybe adapt the test to use a pre-shared key.
391#
392# If not running in a PSK-only build, do nothing.
393# If the test looks like it doesn't use a pre-shared key but can run with a
394# pre-shared key, pass a pre-shared key. If the test looks like it can't run
395# with a pre-shared key, skip it. If the test looks like it's already using
396# a pre-shared key, do nothing.
397#
398# This code does not consider builds with ECDHE-PSK or RSA-PSK.
399#
400# Inputs:
401# * $CLI_CMD, $SRV_CMD, $PXY_CMD: client/server/proxy commands.
402# * $PSK_ONLY: YES if running in a PSK-only build (no asymmetric key exchanges).
403# * "$@": options passed to run_test.
404#
405# Outputs:
406# * $CLI_CMD, $SRV_CMD: may be modified to add PSK-relevant arguments.
407# * $SKIP_NEXT: set to YES if the test can't run with PSK.
408maybe_adapt_for_psk() {
409    if [ "$PSK_ONLY" != "YES" ]; then
410        return
411    fi
412    if [ "$SKIP_NEXT" = "YES" ]; then
413        return
414    fi
415    case "$CLI_CMD $SRV_CMD" in
416        *[-_\ =]psk*|*[-_\ =]PSK*)
417            return;;
418        *force_ciphersuite*)
419            # The test case forces a non-PSK cipher suite. In some cases, a
420            # PSK cipher suite could be substituted, but we're not ready for
421            # that yet.
422            SKIP_NEXT="YES"
423            return;;
424        *\ auth_mode=*|*[-_\ =]crt[_=]*)
425            # The test case involves certificates. PSK won't do.
426            SKIP_NEXT="YES"
427            return;;
428    esac
429    adapt_cmd_for_psk CLI_CMD "$CLI_CMD"
430    adapt_cmd_for_psk SRV_CMD "$SRV_CMD"
431}
432
433case " $CONFIGS_ENABLED " in
434    *\ MBEDTLS_KEY_EXCHANGE_[^P]*) PSK_ONLY="NO";;
435    *\ MBEDTLS_KEY_EXCHANGE_P[^S]*) PSK_ONLY="NO";;
436    *\ MBEDTLS_KEY_EXCHANGE_PS[^K]*) PSK_ONLY="NO";;
437    *\ MBEDTLS_KEY_EXCHANGE_PSK[^_]*) PSK_ONLY="NO";;
438    *\ MBEDTLS_KEY_EXCHANGE_PSK_ENABLED\ *) PSK_ONLY="YES";;
439    *) PSK_ONLY="NO";;
440esac
441
442HAS_ALG_SHA_1="NO"
443HAS_ALG_SHA_224="NO"
444HAS_ALG_SHA_256="NO"
445HAS_ALG_SHA_384="NO"
446HAS_ALG_SHA_512="NO"
447
448check_for_hash_alg()
449{
450    CURR_ALG="INVALID";
451    USE_PSA="NO"
452    case $CONFIGS_ENABLED in
453        *" MBEDTLS_USE_PSA_CRYPTO"[\ =]*)
454            USE_PSA="YES";
455        ;;
456        *) :;;
457    esac
458    if [ $USE_PSA = "YES" ]; then
459        CURR_ALG=PSA_WANT_ALG_${1}
460    else
461        CURR_ALG=MBEDTLS_${1}_C
462        # Remove the second underscore to match MBEDTLS_* naming convention
463        CURR_ALG=$(echo "$CURR_ALG" | sed 's/_//2')
464    fi
465
466    case $CONFIGS_ENABLED in
467        *" $CURR_ALG"[\ =]*)
468            return 0
469        ;;
470        *) :;;
471    esac
472    return 1
473}
474
475populate_enabled_hash_algs()
476{
477    for hash_alg in SHA_1 SHA_224 SHA_256 SHA_384 SHA_512; do
478        if check_for_hash_alg "$hash_alg"; then
479            hash_alg_variable=HAS_ALG_${hash_alg}
480            eval ${hash_alg_variable}=YES
481        fi
482    done
483}
484
485# skip next test if the given hash alg is not supported
486requires_hash_alg() {
487    HASH_DEFINE="Invalid"
488    HAS_HASH_ALG="NO"
489    case $1 in
490        SHA_1):;;
491        SHA_224):;;
492        SHA_256):;;
493        SHA_384):;;
494        SHA_512):;;
495      *)
496            echo "Unsupported hash alg - $1"
497            exit 1
498        ;;
499    esac
500
501    HASH_DEFINE=HAS_ALG_${1}
502    eval "HAS_HASH_ALG=\${${HASH_DEFINE}}"
503    if [ "$HAS_HASH_ALG" = "NO" ]
504    then
505        SKIP_NEXT="YES"
506    fi
507}
508
509# skip next test if OpenSSL doesn't support FALLBACK_SCSV
510requires_openssl_with_fallback_scsv() {
511    if [ -z "${OPENSSL_HAS_FBSCSV:-}" ]; then
512        if $OPENSSL_CMD s_client -help 2>&1 | grep fallback_scsv >/dev/null
513        then
514            OPENSSL_HAS_FBSCSV="YES"
515        else
516            OPENSSL_HAS_FBSCSV="NO"
517        fi
518    fi
519    if [ "$OPENSSL_HAS_FBSCSV" = "NO" ]; then
520        SKIP_NEXT="YES"
521    fi
522}
523
524# skip next test if either IN_CONTENT_LEN or MAX_CONTENT_LEN are below a value
525requires_max_content_len() {
526    requires_config_value_at_least "MBEDTLS_SSL_IN_CONTENT_LEN" $1
527    requires_config_value_at_least "MBEDTLS_SSL_OUT_CONTENT_LEN" $1
528}
529
530# skip next test if GnuTLS isn't available
531requires_gnutls() {
532    if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
533        if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null 2>&1; then
534            GNUTLS_AVAILABLE="YES"
535        else
536            GNUTLS_AVAILABLE="NO"
537        fi
538    fi
539    if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
540        SKIP_NEXT="YES"
541    fi
542}
543
544# skip next test if GnuTLS-next isn't available
545requires_gnutls_next() {
546    if [ -z "${GNUTLS_NEXT_AVAILABLE:-}" ]; then
547        if ( which "${GNUTLS_NEXT_CLI:-}" && which "${GNUTLS_NEXT_SERV:-}" ) >/dev/null 2>&1; then
548            GNUTLS_NEXT_AVAILABLE="YES"
549        else
550            GNUTLS_NEXT_AVAILABLE="NO"
551        fi
552    fi
553    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
554        SKIP_NEXT="YES"
555    fi
556}
557
558# skip next test if OpenSSL-legacy isn't available
559requires_openssl_legacy() {
560    if [ -z "${OPENSSL_LEGACY_AVAILABLE:-}" ]; then
561        if which "${OPENSSL_LEGACY:-}" >/dev/null 2>&1; then
562            OPENSSL_LEGACY_AVAILABLE="YES"
563        else
564            OPENSSL_LEGACY_AVAILABLE="NO"
565        fi
566    fi
567    if [ "$OPENSSL_LEGACY_AVAILABLE" = "NO" ]; then
568        SKIP_NEXT="YES"
569    fi
570}
571
572requires_openssl_next() {
573    if [ -z "${OPENSSL_NEXT_AVAILABLE:-}" ]; then
574        if which "${OPENSSL_NEXT:-}" >/dev/null 2>&1; then
575            OPENSSL_NEXT_AVAILABLE="YES"
576        else
577            OPENSSL_NEXT_AVAILABLE="NO"
578        fi
579    fi
580    if [ "$OPENSSL_NEXT_AVAILABLE" = "NO" ]; then
581        SKIP_NEXT="YES"
582    fi
583}
584
585# skip next test if tls1_3 is not available
586requires_openssl_tls1_3() {
587    requires_openssl_next
588    if [ "$OPENSSL_NEXT_AVAILABLE" = "NO" ]; then
589        OPENSSL_TLS1_3_AVAILABLE="NO"
590    fi
591    if [ -z "${OPENSSL_TLS1_3_AVAILABLE:-}" ]; then
592        if $OPENSSL_NEXT s_client -help 2>&1 | grep tls1_3 >/dev/null
593        then
594            OPENSSL_TLS1_3_AVAILABLE="YES"
595        else
596            OPENSSL_TLS1_3_AVAILABLE="NO"
597        fi
598    fi
599    if [ "$OPENSSL_TLS1_3_AVAILABLE" = "NO" ]; then
600        SKIP_NEXT="YES"
601    fi
602}
603
604# skip next test if tls1_3 is not available
605requires_gnutls_tls1_3() {
606    requires_gnutls_next
607    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
608        GNUTLS_TLS1_3_AVAILABLE="NO"
609    fi
610    if [ -z "${GNUTLS_TLS1_3_AVAILABLE:-}" ]; then
611        if $GNUTLS_NEXT_CLI -l 2>&1 | grep VERS-TLS1.3 >/dev/null
612        then
613            GNUTLS_TLS1_3_AVAILABLE="YES"
614        else
615            GNUTLS_TLS1_3_AVAILABLE="NO"
616        fi
617    fi
618    if [ "$GNUTLS_TLS1_3_AVAILABLE" = "NO" ]; then
619        SKIP_NEXT="YES"
620    fi
621}
622
623# Check %NO_TICKETS option
624requires_gnutls_next_no_ticket() {
625    requires_gnutls_next
626    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
627        GNUTLS_NO_TICKETS_AVAILABLE="NO"
628    fi
629    if [ -z "${GNUTLS_NO_TICKETS_AVAILABLE:-}" ]; then
630        if $GNUTLS_NEXT_CLI --priority-list 2>&1 | grep NO_TICKETS >/dev/null
631        then
632            GNUTLS_NO_TICKETS_AVAILABLE="YES"
633        else
634            GNUTLS_NO_TICKETS_AVAILABLE="NO"
635        fi
636    fi
637    if [ "$GNUTLS_NO_TICKETS_AVAILABLE" = "NO" ]; then
638        SKIP_NEXT="YES"
639    fi
640}
641
642# Check %DISABLE_TLS13_COMPAT_MODE option
643requires_gnutls_next_disable_tls13_compat() {
644    requires_gnutls_next
645    if [ "$GNUTLS_NEXT_AVAILABLE" = "NO" ]; then
646        GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="NO"
647    fi
648    if [ -z "${GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE:-}" ]; then
649        if $GNUTLS_NEXT_CLI --priority-list 2>&1 | grep DISABLE_TLS13_COMPAT_MODE >/dev/null
650        then
651            GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="YES"
652        else
653            GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE="NO"
654        fi
655    fi
656    if [ "$GNUTLS_DISABLE_TLS13_COMPAT_MODE_AVAILABLE" = "NO" ]; then
657        SKIP_NEXT="YES"
658    fi
659}
660
661# skip next test if IPv6 isn't available on this host
662requires_ipv6() {
663    if [ -z "${HAS_IPV6:-}" ]; then
664        $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
665        SRV_PID=$!
666        sleep 1
667        kill $SRV_PID >/dev/null 2>&1
668        if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
669            HAS_IPV6="NO"
670        else
671            HAS_IPV6="YES"
672        fi
673        rm -r $SRV_OUT
674    fi
675
676    if [ "$HAS_IPV6" = "NO" ]; then
677        SKIP_NEXT="YES"
678    fi
679}
680
681# skip next test if it's i686 or uname is not available
682requires_not_i686() {
683    if [ -z "${IS_I686:-}" ]; then
684        IS_I686="YES"
685        if which "uname" >/dev/null 2>&1; then
686            if [ -z "$(uname -a | grep i686)" ]; then
687                IS_I686="NO"
688            fi
689        fi
690    fi
691    if [ "$IS_I686" = "YES" ]; then
692        SKIP_NEXT="YES"
693    fi
694}
695
696# Calculate the input & output maximum content lengths set in the config
697MAX_CONTENT_LEN=16384
698MAX_IN_LEN=$( get_config_value_or_default "MBEDTLS_SSL_IN_CONTENT_LEN" )
699MAX_OUT_LEN=$( get_config_value_or_default "MBEDTLS_SSL_OUT_CONTENT_LEN" )
700
701# Calculate the maximum content length that fits both
702if [ "$MAX_IN_LEN" -lt "$MAX_CONTENT_LEN" ]; then
703    MAX_CONTENT_LEN="$MAX_IN_LEN"
704fi
705if [ "$MAX_OUT_LEN" -lt "$MAX_CONTENT_LEN" ]; then
706    MAX_CONTENT_LEN="$MAX_OUT_LEN"
707fi
708
709# skip the next test if the SSL output buffer is less than 16KB
710requires_full_size_output_buffer() {
711    if [ "$MAX_OUT_LEN" -ne 16384 ]; then
712        SKIP_NEXT="YES"
713    fi
714}
715
716# skip the next test if valgrind is in use
717not_with_valgrind() {
718    if [ "$MEMCHECK" -gt 0 ]; then
719        SKIP_NEXT="YES"
720    fi
721}
722
723# skip the next test if valgrind is NOT in use
724only_with_valgrind() {
725    if [ "$MEMCHECK" -eq 0 ]; then
726        SKIP_NEXT="YES"
727    fi
728}
729
730# multiply the client timeout delay by the given factor for the next test
731client_needs_more_time() {
732    CLI_DELAY_FACTOR=$1
733}
734
735# wait for the given seconds after the client finished in the next test
736server_needs_more_time() {
737    SRV_DELAY_SECONDS=$1
738}
739
740# print_name <name>
741print_name() {
742    TESTS=$(( $TESTS + 1 ))
743    LINE=""
744
745    if [ "$SHOW_TEST_NUMBER" -gt 0 ]; then
746        LINE="$TESTS "
747    fi
748
749    LINE="$LINE$1"
750    printf "%s " "$LINE"
751    LEN=$(( 72 - `echo "$LINE" | wc -c` ))
752    for i in `seq 1 $LEN`; do printf '.'; done
753    printf ' '
754
755}
756
757# record_outcome <outcome> [<failure-reason>]
758# The test name must be in $NAME.
759# Use $TEST_SUITE_NAME as the test suite name if set.
760record_outcome() {
761    echo "$1"
762    if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
763        printf '%s;%s;%s;%s;%s;%s\n' \
764               "$MBEDTLS_TEST_PLATFORM" "$MBEDTLS_TEST_CONFIGURATION" \
765               "${TEST_SUITE_NAME:-ssl-opt}" "$NAME" \
766               "$1" "${2-}" \
767               >>"$MBEDTLS_TEST_OUTCOME_FILE"
768    fi
769}
770unset TEST_SUITE_NAME
771
772# True if the presence of the given pattern in a log definitely indicates
773# that the test has failed. False if the presence is inconclusive.
774#
775# Inputs:
776# * $1: pattern found in the logs
777# * $TIMES_LEFT: >0 if retrying is an option
778#
779# Outputs:
780# * $outcome: set to a retry reason if the pattern is inconclusive,
781#             unchanged otherwise.
782# * Return value: 1 if the pattern is inconclusive,
783#                 0 if the failure is definitive.
784log_pattern_presence_is_conclusive() {
785    # If we've run out of attempts, then don't retry no matter what.
786    if [ $TIMES_LEFT -eq 0 ]; then
787        return 0
788    fi
789    case $1 in
790        "resend")
791            # An undesired resend may have been caused by the OS dropping or
792            # delaying a packet at an inopportune time.
793            outcome="RETRY(resend)"
794            return 1;;
795    esac
796}
797
798# fail <message>
799fail() {
800    record_outcome "FAIL" "$1"
801    echo "  ! $1"
802
803    mv $SRV_OUT o-srv-${TESTS}.log
804    mv $CLI_OUT o-cli-${TESTS}.log
805    if [ -n "$PXY_CMD" ]; then
806        mv $PXY_OUT o-pxy-${TESTS}.log
807    fi
808    echo "  ! outputs saved to o-XXX-${TESTS}.log"
809
810    if [ "${LOG_FAILURE_ON_STDOUT:-0}" != 0 ]; then
811        echo "  ! server output:"
812        cat o-srv-${TESTS}.log
813        echo "  ! ========================================================"
814        echo "  ! client output:"
815        cat o-cli-${TESTS}.log
816        if [ -n "$PXY_CMD" ]; then
817            echo "  ! ========================================================"
818            echo "  ! proxy output:"
819            cat o-pxy-${TESTS}.log
820        fi
821        echo ""
822    fi
823
824    FAILS=$(( $FAILS + 1 ))
825}
826
827# is_polar <cmd_line>
828is_polar() {
829    case "$1" in
830        *ssl_client2*) true;;
831        *ssl_server2*) true;;
832        *) false;;
833    esac
834}
835
836# openssl s_server doesn't have -www with DTLS
837check_osrv_dtls() {
838    case "$SRV_CMD" in
839        *s_server*-dtls*)
840            NEEDS_INPUT=1
841            SRV_CMD="$( echo $SRV_CMD | sed s/-www// )";;
842        *) NEEDS_INPUT=0;;
843    esac
844}
845
846# provide input to commands that need it
847provide_input() {
848    if [ $NEEDS_INPUT -eq 0 ]; then
849        return
850    fi
851
852    while true; do
853        echo "HTTP/1.0 200 OK"
854        sleep 1
855    done
856}
857
858# has_mem_err <log_file_name>
859has_mem_err() {
860    if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
861         grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
862    then
863        return 1 # false: does not have errors
864    else
865        return 0 # true: has errors
866    fi
867}
868
869# Wait for process $2 named $3 to be listening on port $1. Print error to $4.
870if type lsof >/dev/null 2>/dev/null; then
871    wait_app_start() {
872        newline='
873'
874        START_TIME=$(date +%s)
875        if [ "$DTLS" -eq 1 ]; then
876            proto=UDP
877        else
878            proto=TCP
879        fi
880        # Make a tight loop, server normally takes less than 1s to start.
881        while true; do
882              SERVER_PIDS=$(lsof -a -n -b -i "$proto:$1" -t)
883              # When we use a proxy, it will be listening on the same port we
884              # are checking for as well as the server and lsof will list both.
885             case ${newline}${SERVER_PIDS}${newline} in
886                  *${newline}${2}${newline}*) break;;
887              esac
888              if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then
889                  echo "$3 START TIMEOUT"
890                  echo "$3 START TIMEOUT" >> $4
891                  break
892              fi
893              # Linux and *BSD support decimal arguments to sleep. On other
894              # OSes this may be a tight loop.
895              sleep 0.1 2>/dev/null || true
896        done
897    }
898else
899    echo "Warning: lsof not available, wait_app_start = sleep"
900    wait_app_start() {
901        sleep "$START_DELAY"
902    }
903fi
904
905# Wait for server process $2 to be listening on port $1.
906wait_server_start() {
907    wait_app_start $1 $2 "SERVER" $SRV_OUT
908}
909
910# Wait for proxy process $2 to be listening on port $1.
911wait_proxy_start() {
912    wait_app_start $1 $2 "PROXY" $PXY_OUT
913}
914
915# Given the client or server debug output, parse the unix timestamp that is
916# included in the first 4 bytes of the random bytes and check that it's within
917# acceptable bounds
918check_server_hello_time() {
919    # Extract the time from the debug (lvl 3) output of the client
920    SERVER_HELLO_TIME="$(sed -n 's/.*server hello, current time: //p' < "$1")"
921    # Get the Unix timestamp for now
922    CUR_TIME=$(date +'%s')
923    THRESHOLD_IN_SECS=300
924
925    # Check if the ServerHello time was printed
926    if [ -z "$SERVER_HELLO_TIME" ]; then
927        return 1
928    fi
929
930    # Check the time in ServerHello is within acceptable bounds
931    if [ $SERVER_HELLO_TIME -lt $(( $CUR_TIME - $THRESHOLD_IN_SECS )) ]; then
932        # The time in ServerHello is at least 5 minutes before now
933        return 1
934    elif [ $SERVER_HELLO_TIME -gt $(( $CUR_TIME + $THRESHOLD_IN_SECS )) ]; then
935        # The time in ServerHello is at least 5 minutes later than now
936        return 1
937    else
938        return 0
939    fi
940}
941
942# Get handshake memory usage from server or client output and put it into the variable specified by the first argument
943handshake_memory_get() {
944    OUTPUT_VARIABLE="$1"
945    OUTPUT_FILE="$2"
946
947    # Get memory usage from a pattern like "Heap memory usage after handshake: 23112 bytes. Peak memory usage was 33112"
948    MEM_USAGE=$(sed -n 's/.*Heap memory usage after handshake: //p' < "$OUTPUT_FILE" | grep -o "[0-9]*" | head -1)
949
950    # Check if memory usage was read
951    if [ -z "$MEM_USAGE" ]; then
952        echo "Error: Can not read the value of handshake memory usage"
953        return 1
954    else
955        eval "$OUTPUT_VARIABLE=$MEM_USAGE"
956        return 0
957    fi
958}
959
960# Get handshake memory usage from server or client output and check if this value
961# is not higher than the maximum given by the first argument
962handshake_memory_check() {
963    MAX_MEMORY="$1"
964    OUTPUT_FILE="$2"
965
966    # Get memory usage
967    if ! handshake_memory_get "MEMORY_USAGE" "$OUTPUT_FILE"; then
968        return 1
969    fi
970
971    # Check if memory usage is below max value
972    if [ "$MEMORY_USAGE" -gt "$MAX_MEMORY" ]; then
973        echo "\nFailed: Handshake memory usage was $MEMORY_USAGE bytes," \
974             "but should be below $MAX_MEMORY bytes"
975        return 1
976    else
977        return 0
978    fi
979}
980
981# wait for client to terminate and set CLI_EXIT
982# must be called right after starting the client
983wait_client_done() {
984    CLI_PID=$!
985
986    CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
987    CLI_DELAY_FACTOR=1
988
989    ( sleep $CLI_DELAY; echo "===CLIENT_TIMEOUT===" >> $CLI_OUT; kill $CLI_PID ) &
990    DOG_PID=$!
991
992    # For Ubuntu 22.04, `Terminated` message is outputed by wait command.
993    # To remove it from stdout, redirect stdout/stderr to CLI_OUT
994    wait $CLI_PID >> $CLI_OUT 2>&1
995    CLI_EXIT=$?
996
997    kill $DOG_PID >/dev/null 2>&1
998    wait $DOG_PID >> $CLI_OUT 2>&1
999
1000    echo "EXIT: $CLI_EXIT" >> $CLI_OUT
1001
1002    sleep $SRV_DELAY_SECONDS
1003    SRV_DELAY_SECONDS=0
1004}
1005
1006# check if the given command uses dtls and sets global variable DTLS
1007detect_dtls() {
1008    case "$1" in
1009        *dtls=1*|*-dtls*|*-u*) DTLS=1;;
1010        *) DTLS=0;;
1011    esac
1012}
1013
1014# check if the given command uses gnutls and sets global variable CMD_IS_GNUTLS
1015is_gnutls() {
1016    case "$1" in
1017    *gnutls-cli*)
1018        CMD_IS_GNUTLS=1
1019        ;;
1020    *gnutls-serv*)
1021        CMD_IS_GNUTLS=1
1022        ;;
1023    *)
1024        CMD_IS_GNUTLS=0
1025        ;;
1026    esac
1027}
1028
1029# Generate random psk_list argument for ssl_server2
1030get_srv_psk_list ()
1031{
1032    case $(( TESTS % 3 )) in
1033        0) echo "psk_list=abc,dead,def,beef,Client_identity,6162636465666768696a6b6c6d6e6f70";;
1034        1) echo "psk_list=abc,dead,Client_identity,6162636465666768696a6b6c6d6e6f70,def,beef";;
1035        2) echo "psk_list=Client_identity,6162636465666768696a6b6c6d6e6f70,abc,dead,def,beef";;
1036    esac
1037}
1038
1039# Determine what calc_verify trace is to be expected, if any.
1040#
1041# calc_verify is only called for two things: to calculate the
1042# extended master secret, and to process client authentication.
1043#
1044# Warning: the current implementation assumes that extended_ms is not
1045#          disabled on the client or on the server.
1046#
1047# Inputs:
1048# * $1: the value of the server auth_mode parameter.
1049#       'required' if client authentication is expected,
1050#       'none' or absent if not.
1051# * $CONFIGS_ENABLED
1052#
1053# Outputs:
1054# * $maybe_calc_verify: set to a trace expected in the debug logs
1055set_maybe_calc_verify() {
1056    maybe_calc_verify=
1057    case $CONFIGS_ENABLED in
1058        *\ MBEDTLS_SSL_EXTENDED_MASTER_SECRET\ *) :;;
1059        *)
1060            case ${1-} in
1061                ''|none) return;;
1062                required) :;;
1063                *) echo "Bad parameter 1 to set_maybe_calc_verify: $1"; exit 1;;
1064            esac
1065    esac
1066    case $CONFIGS_ENABLED in
1067        *\ MBEDTLS_USE_PSA_CRYPTO\ *) maybe_calc_verify="PSA calc verify";;
1068        *) maybe_calc_verify="<= calc verify";;
1069    esac
1070}
1071
1072# Compare file content
1073# Usage: find_in_both pattern file1 file2
1074# extract from file1 the first line matching the pattern
1075# check in file2 that the same line can be found
1076find_in_both() {
1077        srv_pattern=$(grep -m 1 "$1" "$2");
1078        if [ -z "$srv_pattern" ]; then
1079                return 1;
1080        fi
1081
1082        if grep "$srv_pattern" $3 >/dev/null; then :
1083                return 0;
1084        else
1085                return 1;
1086        fi
1087}
1088
1089SKIP_HANDSHAKE_CHECK="NO"
1090skip_handshake_stage_check() {
1091    SKIP_HANDSHAKE_CHECK="YES"
1092}
1093
1094# Analyze the commands that will be used in a test.
1095#
1096# Analyze and possibly instrument $PXY_CMD, $CLI_CMD, $SRV_CMD to pass
1097# extra arguments or go through wrappers.
1098#
1099# Inputs:
1100# * $@: supplemental options to run_test() (after the mandatory arguments).
1101# * $CLI_CMD, $PXY_CMD, $SRV_CMD: the client, proxy and server commands.
1102# * $DTLS: 1 if DTLS, otherwise 0.
1103#
1104# Outputs:
1105# * $CLI_CMD, $PXY_CMD, $SRV_CMD: may be tweaked.
1106analyze_test_commands() {
1107    # if the test uses DTLS but no custom proxy, add a simple proxy
1108    # as it provides timing info that's useful to debug failures
1109    if [ -z "$PXY_CMD" ] && [ "$DTLS" -eq 1 ]; then
1110        PXY_CMD="$P_PXY"
1111        case " $SRV_CMD " in
1112            *' server_addr=::1 '*)
1113                PXY_CMD="$PXY_CMD server_addr=::1 listen_addr=::1";;
1114        esac
1115    fi
1116
1117    # update CMD_IS_GNUTLS variable
1118    is_gnutls "$SRV_CMD"
1119
1120    # if the server uses gnutls but doesn't set priority, explicitly
1121    # set the default priority
1122    if [ "$CMD_IS_GNUTLS" -eq 1 ]; then
1123        case "$SRV_CMD" in
1124              *--priority*) :;;
1125              *) SRV_CMD="$SRV_CMD --priority=NORMAL";;
1126        esac
1127    fi
1128
1129    # update CMD_IS_GNUTLS variable
1130    is_gnutls "$CLI_CMD"
1131
1132    # if the client uses gnutls but doesn't set priority, explicitly
1133    # set the default priority
1134    if [ "$CMD_IS_GNUTLS" -eq 1 ]; then
1135        case "$CLI_CMD" in
1136              *--priority*) :;;
1137              *) CLI_CMD="$CLI_CMD --priority=NORMAL";;
1138        esac
1139    fi
1140
1141    # fix client port
1142    if [ -n "$PXY_CMD" ]; then
1143        CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
1144    else
1145        CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
1146    fi
1147
1148    # prepend valgrind to our commands if active
1149    if [ "$MEMCHECK" -gt 0 ]; then
1150        if is_polar "$SRV_CMD"; then
1151            SRV_CMD="valgrind --leak-check=full $SRV_CMD"
1152        fi
1153        if is_polar "$CLI_CMD"; then
1154            CLI_CMD="valgrind --leak-check=full $CLI_CMD"
1155        fi
1156    fi
1157}
1158
1159# Check for failure conditions after a test case.
1160#
1161# Inputs from run_test:
1162# * positional parameters: test options (see run_test documentation)
1163# * $CLI_EXIT: client return code
1164# * $CLI_EXPECT: expected client return code
1165# * $SRV_RET: server return code
1166# * $CLI_OUT, $SRV_OUT, $PXY_OUT: files containing client/server/proxy logs
1167# * $TIMES_LEFT: if nonzero, a RETRY outcome is allowed
1168#
1169# Outputs:
1170# * $outcome: one of PASS/RETRY*/FAIL
1171check_test_failure() {
1172    outcome=FAIL
1173
1174    if [ $TIMES_LEFT -gt 0 ] &&
1175       grep '===CLIENT_TIMEOUT===' $CLI_OUT >/dev/null
1176    then
1177        outcome="RETRY(client-timeout)"
1178        return
1179    fi
1180
1181    # check if the client and server went at least to the handshake stage
1182    # (useful to avoid tests with only negative assertions and non-zero
1183    # expected client exit to incorrectly succeed in case of catastrophic
1184    # failure)
1185    if [ "X$SKIP_HANDSHAKE_CHECK" != "XYES" ]
1186    then
1187        if is_polar "$SRV_CMD"; then
1188            if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
1189            else
1190                fail "server or client failed to reach handshake stage"
1191                return
1192            fi
1193        fi
1194        if is_polar "$CLI_CMD"; then
1195            if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
1196            else
1197                fail "server or client failed to reach handshake stage"
1198                return
1199            fi
1200        fi
1201    fi
1202
1203    SKIP_HANDSHAKE_CHECK="NO"
1204    # Check server exit code (only for Mbed TLS: GnuTLS and OpenSSL don't
1205    # exit with status 0 when interrupted by a signal, and we don't really
1206    # care anyway), in case e.g. the server reports a memory leak.
1207    if [ $SRV_RET != 0 ] && is_polar "$SRV_CMD"; then
1208        fail "Server exited with status $SRV_RET"
1209        return
1210    fi
1211
1212    # check client exit code
1213    if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
1214         \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
1215    then
1216        fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
1217        return
1218    fi
1219
1220    # check other assertions
1221    # lines beginning with == are added by valgrind, ignore them
1222    # lines with 'Serious error when reading debug info', are valgrind issues as well
1223    while [ $# -gt 0 ]
1224    do
1225        case $1 in
1226            "-s")
1227                if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
1228                    fail "pattern '$2' MUST be present in the Server output"
1229                    return
1230                fi
1231                ;;
1232
1233            "-c")
1234                if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
1235                    fail "pattern '$2' MUST be present in the Client output"
1236                    return
1237                fi
1238                ;;
1239
1240            "-S")
1241                if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
1242                    if log_pattern_presence_is_conclusive "$2"; then
1243                        fail "pattern '$2' MUST NOT be present in the Server output"
1244                    fi
1245                    return
1246                fi
1247                ;;
1248
1249            "-C")
1250                if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
1251                    if log_pattern_presence_is_conclusive "$2"; then
1252                        fail "pattern '$2' MUST NOT be present in the Client output"
1253                    fi
1254                    return
1255                fi
1256                ;;
1257
1258                # The filtering in the following two options (-u and -U) do the following
1259                #   - ignore valgrind output
1260                #   - filter out everything but lines right after the pattern occurrences
1261                #   - keep one of each non-unique line
1262                #   - count how many lines remain
1263                # A line with '--' will remain in the result from previous outputs, so the number of lines in the result will be 1
1264                # if there were no duplicates.
1265            "-U")
1266                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
1267                    fail "lines following pattern '$2' must be unique in Server output"
1268                    return
1269                fi
1270                ;;
1271
1272            "-u")
1273                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
1274                    fail "lines following pattern '$2' must be unique in Client output"
1275                    return
1276                fi
1277                ;;
1278            "-F")
1279                if ! $2 "$SRV_OUT"; then
1280                    fail "function call to '$2' failed on Server output"
1281                    return
1282                fi
1283                ;;
1284            "-f")
1285                if ! $2 "$CLI_OUT"; then
1286                    fail "function call to '$2' failed on Client output"
1287                    return
1288                fi
1289                ;;
1290            "-g")
1291                if ! eval "$2 '$SRV_OUT' '$CLI_OUT'"; then
1292                    fail "function call to '$2' failed on Server and Client output"
1293                    return
1294                fi
1295                ;;
1296
1297            *)
1298                echo "Unknown test: $1" >&2
1299                exit 1
1300        esac
1301        shift 2
1302    done
1303
1304    # check valgrind's results
1305    if [ "$MEMCHECK" -gt 0 ]; then
1306        if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
1307            fail "Server has memory errors"
1308            return
1309        fi
1310        if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
1311            fail "Client has memory errors"
1312            return
1313        fi
1314    fi
1315
1316    # if we're here, everything is ok
1317    outcome=PASS
1318}
1319
1320# Run the current test case: start the server and if applicable the proxy, run
1321# the client, wait for all processes to finish or time out.
1322#
1323# Inputs:
1324# * $NAME: test case name
1325# * $CLI_CMD, $SRV_CMD, $PXY_CMD: commands to run
1326# * $CLI_OUT, $SRV_OUT, $PXY_OUT: files to contain client/server/proxy logs
1327#
1328# Outputs:
1329# * $CLI_EXIT: client return code
1330# * $SRV_RET: server return code
1331do_run_test_once() {
1332    # run the commands
1333    if [ -n "$PXY_CMD" ]; then
1334        printf "# %s\n%s\n" "$NAME" "$PXY_CMD" > $PXY_OUT
1335        $PXY_CMD >> $PXY_OUT 2>&1 &
1336        PXY_PID=$!
1337        wait_proxy_start "$PXY_PORT" "$PXY_PID"
1338    fi
1339
1340    check_osrv_dtls
1341    printf '# %s\n%s\n' "$NAME" "$SRV_CMD" > $SRV_OUT
1342    provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
1343    SRV_PID=$!
1344    wait_server_start "$SRV_PORT" "$SRV_PID"
1345
1346    printf '# %s\n%s\n' "$NAME" "$CLI_CMD" > $CLI_OUT
1347    # The client must be a subprocess of the script in order for killing it to
1348    # work properly, that's why the ampersand is placed inside the eval command,
1349    # not at the end of the line: the latter approach will spawn eval as a
1350    # subprocess, and the $CLI_CMD as a grandchild.
1351    eval "$CLI_CMD &" >> $CLI_OUT 2>&1
1352    wait_client_done
1353
1354    sleep 0.05
1355
1356    # terminate the server (and the proxy)
1357    kill $SRV_PID
1358    # For Ubuntu 22.04, `Terminated` message is outputed by wait command.
1359    # To remove it from stdout, redirect stdout/stderr to SRV_OUT
1360    wait $SRV_PID >> $SRV_OUT 2>&1
1361    SRV_RET=$?
1362
1363    if [ -n "$PXY_CMD" ]; then
1364        kill $PXY_PID >/dev/null 2>&1
1365        wait $PXY_PID >> $PXY_OUT 2>&1
1366    fi
1367}
1368
1369# Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
1370# Options:  -s pattern  pattern that must be present in server output
1371#           -c pattern  pattern that must be present in client output
1372#           -u pattern  lines after pattern must be unique in client output
1373#           -f call shell function on client output
1374#           -S pattern  pattern that must be absent in server output
1375#           -C pattern  pattern that must be absent in client output
1376#           -U pattern  lines after pattern must be unique in server output
1377#           -F call shell function on server output
1378#           -g call shell function on server and client output
1379run_test() {
1380    NAME="$1"
1381    shift 1
1382
1383    if is_excluded "$NAME"; then
1384        SKIP_NEXT="NO"
1385        # There was no request to run the test, so don't record its outcome.
1386        return
1387    fi
1388
1389    print_name "$NAME"
1390
1391    # Do we only run numbered tests?
1392    if [ -n "$RUN_TEST_NUMBER" ]; then
1393        case ",$RUN_TEST_NUMBER," in
1394            *",$TESTS,"*) :;;
1395            *) SKIP_NEXT="YES";;
1396        esac
1397    fi
1398
1399    # does this test use a proxy?
1400    if [ "X$1" = "X-p" ]; then
1401        PXY_CMD="$2"
1402        shift 2
1403    else
1404        PXY_CMD=""
1405    fi
1406
1407    # get commands and client output
1408    SRV_CMD="$1"
1409    CLI_CMD="$2"
1410    CLI_EXPECT="$3"
1411    shift 3
1412
1413    # Check if test uses files
1414    case "$SRV_CMD $CLI_CMD" in
1415        *data_files/*)
1416            requires_config_enabled MBEDTLS_FS_IO;;
1417    esac
1418
1419    # Check if the test uses DTLS.
1420    detect_dtls "$SRV_CMD"
1421    if [ "$DTLS" -eq 1 ]; then
1422        requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
1423    fi
1424
1425    # If the client or server requires certain features that can be detected
1426    # from their command-line arguments, check that they're enabled.
1427    detect_required_features "$SRV_CMD" "$@"
1428    detect_required_features "$CLI_CMD" "$@"
1429
1430    # If we're in a PSK-only build and the test can be adapted to PSK, do that.
1431    maybe_adapt_for_psk "$@"
1432
1433    # should we skip?
1434    if [ "X$SKIP_NEXT" = "XYES" ]; then
1435        SKIP_NEXT="NO"
1436        record_outcome "SKIP"
1437        SKIPS=$(( $SKIPS + 1 ))
1438        return
1439    fi
1440
1441    analyze_test_commands "$@"
1442
1443    # One regular run and two retries
1444    TIMES_LEFT=3
1445    while [ $TIMES_LEFT -gt 0 ]; do
1446        TIMES_LEFT=$(( $TIMES_LEFT - 1 ))
1447
1448        do_run_test_once
1449
1450        check_test_failure "$@"
1451        case $outcome in
1452            PASS) break;;
1453            RETRY*) printf "$outcome ";;
1454            FAIL) return;;
1455        esac
1456    done
1457
1458    # If we get this far, the test case passed.
1459    record_outcome "PASS"
1460    if [ "$PRESERVE_LOGS" -gt 0 ]; then
1461        mv $SRV_OUT o-srv-${TESTS}.log
1462        mv $CLI_OUT o-cli-${TESTS}.log
1463        if [ -n "$PXY_CMD" ]; then
1464            mv $PXY_OUT o-pxy-${TESTS}.log
1465        fi
1466    fi
1467
1468    rm -f $SRV_OUT $CLI_OUT $PXY_OUT
1469}
1470
1471run_test_psa() {
1472    requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1473    set_maybe_calc_verify none
1474    run_test    "PSA-supported ciphersuite: $1" \
1475                "$P_SRV debug_level=3 force_version=tls12" \
1476                "$P_CLI debug_level=3 force_ciphersuite=$1" \
1477                0 \
1478                -c "$maybe_calc_verify" \
1479                -c "calc PSA finished" \
1480                -s "$maybe_calc_verify" \
1481                -s "calc PSA finished" \
1482                -s "Protocol is TLSv1.2" \
1483                -c "Perform PSA-based ECDH computation."\
1484                -c "Perform PSA-based computation of digest of ServerKeyExchange" \
1485                -S "error" \
1486                -C "error"
1487    unset maybe_calc_verify
1488}
1489
1490run_test_psa_force_curve() {
1491    requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1492    set_maybe_calc_verify none
1493    run_test    "PSA - ECDH with $1" \
1494                "$P_SRV debug_level=4 force_version=tls12 curves=$1" \
1495                "$P_CLI debug_level=4 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 curves=$1" \
1496                0 \
1497                -c "$maybe_calc_verify" \
1498                -c "calc PSA finished" \
1499                -s "$maybe_calc_verify" \
1500                -s "calc PSA finished" \
1501                -s "Protocol is TLSv1.2" \
1502                -c "Perform PSA-based ECDH computation."\
1503                -c "Perform PSA-based computation of digest of ServerKeyExchange" \
1504                -S "error" \
1505                -C "error"
1506    unset maybe_calc_verify
1507}
1508
1509# Test that the server's memory usage after a handshake is reduced when a client specifies
1510# a maximum fragment length.
1511#  first argument ($1) is MFL for SSL client
1512#  second argument ($2) is memory usage for SSL client with default MFL (16k)
1513run_test_memory_after_hanshake_with_mfl()
1514{
1515    # The test passes if the difference is around 2*(16k-MFL)
1516    MEMORY_USAGE_LIMIT="$(( $2 - ( 2 * ( 16384 - $1 )) ))"
1517
1518    # Leave some margin for robustness
1519    MEMORY_USAGE_LIMIT="$(( ( MEMORY_USAGE_LIMIT * 110 ) / 100 ))"
1520
1521    run_test    "Handshake memory usage (MFL $1)" \
1522                "$P_SRV debug_level=3 auth_mode=required force_version=tls12" \
1523                "$P_CLI debug_level=3 \
1524                    crt_file=data_files/server5.crt key_file=data_files/server5.key \
1525                    force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM max_frag_len=$1" \
1526                0 \
1527                -F "handshake_memory_check $MEMORY_USAGE_LIMIT"
1528}
1529
1530
1531# Test that the server's memory usage after a handshake is reduced when a client specifies
1532# different values of Maximum Fragment Length: default (16k), 4k, 2k, 1k and 512 bytes
1533run_tests_memory_after_hanshake()
1534{
1535    # all tests in this sequence requires the same configuration (see requires_config_enabled())
1536    SKIP_THIS_TESTS="$SKIP_NEXT"
1537
1538    # first test with default MFU is to get reference memory usage
1539    MEMORY_USAGE_MFL_16K=0
1540    run_test    "Handshake memory usage initial (MFL 16384 - default)" \
1541                "$P_SRV debug_level=3 auth_mode=required force_version=tls12" \
1542                "$P_CLI debug_level=3 \
1543                    crt_file=data_files/server5.crt key_file=data_files/server5.key \
1544                    force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM" \
1545                0 \
1546                -F "handshake_memory_get MEMORY_USAGE_MFL_16K"
1547
1548    SKIP_NEXT="$SKIP_THIS_TESTS"
1549    run_test_memory_after_hanshake_with_mfl 4096 "$MEMORY_USAGE_MFL_16K"
1550
1551    SKIP_NEXT="$SKIP_THIS_TESTS"
1552    run_test_memory_after_hanshake_with_mfl 2048 "$MEMORY_USAGE_MFL_16K"
1553
1554    SKIP_NEXT="$SKIP_THIS_TESTS"
1555    run_test_memory_after_hanshake_with_mfl 1024 "$MEMORY_USAGE_MFL_16K"
1556
1557    SKIP_NEXT="$SKIP_THIS_TESTS"
1558    run_test_memory_after_hanshake_with_mfl 512 "$MEMORY_USAGE_MFL_16K"
1559}
1560
1561cleanup() {
1562    rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
1563    rm -f context_srv.txt
1564    rm -f context_cli.txt
1565    test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
1566    test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
1567    test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
1568    test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
1569    exit 1
1570}
1571
1572#
1573# MAIN
1574#
1575
1576get_options "$@"
1577
1578populate_enabled_hash_algs
1579
1580# Optimize filters: if $FILTER and $EXCLUDE can be expressed as shell
1581# patterns rather than regular expressions, use a case statement instead
1582# of calling grep. To keep the optimizer simple, it is incomplete and only
1583# detects simple cases: plain substring, everything, nothing.
1584#
1585# As an exception, the character '.' is treated as an ordinary character
1586# if it is the only special character in the string. This is because it's
1587# rare to need "any one character", but needing a literal '.' is common
1588# (e.g. '-f "DTLS 1.2"').
1589need_grep=
1590case "$FILTER" in
1591    '^$') simple_filter=;;
1592    '.*') simple_filter='*';;
1593    *[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
1594        need_grep=1;;
1595    *) # No regexp or shell-pattern special character
1596        simple_filter="*$FILTER*";;
1597esac
1598case "$EXCLUDE" in
1599    '^$') simple_exclude=;;
1600    '.*') simple_exclude='*';;
1601    *[][$+*?\\^{\|}]*) # Regexp special characters (other than .), we need grep
1602        need_grep=1;;
1603    *) # No regexp or shell-pattern special character
1604        simple_exclude="*$EXCLUDE*";;
1605esac
1606if [ -n "$need_grep" ]; then
1607    is_excluded () {
1608        ! echo "$1" | grep "$FILTER" | grep -q -v "$EXCLUDE"
1609    }
1610else
1611    is_excluded () {
1612        case "$1" in
1613            $simple_exclude) true;;
1614            $simple_filter) false;;
1615            *) true;;
1616        esac
1617    }
1618fi
1619
1620# sanity checks, avoid an avalanche of errors
1621P_SRV_BIN="${P_SRV%%[  ]*}"
1622P_CLI_BIN="${P_CLI%%[  ]*}"
1623P_PXY_BIN="${P_PXY%%[  ]*}"
1624if [ ! -x "$P_SRV_BIN" ]; then
1625    echo "Command '$P_SRV_BIN' is not an executable file"
1626    exit 1
1627fi
1628if [ ! -x "$P_CLI_BIN" ]; then
1629    echo "Command '$P_CLI_BIN' is not an executable file"
1630    exit 1
1631fi
1632if [ ! -x "$P_PXY_BIN" ]; then
1633    echo "Command '$P_PXY_BIN' is not an executable file"
1634    exit 1
1635fi
1636if [ "$MEMCHECK" -gt 0 ]; then
1637    if which valgrind >/dev/null 2>&1; then :; else
1638        echo "Memcheck not possible. Valgrind not found"
1639        exit 1
1640    fi
1641fi
1642if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
1643    echo "Command '$OPENSSL_CMD' not found"
1644    exit 1
1645fi
1646
1647# used by watchdog
1648MAIN_PID="$$"
1649
1650# We use somewhat arbitrary delays for tests:
1651# - how long do we wait for the server to start (when lsof not available)?
1652# - how long do we allow for the client to finish?
1653#   (not to check performance, just to avoid waiting indefinitely)
1654# Things are slower with valgrind, so give extra time here.
1655#
1656# Note: without lsof, there is a trade-off between the running time of this
1657# script and the risk of spurious errors because we didn't wait long enough.
1658# The watchdog delay on the other hand doesn't affect normal running time of
1659# the script, only the case where a client or server gets stuck.
1660if [ "$MEMCHECK" -gt 0 ]; then
1661    START_DELAY=6
1662    DOG_DELAY=60
1663else
1664    START_DELAY=2
1665    DOG_DELAY=20
1666fi
1667
1668# some particular tests need more time:
1669# - for the client, we multiply the usual watchdog limit by a factor
1670# - for the server, we sleep for a number of seconds after the client exits
1671# see client_need_more_time() and server_needs_more_time()
1672CLI_DELAY_FACTOR=1
1673SRV_DELAY_SECONDS=0
1674
1675# fix commands to use this port, force IPv4 while at it
1676# +SRV_PORT will be replaced by either $SRV_PORT or $PXY_PORT later
1677# Note: Using 'localhost' rather than 127.0.0.1 here is unwise, as on many
1678# machines that will resolve to ::1, and we don't want ipv6 here.
1679P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
1680P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
1681P_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"}"
1682O_SRV="$O_SRV -accept $SRV_PORT"
1683O_CLI="$O_CLI -connect 127.0.0.1:+SRV_PORT"
1684G_SRV="$G_SRV -p $SRV_PORT"
1685G_CLI="$G_CLI -p +SRV_PORT"
1686
1687if [ -n "${OPENSSL_LEGACY:-}" ]; then
1688    O_LEGACY_SRV="$O_LEGACY_SRV -accept $SRV_PORT -dhparam data_files/dhparams.pem"
1689    O_LEGACY_CLI="$O_LEGACY_CLI -connect 127.0.0.1:+SRV_PORT"
1690fi
1691
1692# Newer versions of OpenSSL have a syntax to enable all "ciphers", even
1693# low-security ones. This covers not just cipher suites but also protocol
1694# versions. It is necessary, for example, to use (D)TLS 1.0/1.1 on
1695# OpenSSL 1.1.1f from Ubuntu 20.04. The syntax was only introduced in
1696# OpenSSL 1.1.0 (21e0c1d23afff48601eb93135defddae51f7e2e3) and I can't find
1697# a way to discover it from -help, so check the openssl version.
1698case $($OPENSSL_CMD version) in
1699    "OpenSSL 0"*|"OpenSSL 1.0"*) :;;
1700    *)
1701        O_CLI="$O_CLI -cipher ALL@SECLEVEL=0"
1702        O_SRV="$O_SRV -cipher ALL@SECLEVEL=0"
1703        ;;
1704esac
1705
1706if [ -n "${OPENSSL_NEXT:-}" ]; then
1707    O_NEXT_SRV="$O_NEXT_SRV -accept $SRV_PORT"
1708    O_NEXT_SRV_NO_CERT="$O_NEXT_SRV_NO_CERT -accept $SRV_PORT"
1709    O_NEXT_SRV_EARLY_DATA="$O_NEXT_SRV_EARLY_DATA -accept $SRV_PORT"
1710    O_NEXT_CLI="$O_NEXT_CLI -connect 127.0.0.1:+SRV_PORT"
1711    O_NEXT_CLI_NO_CERT="$O_NEXT_CLI_NO_CERT -connect 127.0.0.1:+SRV_PORT"
1712fi
1713
1714if [ -n "${GNUTLS_NEXT_SERV:-}" ]; then
1715    G_NEXT_SRV="$G_NEXT_SRV -p $SRV_PORT"
1716    G_NEXT_SRV_NO_CERT="$G_NEXT_SRV_NO_CERT -p $SRV_PORT"
1717fi
1718
1719if [ -n "${GNUTLS_NEXT_CLI:-}" ]; then
1720    G_NEXT_CLI="$G_NEXT_CLI -p +SRV_PORT"
1721    G_NEXT_CLI_NO_CERT="$G_NEXT_CLI_NO_CERT -p +SRV_PORT localhost"
1722fi
1723
1724# Allow SHA-1, because many of our test certificates use it
1725P_SRV="$P_SRV allow_sha1=1"
1726P_CLI="$P_CLI allow_sha1=1"
1727
1728# Also pick a unique name for intermediate files
1729SRV_OUT="srv_out.$$"
1730CLI_OUT="cli_out.$$"
1731PXY_OUT="pxy_out.$$"
1732SESSION="session.$$"
1733
1734SKIP_NEXT="NO"
1735
1736trap cleanup INT TERM HUP
1737
1738# Basic test
1739
1740# Checks that:
1741# - things work with all ciphersuites active (used with config-full in all.sh)
1742# - the expected parameters are selected
1743requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1744requires_ciphersuite_enabled TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256
1745requires_hash_alg SHA_512 # "signature_algorithm ext: 6"
1746requires_config_enabled MBEDTLS_ECP_DP_CURVE25519_ENABLED
1747run_test    "Default" \
1748            "$P_SRV debug_level=3" \
1749            "$P_CLI" \
1750            0 \
1751            -s "Protocol is TLSv1.2" \
1752            -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256" \
1753            -s "client hello v3, signature_algorithm ext: 6" \
1754            -s "ECDHE curve: x25519" \
1755            -S "error" \
1756            -C "error"
1757
1758requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1759requires_ciphersuite_enabled TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256
1760run_test    "Default, DTLS" \
1761            "$P_SRV dtls=1" \
1762            "$P_CLI dtls=1" \
1763            0 \
1764            -s "Protocol is DTLSv1.2" \
1765            -s "Ciphersuite is TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256"
1766
1767requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1768run_test    "TLS client auth: required" \
1769            "$P_SRV auth_mode=required" \
1770            "$P_CLI" \
1771            0 \
1772            -s "Verifying peer X.509 certificate... ok"
1773
1774requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1775run_test    "key size: TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
1776            "$P_SRV" \
1777            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
1778            0 \
1779            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
1780            -c "Key size is 256"
1781
1782requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1783run_test    "key size: TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
1784            "$P_SRV" \
1785            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
1786            0 \
1787            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
1788            -c "Key size is 128"
1789
1790requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1791requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1792requires_config_enabled MBEDTLS_ECDSA_C
1793requires_hash_alg SHA_256
1794run_test    "TLS: password protected client key" \
1795            "$P_SRV auth_mode=required" \
1796            "$P_CLI crt_file=data_files/server5.crt key_file=data_files/server5.key.enc key_pwd=PolarSSLTest" \
1797            0
1798
1799requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1800requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1801requires_config_enabled MBEDTLS_ECDSA_C
1802requires_hash_alg SHA_256
1803run_test    "TLS: password protected server key" \
1804            "$P_SRV crt_file=data_files/server5.crt key_file=data_files/server5.key.enc key_pwd=PolarSSLTest" \
1805            "$P_CLI" \
1806            0
1807
1808requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1809requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1810requires_config_enabled MBEDTLS_ECDSA_C
1811requires_config_enabled MBEDTLS_RSA_C
1812requires_hash_alg SHA_256
1813run_test    "TLS: password protected server key, two certificates" \
1814            "$P_SRV \
1815              key_file=data_files/server5.key.enc key_pwd=PolarSSLTest crt_file=data_files/server5.crt \
1816              key_file2=data_files/server2.key.enc key_pwd2=PolarSSLTest crt_file2=data_files/server2.crt" \
1817            "$P_CLI" \
1818            0
1819
1820requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1821requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1822run_test    "CA callback on client" \
1823            "$P_SRV debug_level=3" \
1824            "$P_CLI ca_callback=1 debug_level=3 " \
1825            0 \
1826            -c "use CA callback for X.509 CRT verification" \
1827            -S "error" \
1828            -C "error"
1829
1830requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1831requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1832requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1833requires_config_enabled MBEDTLS_ECDSA_C
1834requires_hash_alg SHA_256
1835run_test    "CA callback on server" \
1836            "$P_SRV auth_mode=required" \
1837            "$P_CLI ca_callback=1 debug_level=3 crt_file=data_files/server5.crt \
1838             key_file=data_files/server5.key" \
1839            0 \
1840            -c "use CA callback for X.509 CRT verification" \
1841            -s "Verifying peer X.509 certificate... ok" \
1842            -S "error" \
1843            -C "error"
1844
1845# Test using an EC opaque private key for client authentication
1846requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1847requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1848requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1849requires_config_enabled MBEDTLS_ECDSA_C
1850requires_hash_alg SHA_256
1851run_test    "Opaque key for client authentication: ECDHE-ECDSA" \
1852            "$P_SRV auth_mode=required crt_file=data_files/server5.crt \
1853             key_file=data_files/server5.key" \
1854            "$P_CLI key_opaque=1 crt_file=data_files/server5.crt \
1855             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
1856            0 \
1857            -c "key type: Opaque" \
1858            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
1859            -s "Verifying peer X.509 certificate... ok" \
1860            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
1861            -S "error" \
1862            -C "error"
1863
1864# Test using a RSA opaque private key for client authentication
1865requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1866requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1867requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1868requires_config_enabled MBEDTLS_ECDSA_C
1869requires_config_enabled MBEDTLS_RSA_C
1870requires_hash_alg SHA_256
1871run_test    "Opaque key for client authentication: ECDHE-RSA" \
1872            "$P_SRV auth_mode=required crt_file=data_files/server2-sha256.crt \
1873             key_file=data_files/server2.key" \
1874            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
1875             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
1876            0 \
1877            -c "key type: Opaque" \
1878            -c "Ciphersuite is TLS-ECDHE-RSA" \
1879            -s "Verifying peer X.509 certificate... ok" \
1880            -s "Ciphersuite is TLS-ECDHE-RSA" \
1881            -S "error" \
1882            -C "error"
1883
1884requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1885requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1886requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1887requires_config_enabled MBEDTLS_RSA_C
1888requires_hash_alg SHA_256
1889run_test    "Opaque key for client authentication: DHE-RSA" \
1890            "$P_SRV auth_mode=required crt_file=data_files/server2-sha256.crt \
1891             key_file=data_files/server2.key" \
1892            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
1893             key_file=data_files/server2.key force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
1894             key_opaque_algs=rsa-sign-pkcs1,none" \
1895            0 \
1896            -c "key type: Opaque" \
1897            -c "Ciphersuite is TLS-DHE-RSA" \
1898            -s "Verifying peer X.509 certificate... ok" \
1899            -s "Ciphersuite is TLS-DHE-RSA" \
1900            -S "error" \
1901            -C "error"
1902
1903# Test using an EC opaque private key for server authentication
1904requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1905requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1906requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1907requires_config_enabled MBEDTLS_ECDSA_C
1908requires_hash_alg SHA_256
1909run_test    "Opaque key for server authentication: ECDHE-ECDSA" \
1910            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
1911             key_file=data_files/server5.key  key_opaque_algs=ecdsa-sign,none" \
1912            "$P_CLI" \
1913            0 \
1914            -c "Verifying peer X.509 certificate... ok" \
1915            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
1916            -s "key types: Opaque, none" \
1917            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
1918            -S "error" \
1919            -C "error"
1920
1921requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1922requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1923requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1924requires_config_enabled MBEDTLS_ECDSA_C
1925requires_hash_alg SHA_256
1926run_test    "Opaque key for server authentication: ECDH-" \
1927            "$P_SRV force_version=tls12 auth_mode=required key_opaque=1\
1928             crt_file=data_files/server5.ku-ka.crt\
1929             key_file=data_files/server5.key key_opaque_algs=ecdh,none" \
1930            "$P_CLI" \
1931            0 \
1932            -c "Verifying peer X.509 certificate... ok" \
1933            -c "Ciphersuite is TLS-ECDH-" \
1934            -s "key types: Opaque, none" \
1935            -s "Ciphersuite is TLS-ECDH-" \
1936            -S "error" \
1937            -C "error"
1938
1939requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1940requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1941requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1942requires_config_enabled MBEDTLS_ECDSA_C
1943requires_config_disabled MBEDTLS_SSL_ASYNC_PRIVATE
1944requires_hash_alg SHA_256
1945run_test    "Opaque key for server authentication: invalid key: decrypt with ECC key, no async" \
1946            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
1947             key_file=data_files/server5.key key_opaque_algs=rsa-decrypt,none \
1948             debug_level=1" \
1949            "$P_CLI" \
1950            1 \
1951            -s "key types: Opaque, none" \
1952            -s "error" \
1953            -c "error" \
1954            -c "Public key type mismatch"
1955
1956requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1957requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1958requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1959requires_config_enabled MBEDTLS_ECDSA_C
1960requires_config_enabled MBEDTLS_RSA_C
1961requires_config_disabled MBEDTLS_SSL_ASYNC_PRIVATE
1962requires_hash_alg SHA_256
1963run_test    "Opaque key for server authentication: invalid key: ecdh with RSA key, no async" \
1964            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
1965             key_file=data_files/server2.key key_opaque_algs=ecdh,none \
1966             debug_level=1" \
1967            "$P_CLI" \
1968            1 \
1969            -s "key types: Opaque, none" \
1970            -s "error" \
1971            -c "error" \
1972            -c "Public key type mismatch"
1973
1974requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1975requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1976requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1977requires_config_enabled MBEDTLS_ECDSA_C
1978requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
1979requires_hash_alg SHA_256
1980run_test    "Opaque key for server authentication: invalid alg: decrypt with ECC key, async" \
1981            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
1982             key_file=data_files/server5.key key_opaque_algs=rsa-decrypt,none \
1983             debug_level=1" \
1984            "$P_CLI" \
1985            1 \
1986            -s "key types: Opaque, none" \
1987            -s "got ciphersuites in common, but none of them usable" \
1988            -s "error" \
1989            -c "error"
1990
1991requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
1992requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
1993requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
1994requires_config_enabled MBEDTLS_ECDSA_C
1995requires_config_enabled MBEDTLS_RSA_C
1996requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
1997requires_hash_alg SHA_256
1998run_test    "Opaque key for server authentication: invalid alg: ecdh with RSA key, async" \
1999            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2000             key_file=data_files/server2.key key_opaque_algs=ecdh,none \
2001             debug_level=1" \
2002            "$P_CLI" \
2003            1 \
2004            -s "key types: Opaque, none" \
2005            -s "got ciphersuites in common, but none of them usable" \
2006            -s "error" \
2007            -c "error"
2008
2009requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2010requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2011requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2012requires_config_enabled MBEDTLS_ECDSA_C
2013requires_hash_alg SHA_256
2014requires_config_enabled MBEDTLS_CCM_C
2015run_test    "Opaque key for server authentication: invalid alg: ECDHE-ECDSA with ecdh" \
2016            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2017             key_file=data_files/server5.key key_opaque_algs=ecdh,none \
2018             debug_level=1" \
2019            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-CCM" \
2020            1 \
2021            -s "key types: Opaque, none" \
2022            -s "got ciphersuites in common, but none of them usable" \
2023            -s "error" \
2024            -c "error"
2025
2026requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2027requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2028requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2029requires_config_enabled MBEDTLS_ECDSA_C
2030requires_hash_alg SHA_256
2031requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2032run_test    "Opaque keys for server authentication: EC keys with different algs, force ECDHE-ECDSA" \
2033            "$P_SRV key_opaque=1 crt_file=data_files/server7.crt \
2034             key_file=data_files/server7.key key_opaque_algs=ecdh,none \
2035             crt_file2=data_files/server5.crt key_file2=data_files/server5.key \
2036             key_opaque_algs2=ecdsa-sign,none" \
2037            "$P_CLI" \
2038            0 \
2039            -c "Verifying peer X.509 certificate... ok" \
2040            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2041            -c "CN=Polarssl Test EC CA" \
2042            -s "key types: Opaque, Opaque" \
2043            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2044            -S "error" \
2045            -C "error"
2046
2047requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2048requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2049requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2050requires_config_enabled MBEDTLS_ECDSA_C
2051requires_hash_alg SHA_384
2052requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2053run_test    "Opaque keys for server authentication: EC keys with different algs, force ECDH-ECDSA" \
2054            "$P_SRV key_opaque=1 crt_file=data_files/server7.crt \
2055             key_file=data_files/server7.key key_opaque_algs=ecdsa-sign,none \
2056             crt_file2=data_files/server5.crt key_file2=data_files/server5.key \
2057             key_opaque_algs2=ecdh,none debug_level=3" \
2058            "$P_CLI force_ciphersuite=TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384" \
2059            0 \
2060            -c "Verifying peer X.509 certificate... ok" \
2061            -c "Ciphersuite is TLS-ECDH-ECDSA" \
2062            -c "CN=Polarssl Test EC CA" \
2063            -s "key types: Opaque, Opaque" \
2064            -s "Ciphersuite is TLS-ECDH-ECDSA" \
2065            -S "error" \
2066            -C "error"
2067
2068requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2069requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2070requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2071requires_config_enabled MBEDTLS_ECDSA_C
2072requires_hash_alg SHA_384
2073requires_config_enabled MBEDTLS_CCM_C
2074requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2075run_test    "Opaque keys for server authentication: EC + RSA, force ECDHE-ECDSA" \
2076            "$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
2077             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none \
2078             crt_file2=data_files/server2-sha256.crt \
2079             key_file2=data_files/server2.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2080            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-CCM" \
2081            0 \
2082            -c "Verifying peer X.509 certificate... ok" \
2083            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2084            -c "CN=Polarssl Test EC CA" \
2085            -s "key types: Opaque, Opaque" \
2086            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2087            -S "error" \
2088            -C "error"
2089
2090requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2091requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2092requires_config_enabled MBEDTLS_RSA_C
2093run_test    "TLS 1.3 opaque key: no suitable algorithm found" \
2094            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required key_opaque=1 key_opaque_algs=rsa-decrypt,none" \
2095            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2096            1 \
2097            -s "The SSL configuration is tls13 only" \
2098            -c "key type: Opaque" \
2099            -s "key types: Opaque, Opaque" \
2100            -c "error" \
2101            -s "no suitable signature algorithm"
2102
2103requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2104requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2105requires_config_enabled MBEDTLS_RSA_C
2106run_test    "TLS 1.3 opaque key: suitable algorithm found" \
2107            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2108            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2109            0 \
2110            -s "The SSL configuration is tls13 only" \
2111            -c "key type: Opaque" \
2112            -s "key types: Opaque, Opaque" \
2113            -C "error" \
2114            -S "error" \
2115
2116requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2117requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2118requires_config_enabled MBEDTLS_RSA_C
2119run_test    "TLS 1.3 opaque key: first client sig alg not suitable" \
2120            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required key_opaque=1 key_opaque_algs=rsa-sign-pss-sha512,none" \
2121            "$P_CLI debug_level=4 sig_algs=rsa_pss_rsae_sha256,rsa_pss_rsae_sha512" \
2122            0 \
2123            -s "The SSL configuration is tls13 only" \
2124            -s "key types: Opaque, Opaque" \
2125            -s "CertificateVerify signature failed with rsa_pss_rsae_sha256" \
2126            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
2127            -C "error" \
2128            -S "error" \
2129
2130requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2131requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2132requires_config_enabled MBEDTLS_RSA_C
2133run_test    "TLS 1.3 opaque key: 2 keys on server, suitable algorithm found" \
2134            "$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" \
2135            "$P_CLI debug_level=4 key_opaque=1 key_opaque_algs=rsa-decrypt,rsa-sign-pss" \
2136            0 \
2137            -s "The SSL configuration is tls13 only" \
2138            -c "key type: Opaque" \
2139            -s "key types: Opaque, Opaque" \
2140            -C "error" \
2141            -S "error" \
2142
2143# Test using a RSA opaque private key for server authentication
2144requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2145requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2146requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2147requires_config_enabled MBEDTLS_ECDSA_C
2148requires_config_enabled MBEDTLS_RSA_C
2149requires_hash_alg SHA_256
2150run_test    "Opaque key for server authentication: ECDHE-RSA" \
2151            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2152             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
2153            "$P_CLI" \
2154            0 \
2155            -c "Verifying peer X.509 certificate... ok" \
2156            -c "Ciphersuite is TLS-ECDHE-RSA" \
2157            -s "key types: Opaque, none" \
2158            -s "Ciphersuite is TLS-ECDHE-RSA" \
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_config_enabled MBEDTLS_ECDSA_C
2166requires_config_enabled MBEDTLS_RSA_C
2167requires_hash_alg SHA_256
2168run_test    "Opaque key for server authentication: DHE-RSA" \
2169            "$P_SRV key_opaque=1 crt_file=data_files/server2-sha256.crt \
2170             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pkcs1,none" \
2171            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2172            0 \
2173            -c "Verifying peer X.509 certificate... ok" \
2174            -c "Ciphersuite is TLS-DHE-RSA" \
2175            -s "key types: Opaque, none" \
2176            -s "Ciphersuite is TLS-DHE-RSA" \
2177            -S "error" \
2178            -C "error"
2179
2180requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2181requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2182requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2183requires_config_enabled MBEDTLS_RSA_C
2184requires_hash_alg SHA_256
2185run_test    "Opaque key for server authentication: RSA-PSK" \
2186            "$P_SRV debug_level=1 key_opaque=1 key_opaque_algs=rsa-decrypt,none \
2187             psk=abc123 psk_identity=foo" \
2188            "$P_CLI force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256 \
2189             psk=abc123 psk_identity=foo" \
2190            0 \
2191            -c "Verifying peer X.509 certificate... ok" \
2192            -c "Ciphersuite is TLS-RSA-PSK-" \
2193            -s "key types: Opaque, Opaque" \
2194            -s "Ciphersuite is TLS-RSA-PSK-" \
2195            -S "error" \
2196            -C "error"
2197
2198requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2199requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2200requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2201requires_config_enabled MBEDTLS_RSA_C
2202requires_hash_alg SHA_256
2203run_test    "Opaque key for server authentication: RSA-" \
2204            "$P_SRV debug_level=3 key_opaque=1 key_opaque_algs=rsa-decrypt,none " \
2205            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA256" \
2206            0 \
2207            -c "Verifying peer X.509 certificate... ok" \
2208            -c "Ciphersuite is TLS-RSA-" \
2209            -s "key types: Opaque, Opaque" \
2210            -s "Ciphersuite is TLS-RSA-" \
2211            -S "error" \
2212            -C "error"
2213
2214requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2215requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2216requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2217requires_config_enabled MBEDTLS_ECDSA_C
2218requires_config_enabled MBEDTLS_RSA_C
2219requires_hash_alg SHA_256
2220run_test    "Opaque key for server authentication: DHE-RSA, PSS instead of PKCS1" \
2221            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2222             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pss,none debug_level=1" \
2223            "$P_CLI crt_file=data_files/server2-sha256.crt \
2224             key_file=data_files/server2.key force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2225            1 \
2226            -s "key types: Opaque, none" \
2227            -s "got ciphersuites in common, but none of them usable" \
2228            -s "error" \
2229            -c "error"
2230
2231requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2232requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2233requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2234requires_config_enabled MBEDTLS_ECDSA_C
2235requires_config_enabled MBEDTLS_RSA_C
2236requires_hash_alg SHA_256
2237requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2238run_test    "Opaque keys for server authentication: RSA keys with different algs" \
2239            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2240             key_file=data_files/server2.key key_opaque_algs=rsa-sign-pss,none \
2241             crt_file2=data_files/server4.crt \
2242             key_file2=data_files/server4.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2243            "$P_CLI" \
2244            0 \
2245            -c "Verifying peer X.509 certificate... ok" \
2246            -c "Ciphersuite is TLS-ECDHE-RSA" \
2247            -c "CN=Polarssl Test EC CA" \
2248            -s "key types: Opaque, Opaque" \
2249            -s "Ciphersuite is TLS-ECDHE-RSA" \
2250            -S "error" \
2251            -C "error"
2252
2253requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2254requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2255requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2256requires_config_enabled MBEDTLS_ECDSA_C
2257requires_config_enabled MBEDTLS_RSA_C
2258requires_hash_alg SHA_384
2259requires_config_enabled MBEDTLS_GCM_C
2260requires_config_disabled MBEDTLS_X509_REMOVE_INFO
2261run_test    "Opaque keys for server authentication: EC + RSA, force DHE-RSA" \
2262            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server5.crt \
2263             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none \
2264             crt_file2=data_files/server4.crt \
2265             key_file2=data_files/server4.key key_opaque_algs2=rsa-sign-pkcs1,none" \
2266            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2267            0 \
2268            -c "Verifying peer X.509 certificate... ok" \
2269            -c "Ciphersuite is TLS-DHE-RSA" \
2270            -c "CN=Polarssl Test EC CA" \
2271            -s "key types: Opaque, Opaque" \
2272            -s "Ciphersuite is TLS-DHE-RSA" \
2273            -S "error" \
2274            -C "error"
2275
2276# Test using an EC opaque private key for client/server authentication
2277requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2278requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2279requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2280requires_config_enabled MBEDTLS_ECDSA_C
2281requires_hash_alg SHA_256
2282run_test    "Opaque key for client/server authentication: ECDHE-ECDSA" \
2283            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server5.crt \
2284             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
2285            "$P_CLI key_opaque=1 crt_file=data_files/server5.crt \
2286             key_file=data_files/server5.key key_opaque_algs=ecdsa-sign,none" \
2287            0 \
2288            -c "key type: Opaque" \
2289            -c "Verifying peer X.509 certificate... ok" \
2290            -c "Ciphersuite is TLS-ECDHE-ECDSA" \
2291            -s "key types: Opaque, none" \
2292            -s "Verifying peer X.509 certificate... ok" \
2293            -s "Ciphersuite is TLS-ECDHE-ECDSA" \
2294            -S "error" \
2295            -C "error"
2296
2297# Test using a RSA opaque private key for client/server authentication
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_ECDSA_C
2302requires_config_enabled MBEDTLS_RSA_C
2303requires_hash_alg SHA_256
2304run_test    "Opaque key for client/server authentication: ECDHE-RSA" \
2305            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2306             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2307            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
2308             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2309            0 \
2310            -c "key type: Opaque" \
2311            -c "Verifying peer X.509 certificate... ok" \
2312            -c "Ciphersuite is TLS-ECDHE-RSA" \
2313            -s "key types: Opaque, none" \
2314            -s "Verifying peer X.509 certificate... ok" \
2315            -s "Ciphersuite is TLS-ECDHE-RSA" \
2316            -S "error" \
2317            -C "error"
2318
2319requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2320requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
2321requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
2322requires_config_enabled MBEDTLS_ECDSA_C
2323requires_config_enabled MBEDTLS_RSA_C
2324requires_hash_alg SHA_256
2325run_test    "Opaque key for client/server authentication: DHE-RSA" \
2326            "$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server2-sha256.crt \
2327             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none" \
2328            "$P_CLI key_opaque=1 crt_file=data_files/server2-sha256.crt \
2329             key_file=data_files/server2.key  key_opaque_algs=rsa-sign-pkcs1,none \
2330             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
2331            0 \
2332            -c "key type: Opaque" \
2333            -c "Verifying peer X.509 certificate... ok" \
2334            -c "Ciphersuite is TLS-DHE-RSA" \
2335            -s "key types: Opaque, none" \
2336            -s "Verifying peer X.509 certificate... ok" \
2337            -s "Ciphersuite is TLS-DHE-RSA" \
2338            -S "error" \
2339            -C "error"
2340
2341
2342# Test ciphersuites which we expect to be fully supported by PSA Crypto
2343# and check that we don't fall back to Mbed TLS' internal crypto primitives.
2344run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CCM
2345run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8
2346run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CCM
2347run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CCM-8
2348run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
2349run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384
2350run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA
2351run_test_psa TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256
2352run_test_psa TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384
2353
2354requires_config_enabled MBEDTLS_ECP_DP_SECP521R1_ENABLED
2355run_test_psa_force_curve "secp521r1"
2356requires_config_enabled MBEDTLS_ECP_DP_BP512R1_ENABLED
2357run_test_psa_force_curve "brainpoolP512r1"
2358requires_config_enabled MBEDTLS_ECP_DP_SECP384R1_ENABLED
2359run_test_psa_force_curve "secp384r1"
2360requires_config_enabled MBEDTLS_ECP_DP_BP384R1_ENABLED
2361run_test_psa_force_curve "brainpoolP384r1"
2362requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
2363run_test_psa_force_curve "secp256r1"
2364requires_config_enabled MBEDTLS_ECP_DP_SECP256K1_ENABLED
2365run_test_psa_force_curve "secp256k1"
2366requires_config_enabled MBEDTLS_ECP_DP_BP256R1_ENABLED
2367run_test_psa_force_curve "brainpoolP256r1"
2368requires_config_enabled MBEDTLS_ECP_DP_SECP224R1_ENABLED
2369run_test_psa_force_curve "secp224r1"
2370## SECP224K1 is buggy via the PSA API
2371## (https://github.com/Mbed-TLS/mbedtls/issues/3541),
2372## so it is disabled in PSA even when it's enabled in Mbed TLS.
2373## The proper dependency would be on PSA_WANT_ECC_SECP_K1_224 but
2374## dependencies on PSA symbols in ssl-opt.sh are not implemented yet.
2375#requires_config_enabled MBEDTLS_ECP_DP_SECP224K1_ENABLED
2376#run_test_psa_force_curve "secp224k1"
2377requires_config_enabled MBEDTLS_ECP_DP_SECP192R1_ENABLED
2378run_test_psa_force_curve "secp192r1"
2379requires_config_enabled MBEDTLS_ECP_DP_SECP192K1_ENABLED
2380run_test_psa_force_curve "secp192k1"
2381
2382# Test current time in ServerHello
2383requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2384requires_config_enabled MBEDTLS_HAVE_TIME
2385run_test    "ServerHello contains gmt_unix_time" \
2386            "$P_SRV debug_level=3" \
2387            "$P_CLI debug_level=3" \
2388            0 \
2389            -f "check_server_hello_time" \
2390            -F "check_server_hello_time"
2391
2392# Test for uniqueness of IVs in AEAD ciphersuites
2393requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2394run_test    "Unique IV in GCM" \
2395            "$P_SRV exchanges=20 debug_level=4" \
2396            "$P_CLI exchanges=20 debug_level=4 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
2397            0 \
2398            -u "IV used" \
2399            -U "IV used"
2400
2401# Test for correctness of sent single supported algorithm
2402requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
2403requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2404requires_config_enabled MBEDTLS_DEBUG_C
2405requires_config_enabled MBEDTLS_SSL_CLI_C
2406requires_config_enabled MBEDTLS_SSL_SRV_C
2407requires_config_enabled MBEDTLS_ECDSA_C
2408requires_hash_alg SHA_256
2409run_test    "Single supported algorithm sending: mbedtls client" \
2410            "$P_SRV sig_algs=ecdsa_secp256r1_sha256 auth_mode=required" \
2411            "$P_CLI sig_algs=ecdsa_secp256r1_sha256 debug_level=3" \
2412            0 \
2413            -c "Supported Signature Algorithm found: 04 03"
2414
2415requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2416requires_config_enabled MBEDTLS_SSL_SRV_C
2417requires_config_enabled MBEDTLS_ECDSA_C
2418requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
2419requires_hash_alg SHA_256
2420run_test    "Single supported algorithm sending: openssl client" \
2421            "$P_SRV sig_algs=ecdsa_secp256r1_sha256 auth_mode=required" \
2422            "$O_CLI -cert data_files/server6.crt \
2423                    -key data_files/server6.key" \
2424            0
2425
2426# Tests for certificate verification callback
2427requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2428run_test    "Configuration-specific CRT verification callback" \
2429            "$P_SRV debug_level=3" \
2430            "$P_CLI context_crt_cb=0 debug_level=3" \
2431            0 \
2432            -S "error" \
2433            -c "Verify requested for " \
2434            -c "Use configuration-specific verification callback" \
2435            -C "Use context-specific verification callback" \
2436            -C "error"
2437
2438requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2439run_test    "Context-specific CRT verification callback" \
2440            "$P_SRV debug_level=3" \
2441            "$P_CLI context_crt_cb=1 debug_level=3" \
2442            0 \
2443            -S "error" \
2444            -c "Verify requested for " \
2445            -c "Use context-specific verification callback" \
2446            -C "Use configuration-specific verification callback" \
2447            -C "error"
2448
2449# Tests for SHA-1 support
2450requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2451run_test    "SHA-1 forbidden by default in server certificate" \
2452            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
2453            "$P_CLI debug_level=2 allow_sha1=0" \
2454            1 \
2455            -c "The certificate is signed with an unacceptable hash"
2456
2457requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2458run_test    "SHA-1 explicitly allowed in server certificate" \
2459            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2.crt" \
2460            "$P_CLI allow_sha1=1" \
2461            0
2462
2463requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2464run_test    "SHA-256 allowed by default in server certificate" \
2465            "$P_SRV key_file=data_files/server2.key crt_file=data_files/server2-sha256.crt" \
2466            "$P_CLI allow_sha1=0" \
2467            0
2468
2469requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2470run_test    "SHA-1 forbidden by default in client certificate" \
2471            "$P_SRV auth_mode=required allow_sha1=0" \
2472            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
2473            1 \
2474            -s "The certificate is signed with an unacceptable hash"
2475
2476requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2477run_test    "SHA-1 explicitly allowed in client certificate" \
2478            "$P_SRV auth_mode=required allow_sha1=1" \
2479            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha1.crt" \
2480            0
2481
2482requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2483run_test    "SHA-256 allowed by default in client certificate" \
2484            "$P_SRV auth_mode=required allow_sha1=0" \
2485            "$P_CLI key_file=data_files/cli-rsa.key crt_file=data_files/cli-rsa-sha256.crt" \
2486            0
2487
2488# Dummy TLS 1.3 test
2489# Currently only checking that passing TLS 1.3 key exchange modes to
2490# ssl_client2/ssl_server2 example programs works.
2491requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2492requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2493requires_config_enabled MBEDTLS_SSL_CLI_C
2494requires_config_enabled MBEDTLS_SSL_SRV_C
2495run_test    "TLS 1.3: key exchange mode parameter passing: PSK only" \
2496            "$P_SRV tls13_kex_modes=psk debug_level=4" \
2497            "$P_CLI tls13_kex_modes=psk debug_level=4" \
2498            0
2499
2500requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2501requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2502requires_config_enabled MBEDTLS_SSL_CLI_C
2503requires_config_enabled MBEDTLS_SSL_SRV_C
2504run_test    "TLS 1.3: key exchange mode parameter passing: PSK-ephemeral only" \
2505            "$P_SRV tls13_kex_modes=psk_ephemeral" \
2506            "$P_CLI tls13_kex_modes=psk_ephemeral" \
2507            0
2508
2509requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2510requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2511requires_config_enabled MBEDTLS_SSL_CLI_C
2512requires_config_enabled MBEDTLS_SSL_SRV_C
2513run_test    "TLS 1.3: key exchange mode parameter passing: Pure-ephemeral only" \
2514            "$P_SRV tls13_kex_modes=ephemeral" \
2515            "$P_CLI tls13_kex_modes=ephemeral" \
2516            0
2517
2518requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2519requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2520requires_config_enabled MBEDTLS_SSL_CLI_C
2521requires_config_enabled MBEDTLS_SSL_SRV_C
2522run_test    "TLS 1.3: key exchange mode parameter passing: All ephemeral" \
2523            "$P_SRV tls13_kex_modes=ephemeral_all" \
2524            "$P_CLI tls13_kex_modes=ephemeral_all" \
2525            0
2526
2527requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2528requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2529requires_config_enabled MBEDTLS_SSL_CLI_C
2530requires_config_enabled MBEDTLS_SSL_SRV_C
2531run_test    "TLS 1.3: key exchange mode parameter passing: All PSK" \
2532            "$P_SRV tls13_kex_modes=psk_all" \
2533            "$P_CLI tls13_kex_modes=psk_all" \
2534            0
2535
2536requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2537requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
2538requires_config_enabled MBEDTLS_SSL_CLI_C
2539requires_config_enabled MBEDTLS_SSL_SRV_C
2540run_test    "TLS 1.3: key exchange mode parameter passing: All" \
2541            "$P_SRV tls13_kex_modes=all" \
2542            "$P_CLI tls13_kex_modes=all" \
2543            0
2544
2545# Tests for datagram packing
2546requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2547run_test    "DTLS: multiple records in same datagram, client and server" \
2548            "$P_SRV dtls=1 dgram_packing=1 debug_level=2" \
2549            "$P_CLI dtls=1 dgram_packing=1 debug_level=2" \
2550            0 \
2551            -c "next record in same datagram" \
2552            -s "next record in same datagram"
2553
2554requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2555run_test    "DTLS: multiple records in same datagram, client only" \
2556            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
2557            "$P_CLI dtls=1 dgram_packing=1 debug_level=2" \
2558            0 \
2559            -s "next record in same datagram" \
2560            -C "next record in same datagram"
2561
2562requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2563run_test    "DTLS: multiple records in same datagram, server only" \
2564            "$P_SRV dtls=1 dgram_packing=1 debug_level=2" \
2565            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
2566            0 \
2567            -S "next record in same datagram" \
2568            -c "next record in same datagram"
2569
2570requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2571run_test    "DTLS: multiple records in same datagram, neither client nor server" \
2572            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
2573            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
2574            0 \
2575            -S "next record in same datagram" \
2576            -C "next record in same datagram"
2577
2578# Tests for Context serialization
2579
2580requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2581requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2582run_test    "Context serialization, client serializes, CCM" \
2583            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2584            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2585            0 \
2586            -c "Deserializing connection..." \
2587            -S "Deserializing connection..."
2588
2589requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2590requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2591run_test    "Context serialization, client serializes, ChaChaPoly" \
2592            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2593            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2594            0 \
2595            -c "Deserializing connection..." \
2596            -S "Deserializing connection..."
2597
2598requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2599requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2600run_test    "Context serialization, client serializes, GCM" \
2601            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2602            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2603            0 \
2604            -c "Deserializing connection..." \
2605            -S "Deserializing connection..."
2606
2607requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2608requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2609requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2610run_test    "Context serialization, client serializes, with CID" \
2611            "$P_SRV dtls=1 serialize=0 exchanges=2 cid=1 cid_val=dead" \
2612            "$P_CLI dtls=1 serialize=1 exchanges=2 cid=1 cid_val=beef" \
2613            0 \
2614            -c "Deserializing connection..." \
2615            -S "Deserializing connection..."
2616
2617requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2618run_test    "Context serialization, server serializes, CCM" \
2619            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2620            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2621            0 \
2622            -C "Deserializing connection..." \
2623            -s "Deserializing connection..."
2624
2625requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2626requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2627run_test    "Context serialization, server serializes, ChaChaPoly" \
2628            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2629            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2630            0 \
2631            -C "Deserializing connection..." \
2632            -s "Deserializing connection..."
2633
2634requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2635requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2636run_test    "Context serialization, server serializes, GCM" \
2637            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2638            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2639            0 \
2640            -C "Deserializing connection..." \
2641            -s "Deserializing connection..."
2642
2643requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2644requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2645requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2646run_test    "Context serialization, server serializes, with CID" \
2647            "$P_SRV dtls=1 serialize=1 exchanges=2 cid=1 cid_val=dead" \
2648            "$P_CLI dtls=1 serialize=0 exchanges=2 cid=1 cid_val=beef" \
2649            0 \
2650            -C "Deserializing connection..." \
2651            -s "Deserializing connection..."
2652
2653requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2654requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2655run_test    "Context serialization, both serialize, CCM" \
2656            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2657            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2658            0 \
2659            -c "Deserializing connection..." \
2660            -s "Deserializing connection..."
2661
2662requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2663requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2664run_test    "Context serialization, both serialize, ChaChaPoly" \
2665            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2666            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2667            0 \
2668            -c "Deserializing connection..." \
2669            -s "Deserializing connection..."
2670
2671requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2672requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2673run_test    "Context serialization, both serialize, GCM" \
2674            "$P_SRV dtls=1 serialize=1 exchanges=2" \
2675            "$P_CLI dtls=1 serialize=1 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2676            0 \
2677            -c "Deserializing connection..." \
2678            -s "Deserializing connection..."
2679
2680requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2681requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2682requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2683run_test    "Context serialization, both serialize, with CID" \
2684            "$P_SRV dtls=1 serialize=1 exchanges=2 cid=1 cid_val=dead" \
2685            "$P_CLI dtls=1 serialize=1 exchanges=2 cid=1 cid_val=beef" \
2686            0 \
2687            -c "Deserializing connection..." \
2688            -s "Deserializing connection..."
2689
2690requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2691run_test    "Context serialization, re-init, client serializes, CCM" \
2692            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2693            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2694            0 \
2695            -c "Deserializing connection..." \
2696            -S "Deserializing connection..."
2697
2698requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2699requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2700run_test    "Context serialization, re-init, client serializes, ChaChaPoly" \
2701            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2702            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2703            0 \
2704            -c "Deserializing connection..." \
2705            -S "Deserializing connection..."
2706
2707requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2708requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2709run_test    "Context serialization, re-init, client serializes, GCM" \
2710            "$P_SRV dtls=1 serialize=0 exchanges=2" \
2711            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
2712            0 \
2713            -c "Deserializing connection..." \
2714            -S "Deserializing connection..."
2715
2716requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2717requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2718requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2719run_test    "Context serialization, re-init, client serializes, with CID" \
2720            "$P_SRV dtls=1 serialize=0 exchanges=2 cid=1 cid_val=dead" \
2721            "$P_CLI dtls=1 serialize=2 exchanges=2 cid=1 cid_val=beef" \
2722            0 \
2723            -c "Deserializing connection..." \
2724            -S "Deserializing connection..."
2725
2726requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2727run_test    "Context serialization, re-init, server serializes, CCM" \
2728            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2729            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2730            0 \
2731            -C "Deserializing connection..." \
2732            -s "Deserializing connection..."
2733
2734requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2735requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2736run_test    "Context serialization, re-init, server serializes, ChaChaPoly" \
2737            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2738            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2739            0 \
2740            -C "Deserializing connection..." \
2741            -s "Deserializing connection..."
2742
2743requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2744requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2745run_test    "Context serialization, re-init, server serializes, GCM" \
2746            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2747            "$P_CLI dtls=1 serialize=0 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2748            0 \
2749            -C "Deserializing connection..." \
2750            -s "Deserializing connection..."
2751
2752requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2753requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2754requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2755run_test    "Context serialization, re-init, server serializes, with CID" \
2756            "$P_SRV dtls=1 serialize=2 exchanges=2 cid=1 cid_val=dead" \
2757            "$P_CLI dtls=1 serialize=0 exchanges=2 cid=1 cid_val=beef" \
2758            0 \
2759            -C "Deserializing connection..." \
2760            -s "Deserializing connection..."
2761
2762requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2763requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2764run_test    "Context serialization, re-init, both serialize, CCM" \
2765            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2766            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
2767            0 \
2768            -c "Deserializing connection..." \
2769            -s "Deserializing connection..."
2770
2771requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2772requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2773run_test    "Context serialization, re-init, both serialize, ChaChaPoly" \
2774            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2775            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2776            0 \
2777            -c "Deserializing connection..." \
2778            -s "Deserializing connection..."
2779
2780requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2781requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2782run_test    "Context serialization, re-init, both serialize, GCM" \
2783            "$P_SRV dtls=1 serialize=2 exchanges=2" \
2784            "$P_CLI dtls=1 serialize=2 exchanges=2 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" \
2785            0 \
2786            -c "Deserializing connection..." \
2787            -s "Deserializing connection..."
2788
2789requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2790requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2791requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2792run_test    "Context serialization, re-init, both serialize, with CID" \
2793            "$P_SRV dtls=1 serialize=2 exchanges=2 cid=1 cid_val=dead" \
2794            "$P_CLI dtls=1 serialize=2 exchanges=2 cid=1 cid_val=beef" \
2795            0 \
2796            -c "Deserializing connection..." \
2797            -s "Deserializing connection..."
2798
2799requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2800requires_config_enabled MBEDTLS_SSL_CONTEXT_SERIALIZATION
2801run_test    "Saving the serialized context to a file" \
2802            "$P_SRV dtls=1 serialize=1 context_file=context_srv.txt" \
2803            "$P_CLI dtls=1 serialize=1 context_file=context_cli.txt" \
2804            0 \
2805            -s "Save serialized context to a file... ok" \
2806            -c "Save serialized context to a file... ok"
2807rm -f context_srv.txt
2808rm -f context_cli.txt
2809
2810# Tests for DTLS Connection ID extension
2811
2812# So far, the CID API isn't implemented, so we can't
2813# grep for output witnessing its use. This needs to be
2814# changed once the CID extension is implemented.
2815
2816requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2817requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2818run_test    "Connection ID: Cli enabled, Srv disabled" \
2819            "$P_SRV debug_level=3 dtls=1 cid=0" \
2820            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
2821            0 \
2822            -s "Disable use of CID extension." \
2823            -s "found CID extension"           \
2824            -s "Client sent CID extension, but CID disabled" \
2825            -c "Enable use of CID extension."  \
2826            -c "client hello, adding CID extension" \
2827            -S "server hello, adding CID extension" \
2828            -C "found CID extension" \
2829            -S "Copy CIDs into SSL transform" \
2830            -C "Copy CIDs into SSL transform" \
2831            -c "Use of Connection ID was rejected by the server"
2832
2833requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2834requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2835run_test    "Connection ID: Cli disabled, Srv enabled" \
2836            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
2837            "$P_CLI debug_level=3 dtls=1 cid=0" \
2838            0 \
2839            -c "Disable use of CID extension." \
2840            -C "client hello, adding CID extension"           \
2841            -S "found CID extension"           \
2842            -s "Enable use of CID extension." \
2843            -S "server hello, adding CID extension" \
2844            -C "found CID extension" \
2845            -S "Copy CIDs into SSL transform" \
2846            -C "Copy CIDs into SSL transform"  \
2847            -s "Use of Connection ID was not offered by client"
2848
2849requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2850requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2851run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty" \
2852            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
2853            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef" \
2854            0 \
2855            -c "Enable use of CID extension." \
2856            -s "Enable use of CID extension." \
2857            -c "client hello, adding CID extension" \
2858            -s "found CID extension"           \
2859            -s "Use of CID extension negotiated" \
2860            -s "server hello, adding CID extension" \
2861            -c "found CID extension" \
2862            -c "Use of CID extension negotiated" \
2863            -s "Copy CIDs into SSL transform" \
2864            -c "Copy CIDs into SSL transform" \
2865            -c "Peer CID (length 2 Bytes): de ad" \
2866            -s "Peer CID (length 2 Bytes): be ef" \
2867            -s "Use of Connection ID has been negotiated" \
2868            -c "Use of Connection ID has been negotiated"
2869
2870requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2871requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2872run_test    "Connection ID, 3D: Cli+Srv enabled, Cli+Srv CID nonempty" \
2873            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
2874            "$P_SRV debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=dead" \
2875            "$P_CLI debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=beef" \
2876            0 \
2877            -c "Enable use of CID extension." \
2878            -s "Enable use of CID extension." \
2879            -c "client hello, adding CID extension" \
2880            -s "found CID extension"           \
2881            -s "Use of CID extension negotiated" \
2882            -s "server hello, adding CID extension" \
2883            -c "found CID extension" \
2884            -c "Use of CID extension negotiated" \
2885            -s "Copy CIDs into SSL transform" \
2886            -c "Copy CIDs into SSL transform" \
2887            -c "Peer CID (length 2 Bytes): de ad" \
2888            -s "Peer CID (length 2 Bytes): be ef" \
2889            -s "Use of Connection ID has been negotiated" \
2890            -c "Use of Connection ID has been negotiated" \
2891            -c "ignoring unexpected CID" \
2892            -s "ignoring unexpected CID"
2893
2894requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2895requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2896run_test    "Connection ID, MTU: Cli+Srv enabled, Cli+Srv CID nonempty" \
2897            -p "$P_PXY mtu=800" \
2898            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead" \
2899            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef" \
2900            0 \
2901            -c "Enable use of CID extension." \
2902            -s "Enable use of CID extension." \
2903            -c "client hello, adding CID extension" \
2904            -s "found CID extension"           \
2905            -s "Use of CID extension negotiated" \
2906            -s "server hello, adding CID extension" \
2907            -c "found CID extension" \
2908            -c "Use of CID extension negotiated" \
2909            -s "Copy CIDs into SSL transform" \
2910            -c "Copy CIDs into SSL transform" \
2911            -c "Peer CID (length 2 Bytes): de ad" \
2912            -s "Peer CID (length 2 Bytes): be ef" \
2913            -s "Use of Connection ID has been negotiated" \
2914            -c "Use of Connection ID has been negotiated"
2915
2916requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2917requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2918run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, Cli+Srv CID nonempty" \
2919            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
2920            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead" \
2921            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef" \
2922            0 \
2923            -c "Enable use of CID extension." \
2924            -s "Enable use of CID extension." \
2925            -c "client hello, adding CID extension" \
2926            -s "found CID extension"           \
2927            -s "Use of CID extension negotiated" \
2928            -s "server hello, adding CID extension" \
2929            -c "found CID extension" \
2930            -c "Use of CID extension negotiated" \
2931            -s "Copy CIDs into SSL transform" \
2932            -c "Copy CIDs into SSL transform" \
2933            -c "Peer CID (length 2 Bytes): de ad" \
2934            -s "Peer CID (length 2 Bytes): be ef" \
2935            -s "Use of Connection ID has been negotiated" \
2936            -c "Use of Connection ID has been negotiated" \
2937            -c "ignoring unexpected CID" \
2938            -s "ignoring unexpected CID"
2939
2940requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2941requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2942run_test    "Connection ID: Cli+Srv enabled, Cli CID empty" \
2943            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
2944            "$P_CLI debug_level=3 dtls=1 cid=1" \
2945            0 \
2946            -c "Enable use of CID extension." \
2947            -s "Enable use of CID extension." \
2948            -c "client hello, adding CID extension" \
2949            -s "found CID extension"           \
2950            -s "Use of CID extension negotiated" \
2951            -s "server hello, adding CID extension" \
2952            -c "found CID extension" \
2953            -c "Use of CID extension negotiated" \
2954            -s "Copy CIDs into SSL transform" \
2955            -c "Copy CIDs into SSL transform" \
2956            -c "Peer CID (length 4 Bytes): de ad be ef" \
2957            -s "Peer CID (length 0 Bytes):" \
2958            -s "Use of Connection ID has been negotiated" \
2959            -c "Use of Connection ID has been negotiated"
2960
2961requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2962requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2963run_test    "Connection ID: Cli+Srv enabled, Srv CID empty" \
2964            "$P_SRV debug_level=3 dtls=1 cid=1" \
2965            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
2966            0 \
2967            -c "Enable use of CID extension." \
2968            -s "Enable use of CID extension." \
2969            -c "client hello, adding CID extension" \
2970            -s "found CID extension"           \
2971            -s "Use of CID extension negotiated" \
2972            -s "server hello, adding CID extension" \
2973            -c "found CID extension" \
2974            -c "Use of CID extension negotiated" \
2975            -s "Copy CIDs into SSL transform" \
2976            -c "Copy CIDs into SSL transform" \
2977            -s "Peer CID (length 4 Bytes): de ad be ef" \
2978            -c "Peer CID (length 0 Bytes):" \
2979            -s "Use of Connection ID has been negotiated" \
2980            -c "Use of Connection ID has been negotiated"
2981
2982requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
2983requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
2984run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty" \
2985            "$P_SRV debug_level=3 dtls=1 cid=1" \
2986            "$P_CLI debug_level=3 dtls=1 cid=1" \
2987            0 \
2988            -c "Enable use of CID extension." \
2989            -s "Enable use of CID extension." \
2990            -c "client hello, adding CID extension" \
2991            -s "found CID extension"           \
2992            -s "Use of CID extension negotiated" \
2993            -s "server hello, adding CID extension" \
2994            -c "found CID extension" \
2995            -c "Use of CID extension negotiated" \
2996            -s "Copy CIDs into SSL transform" \
2997            -c "Copy CIDs into SSL transform" \
2998            -S "Use of Connection ID has been negotiated" \
2999            -C "Use of Connection ID has been negotiated"
3000
3001requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3002requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3003run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty, AES-128-CCM-8" \
3004            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
3005            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3006            0 \
3007            -c "Enable use of CID extension." \
3008            -s "Enable use of CID extension." \
3009            -c "client hello, adding CID extension" \
3010            -s "found CID extension"           \
3011            -s "Use of CID extension negotiated" \
3012            -s "server hello, adding CID extension" \
3013            -c "found CID extension" \
3014            -c "Use of CID extension negotiated" \
3015            -s "Copy CIDs into SSL transform" \
3016            -c "Copy CIDs into SSL transform" \
3017            -c "Peer CID (length 2 Bytes): de ad" \
3018            -s "Peer CID (length 2 Bytes): be ef" \
3019            -s "Use of Connection ID has been negotiated" \
3020            -c "Use of Connection ID has been negotiated"
3021
3022requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3023requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3024run_test    "Connection ID: Cli+Srv enabled, Cli CID empty, AES-128-CCM-8" \
3025            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3026            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3027            0 \
3028            -c "Enable use of CID extension." \
3029            -s "Enable use of CID extension." \
3030            -c "client hello, adding CID extension" \
3031            -s "found CID extension"           \
3032            -s "Use of CID extension negotiated" \
3033            -s "server hello, adding CID extension" \
3034            -c "found CID extension" \
3035            -c "Use of CID extension negotiated" \
3036            -s "Copy CIDs into SSL transform" \
3037            -c "Copy CIDs into SSL transform" \
3038            -c "Peer CID (length 4 Bytes): de ad be ef" \
3039            -s "Peer CID (length 0 Bytes):" \
3040            -s "Use of Connection ID has been negotiated" \
3041            -c "Use of Connection ID has been negotiated"
3042
3043requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3044requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3045run_test    "Connection ID: Cli+Srv enabled, Srv CID empty, AES-128-CCM-8" \
3046            "$P_SRV debug_level=3 dtls=1 cid=1" \
3047            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3048            0 \
3049            -c "Enable use of CID extension." \
3050            -s "Enable use of CID extension." \
3051            -c "client hello, adding CID extension" \
3052            -s "found CID extension"           \
3053            -s "Use of CID extension negotiated" \
3054            -s "server hello, adding CID extension" \
3055            -c "found CID extension" \
3056            -c "Use of CID extension negotiated" \
3057            -s "Copy CIDs into SSL transform" \
3058            -c "Copy CIDs into SSL transform" \
3059            -s "Peer CID (length 4 Bytes): de ad be ef" \
3060            -c "Peer CID (length 0 Bytes):" \
3061            -s "Use of Connection ID has been negotiated" \
3062            -c "Use of Connection ID has been negotiated"
3063
3064requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3065requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3066run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty, AES-128-CCM-8" \
3067            "$P_SRV debug_level=3 dtls=1 cid=1" \
3068            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
3069            0 \
3070            -c "Enable use of CID extension." \
3071            -s "Enable use of CID extension." \
3072            -c "client hello, adding CID extension" \
3073            -s "found CID extension"           \
3074            -s "Use of CID extension negotiated" \
3075            -s "server hello, adding CID extension" \
3076            -c "found CID extension" \
3077            -c "Use of CID extension negotiated" \
3078            -s "Copy CIDs into SSL transform" \
3079            -c "Copy CIDs into SSL transform" \
3080            -S "Use of Connection ID has been negotiated" \
3081            -C "Use of Connection ID has been negotiated"
3082
3083requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3084requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3085run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID nonempty, AES-128-CBC" \
3086            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead" \
3087            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3088            0 \
3089            -c "Enable use of CID extension." \
3090            -s "Enable use of CID extension." \
3091            -c "client hello, adding CID extension" \
3092            -s "found CID extension"           \
3093            -s "Use of CID extension negotiated" \
3094            -s "server hello, adding CID extension" \
3095            -c "found CID extension" \
3096            -c "Use of CID extension negotiated" \
3097            -s "Copy CIDs into SSL transform" \
3098            -c "Copy CIDs into SSL transform" \
3099            -c "Peer CID (length 2 Bytes): de ad" \
3100            -s "Peer CID (length 2 Bytes): be ef" \
3101            -s "Use of Connection ID has been negotiated" \
3102            -c "Use of Connection ID has been negotiated"
3103
3104requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3105requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3106run_test    "Connection ID: Cli+Srv enabled, Cli CID empty, AES-128-CBC" \
3107            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=deadbeef" \
3108            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3109            0 \
3110            -c "Enable use of CID extension." \
3111            -s "Enable use of CID extension." \
3112            -c "client hello, adding CID extension" \
3113            -s "found CID extension"           \
3114            -s "Use of CID extension negotiated" \
3115            -s "server hello, adding CID extension" \
3116            -c "found CID extension" \
3117            -c "Use of CID extension negotiated" \
3118            -s "Copy CIDs into SSL transform" \
3119            -c "Copy CIDs into SSL transform" \
3120            -c "Peer CID (length 4 Bytes): de ad be ef" \
3121            -s "Peer CID (length 0 Bytes):" \
3122            -s "Use of Connection ID has been negotiated" \
3123            -c "Use of Connection ID has been negotiated"
3124
3125requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3126requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3127run_test    "Connection ID: Cli+Srv enabled, Srv CID empty, AES-128-CBC" \
3128            "$P_SRV debug_level=3 dtls=1 cid=1" \
3129            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=deadbeef force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3130            0 \
3131            -c "Enable use of CID extension." \
3132            -s "Enable use of CID extension." \
3133            -c "client hello, adding CID extension" \
3134            -s "found CID extension"           \
3135            -s "Use of CID extension negotiated" \
3136            -s "server hello, adding CID extension" \
3137            -c "found CID extension" \
3138            -c "Use of CID extension negotiated" \
3139            -s "Copy CIDs into SSL transform" \
3140            -c "Copy CIDs into SSL transform" \
3141            -s "Peer CID (length 4 Bytes): de ad be ef" \
3142            -c "Peer CID (length 0 Bytes):" \
3143            -s "Use of Connection ID has been negotiated" \
3144            -c "Use of Connection ID has been negotiated"
3145
3146requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3147requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3148run_test    "Connection ID: Cli+Srv enabled, Cli+Srv CID empty, AES-128-CBC" \
3149            "$P_SRV debug_level=3 dtls=1 cid=1" \
3150            "$P_CLI debug_level=3 dtls=1 cid=1 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
3151            0 \
3152            -c "Enable use of CID extension." \
3153            -s "Enable use of CID extension." \
3154            -c "client hello, adding CID extension" \
3155            -s "found CID extension"           \
3156            -s "Use of CID extension negotiated" \
3157            -s "server hello, adding CID extension" \
3158            -c "found CID extension" \
3159            -c "Use of CID extension negotiated" \
3160            -s "Copy CIDs into SSL transform" \
3161            -c "Copy CIDs into SSL transform" \
3162            -S "Use of Connection ID has been negotiated" \
3163            -C "Use of Connection ID has been negotiated"
3164
3165requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3166requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3167requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3168run_test    "Connection ID: Cli+Srv enabled, renegotiate without change of CID" \
3169            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3170            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3171            0 \
3172            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3173            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3174            -s "(initial handshake) Use of Connection ID has been negotiated" \
3175            -c "(initial handshake) Use of Connection ID has been negotiated" \
3176            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3177            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3178            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3179            -c "(after renegotiation) Use of Connection ID has been negotiated"
3180
3181requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3182requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3183requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3184run_test    "Connection ID: Cli+Srv enabled, renegotiate with different CID" \
3185            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_val_renego=beef renegotiation=1" \
3186            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3187            0 \
3188            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3189            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3190            -s "(initial handshake) Use of Connection ID has been negotiated" \
3191            -c "(initial handshake) Use of Connection ID has been negotiated" \
3192            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3193            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3194            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3195            -c "(after renegotiation) Use of Connection ID has been negotiated"
3196
3197requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3198requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3199requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3200run_test    "Connection ID, no packing: Cli+Srv enabled, renegotiate with different CID" \
3201            "$P_SRV debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=dead cid_val_renego=beef renegotiation=1" \
3202            "$P_CLI debug_level=3 dtls=1 cid=1 dgram_packing=0 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3203            0 \
3204            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3205            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3206            -s "(initial handshake) Use of Connection ID has been negotiated" \
3207            -c "(initial handshake) Use of Connection ID has been negotiated" \
3208            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3209            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3210            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3211            -c "(after renegotiation) Use of Connection ID has been negotiated"
3212
3213requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3214requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3215requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3216run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, renegotiate with different CID" \
3217            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3218            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead cid_val_renego=beef renegotiation=1" \
3219            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef cid_val_renego=dead renegotiation=1 renegotiate=1" \
3220            0 \
3221            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3222            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3223            -s "(initial handshake) Use of Connection ID has been negotiated" \
3224            -c "(initial handshake) Use of Connection ID has been negotiated" \
3225            -c "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3226            -s "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3227            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3228            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3229            -c "ignoring unexpected CID" \
3230            -s "ignoring unexpected CID"
3231
3232requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3233requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3234requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3235run_test    "Connection ID: Cli+Srv enabled, renegotiate without CID" \
3236            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3237            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3238            0 \
3239            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3240            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3241            -s "(initial handshake) Use of Connection ID has been negotiated" \
3242            -c "(initial handshake) Use of Connection ID has been negotiated" \
3243            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3244            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3245            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3246            -S "(after renegotiation) Use of Connection ID has been negotiated"
3247
3248requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3249requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3250requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3251run_test    "Connection ID, no packing: Cli+Srv enabled, renegotiate without CID" \
3252            "$P_SRV debug_level=3 dtls=1 dgram_packing=0 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3253            "$P_CLI debug_level=3 dtls=1 dgram_packing=0 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3254            0 \
3255            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3256            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3257            -s "(initial handshake) Use of Connection ID has been negotiated" \
3258            -c "(initial handshake) Use of Connection ID has been negotiated" \
3259            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3260            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3261            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3262            -S "(after renegotiation) Use of Connection ID has been negotiated"
3263
3264requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3265requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3266requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3267run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, renegotiate without CID" \
3268            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3269            "$P_SRV debug_level=3 mtu=800 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3270            "$P_CLI debug_level=3 mtu=800 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3271            0 \
3272            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3273            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3274            -s "(initial handshake) Use of Connection ID has been negotiated" \
3275            -c "(initial handshake) Use of Connection ID has been negotiated" \
3276            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3277            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3278            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3279            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3280            -c "ignoring unexpected CID" \
3281            -s "ignoring unexpected CID"
3282
3283requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3284requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3285requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3286run_test    "Connection ID: Cli+Srv enabled, CID on renegotiation" \
3287            "$P_SRV debug_level=3 dtls=1 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3288            "$P_CLI debug_level=3 dtls=1 cid=0 cid_renego=1 cid_val_renego=beef renegotiation=1 renegotiate=1" \
3289            0 \
3290            -S "(initial handshake) Use of Connection ID has been negotiated" \
3291            -C "(initial handshake) Use of Connection ID has been negotiated" \
3292            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3293            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3294            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3295            -s "(after renegotiation) Use of Connection ID has been negotiated"
3296
3297requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3298requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3299requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3300run_test    "Connection ID, no packing: Cli+Srv enabled, CID on renegotiation" \
3301            "$P_SRV debug_level=3 dtls=1 dgram_packing=0 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3302            "$P_CLI debug_level=3 dtls=1 dgram_packing=0 cid=0 cid_renego=1 cid_val_renego=beef renegotiation=1 renegotiate=1" \
3303            0 \
3304            -S "(initial handshake) Use of Connection ID has been negotiated" \
3305            -C "(initial handshake) Use of Connection ID has been negotiated" \
3306            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3307            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3308            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3309            -s "(after renegotiation) Use of Connection ID has been negotiated"
3310
3311requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3312requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3313requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3314run_test    "Connection ID, 3D+MTU: Cli+Srv enabled, CID on renegotiation" \
3315            -p "$P_PXY mtu=800 drop=5 delay=5 duplicate=5 bad_cid=1" \
3316            "$P_SRV debug_level=3 mtu=800 dtls=1 dgram_packing=1 cid=0 cid_renego=1 cid_val_renego=dead renegotiation=1" \
3317            "$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" \
3318            0 \
3319            -S "(initial handshake) Use of Connection ID has been negotiated" \
3320            -C "(initial handshake) Use of Connection ID has been negotiated" \
3321            -c "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3322            -s "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3323            -c "(after renegotiation) Use of Connection ID has been negotiated" \
3324            -s "(after renegotiation) Use of Connection ID has been negotiated" \
3325            -c "ignoring unexpected CID" \
3326            -s "ignoring unexpected CID"
3327
3328requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3329requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3330requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3331run_test    "Connection ID: Cli+Srv enabled, Cli disables on renegotiation" \
3332            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3333            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3334            0 \
3335            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3336            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3337            -s "(initial handshake) Use of Connection ID has been negotiated" \
3338            -c "(initial handshake) Use of Connection ID has been negotiated" \
3339            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3340            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3341            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3342            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3343            -s "(after renegotiation) Use of Connection ID was not offered by client"
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, 3D: Cli+Srv enabled, Cli disables on renegotiation" \
3349            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3350            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead renegotiation=1" \
3351            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef cid_renego=0 renegotiation=1 renegotiate=1" \
3352            0 \
3353            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3354            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3355            -s "(initial handshake) Use of Connection ID has been negotiated" \
3356            -c "(initial handshake) Use of Connection ID has been negotiated" \
3357            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3358            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3359            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3360            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3361            -s "(after renegotiation) Use of Connection ID was not offered by client" \
3362            -c "ignoring unexpected CID" \
3363            -s "ignoring unexpected CID"
3364
3365requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3366requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3367requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3368run_test    "Connection ID: Cli+Srv enabled, Srv disables on renegotiation" \
3369            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3370            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3371            0 \
3372            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3373            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3374            -s "(initial handshake) Use of Connection ID has been negotiated" \
3375            -c "(initial handshake) Use of Connection ID has been negotiated" \
3376            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3377            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3378            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3379            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3380            -c "(after renegotiation) Use of Connection ID was rejected by the server"
3381
3382requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3383requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3384requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
3385run_test    "Connection ID, 3D: Cli+Srv enabled, Srv disables on renegotiation" \
3386            -p "$P_PXY drop=5 delay=5 duplicate=5 bad_cid=1" \
3387            "$P_SRV debug_level=3 dtls=1 cid=1 cid_val=dead cid_renego=0 renegotiation=1" \
3388            "$P_CLI debug_level=3 dtls=1 cid=1 cid_val=beef renegotiation=1 renegotiate=1" \
3389            0 \
3390            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3391            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3392            -s "(initial handshake) Use of Connection ID has been negotiated" \
3393            -c "(initial handshake) Use of Connection ID has been negotiated" \
3394            -C "(after renegotiation) Peer CID (length 2 Bytes): de ad" \
3395            -S "(after renegotiation) Peer CID (length 2 Bytes): be ef" \
3396            -C "(after renegotiation) Use of Connection ID has been negotiated" \
3397            -S "(after renegotiation) Use of Connection ID has been negotiated" \
3398            -c "(after renegotiation) Use of Connection ID was rejected by the server" \
3399            -c "ignoring unexpected CID" \
3400            -s "ignoring unexpected CID"
3401
3402# This and the test below it require MAX_CONTENT_LEN to be at least MFL+1, because the
3403# tests check that the buffer contents are reallocated when the message is
3404# larger than the buffer.
3405requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3406requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3407requires_config_enabled MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3408requires_max_content_len 513
3409run_test    "Connection ID: Cli+Srv enabled, variable buffer lengths, MFL=512" \
3410            "$P_SRV dtls=1 cid=1 cid_val=dead debug_level=2" \
3411            "$P_CLI force_ciphersuite="TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" max_frag_len=512 dtls=1 cid=1 cid_val=beef" \
3412            0 \
3413            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3414            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3415            -s "(initial handshake) Use of Connection ID has been negotiated" \
3416            -c "(initial handshake) Use of Connection ID has been negotiated" \
3417            -s "Reallocating in_buf" \
3418            -s "Reallocating out_buf"
3419
3420requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3421requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
3422requires_config_enabled MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3423requires_max_content_len 1025
3424run_test    "Connection ID: Cli+Srv enabled, variable buffer lengths, MFL=1024" \
3425            "$P_SRV dtls=1 cid=1 cid_val=dead debug_level=2" \
3426            "$P_CLI force_ciphersuite="TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" max_frag_len=1024 dtls=1 cid=1 cid_val=beef" \
3427            0 \
3428            -c "(initial handshake) Peer CID (length 2 Bytes): de ad" \
3429            -s "(initial handshake) Peer CID (length 2 Bytes): be ef" \
3430            -s "(initial handshake) Use of Connection ID has been negotiated" \
3431            -c "(initial handshake) Use of Connection ID has been negotiated" \
3432            -s "Reallocating in_buf" \
3433            -s "Reallocating out_buf"
3434
3435# Tests for Encrypt-then-MAC extension
3436
3437requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3438run_test    "Encrypt then MAC: default" \
3439            "$P_SRV debug_level=3 \
3440             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3441            "$P_CLI debug_level=3" \
3442            0 \
3443            -c "client hello, adding encrypt_then_mac extension" \
3444            -s "found encrypt then mac extension" \
3445            -s "server hello, adding encrypt then mac extension" \
3446            -c "found encrypt_then_mac extension" \
3447            -c "using encrypt then mac" \
3448            -s "using encrypt then mac"
3449
3450requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3451run_test    "Encrypt then MAC: client enabled, server disabled" \
3452            "$P_SRV debug_level=3 etm=0 \
3453             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3454            "$P_CLI debug_level=3 etm=1" \
3455            0 \
3456            -c "client hello, adding encrypt_then_mac extension" \
3457            -s "found encrypt then mac extension" \
3458            -S "server hello, adding encrypt then mac extension" \
3459            -C "found encrypt_then_mac extension" \
3460            -C "using encrypt then mac" \
3461            -S "using encrypt then mac"
3462
3463requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3464run_test    "Encrypt then MAC: client enabled, aead cipher" \
3465            "$P_SRV debug_level=3 etm=1 \
3466             force_ciphersuite=TLS-RSA-WITH-AES-128-GCM-SHA256" \
3467            "$P_CLI debug_level=3 etm=1" \
3468            0 \
3469            -c "client hello, adding encrypt_then_mac extension" \
3470            -s "found encrypt then mac extension" \
3471            -S "server hello, adding encrypt then mac extension" \
3472            -C "found encrypt_then_mac extension" \
3473            -C "using encrypt then mac" \
3474            -S "using encrypt then mac"
3475
3476requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3477run_test    "Encrypt then MAC: client disabled, server enabled" \
3478            "$P_SRV debug_level=3 etm=1 \
3479             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
3480            "$P_CLI debug_level=3 etm=0" \
3481            0 \
3482            -C "client hello, adding encrypt_then_mac extension" \
3483            -S "found encrypt then mac extension" \
3484            -S "server hello, adding encrypt then mac extension" \
3485            -C "found encrypt_then_mac extension" \
3486            -C "using encrypt then mac" \
3487            -S "using encrypt then mac"
3488
3489# Tests for Extended Master Secret extension
3490
3491requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3492requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3493run_test    "Extended Master Secret: default" \
3494            "$P_SRV debug_level=3" \
3495            "$P_CLI debug_level=3" \
3496            0 \
3497            -c "client hello, adding extended_master_secret extension" \
3498            -s "found extended master secret extension" \
3499            -s "server hello, adding extended master secret extension" \
3500            -c "found extended_master_secret extension" \
3501            -c "session hash for extended master secret" \
3502            -s "session hash for extended master secret"
3503
3504requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3505requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3506run_test    "Extended Master Secret: client enabled, server disabled" \
3507            "$P_SRV debug_level=3 extended_ms=0" \
3508            "$P_CLI debug_level=3 extended_ms=1" \
3509            0 \
3510            -c "client hello, adding extended_master_secret extension" \
3511            -s "found extended master secret extension" \
3512            -S "server hello, adding extended master secret extension" \
3513            -C "found extended_master_secret extension" \
3514            -C "session hash for extended master secret" \
3515            -S "session hash for extended master secret"
3516
3517requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3518requires_config_enabled MBEDTLS_SSL_EXTENDED_MASTER_SECRET
3519run_test    "Extended Master Secret: client disabled, server enabled" \
3520            "$P_SRV debug_level=3 extended_ms=1" \
3521            "$P_CLI debug_level=3 extended_ms=0" \
3522            0 \
3523            -C "client hello, adding extended_master_secret extension" \
3524            -S "found extended master secret extension" \
3525            -S "server hello, adding extended master secret extension" \
3526            -C "found extended_master_secret extension" \
3527            -C "session hash for extended master secret" \
3528            -S "session hash for extended master secret"
3529
3530# Test sending and receiving empty application data records
3531
3532requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3533run_test    "Encrypt then MAC: empty application data record" \
3534            "$P_SRV auth_mode=none debug_level=4 etm=1" \
3535            "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA" \
3536            0 \
3537            -S "0000:  0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
3538            -s "dumping 'input payload after decrypt' (0 bytes)" \
3539            -c "0 bytes written in 1 fragments"
3540
3541requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3542run_test    "Encrypt then MAC: disabled, empty application data record" \
3543            "$P_SRV auth_mode=none debug_level=4 etm=0" \
3544            "$P_CLI auth_mode=none etm=0 request_size=0" \
3545            0 \
3546            -s "dumping 'input payload after decrypt' (0 bytes)" \
3547            -c "0 bytes written in 1 fragments"
3548
3549requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3550run_test    "Encrypt then MAC, DTLS: empty application data record" \
3551            "$P_SRV auth_mode=none debug_level=4 etm=1 dtls=1" \
3552            "$P_CLI auth_mode=none etm=1 request_size=0 force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA dtls=1" \
3553            0 \
3554            -S "0000:  0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f" \
3555            -s "dumping 'input payload after decrypt' (0 bytes)" \
3556            -c "0 bytes written in 1 fragments"
3557
3558requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3559run_test    "Encrypt then MAC, DTLS: disabled, empty application data record" \
3560            "$P_SRV auth_mode=none debug_level=4 etm=0 dtls=1" \
3561            "$P_CLI auth_mode=none etm=0 request_size=0 dtls=1" \
3562            0 \
3563            -s "dumping 'input payload after decrypt' (0 bytes)" \
3564            -c "0 bytes written in 1 fragments"
3565
3566# Tests for CBC 1/n-1 record splitting
3567
3568run_test    "CBC Record splitting: TLS 1.2, no splitting" \
3569            "$P_SRV force_version=tls12" \
3570            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
3571             request_size=123" \
3572            0 \
3573            -s "Read from client: 123 bytes read" \
3574            -S "Read from client: 1 bytes read" \
3575            -S "122 bytes read"
3576
3577# Tests for Session Tickets
3578
3579requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3580run_test    "Session resume using tickets: basic" \
3581            "$P_SRV debug_level=3 tickets=1" \
3582            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3583            0 \
3584            -c "client hello, adding session ticket extension" \
3585            -s "found session ticket extension" \
3586            -s "server hello, adding session ticket extension" \
3587            -c "found session_ticket extension" \
3588            -c "parse new session ticket" \
3589            -S "session successfully restored from cache" \
3590            -s "session successfully restored from ticket" \
3591            -s "a session has been resumed" \
3592            -c "a session has been resumed"
3593
3594requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3595run_test    "Session resume using tickets: manual rotation" \
3596            "$P_SRV debug_level=3 tickets=1 ticket_rotate=1" \
3597            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3598            0 \
3599            -c "client hello, adding session ticket extension" \
3600            -s "found session ticket extension" \
3601            -s "server hello, adding session ticket extension" \
3602            -c "found session_ticket extension" \
3603            -c "parse new session ticket" \
3604            -S "session successfully restored from cache" \
3605            -s "session successfully restored from ticket" \
3606            -s "a session has been resumed" \
3607            -c "a session has been resumed"
3608
3609requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3610run_test    "Session resume using tickets: cache disabled" \
3611            "$P_SRV debug_level=3 tickets=1 cache_max=0" \
3612            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3613            0 \
3614            -c "client hello, adding session ticket extension" \
3615            -s "found session ticket extension" \
3616            -s "server hello, adding session ticket extension" \
3617            -c "found session_ticket extension" \
3618            -c "parse new session ticket" \
3619            -S "session successfully restored from cache" \
3620            -s "session successfully restored from ticket" \
3621            -s "a session has been resumed" \
3622            -c "a session has been resumed"
3623
3624requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3625run_test    "Session resume using tickets: timeout" \
3626            "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
3627            "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
3628            0 \
3629            -c "client hello, adding session ticket extension" \
3630            -s "found session ticket extension" \
3631            -s "server hello, adding session ticket extension" \
3632            -c "found session_ticket extension" \
3633            -c "parse new session ticket" \
3634            -S "session successfully restored from cache" \
3635            -S "session successfully restored from ticket" \
3636            -S "a session has been resumed" \
3637            -C "a session has been resumed"
3638
3639requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3640run_test    "Session resume using tickets: session copy" \
3641            "$P_SRV debug_level=3 tickets=1 cache_max=0" \
3642            "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_mode=0" \
3643            0 \
3644            -c "client hello, adding session ticket extension" \
3645            -s "found session ticket extension" \
3646            -s "server hello, adding session ticket extension" \
3647            -c "found session_ticket extension" \
3648            -c "parse new session ticket" \
3649            -S "session successfully restored from cache" \
3650            -s "session successfully restored from ticket" \
3651            -s "a session has been resumed" \
3652            -c "a session has been resumed"
3653
3654requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3655run_test    "Session resume using tickets: openssl server" \
3656            "$O_SRV -tls1_2" \
3657            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3658            0 \
3659            -c "client hello, adding session ticket extension" \
3660            -c "found session_ticket extension" \
3661            -c "parse new session ticket" \
3662            -c "a session has been resumed"
3663
3664requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3665run_test    "Session resume using tickets: openssl client" \
3666            "$P_SRV debug_level=3 tickets=1" \
3667            "( $O_CLI -sess_out $SESSION; \
3668               $O_CLI -sess_in $SESSION; \
3669               rm -f $SESSION )" \
3670            0 \
3671            -s "found session ticket extension" \
3672            -s "server hello, adding session ticket extension" \
3673            -S "session successfully restored from cache" \
3674            -s "session successfully restored from ticket" \
3675            -s "a session has been resumed"
3676
3677requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3678run_test    "Session resume using tickets: AES-128-GCM" \
3679            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-128-GCM" \
3680            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3681            0 \
3682            -c "client hello, adding session ticket extension" \
3683            -s "found session ticket extension" \
3684            -s "server hello, adding session ticket extension" \
3685            -c "found session_ticket extension" \
3686            -c "parse new session ticket" \
3687            -S "session successfully restored from cache" \
3688            -s "session successfully restored from ticket" \
3689            -s "a session has been resumed" \
3690            -c "a session has been resumed"
3691
3692requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3693run_test    "Session resume using tickets: AES-192-GCM" \
3694            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-192-GCM" \
3695            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3696            0 \
3697            -c "client hello, adding session ticket extension" \
3698            -s "found session ticket extension" \
3699            -s "server hello, adding session ticket extension" \
3700            -c "found session_ticket extension" \
3701            -c "parse new session ticket" \
3702            -S "session successfully restored from cache" \
3703            -s "session successfully restored from ticket" \
3704            -s "a session has been resumed" \
3705            -c "a session has been resumed"
3706
3707requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3708run_test    "Session resume using tickets: AES-128-CCM" \
3709            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-128-CCM" \
3710            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3711            0 \
3712            -c "client hello, adding session ticket extension" \
3713            -s "found session ticket extension" \
3714            -s "server hello, adding session ticket extension" \
3715            -c "found session_ticket extension" \
3716            -c "parse new session ticket" \
3717            -S "session successfully restored from cache" \
3718            -s "session successfully restored from ticket" \
3719            -s "a session has been resumed" \
3720            -c "a session has been resumed"
3721
3722requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3723run_test    "Session resume using tickets: AES-192-CCM" \
3724            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-192-CCM" \
3725            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3726            0 \
3727            -c "client hello, adding session ticket extension" \
3728            -s "found session ticket extension" \
3729            -s "server hello, adding session ticket extension" \
3730            -c "found session_ticket extension" \
3731            -c "parse new session ticket" \
3732            -S "session successfully restored from cache" \
3733            -s "session successfully restored from ticket" \
3734            -s "a session has been resumed" \
3735            -c "a session has been resumed"
3736
3737requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3738run_test    "Session resume using tickets: AES-256-CCM" \
3739            "$P_SRV debug_level=3 tickets=1 ticket_aead=AES-256-CCM" \
3740            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3741            0 \
3742            -c "client hello, adding session ticket extension" \
3743            -s "found session ticket extension" \
3744            -s "server hello, adding session ticket extension" \
3745            -c "found session_ticket extension" \
3746            -c "parse new session ticket" \
3747            -S "session successfully restored from cache" \
3748            -s "session successfully restored from ticket" \
3749            -s "a session has been resumed" \
3750            -c "a session has been resumed"
3751
3752requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3753run_test    "Session resume using tickets: CAMELLIA-128-CCM" \
3754            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-128-CCM" \
3755            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3756            0 \
3757            -c "client hello, adding session ticket extension" \
3758            -s "found session ticket extension" \
3759            -s "server hello, adding session ticket extension" \
3760            -c "found session_ticket extension" \
3761            -c "parse new session ticket" \
3762            -S "session successfully restored from cache" \
3763            -s "session successfully restored from ticket" \
3764            -s "a session has been resumed" \
3765            -c "a session has been resumed"
3766
3767requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3768run_test    "Session resume using tickets: CAMELLIA-192-CCM" \
3769            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-192-CCM" \
3770            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3771            0 \
3772            -c "client hello, adding session ticket extension" \
3773            -s "found session ticket extension" \
3774            -s "server hello, adding session ticket extension" \
3775            -c "found session_ticket extension" \
3776            -c "parse new session ticket" \
3777            -S "session successfully restored from cache" \
3778            -s "session successfully restored from ticket" \
3779            -s "a session has been resumed" \
3780            -c "a session has been resumed"
3781
3782requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3783run_test    "Session resume using tickets: CAMELLIA-256-CCM" \
3784            "$P_SRV debug_level=3 tickets=1 ticket_aead=CAMELLIA-256-CCM" \
3785            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3786            0 \
3787            -c "client hello, adding session ticket extension" \
3788            -s "found session ticket extension" \
3789            -s "server hello, adding session ticket extension" \
3790            -c "found session_ticket extension" \
3791            -c "parse new session ticket" \
3792            -S "session successfully restored from cache" \
3793            -s "session successfully restored from ticket" \
3794            -s "a session has been resumed" \
3795            -c "a session has been resumed"
3796
3797requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3798run_test    "Session resume using tickets: ARIA-128-GCM" \
3799            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-128-GCM" \
3800            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3801            0 \
3802            -c "client hello, adding session ticket extension" \
3803            -s "found session ticket extension" \
3804            -s "server hello, adding session ticket extension" \
3805            -c "found session_ticket extension" \
3806            -c "parse new session ticket" \
3807            -S "session successfully restored from cache" \
3808            -s "session successfully restored from ticket" \
3809            -s "a session has been resumed" \
3810            -c "a session has been resumed"
3811
3812requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3813run_test    "Session resume using tickets: ARIA-192-GCM" \
3814            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-192-GCM" \
3815            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3816            0 \
3817            -c "client hello, adding session ticket extension" \
3818            -s "found session ticket extension" \
3819            -s "server hello, adding session ticket extension" \
3820            -c "found session_ticket extension" \
3821            -c "parse new session ticket" \
3822            -S "session successfully restored from cache" \
3823            -s "session successfully restored from ticket" \
3824            -s "a session has been resumed" \
3825            -c "a session has been resumed"
3826
3827requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3828run_test    "Session resume using tickets: ARIA-256-GCM" \
3829            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-256-GCM" \
3830            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3831            0 \
3832            -c "client hello, adding session ticket extension" \
3833            -s "found session ticket extension" \
3834            -s "server hello, adding session ticket extension" \
3835            -c "found session_ticket extension" \
3836            -c "parse new session ticket" \
3837            -S "session successfully restored from cache" \
3838            -s "session successfully restored from ticket" \
3839            -s "a session has been resumed" \
3840            -c "a session has been resumed"
3841
3842requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3843run_test    "Session resume using tickets: ARIA-128-CCM" \
3844            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-128-CCM" \
3845            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3846            0 \
3847            -c "client hello, adding session ticket extension" \
3848            -s "found session ticket extension" \
3849            -s "server hello, adding session ticket extension" \
3850            -c "found session_ticket extension" \
3851            -c "parse new session ticket" \
3852            -S "session successfully restored from cache" \
3853            -s "session successfully restored from ticket" \
3854            -s "a session has been resumed" \
3855            -c "a session has been resumed"
3856
3857requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3858run_test    "Session resume using tickets: ARIA-192-CCM" \
3859            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-192-CCM" \
3860            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3861            0 \
3862            -c "client hello, adding session ticket extension" \
3863            -s "found session ticket extension" \
3864            -s "server hello, adding session ticket extension" \
3865            -c "found session_ticket extension" \
3866            -c "parse new session ticket" \
3867            -S "session successfully restored from cache" \
3868            -s "session successfully restored from ticket" \
3869            -s "a session has been resumed" \
3870            -c "a session has been resumed"
3871
3872requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3873run_test    "Session resume using tickets: ARIA-256-CCM" \
3874            "$P_SRV debug_level=3 tickets=1 ticket_aead=ARIA-256-CCM" \
3875            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3876            0 \
3877            -c "client hello, adding session ticket extension" \
3878            -s "found session ticket extension" \
3879            -s "server hello, adding session ticket extension" \
3880            -c "found session_ticket extension" \
3881            -c "parse new session ticket" \
3882            -S "session successfully restored from cache" \
3883            -s "session successfully restored from ticket" \
3884            -s "a session has been resumed" \
3885            -c "a session has been resumed"
3886
3887requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3888run_test    "Session resume using tickets: CHACHA20-POLY1305" \
3889            "$P_SRV debug_level=3 tickets=1 ticket_aead=CHACHA20-POLY1305" \
3890            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3891            0 \
3892            -c "client hello, adding session ticket extension" \
3893            -s "found session ticket extension" \
3894            -s "server hello, adding session ticket extension" \
3895            -c "found session_ticket extension" \
3896            -c "parse new session ticket" \
3897            -S "session successfully restored from cache" \
3898            -s "session successfully restored from ticket" \
3899            -s "a session has been resumed" \
3900            -c "a session has been resumed"
3901
3902# Tests for Session Tickets with DTLS
3903
3904requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3905run_test    "Session resume using tickets, DTLS: basic" \
3906            "$P_SRV debug_level=3 dtls=1 tickets=1" \
3907            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1" \
3908            0 \
3909            -c "client hello, adding session ticket extension" \
3910            -s "found session ticket extension" \
3911            -s "server hello, adding session ticket extension" \
3912            -c "found session_ticket extension" \
3913            -c "parse new session ticket" \
3914            -S "session successfully restored from cache" \
3915            -s "session successfully restored from ticket" \
3916            -s "a session has been resumed" \
3917            -c "a session has been resumed"
3918
3919requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3920run_test    "Session resume using tickets, DTLS: cache disabled" \
3921            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0" \
3922            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1" \
3923            0 \
3924            -c "client hello, adding session ticket extension" \
3925            -s "found session ticket extension" \
3926            -s "server hello, adding session ticket extension" \
3927            -c "found session_ticket extension" \
3928            -c "parse new session ticket" \
3929            -S "session successfully restored from cache" \
3930            -s "session successfully restored from ticket" \
3931            -s "a session has been resumed" \
3932            -c "a session has been resumed"
3933
3934requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3935run_test    "Session resume using tickets, DTLS: timeout" \
3936            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0 ticket_timeout=1" \
3937            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1 reco_delay=2" \
3938            0 \
3939            -c "client hello, adding session ticket extension" \
3940            -s "found session ticket extension" \
3941            -s "server hello, adding session ticket extension" \
3942            -c "found session_ticket extension" \
3943            -c "parse new session ticket" \
3944            -S "session successfully restored from cache" \
3945            -S "session successfully restored from ticket" \
3946            -S "a session has been resumed" \
3947            -C "a session has been resumed"
3948
3949requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3950run_test    "Session resume using tickets, DTLS: session copy" \
3951            "$P_SRV debug_level=3 dtls=1 tickets=1 cache_max=0" \
3952            "$P_CLI debug_level=3 dtls=1 tickets=1 reconnect=1 skip_close_notify=1 reco_mode=0" \
3953            0 \
3954            -c "client hello, adding session ticket extension" \
3955            -s "found session ticket extension" \
3956            -s "server hello, adding session ticket extension" \
3957            -c "found session_ticket extension" \
3958            -c "parse new session ticket" \
3959            -S "session successfully restored from cache" \
3960            -s "session successfully restored from ticket" \
3961            -s "a session has been resumed" \
3962            -c "a session has been resumed"
3963
3964requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3965run_test    "Session resume using tickets, DTLS: openssl server" \
3966            "$O_SRV -dtls" \
3967            "$P_CLI dtls=1 debug_level=3 tickets=1 reconnect=1" \
3968            0 \
3969            -c "client hello, adding session ticket extension" \
3970            -c "found session_ticket extension" \
3971            -c "parse new session ticket" \
3972            -c "a session has been resumed"
3973
3974# For reasons that aren't fully understood, this test randomly fails with high
3975# probability with OpenSSL 1.0.2g on the CI, see #5012.
3976requires_openssl_next
3977requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3978run_test    "Session resume using tickets, DTLS: openssl client" \
3979            "$P_SRV dtls=1 debug_level=3 tickets=1" \
3980            "( $O_NEXT_CLI -dtls -sess_out $SESSION; \
3981               $O_NEXT_CLI -dtls -sess_in $SESSION; \
3982               rm -f $SESSION )" \
3983            0 \
3984            -s "found session ticket extension" \
3985            -s "server hello, adding session ticket extension" \
3986            -S "session successfully restored from cache" \
3987            -s "session successfully restored from ticket" \
3988            -s "a session has been resumed"
3989
3990# Tests for Session Resume based on session-ID and cache
3991
3992requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
3993requires_config_enabled MBEDTLS_SSL_CACHE_C
3994run_test    "Session resume using cache: tickets enabled on client" \
3995            "$P_SRV debug_level=3 tickets=0" \
3996            "$P_CLI debug_level=3 tickets=1 reconnect=1" \
3997            0 \
3998            -c "client hello, adding session ticket extension" \
3999            -s "found session ticket extension" \
4000            -S "server hello, adding session ticket extension" \
4001            -C "found session_ticket extension" \
4002            -C "parse new session ticket" \
4003            -s "session successfully restored from cache" \
4004            -S "session successfully restored from ticket" \
4005            -s "a session has been resumed" \
4006            -c "a session has been resumed"
4007
4008requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4009requires_config_enabled MBEDTLS_SSL_CACHE_C
4010run_test    "Session resume using cache: tickets enabled on server" \
4011            "$P_SRV debug_level=3 tickets=1" \
4012            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4013            0 \
4014            -C "client hello, adding session ticket extension" \
4015            -S "found session ticket extension" \
4016            -S "server hello, adding session ticket extension" \
4017            -C "found session_ticket extension" \
4018            -C "parse new session ticket" \
4019            -s "session successfully restored from cache" \
4020            -S "session successfully restored from ticket" \
4021            -s "a session has been resumed" \
4022            -c "a session has been resumed"
4023
4024requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4025requires_config_enabled MBEDTLS_SSL_CACHE_C
4026run_test    "Session resume using cache: cache_max=0" \
4027            "$P_SRV debug_level=3 tickets=0 cache_max=0" \
4028            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4029            0 \
4030            -S "session successfully restored from cache" \
4031            -S "session successfully restored from ticket" \
4032            -S "a session has been resumed" \
4033            -C "a session has been resumed"
4034
4035requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4036requires_config_enabled MBEDTLS_SSL_CACHE_C
4037run_test    "Session resume using cache: cache_max=1" \
4038            "$P_SRV debug_level=3 tickets=0 cache_max=1" \
4039            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4040            0 \
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
4047requires_config_enabled MBEDTLS_SSL_CACHE_C
4048run_test    "Session resume using cache: timeout > delay" \
4049            "$P_SRV debug_level=3 tickets=0" \
4050            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
4051            0 \
4052            -s "session successfully restored from cache" \
4053            -S "session successfully restored from ticket" \
4054            -s "a session has been resumed" \
4055            -c "a session has been resumed"
4056
4057requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4058requires_config_enabled MBEDTLS_SSL_CACHE_C
4059run_test    "Session resume using cache: timeout < delay" \
4060            "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
4061            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
4062            0 \
4063            -S "session successfully restored from cache" \
4064            -S "session successfully restored from ticket" \
4065            -S "a session has been resumed" \
4066            -C "a session has been resumed"
4067
4068requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4069requires_config_enabled MBEDTLS_SSL_CACHE_C
4070run_test    "Session resume using cache: no timeout" \
4071            "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
4072            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
4073            0 \
4074            -s "session successfully restored from cache" \
4075            -S "session successfully restored from ticket" \
4076            -s "a session has been resumed" \
4077            -c "a session has been resumed"
4078
4079requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4080requires_config_enabled MBEDTLS_SSL_CACHE_C
4081run_test    "Session resume using cache: session copy" \
4082            "$P_SRV debug_level=3 tickets=0" \
4083            "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_mode=0" \
4084            0 \
4085            -s "session successfully restored from cache" \
4086            -S "session successfully restored from ticket" \
4087            -s "a session has been resumed" \
4088            -c "a session has been resumed"
4089
4090requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4091requires_config_enabled MBEDTLS_SSL_CACHE_C
4092run_test    "Session resume using cache: openssl client" \
4093            "$P_SRV debug_level=3 tickets=0" \
4094            "( $O_CLI -sess_out $SESSION; \
4095               $O_CLI -sess_in $SESSION; \
4096               rm -f $SESSION )" \
4097            0 \
4098            -s "found session ticket extension" \
4099            -S "server hello, adding session ticket extension" \
4100            -s "session successfully restored from cache" \
4101            -S "session successfully restored from ticket" \
4102            -s "a session has been resumed"
4103
4104requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4105requires_config_enabled MBEDTLS_SSL_CACHE_C
4106run_test    "Session resume using cache: openssl server" \
4107            "$O_SRV -tls1_2" \
4108            "$P_CLI debug_level=3 tickets=0 reconnect=1" \
4109            0 \
4110            -C "found session_ticket extension" \
4111            -C "parse new session ticket" \
4112            -c "a session has been resumed"
4113
4114# Tests for Session resume and extensions
4115
4116requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4117requires_config_enabled MBEDTLS_SSL_DTLS_CONNECTION_ID
4118run_test    "Session resume and connection ID" \
4119            "$P_SRV debug_level=3 cid=1 cid_val=dead dtls=1 tickets=0" \
4120            "$P_CLI debug_level=3 cid=1 cid_val=beef dtls=1 tickets=0 reconnect=1" \
4121            0 \
4122            -c "Enable use of CID extension." \
4123            -s "Enable use of CID extension." \
4124            -c "client hello, adding CID extension" \
4125            -s "found CID extension"           \
4126            -s "Use of CID extension negotiated" \
4127            -s "server hello, adding CID extension" \
4128            -c "found CID extension" \
4129            -c "Use of CID extension negotiated" \
4130            -s "Copy CIDs into SSL transform" \
4131            -c "Copy CIDs into SSL transform" \
4132            -c "Peer CID (length 2 Bytes): de ad" \
4133            -s "Peer CID (length 2 Bytes): be ef" \
4134            -s "Use of Connection ID has been negotiated" \
4135            -c "Use of Connection ID has been negotiated"
4136
4137# Tests for Session Resume based on session-ID and cache, DTLS
4138
4139requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4140requires_config_enabled MBEDTLS_SSL_CACHE_C
4141run_test    "Session resume using cache, DTLS: tickets enabled on client" \
4142            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4143            "$P_CLI dtls=1 debug_level=3 tickets=1 reconnect=1 skip_close_notify=1" \
4144            0 \
4145            -c "client hello, adding session ticket extension" \
4146            -s "found session ticket extension" \
4147            -S "server hello, adding session ticket extension" \
4148            -C "found session_ticket extension" \
4149            -C "parse new session ticket" \
4150            -s "session successfully restored from cache" \
4151            -S "session successfully restored from ticket" \
4152            -s "a session has been resumed" \
4153            -c "a session has been resumed"
4154
4155requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4156requires_config_enabled MBEDTLS_SSL_CACHE_C
4157run_test    "Session resume using cache, DTLS: tickets enabled on server" \
4158            "$P_SRV dtls=1 debug_level=3 tickets=1" \
4159            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4160            0 \
4161            -C "client hello, adding session ticket extension" \
4162            -S "found session ticket extension" \
4163            -S "server hello, adding session ticket extension" \
4164            -C "found session_ticket extension" \
4165            -C "parse new session ticket" \
4166            -s "session successfully restored from cache" \
4167            -S "session successfully restored from ticket" \
4168            -s "a session has been resumed" \
4169            -c "a session has been resumed"
4170
4171requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4172requires_config_enabled MBEDTLS_SSL_CACHE_C
4173run_test    "Session resume using cache, DTLS: cache_max=0" \
4174            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_max=0" \
4175            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4176            0 \
4177            -S "session successfully restored from cache" \
4178            -S "session successfully restored from ticket" \
4179            -S "a session has been resumed" \
4180            -C "a session has been resumed"
4181
4182requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4183requires_config_enabled MBEDTLS_SSL_CACHE_C
4184run_test    "Session resume using cache, DTLS: cache_max=1" \
4185            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_max=1" \
4186            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1" \
4187            0 \
4188            -s "session successfully restored from cache" \
4189            -S "session successfully restored from ticket" \
4190            -s "a session has been resumed" \
4191            -c "a session has been resumed"
4192
4193requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4194requires_config_enabled MBEDTLS_SSL_CACHE_C
4195run_test    "Session resume using cache, DTLS: timeout > delay" \
4196            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4197            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=0" \
4198            0 \
4199            -s "session successfully restored from cache" \
4200            -S "session successfully restored from ticket" \
4201            -s "a session has been resumed" \
4202            -c "a session has been resumed"
4203
4204requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4205requires_config_enabled MBEDTLS_SSL_CACHE_C
4206run_test    "Session resume using cache, DTLS: timeout < delay" \
4207            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_timeout=1" \
4208            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=2" \
4209            0 \
4210            -S "session successfully restored from cache" \
4211            -S "session successfully restored from ticket" \
4212            -S "a session has been resumed" \
4213            -C "a session has been resumed"
4214
4215requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4216requires_config_enabled MBEDTLS_SSL_CACHE_C
4217run_test    "Session resume using cache, DTLS: no timeout" \
4218            "$P_SRV dtls=1 debug_level=3 tickets=0 cache_timeout=0" \
4219            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_delay=2" \
4220            0 \
4221            -s "session successfully restored from cache" \
4222            -S "session successfully restored from ticket" \
4223            -s "a session has been resumed" \
4224            -c "a session has been resumed"
4225
4226requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4227requires_config_enabled MBEDTLS_SSL_CACHE_C
4228run_test    "Session resume using cache, DTLS: session copy" \
4229            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4230            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1 skip_close_notify=1 reco_mode=0" \
4231            0 \
4232            -s "session successfully restored from cache" \
4233            -S "session successfully restored from ticket" \
4234            -s "a session has been resumed" \
4235            -c "a session has been resumed"
4236
4237# For reasons that aren't fully understood, this test randomly fails with high
4238# probability with OpenSSL 1.0.2g on the CI, see #5012.
4239requires_openssl_next
4240requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4241requires_config_enabled MBEDTLS_SSL_CACHE_C
4242run_test    "Session resume using cache, DTLS: openssl client" \
4243            "$P_SRV dtls=1 debug_level=3 tickets=0" \
4244            "( $O_NEXT_CLI -dtls -sess_out $SESSION; \
4245               $O_NEXT_CLI -dtls -sess_in $SESSION; \
4246               rm -f $SESSION )" \
4247            0 \
4248            -s "found session ticket extension" \
4249            -S "server hello, adding session ticket extension" \
4250            -s "session successfully restored from cache" \
4251            -S "session successfully restored from ticket" \
4252            -s "a session has been resumed"
4253
4254requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4255requires_config_enabled MBEDTLS_SSL_CACHE_C
4256run_test    "Session resume using cache, DTLS: openssl server" \
4257            "$O_SRV -dtls" \
4258            "$P_CLI dtls=1 debug_level=3 tickets=0 reconnect=1" \
4259            0 \
4260            -C "found session_ticket extension" \
4261            -C "parse new session ticket" \
4262            -c "a session has been resumed"
4263
4264# Tests for Max Fragment Length extension
4265
4266requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4267requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4268run_test    "Max fragment length: enabled, default" \
4269            "$P_SRV debug_level=3" \
4270            "$P_CLI debug_level=3" \
4271            0 \
4272            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4273            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4274            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4275            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4276            -C "client hello, adding max_fragment_length extension" \
4277            -S "found max fragment length extension" \
4278            -S "server hello, max_fragment_length extension" \
4279            -C "found max_fragment_length extension"
4280
4281requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4282requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4283run_test    "Max fragment length: enabled, default, larger message" \
4284            "$P_SRV debug_level=3" \
4285            "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4286            0 \
4287            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4288            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4289            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4290            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4291            -C "client hello, adding max_fragment_length extension" \
4292            -S "found max fragment length extension" \
4293            -S "server hello, max_fragment_length extension" \
4294            -C "found max_fragment_length extension" \
4295            -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
4296            -s "$MAX_CONTENT_LEN bytes read" \
4297            -s "1 bytes read"
4298
4299requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4300requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4301run_test    "Max fragment length, DTLS: enabled, default, larger message" \
4302            "$P_SRV debug_level=3 dtls=1" \
4303            "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4304            1 \
4305            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4306            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4307            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4308            -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4309            -C "client hello, adding max_fragment_length extension" \
4310            -S "found max fragment length extension" \
4311            -S "server hello, max_fragment_length extension" \
4312            -C "found max_fragment_length extension" \
4313            -c "fragment larger than.*maximum "
4314
4315# Run some tests with MBEDTLS_SSL_MAX_FRAGMENT_LENGTH disabled
4316# (session fragment length will be 16384 regardless of mbedtls
4317# content length configuration.)
4318
4319requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4320requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4321run_test    "Max fragment length: disabled, larger message" \
4322            "$P_SRV debug_level=3" \
4323            "$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4324            0 \
4325            -C "Maximum incoming record payload length is 16384" \
4326            -C "Maximum outgoing record payload length is 16384" \
4327            -S "Maximum incoming record payload length is 16384" \
4328            -S "Maximum outgoing record payload length is 16384" \
4329            -c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
4330            -s "$MAX_CONTENT_LEN bytes read" \
4331            -s "1 bytes read"
4332
4333requires_config_disabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4334requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4335run_test    "Max fragment length, DTLS: disabled, larger message" \
4336            "$P_SRV debug_level=3 dtls=1" \
4337            "$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
4338            1 \
4339            -C "Maximum incoming record payload length is 16384" \
4340            -C "Maximum outgoing record payload length is 16384" \
4341            -S "Maximum incoming record payload length is 16384" \
4342            -S "Maximum outgoing record payload length is 16384" \
4343            -c "fragment larger than.*maximum "
4344
4345requires_max_content_len 4096
4346requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4347requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4348run_test    "Max fragment length: used by client" \
4349            "$P_SRV debug_level=3" \
4350            "$P_CLI debug_level=3 max_frag_len=4096" \
4351            0 \
4352            -c "Maximum incoming record payload length is 4096" \
4353            -c "Maximum outgoing record payload length is 4096" \
4354            -s "Maximum incoming record payload length is 4096" \
4355            -s "Maximum outgoing record payload length is 4096" \
4356            -c "client hello, adding max_fragment_length extension" \
4357            -s "found max fragment length extension" \
4358            -s "server hello, max_fragment_length extension" \
4359            -c "found max_fragment_length extension"
4360
4361requires_max_content_len 1024
4362requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4363requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4364run_test    "Max fragment length: client 512, server 1024" \
4365            "$P_SRV debug_level=3 max_frag_len=1024" \
4366            "$P_CLI debug_level=3 max_frag_len=512" \
4367            0 \
4368            -c "Maximum incoming record payload length is 512" \
4369            -c "Maximum outgoing record payload length is 512" \
4370            -s "Maximum incoming record payload length is 512" \
4371            -s "Maximum outgoing record payload length is 512" \
4372            -c "client hello, adding max_fragment_length extension" \
4373            -s "found max fragment length extension" \
4374            -s "server hello, max_fragment_length extension" \
4375            -c "found max_fragment_length extension"
4376
4377requires_max_content_len 2048
4378requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4379requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4380run_test    "Max fragment length: client 512, server 2048" \
4381            "$P_SRV debug_level=3 max_frag_len=2048" \
4382            "$P_CLI debug_level=3 max_frag_len=512" \
4383            0 \
4384            -c "Maximum incoming record payload length is 512" \
4385            -c "Maximum outgoing record payload length is 512" \
4386            -s "Maximum incoming record payload length is 512" \
4387            -s "Maximum outgoing record payload length is 512" \
4388            -c "client hello, adding max_fragment_length extension" \
4389            -s "found max fragment length extension" \
4390            -s "server hello, max_fragment_length extension" \
4391            -c "found max_fragment_length extension"
4392
4393requires_max_content_len 4096
4394requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4395requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4396run_test    "Max fragment length: client 512, server 4096" \
4397            "$P_SRV debug_level=3 max_frag_len=4096" \
4398            "$P_CLI debug_level=3 max_frag_len=512" \
4399            0 \
4400            -c "Maximum incoming record payload length is 512" \
4401            -c "Maximum outgoing record payload length is 512" \
4402            -s "Maximum incoming record payload length is 512" \
4403            -s "Maximum outgoing record payload length is 512" \
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
4409requires_max_content_len 1024
4410requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4411requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4412run_test    "Max fragment length: client 1024, server 512" \
4413            "$P_SRV debug_level=3 max_frag_len=512" \
4414            "$P_CLI debug_level=3 max_frag_len=1024" \
4415            0 \
4416            -c "Maximum incoming record payload length is 1024" \
4417            -c "Maximum outgoing record payload length is 1024" \
4418            -s "Maximum incoming record payload length is 1024" \
4419            -s "Maximum outgoing record payload length is 512" \
4420            -c "client hello, adding max_fragment_length extension" \
4421            -s "found max fragment length extension" \
4422            -s "server hello, max_fragment_length extension" \
4423            -c "found max_fragment_length extension"
4424
4425requires_max_content_len 2048
4426requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4427requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4428run_test    "Max fragment length: client 1024, server 2048" \
4429            "$P_SRV debug_level=3 max_frag_len=2048" \
4430            "$P_CLI debug_level=3 max_frag_len=1024" \
4431            0 \
4432            -c "Maximum incoming record payload length is 1024" \
4433            -c "Maximum outgoing record payload length is 1024" \
4434            -s "Maximum incoming record payload length is 1024" \
4435            -s "Maximum outgoing record payload length is 1024" \
4436            -c "client hello, adding max_fragment_length extension" \
4437            -s "found max fragment length extension" \
4438            -s "server hello, max_fragment_length extension" \
4439            -c "found max_fragment_length extension"
4440
4441requires_max_content_len 4096
4442requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4443requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4444run_test    "Max fragment length: client 1024, server 4096" \
4445            "$P_SRV debug_level=3 max_frag_len=4096" \
4446            "$P_CLI debug_level=3 max_frag_len=1024" \
4447            0 \
4448            -c "Maximum incoming record payload length is 1024" \
4449            -c "Maximum outgoing record payload length is 1024" \
4450            -s "Maximum incoming record payload length is 1024" \
4451            -s "Maximum outgoing record payload length is 1024" \
4452            -c "client hello, adding max_fragment_length extension" \
4453            -s "found max fragment length extension" \
4454            -s "server hello, max_fragment_length extension" \
4455            -c "found max_fragment_length extension"
4456
4457requires_max_content_len 2048
4458requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4459requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4460run_test    "Max fragment length: client 2048, server 512" \
4461            "$P_SRV debug_level=3 max_frag_len=512" \
4462            "$P_CLI debug_level=3 max_frag_len=2048" \
4463            0 \
4464            -c "Maximum incoming record payload length is 2048" \
4465            -c "Maximum outgoing record payload length is 2048" \
4466            -s "Maximum incoming record payload length is 2048" \
4467            -s "Maximum outgoing record payload length is 512" \
4468            -c "client hello, adding max_fragment_length extension" \
4469            -s "found max fragment length extension" \
4470            -s "server hello, max_fragment_length extension" \
4471            -c "found max_fragment_length extension"
4472
4473requires_max_content_len 2048
4474requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4475requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4476run_test    "Max fragment length: client 2048, server 1024" \
4477            "$P_SRV debug_level=3 max_frag_len=1024" \
4478            "$P_CLI debug_level=3 max_frag_len=2048" \
4479            0 \
4480            -c "Maximum incoming record payload length is 2048" \
4481            -c "Maximum outgoing record payload length is 2048" \
4482            -s "Maximum incoming record payload length is 2048" \
4483            -s "Maximum outgoing record payload length is 1024" \
4484            -c "client hello, adding max_fragment_length extension" \
4485            -s "found max fragment length extension" \
4486            -s "server hello, max_fragment_length extension" \
4487            -c "found max_fragment_length extension"
4488
4489requires_max_content_len 4096
4490requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4491requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4492run_test    "Max fragment length: client 2048, server 4096" \
4493            "$P_SRV debug_level=3 max_frag_len=4096" \
4494            "$P_CLI debug_level=3 max_frag_len=2048" \
4495            0 \
4496            -c "Maximum incoming record payload length is 2048" \
4497            -c "Maximum outgoing record payload length is 2048" \
4498            -s "Maximum incoming record payload length is 2048" \
4499            -s "Maximum outgoing record payload length is 2048" \
4500            -c "client hello, adding max_fragment_length extension" \
4501            -s "found max fragment length extension" \
4502            -s "server hello, max_fragment_length extension" \
4503            -c "found max_fragment_length extension"
4504
4505requires_max_content_len 4096
4506requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4507requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4508run_test    "Max fragment length: client 4096, server 512" \
4509            "$P_SRV debug_level=3 max_frag_len=512" \
4510            "$P_CLI debug_level=3 max_frag_len=4096" \
4511            0 \
4512            -c "Maximum incoming record payload length is 4096" \
4513            -c "Maximum outgoing record payload length is 4096" \
4514            -s "Maximum incoming record payload length is 4096" \
4515            -s "Maximum outgoing record payload length is 512" \
4516            -c "client hello, adding max_fragment_length extension" \
4517            -s "found max fragment length extension" \
4518            -s "server hello, max_fragment_length extension" \
4519            -c "found max_fragment_length extension"
4520
4521requires_max_content_len 4096
4522requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4523requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4524run_test    "Max fragment length: client 4096, server 1024" \
4525            "$P_SRV debug_level=3 max_frag_len=1024" \
4526            "$P_CLI debug_level=3 max_frag_len=4096" \
4527            0 \
4528            -c "Maximum incoming record payload length is 4096" \
4529            -c "Maximum outgoing record payload length is 4096" \
4530            -s "Maximum incoming record payload length is 4096" \
4531            -s "Maximum outgoing record payload length is 1024" \
4532            -c "client hello, adding max_fragment_length extension" \
4533            -s "found max fragment length extension" \
4534            -s "server hello, max_fragment_length extension" \
4535            -c "found max_fragment_length extension"
4536
4537requires_max_content_len 4096
4538requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4539requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4540run_test    "Max fragment length: client 4096, server 2048" \
4541            "$P_SRV debug_level=3 max_frag_len=2048" \
4542            "$P_CLI debug_level=3 max_frag_len=4096" \
4543            0 \
4544            -c "Maximum incoming record payload length is 4096" \
4545            -c "Maximum outgoing record payload length is 4096" \
4546            -s "Maximum incoming record payload length is 4096" \
4547            -s "Maximum outgoing record payload length is 2048" \
4548            -c "client hello, adding max_fragment_length extension" \
4549            -s "found max fragment length extension" \
4550            -s "server hello, max_fragment_length extension" \
4551            -c "found max_fragment_length extension"
4552
4553requires_max_content_len 4096
4554requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4555requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4556run_test    "Max fragment length: used by server" \
4557            "$P_SRV debug_level=3 max_frag_len=4096" \
4558            "$P_CLI debug_level=3" \
4559            0 \
4560            -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4561            -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
4562            -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
4563            -s "Maximum outgoing record payload length is 4096" \
4564            -C "client hello, adding max_fragment_length extension" \
4565            -S "found max fragment length extension" \
4566            -S "server hello, max_fragment_length extension" \
4567            -C "found max_fragment_length extension"
4568
4569requires_max_content_len 4096
4570requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4571requires_gnutls
4572requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4573run_test    "Max fragment length: gnutls server" \
4574            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
4575            "$P_CLI debug_level=3 max_frag_len=4096" \
4576            0 \
4577            -c "Maximum incoming record payload length is 4096" \
4578            -c "Maximum outgoing record payload length is 4096" \
4579            -c "client hello, adding max_fragment_length extension" \
4580            -c "found max_fragment_length extension"
4581
4582requires_max_content_len 2048
4583requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4584requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4585run_test    "Max fragment length: client, message just fits" \
4586            "$P_SRV debug_level=3" \
4587            "$P_CLI debug_level=3 max_frag_len=2048 request_size=2048" \
4588            0 \
4589            -c "Maximum incoming record payload length is 2048" \
4590            -c "Maximum outgoing record payload length is 2048" \
4591            -s "Maximum incoming record payload length is 2048" \
4592            -s "Maximum outgoing record payload length is 2048" \
4593            -c "client hello, adding max_fragment_length extension" \
4594            -s "found max fragment length extension" \
4595            -s "server hello, max_fragment_length extension" \
4596            -c "found max_fragment_length extension" \
4597            -c "2048 bytes written in 1 fragments" \
4598            -s "2048 bytes read"
4599
4600requires_max_content_len 2048
4601requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4602requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4603run_test    "Max fragment length: client, larger message" \
4604            "$P_SRV debug_level=3" \
4605            "$P_CLI debug_level=3 max_frag_len=2048 request_size=2345" \
4606            0 \
4607            -c "Maximum incoming record payload length is 2048" \
4608            -c "Maximum outgoing record payload length is 2048" \
4609            -s "Maximum incoming record payload length is 2048" \
4610            -s "Maximum outgoing record payload length is 2048" \
4611            -c "client hello, adding max_fragment_length extension" \
4612            -s "found max fragment length extension" \
4613            -s "server hello, max_fragment_length extension" \
4614            -c "found max_fragment_length extension" \
4615            -c "2345 bytes written in 2 fragments" \
4616            -s "2048 bytes read" \
4617            -s "297 bytes read"
4618
4619requires_max_content_len 2048
4620requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4621requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4622run_test    "Max fragment length: DTLS client, larger message" \
4623            "$P_SRV debug_level=3 dtls=1" \
4624            "$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
4625            1 \
4626            -c "Maximum incoming record payload length is 2048" \
4627            -c "Maximum outgoing record payload length is 2048" \
4628            -s "Maximum incoming record payload length is 2048" \
4629            -s "Maximum outgoing record payload length is 2048" \
4630            -c "client hello, adding max_fragment_length extension" \
4631            -s "found max fragment length extension" \
4632            -s "server hello, max_fragment_length extension" \
4633            -c "found max_fragment_length extension" \
4634            -c "fragment larger than.*maximum"
4635
4636# Tests for renegotiation
4637
4638# Renegotiation SCSV always added, regardless of SSL_RENEGOTIATION
4639requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4640run_test    "Renegotiation: none, for reference" \
4641            "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \
4642            "$P_CLI debug_level=3 exchanges=2" \
4643            0 \
4644            -C "client hello, adding renegotiation extension" \
4645            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4646            -S "found renegotiation extension" \
4647            -s "server hello, secure renegotiation extension" \
4648            -c "found renegotiation extension" \
4649            -C "=> renegotiate" \
4650            -S "=> renegotiate" \
4651            -S "write hello request"
4652
4653requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4654requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4655run_test    "Renegotiation: client-initiated" \
4656            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
4657            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4658            0 \
4659            -c "client hello, adding renegotiation extension" \
4660            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4661            -s "found renegotiation extension" \
4662            -s "server hello, secure renegotiation extension" \
4663            -c "found renegotiation extension" \
4664            -c "=> renegotiate" \
4665            -s "=> renegotiate" \
4666            -S "write hello request"
4667
4668requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4669requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4670run_test    "Renegotiation: server-initiated" \
4671            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
4672            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
4673            0 \
4674            -c "client hello, adding renegotiation extension" \
4675            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4676            -s "found renegotiation extension" \
4677            -s "server hello, secure renegotiation extension" \
4678            -c "found renegotiation extension" \
4679            -c "=> renegotiate" \
4680            -s "=> renegotiate" \
4681            -s "write hello request"
4682
4683# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
4684# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
4685# algorithm stronger than SHA-1 is enabled in mbedtls_config.h
4686requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4687requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4688run_test    "Renegotiation: Signature Algorithms parsing, client-initiated" \
4689            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
4690            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4691            0 \
4692            -c "client hello, adding renegotiation extension" \
4693            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4694            -s "found renegotiation extension" \
4695            -s "server hello, secure renegotiation extension" \
4696            -c "found renegotiation extension" \
4697            -c "=> renegotiate" \
4698            -s "=> renegotiate" \
4699            -S "write hello request" \
4700            -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
4701
4702# Checks that no Signature Algorithm with SHA-1 gets negotiated. Negotiating SHA-1 would mean that
4703# the server did not parse the Signature Algorithm extension. This test is valid only if an MD
4704# algorithm stronger than SHA-1 is enabled in mbedtls_config.h
4705requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4706requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4707run_test    "Renegotiation: Signature Algorithms parsing, server-initiated" \
4708            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
4709            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
4710            0 \
4711            -c "client hello, adding renegotiation extension" \
4712            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4713            -s "found renegotiation extension" \
4714            -s "server hello, secure renegotiation extension" \
4715            -c "found renegotiation extension" \
4716            -c "=> renegotiate" \
4717            -s "=> renegotiate" \
4718            -s "write hello request" \
4719            -S "client hello v3, signature_algorithm ext: 2" # Is SHA-1 negotiated?
4720
4721requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4722requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4723run_test    "Renegotiation: double" \
4724            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
4725            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4726            0 \
4727            -c "client hello, adding renegotiation extension" \
4728            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4729            -s "found renegotiation extension" \
4730            -s "server hello, secure renegotiation extension" \
4731            -c "found renegotiation extension" \
4732            -c "=> renegotiate" \
4733            -s "=> renegotiate" \
4734            -s "write hello request"
4735
4736requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4737requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4738requires_max_content_len 2048
4739requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4740run_test    "Renegotiation with max fragment length: client 2048, server 512" \
4741            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1 max_frag_len=512" \
4742            "$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" \
4743            0 \
4744            -c "Maximum incoming record payload length is 2048" \
4745            -c "Maximum outgoing record payload length is 2048" \
4746            -s "Maximum incoming record payload length is 2048" \
4747            -s "Maximum outgoing record payload length is 512" \
4748            -c "client hello, adding max_fragment_length extension" \
4749            -s "found max fragment length extension" \
4750            -s "server hello, max_fragment_length extension" \
4751            -c "found max_fragment_length extension" \
4752            -c "client hello, adding renegotiation extension" \
4753            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4754            -s "found renegotiation extension" \
4755            -s "server hello, secure renegotiation extension" \
4756            -c "found renegotiation extension" \
4757            -c "=> renegotiate" \
4758            -s "=> renegotiate" \
4759            -s "write hello request"
4760
4761requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4762requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4763run_test    "Renegotiation: client-initiated, server-rejected" \
4764            "$P_SRV debug_level=3 exchanges=2 renegotiation=0 auth_mode=optional" \
4765            "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
4766            1 \
4767            -c "client hello, adding renegotiation extension" \
4768            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4769            -S "found renegotiation extension" \
4770            -s "server hello, secure renegotiation extension" \
4771            -c "found renegotiation extension" \
4772            -c "=> renegotiate" \
4773            -S "=> renegotiate" \
4774            -S "write hello request" \
4775            -c "SSL - Unexpected message at ServerHello in renegotiation" \
4776            -c "failed"
4777
4778requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4779requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4780run_test    "Renegotiation: server-initiated, client-rejected, default" \
4781            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
4782            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
4783            0 \
4784            -C "client hello, adding renegotiation extension" \
4785            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4786            -S "found renegotiation extension" \
4787            -s "server hello, secure renegotiation extension" \
4788            -c "found renegotiation extension" \
4789            -C "=> renegotiate" \
4790            -S "=> renegotiate" \
4791            -s "write hello request" \
4792            -S "SSL - An unexpected message was received from our peer" \
4793            -S "failed"
4794
4795requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4796requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4797run_test    "Renegotiation: server-initiated, client-rejected, not enforced" \
4798            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
4799             renego_delay=-1 auth_mode=optional" \
4800            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
4801            0 \
4802            -C "client hello, adding renegotiation extension" \
4803            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4804            -S "found renegotiation extension" \
4805            -s "server hello, secure renegotiation extension" \
4806            -c "found renegotiation extension" \
4807            -C "=> renegotiate" \
4808            -S "=> renegotiate" \
4809            -s "write hello request" \
4810            -S "SSL - An unexpected message was received from our peer" \
4811            -S "failed"
4812
4813# delay 2 for 1 alert record + 1 application data record
4814requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4815requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4816run_test    "Renegotiation: server-initiated, client-rejected, delay 2" \
4817            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
4818             renego_delay=2 auth_mode=optional" \
4819            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
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            -S "SSL - An unexpected message was received from our peer" \
4830            -S "failed"
4831
4832requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4833requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4834run_test    "Renegotiation: server-initiated, client-rejected, delay 0" \
4835            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
4836             renego_delay=0 auth_mode=optional" \
4837            "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
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 "SSL - An unexpected message was received from our peer"
4848
4849requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4850requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4851run_test    "Renegotiation: server-initiated, client-accepted, delay 0" \
4852            "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
4853             renego_delay=0 auth_mode=optional" \
4854            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
4855            0 \
4856            -c "client hello, adding renegotiation extension" \
4857            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4858            -s "found renegotiation extension" \
4859            -s "server hello, secure renegotiation extension" \
4860            -c "found renegotiation extension" \
4861            -c "=> renegotiate" \
4862            -s "=> renegotiate" \
4863            -s "write hello request" \
4864            -S "SSL - An unexpected message was received from our peer" \
4865            -S "failed"
4866
4867requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4868requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4869run_test    "Renegotiation: periodic, just below period" \
4870            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
4871            "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
4872            0 \
4873            -C "client hello, adding renegotiation extension" \
4874            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4875            -S "found renegotiation extension" \
4876            -s "server hello, secure renegotiation extension" \
4877            -c "found renegotiation extension" \
4878            -S "record counter limit reached: renegotiate" \
4879            -C "=> renegotiate" \
4880            -S "=> renegotiate" \
4881            -S "write hello request" \
4882            -S "SSL - An unexpected message was received from our peer" \
4883            -S "failed"
4884
4885# one extra exchange to be able to complete renego
4886requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4887requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4888run_test    "Renegotiation: periodic, just above period" \
4889            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
4890            "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
4891            0 \
4892            -c "client hello, adding renegotiation extension" \
4893            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4894            -s "found renegotiation extension" \
4895            -s "server hello, secure renegotiation extension" \
4896            -c "found renegotiation extension" \
4897            -s "record counter limit reached: renegotiate" \
4898            -c "=> renegotiate" \
4899            -s "=> renegotiate" \
4900            -s "write hello request" \
4901            -S "SSL - An unexpected message was received from our peer" \
4902            -S "failed"
4903
4904requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4905requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4906run_test    "Renegotiation: periodic, two times period" \
4907            "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
4908            "$P_CLI debug_level=3 exchanges=7 renegotiation=1" \
4909            0 \
4910            -c "client hello, adding renegotiation extension" \
4911            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4912            -s "found renegotiation extension" \
4913            -s "server hello, secure renegotiation extension" \
4914            -c "found renegotiation extension" \
4915            -s "record counter limit reached: renegotiate" \
4916            -c "=> renegotiate" \
4917            -s "=> renegotiate" \
4918            -s "write hello request" \
4919            -S "SSL - An unexpected message was received from our peer" \
4920            -S "failed"
4921
4922requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4923requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4924run_test    "Renegotiation: periodic, above period, disabled" \
4925            "$P_SRV debug_level=3 exchanges=9 renegotiation=0 renego_period=3 auth_mode=optional" \
4926            "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
4927            0 \
4928            -C "client hello, adding renegotiation extension" \
4929            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4930            -S "found renegotiation extension" \
4931            -s "server hello, secure renegotiation extension" \
4932            -c "found renegotiation extension" \
4933            -S "record counter limit reached: renegotiate" \
4934            -C "=> renegotiate" \
4935            -S "=> renegotiate" \
4936            -S "write hello request" \
4937            -S "SSL - An unexpected message was received from our peer" \
4938            -S "failed"
4939
4940requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4941requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4942run_test    "Renegotiation: nbio, client-initiated" \
4943            "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 auth_mode=optional" \
4944            "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
4945            0 \
4946            -c "client hello, adding renegotiation extension" \
4947            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4948            -s "found renegotiation extension" \
4949            -s "server hello, secure renegotiation extension" \
4950            -c "found renegotiation extension" \
4951            -c "=> renegotiate" \
4952            -s "=> renegotiate" \
4953            -S "write hello request"
4954
4955requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4956requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4957run_test    "Renegotiation: nbio, server-initiated" \
4958            "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
4959            "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
4960            0 \
4961            -c "client hello, adding renegotiation extension" \
4962            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
4963            -s "found renegotiation extension" \
4964            -s "server hello, secure renegotiation extension" \
4965            -c "found renegotiation extension" \
4966            -c "=> renegotiate" \
4967            -s "=> renegotiate" \
4968            -s "write hello request"
4969
4970requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4971requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4972run_test    "Renegotiation: openssl server, client-initiated" \
4973            "$O_SRV -www -tls1_2" \
4974            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
4975            0 \
4976            -c "client hello, adding renegotiation extension" \
4977            -c "found renegotiation extension" \
4978            -c "=> renegotiate" \
4979            -C "ssl_hanshake() returned" \
4980            -C "error" \
4981            -c "HTTP/1.0 200 [Oo][Kk]"
4982
4983requires_gnutls
4984requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4985requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
4986run_test    "Renegotiation: gnutls server strict, client-initiated" \
4987            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \
4988            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
4989            0 \
4990            -c "client hello, adding renegotiation extension" \
4991            -c "found renegotiation extension" \
4992            -c "=> renegotiate" \
4993            -C "ssl_hanshake() returned" \
4994            -C "error" \
4995            -c "HTTP/1.0 200 [Oo][Kk]"
4996
4997requires_gnutls
4998requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
4999requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5000run_test    "Renegotiation: gnutls server unsafe, client-initiated default" \
5001            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5002            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
5003            1 \
5004            -c "client hello, adding renegotiation extension" \
5005            -C "found renegotiation extension" \
5006            -c "=> renegotiate" \
5007            -c "mbedtls_ssl_handshake() returned" \
5008            -c "error" \
5009            -C "HTTP/1.0 200 [Oo][Kk]"
5010
5011requires_gnutls
5012requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5013requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5014run_test    "Renegotiation: gnutls server unsafe, client-inititated no legacy" \
5015            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5016            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
5017             allow_legacy=0" \
5018            1 \
5019            -c "client hello, adding renegotiation extension" \
5020            -C "found renegotiation extension" \
5021            -c "=> renegotiate" \
5022            -c "mbedtls_ssl_handshake() returned" \
5023            -c "error" \
5024            -C "HTTP/1.0 200 [Oo][Kk]"
5025
5026requires_gnutls
5027requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5028requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5029run_test    "Renegotiation: gnutls server unsafe, client-inititated legacy" \
5030            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5031            "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
5032             allow_legacy=1" \
5033            0 \
5034            -c "client hello, adding renegotiation extension" \
5035            -C "found renegotiation extension" \
5036            -c "=> renegotiate" \
5037            -C "ssl_hanshake() returned" \
5038            -C "error" \
5039            -c "HTTP/1.0 200 [Oo][Kk]"
5040
5041requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5042requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5043run_test    "Renegotiation: DTLS, client-initiated" \
5044            "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
5045            "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
5046            0 \
5047            -c "client hello, adding renegotiation extension" \
5048            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5049            -s "found renegotiation extension" \
5050            -s "server hello, secure renegotiation extension" \
5051            -c "found renegotiation extension" \
5052            -c "=> renegotiate" \
5053            -s "=> renegotiate" \
5054            -S "write hello request"
5055
5056requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5057requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5058run_test    "Renegotiation: DTLS, server-initiated" \
5059            "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
5060            "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
5061             read_timeout=1000 max_resend=2" \
5062            0 \
5063            -c "client hello, adding renegotiation extension" \
5064            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5065            -s "found renegotiation extension" \
5066            -s "server hello, secure renegotiation extension" \
5067            -c "found renegotiation extension" \
5068            -c "=> renegotiate" \
5069            -s "=> renegotiate" \
5070            -s "write hello request"
5071
5072requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5073requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5074run_test    "Renegotiation: DTLS, renego_period overflow" \
5075            "$P_SRV debug_level=3 dtls=1 exchanges=4 renegotiation=1 renego_period=18446462598732840962 auth_mode=optional" \
5076            "$P_CLI debug_level=3 dtls=1 exchanges=4 renegotiation=1" \
5077            0 \
5078            -c "client hello, adding renegotiation extension" \
5079            -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
5080            -s "found renegotiation extension" \
5081            -s "server hello, secure renegotiation extension" \
5082            -s "record counter limit reached: renegotiate" \
5083            -c "=> renegotiate" \
5084            -s "=> renegotiate" \
5085            -s "write hello request"
5086
5087requires_gnutls
5088requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
5089requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5090run_test    "Renegotiation: DTLS, gnutls server, client-initiated" \
5091            "$G_SRV -u --mtu 4096" \
5092            "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
5093            0 \
5094            -c "client hello, adding renegotiation extension" \
5095            -c "found renegotiation extension" \
5096            -c "=> renegotiate" \
5097            -C "mbedtls_ssl_handshake returned" \
5098            -C "error" \
5099            -s "Extra-header:"
5100
5101# Test for the "secure renegotiation" extension only (no actual renegotiation)
5102
5103requires_gnutls
5104requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5105run_test    "Renego ext: gnutls server strict, client default" \
5106            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \
5107            "$P_CLI debug_level=3" \
5108            0 \
5109            -c "found renegotiation extension" \
5110            -C "error" \
5111            -c "HTTP/1.0 200 [Oo][Kk]"
5112
5113requires_gnutls
5114requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5115run_test    "Renego ext: gnutls server unsafe, client default" \
5116            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5117            "$P_CLI debug_level=3" \
5118            0 \
5119            -C "found renegotiation extension" \
5120            -C "error" \
5121            -c "HTTP/1.0 200 [Oo][Kk]"
5122
5123requires_gnutls
5124requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5125run_test    "Renego ext: gnutls server unsafe, client break legacy" \
5126            "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \
5127            "$P_CLI debug_level=3 allow_legacy=-1" \
5128            1 \
5129            -C "found renegotiation extension" \
5130            -c "error" \
5131            -C "HTTP/1.0 200 [Oo][Kk]"
5132
5133requires_gnutls
5134requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5135run_test    "Renego ext: gnutls client strict, server default" \
5136            "$P_SRV debug_level=3" \
5137            "$G_CLI --priority=NORMAL:%SAFE_RENEGOTIATION localhost" \
5138            0 \
5139            -s "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5140            -s "server hello, secure renegotiation extension"
5141
5142requires_gnutls
5143requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5144run_test    "Renego ext: gnutls client unsafe, server default" \
5145            "$P_SRV debug_level=3" \
5146            "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION localhost" \
5147            0 \
5148            -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5149            -S "server hello, secure renegotiation extension"
5150
5151requires_gnutls
5152requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5153run_test    "Renego ext: gnutls client unsafe, server break legacy" \
5154            "$P_SRV debug_level=3 allow_legacy=-1" \
5155            "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION localhost" \
5156            1 \
5157            -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
5158            -S "server hello, secure renegotiation extension"
5159
5160# Tests for silently dropping trailing extra bytes in .der certificates
5161
5162requires_gnutls
5163requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5164run_test    "DER format: no trailing bytes" \
5165            "$P_SRV crt_file=data_files/server5-der0.crt \
5166             key_file=data_files/server5.key" \
5167            "$G_CLI localhost" \
5168            0 \
5169            -c "Handshake was completed" \
5170
5171requires_gnutls
5172requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5173run_test    "DER format: with a trailing zero byte" \
5174            "$P_SRV crt_file=data_files/server5-der1a.crt \
5175             key_file=data_files/server5.key" \
5176            "$G_CLI localhost" \
5177            0 \
5178            -c "Handshake was completed" \
5179
5180requires_gnutls
5181requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5182run_test    "DER format: with a trailing random byte" \
5183            "$P_SRV crt_file=data_files/server5-der1b.crt \
5184             key_file=data_files/server5.key" \
5185            "$G_CLI localhost" \
5186            0 \
5187            -c "Handshake was completed" \
5188
5189requires_gnutls
5190requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5191run_test    "DER format: with 2 trailing random bytes" \
5192            "$P_SRV crt_file=data_files/server5-der2.crt \
5193             key_file=data_files/server5.key" \
5194            "$G_CLI localhost" \
5195            0 \
5196            -c "Handshake was completed" \
5197
5198requires_gnutls
5199requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5200run_test    "DER format: with 4 trailing random bytes" \
5201            "$P_SRV crt_file=data_files/server5-der4.crt \
5202             key_file=data_files/server5.key" \
5203            "$G_CLI localhost" \
5204            0 \
5205            -c "Handshake was completed" \
5206
5207requires_gnutls
5208requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5209run_test    "DER format: with 8 trailing random bytes" \
5210            "$P_SRV crt_file=data_files/server5-der8.crt \
5211             key_file=data_files/server5.key" \
5212            "$G_CLI localhost" \
5213            0 \
5214            -c "Handshake was completed" \
5215
5216requires_gnutls
5217requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5218run_test    "DER format: with 9 trailing random bytes" \
5219            "$P_SRV crt_file=data_files/server5-der9.crt \
5220             key_file=data_files/server5.key" \
5221            "$G_CLI localhost" \
5222            0 \
5223            -c "Handshake was completed" \
5224
5225# Tests for auth_mode, there are duplicated tests using ca callback for authentication
5226# When updating these tests, modify the matching authentication tests accordingly
5227
5228requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5229run_test    "Authentication: server badcert, client required" \
5230            "$P_SRV crt_file=data_files/server5-badsign.crt \
5231             key_file=data_files/server5.key" \
5232            "$P_CLI debug_level=1 auth_mode=required" \
5233            1 \
5234            -c "x509_verify_cert() returned" \
5235            -c "! The certificate is not correctly signed by the trusted CA" \
5236            -c "! mbedtls_ssl_handshake returned" \
5237            -c "X509 - Certificate verification failed"
5238
5239requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5240requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5241run_test    "Authentication: server badcert, client optional" \
5242            "$P_SRV crt_file=data_files/server5-badsign.crt \
5243             key_file=data_files/server5.key" \
5244            "$P_CLI debug_level=1 auth_mode=optional" \
5245            0 \
5246            -c "x509_verify_cert() returned" \
5247            -c "! The certificate is not correctly signed by the trusted CA" \
5248            -C "! mbedtls_ssl_handshake returned" \
5249            -C "X509 - Certificate verification failed"
5250
5251requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5252requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5253run_test    "Authentication: server goodcert, client optional, no trusted CA" \
5254            "$P_SRV" \
5255            "$P_CLI debug_level=3 auth_mode=optional ca_file=none ca_path=none" \
5256            0 \
5257            -c "x509_verify_cert() returned" \
5258            -c "! The certificate is not correctly signed by the trusted CA" \
5259            -c "! Certificate verification flags"\
5260            -C "! mbedtls_ssl_handshake returned" \
5261            -C "X509 - Certificate verification failed" \
5262            -C "SSL - No CA Chain is set, but required to operate"
5263
5264requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5265run_test    "Authentication: server goodcert, client required, no trusted CA" \
5266            "$P_SRV" \
5267            "$P_CLI debug_level=3 auth_mode=required ca_file=none ca_path=none" \
5268            1 \
5269            -c "x509_verify_cert() returned" \
5270            -c "! The certificate is not correctly signed by the trusted CA" \
5271            -c "! Certificate verification flags"\
5272            -c "! mbedtls_ssl_handshake returned" \
5273            -c "SSL - No CA Chain is set, but required to operate"
5274
5275# The purpose of the next two tests is to test the client's behaviour when receiving a server
5276# certificate with an unsupported elliptic curve. This should usually not happen because
5277# the client informs the server about the supported curves - it does, though, in the
5278# corner case of a static ECDH suite, because the server doesn't check the curve on that
5279# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
5280# different means to have the server ignoring the client's supported curve list.
5281
5282requires_config_enabled MBEDTLS_ECP_C
5283requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5284requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5285run_test    "Authentication: server ECDH p256v1, client required, p256v1 unsupported" \
5286            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5287             crt_file=data_files/server5.ku-ka.crt" \
5288            "$P_CLI debug_level=3 auth_mode=required curves=secp521r1" \
5289            1 \
5290            -c "bad certificate (EC key curve)"\
5291            -c "! Certificate verification flags"\
5292            -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
5293
5294requires_config_enabled MBEDTLS_ECP_C
5295requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5296requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5297run_test    "Authentication: server ECDH p256v1, client optional, p256v1 unsupported" \
5298            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5299             crt_file=data_files/server5.ku-ka.crt" \
5300            "$P_CLI debug_level=3 auth_mode=optional curves=secp521r1" \
5301            1 \
5302            -c "bad certificate (EC key curve)"\
5303            -c "! Certificate verification flags"\
5304            -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
5305
5306requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5307requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5308run_test    "Authentication: server badcert, client none" \
5309            "$P_SRV crt_file=data_files/server5-badsign.crt \
5310             key_file=data_files/server5.key" \
5311            "$P_CLI debug_level=1 auth_mode=none" \
5312            0 \
5313            -C "x509_verify_cert() returned" \
5314            -C "! The certificate is not correctly signed by the trusted CA" \
5315            -C "! mbedtls_ssl_handshake returned" \
5316            -C "X509 - Certificate verification failed"
5317
5318requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5319requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5320run_test    "Authentication: client SHA256, server required" \
5321            "$P_SRV auth_mode=required" \
5322            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5323             key_file=data_files/server6.key \
5324             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
5325            0 \
5326            -c "Supported Signature Algorithm found: 04 " \
5327            -c "Supported Signature Algorithm found: 05 "
5328
5329requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5330requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5331run_test    "Authentication: client SHA384, server required" \
5332            "$P_SRV auth_mode=required" \
5333            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5334             key_file=data_files/server6.key \
5335             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
5336            0 \
5337            -c "Supported Signature Algorithm found: 04 " \
5338            -c "Supported Signature Algorithm found: 05 "
5339
5340requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5341run_test    "Authentication: client has no cert, server required (TLS)" \
5342            "$P_SRV debug_level=3 auth_mode=required" \
5343            "$P_CLI debug_level=3 crt_file=none \
5344             key_file=data_files/server5.key" \
5345            1 \
5346            -S "skip write certificate request" \
5347            -C "skip parse certificate request" \
5348            -c "got a certificate request" \
5349            -c "= write certificate$" \
5350            -C "skip write certificate$" \
5351            -S "x509_verify_cert() returned" \
5352            -s "peer has no certificate" \
5353            -s "! mbedtls_ssl_handshake returned" \
5354            -s "No client certification received from the client, but required by the authentication mode"
5355
5356requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5357run_test    "Authentication: client badcert, server required" \
5358            "$P_SRV debug_level=3 auth_mode=required" \
5359            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5360             key_file=data_files/server5.key" \
5361            1 \
5362            -S "skip write certificate request" \
5363            -C "skip parse certificate request" \
5364            -c "got a certificate request" \
5365            -C "skip write certificate" \
5366            -C "skip write certificate verify" \
5367            -S "skip parse certificate verify" \
5368            -s "x509_verify_cert() returned" \
5369            -s "! The certificate is not correctly signed by the trusted CA" \
5370            -s "! mbedtls_ssl_handshake returned" \
5371            -s "send alert level=2 message=48" \
5372            -s "X509 - Certificate verification failed"
5373# We don't check that the client receives the alert because it might
5374# detect that its write end of the connection is closed and abort
5375# before reading the alert message.
5376
5377requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5378run_test    "Authentication: client cert self-signed and trusted, server required" \
5379            "$P_SRV debug_level=3 auth_mode=required ca_file=data_files/server5-selfsigned.crt" \
5380            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5381             key_file=data_files/server5.key" \
5382            0 \
5383            -S "skip write certificate request" \
5384            -C "skip parse certificate request" \
5385            -c "got a certificate request" \
5386            -C "skip write certificate" \
5387            -C "skip write certificate verify" \
5388            -S "skip parse certificate verify" \
5389            -S "x509_verify_cert() returned" \
5390            -S "! The certificate is not correctly signed" \
5391            -S "X509 - Certificate verification failed"
5392
5393requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5394run_test    "Authentication: client cert not trusted, server required" \
5395            "$P_SRV debug_level=3 auth_mode=required" \
5396            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5397             key_file=data_files/server5.key" \
5398            1 \
5399            -S "skip write certificate request" \
5400            -C "skip parse certificate request" \
5401            -c "got a certificate request" \
5402            -C "skip write certificate" \
5403            -C "skip write certificate verify" \
5404            -S "skip parse certificate verify" \
5405            -s "x509_verify_cert() returned" \
5406            -s "! The certificate is not correctly signed by the trusted CA" \
5407            -s "! mbedtls_ssl_handshake returned" \
5408            -s "X509 - Certificate verification failed"
5409
5410requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5411run_test    "Authentication: client badcert, server optional" \
5412            "$P_SRV debug_level=3 auth_mode=optional" \
5413            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5414             key_file=data_files/server5.key" \
5415            0 \
5416            -S "skip write certificate request" \
5417            -C "skip parse certificate request" \
5418            -c "got a certificate request" \
5419            -C "skip write certificate" \
5420            -C "skip write certificate verify" \
5421            -S "skip parse certificate verify" \
5422            -s "x509_verify_cert() returned" \
5423            -s "! The certificate is not correctly signed by the trusted CA" \
5424            -S "! mbedtls_ssl_handshake returned" \
5425            -C "! mbedtls_ssl_handshake returned" \
5426            -S "X509 - Certificate verification failed"
5427
5428requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5429run_test    "Authentication: client badcert, server none" \
5430            "$P_SRV debug_level=3 auth_mode=none" \
5431            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5432             key_file=data_files/server5.key" \
5433            0 \
5434            -s "skip write certificate request" \
5435            -C "skip parse certificate request" \
5436            -c "got no certificate request" \
5437            -c "skip write certificate" \
5438            -c "skip write certificate verify" \
5439            -s "skip parse certificate verify" \
5440            -S "x509_verify_cert() returned" \
5441            -S "! The certificate is not correctly signed by the trusted CA" \
5442            -S "! mbedtls_ssl_handshake returned" \
5443            -C "! mbedtls_ssl_handshake returned" \
5444            -S "X509 - Certificate verification failed"
5445
5446requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5447run_test    "Authentication: client no cert, server optional" \
5448            "$P_SRV debug_level=3 auth_mode=optional" \
5449            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5450            0 \
5451            -S "skip write certificate request" \
5452            -C "skip parse certificate request" \
5453            -c "got a certificate request" \
5454            -C "skip write certificate$" \
5455            -C "got no certificate to send" \
5456            -c "skip write certificate verify" \
5457            -s "skip parse certificate verify" \
5458            -s "! Certificate was missing" \
5459            -S "! mbedtls_ssl_handshake returned" \
5460            -C "! mbedtls_ssl_handshake returned" \
5461            -S "X509 - Certificate verification failed"
5462
5463requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5464requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5465run_test    "Authentication: openssl client no cert, server optional" \
5466            "$P_SRV debug_level=3 auth_mode=optional" \
5467            "$O_CLI" \
5468            0 \
5469            -S "skip write certificate request" \
5470            -s "skip parse certificate verify" \
5471            -s "! Certificate was missing" \
5472            -S "! mbedtls_ssl_handshake returned" \
5473            -S "X509 - Certificate verification failed"
5474
5475requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5476requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5477run_test    "Authentication: client no cert, openssl server optional" \
5478            "$O_SRV -verify 10 -tls1_2" \
5479            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5480            0 \
5481            -C "skip parse certificate request" \
5482            -c "got a certificate request" \
5483            -C "skip write certificate$" \
5484            -c "skip write certificate verify" \
5485            -C "! mbedtls_ssl_handshake returned"
5486
5487requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5488requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5489run_test    "Authentication: client no cert, openssl server required" \
5490            "$O_SRV -Verify 10 -tls1_2" \
5491            "$P_CLI debug_level=3 crt_file=none key_file=none" \
5492            1 \
5493            -C "skip parse certificate request" \
5494            -c "got a certificate request" \
5495            -C "skip write certificate$" \
5496            -c "skip write certificate verify" \
5497            -c "! mbedtls_ssl_handshake returned"
5498
5499# This script assumes that MBEDTLS_X509_MAX_INTERMEDIATE_CA has its default
5500# value, defined here as MAX_IM_CA. Some test cases will be skipped if the
5501# library is configured with a different value.
5502
5503MAX_IM_CA='8'
5504
5505# The tests for the max_int tests can pass with any number higher than MAX_IM_CA
5506# because only a chain of MAX_IM_CA length is tested. Equally, the max_int+1
5507# tests can pass with any number less than MAX_IM_CA. However, stricter preconditions
5508# are in place so that the semantics are consistent with the test description.
5509requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5510requires_full_size_output_buffer
5511requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5512run_test    "Authentication: server max_int chain, client default" \
5513            "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
5514                    key_file=data_files/dir-maxpath/09.key" \
5515            "$P_CLI server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
5516            0 \
5517            -C "X509 - A fatal error occurred"
5518
5519requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5520requires_full_size_output_buffer
5521requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5522run_test    "Authentication: server max_int+1 chain, client default" \
5523            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5524                    key_file=data_files/dir-maxpath/10.key" \
5525            "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
5526            1 \
5527            -c "X509 - A fatal error occurred"
5528
5529requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5530requires_full_size_output_buffer
5531requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5532requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5533run_test    "Authentication: server max_int+1 chain, client optional" \
5534            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5535                    key_file=data_files/dir-maxpath/10.key" \
5536            "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
5537                    auth_mode=optional" \
5538            1 \
5539            -c "X509 - A fatal error occurred"
5540
5541requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5542requires_full_size_output_buffer
5543requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5544requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5545run_test    "Authentication: server max_int+1 chain, client none" \
5546            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5547                    key_file=data_files/dir-maxpath/10.key" \
5548            "$P_CLI server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
5549                    auth_mode=none" \
5550            0 \
5551            -C "X509 - A fatal error occurred"
5552
5553requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5554requires_full_size_output_buffer
5555requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5556run_test    "Authentication: client max_int+1 chain, server default" \
5557            "$P_SRV ca_file=data_files/dir-maxpath/00.crt" \
5558            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5559                    key_file=data_files/dir-maxpath/10.key" \
5560            0 \
5561            -S "X509 - A fatal error occurred"
5562
5563requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5564requires_full_size_output_buffer
5565requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5566run_test    "Authentication: client max_int+1 chain, server optional" \
5567            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
5568            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5569                    key_file=data_files/dir-maxpath/10.key" \
5570            1 \
5571            -s "X509 - A fatal error occurred"
5572
5573requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5574requires_full_size_output_buffer
5575requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5576run_test    "Authentication: client max_int+1 chain, server required" \
5577            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
5578            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5579                    key_file=data_files/dir-maxpath/10.key" \
5580            1 \
5581            -s "X509 - A fatal error occurred"
5582
5583requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5584requires_full_size_output_buffer
5585requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5586run_test    "Authentication: client max_int chain, server required" \
5587            "$P_SRV ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
5588            "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
5589                    key_file=data_files/dir-maxpath/09.key" \
5590            0 \
5591            -S "X509 - A fatal error occurred"
5592
5593# Tests for CA list in CertificateRequest messages
5594
5595requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5596requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5597run_test    "Authentication: send CA list in CertificateRequest  (default)" \
5598            "$P_SRV debug_level=3 auth_mode=required" \
5599            "$P_CLI crt_file=data_files/server6.crt \
5600             key_file=data_files/server6.key" \
5601            0 \
5602            -s "requested DN"
5603
5604requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5605requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5606run_test    "Authentication: do not send CA list in CertificateRequest" \
5607            "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
5608            "$P_CLI crt_file=data_files/server6.crt \
5609             key_file=data_files/server6.key" \
5610            0 \
5611            -S "requested DN"
5612
5613requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5614requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5615run_test    "Authentication: send CA list in CertificateRequest, client self signed" \
5616            "$P_SRV debug_level=3 auth_mode=required cert_req_ca_list=0" \
5617            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5618             key_file=data_files/server5.key" \
5619            1 \
5620            -S "requested DN" \
5621            -s "x509_verify_cert() returned" \
5622            -s "! The certificate is not correctly signed by the trusted CA" \
5623            -s "! mbedtls_ssl_handshake returned" \
5624            -c "! mbedtls_ssl_handshake returned" \
5625            -s "X509 - Certificate verification failed"
5626
5627requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5628requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5629run_test    "Authentication: send alt conf DN hints in CertificateRequest" \
5630            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=2 \
5631             crt_file2=data_files/server1.crt \
5632             key_file2=data_files/server1.key" \
5633            "$P_CLI debug_level=3 auth_mode=optional \
5634             crt_file=data_files/server6.crt \
5635             key_file=data_files/server6.key" \
5636            0 \
5637            -c "DN hint: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
5638
5639requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5640requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5641run_test    "Authentication: send alt conf DN hints in CertificateRequest (2)" \
5642            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=2 \
5643             crt_file2=data_files/server2.crt \
5644             key_file2=data_files/server2.key" \
5645            "$P_CLI debug_level=3 auth_mode=optional \
5646             crt_file=data_files/server6.crt \
5647             key_file=data_files/server6.key" \
5648            0 \
5649            -c "DN hint: C=NL, O=PolarSSL, CN=localhost"
5650
5651requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5652requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5653run_test    "Authentication: send alt hs DN hints in CertificateRequest" \
5654            "$P_SRV debug_level=3 auth_mode=optional cert_req_ca_list=3 \
5655             crt_file2=data_files/server1.crt \
5656             key_file2=data_files/server1.key" \
5657            "$P_CLI debug_level=3 auth_mode=optional \
5658             crt_file=data_files/server6.crt \
5659             key_file=data_files/server6.key" \
5660            0 \
5661            -c "DN hint: C=NL, O=PolarSSL, CN=PolarSSL Server 1"
5662
5663# Tests for auth_mode, using CA callback, these are duplicated from the authentication tests
5664# When updating these tests, modify the matching authentication tests accordingly
5665
5666requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5667requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5668requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5669run_test    "Authentication, CA callback: server badcert, client required" \
5670            "$P_SRV crt_file=data_files/server5-badsign.crt \
5671             key_file=data_files/server5.key" \
5672            "$P_CLI ca_callback=1 debug_level=3 auth_mode=required" \
5673            1 \
5674            -c "use CA callback for X.509 CRT verification" \
5675            -c "x509_verify_cert() returned" \
5676            -c "! The certificate is not correctly signed by the trusted CA" \
5677            -c "! mbedtls_ssl_handshake returned" \
5678            -c "X509 - Certificate verification failed"
5679
5680requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5681requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5682requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5683run_test    "Authentication, CA callback: server badcert, client optional" \
5684            "$P_SRV crt_file=data_files/server5-badsign.crt \
5685             key_file=data_files/server5.key" \
5686            "$P_CLI ca_callback=1 debug_level=3 auth_mode=optional" \
5687            0 \
5688            -c "use CA callback for X.509 CRT verification" \
5689            -c "x509_verify_cert() returned" \
5690            -c "! The certificate is not correctly signed by the trusted CA" \
5691            -C "! mbedtls_ssl_handshake returned" \
5692            -C "X509 - Certificate verification failed"
5693
5694# The purpose of the next two tests is to test the client's behaviour when receiving a server
5695# certificate with an unsupported elliptic curve. This should usually not happen because
5696# the client informs the server about the supported curves - it does, though, in the
5697# corner case of a static ECDH suite, because the server doesn't check the curve on that
5698# occasion (to be fixed). If that bug's fixed, the test needs to be altered to use a
5699# different means to have the server ignoring the client's supported curve list.
5700
5701requires_config_enabled MBEDTLS_ECP_C
5702requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5703requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5704requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5705run_test    "Authentication, CA callback: server ECDH p256v1, client required, p256v1 unsupported" \
5706            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5707             crt_file=data_files/server5.ku-ka.crt" \
5708            "$P_CLI ca_callback=1 debug_level=3 auth_mode=required curves=secp521r1" \
5709            1 \
5710            -c "use CA callback for X.509 CRT verification" \
5711            -c "bad certificate (EC key curve)" \
5712            -c "! Certificate verification flags" \
5713            -C "bad server certificate (ECDH curve)" # Expect failure at earlier verification stage
5714
5715requires_config_enabled MBEDTLS_ECP_C
5716requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5717requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5718requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5719run_test    "Authentication, CA callback: server ECDH p256v1, client optional, p256v1 unsupported" \
5720            "$P_SRV debug_level=1 key_file=data_files/server5.key \
5721             crt_file=data_files/server5.ku-ka.crt" \
5722            "$P_CLI ca_callback=1 debug_level=3 auth_mode=optional curves=secp521r1" \
5723            1 \
5724            -c "use CA callback for X.509 CRT verification" \
5725            -c "bad certificate (EC key curve)"\
5726            -c "! Certificate verification flags"\
5727            -c "bad server certificate (ECDH curve)" # Expect failure only at ECDH params check
5728
5729requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5730requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5731requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5732run_test    "Authentication, CA callback: client SHA256, server required" \
5733            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5734            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5735             key_file=data_files/server6.key \
5736             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
5737            0 \
5738            -s "use CA callback for X.509 CRT verification" \
5739            -c "Supported Signature Algorithm found: 04 " \
5740            -c "Supported Signature Algorithm found: 05 "
5741
5742requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5743requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5744requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5745run_test    "Authentication, CA callback: client SHA384, server required" \
5746            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5747            "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
5748             key_file=data_files/server6.key \
5749             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
5750            0 \
5751            -s "use CA callback for X.509 CRT verification" \
5752            -c "Supported Signature Algorithm found: 04 " \
5753            -c "Supported Signature Algorithm found: 05 "
5754
5755requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5756requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5757requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5758run_test    "Authentication, CA callback: client badcert, server required" \
5759            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5760            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5761             key_file=data_files/server5.key" \
5762            1 \
5763            -s "use CA callback for X.509 CRT verification" \
5764            -S "skip write certificate request" \
5765            -C "skip parse certificate request" \
5766            -c "got a certificate request" \
5767            -C "skip write certificate" \
5768            -C "skip write certificate verify" \
5769            -S "skip parse certificate verify" \
5770            -s "x509_verify_cert() returned" \
5771            -s "! The certificate is not correctly signed by the trusted CA" \
5772            -s "! mbedtls_ssl_handshake returned" \
5773            -s "send alert level=2 message=48" \
5774            -c "! mbedtls_ssl_handshake returned" \
5775            -s "X509 - Certificate verification failed"
5776# We don't check that the client receives the alert because it might
5777# detect that its write end of the connection is closed and abort
5778# before reading the alert message.
5779
5780requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5781requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5782requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5783run_test    "Authentication, CA callback: client cert not trusted, server required" \
5784            "$P_SRV ca_callback=1 debug_level=3 auth_mode=required" \
5785            "$P_CLI debug_level=3 crt_file=data_files/server5-selfsigned.crt \
5786             key_file=data_files/server5.key" \
5787            1 \
5788            -s "use CA callback for X.509 CRT verification" \
5789            -S "skip write certificate request" \
5790            -C "skip parse certificate request" \
5791            -c "got a certificate request" \
5792            -C "skip write certificate" \
5793            -C "skip write certificate verify" \
5794            -S "skip parse certificate verify" \
5795            -s "x509_verify_cert() returned" \
5796            -s "! The certificate is not correctly signed by the trusted CA" \
5797            -s "! mbedtls_ssl_handshake returned" \
5798            -c "! mbedtls_ssl_handshake returned" \
5799            -s "X509 - Certificate verification failed"
5800
5801requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5802requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5803requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5804run_test    "Authentication, CA callback: client badcert, server optional" \
5805            "$P_SRV ca_callback=1 debug_level=3 auth_mode=optional" \
5806            "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
5807             key_file=data_files/server5.key" \
5808            0 \
5809            -s "use CA callback for X.509 CRT verification" \
5810            -S "skip write certificate request" \
5811            -C "skip parse certificate request" \
5812            -c "got a certificate request" \
5813            -C "skip write certificate" \
5814            -C "skip write certificate verify" \
5815            -S "skip parse certificate verify" \
5816            -s "x509_verify_cert() returned" \
5817            -s "! The certificate is not correctly signed by the trusted CA" \
5818            -S "! mbedtls_ssl_handshake returned" \
5819            -C "! mbedtls_ssl_handshake returned" \
5820            -S "X509 - Certificate verification failed"
5821
5822requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5823requires_full_size_output_buffer
5824requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5825requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5826requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5827run_test    "Authentication, CA callback: server max_int chain, client default" \
5828            "$P_SRV crt_file=data_files/dir-maxpath/c09.pem \
5829                    key_file=data_files/dir-maxpath/09.key" \
5830            "$P_CLI ca_callback=1 debug_level=3 server_name=CA09 ca_file=data_files/dir-maxpath/00.crt" \
5831            0 \
5832            -c "use CA callback for X.509 CRT verification" \
5833            -C "X509 - A fatal error occurred"
5834
5835requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5836requires_full_size_output_buffer
5837requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5838requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5839requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5840run_test    "Authentication, CA callback: server max_int+1 chain, client default" \
5841            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5842                    key_file=data_files/dir-maxpath/10.key" \
5843            "$P_CLI debug_level=3 ca_callback=1 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt" \
5844            1 \
5845            -c "use CA callback for X.509 CRT verification" \
5846            -c "X509 - A fatal error occurred"
5847
5848requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5849requires_full_size_output_buffer
5850requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5851requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5852requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5853run_test    "Authentication, CA callback: server max_int+1 chain, client optional" \
5854            "$P_SRV crt_file=data_files/dir-maxpath/c10.pem \
5855                    key_file=data_files/dir-maxpath/10.key" \
5856            "$P_CLI ca_callback=1 server_name=CA10 ca_file=data_files/dir-maxpath/00.crt \
5857                    debug_level=3 auth_mode=optional" \
5858            1 \
5859            -c "use CA callback for X.509 CRT verification" \
5860            -c "X509 - A fatal error occurred"
5861
5862requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5863requires_full_size_output_buffer
5864requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5865requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5866requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5867run_test    "Authentication, CA callback: client max_int+1 chain, server optional" \
5868            "$P_SRV ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=optional" \
5869            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5870                    key_file=data_files/dir-maxpath/10.key" \
5871            1 \
5872            -s "use CA callback for X.509 CRT verification" \
5873            -s "X509 - A fatal error occurred"
5874
5875requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5876requires_full_size_output_buffer
5877requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5878requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5879requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5880run_test    "Authentication, CA callback: client max_int+1 chain, server required" \
5881            "$P_SRV ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
5882            "$P_CLI crt_file=data_files/dir-maxpath/c10.pem \
5883                    key_file=data_files/dir-maxpath/10.key" \
5884            1 \
5885            -s "use CA callback for X.509 CRT verification" \
5886            -s "X509 - A fatal error occurred"
5887
5888requires_config_value_equals "MBEDTLS_X509_MAX_INTERMEDIATE_CA" $MAX_IM_CA
5889requires_full_size_output_buffer
5890requires_config_enabled MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
5891requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
5892requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
5893run_test    "Authentication, CA callback: client max_int chain, server required" \
5894            "$P_SRV ca_callback=1 debug_level=3 ca_file=data_files/dir-maxpath/00.crt auth_mode=required" \
5895            "$P_CLI crt_file=data_files/dir-maxpath/c09.pem \
5896                    key_file=data_files/dir-maxpath/09.key" \
5897            0 \
5898            -s "use CA callback for X.509 CRT verification" \
5899            -S "X509 - A fatal error occurred"
5900
5901# Tests for certificate selection based on SHA version
5902
5903requires_config_disabled MBEDTLS_X509_REMOVE_INFO
5904run_test    "Certificate hash: client TLS 1.2 -> SHA-2" \
5905            "$P_SRV force_version=tls12 crt_file=data_files/server5.crt \
5906                    key_file=data_files/server5.key \
5907                    crt_file2=data_files/server5-sha1.crt \
5908                    key_file2=data_files/server5.key" \
5909            "$P_CLI" \
5910            0 \
5911            -c "signed using.*ECDSA with SHA256" \
5912            -C "signed using.*ECDSA with SHA1"
5913
5914# tests for SNI
5915
5916requires_config_disabled MBEDTLS_X509_REMOVE_INFO
5917requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5918run_test    "SNI: no SNI callback" \
5919            "$P_SRV debug_level=3 \
5920             crt_file=data_files/server5.crt key_file=data_files/server5.key" \
5921            "$P_CLI server_name=localhost" \
5922            0 \
5923            -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
5924            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
5925
5926requires_config_disabled MBEDTLS_X509_REMOVE_INFO
5927requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5928run_test    "SNI: matching cert 1" \
5929            "$P_SRV debug_level=3 \
5930             crt_file=data_files/server5.crt key_file=data_files/server5.key \
5931             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
5932            "$P_CLI server_name=localhost" \
5933            0 \
5934            -s "parse ServerName extension" \
5935            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
5936            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
5937
5938requires_config_disabled MBEDTLS_X509_REMOVE_INFO
5939requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5940run_test    "SNI: matching cert 2" \
5941            "$P_SRV debug_level=3 \
5942             crt_file=data_files/server5.crt key_file=data_files/server5.key \
5943             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
5944            "$P_CLI server_name=polarssl.example" \
5945            0 \
5946            -s "parse ServerName extension" \
5947            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
5948            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
5949
5950requires_config_disabled MBEDTLS_X509_REMOVE_INFO
5951requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5952run_test    "SNI: no matching cert" \
5953            "$P_SRV debug_level=3 \
5954             crt_file=data_files/server5.crt key_file=data_files/server5.key \
5955             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
5956            "$P_CLI server_name=nonesuch.example" \
5957            1 \
5958            -s "parse ServerName extension" \
5959            -s "ssl_sni_wrapper() returned" \
5960            -s "mbedtls_ssl_handshake returned" \
5961            -c "mbedtls_ssl_handshake returned" \
5962            -c "SSL - A fatal alert message was received from our peer"
5963
5964requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5965run_test    "SNI: client auth no override: optional" \
5966            "$P_SRV debug_level=3 auth_mode=optional \
5967             crt_file=data_files/server5.crt key_file=data_files/server5.key \
5968             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
5969            "$P_CLI debug_level=3 server_name=localhost" \
5970            0 \
5971            -S "skip write certificate request" \
5972            -C "skip parse certificate request" \
5973            -c "got a certificate request" \
5974            -C "skip write certificate" \
5975            -C "skip write certificate verify" \
5976            -S "skip parse certificate verify"
5977
5978requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5979run_test    "SNI: client auth override: none -> optional" \
5980            "$P_SRV debug_level=3 auth_mode=none \
5981             crt_file=data_files/server5.crt key_file=data_files/server5.key \
5982             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
5983            "$P_CLI debug_level=3 server_name=localhost" \
5984            0 \
5985            -S "skip write certificate request" \
5986            -C "skip parse certificate request" \
5987            -c "got a certificate request" \
5988            -C "skip write certificate" \
5989            -C "skip write certificate verify" \
5990            -S "skip parse certificate verify"
5991
5992requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
5993run_test    "SNI: client auth override: optional -> none" \
5994            "$P_SRV debug_level=3 auth_mode=optional \
5995             crt_file=data_files/server5.crt key_file=data_files/server5.key \
5996             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
5997            "$P_CLI debug_level=3 server_name=localhost" \
5998            0 \
5999            -s "skip write certificate request" \
6000            -C "skip parse certificate request" \
6001            -c "got no certificate request" \
6002            -c "skip write certificate"
6003
6004requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6005run_test    "SNI: CA no override" \
6006            "$P_SRV debug_level=3 auth_mode=optional \
6007             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6008             ca_file=data_files/test-ca.crt \
6009             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
6010            "$P_CLI debug_level=3 server_name=localhost \
6011             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6012            1 \
6013            -S "skip write certificate request" \
6014            -C "skip parse certificate request" \
6015            -c "got a certificate request" \
6016            -C "skip write certificate" \
6017            -C "skip write certificate verify" \
6018            -S "skip parse certificate verify" \
6019            -s "x509_verify_cert() returned" \
6020            -s "! The certificate is not correctly signed by the trusted CA" \
6021            -S "The certificate has been revoked (is on a CRL)"
6022
6023requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6024run_test    "SNI: CA override" \
6025            "$P_SRV debug_level=3 auth_mode=optional \
6026             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6027             ca_file=data_files/test-ca.crt \
6028             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
6029            "$P_CLI debug_level=3 server_name=localhost \
6030             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6031            0 \
6032            -S "skip write certificate request" \
6033            -C "skip parse certificate request" \
6034            -c "got a certificate request" \
6035            -C "skip write certificate" \
6036            -C "skip write certificate verify" \
6037            -S "skip parse certificate verify" \
6038            -S "x509_verify_cert() returned" \
6039            -S "! The certificate is not correctly signed by the trusted CA" \
6040            -S "The certificate has been revoked (is on a CRL)"
6041
6042requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6043run_test    "SNI: CA override with CRL" \
6044            "$P_SRV debug_level=3 auth_mode=optional \
6045             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6046             ca_file=data_files/test-ca.crt \
6047             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
6048            "$P_CLI debug_level=3 server_name=localhost \
6049             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6050            1 \
6051            -S "skip write certificate request" \
6052            -C "skip parse certificate request" \
6053            -c "got a certificate request" \
6054            -C "skip write certificate" \
6055            -C "skip write certificate verify" \
6056            -S "skip parse certificate verify" \
6057            -s "x509_verify_cert() returned" \
6058            -S "! The certificate is not correctly signed by the trusted CA" \
6059            -s "The certificate has been revoked (is on a CRL)"
6060
6061# Tests for SNI and DTLS
6062
6063requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6064requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6065run_test    "SNI: DTLS, no SNI callback" \
6066            "$P_SRV debug_level=3 dtls=1 \
6067             crt_file=data_files/server5.crt key_file=data_files/server5.key" \
6068            "$P_CLI server_name=localhost dtls=1" \
6069            0 \
6070            -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
6071            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6072
6073requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6074requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6075run_test    "SNI: DTLS, matching cert 1" \
6076            "$P_SRV debug_level=3 dtls=1 \
6077             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6078             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6079            "$P_CLI server_name=localhost dtls=1" \
6080            0 \
6081            -s "parse ServerName extension" \
6082            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6083            -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
6084
6085requires_config_disabled MBEDTLS_X509_REMOVE_INFO
6086requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6087run_test    "SNI: DTLS, matching cert 2" \
6088            "$P_SRV debug_level=3 dtls=1 \
6089             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6090             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6091            "$P_CLI server_name=polarssl.example dtls=1" \
6092            0 \
6093            -s "parse ServerName extension" \
6094            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
6095            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
6096
6097requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6098run_test    "SNI: DTLS, no matching cert" \
6099            "$P_SRV debug_level=3 dtls=1 \
6100             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6101             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
6102            "$P_CLI server_name=nonesuch.example dtls=1" \
6103            1 \
6104            -s "parse ServerName extension" \
6105            -s "ssl_sni_wrapper() returned" \
6106            -s "mbedtls_ssl_handshake returned" \
6107            -c "mbedtls_ssl_handshake returned" \
6108            -c "SSL - A fatal alert message was received from our peer"
6109
6110requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6111run_test    "SNI: DTLS, client auth no override: optional" \
6112            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6113             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6114             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
6115            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6116            0 \
6117            -S "skip write certificate request" \
6118            -C "skip parse certificate request" \
6119            -c "got a certificate request" \
6120            -C "skip write certificate" \
6121            -C "skip write certificate verify" \
6122            -S "skip parse certificate verify"
6123
6124requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6125run_test    "SNI: DTLS, client auth override: none -> optional" \
6126            "$P_SRV debug_level=3 auth_mode=none dtls=1 \
6127             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6128             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
6129            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6130            0 \
6131            -S "skip write certificate request" \
6132            -C "skip parse certificate request" \
6133            -c "got a certificate request" \
6134            -C "skip write certificate" \
6135            -C "skip write certificate verify" \
6136            -S "skip parse certificate verify"
6137
6138requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6139run_test    "SNI: DTLS, client auth override: optional -> none" \
6140            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6141             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6142             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
6143            "$P_CLI debug_level=3 server_name=localhost dtls=1" \
6144            0 \
6145            -s "skip write certificate request" \
6146            -C "skip parse certificate request" \
6147            -c "got no certificate request" \
6148            -c "skip write certificate" \
6149            -c "skip write certificate verify" \
6150            -s "skip parse certificate verify"
6151
6152requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6153run_test    "SNI: DTLS, CA no override" \
6154            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
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,-,-,required" \
6158            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
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
6171requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6172run_test    "SNI: DTLS, CA override" \
6173            "$P_SRV debug_level=3 auth_mode=optional dtls=1 \
6174             crt_file=data_files/server5.crt key_file=data_files/server5.key \
6175             ca_file=data_files/test-ca.crt \
6176             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
6177            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6178             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6179            0 \
6180            -S "skip write certificate request" \
6181            -C "skip parse certificate request" \
6182            -c "got a certificate request" \
6183            -C "skip write certificate" \
6184            -C "skip write certificate verify" \
6185            -S "skip parse certificate verify" \
6186            -S "x509_verify_cert() returned" \
6187            -S "! The certificate is not correctly signed by the trusted CA" \
6188            -S "The certificate has been revoked (is on a CRL)"
6189
6190requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6191run_test    "SNI: DTLS, CA override with CRL" \
6192            "$P_SRV debug_level=3 auth_mode=optional \
6193             crt_file=data_files/server5.crt key_file=data_files/server5.key dtls=1 \
6194             ca_file=data_files/test-ca.crt \
6195             sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
6196            "$P_CLI debug_level=3 server_name=localhost dtls=1 \
6197             crt_file=data_files/server6.crt key_file=data_files/server6.key" \
6198            1 \
6199            -S "skip write certificate request" \
6200            -C "skip parse certificate request" \
6201            -c "got a certificate request" \
6202            -C "skip write certificate" \
6203            -C "skip write certificate verify" \
6204            -S "skip parse certificate verify" \
6205            -s "x509_verify_cert() returned" \
6206            -S "! The certificate is not correctly signed by the trusted CA" \
6207            -s "The certificate has been revoked (is on a CRL)"
6208
6209# Tests for non-blocking I/O: exercise a variety of handshake flows
6210
6211requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6212run_test    "Non-blocking I/O: basic handshake" \
6213            "$P_SRV nbio=2 tickets=0 auth_mode=none" \
6214            "$P_CLI nbio=2 tickets=0" \
6215            0 \
6216            -S "mbedtls_ssl_handshake returned" \
6217            -C "mbedtls_ssl_handshake returned" \
6218            -c "Read from server: .* bytes read"
6219
6220requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6221run_test    "Non-blocking I/O: client auth" \
6222            "$P_SRV nbio=2 tickets=0 auth_mode=required" \
6223            "$P_CLI nbio=2 tickets=0" \
6224            0 \
6225            -S "mbedtls_ssl_handshake returned" \
6226            -C "mbedtls_ssl_handshake returned" \
6227            -c "Read from server: .* bytes read"
6228
6229requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6230requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6231run_test    "Non-blocking I/O: ticket" \
6232            "$P_SRV nbio=2 tickets=1 auth_mode=none" \
6233            "$P_CLI nbio=2 tickets=1" \
6234            0 \
6235            -S "mbedtls_ssl_handshake returned" \
6236            -C "mbedtls_ssl_handshake returned" \
6237            -c "Read from server: .* bytes read"
6238
6239requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6240requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6241run_test    "Non-blocking I/O: ticket + client auth" \
6242            "$P_SRV nbio=2 tickets=1 auth_mode=required" \
6243            "$P_CLI nbio=2 tickets=1" \
6244            0 \
6245            -S "mbedtls_ssl_handshake returned" \
6246            -C "mbedtls_ssl_handshake returned" \
6247            -c "Read from server: .* bytes read"
6248
6249requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6250requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6251run_test    "Non-blocking I/O: ticket + client auth + resume" \
6252            "$P_SRV nbio=2 tickets=1 auth_mode=required" \
6253            "$P_CLI nbio=2 tickets=1 reconnect=1" \
6254            0 \
6255            -S "mbedtls_ssl_handshake returned" \
6256            -C "mbedtls_ssl_handshake returned" \
6257            -c "Read from server: .* bytes read"
6258
6259requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6260requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6261run_test    "Non-blocking I/O: ticket + resume" \
6262            "$P_SRV nbio=2 tickets=1 auth_mode=none" \
6263            "$P_CLI nbio=2 tickets=1 reconnect=1" \
6264            0 \
6265            -S "mbedtls_ssl_handshake returned" \
6266            -C "mbedtls_ssl_handshake returned" \
6267            -c "Read from server: .* bytes read"
6268
6269requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6270requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6271run_test    "Non-blocking I/O: session-id resume" \
6272            "$P_SRV nbio=2 tickets=0 auth_mode=none" \
6273            "$P_CLI nbio=2 tickets=0 reconnect=1" \
6274            0 \
6275            -S "mbedtls_ssl_handshake returned" \
6276            -C "mbedtls_ssl_handshake returned" \
6277            -c "Read from server: .* bytes read"
6278
6279# Tests for event-driven I/O: exercise a variety of handshake flows
6280
6281requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6282run_test    "Event-driven I/O: basic handshake" \
6283            "$P_SRV event=1 tickets=0 auth_mode=none" \
6284            "$P_CLI event=1 tickets=0" \
6285            0 \
6286            -S "mbedtls_ssl_handshake returned" \
6287            -C "mbedtls_ssl_handshake returned" \
6288            -c "Read from server: .* bytes read"
6289
6290requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6291run_test    "Event-driven I/O: client auth" \
6292            "$P_SRV event=1 tickets=0 auth_mode=required" \
6293            "$P_CLI event=1 tickets=0" \
6294            0 \
6295            -S "mbedtls_ssl_handshake returned" \
6296            -C "mbedtls_ssl_handshake returned" \
6297            -c "Read from server: .* bytes read"
6298
6299requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6300requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6301run_test    "Event-driven I/O: ticket" \
6302            "$P_SRV event=1 tickets=1 auth_mode=none" \
6303            "$P_CLI event=1 tickets=1" \
6304            0 \
6305            -S "mbedtls_ssl_handshake returned" \
6306            -C "mbedtls_ssl_handshake returned" \
6307            -c "Read from server: .* bytes read"
6308
6309requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6310requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6311run_test    "Event-driven I/O: ticket + client auth" \
6312            "$P_SRV event=1 tickets=1 auth_mode=required" \
6313            "$P_CLI event=1 tickets=1" \
6314            0 \
6315            -S "mbedtls_ssl_handshake returned" \
6316            -C "mbedtls_ssl_handshake returned" \
6317            -c "Read from server: .* bytes read"
6318
6319requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6320requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6321run_test    "Event-driven I/O: ticket + client auth + resume" \
6322            "$P_SRV event=1 tickets=1 auth_mode=required" \
6323            "$P_CLI event=1 tickets=1 reconnect=1" \
6324            0 \
6325            -S "mbedtls_ssl_handshake returned" \
6326            -C "mbedtls_ssl_handshake returned" \
6327            -c "Read from server: .* bytes read"
6328
6329requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6330requires_any_configs_enabled $TLS1_2_KEY_EXCHANGES_WITH_CERT
6331run_test    "Event-driven I/O: ticket + resume" \
6332            "$P_SRV event=1 tickets=1 auth_mode=none" \
6333            "$P_CLI event=1 tickets=1 reconnect=1" \
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    "Event-driven I/O: session-id resume" \
6342            "$P_SRV event=1 tickets=0 auth_mode=none" \
6343            "$P_CLI event=1 tickets=0 reconnect=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
6350run_test    "Event-driven I/O, DTLS: basic handshake" \
6351            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
6352            "$P_CLI dtls=1 event=1 tickets=0" \
6353            0 \
6354            -c "Read from server: .* bytes read"
6355
6356requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6357run_test    "Event-driven I/O, DTLS: client auth" \
6358            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
6359            "$P_CLI dtls=1 event=1 tickets=0" \
6360            0 \
6361            -c "Read from server: .* bytes read"
6362
6363requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6364run_test    "Event-driven I/O, DTLS: ticket" \
6365            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
6366            "$P_CLI dtls=1 event=1 tickets=1" \
6367            0 \
6368            -c "Read from server: .* bytes read"
6369
6370requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6371run_test    "Event-driven I/O, DTLS: ticket + client auth" \
6372            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
6373            "$P_CLI dtls=1 event=1 tickets=1" \
6374            0 \
6375            -c "Read from server: .* bytes read"
6376
6377requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6378run_test    "Event-driven I/O, DTLS: ticket + client auth + resume" \
6379            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=required" \
6380            "$P_CLI dtls=1 event=1 tickets=1 reconnect=1 skip_close_notify=1" \
6381            0 \
6382            -c "Read from server: .* bytes read"
6383
6384requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6385run_test    "Event-driven I/O, DTLS: ticket + resume" \
6386            "$P_SRV dtls=1 event=1 tickets=1 auth_mode=none" \
6387            "$P_CLI dtls=1 event=1 tickets=1 reconnect=1 skip_close_notify=1" \
6388            0 \
6389            -c "Read from server: .* bytes read"
6390
6391requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6392run_test    "Event-driven I/O, DTLS: session-id resume" \
6393            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=none" \
6394            "$P_CLI dtls=1 event=1 tickets=0 reconnect=1 skip_close_notify=1" \
6395            0 \
6396            -c "Read from server: .* bytes read"
6397
6398# This test demonstrates the need for the mbedtls_ssl_check_pending function.
6399# During session resumption, the client will send its ApplicationData record
6400# within the same datagram as the Finished messages. In this situation, the
6401# server MUST NOT idle on the underlying transport after handshake completion,
6402# because the ApplicationData request has already been queued internally.
6403requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6404run_test    "Event-driven I/O, DTLS: session-id resume, UDP packing" \
6405            -p "$P_PXY pack=50" \
6406            "$P_SRV dtls=1 event=1 tickets=0 auth_mode=required" \
6407            "$P_CLI dtls=1 event=1 tickets=0 reconnect=1 skip_close_notify=1" \
6408            0 \
6409            -c "Read from server: .* bytes read"
6410
6411# Tests for version negotiation
6412
6413requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6414run_test    "Version check: all -> 1.2" \
6415            "$P_SRV" \
6416            "$P_CLI" \
6417            0 \
6418            -S "mbedtls_ssl_handshake returned" \
6419            -C "mbedtls_ssl_handshake returned" \
6420            -s "Protocol is TLSv1.2" \
6421            -c "Protocol is TLSv1.2"
6422
6423requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6424run_test    "Not supported version check: cli TLS 1.0" \
6425            "$P_SRV" \
6426            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.0" \
6427            1 \
6428            -s "Handshake protocol not within min/max boundaries" \
6429            -c "Error in protocol version" \
6430            -S "Protocol is TLSv1.0" \
6431            -C "Handshake was completed"
6432
6433requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6434run_test    "Not supported version check: cli TLS 1.1" \
6435            "$P_SRV" \
6436            "$G_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.1" \
6437            1 \
6438            -s "Handshake protocol not within min/max boundaries" \
6439            -c "Error in protocol version" \
6440            -S "Protocol is TLSv1.1" \
6441            -C "Handshake was completed"
6442
6443requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6444run_test    "Not supported version check: srv max TLS 1.0" \
6445            "$G_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0" \
6446            "$P_CLI" \
6447            1 \
6448            -s "Error in protocol version" \
6449            -c "Handshake protocol not within min/max boundaries" \
6450            -S "Version: TLS1.0" \
6451            -C "Protocol is TLSv1.0"
6452
6453requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6454run_test    "Not supported version check: srv max TLS 1.1" \
6455            "$G_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1" \
6456            "$P_CLI" \
6457            1 \
6458            -s "Error in protocol version" \
6459            -c "Handshake protocol not within min/max boundaries" \
6460            -S "Version: TLS1.1" \
6461            -C "Protocol is TLSv1.1"
6462
6463# Tests for ALPN extension
6464
6465requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6466run_test    "ALPN: none" \
6467            "$P_SRV debug_level=3" \
6468            "$P_CLI debug_level=3" \
6469            0 \
6470            -C "client hello, adding alpn extension" \
6471            -S "found alpn extension" \
6472            -C "got an alert message, type: \\[2:120]" \
6473            -S "server side, adding alpn extension" \
6474            -C "found alpn extension " \
6475            -C "Application Layer Protocol is" \
6476            -S "Application Layer Protocol is"
6477
6478requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6479run_test    "ALPN: client only" \
6480            "$P_SRV debug_level=3" \
6481            "$P_CLI debug_level=3 alpn=abc,1234" \
6482            0 \
6483            -c "client hello, adding alpn extension" \
6484            -s "found alpn extension" \
6485            -C "got an alert message, type: \\[2:120]" \
6486            -S "server side, adding alpn extension" \
6487            -C "found alpn extension " \
6488            -c "Application Layer Protocol is (none)" \
6489            -S "Application Layer Protocol is"
6490
6491requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6492run_test    "ALPN: server only" \
6493            "$P_SRV debug_level=3 alpn=abc,1234" \
6494            "$P_CLI debug_level=3" \
6495            0 \
6496            -C "client hello, adding alpn extension" \
6497            -S "found alpn extension" \
6498            -C "got an alert message, type: \\[2:120]" \
6499            -S "server side, adding alpn extension" \
6500            -C "found alpn extension " \
6501            -C "Application Layer Protocol is" \
6502            -s "Application Layer Protocol is (none)"
6503
6504requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6505run_test    "ALPN: both, common cli1-srv1" \
6506            "$P_SRV debug_level=3 alpn=abc,1234" \
6507            "$P_CLI debug_level=3 alpn=abc,1234" \
6508            0 \
6509            -c "client hello, adding alpn extension" \
6510            -s "found alpn extension" \
6511            -C "got an alert message, type: \\[2:120]" \
6512            -s "server side, adding alpn extension" \
6513            -c "found alpn extension" \
6514            -c "Application Layer Protocol is abc" \
6515            -s "Application Layer Protocol is abc"
6516
6517requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6518run_test    "ALPN: both, common cli2-srv1" \
6519            "$P_SRV debug_level=3 alpn=abc,1234" \
6520            "$P_CLI debug_level=3 alpn=1234,abc" \
6521            0 \
6522            -c "client hello, adding alpn extension" \
6523            -s "found alpn extension" \
6524            -C "got an alert message, type: \\[2:120]" \
6525            -s "server side, adding alpn extension" \
6526            -c "found alpn extension" \
6527            -c "Application Layer Protocol is abc" \
6528            -s "Application Layer Protocol is abc"
6529
6530requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6531run_test    "ALPN: both, common cli1-srv2" \
6532            "$P_SRV debug_level=3 alpn=abc,1234" \
6533            "$P_CLI debug_level=3 alpn=1234,abcde" \
6534            0 \
6535            -c "client hello, adding alpn extension" \
6536            -s "found alpn extension" \
6537            -C "got an alert message, type: \\[2:120]" \
6538            -s "server side, adding alpn extension" \
6539            -c "found alpn extension" \
6540            -c "Application Layer Protocol is 1234" \
6541            -s "Application Layer Protocol is 1234"
6542
6543requires_key_exchange_with_cert_in_tls12_or_tls13_enabled
6544run_test    "ALPN: both, no common" \
6545            "$P_SRV debug_level=3 alpn=abc,123" \
6546            "$P_CLI debug_level=3 alpn=1234,abcde" \
6547            1 \
6548            -c "client hello, adding alpn extension" \
6549            -s "found alpn extension" \
6550            -c "got an alert message, type: \\[2:120]" \
6551            -S "server side, adding alpn extension" \
6552            -C "found alpn extension" \
6553            -C "Application Layer Protocol is 1234" \
6554            -S "Application Layer Protocol is 1234"
6555
6556
6557# Tests for keyUsage in leaf certificates, part 1:
6558# server-side certificate/suite selection
6559
6560requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6561run_test    "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
6562            "$P_SRV key_file=data_files/server2.key \
6563             crt_file=data_files/server2.ku-ds.crt" \
6564            "$P_CLI" \
6565            0 \
6566            -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
6567
6568requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6569run_test    "keyUsage srv: RSA, keyEncipherment -> RSA" \
6570            "$P_SRV key_file=data_files/server2.key \
6571             crt_file=data_files/server2.ku-ke.crt" \
6572            "$P_CLI" \
6573            0 \
6574            -c "Ciphersuite is TLS-RSA-WITH-"
6575
6576requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6577run_test    "keyUsage srv: RSA, keyAgreement -> fail" \
6578            "$P_SRV key_file=data_files/server2.key \
6579             crt_file=data_files/server2.ku-ka.crt" \
6580            "$P_CLI" \
6581            1 \
6582            -C "Ciphersuite is "
6583
6584requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6585run_test    "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
6586            "$P_SRV key_file=data_files/server5.key \
6587             crt_file=data_files/server5.ku-ds.crt" \
6588            "$P_CLI" \
6589            0 \
6590            -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
6591
6592
6593requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6594run_test    "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
6595            "$P_SRV key_file=data_files/server5.key \
6596             crt_file=data_files/server5.ku-ka.crt" \
6597            "$P_CLI" \
6598            0 \
6599            -c "Ciphersuite is TLS-ECDH-"
6600
6601requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6602run_test    "keyUsage srv: ECDSA, keyEncipherment -> fail" \
6603            "$P_SRV key_file=data_files/server5.key \
6604             crt_file=data_files/server5.ku-ke.crt" \
6605            "$P_CLI" \
6606            1 \
6607            -C "Ciphersuite is "
6608
6609# Tests for keyUsage in leaf certificates, part 2:
6610# client-side checking of server cert
6611
6612requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6613run_test    "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
6614            "$O_SRV -tls1_2 -key data_files/server2.key \
6615             -cert data_files/server2.ku-ds_ke.crt" \
6616            "$P_CLI debug_level=1 \
6617             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6618            0 \
6619            -C "bad certificate (usage extensions)" \
6620            -C "Processing of the Certificate handshake message failed" \
6621            -c "Ciphersuite is TLS-"
6622
6623requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6624run_test    "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
6625            "$O_SRV -tls1_2 -key data_files/server2.key \
6626             -cert data_files/server2.ku-ds_ke.crt" \
6627            "$P_CLI debug_level=1 \
6628             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6629            0 \
6630            -C "bad certificate (usage extensions)" \
6631            -C "Processing of the Certificate handshake message failed" \
6632            -c "Ciphersuite is TLS-"
6633
6634requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6635run_test    "keyUsage cli: KeyEncipherment, RSA: OK" \
6636            "$O_SRV -tls1_2 -key data_files/server2.key \
6637             -cert data_files/server2.ku-ke.crt" \
6638            "$P_CLI debug_level=1 \
6639             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6640            0 \
6641            -C "bad certificate (usage extensions)" \
6642            -C "Processing of the Certificate handshake message failed" \
6643            -c "Ciphersuite is TLS-"
6644
6645requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6646run_test    "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
6647            "$O_SRV -tls1_2 -key data_files/server2.key \
6648             -cert data_files/server2.ku-ke.crt" \
6649            "$P_CLI debug_level=1 \
6650             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6651            1 \
6652            -c "bad certificate (usage extensions)" \
6653            -c "Processing of the Certificate handshake message failed" \
6654            -C "Ciphersuite is TLS-"
6655
6656requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6657run_test    "keyUsage cli: KeyEncipherment, DHE-RSA: fail, soft" \
6658            "$O_SRV -tls1_2 -key data_files/server2.key \
6659             -cert data_files/server2.ku-ke.crt" \
6660            "$P_CLI debug_level=1 auth_mode=optional \
6661             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6662            0 \
6663            -c "bad certificate (usage extensions)" \
6664            -C "Processing of the Certificate handshake message failed" \
6665            -c "Ciphersuite is TLS-" \
6666            -c "! Usage does not match the keyUsage extension"
6667
6668requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6669run_test    "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
6670            "$O_SRV -tls1_2 -key data_files/server2.key \
6671             -cert data_files/server2.ku-ds.crt" \
6672            "$P_CLI debug_level=1 \
6673             force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
6674            0 \
6675            -C "bad certificate (usage extensions)" \
6676            -C "Processing of the Certificate handshake message failed" \
6677            -c "Ciphersuite is TLS-"
6678
6679requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6680run_test    "keyUsage cli: DigitalSignature, RSA: fail" \
6681            "$O_SRV -tls1_2 -key data_files/server2.key \
6682             -cert data_files/server2.ku-ds.crt" \
6683            "$P_CLI debug_level=1 \
6684             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6685            1 \
6686            -c "bad certificate (usage extensions)" \
6687            -c "Processing of the Certificate handshake message failed" \
6688            -C "Ciphersuite is TLS-"
6689
6690requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6691run_test    "keyUsage cli: DigitalSignature, RSA: fail, soft" \
6692            "$O_SRV -tls1_2 -key data_files/server2.key \
6693             -cert data_files/server2.ku-ds.crt" \
6694            "$P_CLI debug_level=1 auth_mode=optional \
6695             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
6696            0 \
6697            -c "bad certificate (usage extensions)" \
6698            -C "Processing of the Certificate handshake message failed" \
6699            -c "Ciphersuite is TLS-" \
6700            -c "! Usage does not match the keyUsage extension"
6701
6702requires_openssl_tls1_3
6703requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6704                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6705run_test    "keyUsage cli 1.3: DigitalSignature+KeyEncipherment, RSA: OK" \
6706            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
6707             -cert data_files/server2.ku-ds_ke.crt" \
6708            "$P_CLI debug_level=3" \
6709            0 \
6710            -C "bad certificate (usage extensions)" \
6711            -C "Processing of the Certificate handshake message failed" \
6712            -c "Ciphersuite is"
6713
6714requires_openssl_tls1_3
6715requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6716                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6717run_test    "keyUsage cli 1.3: KeyEncipherment, RSA: fail" \
6718            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
6719             -cert data_files/server2.ku-ke.crt" \
6720            "$P_CLI debug_level=1" \
6721            1 \
6722            -c "bad certificate (usage extensions)" \
6723            -c "Processing of the Certificate handshake message failed" \
6724            -C "Ciphersuite is"
6725
6726requires_openssl_tls1_3
6727requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6728                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6729run_test    "keyUsage cli 1.3: KeyAgreement, RSA: fail" \
6730            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server2.key \
6731             -cert data_files/server2.ku-ka.crt" \
6732            "$P_CLI debug_level=1" \
6733            1 \
6734            -c "bad certificate (usage extensions)" \
6735            -c "Processing of the Certificate handshake message failed" \
6736            -C "Ciphersuite is"
6737
6738requires_openssl_tls1_3
6739requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6740                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6741run_test    "keyUsage cli 1.3: DigitalSignature, ECDSA: OK" \
6742            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6743             -cert data_files/server5.ku-ds.crt" \
6744            "$P_CLI debug_level=3" \
6745            0 \
6746            -C "bad certificate (usage extensions)" \
6747            -C "Processing of the Certificate handshake message failed" \
6748            -c "Ciphersuite is"
6749
6750requires_openssl_tls1_3
6751requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6752                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6753run_test    "keyUsage cli 1.3: KeyEncipherment, ECDSA: fail" \
6754            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6755             -cert data_files/server5.ku-ke.crt" \
6756            "$P_CLI debug_level=1" \
6757            1 \
6758            -c "bad certificate (usage extensions)" \
6759            -c "Processing of the Certificate handshake message failed" \
6760            -C "Ciphersuite is"
6761
6762requires_openssl_tls1_3
6763requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6764                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6765run_test    "keyUsage cli 1.3: KeyAgreement, ECDSA: fail" \
6766            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6767             -cert data_files/server5.ku-ka.crt" \
6768            "$P_CLI debug_level=1" \
6769            1 \
6770            -c "bad certificate (usage extensions)" \
6771            -c "Processing of the Certificate handshake message failed" \
6772            -C "Ciphersuite is"
6773
6774# Tests for keyUsage in leaf certificates, part 3:
6775# server-side checking of client cert
6776
6777requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6778run_test    "keyUsage cli-auth: RSA, DigitalSignature: OK" \
6779            "$P_SRV debug_level=1 auth_mode=optional" \
6780            "$O_CLI -key data_files/server2.key \
6781             -cert data_files/server2.ku-ds.crt" \
6782            0 \
6783            -s "Verifying peer X.509 certificate... ok" \
6784            -S "bad certificate (usage extensions)" \
6785            -S "Processing of the Certificate handshake message failed"
6786
6787requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6788run_test    "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
6789            "$P_SRV debug_level=1 auth_mode=optional" \
6790            "$O_CLI -key data_files/server2.key \
6791             -cert data_files/server2.ku-ke.crt" \
6792            0 \
6793            -s "bad certificate (usage extensions)" \
6794            -S "Processing of the Certificate handshake message failed"
6795
6796requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6797run_test    "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
6798            "$P_SRV debug_level=1 auth_mode=required" \
6799            "$O_CLI -key data_files/server2.key \
6800             -cert data_files/server2.ku-ke.crt" \
6801            1 \
6802            -s "bad certificate (usage extensions)" \
6803            -s "Processing of the Certificate handshake message failed"
6804
6805requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6806run_test    "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
6807            "$P_SRV debug_level=1 auth_mode=optional" \
6808            "$O_CLI -key data_files/server5.key \
6809             -cert data_files/server5.ku-ds.crt" \
6810            0 \
6811            -s "Verifying peer X.509 certificate... ok" \
6812            -S "bad certificate (usage extensions)" \
6813            -S "Processing of the Certificate handshake message failed"
6814
6815requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6816run_test    "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
6817            "$P_SRV debug_level=1 auth_mode=optional" \
6818            "$O_CLI -key data_files/server5.key \
6819             -cert data_files/server5.ku-ka.crt" \
6820            0 \
6821            -s "bad certificate (usage extensions)" \
6822            -S "Processing of the Certificate handshake message failed"
6823
6824requires_openssl_tls1_3
6825requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6826                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6827run_test    "keyUsage cli-auth 1.3: RSA, DigitalSignature: OK" \
6828            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6829            "$O_NEXT_CLI_NO_CERT -key data_files/server2.key \
6830             -cert data_files/server2.ku-ds.crt" \
6831            0 \
6832            -s "Verifying peer X.509 certificate... ok" \
6833            -S "bad certificate (usage extensions)" \
6834            -S "Processing of the Certificate handshake message failed"
6835
6836requires_openssl_tls1_3
6837requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6838                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6839run_test    "keyUsage cli-auth 1.3: RSA, KeyEncipherment: fail (soft)" \
6840            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6841            "$O_NEXT_CLI_NO_CERT -key data_files/server2.key \
6842             -cert data_files/server2.ku-ke.crt" \
6843            0 \
6844            -s "bad certificate (usage extensions)" \
6845            -S "Processing of the Certificate handshake message failed"
6846
6847requires_openssl_tls1_3
6848requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6849                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6850run_test    "keyUsage cli-auth 1.3: ECDSA, DigitalSignature: OK" \
6851            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6852            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
6853             -cert data_files/server5.ku-ds.crt" \
6854            0 \
6855            -s "Verifying peer X.509 certificate... ok" \
6856            -S "bad certificate (usage extensions)" \
6857            -S "Processing of the Certificate handshake message failed"
6858
6859requires_openssl_tls1_3
6860requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6861                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6862run_test    "keyUsage cli-auth 1.3: ECDSA, KeyAgreement: fail (soft)" \
6863            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
6864            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
6865             -cert data_files/server5.ku-ka.crt" \
6866            0 \
6867            -s "bad certificate (usage extensions)" \
6868            -S "Processing of the Certificate handshake message failed"
6869
6870# Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
6871
6872requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6873run_test    "extKeyUsage srv: serverAuth -> OK" \
6874            "$P_SRV key_file=data_files/server5.key \
6875             crt_file=data_files/server5.eku-srv.crt" \
6876            "$P_CLI" \
6877            0
6878
6879requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6880run_test    "extKeyUsage srv: serverAuth,clientAuth -> OK" \
6881            "$P_SRV key_file=data_files/server5.key \
6882             crt_file=data_files/server5.eku-srv.crt" \
6883            "$P_CLI" \
6884            0
6885
6886requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6887run_test    "extKeyUsage srv: codeSign,anyEKU -> OK" \
6888            "$P_SRV key_file=data_files/server5.key \
6889             crt_file=data_files/server5.eku-cs_any.crt" \
6890            "$P_CLI" \
6891            0
6892
6893requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6894run_test    "extKeyUsage srv: codeSign -> fail" \
6895            "$P_SRV key_file=data_files/server5.key \
6896             crt_file=data_files/server5.eku-cli.crt" \
6897            "$P_CLI" \
6898            1
6899
6900# Tests for extendedKeyUsage, part 2: client-side checking of server cert
6901
6902requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6903run_test    "extKeyUsage cli: serverAuth -> OK" \
6904            "$O_SRV -tls1_2 -key data_files/server5.key \
6905             -cert data_files/server5.eku-srv.crt" \
6906            "$P_CLI debug_level=1" \
6907            0 \
6908            -C "bad certificate (usage extensions)" \
6909            -C "Processing of the Certificate handshake message failed" \
6910            -c "Ciphersuite is TLS-"
6911
6912requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6913run_test    "extKeyUsage cli: serverAuth,clientAuth -> OK" \
6914            "$O_SRV -tls1_2 -key data_files/server5.key \
6915             -cert data_files/server5.eku-srv_cli.crt" \
6916            "$P_CLI debug_level=1" \
6917            0 \
6918            -C "bad certificate (usage extensions)" \
6919            -C "Processing of the Certificate handshake message failed" \
6920            -c "Ciphersuite is TLS-"
6921
6922requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6923run_test    "extKeyUsage cli: codeSign,anyEKU -> OK" \
6924            "$O_SRV -tls1_2 -key data_files/server5.key \
6925             -cert data_files/server5.eku-cs_any.crt" \
6926            "$P_CLI debug_level=1" \
6927            0 \
6928            -C "bad certificate (usage extensions)" \
6929            -C "Processing of the Certificate handshake message failed" \
6930            -c "Ciphersuite is TLS-"
6931
6932requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6933run_test    "extKeyUsage cli: codeSign -> fail" \
6934            "$O_SRV -tls1_2 -key data_files/server5.key \
6935             -cert data_files/server5.eku-cs.crt" \
6936            "$P_CLI debug_level=1" \
6937            1 \
6938            -c "bad certificate (usage extensions)" \
6939            -c "Processing of the Certificate handshake message failed" \
6940            -C "Ciphersuite is TLS-"
6941
6942requires_openssl_tls1_3
6943requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6944                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6945run_test    "extKeyUsage cli 1.3: serverAuth -> OK" \
6946            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6947             -cert data_files/server5.eku-srv.crt" \
6948            "$P_CLI debug_level=1" \
6949            0 \
6950            -C "bad certificate (usage extensions)" \
6951            -C "Processing of the Certificate handshake message failed" \
6952            -c "Ciphersuite is"
6953
6954requires_openssl_tls1_3
6955requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6956                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6957run_test    "extKeyUsage cli 1.3: serverAuth,clientAuth -> OK" \
6958            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6959             -cert data_files/server5.eku-srv_cli.crt" \
6960            "$P_CLI debug_level=1" \
6961            0 \
6962            -C "bad certificate (usage extensions)" \
6963            -C "Processing of the Certificate handshake message failed" \
6964            -c "Ciphersuite is"
6965
6966requires_openssl_tls1_3
6967requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6968                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6969run_test    "extKeyUsage cli 1.3: codeSign,anyEKU -> OK" \
6970            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6971             -cert data_files/server5.eku-cs_any.crt" \
6972            "$P_CLI debug_level=1" \
6973            0 \
6974            -C "bad certificate (usage extensions)" \
6975            -C "Processing of the Certificate handshake message failed" \
6976            -c "Ciphersuite is"
6977
6978requires_openssl_tls1_3
6979requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
6980                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6981run_test    "extKeyUsage cli 1.3: codeSign -> fail" \
6982            "$O_NEXT_SRV_NO_CERT -tls1_3 -num_tickets=0 -key data_files/server5.key \
6983             -cert data_files/server5.eku-cs.crt" \
6984            "$P_CLI debug_level=1" \
6985            1 \
6986            -c "bad certificate (usage extensions)" \
6987            -c "Processing of the Certificate handshake message failed" \
6988            -C "Ciphersuite is"
6989
6990# Tests for extendedKeyUsage, part 3: server-side checking of client cert
6991
6992requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
6993run_test    "extKeyUsage cli-auth: clientAuth -> OK" \
6994            "$P_SRV debug_level=1 auth_mode=optional" \
6995            "$O_CLI -key data_files/server5.key \
6996             -cert data_files/server5.eku-cli.crt" \
6997            0 \
6998            -S "bad certificate (usage extensions)" \
6999            -S "Processing of the Certificate handshake message failed"
7000
7001requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7002run_test    "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
7003            "$P_SRV debug_level=1 auth_mode=optional" \
7004            "$O_CLI -key data_files/server5.key \
7005             -cert data_files/server5.eku-srv_cli.crt" \
7006            0 \
7007            -S "bad certificate (usage extensions)" \
7008            -S "Processing of the Certificate handshake message failed"
7009
7010requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7011run_test    "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
7012            "$P_SRV debug_level=1 auth_mode=optional" \
7013            "$O_CLI -key data_files/server5.key \
7014             -cert data_files/server5.eku-cs_any.crt" \
7015            0 \
7016            -S "bad certificate (usage extensions)" \
7017            -S "Processing of the Certificate handshake message failed"
7018
7019requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7020run_test    "extKeyUsage cli-auth: codeSign -> fail (soft)" \
7021            "$P_SRV debug_level=1 auth_mode=optional" \
7022            "$O_CLI -key data_files/server5.key \
7023             -cert data_files/server5.eku-cs.crt" \
7024            0 \
7025            -s "bad certificate (usage extensions)" \
7026            -S "Processing of the Certificate handshake message failed"
7027
7028requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7029run_test    "extKeyUsage cli-auth: codeSign -> fail (hard)" \
7030            "$P_SRV debug_level=1 auth_mode=required" \
7031            "$O_CLI -key data_files/server5.key \
7032             -cert data_files/server5.eku-cs.crt" \
7033            1 \
7034            -s "bad certificate (usage extensions)" \
7035            -s "Processing of the Certificate handshake message failed"
7036
7037requires_openssl_tls1_3
7038requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7039                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7040run_test    "extKeyUsage cli-auth 1.3: clientAuth -> OK" \
7041            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7042            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7043             -cert data_files/server5.eku-cli.crt" \
7044            0 \
7045            -S "bad certificate (usage extensions)" \
7046            -S "Processing of the Certificate handshake message failed"
7047
7048requires_openssl_tls1_3
7049requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7050                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7051run_test    "extKeyUsage cli-auth 1.3: serverAuth,clientAuth -> OK" \
7052            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7053            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7054             -cert data_files/server5.eku-srv_cli.crt" \
7055            0 \
7056            -S "bad certificate (usage extensions)" \
7057            -S "Processing of the Certificate handshake message failed"
7058
7059requires_openssl_tls1_3
7060requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7061                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7062run_test    "extKeyUsage cli-auth 1.3: codeSign,anyEKU -> OK" \
7063            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7064            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7065             -cert data_files/server5.eku-cs_any.crt" \
7066            0 \
7067            -S "bad certificate (usage extensions)" \
7068            -S "Processing of the Certificate handshake message failed"
7069
7070requires_openssl_tls1_3
7071requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
7072                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
7073run_test    "extKeyUsage cli-auth 1.3: codeSign -> fail (soft)" \
7074            "$P_SRV debug_level=1 force_version=tls13 auth_mode=optional" \
7075            "$O_NEXT_CLI_NO_CERT -key data_files/server5.key \
7076             -cert data_files/server5.eku-cs.crt" \
7077            0 \
7078            -s "bad certificate (usage extensions)" \
7079            -S "Processing of the Certificate handshake message failed"
7080
7081# Tests for DHM parameters loading
7082
7083requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7084run_test    "DHM parameters: reference" \
7085            "$P_SRV" \
7086            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7087                    debug_level=3" \
7088            0 \
7089            -c "value of 'DHM: P ' (2048 bits)" \
7090            -c "value of 'DHM: G ' (2 bits)"
7091
7092requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7093run_test    "DHM parameters: other parameters" \
7094            "$P_SRV dhm_file=data_files/dhparams.pem" \
7095            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7096                    debug_level=3" \
7097            0 \
7098            -c "value of 'DHM: P ' (1024 bits)" \
7099            -c "value of 'DHM: G ' (2 bits)"
7100
7101# Tests for DHM client-side size checking
7102
7103requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7104run_test    "DHM size: server default, client default, OK" \
7105            "$P_SRV" \
7106            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7107                    debug_level=1" \
7108            0 \
7109            -C "DHM prime too short:"
7110
7111requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7112run_test    "DHM size: server default, client 2048, OK" \
7113            "$P_SRV" \
7114            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7115                    debug_level=1 dhmlen=2048" \
7116            0 \
7117            -C "DHM prime too short:"
7118
7119requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7120run_test    "DHM size: server 1024, client default, OK" \
7121            "$P_SRV dhm_file=data_files/dhparams.pem" \
7122            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7123                    debug_level=1" \
7124            0 \
7125            -C "DHM prime too short:"
7126
7127requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7128run_test    "DHM size: server 999, client 999, OK" \
7129            "$P_SRV dhm_file=data_files/dh.999.pem" \
7130            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7131                    debug_level=1 dhmlen=999" \
7132            0 \
7133            -C "DHM prime too short:"
7134
7135requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7136run_test    "DHM size: server 1000, client 1000, OK" \
7137            "$P_SRV dhm_file=data_files/dh.1000.pem" \
7138            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7139                    debug_level=1 dhmlen=1000" \
7140            0 \
7141            -C "DHM prime too short:"
7142
7143requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7144run_test    "DHM size: server 1000, client default, rejected" \
7145            "$P_SRV dhm_file=data_files/dh.1000.pem" \
7146            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7147                    debug_level=1" \
7148            1 \
7149            -c "DHM prime too short:"
7150
7151requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7152run_test    "DHM size: server 1000, client 1001, rejected" \
7153            "$P_SRV dhm_file=data_files/dh.1000.pem" \
7154            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7155                    debug_level=1 dhmlen=1001" \
7156            1 \
7157            -c "DHM prime too short:"
7158
7159requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7160run_test    "DHM size: server 999, client 1000, rejected" \
7161            "$P_SRV dhm_file=data_files/dh.999.pem" \
7162            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7163                    debug_level=1 dhmlen=1000" \
7164            1 \
7165            -c "DHM prime too short:"
7166
7167requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7168run_test    "DHM size: server 998, client 999, rejected" \
7169            "$P_SRV dhm_file=data_files/dh.998.pem" \
7170            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7171                    debug_level=1 dhmlen=999" \
7172            1 \
7173            -c "DHM prime too short:"
7174
7175requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7176run_test    "DHM size: server default, client 2049, rejected" \
7177            "$P_SRV" \
7178            "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
7179                    debug_level=1 dhmlen=2049" \
7180            1 \
7181            -c "DHM prime too short:"
7182
7183# Tests for PSK callback
7184
7185requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7186run_test    "PSK callback: psk, no callback" \
7187            "$P_SRV psk=abc123 psk_identity=foo" \
7188            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7189            psk_identity=foo psk=abc123" \
7190            0 \
7191            -S "SSL - The handshake negotiation failed" \
7192            -S "SSL - Unknown identity received" \
7193            -S "SSL - Verification of the message MAC failed"
7194
7195requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7196requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7197run_test    "PSK callback: opaque psk on client, no callback" \
7198            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7199            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7200            psk_identity=foo psk=abc123 psk_opaque=1" \
7201            0 \
7202            -C "session hash for extended master secret"\
7203            -S "session hash for extended master secret"\
7204            -S "SSL - The handshake negotiation failed" \
7205            -S "SSL - Unknown identity received" \
7206            -S "SSL - Verification of the message MAC failed"
7207
7208requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7209requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7210run_test    "PSK callback: opaque psk on client, no callback, SHA-384" \
7211            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7212            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7213            psk_identity=foo psk=abc123 psk_opaque=1" \
7214            0 \
7215            -C "session hash for extended master secret"\
7216            -S "session hash for extended master secret"\
7217            -S "SSL - The handshake negotiation failed" \
7218            -S "SSL - Unknown identity received" \
7219            -S "SSL - Verification of the message MAC failed"
7220
7221requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7222requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7223run_test    "PSK callback: opaque psk on client, no callback, EMS" \
7224            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7225            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7226            psk_identity=foo psk=abc123 psk_opaque=1" \
7227            0 \
7228            -c "session hash for extended master secret"\
7229            -s "session hash for extended master secret"\
7230            -S "SSL - The handshake negotiation failed" \
7231            -S "SSL - Unknown identity received" \
7232            -S "SSL - Verification of the message MAC failed"
7233
7234requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7235requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7236run_test    "PSK callback: opaque psk on client, no callback, SHA-384, EMS" \
7237            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7238            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7239            psk_identity=foo psk=abc123 psk_opaque=1" \
7240            0 \
7241            -c "session hash for extended master secret"\
7242            -s "session hash for extended master secret"\
7243            -S "SSL - The handshake negotiation failed" \
7244            -S "SSL - Unknown identity received" \
7245            -S "SSL - Verification of the message MAC failed"
7246
7247requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7248requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7249run_test    "PSK callback: opaque rsa-psk on client, no callback" \
7250            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7251            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256 \
7252            psk_identity=foo psk=abc123 psk_opaque=1" \
7253            0 \
7254            -C "session hash for extended master secret"\
7255            -S "session hash for extended master secret"\
7256            -S "SSL - The handshake negotiation failed" \
7257            -S "SSL - Unknown identity received" \
7258            -S "SSL - Verification of the message MAC failed"
7259
7260requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7261requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7262run_test    "PSK callback: opaque rsa-psk on client, no callback, SHA-384" \
7263            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7264            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7265            psk_identity=foo psk=abc123 psk_opaque=1" \
7266            0 \
7267            -C "session hash for extended master secret"\
7268            -S "session hash for extended master secret"\
7269            -S "SSL - The handshake negotiation failed" \
7270            -S "SSL - Unknown identity received" \
7271            -S "SSL - Verification of the message MAC failed"
7272
7273requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7274requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7275run_test    "PSK callback: opaque rsa-psk on client, no callback, EMS" \
7276            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7277            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7278            psk_identity=foo psk=abc123 psk_opaque=1" \
7279            0 \
7280            -c "session hash for extended master secret"\
7281            -s "session hash for extended master secret"\
7282            -S "SSL - The handshake negotiation failed" \
7283            -S "SSL - Unknown identity received" \
7284            -S "SSL - Verification of the message MAC failed"
7285
7286requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7287requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7288run_test    "PSK callback: opaque rsa-psk on client, no callback, SHA-384, EMS" \
7289            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7290            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7291            psk_identity=foo psk=abc123 psk_opaque=1" \
7292            0 \
7293            -c "session hash for extended master secret"\
7294            -s "session hash for extended master secret"\
7295            -S "SSL - The handshake negotiation failed" \
7296            -S "SSL - Unknown identity received" \
7297            -S "SSL - Verification of the message MAC failed"
7298
7299requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7300requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7301run_test    "PSK callback: opaque ecdhe-psk on client, no callback" \
7302            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7303            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 \
7304            psk_identity=foo psk=abc123 psk_opaque=1" \
7305            0 \
7306            -C "session hash for extended master secret"\
7307            -S "session hash for extended master secret"\
7308            -S "SSL - The handshake negotiation failed" \
7309            -S "SSL - Unknown identity received" \
7310            -S "SSL - Verification of the message MAC failed"
7311
7312requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7313requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7314run_test    "PSK callback: opaque ecdhe-psk on client, no callback, SHA-384" \
7315            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7316            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7317            psk_identity=foo psk=abc123 psk_opaque=1" \
7318            0 \
7319            -C "session hash for extended master secret"\
7320            -S "session hash for extended master secret"\
7321            -S "SSL - The handshake negotiation failed" \
7322            -S "SSL - Unknown identity received" \
7323            -S "SSL - Verification of the message MAC failed"
7324
7325requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7326requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7327run_test    "PSK callback: opaque ecdhe-psk on client, no callback, EMS" \
7328            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7329            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7330            psk_identity=foo psk=abc123 psk_opaque=1" \
7331            0 \
7332            -c "session hash for extended master secret"\
7333            -s "session hash for extended master secret"\
7334            -S "SSL - The handshake negotiation failed" \
7335            -S "SSL - Unknown identity received" \
7336            -S "SSL - Verification of the message MAC failed"
7337
7338requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7339requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7340run_test    "PSK callback: opaque ecdhe-psk on client, no callback, SHA-384, EMS" \
7341            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7342            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7343            psk_identity=foo psk=abc123 psk_opaque=1" \
7344            0 \
7345            -c "session hash for extended master secret"\
7346            -s "session hash for extended master secret"\
7347            -S "SSL - The handshake negotiation failed" \
7348            -S "SSL - Unknown identity received" \
7349            -S "SSL - Verification of the message MAC failed"
7350
7351requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7352requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7353run_test    "PSK callback: opaque dhe-psk on client, no callback" \
7354            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7355            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA256 \
7356            psk_identity=foo psk=abc123 psk_opaque=1" \
7357            0 \
7358            -C "session hash for extended master secret"\
7359            -S "session hash for extended master secret"\
7360            -S "SSL - The handshake negotiation failed" \
7361            -S "SSL - Unknown identity received" \
7362            -S "SSL - Verification of the message MAC failed"
7363
7364requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7365requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7366run_test    "PSK callback: opaque dhe-psk on client, no callback, SHA-384" \
7367            "$P_SRV extended_ms=0 debug_level=1 psk=abc123 psk_identity=foo" \
7368            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7369            psk_identity=foo psk=abc123 psk_opaque=1" \
7370            0 \
7371            -C "session hash for extended master secret"\
7372            -S "session hash for extended master secret"\
7373            -S "SSL - The handshake negotiation failed" \
7374            -S "SSL - Unknown identity received" \
7375            -S "SSL - Verification of the message MAC failed"
7376
7377requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7378requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7379run_test    "PSK callback: opaque dhe-psk on client, no callback, EMS" \
7380            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7381            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7382            psk_identity=foo psk=abc123 psk_opaque=1" \
7383            0 \
7384            -c "session hash for extended master secret"\
7385            -s "session hash for extended master secret"\
7386            -S "SSL - The handshake negotiation failed" \
7387            -S "SSL - Unknown identity received" \
7388            -S "SSL - Verification of the message MAC failed"
7389
7390requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7391requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7392run_test    "PSK callback: opaque dhe-psk on client, no callback, SHA-384, EMS" \
7393            "$P_SRV extended_ms=1 debug_level=3 psk=abc123 psk_identity=foo" \
7394            "$P_CLI extended_ms=1 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7395            psk_identity=foo psk=abc123 psk_opaque=1" \
7396            0 \
7397            -c "session hash for extended master secret"\
7398            -s "session hash for extended master secret"\
7399            -S "SSL - The handshake negotiation failed" \
7400            -S "SSL - Unknown identity received" \
7401            -S "SSL - Verification of the message MAC failed"
7402
7403requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7404requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7405run_test    "PSK callback: raw psk on client, static opaque on server, no callback" \
7406            "$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" \
7407            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7408            psk_identity=foo psk=abc123" \
7409            0 \
7410            -C "session hash for extended master secret"\
7411            -S "session hash for extended master secret"\
7412            -S "SSL - The handshake negotiation failed" \
7413            -S "SSL - Unknown identity received" \
7414            -S "SSL - Verification of the message MAC failed"
7415
7416requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7417requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7418run_test    "PSK callback: raw psk on client, static opaque on server, no callback, SHA-384" \
7419            "$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" \
7420            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7421            psk_identity=foo psk=abc123" \
7422            0 \
7423            -C "session hash for extended master secret"\
7424            -S "session hash for extended master secret"\
7425            -S "SSL - The handshake negotiation failed" \
7426            -S "SSL - Unknown identity received" \
7427            -S "SSL - Verification of the message MAC failed"
7428
7429requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7430requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7431run_test    "PSK callback: raw psk on client, static opaque on server, no callback, EMS" \
7432            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7433            force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7434            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7435            psk_identity=foo psk=abc123 extended_ms=1" \
7436            0 \
7437            -c "session hash for extended master secret"\
7438            -s "session hash for extended master secret"\
7439            -S "SSL - The handshake negotiation failed" \
7440            -S "SSL - Unknown identity received" \
7441            -S "SSL - Verification of the message MAC failed"
7442
7443requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7444requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7445run_test    "PSK callback: raw psk on client, static opaque on server, no callback, EMS, SHA384" \
7446            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7447            force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7448            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7449            psk_identity=foo psk=abc123 extended_ms=1" \
7450            0 \
7451            -c "session hash for extended master secret"\
7452            -s "session hash for extended master secret"\
7453            -S "SSL - The handshake negotiation failed" \
7454            -S "SSL - Unknown identity received" \
7455            -S "SSL - Verification of the message MAC failed"
7456
7457requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7458requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7459run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback" \
7460            "$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" \
7461            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7462            psk_identity=foo psk=abc123" \
7463            0 \
7464            -C "session hash for extended master secret"\
7465            -S "session hash for extended master secret"\
7466            -S "SSL - The handshake negotiation failed" \
7467            -S "SSL - Unknown identity received" \
7468            -S "SSL - Verification of the message MAC failed"
7469
7470requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7471requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7472run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, SHA-384" \
7473            "$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" \
7474            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7475            psk_identity=foo psk=abc123" \
7476            0 \
7477            -C "session hash for extended master secret"\
7478            -S "session hash for extended master secret"\
7479            -S "SSL - The handshake negotiation failed" \
7480            -S "SSL - Unknown identity received" \
7481            -S "SSL - Verification of the message MAC failed"
7482
7483requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7484requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7485run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, EMS" \
7486            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7487            force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7488            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7489            psk_identity=foo psk=abc123 extended_ms=1" \
7490            0 \
7491            -c "session hash for extended master secret"\
7492            -s "session hash for extended master secret"\
7493            -S "SSL - The handshake negotiation failed" \
7494            -S "SSL - Unknown identity received" \
7495            -S "SSL - Verification of the message MAC failed"
7496
7497requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7498requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7499run_test    "PSK callback: raw rsa-psk on client, static opaque on server, no callback, EMS, SHA384" \
7500            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7501            force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7502            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7503            psk_identity=foo psk=abc123 extended_ms=1" \
7504            0 \
7505            -c "session hash for extended master secret"\
7506            -s "session hash for extended master secret"\
7507            -S "SSL - The handshake negotiation failed" \
7508            -S "SSL - Unknown identity received" \
7509            -S "SSL - Verification of the message MAC failed"
7510
7511requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7512requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7513run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback" \
7514            "$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" \
7515            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7516            psk_identity=foo psk=abc123" \
7517            0 \
7518            -C "session hash for extended master secret"\
7519            -S "session hash for extended master secret"\
7520            -S "SSL - The handshake negotiation failed" \
7521            -S "SSL - Unknown identity received" \
7522            -S "SSL - Verification of the message MAC failed"
7523
7524requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7525requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7526run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, SHA-384" \
7527            "$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" \
7528            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7529            psk_identity=foo psk=abc123" \
7530            0 \
7531            -C "session hash for extended master secret"\
7532            -S "session hash for extended master secret"\
7533            -S "SSL - The handshake negotiation failed" \
7534            -S "SSL - Unknown identity received" \
7535            -S "SSL - Verification of the message MAC failed"
7536
7537requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7538requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7539run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, EMS" \
7540            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7541            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7542            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7543            psk_identity=foo psk=abc123 extended_ms=1" \
7544            0 \
7545            -c "session hash for extended master secret"\
7546            -s "session hash for extended master secret"\
7547            -S "SSL - The handshake negotiation failed" \
7548            -S "SSL - Unknown identity received" \
7549            -S "SSL - Verification of the message MAC failed"
7550
7551requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7552requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7553run_test    "PSK callback: raw ecdhe-psk on client, static opaque on server, no callback, EMS, SHA384" \
7554            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7555            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7556            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7557            psk_identity=foo psk=abc123 extended_ms=1" \
7558            0 \
7559            -c "session hash for extended master secret"\
7560            -s "session hash for extended master secret"\
7561            -S "SSL - The handshake negotiation failed" \
7562            -S "SSL - Unknown identity received" \
7563            -S "SSL - Verification of the message MAC failed"
7564
7565requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7566requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7567run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback" \
7568            "$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" \
7569            "$P_CLI extended_ms=0 debug_level=5 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7570            psk_identity=foo psk=abc123" \
7571            0 \
7572            -C "session hash for extended master secret"\
7573            -S "session hash for extended master secret"\
7574            -S "SSL - The handshake negotiation failed" \
7575            -S "SSL - Unknown identity received" \
7576            -S "SSL - Verification of the message MAC failed"
7577
7578requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7579requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7580run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, SHA-384" \
7581            "$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" \
7582            "$P_CLI extended_ms=0 debug_level=1 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7583            psk_identity=foo psk=abc123" \
7584            0 \
7585            -C "session hash for extended master secret"\
7586            -S "session hash for extended master secret"\
7587            -S "SSL - The handshake negotiation failed" \
7588            -S "SSL - Unknown identity received" \
7589            -S "SSL - Verification of the message MAC failed"
7590
7591requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7592requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7593run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, EMS" \
7594            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7595            force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7596            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7597            psk_identity=foo psk=abc123 extended_ms=1" \
7598            0 \
7599            -c "session hash for extended master secret"\
7600            -s "session hash for extended master secret"\
7601            -S "SSL - The handshake negotiation failed" \
7602            -S "SSL - Unknown identity received" \
7603            -S "SSL - Verification of the message MAC failed"
7604
7605requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7606requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7607run_test    "PSK callback: raw dhe-psk on client, static opaque on server, no callback, EMS, SHA384" \
7608            "$P_SRV debug_level=3 psk=abc123 psk_identity=foo psk_opaque=1 min_version=tls12 \
7609            force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7610            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7611            psk_identity=foo psk=abc123 extended_ms=1" \
7612            0 \
7613            -c "session hash for extended master secret"\
7614            -s "session hash for extended master secret"\
7615            -S "SSL - The handshake negotiation failed" \
7616            -S "SSL - Unknown identity received" \
7617            -S "SSL - Verification of the message MAC failed"
7618
7619requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7620requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7621run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback" \
7622            "$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" \
7623            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7624            psk_identity=def psk=beef" \
7625            0 \
7626            -C "session hash for extended master secret"\
7627            -S "session hash for extended master secret"\
7628            -S "SSL - The handshake negotiation failed" \
7629            -S "SSL - Unknown identity received" \
7630            -S "SSL - Verification of the message MAC failed"
7631
7632requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7633requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7634run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, SHA-384" \
7635            "$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" \
7636            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7637            psk_identity=def psk=beef" \
7638            0 \
7639            -C "session hash for extended master secret"\
7640            -S "session hash for extended master secret"\
7641            -S "SSL - The handshake negotiation failed" \
7642            -S "SSL - Unknown identity received" \
7643            -S "SSL - Verification of the message MAC failed"
7644
7645requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7646requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7647run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, EMS" \
7648            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7649            force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7650            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7651            psk_identity=abc psk=dead extended_ms=1" \
7652            0 \
7653            -c "session hash for extended master secret"\
7654            -s "session hash for extended master secret"\
7655            -S "SSL - The handshake negotiation failed" \
7656            -S "SSL - Unknown identity received" \
7657            -S "SSL - Verification of the message MAC failed"
7658
7659requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7660requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7661run_test    "PSK callback: raw psk on client, no static PSK on server, opaque PSK from callback, EMS, SHA384" \
7662            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7663            force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7664            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-256-CBC-SHA384 \
7665            psk_identity=abc psk=dead extended_ms=1" \
7666            0 \
7667            -c "session hash for extended master secret"\
7668            -s "session hash for extended master secret"\
7669            -S "SSL - The handshake negotiation failed" \
7670            -S "SSL - Unknown identity received" \
7671            -S "SSL - Verification of the message MAC failed"
7672
7673requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7674requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7675run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback" \
7676            "$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" \
7677            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7678            psk_identity=def psk=beef" \
7679            0 \
7680            -C "session hash for extended master secret"\
7681            -S "session hash for extended master secret"\
7682            -S "SSL - The handshake negotiation failed" \
7683            -S "SSL - Unknown identity received" \
7684            -S "SSL - Verification of the message MAC failed"
7685
7686requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7687requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7688run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, SHA-384" \
7689            "$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" \
7690            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7691            psk_identity=def psk=beef" \
7692            0 \
7693            -C "session hash for extended master secret"\
7694            -S "session hash for extended master secret"\
7695            -S "SSL - The handshake negotiation failed" \
7696            -S "SSL - Unknown identity received" \
7697            -S "SSL - Verification of the message MAC failed"
7698
7699requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7700requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7701run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, EMS" \
7702            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7703            force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7704            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
7705            psk_identity=abc psk=dead extended_ms=1" \
7706            0 \
7707            -c "session hash for extended master secret"\
7708            -s "session hash for extended master secret"\
7709            -S "SSL - The handshake negotiation failed" \
7710            -S "SSL - Unknown identity received" \
7711            -S "SSL - Verification of the message MAC failed"
7712
7713requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7714requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7715run_test    "PSK callback: raw rsa-psk on client, no static RSA-PSK on server, opaque RSA-PSK from callback, EMS, SHA384" \
7716            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7717            force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7718            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
7719            psk_identity=abc psk=dead extended_ms=1" \
7720            0 \
7721            -c "session hash for extended master secret"\
7722            -s "session hash for extended master secret"\
7723            -S "SSL - The handshake negotiation failed" \
7724            -S "SSL - Unknown identity received" \
7725            -S "SSL - Verification of the message MAC failed"
7726
7727requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7728requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7729run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback" \
7730            "$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" \
7731            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7732            psk_identity=def psk=beef" \
7733            0 \
7734            -C "session hash for extended master secret"\
7735            -S "session hash for extended master secret"\
7736            -S "SSL - The handshake negotiation failed" \
7737            -S "SSL - Unknown identity received" \
7738            -S "SSL - Verification of the message MAC failed"
7739
7740requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7741requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7742run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, SHA-384" \
7743            "$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" \
7744            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7745            psk_identity=def psk=beef" \
7746            0 \
7747            -C "session hash for extended master secret"\
7748            -S "session hash for extended master secret"\
7749            -S "SSL - The handshake negotiation failed" \
7750            -S "SSL - Unknown identity received" \
7751            -S "SSL - Verification of the message MAC failed"
7752
7753requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7754requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7755run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, EMS" \
7756            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7757            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7758            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
7759            psk_identity=abc psk=dead extended_ms=1" \
7760            0 \
7761            -c "session hash for extended master secret"\
7762            -s "session hash for extended master secret"\
7763            -S "SSL - The handshake negotiation failed" \
7764            -S "SSL - Unknown identity received" \
7765            -S "SSL - Verification of the message MAC failed"
7766
7767requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7768requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7769run_test    "PSK callback: raw ecdhe-psk on client, no static ECDHE-PSK on server, opaque ECDHE-PSK from callback, EMS, SHA384" \
7770            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7771            force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7772            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
7773            psk_identity=abc psk=dead extended_ms=1" \
7774            0 \
7775            -c "session hash for extended master secret"\
7776            -s "session hash for extended master secret"\
7777            -S "SSL - The handshake negotiation failed" \
7778            -S "SSL - Unknown identity received" \
7779            -S "SSL - Verification of the message MAC failed"
7780
7781requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7782requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7783run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback" \
7784            "$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" \
7785            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7786            psk_identity=def psk=beef" \
7787            0 \
7788            -C "session hash for extended master secret"\
7789            -S "session hash for extended master secret"\
7790            -S "SSL - The handshake negotiation failed" \
7791            -S "SSL - Unknown identity received" \
7792            -S "SSL - Verification of the message MAC failed"
7793
7794requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7795requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7796run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, SHA-384" \
7797            "$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" \
7798            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7799            psk_identity=def psk=beef" \
7800            0 \
7801            -C "session hash for extended master secret"\
7802            -S "session hash for extended master secret"\
7803            -S "SSL - The handshake negotiation failed" \
7804            -S "SSL - Unknown identity received" \
7805            -S "SSL - Verification of the message MAC failed"
7806
7807requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7808requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7809run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, EMS" \
7810            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7811            force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA extended_ms=1" \
7812            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
7813            psk_identity=abc psk=dead extended_ms=1" \
7814            0 \
7815            -c "session hash for extended master secret"\
7816            -s "session hash for extended master secret"\
7817            -S "SSL - The handshake negotiation failed" \
7818            -S "SSL - Unknown identity received" \
7819            -S "SSL - Verification of the message MAC failed"
7820
7821requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7822requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7823run_test    "PSK callback: raw dhe-psk on client, no static DHE-PSK on server, opaque DHE-PSK from callback, EMS, SHA384" \
7824            "$P_SRV debug_level=3 psk_list=abc,dead,def,beef psk_list_opaque=1 min_version=tls12 \
7825            force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 extended_ms=1" \
7826            "$P_CLI debug_level=3 min_version=tls12 force_ciphersuite=TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
7827            psk_identity=abc psk=dead extended_ms=1" \
7828            0 \
7829            -c "session hash for extended master secret"\
7830            -s "session hash for extended master secret"\
7831            -S "SSL - The handshake negotiation failed" \
7832            -S "SSL - Unknown identity received" \
7833            -S "SSL - Verification of the message MAC failed"
7834
7835requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7836requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7837run_test    "PSK callback: raw psk on client, mismatching static raw PSK on server, opaque PSK from callback" \
7838            "$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" \
7839            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7840            psk_identity=def psk=beef" \
7841            0 \
7842            -C "session hash for extended master secret"\
7843            -S "session hash for extended master secret"\
7844            -S "SSL - The handshake negotiation failed" \
7845            -S "SSL - Unknown identity received" \
7846            -S "SSL - Verification of the message MAC failed"
7847
7848requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7849requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7850run_test    "PSK callback: raw psk on client, mismatching static opaque PSK on server, opaque PSK from callback" \
7851            "$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" \
7852            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7853            psk_identity=def psk=beef" \
7854            0 \
7855            -C "session hash for extended master secret"\
7856            -S "session hash for extended master secret"\
7857            -S "SSL - The handshake negotiation failed" \
7858            -S "SSL - Unknown identity received" \
7859            -S "SSL - Verification of the message MAC failed"
7860
7861requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7862requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7863run_test    "PSK callback: raw psk on client, mismatching static opaque PSK on server, raw PSK from callback" \
7864            "$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" \
7865            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7866            psk_identity=def psk=beef" \
7867            0 \
7868            -C "session hash for extended master secret"\
7869            -S "session hash for extended master secret"\
7870            -S "SSL - The handshake negotiation failed" \
7871            -S "SSL - Unknown identity received" \
7872            -S "SSL - Verification of the message MAC failed"
7873
7874requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7875requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7876run_test    "PSK callback: raw psk on client, id-matching but wrong raw PSK on server, opaque PSK from callback" \
7877            "$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" \
7878            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7879            psk_identity=def psk=beef" \
7880            0 \
7881            -C "session hash for extended master secret"\
7882            -S "session hash for extended master secret"\
7883            -S "SSL - The handshake negotiation failed" \
7884            -S "SSL - Unknown identity received" \
7885            -S "SSL - Verification of the message MAC failed"
7886
7887requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
7888requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7889run_test    "PSK callback: raw psk on client, matching opaque PSK on server, wrong opaque PSK from callback" \
7890            "$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" \
7891            "$P_CLI extended_ms=0 debug_level=3 min_version=tls12 force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7892            psk_identity=def psk=beef" \
7893            1 \
7894            -s "SSL - Verification of the message MAC failed"
7895
7896requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7897run_test    "PSK callback: no psk, no callback" \
7898            "$P_SRV" \
7899            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7900            psk_identity=foo psk=abc123" \
7901            1 \
7902            -s "SSL - The handshake negotiation failed" \
7903            -S "SSL - Unknown identity received" \
7904            -S "SSL - Verification of the message MAC failed"
7905
7906requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7907run_test    "PSK callback: callback overrides other settings" \
7908            "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
7909            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7910            psk_identity=foo psk=abc123" \
7911            1 \
7912            -S "SSL - The handshake negotiation failed" \
7913            -s "SSL - Unknown identity received" \
7914            -S "SSL - Verification of the message MAC failed"
7915
7916requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7917run_test    "PSK callback: first id matches" \
7918            "$P_SRV psk_list=abc,dead,def,beef" \
7919            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7920            psk_identity=abc psk=dead" \
7921            0 \
7922            -S "SSL - The handshake negotiation failed" \
7923            -S "SSL - Unknown identity received" \
7924            -S "SSL - Verification of the message MAC failed"
7925
7926requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7927run_test    "PSK callback: second id matches" \
7928            "$P_SRV psk_list=abc,dead,def,beef" \
7929            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7930            psk_identity=def psk=beef" \
7931            0 \
7932            -S "SSL - The handshake negotiation failed" \
7933            -S "SSL - Unknown identity received" \
7934            -S "SSL - Verification of the message MAC failed"
7935
7936requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7937run_test    "PSK callback: no match" \
7938            "$P_SRV psk_list=abc,dead,def,beef" \
7939            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7940            psk_identity=ghi psk=beef" \
7941            1 \
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_SSL_PROTO_TLS1_2
7947run_test    "PSK callback: wrong key" \
7948            "$P_SRV psk_list=abc,dead,def,beef" \
7949            "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
7950            psk_identity=abc psk=beef" \
7951            1 \
7952            -S "SSL - The handshake negotiation failed" \
7953            -S "SSL - Unknown identity received" \
7954            -s "SSL - Verification of the message MAC failed"
7955
7956# Tests for EC J-PAKE
7957
7958requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
7959requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7960run_test    "ECJPAKE: client not configured" \
7961            "$P_SRV debug_level=3" \
7962            "$P_CLI debug_level=3" \
7963            0 \
7964            -C "add ciphersuite: 0xc0ff" \
7965            -C "adding ecjpake_kkpp extension" \
7966            -S "found ecjpake kkpp extension" \
7967            -S "skip ecjpake kkpp extension" \
7968            -S "ciphersuite mismatch: ecjpake not configured" \
7969            -S "server hello, ecjpake kkpp extension" \
7970            -C "found ecjpake_kkpp extension" \
7971            -S "SSL - The handshake negotiation failed"
7972
7973requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
7974requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7975run_test    "ECJPAKE: server not configured" \
7976            "$P_SRV debug_level=3" \
7977            "$P_CLI debug_level=3 ecjpake_pw=bla \
7978             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
7979            1 \
7980            -c "add ciphersuite: c0ff" \
7981            -c "adding ecjpake_kkpp extension" \
7982            -s "found ecjpake kkpp extension" \
7983            -s "skip ecjpake kkpp extension" \
7984            -s "ciphersuite mismatch: ecjpake not configured" \
7985            -S "server hello, ecjpake kkpp extension" \
7986            -C "found ecjpake_kkpp extension" \
7987            -s "SSL - The handshake negotiation failed"
7988
7989requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
7990requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
7991run_test    "ECJPAKE: working, TLS" \
7992            "$P_SRV debug_level=3 ecjpake_pw=bla" \
7993            "$P_CLI debug_level=3 ecjpake_pw=bla \
7994             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
7995            0 \
7996            -c "add ciphersuite: c0ff" \
7997            -c "adding ecjpake_kkpp extension" \
7998            -C "re-using cached ecjpake parameters" \
7999            -s "found ecjpake kkpp extension" \
8000            -S "skip ecjpake kkpp extension" \
8001            -S "ciphersuite mismatch: ecjpake not configured" \
8002            -s "server hello, ecjpake kkpp extension" \
8003            -c "found ecjpake_kkpp extension" \
8004            -S "SSL - The handshake negotiation failed" \
8005            -S "SSL - Verification of the message MAC failed"
8006
8007server_needs_more_time 1
8008requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8009requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8010run_test    "ECJPAKE: password mismatch, TLS" \
8011            "$P_SRV debug_level=3 ecjpake_pw=bla" \
8012            "$P_CLI debug_level=3 ecjpake_pw=bad \
8013             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8014            1 \
8015            -C "re-using cached ecjpake parameters" \
8016            -s "SSL - Verification of the message MAC failed"
8017
8018requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8019requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8020run_test    "ECJPAKE: working, DTLS" \
8021            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
8022            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
8023             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8024            0 \
8025            -c "re-using cached ecjpake parameters" \
8026            -S "SSL - Verification of the message MAC failed"
8027
8028requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8029requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8030run_test    "ECJPAKE: working, DTLS, no cookie" \
8031            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla cookies=0" \
8032            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
8033             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8034            0 \
8035            -C "re-using cached ecjpake parameters" \
8036            -S "SSL - Verification of the message MAC failed"
8037
8038server_needs_more_time 1
8039requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8040requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8041run_test    "ECJPAKE: password mismatch, DTLS" \
8042            "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
8043            "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bad \
8044             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8045            1 \
8046            -c "re-using cached ecjpake parameters" \
8047            -s "SSL - Verification of the message MAC failed"
8048
8049# for tests with configs/config-thread.h
8050requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
8051requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8052run_test    "ECJPAKE: working, DTLS, nolog" \
8053            "$P_SRV dtls=1 ecjpake_pw=bla" \
8054            "$P_CLI dtls=1 ecjpake_pw=bla \
8055             force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
8056            0
8057
8058# Test for ClientHello without extensions
8059
8060requires_gnutls
8061requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8062run_test    "ClientHello without extensions" \
8063            "$P_SRV debug_level=3" \
8064            "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION localhost" \
8065            0 \
8066            -s "dumping 'client hello extensions' (0 bytes)"
8067
8068# Tests for mbedtls_ssl_get_bytes_avail()
8069
8070# The server first reads buffer_size-1 bytes, then reads the remainder.
8071requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8072run_test    "mbedtls_ssl_get_bytes_avail: no extra data" \
8073            "$P_SRV buffer_size=100" \
8074            "$P_CLI request_size=100" \
8075            0 \
8076            -s "Read from client: 100 bytes read$"
8077
8078requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8079run_test    "mbedtls_ssl_get_bytes_avail: extra data (+1)" \
8080            "$P_SRV buffer_size=100" \
8081            "$P_CLI request_size=101" \
8082            0 \
8083            -s "Read from client: 101 bytes read (100 + 1)"
8084
8085requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8086requires_max_content_len 200
8087run_test    "mbedtls_ssl_get_bytes_avail: extra data (*2)" \
8088            "$P_SRV buffer_size=100" \
8089            "$P_CLI request_size=200" \
8090            0 \
8091            -s "Read from client: 200 bytes read (100 + 100)"
8092
8093requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8094run_test    "mbedtls_ssl_get_bytes_avail: extra data (max)" \
8095            "$P_SRV buffer_size=100" \
8096            "$P_CLI request_size=$MAX_CONTENT_LEN" \
8097            0 \
8098            -s "Read from client: $MAX_CONTENT_LEN bytes read (100 + $((MAX_CONTENT_LEN - 100)))"
8099
8100# Tests for small client packets
8101
8102run_test    "Small client packet TLS 1.2 BlockCipher" \
8103            "$P_SRV force_version=tls12" \
8104            "$P_CLI request_size=1 \
8105             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8106            0 \
8107            -s "Read from client: 1 bytes read"
8108
8109run_test    "Small client packet TLS 1.2 BlockCipher, without EtM" \
8110            "$P_SRV force_version=tls12" \
8111            "$P_CLI request_size=1 \
8112             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
8113            0 \
8114            -s "Read from client: 1 bytes read"
8115
8116run_test    "Small client packet TLS 1.2 BlockCipher larger MAC" \
8117            "$P_SRV force_version=tls12" \
8118            "$P_CLI request_size=1 \
8119             force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8120            0 \
8121            -s "Read from client: 1 bytes read"
8122
8123run_test    "Small client packet TLS 1.2 AEAD" \
8124            "$P_SRV force_version=tls12" \
8125            "$P_CLI request_size=1 \
8126             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8127            0 \
8128            -s "Read from client: 1 bytes read"
8129
8130run_test    "Small client packet TLS 1.2 AEAD shorter tag" \
8131            "$P_SRV force_version=tls12" \
8132            "$P_CLI request_size=1 \
8133             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8134            0 \
8135            -s "Read from client: 1 bytes read"
8136
8137requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8138run_test    "Small client packet TLS 1.3 AEAD" \
8139            "$P_SRV force_version=tls13" \
8140            "$P_CLI request_size=1 \
8141             force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8142            0 \
8143            -s "Read from client: 1 bytes read"
8144
8145requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8146run_test    "Small client packet TLS 1.3 AEAD shorter tag" \
8147            "$P_SRV force_version=tls13" \
8148            "$P_CLI request_size=1 \
8149             force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8150            0 \
8151            -s "Read from client: 1 bytes read"
8152
8153# Tests for small client packets in DTLS
8154
8155requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8156run_test    "Small client packet DTLS 1.2" \
8157            "$P_SRV dtls=1 force_version=dtls12" \
8158            "$P_CLI dtls=1 request_size=1 \
8159             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8160            0 \
8161            -s "Read from client: 1 bytes read"
8162
8163requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8164run_test    "Small client packet DTLS 1.2, without EtM" \
8165            "$P_SRV dtls=1 force_version=dtls12 etm=0" \
8166            "$P_CLI dtls=1 request_size=1 \
8167             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8168            0 \
8169            -s "Read from client: 1 bytes read"
8170
8171# Tests for small server packets
8172
8173run_test    "Small server packet TLS 1.2 BlockCipher" \
8174            "$P_SRV response_size=1 force_version=tls12" \
8175            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8176            0 \
8177            -c "Read from server: 1 bytes read"
8178
8179run_test    "Small server packet TLS 1.2 BlockCipher, without EtM" \
8180            "$P_SRV response_size=1 force_version=tls12" \
8181            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA etm=0" \
8182            0 \
8183            -c "Read from server: 1 bytes read"
8184
8185run_test    "Small server packet TLS 1.2 BlockCipher larger MAC" \
8186            "$P_SRV response_size=1 force_version=tls12" \
8187            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8188            0 \
8189            -c "Read from server: 1 bytes read"
8190
8191run_test    "Small server packet TLS 1.2 AEAD" \
8192            "$P_SRV response_size=1 force_version=tls12" \
8193            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8194            0 \
8195            -c "Read from server: 1 bytes read"
8196
8197run_test    "Small server packet TLS 1.2 AEAD shorter tag" \
8198            "$P_SRV response_size=1 force_version=tls12" \
8199            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8200            0 \
8201            -c "Read from server: 1 bytes read"
8202
8203requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8204run_test    "Small server packet TLS 1.3 AEAD" \
8205            "$P_SRV response_size=1 force_version=tls13" \
8206            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8207            0 \
8208            -c "Read from server: 1 bytes read"
8209
8210requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8211run_test    "Small server packet TLS 1.3 AEAD shorter tag" \
8212            "$P_SRV response_size=1 force_version=tls13" \
8213            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8214            0 \
8215            -c "Read from server: 1 bytes read"
8216
8217# Tests for small server packets in DTLS
8218
8219requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8220run_test    "Small server packet DTLS 1.2" \
8221            "$P_SRV dtls=1 response_size=1 force_version=dtls12" \
8222            "$P_CLI dtls=1 \
8223             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8224            0 \
8225            -c "Read from server: 1 bytes read"
8226
8227requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
8228run_test    "Small server packet DTLS 1.2, without EtM" \
8229            "$P_SRV dtls=1 response_size=1 force_version=dtls12 etm=0" \
8230            "$P_CLI dtls=1 \
8231             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8232            0 \
8233            -c "Read from server: 1 bytes read"
8234
8235# Test for large client packets
8236
8237# How many fragments do we expect to write $1 bytes?
8238fragments_for_write() {
8239    echo "$(( ( $1 + $MAX_OUT_LEN - 1 ) / $MAX_OUT_LEN ))"
8240}
8241
8242run_test    "Large client packet TLS 1.2 BlockCipher" \
8243            "$P_SRV force_version=tls12" \
8244            "$P_CLI request_size=16384 \
8245             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8246            0 \
8247            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8248            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8249
8250run_test    "Large client packet TLS 1.2 BlockCipher, without EtM" \
8251            "$P_SRV force_version=tls12" \
8252            "$P_CLI request_size=16384 etm=0 \
8253             force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8254            0 \
8255            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8256
8257run_test    "Large client packet TLS 1.2 BlockCipher larger MAC" \
8258            "$P_SRV force_version=tls12" \
8259            "$P_CLI request_size=16384 \
8260             force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8261            0 \
8262            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8263            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8264
8265run_test    "Large client packet TLS 1.2 AEAD" \
8266            "$P_SRV force_version=tls12" \
8267            "$P_CLI request_size=16384 \
8268             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8269            0 \
8270            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8271            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8272
8273run_test    "Large client packet TLS 1.2 AEAD shorter tag" \
8274            "$P_SRV force_version=tls12" \
8275            "$P_CLI request_size=16384 \
8276             force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8277            0 \
8278            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8279            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8280
8281requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8282run_test    "Large client packet TLS 1.3 AEAD" \
8283            "$P_SRV force_version=tls13" \
8284            "$P_CLI request_size=16384 \
8285             force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8286            0 \
8287            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8288            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8289
8290requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8291run_test    "Large client packet TLS 1.3 AEAD shorter tag" \
8292            "$P_SRV force_version=tls13" \
8293            "$P_CLI request_size=16384 \
8294             force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8295            0 \
8296            -c "16384 bytes written in $(fragments_for_write 16384) fragments" \
8297            -s "Read from client: $MAX_CONTENT_LEN bytes read"
8298
8299# The tests below fail when the server's OUT_CONTENT_LEN is less than 16384.
8300run_test    "Large server packet TLS 1.2 BlockCipher" \
8301            "$P_SRV response_size=16384 force_version=tls12" \
8302            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8303            0 \
8304            -c "Read from server: 16384 bytes read"
8305
8306run_test    "Large server packet TLS 1.2 BlockCipher, without EtM" \
8307            "$P_SRV response_size=16384 force_version=tls12" \
8308            "$P_CLI etm=0 force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
8309            0 \
8310            -s "16384 bytes written in 1 fragments" \
8311            -c "Read from server: 16384 bytes read"
8312
8313run_test    "Large server packet TLS 1.2 BlockCipher larger MAC" \
8314            "$P_SRV response_size=16384 force_version=tls12" \
8315            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
8316            0 \
8317            -c "Read from server: 16384 bytes read"
8318
8319run_test    "Large server packet TLS 1.2 BlockCipher, without EtM, truncated MAC" \
8320            "$P_SRV response_size=16384 trunc_hmac=1 force_version=tls12" \
8321            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA trunc_hmac=1 etm=0" \
8322            0 \
8323            -s "16384 bytes written in 1 fragments" \
8324            -c "Read from server: 16384 bytes read"
8325
8326run_test    "Large server packet TLS 1.2 AEAD" \
8327            "$P_SRV response_size=16384 force_version=tls12" \
8328            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
8329            0 \
8330            -c "Read from server: 16384 bytes read"
8331
8332run_test    "Large server packet TLS 1.2 AEAD shorter tag" \
8333            "$P_SRV response_size=16384 force_version=tls12" \
8334            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
8335            0 \
8336            -c "Read from server: 16384 bytes read"
8337
8338requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8339run_test    "Large server packet TLS 1.3 AEAD" \
8340            "$P_SRV response_size=16384 force_version=tls13" \
8341            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-SHA256" \
8342            0 \
8343            -c "Read from server: 16384 bytes read"
8344
8345requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
8346run_test    "Large server packet TLS 1.3 AEAD shorter tag" \
8347            "$P_SRV response_size=16384 force_version=tls13" \
8348            "$P_CLI force_ciphersuite=TLS1-3-AES-128-CCM-8-SHA256" \
8349            0 \
8350            -c "Read from server: 16384 bytes read"
8351
8352# Tests for restartable ECC
8353
8354# Force the use of a curve that supports restartable ECC (secp256r1).
8355
8356requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8357requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8358requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8359run_test    "EC restart: TLS, default" \
8360            "$P_SRV curves=secp256r1 auth_mode=required" \
8361            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8362             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8363             debug_level=1" \
8364            0 \
8365            -C "x509_verify_cert.*4b00" \
8366            -C "mbedtls_pk_verify.*4b00" \
8367            -C "mbedtls_ecdh_make_public.*4b00" \
8368            -C "mbedtls_pk_sign.*4b00"
8369
8370requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8371requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8372requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8373run_test    "EC restart: TLS, max_ops=0" \
8374            "$P_SRV curves=secp256r1 auth_mode=required" \
8375            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8376             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8377             debug_level=1 ec_max_ops=0" \
8378            0 \
8379            -C "x509_verify_cert.*4b00" \
8380            -C "mbedtls_pk_verify.*4b00" \
8381            -C "mbedtls_ecdh_make_public.*4b00" \
8382            -C "mbedtls_pk_sign.*4b00"
8383
8384requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8385requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8386requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8387run_test    "EC restart: TLS, max_ops=65535" \
8388            "$P_SRV curves=secp256r1 auth_mode=required" \
8389            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8390             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8391             debug_level=1 ec_max_ops=65535" \
8392            0 \
8393            -C "x509_verify_cert.*4b00" \
8394            -C "mbedtls_pk_verify.*4b00" \
8395            -C "mbedtls_ecdh_make_public.*4b00" \
8396            -C "mbedtls_pk_sign.*4b00"
8397
8398requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8399requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8400requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8401run_test    "EC restart: TLS, max_ops=1000" \
8402            "$P_SRV curves=secp256r1 auth_mode=required" \
8403            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8404             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8405             debug_level=1 ec_max_ops=1000" \
8406            0 \
8407            -c "x509_verify_cert.*4b00" \
8408            -c "mbedtls_pk_verify.*4b00" \
8409            -c "mbedtls_ecdh_make_public.*4b00" \
8410            -c "mbedtls_pk_sign.*4b00"
8411
8412requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8413requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8414requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8415run_test    "EC restart: TLS, max_ops=1000, badsign" \
8416            "$P_SRV curves=secp256r1 auth_mode=required \
8417             crt_file=data_files/server5-badsign.crt \
8418             key_file=data_files/server5.key" \
8419            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8420             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8421             debug_level=1 ec_max_ops=1000" \
8422            1 \
8423            -c "x509_verify_cert.*4b00" \
8424            -C "mbedtls_pk_verify.*4b00" \
8425            -C "mbedtls_ecdh_make_public.*4b00" \
8426            -C "mbedtls_pk_sign.*4b00" \
8427            -c "! The certificate is not correctly signed by the trusted CA" \
8428            -c "! mbedtls_ssl_handshake returned" \
8429            -c "X509 - Certificate verification failed"
8430
8431requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8432requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8433requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8434run_test    "EC restart: TLS, max_ops=1000, auth_mode=optional badsign" \
8435            "$P_SRV curves=secp256r1 auth_mode=required \
8436             crt_file=data_files/server5-badsign.crt \
8437             key_file=data_files/server5.key" \
8438            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8439             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8440             debug_level=1 ec_max_ops=1000 auth_mode=optional" \
8441            0 \
8442            -c "x509_verify_cert.*4b00" \
8443            -c "mbedtls_pk_verify.*4b00" \
8444            -c "mbedtls_ecdh_make_public.*4b00" \
8445            -c "mbedtls_pk_sign.*4b00" \
8446            -c "! The certificate is not correctly signed by the trusted CA" \
8447            -C "! mbedtls_ssl_handshake returned" \
8448            -C "X509 - Certificate verification failed"
8449
8450requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8451requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8452requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8453run_test    "EC restart: TLS, max_ops=1000, auth_mode=none badsign" \
8454            "$P_SRV curves=secp256r1 auth_mode=required \
8455             crt_file=data_files/server5-badsign.crt \
8456             key_file=data_files/server5.key" \
8457            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8458             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8459             debug_level=1 ec_max_ops=1000 auth_mode=none" \
8460            0 \
8461            -C "x509_verify_cert.*4b00" \
8462            -c "mbedtls_pk_verify.*4b00" \
8463            -c "mbedtls_ecdh_make_public.*4b00" \
8464            -c "mbedtls_pk_sign.*4b00" \
8465            -C "! The certificate is not correctly signed by the trusted CA" \
8466            -C "! mbedtls_ssl_handshake returned" \
8467            -C "X509 - Certificate verification failed"
8468
8469requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8470requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8471requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8472run_test    "EC restart: DTLS, max_ops=1000" \
8473            "$P_SRV curves=secp256r1 auth_mode=required dtls=1" \
8474            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8475             key_file=data_files/server5.key crt_file=data_files/server5.crt  \
8476             dtls=1 debug_level=1 ec_max_ops=1000" \
8477            0 \
8478            -c "x509_verify_cert.*4b00" \
8479            -c "mbedtls_pk_verify.*4b00" \
8480            -c "mbedtls_ecdh_make_public.*4b00" \
8481            -c "mbedtls_pk_sign.*4b00"
8482
8483requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8484requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8485requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8486run_test    "EC restart: TLS, max_ops=1000 no client auth" \
8487            "$P_SRV curves=secp256r1" \
8488            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
8489             debug_level=1 ec_max_ops=1000" \
8490            0 \
8491            -c "x509_verify_cert.*4b00" \
8492            -c "mbedtls_pk_verify.*4b00" \
8493            -c "mbedtls_ecdh_make_public.*4b00" \
8494            -C "mbedtls_pk_sign.*4b00"
8495
8496requires_config_enabled MBEDTLS_ECP_RESTARTABLE
8497requires_config_enabled MBEDTLS_ECP_DP_SECP256R1_ENABLED
8498requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8499run_test    "EC restart: TLS, max_ops=1000, ECDHE-PSK" \
8500            "$P_SRV curves=secp256r1 psk=abc123" \
8501            "$P_CLI force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 \
8502             psk=abc123 debug_level=1 ec_max_ops=1000" \
8503            0 \
8504            -C "x509_verify_cert.*4b00" \
8505            -C "mbedtls_pk_verify.*4b00" \
8506            -C "mbedtls_ecdh_make_public.*4b00" \
8507            -C "mbedtls_pk_sign.*4b00"
8508
8509# Tests of asynchronous private key support in SSL
8510
8511requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8512requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8513run_test    "SSL async private: sign, delay=0" \
8514            "$P_SRV \
8515             async_operations=s async_private_delay1=0 async_private_delay2=0" \
8516            "$P_CLI" \
8517            0 \
8518            -s "Async sign callback: using key slot " \
8519            -s "Async resume (slot [0-9]): sign done, status=0"
8520
8521requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8522requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8523run_test    "SSL async private: sign, delay=1" \
8524            "$P_SRV \
8525             async_operations=s async_private_delay1=1 async_private_delay2=1" \
8526            "$P_CLI" \
8527            0 \
8528            -s "Async sign callback: using key slot " \
8529            -s "Async resume (slot [0-9]): call 0 more times." \
8530            -s "Async resume (slot [0-9]): sign done, status=0"
8531
8532requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8533requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8534run_test    "SSL async private: sign, delay=2" \
8535            "$P_SRV \
8536             async_operations=s async_private_delay1=2 async_private_delay2=2" \
8537            "$P_CLI" \
8538            0 \
8539            -s "Async sign callback: using key slot " \
8540            -U "Async sign callback: using key slot " \
8541            -s "Async resume (slot [0-9]): call 1 more times." \
8542            -s "Async resume (slot [0-9]): call 0 more times." \
8543            -s "Async resume (slot [0-9]): sign done, status=0"
8544
8545requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8546requires_config_disabled MBEDTLS_X509_REMOVE_INFO
8547requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8548run_test    "SSL async private: sign, SNI" \
8549            "$P_SRV debug_level=3 \
8550             async_operations=s async_private_delay1=0 async_private_delay2=0 \
8551             crt_file=data_files/server5.crt key_file=data_files/server5.key \
8552             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
8553            "$P_CLI server_name=polarssl.example" \
8554            0 \
8555            -s "Async sign callback: using key slot " \
8556            -s "Async resume (slot [0-9]): sign done, status=0" \
8557            -s "parse ServerName extension" \
8558            -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
8559            -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
8560
8561requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8562requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8563run_test    "SSL async private: decrypt, delay=0" \
8564            "$P_SRV \
8565             async_operations=d async_private_delay1=0 async_private_delay2=0" \
8566            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8567            0 \
8568            -s "Async decrypt callback: using key slot " \
8569            -s "Async resume (slot [0-9]): decrypt done, status=0"
8570
8571requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8572requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8573run_test    "SSL async private: decrypt, delay=1" \
8574            "$P_SRV \
8575             async_operations=d async_private_delay1=1 async_private_delay2=1" \
8576            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8577            0 \
8578            -s "Async decrypt callback: using key slot " \
8579            -s "Async resume (slot [0-9]): call 0 more times." \
8580            -s "Async resume (slot [0-9]): decrypt done, status=0"
8581
8582requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8583requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8584run_test    "SSL async private: decrypt RSA-PSK, delay=0" \
8585            "$P_SRV psk=abc123 \
8586             async_operations=d async_private_delay1=0 async_private_delay2=0" \
8587            "$P_CLI psk=abc123 \
8588             force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
8589            0 \
8590            -s "Async decrypt callback: using key slot " \
8591            -s "Async resume (slot [0-9]): decrypt done, status=0"
8592
8593requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8594requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8595run_test    "SSL async private: decrypt RSA-PSK, delay=1" \
8596            "$P_SRV psk=abc123 \
8597             async_operations=d async_private_delay1=1 async_private_delay2=1" \
8598            "$P_CLI psk=abc123 \
8599             force_ciphersuite=TLS-RSA-PSK-WITH-AES-128-CBC-SHA256" \
8600            0 \
8601            -s "Async decrypt callback: using key slot " \
8602            -s "Async resume (slot [0-9]): call 0 more times." \
8603            -s "Async resume (slot [0-9]): decrypt done, status=0"
8604
8605requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8606requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8607run_test    "SSL async private: sign callback not present" \
8608            "$P_SRV \
8609             async_operations=d async_private_delay1=1 async_private_delay2=1" \
8610            "$P_CLI; [ \$? -eq 1 ] &&
8611             $P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8612            0 \
8613            -S "Async sign callback" \
8614            -s "! mbedtls_ssl_handshake returned" \
8615            -s "The own private key or pre-shared key is not set, but needed" \
8616            -s "Async resume (slot [0-9]): decrypt done, status=0" \
8617            -s "Successful connection"
8618
8619requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8620requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8621run_test    "SSL async private: decrypt callback not present" \
8622            "$P_SRV debug_level=1 \
8623             async_operations=s async_private_delay1=1 async_private_delay2=1" \
8624            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA;
8625             [ \$? -eq 1 ] && $P_CLI" \
8626            0 \
8627            -S "Async decrypt callback" \
8628            -s "! mbedtls_ssl_handshake returned" \
8629            -s "got no RSA private key" \
8630            -s "Async resume (slot [0-9]): sign done, status=0" \
8631            -s "Successful connection"
8632
8633# key1: ECDSA, key2: RSA; use key1 from slot 0
8634requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8635requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8636run_test    "SSL async private: slot 0 used with key1" \
8637            "$P_SRV \
8638             async_operations=s async_private_delay1=1 \
8639             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8640             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8641            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
8642            0 \
8643            -s "Async sign callback: using key slot 0," \
8644            -s "Async resume (slot 0): call 0 more times." \
8645            -s "Async resume (slot 0): sign done, status=0"
8646
8647# key1: ECDSA, key2: RSA; use key2 from slot 0
8648requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8649requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8650run_test    "SSL async private: slot 0 used with key2" \
8651            "$P_SRV \
8652             async_operations=s async_private_delay2=1 \
8653             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8654             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8655            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8656            0 \
8657            -s "Async sign callback: using key slot 0," \
8658            -s "Async resume (slot 0): call 0 more times." \
8659            -s "Async resume (slot 0): sign done, status=0"
8660
8661# key1: ECDSA, key2: RSA; use key2 from slot 1
8662requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8663requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8664run_test    "SSL async private: slot 1 used with key2" \
8665            "$P_SRV \
8666             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8667             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8668             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8669            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8670            0 \
8671            -s "Async sign callback: using key slot 1," \
8672            -s "Async resume (slot 1): call 0 more times." \
8673            -s "Async resume (slot 1): sign done, status=0"
8674
8675# key1: ECDSA, key2: RSA; use key2 directly
8676requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8677requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8678run_test    "SSL async private: fall back to transparent key" \
8679            "$P_SRV \
8680             async_operations=s async_private_delay1=1 \
8681             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8682             key_file2=data_files/server2.key crt_file2=data_files/server2.crt " \
8683            "$P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8684            0 \
8685            -s "Async sign callback: no key matches this certificate."
8686
8687requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8688requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8689run_test    "SSL async private: sign, error in start" \
8690            "$P_SRV \
8691             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8692             async_private_error=1" \
8693            "$P_CLI" \
8694            1 \
8695            -s "Async sign callback: injected error" \
8696            -S "Async resume" \
8697            -S "Async cancel" \
8698            -s "! mbedtls_ssl_handshake returned"
8699
8700requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8701requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8702run_test    "SSL async private: sign, cancel after start" \
8703            "$P_SRV \
8704             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8705             async_private_error=2" \
8706            "$P_CLI" \
8707            1 \
8708            -s "Async sign callback: using key slot " \
8709            -S "Async resume" \
8710            -s "Async cancel"
8711
8712requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8713requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8714run_test    "SSL async private: sign, error in resume" \
8715            "$P_SRV \
8716             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8717             async_private_error=3" \
8718            "$P_CLI" \
8719            1 \
8720            -s "Async sign callback: using key slot " \
8721            -s "Async resume callback: sign done but injected error" \
8722            -S "Async cancel" \
8723            -s "! mbedtls_ssl_handshake returned"
8724
8725requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8726requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8727run_test    "SSL async private: decrypt, error in start" \
8728            "$P_SRV \
8729             async_operations=d async_private_delay1=1 async_private_delay2=1 \
8730             async_private_error=1" \
8731            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8732            1 \
8733            -s "Async decrypt callback: injected error" \
8734            -S "Async resume" \
8735            -S "Async cancel" \
8736            -s "! mbedtls_ssl_handshake returned"
8737
8738requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8739requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8740run_test    "SSL async private: decrypt, cancel after start" \
8741            "$P_SRV \
8742             async_operations=d async_private_delay1=1 async_private_delay2=1 \
8743             async_private_error=2" \
8744            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8745            1 \
8746            -s "Async decrypt callback: using key slot " \
8747            -S "Async resume" \
8748            -s "Async cancel"
8749
8750requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8751requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8752run_test    "SSL async private: decrypt, error in resume" \
8753            "$P_SRV \
8754             async_operations=d async_private_delay1=1 async_private_delay2=1 \
8755             async_private_error=3" \
8756            "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8757            1 \
8758            -s "Async decrypt callback: using key slot " \
8759            -s "Async resume callback: decrypt done but injected error" \
8760            -S "Async cancel" \
8761            -s "! mbedtls_ssl_handshake returned"
8762
8763requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8764requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8765run_test    "SSL async private: cancel after start then operate correctly" \
8766            "$P_SRV \
8767             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8768             async_private_error=-2" \
8769            "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
8770            0 \
8771            -s "Async cancel" \
8772            -s "! mbedtls_ssl_handshake returned" \
8773            -s "Async resume" \
8774            -s "Successful connection"
8775
8776requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8777requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8778run_test    "SSL async private: error in resume then operate correctly" \
8779            "$P_SRV \
8780             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8781             async_private_error=-3" \
8782            "$P_CLI; [ \$? -eq 1 ] && $P_CLI" \
8783            0 \
8784            -s "! mbedtls_ssl_handshake returned" \
8785            -s "Async resume" \
8786            -s "Successful connection"
8787
8788# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
8789requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8790requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8791run_test    "SSL async private: cancel after start then fall back to transparent key" \
8792            "$P_SRV \
8793             async_operations=s async_private_delay1=1 async_private_error=-2 \
8794             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8795             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8796            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
8797             [ \$? -eq 1 ] &&
8798             $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8799            0 \
8800            -s "Async sign callback: using key slot 0" \
8801            -S "Async resume" \
8802            -s "Async cancel" \
8803            -s "! mbedtls_ssl_handshake returned" \
8804            -s "Async sign callback: no key matches this certificate." \
8805            -s "Successful connection"
8806
8807# key1: ECDSA, key2: RSA; use key1 through async, then key2 directly
8808requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8809requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8810run_test    "SSL async private: sign, error in resume then fall back to transparent key" \
8811            "$P_SRV \
8812             async_operations=s async_private_delay1=1 async_private_error=-3 \
8813             key_file=data_files/server5.key crt_file=data_files/server5.crt \
8814             key_file2=data_files/server2.key crt_file2=data_files/server2.crt" \
8815            "$P_CLI force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256;
8816             [ \$? -eq 1 ] &&
8817             $P_CLI force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" \
8818            0 \
8819            -s "Async resume" \
8820            -s "! mbedtls_ssl_handshake returned" \
8821            -s "Async sign callback: no key matches this certificate." \
8822            -s "Successful connection"
8823
8824requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8825requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
8826requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8827run_test    "SSL async private: renegotiation: client-initiated, sign" \
8828            "$P_SRV \
8829             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8830             exchanges=2 renegotiation=1" \
8831            "$P_CLI exchanges=2 renegotiation=1 renegotiate=1" \
8832            0 \
8833            -s "Async sign callback: using key slot " \
8834            -s "Async resume (slot [0-9]): sign done, status=0"
8835
8836requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8837requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
8838requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8839run_test    "SSL async private: renegotiation: server-initiated, sign" \
8840            "$P_SRV \
8841             async_operations=s async_private_delay1=1 async_private_delay2=1 \
8842             exchanges=2 renegotiation=1 renegotiate=1" \
8843            "$P_CLI exchanges=2 renegotiation=1" \
8844            0 \
8845            -s "Async sign callback: using key slot " \
8846            -s "Async resume (slot [0-9]): sign done, status=0"
8847
8848requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8849requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
8850requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8851run_test    "SSL async private: renegotiation: client-initiated, decrypt" \
8852            "$P_SRV \
8853             async_operations=d async_private_delay1=1 async_private_delay2=1 \
8854             exchanges=2 renegotiation=1" \
8855            "$P_CLI exchanges=2 renegotiation=1 renegotiate=1 \
8856             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8857            0 \
8858            -s "Async decrypt callback: using key slot " \
8859            -s "Async resume (slot [0-9]): decrypt done, status=0"
8860
8861requires_config_enabled MBEDTLS_SSL_ASYNC_PRIVATE
8862requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
8863requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8864run_test    "SSL async private: renegotiation: server-initiated, decrypt" \
8865            "$P_SRV \
8866             async_operations=d async_private_delay1=1 async_private_delay2=1 \
8867             exchanges=2 renegotiation=1 renegotiate=1" \
8868            "$P_CLI exchanges=2 renegotiation=1 \
8869             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
8870            0 \
8871            -s "Async decrypt callback: using key slot " \
8872            -s "Async resume (slot [0-9]): decrypt done, status=0"
8873
8874# Tests for ECC extensions (rfc 4492)
8875
8876requires_config_enabled MBEDTLS_AES_C
8877requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
8878requires_hash_alg SHA_256
8879requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
8880requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8881run_test    "Force a non ECC ciphersuite in the client side" \
8882            "$P_SRV debug_level=3" \
8883            "$P_CLI debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
8884            0 \
8885            -C "client hello, adding supported_groups extension" \
8886            -C "client hello, adding supported_point_formats extension" \
8887            -S "found supported elliptic curves extension" \
8888            -S "found supported point formats extension"
8889
8890requires_config_enabled MBEDTLS_AES_C
8891requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
8892requires_hash_alg SHA_256
8893requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
8894requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8895run_test    "Force a non ECC ciphersuite in the server side" \
8896            "$P_SRV debug_level=3 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA256" \
8897            "$P_CLI debug_level=3" \
8898            0 \
8899            -C "found supported_point_formats extension" \
8900            -S "server hello, supported_point_formats extension"
8901
8902requires_config_enabled MBEDTLS_AES_C
8903requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
8904requires_hash_alg SHA_256
8905requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
8906requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8907run_test    "Force an ECC ciphersuite in the client side" \
8908            "$P_SRV debug_level=3" \
8909            "$P_CLI debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
8910            0 \
8911            -c "client hello, adding supported_groups extension" \
8912            -c "client hello, adding supported_point_formats extension" \
8913            -s "found supported elliptic curves extension" \
8914            -s "found supported point formats extension"
8915
8916requires_config_enabled MBEDTLS_AES_C
8917requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
8918requires_hash_alg SHA_256
8919requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
8920requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8921run_test    "Force an ECC ciphersuite in the server side" \
8922            "$P_SRV debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
8923            "$P_CLI debug_level=3" \
8924            0 \
8925            -c "found supported_point_formats extension" \
8926            -s "server hello, supported_point_formats extension"
8927
8928# Tests for DTLS HelloVerifyRequest
8929
8930requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8931run_test    "DTLS cookie: enabled" \
8932            "$P_SRV dtls=1 debug_level=2" \
8933            "$P_CLI dtls=1 debug_level=2" \
8934            0 \
8935            -s "cookie verification failed" \
8936            -s "cookie verification passed" \
8937            -S "cookie verification skipped" \
8938            -c "received hello verify request" \
8939            -s "hello verification requested" \
8940            -S "SSL - The requested feature is not available"
8941
8942requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8943run_test    "DTLS cookie: disabled" \
8944            "$P_SRV dtls=1 debug_level=2 cookies=0" \
8945            "$P_CLI dtls=1 debug_level=2" \
8946            0 \
8947            -S "cookie verification failed" \
8948            -S "cookie verification passed" \
8949            -s "cookie verification skipped" \
8950            -C "received hello verify request" \
8951            -S "hello verification requested" \
8952            -S "SSL - The requested feature is not available"
8953
8954requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8955run_test    "DTLS cookie: default (failing)" \
8956            "$P_SRV dtls=1 debug_level=2 cookies=-1" \
8957            "$P_CLI dtls=1 debug_level=2 hs_timeout=100-400" \
8958            1 \
8959            -s "cookie verification failed" \
8960            -S "cookie verification passed" \
8961            -S "cookie verification skipped" \
8962            -C "received hello verify request" \
8963            -S "hello verification requested" \
8964            -s "SSL - The requested feature is not available"
8965
8966requires_ipv6
8967requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8968run_test    "DTLS cookie: enabled, IPv6" \
8969            "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
8970            "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
8971            0 \
8972            -s "cookie verification failed" \
8973            -s "cookie verification passed" \
8974            -S "cookie verification skipped" \
8975            -c "received hello verify request" \
8976            -s "hello verification requested" \
8977            -S "SSL - The requested feature is not available"
8978
8979requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8980run_test    "DTLS cookie: enabled, nbio" \
8981            "$P_SRV dtls=1 nbio=2 debug_level=2" \
8982            "$P_CLI dtls=1 nbio=2 debug_level=2" \
8983            0 \
8984            -s "cookie verification failed" \
8985            -s "cookie verification passed" \
8986            -S "cookie verification skipped" \
8987            -c "received hello verify request" \
8988            -s "hello verification requested" \
8989            -S "SSL - The requested feature is not available"
8990
8991# Tests for client reconnecting from the same port with DTLS
8992
8993not_with_valgrind # spurious resend
8994requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
8995run_test    "DTLS client reconnect from same port: reference" \
8996            "$P_SRV dtls=1 exchanges=2 read_timeout=20000 hs_timeout=10000-20000" \
8997            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=10000-20000" \
8998            0 \
8999            -C "resend" \
9000            -S "The operation timed out" \
9001            -S "Client initiated reconnection from same port"
9002
9003not_with_valgrind # spurious resend
9004requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9005run_test    "DTLS client reconnect from same port: reconnect" \
9006            "$P_SRV dtls=1 exchanges=2 read_timeout=20000 hs_timeout=10000-20000" \
9007            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=10000-20000 reconnect_hard=1" \
9008            0 \
9009            -C "resend" \
9010            -S "The operation timed out" \
9011            -s "Client initiated reconnection from same port"
9012
9013not_with_valgrind # server/client too slow to respond in time (next test has higher timeouts)
9014requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9015run_test    "DTLS client reconnect from same port: reconnect, nbio, no valgrind" \
9016            "$P_SRV dtls=1 exchanges=2 read_timeout=1000 nbio=2" \
9017            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000 reconnect_hard=1" \
9018            0 \
9019            -S "The operation timed out" \
9020            -s "Client initiated reconnection from same port"
9021
9022only_with_valgrind # Only with valgrind, do previous test but with higher read_timeout and hs_timeout
9023requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9024run_test    "DTLS client reconnect from same port: reconnect, nbio, valgrind" \
9025            "$P_SRV dtls=1 exchanges=2 read_timeout=2000 nbio=2 hs_timeout=1500-6000" \
9026            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=1500-3000 reconnect_hard=1" \
9027            0 \
9028            -S "The operation timed out" \
9029            -s "Client initiated reconnection from same port"
9030
9031requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9032run_test    "DTLS client reconnect from same port: no cookies" \
9033            "$P_SRV dtls=1 exchanges=2 read_timeout=1000 cookies=0" \
9034            "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-8000 reconnect_hard=1" \
9035            0 \
9036            -s "The operation timed out" \
9037            -S "Client initiated reconnection from same port"
9038
9039requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9040run_test    "DTLS client reconnect from same port: attacker-injected" \
9041            -p "$P_PXY inject_clihlo=1" \
9042            "$P_SRV dtls=1 exchanges=2 debug_level=1" \
9043            "$P_CLI dtls=1 exchanges=2" \
9044            0 \
9045            -s "possible client reconnect from the same port" \
9046            -S "Client initiated reconnection from same port"
9047
9048# Tests for various cases of client authentication with DTLS
9049# (focused on handshake flows and message parsing)
9050
9051requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9052run_test    "DTLS client auth: required" \
9053            "$P_SRV dtls=1 auth_mode=required" \
9054            "$P_CLI dtls=1" \
9055            0 \
9056            -s "Verifying peer X.509 certificate... ok"
9057
9058requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9059run_test    "DTLS client auth: optional, client has no cert" \
9060            "$P_SRV dtls=1 auth_mode=optional" \
9061            "$P_CLI dtls=1 crt_file=none key_file=none" \
9062            0 \
9063            -s "! Certificate was missing"
9064
9065requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9066run_test    "DTLS client auth: none, client has no cert" \
9067            "$P_SRV dtls=1 auth_mode=none" \
9068            "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
9069            0 \
9070            -c "skip write certificate$" \
9071            -s "! Certificate verification was skipped"
9072
9073requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9074run_test    "DTLS wrong PSK: badmac alert" \
9075            "$P_SRV dtls=1 psk=abc123 force_ciphersuite=TLS-PSK-WITH-AES-128-GCM-SHA256" \
9076            "$P_CLI dtls=1 psk=abc124" \
9077            1 \
9078            -s "SSL - Verification of the message MAC failed" \
9079            -c "SSL - A fatal alert message was received from our peer"
9080
9081# Tests for receiving fragmented handshake messages with DTLS
9082
9083requires_gnutls
9084requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9085run_test    "DTLS reassembly: no fragmentation (gnutls server)" \
9086            "$G_SRV -u --mtu 2048 -a" \
9087            "$P_CLI dtls=1 debug_level=2" \
9088            0 \
9089            -C "found fragmented DTLS handshake message" \
9090            -C "error"
9091
9092requires_gnutls
9093requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9094run_test    "DTLS reassembly: some fragmentation (gnutls server)" \
9095            "$G_SRV -u --mtu 512" \
9096            "$P_CLI dtls=1 debug_level=2" \
9097            0 \
9098            -c "found fragmented DTLS handshake message" \
9099            -C "error"
9100
9101requires_gnutls
9102requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9103run_test    "DTLS reassembly: more fragmentation (gnutls server)" \
9104            "$G_SRV -u --mtu 128" \
9105            "$P_CLI dtls=1 debug_level=2" \
9106            0 \
9107            -c "found fragmented DTLS handshake message" \
9108            -C "error"
9109
9110requires_gnutls
9111requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9112run_test    "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
9113            "$G_SRV -u --mtu 128" \
9114            "$P_CLI dtls=1 nbio=2 debug_level=2" \
9115            0 \
9116            -c "found fragmented DTLS handshake message" \
9117            -C "error"
9118
9119requires_gnutls
9120requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9121requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9122run_test    "DTLS reassembly: fragmentation, renego (gnutls server)" \
9123            "$G_SRV -u --mtu 256" \
9124            "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
9125            0 \
9126            -c "found fragmented DTLS handshake message" \
9127            -c "client hello, adding renegotiation extension" \
9128            -c "found renegotiation extension" \
9129            -c "=> renegotiate" \
9130            -C "mbedtls_ssl_handshake returned" \
9131            -C "error" \
9132            -s "Extra-header:"
9133
9134requires_gnutls
9135requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9136requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9137run_test    "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
9138            "$G_SRV -u --mtu 256" \
9139            "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
9140            0 \
9141            -c "found fragmented DTLS handshake message" \
9142            -c "client hello, adding renegotiation extension" \
9143            -c "found renegotiation extension" \
9144            -c "=> renegotiate" \
9145            -C "mbedtls_ssl_handshake returned" \
9146            -C "error" \
9147            -s "Extra-header:"
9148
9149requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9150run_test    "DTLS reassembly: no fragmentation (openssl server)" \
9151            "$O_SRV -dtls -mtu 2048" \
9152            "$P_CLI dtls=1 debug_level=2" \
9153            0 \
9154            -C "found fragmented DTLS handshake message" \
9155            -C "error"
9156
9157requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9158run_test    "DTLS reassembly: some fragmentation (openssl server)" \
9159            "$O_SRV -dtls -mtu 768" \
9160            "$P_CLI dtls=1 debug_level=2" \
9161            0 \
9162            -c "found fragmented DTLS handshake message" \
9163            -C "error"
9164
9165requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9166run_test    "DTLS reassembly: more fragmentation (openssl server)" \
9167            "$O_SRV -dtls -mtu 256" \
9168            "$P_CLI dtls=1 debug_level=2" \
9169            0 \
9170            -c "found fragmented DTLS handshake message" \
9171            -C "error"
9172
9173requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9174run_test    "DTLS reassembly: fragmentation, nbio (openssl server)" \
9175            "$O_SRV -dtls -mtu 256" \
9176            "$P_CLI dtls=1 nbio=2 debug_level=2" \
9177            0 \
9178            -c "found fragmented DTLS handshake message" \
9179            -C "error"
9180
9181# Tests for sending fragmented handshake messages with DTLS
9182#
9183# Use client auth when we need the client to send large messages,
9184# and use large cert chains on both sides too (the long chains we have all use
9185# both RSA and ECDSA, but ideally we should have long chains with either).
9186# Sizes reached (UDP payload):
9187# - 2037B for server certificate
9188# - 1542B for client certificate
9189# - 1013B for newsessionticket
9190# - all others below 512B
9191# All those tests assume MAX_CONTENT_LEN is at least 2048
9192
9193requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9194requires_config_enabled MBEDTLS_RSA_C
9195requires_config_enabled MBEDTLS_ECDSA_C
9196requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9197requires_max_content_len 4096
9198requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9199run_test    "DTLS fragmenting: none (for reference)" \
9200            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9201             crt_file=data_files/server7_int-ca.crt \
9202             key_file=data_files/server7.key \
9203             hs_timeout=2500-60000 \
9204             max_frag_len=4096" \
9205            "$P_CLI dtls=1 debug_level=2 \
9206             crt_file=data_files/server8_int-ca2.crt \
9207             key_file=data_files/server8.key \
9208             hs_timeout=2500-60000 \
9209             max_frag_len=4096" \
9210            0 \
9211            -S "found fragmented DTLS handshake message" \
9212            -C "found fragmented DTLS handshake message" \
9213            -C "error"
9214
9215requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9216requires_config_enabled MBEDTLS_RSA_C
9217requires_config_enabled MBEDTLS_ECDSA_C
9218requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9219requires_max_content_len 2048
9220requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9221run_test    "DTLS fragmenting: server only (max_frag_len)" \
9222            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9223             crt_file=data_files/server7_int-ca.crt \
9224             key_file=data_files/server7.key \
9225             hs_timeout=2500-60000 \
9226             max_frag_len=1024" \
9227            "$P_CLI dtls=1 debug_level=2 \
9228             crt_file=data_files/server8_int-ca2.crt \
9229             key_file=data_files/server8.key \
9230             hs_timeout=2500-60000 \
9231             max_frag_len=2048" \
9232            0 \
9233            -S "found fragmented DTLS handshake message" \
9234            -c "found fragmented DTLS handshake message" \
9235            -C "error"
9236
9237# With the MFL extension, the server has no way of forcing
9238# the client to not exceed a certain MTU; hence, the following
9239# test can't be replicated with an MTU proxy such as the one
9240# `client-initiated, server only (max_frag_len)` below.
9241requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9242requires_config_enabled MBEDTLS_RSA_C
9243requires_config_enabled MBEDTLS_ECDSA_C
9244requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9245requires_max_content_len 4096
9246requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9247run_test    "DTLS fragmenting: server only (more) (max_frag_len)" \
9248            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9249             crt_file=data_files/server7_int-ca.crt \
9250             key_file=data_files/server7.key \
9251             hs_timeout=2500-60000 \
9252             max_frag_len=512" \
9253            "$P_CLI dtls=1 debug_level=2 \
9254             crt_file=data_files/server8_int-ca2.crt \
9255             key_file=data_files/server8.key \
9256             hs_timeout=2500-60000 \
9257             max_frag_len=4096" \
9258            0 \
9259            -S "found fragmented DTLS handshake message" \
9260            -c "found fragmented DTLS handshake message" \
9261            -C "error"
9262
9263requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9264requires_config_enabled MBEDTLS_RSA_C
9265requires_config_enabled MBEDTLS_ECDSA_C
9266requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9267requires_max_content_len 2048
9268requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9269run_test    "DTLS fragmenting: client-initiated, server only (max_frag_len)" \
9270            "$P_SRV dtls=1 debug_level=2 auth_mode=none \
9271             crt_file=data_files/server7_int-ca.crt \
9272             key_file=data_files/server7.key \
9273             hs_timeout=2500-60000 \
9274             max_frag_len=2048" \
9275            "$P_CLI dtls=1 debug_level=2 \
9276             crt_file=data_files/server8_int-ca2.crt \
9277             key_file=data_files/server8.key \
9278             hs_timeout=2500-60000 \
9279             max_frag_len=1024" \
9280             0 \
9281            -S "found fragmented DTLS handshake message" \
9282            -c "found fragmented DTLS handshake message" \
9283            -C "error"
9284
9285# While not required by the standard defining the MFL extension
9286# (according to which it only applies to records, not to datagrams),
9287# Mbed TLS will never send datagrams larger than MFL + { Max record expansion },
9288# as otherwise there wouldn't be any means to communicate MTU restrictions
9289# to the peer.
9290# The next test checks that no datagrams significantly larger than the
9291# negotiated MFL are sent.
9292requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9293requires_config_enabled MBEDTLS_RSA_C
9294requires_config_enabled MBEDTLS_ECDSA_C
9295requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9296requires_max_content_len 2048
9297requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9298run_test    "DTLS fragmenting: client-initiated, server only (max_frag_len), proxy MTU" \
9299            -p "$P_PXY mtu=1110" \
9300            "$P_SRV dtls=1 debug_level=2 auth_mode=none \
9301             crt_file=data_files/server7_int-ca.crt \
9302             key_file=data_files/server7.key \
9303             hs_timeout=2500-60000 \
9304             max_frag_len=2048" \
9305            "$P_CLI dtls=1 debug_level=2 \
9306             crt_file=data_files/server8_int-ca2.crt \
9307             key_file=data_files/server8.key \
9308             hs_timeout=2500-60000 \
9309             max_frag_len=1024" \
9310            0 \
9311            -S "found fragmented DTLS handshake message" \
9312            -c "found fragmented DTLS handshake message" \
9313            -C "error"
9314
9315requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9316requires_config_enabled MBEDTLS_RSA_C
9317requires_config_enabled MBEDTLS_ECDSA_C
9318requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9319requires_max_content_len 2048
9320requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9321run_test    "DTLS fragmenting: client-initiated, both (max_frag_len)" \
9322            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9323             crt_file=data_files/server7_int-ca.crt \
9324             key_file=data_files/server7.key \
9325             hs_timeout=2500-60000 \
9326             max_frag_len=2048" \
9327            "$P_CLI dtls=1 debug_level=2 \
9328             crt_file=data_files/server8_int-ca2.crt \
9329             key_file=data_files/server8.key \
9330             hs_timeout=2500-60000 \
9331             max_frag_len=1024" \
9332            0 \
9333            -s "found fragmented DTLS handshake message" \
9334            -c "found fragmented DTLS handshake message" \
9335            -C "error"
9336
9337# While not required by the standard defining the MFL extension
9338# (according to which it only applies to records, not to datagrams),
9339# Mbed TLS will never send datagrams larger than MFL + { Max record expansion },
9340# as otherwise there wouldn't be any means to communicate MTU restrictions
9341# to the peer.
9342# The next test checks that no datagrams significantly larger than the
9343# negotiated MFL are sent.
9344requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9345requires_config_enabled MBEDTLS_RSA_C
9346requires_config_enabled MBEDTLS_ECDSA_C
9347requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
9348requires_max_content_len 2048
9349requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9350run_test    "DTLS fragmenting: client-initiated, both (max_frag_len), proxy MTU" \
9351            -p "$P_PXY mtu=1110" \
9352            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9353             crt_file=data_files/server7_int-ca.crt \
9354             key_file=data_files/server7.key \
9355             hs_timeout=2500-60000 \
9356             max_frag_len=2048" \
9357            "$P_CLI dtls=1 debug_level=2 \
9358             crt_file=data_files/server8_int-ca2.crt \
9359             key_file=data_files/server8.key \
9360             hs_timeout=2500-60000 \
9361             max_frag_len=1024" \
9362            0 \
9363            -s "found fragmented DTLS handshake message" \
9364            -c "found fragmented DTLS handshake message" \
9365            -C "error"
9366
9367requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9368requires_config_enabled MBEDTLS_RSA_C
9369requires_config_enabled MBEDTLS_ECDSA_C
9370requires_max_content_len 4096
9371requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9372run_test    "DTLS fragmenting: none (for reference) (MTU)" \
9373            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9374             crt_file=data_files/server7_int-ca.crt \
9375             key_file=data_files/server7.key \
9376             hs_timeout=2500-60000 \
9377             mtu=4096" \
9378            "$P_CLI dtls=1 debug_level=2 \
9379             crt_file=data_files/server8_int-ca2.crt \
9380             key_file=data_files/server8.key \
9381             hs_timeout=2500-60000 \
9382             mtu=4096" \
9383            0 \
9384            -S "found fragmented DTLS handshake message" \
9385            -C "found fragmented DTLS handshake message" \
9386            -C "error"
9387
9388requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9389requires_config_enabled MBEDTLS_RSA_C
9390requires_config_enabled MBEDTLS_ECDSA_C
9391requires_max_content_len 4096
9392requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9393run_test    "DTLS fragmenting: client (MTU)" \
9394            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9395             crt_file=data_files/server7_int-ca.crt \
9396             key_file=data_files/server7.key \
9397             hs_timeout=3500-60000 \
9398             mtu=4096" \
9399            "$P_CLI dtls=1 debug_level=2 \
9400             crt_file=data_files/server8_int-ca2.crt \
9401             key_file=data_files/server8.key \
9402             hs_timeout=3500-60000 \
9403             mtu=1024" \
9404            0 \
9405            -s "found fragmented DTLS handshake message" \
9406            -C "found fragmented DTLS handshake message" \
9407            -C "error"
9408
9409requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9410requires_config_enabled MBEDTLS_RSA_C
9411requires_config_enabled MBEDTLS_ECDSA_C
9412requires_max_content_len 2048
9413requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9414run_test    "DTLS fragmenting: server (MTU)" \
9415            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9416             crt_file=data_files/server7_int-ca.crt \
9417             key_file=data_files/server7.key \
9418             hs_timeout=2500-60000 \
9419             mtu=512" \
9420            "$P_CLI dtls=1 debug_level=2 \
9421             crt_file=data_files/server8_int-ca2.crt \
9422             key_file=data_files/server8.key \
9423             hs_timeout=2500-60000 \
9424             mtu=2048" \
9425            0 \
9426            -S "found fragmented DTLS handshake message" \
9427            -c "found fragmented DTLS handshake message" \
9428            -C "error"
9429
9430requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9431requires_config_enabled MBEDTLS_RSA_C
9432requires_config_enabled MBEDTLS_ECDSA_C
9433requires_max_content_len 2048
9434requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9435run_test    "DTLS fragmenting: both (MTU=1024)" \
9436            -p "$P_PXY mtu=1024" \
9437            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9438             crt_file=data_files/server7_int-ca.crt \
9439             key_file=data_files/server7.key \
9440             hs_timeout=2500-60000 \
9441             mtu=1024" \
9442            "$P_CLI dtls=1 debug_level=2 \
9443             crt_file=data_files/server8_int-ca2.crt \
9444             key_file=data_files/server8.key \
9445             hs_timeout=2500-60000 \
9446             mtu=1024" \
9447            0 \
9448            -s "found fragmented DTLS handshake message" \
9449            -c "found fragmented DTLS handshake message" \
9450            -C "error"
9451
9452# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9453requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9454requires_config_enabled MBEDTLS_RSA_C
9455requires_config_enabled MBEDTLS_ECDSA_C
9456requires_hash_alg SHA_256
9457requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9458requires_config_enabled MBEDTLS_AES_C
9459requires_config_enabled MBEDTLS_GCM_C
9460requires_max_content_len 2048
9461requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9462run_test    "DTLS fragmenting: both (MTU=512)" \
9463            -p "$P_PXY mtu=512" \
9464            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9465             crt_file=data_files/server7_int-ca.crt \
9466             key_file=data_files/server7.key \
9467             hs_timeout=2500-60000 \
9468             mtu=512" \
9469            "$P_CLI dtls=1 debug_level=2 \
9470             crt_file=data_files/server8_int-ca2.crt \
9471             key_file=data_files/server8.key \
9472             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9473             hs_timeout=2500-60000 \
9474             mtu=512" \
9475            0 \
9476            -s "found fragmented DTLS handshake message" \
9477            -c "found fragmented DTLS handshake message" \
9478            -C "error"
9479
9480# Test for automatic MTU reduction on repeated resend.
9481# Forcing ciphersuite for this test to fit the MTU of 508 with full config.
9482# The ratio of max/min timeout should ideally equal 4 to accept two
9483# retransmissions, but in some cases (like both the server and client using
9484# fragmentation and auto-reduction) an extra retransmission might occur,
9485# hence the ratio of 8.
9486not_with_valgrind
9487requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9488requires_config_enabled MBEDTLS_RSA_C
9489requires_config_enabled MBEDTLS_ECDSA_C
9490requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9491requires_config_enabled MBEDTLS_AES_C
9492requires_config_enabled MBEDTLS_GCM_C
9493requires_max_content_len 2048
9494requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9495run_test    "DTLS fragmenting: proxy MTU: auto-reduction (not valgrind)" \
9496            -p "$P_PXY mtu=508" \
9497            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9498             crt_file=data_files/server7_int-ca.crt \
9499             key_file=data_files/server7.key \
9500             hs_timeout=400-3200" \
9501            "$P_CLI dtls=1 debug_level=2 \
9502             crt_file=data_files/server8_int-ca2.crt \
9503             key_file=data_files/server8.key \
9504             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9505             hs_timeout=400-3200" \
9506            0 \
9507            -s "found fragmented DTLS handshake message" \
9508            -c "found fragmented DTLS handshake message" \
9509            -C "error"
9510
9511# Forcing ciphersuite for this test to fit the MTU of 508 with full config.
9512only_with_valgrind
9513requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9514requires_config_enabled MBEDTLS_RSA_C
9515requires_config_enabled MBEDTLS_ECDSA_C
9516requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9517requires_config_enabled MBEDTLS_AES_C
9518requires_config_enabled MBEDTLS_GCM_C
9519requires_max_content_len 2048
9520requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9521run_test    "DTLS fragmenting: proxy MTU: auto-reduction (with valgrind)" \
9522            -p "$P_PXY mtu=508" \
9523            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9524             crt_file=data_files/server7_int-ca.crt \
9525             key_file=data_files/server7.key \
9526             hs_timeout=250-10000" \
9527            "$P_CLI dtls=1 debug_level=2 \
9528             crt_file=data_files/server8_int-ca2.crt \
9529             key_file=data_files/server8.key \
9530             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9531             hs_timeout=250-10000" \
9532            0 \
9533            -s "found fragmented DTLS handshake message" \
9534            -c "found fragmented DTLS handshake message" \
9535            -C "error"
9536
9537# the proxy shouldn't drop or mess up anything, so we shouldn't need to resend
9538# OTOH the client might resend if the server is to slow to reset after sending
9539# a HelloVerifyRequest, so only check for no retransmission server-side
9540not_with_valgrind # spurious autoreduction due to timeout
9541requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9542requires_config_enabled MBEDTLS_RSA_C
9543requires_config_enabled MBEDTLS_ECDSA_C
9544requires_max_content_len 2048
9545requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9546run_test    "DTLS fragmenting: proxy MTU, simple handshake (MTU=1024)" \
9547            -p "$P_PXY mtu=1024" \
9548            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9549             crt_file=data_files/server7_int-ca.crt \
9550             key_file=data_files/server7.key \
9551             hs_timeout=10000-60000 \
9552             mtu=1024" \
9553            "$P_CLI dtls=1 debug_level=2 \
9554             crt_file=data_files/server8_int-ca2.crt \
9555             key_file=data_files/server8.key \
9556             hs_timeout=10000-60000 \
9557             mtu=1024" \
9558            0 \
9559            -S "autoreduction" \
9560            -s "found fragmented DTLS handshake message" \
9561            -c "found fragmented DTLS handshake message" \
9562            -C "error"
9563
9564# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9565# the proxy shouldn't drop or mess up anything, so we shouldn't need to resend
9566# OTOH the client might resend if the server is to slow to reset after sending
9567# a HelloVerifyRequest, so only check for no retransmission server-side
9568not_with_valgrind # spurious autoreduction due to timeout
9569requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9570requires_config_enabled MBEDTLS_RSA_C
9571requires_config_enabled MBEDTLS_ECDSA_C
9572requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9573requires_config_enabled MBEDTLS_AES_C
9574requires_config_enabled MBEDTLS_GCM_C
9575requires_max_content_len 2048
9576requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9577run_test    "DTLS fragmenting: proxy MTU, simple handshake (MTU=512)" \
9578            -p "$P_PXY mtu=512" \
9579            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9580             crt_file=data_files/server7_int-ca.crt \
9581             key_file=data_files/server7.key \
9582             hs_timeout=10000-60000 \
9583             mtu=512" \
9584            "$P_CLI dtls=1 debug_level=2 \
9585             crt_file=data_files/server8_int-ca2.crt \
9586             key_file=data_files/server8.key \
9587             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9588             hs_timeout=10000-60000 \
9589             mtu=512" \
9590            0 \
9591            -S "autoreduction" \
9592            -s "found fragmented DTLS handshake message" \
9593            -c "found fragmented DTLS handshake message" \
9594            -C "error"
9595
9596not_with_valgrind # spurious autoreduction due to timeout
9597requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9598requires_config_enabled MBEDTLS_RSA_C
9599requires_config_enabled MBEDTLS_ECDSA_C
9600requires_max_content_len 2048
9601requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9602run_test    "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=1024)" \
9603            -p "$P_PXY mtu=1024" \
9604            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9605             crt_file=data_files/server7_int-ca.crt \
9606             key_file=data_files/server7.key \
9607             hs_timeout=10000-60000 \
9608             mtu=1024 nbio=2" \
9609            "$P_CLI dtls=1 debug_level=2 \
9610             crt_file=data_files/server8_int-ca2.crt \
9611             key_file=data_files/server8.key \
9612             hs_timeout=10000-60000 \
9613             mtu=1024 nbio=2" \
9614            0 \
9615            -S "autoreduction" \
9616            -s "found fragmented DTLS handshake message" \
9617            -c "found fragmented DTLS handshake message" \
9618            -C "error"
9619
9620# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9621not_with_valgrind # spurious autoreduction due to timeout
9622requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9623requires_config_enabled MBEDTLS_RSA_C
9624requires_config_enabled MBEDTLS_ECDSA_C
9625requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9626requires_config_enabled MBEDTLS_AES_C
9627requires_config_enabled MBEDTLS_GCM_C
9628requires_max_content_len 2048
9629requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9630run_test    "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=512)" \
9631            -p "$P_PXY mtu=512" \
9632            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9633             crt_file=data_files/server7_int-ca.crt \
9634             key_file=data_files/server7.key \
9635             hs_timeout=10000-60000 \
9636             mtu=512 nbio=2" \
9637            "$P_CLI dtls=1 debug_level=2 \
9638             crt_file=data_files/server8_int-ca2.crt \
9639             key_file=data_files/server8.key \
9640             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9641             hs_timeout=10000-60000 \
9642             mtu=512 nbio=2" \
9643            0 \
9644            -S "autoreduction" \
9645            -s "found fragmented DTLS handshake message" \
9646            -c "found fragmented DTLS handshake message" \
9647            -C "error"
9648
9649# Forcing ciphersuite for this test to fit the MTU of 1450 with full config.
9650# This ensures things still work after session_reset().
9651# It also exercises the "resumed handshake" flow.
9652# Since we don't support reading fragmented ClientHello yet,
9653# up the MTU to 1450 (larger than ClientHello with session ticket,
9654# but still smaller than client's Certificate to ensure fragmentation).
9655# An autoreduction on the client-side might happen if the server is
9656# slow to reset, therefore omitting '-C "autoreduction"' below.
9657# reco_delay avoids races where the client reconnects before the server has
9658# resumed listening, which would result in a spurious autoreduction.
9659not_with_valgrind # spurious autoreduction due to timeout
9660requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9661requires_config_enabled MBEDTLS_RSA_C
9662requires_config_enabled MBEDTLS_ECDSA_C
9663requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9664requires_config_enabled MBEDTLS_AES_C
9665requires_config_enabled MBEDTLS_GCM_C
9666requires_max_content_len 2048
9667requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9668run_test    "DTLS fragmenting: proxy MTU, resumed handshake" \
9669            -p "$P_PXY mtu=1450" \
9670            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9671             crt_file=data_files/server7_int-ca.crt \
9672             key_file=data_files/server7.key \
9673             hs_timeout=10000-60000 \
9674             mtu=1450" \
9675            "$P_CLI dtls=1 debug_level=2 \
9676             crt_file=data_files/server8_int-ca2.crt \
9677             key_file=data_files/server8.key \
9678             hs_timeout=10000-60000 \
9679             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9680             mtu=1450 reconnect=1 skip_close_notify=1 reco_delay=1" \
9681            0 \
9682            -S "autoreduction" \
9683            -s "found fragmented DTLS handshake message" \
9684            -c "found fragmented DTLS handshake message" \
9685            -C "error"
9686
9687# An autoreduction on the client-side might happen if the server is
9688# slow to reset, therefore omitting '-C "autoreduction"' below.
9689not_with_valgrind # spurious autoreduction due to timeout
9690requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9691requires_config_enabled MBEDTLS_RSA_C
9692requires_config_enabled MBEDTLS_ECDSA_C
9693requires_hash_alg SHA_256
9694requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9695requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9696requires_config_enabled MBEDTLS_CHACHAPOLY_C
9697requires_max_content_len 2048
9698requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9699run_test    "DTLS fragmenting: proxy MTU, ChachaPoly renego" \
9700            -p "$P_PXY mtu=512" \
9701            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9702             crt_file=data_files/server7_int-ca.crt \
9703             key_file=data_files/server7.key \
9704             exchanges=2 renegotiation=1 \
9705             hs_timeout=10000-60000 \
9706             mtu=512" \
9707            "$P_CLI dtls=1 debug_level=2 \
9708             crt_file=data_files/server8_int-ca2.crt \
9709             key_file=data_files/server8.key \
9710             exchanges=2 renegotiation=1 renegotiate=1 \
9711             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9712             hs_timeout=10000-60000 \
9713             mtu=512" \
9714            0 \
9715            -S "autoreduction" \
9716            -s "found fragmented DTLS handshake message" \
9717            -c "found fragmented DTLS handshake message" \
9718            -C "error"
9719
9720# An autoreduction on the client-side might happen if the server is
9721# slow to reset, therefore omitting '-C "autoreduction"' below.
9722not_with_valgrind # spurious autoreduction due to timeout
9723requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9724requires_config_enabled MBEDTLS_RSA_C
9725requires_config_enabled MBEDTLS_ECDSA_C
9726requires_hash_alg SHA_256
9727requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9728requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9729requires_config_enabled MBEDTLS_AES_C
9730requires_config_enabled MBEDTLS_GCM_C
9731requires_max_content_len 2048
9732requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9733run_test    "DTLS fragmenting: proxy MTU, AES-GCM renego" \
9734            -p "$P_PXY mtu=512" \
9735            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9736             crt_file=data_files/server7_int-ca.crt \
9737             key_file=data_files/server7.key \
9738             exchanges=2 renegotiation=1 \
9739             hs_timeout=10000-60000 \
9740             mtu=512" \
9741            "$P_CLI dtls=1 debug_level=2 \
9742             crt_file=data_files/server8_int-ca2.crt \
9743             key_file=data_files/server8.key \
9744             exchanges=2 renegotiation=1 renegotiate=1 \
9745             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9746             hs_timeout=10000-60000 \
9747             mtu=512" \
9748            0 \
9749            -S "autoreduction" \
9750            -s "found fragmented DTLS handshake message" \
9751            -c "found fragmented DTLS handshake message" \
9752            -C "error"
9753
9754# An autoreduction on the client-side might happen if the server is
9755# slow to reset, therefore omitting '-C "autoreduction"' below.
9756not_with_valgrind # spurious autoreduction due to timeout
9757requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9758requires_config_enabled MBEDTLS_RSA_C
9759requires_config_enabled MBEDTLS_ECDSA_C
9760requires_hash_alg SHA_256
9761requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9762requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9763requires_config_enabled MBEDTLS_AES_C
9764requires_config_enabled MBEDTLS_CCM_C
9765requires_max_content_len 2048
9766requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9767run_test    "DTLS fragmenting: proxy MTU, AES-CCM renego" \
9768            -p "$P_PXY mtu=1024" \
9769            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9770             crt_file=data_files/server7_int-ca.crt \
9771             key_file=data_files/server7.key \
9772             exchanges=2 renegotiation=1 \
9773             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8 \
9774             hs_timeout=10000-60000 \
9775             mtu=1024" \
9776            "$P_CLI dtls=1 debug_level=2 \
9777             crt_file=data_files/server8_int-ca2.crt \
9778             key_file=data_files/server8.key \
9779             exchanges=2 renegotiation=1 renegotiate=1 \
9780             hs_timeout=10000-60000 \
9781             mtu=1024" \
9782            0 \
9783            -S "autoreduction" \
9784            -s "found fragmented DTLS handshake message" \
9785            -c "found fragmented DTLS handshake message" \
9786            -C "error"
9787
9788# An autoreduction on the client-side might happen if the server is
9789# slow to reset, therefore omitting '-C "autoreduction"' below.
9790not_with_valgrind # spurious autoreduction due to timeout
9791requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9792requires_config_enabled MBEDTLS_RSA_C
9793requires_config_enabled MBEDTLS_ECDSA_C
9794requires_hash_alg SHA_256
9795requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9796requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9797requires_config_enabled MBEDTLS_AES_C
9798requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
9799requires_config_enabled MBEDTLS_SSL_ENCRYPT_THEN_MAC
9800requires_max_content_len 2048
9801requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9802run_test    "DTLS fragmenting: proxy MTU, AES-CBC EtM renego" \
9803            -p "$P_PXY mtu=1024" \
9804            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9805             crt_file=data_files/server7_int-ca.crt \
9806             key_file=data_files/server7.key \
9807             exchanges=2 renegotiation=1 \
9808             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 \
9809             hs_timeout=10000-60000 \
9810             mtu=1024" \
9811            "$P_CLI dtls=1 debug_level=2 \
9812             crt_file=data_files/server8_int-ca2.crt \
9813             key_file=data_files/server8.key \
9814             exchanges=2 renegotiation=1 renegotiate=1 \
9815             hs_timeout=10000-60000 \
9816             mtu=1024" \
9817            0 \
9818            -S "autoreduction" \
9819            -s "found fragmented DTLS handshake message" \
9820            -c "found fragmented DTLS handshake message" \
9821            -C "error"
9822
9823# An autoreduction on the client-side might happen if the server is
9824# slow to reset, therefore omitting '-C "autoreduction"' below.
9825not_with_valgrind # spurious autoreduction due to timeout
9826requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9827requires_config_enabled MBEDTLS_RSA_C
9828requires_config_enabled MBEDTLS_ECDSA_C
9829requires_hash_alg SHA_256
9830requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9831requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
9832requires_config_enabled MBEDTLS_AES_C
9833requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
9834requires_max_content_len 2048
9835requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9836run_test    "DTLS fragmenting: proxy MTU, AES-CBC non-EtM renego" \
9837            -p "$P_PXY mtu=1024" \
9838            "$P_SRV dtls=1 debug_level=2 auth_mode=required \
9839             crt_file=data_files/server7_int-ca.crt \
9840             key_file=data_files/server7.key \
9841             exchanges=2 renegotiation=1 \
9842             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 etm=0 \
9843             hs_timeout=10000-60000 \
9844             mtu=1024" \
9845            "$P_CLI dtls=1 debug_level=2 \
9846             crt_file=data_files/server8_int-ca2.crt \
9847             key_file=data_files/server8.key \
9848             exchanges=2 renegotiation=1 renegotiate=1 \
9849             hs_timeout=10000-60000 \
9850             mtu=1024" \
9851            0 \
9852            -S "autoreduction" \
9853            -s "found fragmented DTLS handshake message" \
9854            -c "found fragmented DTLS handshake message" \
9855            -C "error"
9856
9857# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9858requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9859requires_config_enabled MBEDTLS_RSA_C
9860requires_config_enabled MBEDTLS_ECDSA_C
9861requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9862requires_config_enabled MBEDTLS_AES_C
9863requires_config_enabled MBEDTLS_GCM_C
9864client_needs_more_time 2
9865requires_max_content_len 2048
9866requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9867run_test    "DTLS fragmenting: proxy MTU + 3d" \
9868            -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
9869            "$P_SRV dgram_packing=0 dtls=1 debug_level=2 auth_mode=required \
9870             crt_file=data_files/server7_int-ca.crt \
9871             key_file=data_files/server7.key \
9872             hs_timeout=250-10000 mtu=512" \
9873            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
9874             crt_file=data_files/server8_int-ca2.crt \
9875             key_file=data_files/server8.key \
9876             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9877             hs_timeout=250-10000 mtu=512" \
9878            0 \
9879            -s "found fragmented DTLS handshake message" \
9880            -c "found fragmented DTLS handshake message" \
9881            -C "error"
9882
9883# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
9884requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9885requires_config_enabled MBEDTLS_RSA_C
9886requires_config_enabled MBEDTLS_ECDSA_C
9887requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
9888requires_config_enabled MBEDTLS_AES_C
9889requires_config_enabled MBEDTLS_GCM_C
9890client_needs_more_time 2
9891requires_max_content_len 2048
9892requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
9893run_test    "DTLS fragmenting: proxy MTU + 3d, nbio" \
9894            -p "$P_PXY mtu=512 drop=8 delay=8 duplicate=8" \
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=250-10000 mtu=512 nbio=2" \
9899            "$P_CLI dtls=1 debug_level=2 \
9900             crt_file=data_files/server8_int-ca2.crt \
9901             key_file=data_files/server8.key \
9902             force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
9903             hs_timeout=250-10000 mtu=512 nbio=2" \
9904            0 \
9905            -s "found fragmented DTLS handshake message" \
9906            -c "found fragmented DTLS handshake message" \
9907            -C "error"
9908
9909# interop tests for DTLS fragmentating with reliable connection
9910#
9911# here and below we just want to test that the we fragment in a way that
9912# pleases other implementations, so we don't need the peer to fragment
9913requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9914requires_config_enabled MBEDTLS_RSA_C
9915requires_config_enabled MBEDTLS_ECDSA_C
9916requires_gnutls
9917requires_max_content_len 2048
9918run_test    "DTLS fragmenting: gnutls server, DTLS 1.2" \
9919            "$G_SRV -u" \
9920            "$P_CLI dtls=1 debug_level=2 \
9921             crt_file=data_files/server8_int-ca2.crt \
9922             key_file=data_files/server8.key \
9923             mtu=512 force_version=dtls12" \
9924            0 \
9925            -c "fragmenting handshake message" \
9926            -C "error"
9927
9928# We use --insecure for the GnuTLS client because it expects
9929# the hostname / IP it connects to to be the name used in the
9930# certificate obtained from the server. Here, however, it
9931# connects to 127.0.0.1 while our test certificates use 'localhost'
9932# as the server name in the certificate. This will make the
9933# certificate validation fail, but passing --insecure makes
9934# GnuTLS continue the connection nonetheless.
9935requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9936requires_config_enabled MBEDTLS_RSA_C
9937requires_config_enabled MBEDTLS_ECDSA_C
9938requires_gnutls
9939requires_not_i686
9940requires_max_content_len 2048
9941run_test    "DTLS fragmenting: gnutls client, DTLS 1.2" \
9942            "$P_SRV dtls=1 debug_level=2 \
9943             crt_file=data_files/server7_int-ca.crt \
9944             key_file=data_files/server7.key \
9945             mtu=512 force_version=dtls12" \
9946            "$G_CLI -u --insecure 127.0.0.1" \
9947            0 \
9948            -s "fragmenting handshake message"
9949
9950requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9951requires_config_enabled MBEDTLS_RSA_C
9952requires_config_enabled MBEDTLS_ECDSA_C
9953requires_max_content_len 2048
9954run_test    "DTLS fragmenting: openssl server, DTLS 1.2" \
9955            "$O_SRV -dtls1_2 -verify 10" \
9956            "$P_CLI dtls=1 debug_level=2 \
9957             crt_file=data_files/server8_int-ca2.crt \
9958             key_file=data_files/server8.key \
9959             mtu=512 force_version=dtls12" \
9960            0 \
9961            -c "fragmenting handshake message" \
9962            -C "error"
9963
9964requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9965requires_config_enabled MBEDTLS_RSA_C
9966requires_config_enabled MBEDTLS_ECDSA_C
9967requires_max_content_len 2048
9968run_test    "DTLS fragmenting: openssl client, DTLS 1.2" \
9969            "$P_SRV dtls=1 debug_level=2 \
9970             crt_file=data_files/server7_int-ca.crt \
9971             key_file=data_files/server7.key \
9972             mtu=512 force_version=dtls12" \
9973            "$O_CLI -dtls1_2" \
9974            0 \
9975            -s "fragmenting handshake message"
9976
9977# interop tests for DTLS fragmentating with unreliable connection
9978#
9979# again we just want to test that the we fragment in a way that
9980# pleases other implementations, so we don't need the peer to fragment
9981requires_gnutls_next
9982requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
9983requires_config_enabled MBEDTLS_RSA_C
9984requires_config_enabled MBEDTLS_ECDSA_C
9985client_needs_more_time 4
9986requires_max_content_len 2048
9987run_test    "DTLS fragmenting: 3d, gnutls server, DTLS 1.2" \
9988            -p "$P_PXY drop=8 delay=8 duplicate=8" \
9989            "$G_NEXT_SRV -u" \
9990            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
9991             crt_file=data_files/server8_int-ca2.crt \
9992             key_file=data_files/server8.key \
9993             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
9994            0 \
9995            -c "fragmenting handshake message" \
9996            -C "error"
9997
9998requires_gnutls_next
9999requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10000requires_config_enabled MBEDTLS_RSA_C
10001requires_config_enabled MBEDTLS_ECDSA_C
10002client_needs_more_time 4
10003requires_max_content_len 2048
10004run_test    "DTLS fragmenting: 3d, gnutls client, DTLS 1.2" \
10005            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10006            "$P_SRV dtls=1 debug_level=2 \
10007             crt_file=data_files/server7_int-ca.crt \
10008             key_file=data_files/server7.key \
10009             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10010           "$G_NEXT_CLI -u --insecure 127.0.0.1" \
10011            0 \
10012            -s "fragmenting handshake message"
10013
10014## The test below requires 1.1.1a or higher version of openssl, otherwise
10015## it might trigger a bug due to openssl server (https://github.com/openssl/openssl/issues/6902)
10016requires_openssl_next
10017requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10018requires_config_enabled MBEDTLS_RSA_C
10019requires_config_enabled MBEDTLS_ECDSA_C
10020client_needs_more_time 4
10021requires_max_content_len 2048
10022run_test    "DTLS fragmenting: 3d, openssl server, DTLS 1.2" \
10023            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10024            "$O_NEXT_SRV -dtls1_2 -verify 10" \
10025            "$P_CLI dtls=1 debug_level=2 \
10026             crt_file=data_files/server8_int-ca2.crt \
10027             key_file=data_files/server8.key \
10028             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10029            0 \
10030            -c "fragmenting handshake message" \
10031            -C "error"
10032
10033## the test below will time out with certain seed.
10034## The cause is an openssl bug (https://github.com/openssl/openssl/issues/18887)
10035skip_next_test
10036requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
10037requires_config_enabled MBEDTLS_RSA_C
10038requires_config_enabled MBEDTLS_ECDSA_C
10039client_needs_more_time 4
10040requires_max_content_len 2048
10041run_test    "DTLS fragmenting: 3d, openssl client, DTLS 1.2" \
10042            -p "$P_PXY drop=8 delay=8 duplicate=8" \
10043            "$P_SRV dtls=1 debug_level=2 \
10044             crt_file=data_files/server7_int-ca.crt \
10045             key_file=data_files/server7.key \
10046             hs_timeout=250-60000 mtu=512 force_version=dtls12" \
10047            "$O_CLI -dtls1_2" \
10048            0 \
10049            -s "fragmenting handshake message"
10050
10051# Tests for DTLS-SRTP (RFC 5764)
10052requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10053requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10054run_test  "DTLS-SRTP all profiles supported" \
10055          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10056          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10057          0 \
10058          -s "found use_srtp extension" \
10059          -s "found srtp profile" \
10060          -s "selected srtp profile" \
10061          -s "server hello, adding use_srtp extension" \
10062          -s "DTLS-SRTP key material is"\
10063          -c "client hello, adding use_srtp extension" \
10064          -c "found use_srtp extension" \
10065          -c "found srtp profile" \
10066          -c "selected srtp profile" \
10067          -c "DTLS-SRTP key material is"\
10068          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10069          -C "error"
10070
10071
10072requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10073requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10074run_test  "DTLS-SRTP server supports all profiles. Client supports one profile." \
10075          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10076          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=5 debug_level=3" \
10077          0 \
10078          -s "found use_srtp extension" \
10079          -s "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10080          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10081          -s "server hello, adding use_srtp extension" \
10082          -s "DTLS-SRTP key material is"\
10083          -c "client hello, adding use_srtp extension" \
10084          -c "found use_srtp extension" \
10085          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10086          -c "selected srtp profile" \
10087          -c "DTLS-SRTP key material is"\
10088          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10089          -C "error"
10090
10091requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10092requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10093run_test  "DTLS-SRTP server supports one profile. Client supports all profiles." \
10094          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10095          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10096          0 \
10097          -s "found use_srtp extension" \
10098          -s "found srtp profile" \
10099          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10100          -s "server hello, adding use_srtp extension" \
10101          -s "DTLS-SRTP key material is"\
10102          -c "client hello, adding use_srtp extension" \
10103          -c "found use_srtp extension" \
10104          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10105          -c "selected srtp profile" \
10106          -c "DTLS-SRTP key material is"\
10107          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10108          -C "error"
10109
10110requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10111requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10112run_test  "DTLS-SRTP server and Client support only one matching profile." \
10113          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10114          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10115          0 \
10116          -s "found use_srtp extension" \
10117          -s "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10118          -s "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10119          -s "server hello, adding use_srtp extension" \
10120          -s "DTLS-SRTP key material is"\
10121          -c "client hello, adding use_srtp extension" \
10122          -c "found use_srtp extension" \
10123          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10124          -c "selected srtp profile" \
10125          -c "DTLS-SRTP key material is"\
10126          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10127          -C "error"
10128
10129requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10130requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10131run_test  "DTLS-SRTP server and Client support only one different profile." \
10132          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10133          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10134          0 \
10135          -s "found use_srtp extension" \
10136          -s "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10137          -S "selected srtp profile" \
10138          -S "server hello, adding use_srtp extension" \
10139          -S "DTLS-SRTP key material is"\
10140          -c "client hello, adding use_srtp extension" \
10141          -C "found use_srtp extension" \
10142          -C "found srtp profile" \
10143          -C "selected srtp profile" \
10144          -C "DTLS-SRTP key material is"\
10145          -C "error"
10146
10147requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10148requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10149run_test  "DTLS-SRTP server doesn't support use_srtp extension." \
10150          "$P_SRV dtls=1 debug_level=3" \
10151          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10152          0 \
10153          -s "found use_srtp extension" \
10154          -S "server hello, adding use_srtp extension" \
10155          -S "DTLS-SRTP key material is"\
10156          -c "client hello, adding use_srtp extension" \
10157          -C "found use_srtp extension" \
10158          -C "found srtp profile" \
10159          -C "selected srtp profile" \
10160          -C "DTLS-SRTP key material is"\
10161          -C "error"
10162
10163requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10164requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10165run_test  "DTLS-SRTP all profiles supported. mki used" \
10166          "$P_SRV dtls=1 use_srtp=1 support_mki=1 debug_level=3" \
10167          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10168          0 \
10169          -s "found use_srtp extension" \
10170          -s "found srtp profile" \
10171          -s "selected srtp profile" \
10172          -s "server hello, adding use_srtp extension" \
10173          -s "dumping 'using mki' (8 bytes)" \
10174          -s "DTLS-SRTP key material is"\
10175          -c "client hello, adding use_srtp extension" \
10176          -c "found use_srtp extension" \
10177          -c "found srtp profile" \
10178          -c "selected srtp profile" \
10179          -c "dumping 'sending mki' (8 bytes)" \
10180          -c "dumping 'received mki' (8 bytes)" \
10181          -c "DTLS-SRTP key material is"\
10182          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10183          -g "find_in_both '^ *DTLS-SRTP mki value: [0-9A-F]*$'"\
10184          -C "error"
10185
10186requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10187requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10188run_test  "DTLS-SRTP all profiles supported. server doesn't support mki." \
10189          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10190          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10191          0 \
10192          -s "found use_srtp extension" \
10193          -s "found srtp profile" \
10194          -s "selected srtp profile" \
10195          -s "server hello, adding use_srtp extension" \
10196          -s "DTLS-SRTP key material is"\
10197          -s "DTLS-SRTP no mki value negotiated"\
10198          -S "dumping 'using mki' (8 bytes)" \
10199          -c "client hello, adding use_srtp extension" \
10200          -c "found use_srtp extension" \
10201          -c "found srtp profile" \
10202          -c "selected srtp profile" \
10203          -c "DTLS-SRTP key material is"\
10204          -c "DTLS-SRTP no mki value negotiated"\
10205          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10206          -c "dumping 'sending mki' (8 bytes)" \
10207          -C "dumping 'received mki' (8 bytes)" \
10208          -C "error"
10209
10210requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10211requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10212run_test  "DTLS-SRTP all profiles supported. openssl client." \
10213          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10214          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10215          0 \
10216          -s "found use_srtp extension" \
10217          -s "found srtp profile" \
10218          -s "selected srtp profile" \
10219          -s "server hello, adding use_srtp extension" \
10220          -s "DTLS-SRTP key material is"\
10221          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10222          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_80"
10223
10224requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10225requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10226run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. openssl client." \
10227          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10228          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32:SRTP_AES128_CM_SHA1_80 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10229          0 \
10230          -s "found use_srtp extension" \
10231          -s "found srtp profile" \
10232          -s "selected srtp profile" \
10233          -s "server hello, adding use_srtp extension" \
10234          -s "DTLS-SRTP key material is"\
10235          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10236          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10237
10238requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10239requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10240run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. openssl client." \
10241          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10242          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10243          0 \
10244          -s "found use_srtp extension" \
10245          -s "found srtp profile" \
10246          -s "selected srtp profile" \
10247          -s "server hello, adding use_srtp extension" \
10248          -s "DTLS-SRTP key material is"\
10249          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10250          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10251
10252requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10253requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10254run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. openssl client." \
10255          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10256          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10257          0 \
10258          -s "found use_srtp extension" \
10259          -s "found srtp profile" \
10260          -s "selected srtp profile" \
10261          -s "server hello, adding use_srtp extension" \
10262          -s "DTLS-SRTP key material is"\
10263          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10264          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10265
10266requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10267requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10268run_test  "DTLS-SRTP server and Client support only one matching profile. openssl client." \
10269          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10270          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10271          0 \
10272          -s "found use_srtp extension" \
10273          -s "found srtp profile" \
10274          -s "selected srtp profile" \
10275          -s "server hello, adding use_srtp extension" \
10276          -s "DTLS-SRTP key material is"\
10277          -g "find_in_both '^ *Keying material: [0-9A-F]*$'"\
10278          -c "SRTP Extension negotiated, profile=SRTP_AES128_CM_SHA1_32"
10279
10280requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10281requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10282run_test  "DTLS-SRTP server and Client support only one different profile. openssl client." \
10283          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=1 debug_level=3" \
10284          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10285          0 \
10286          -s "found use_srtp extension" \
10287          -s "found srtp profile" \
10288          -S "selected srtp profile" \
10289          -S "server hello, adding use_srtp extension" \
10290          -S "DTLS-SRTP key material is"\
10291          -C "SRTP Extension negotiated, profile"
10292
10293requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10294requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10295run_test  "DTLS-SRTP server doesn't support use_srtp extension. openssl client" \
10296          "$P_SRV dtls=1 debug_level=3" \
10297          "$O_CLI -dtls -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10298          0 \
10299          -s "found use_srtp extension" \
10300          -S "server hello, adding use_srtp extension" \
10301          -S "DTLS-SRTP key material is"\
10302          -C "SRTP Extension negotiated, profile"
10303
10304requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10305requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10306run_test  "DTLS-SRTP all profiles supported. openssl server" \
10307          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10308          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10309          0 \
10310          -c "client hello, adding use_srtp extension" \
10311          -c "found use_srtp extension" \
10312          -c "found srtp profile" \
10313          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
10314          -c "DTLS-SRTP key material is"\
10315          -C "error"
10316
10317requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10318requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10319run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. openssl server." \
10320          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32:SRTP_AES128_CM_SHA1_80 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10321          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10322          0 \
10323          -c "client hello, adding use_srtp extension" \
10324          -c "found use_srtp extension" \
10325          -c "found srtp profile" \
10326          -c "selected srtp profile" \
10327          -c "DTLS-SRTP key material is"\
10328          -C "error"
10329
10330requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10331requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10332run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. openssl server." \
10333          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10334          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10335          0 \
10336          -c "client hello, adding use_srtp extension" \
10337          -c "found use_srtp extension" \
10338          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10339          -c "selected srtp profile" \
10340          -c "DTLS-SRTP key material is"\
10341          -C "error"
10342
10343requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10344requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10345run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. openssl server." \
10346          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10347          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10348          0 \
10349          -c "client hello, adding use_srtp extension" \
10350          -c "found use_srtp extension" \
10351          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10352          -c "selected srtp profile" \
10353          -c "DTLS-SRTP key material is"\
10354          -C "error"
10355
10356requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10357requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10358run_test  "DTLS-SRTP server and Client support only one matching profile. openssl server." \
10359          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10360          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10361          0 \
10362          -c "client hello, adding use_srtp extension" \
10363          -c "found use_srtp extension" \
10364          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10365          -c "selected srtp profile" \
10366          -c "DTLS-SRTP key material is"\
10367          -C "error"
10368
10369requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10370requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10371run_test  "DTLS-SRTP server and Client support only one different profile. openssl server." \
10372          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10373          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10374          0 \
10375          -c "client hello, adding use_srtp extension" \
10376          -C "found use_srtp extension" \
10377          -C "found srtp profile" \
10378          -C "selected srtp profile" \
10379          -C "DTLS-SRTP key material is"\
10380          -C "error"
10381
10382requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10383requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10384run_test  "DTLS-SRTP server doesn't support use_srtp extension. openssl server" \
10385          "$O_SRV -dtls" \
10386          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10387          0 \
10388          -c "client hello, adding use_srtp extension" \
10389          -C "found use_srtp extension" \
10390          -C "found srtp profile" \
10391          -C "selected srtp profile" \
10392          -C "DTLS-SRTP key material is"\
10393          -C "error"
10394
10395requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10396requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10397run_test  "DTLS-SRTP all profiles supported. server doesn't support mki. openssl server." \
10398          "$O_SRV -dtls -verify 0 -use_srtp SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32 -keymatexport 'EXTRACTOR-dtls_srtp' -keymatexportlen 60" \
10399          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10400          0 \
10401          -c "client hello, adding use_srtp extension" \
10402          -c "found use_srtp extension" \
10403          -c "found srtp profile" \
10404          -c "selected srtp profile" \
10405          -c "DTLS-SRTP key material is"\
10406          -c "DTLS-SRTP no mki value negotiated"\
10407          -c "dumping 'sending mki' (8 bytes)" \
10408          -C "dumping 'received mki' (8 bytes)" \
10409          -C "error"
10410
10411requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10412requires_gnutls
10413requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10414run_test  "DTLS-SRTP all profiles supported. gnutls client." \
10415          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10416          "$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" \
10417          0 \
10418          -s "found use_srtp extension" \
10419          -s "found srtp profile" \
10420          -s "selected srtp profile" \
10421          -s "server hello, adding use_srtp extension" \
10422          -s "DTLS-SRTP key material is"\
10423          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_80"
10424
10425requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10426requires_gnutls
10427requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10428run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. gnutls client." \
10429          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10430          "$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" \
10431          0 \
10432          -s "found use_srtp extension" \
10433          -s "found srtp profile" \
10434          -s "selected srtp profile" \
10435          -s "server hello, adding use_srtp extension" \
10436          -s "DTLS-SRTP key material is"\
10437          -c "SRTP profile: SRTP_NULL_HMAC_SHA1_80"
10438
10439requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10440requires_gnutls
10441requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10442run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. gnutls client." \
10443          "$P_SRV dtls=1 use_srtp=1 debug_level=3" \
10444          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
10445          0 \
10446          -s "found use_srtp extension" \
10447          -s "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10448          -s "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10449          -s "server hello, adding use_srtp extension" \
10450          -s "DTLS-SRTP key material is"\
10451          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_32"
10452
10453requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10454requires_gnutls
10455requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10456run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. gnutls client." \
10457          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10458          "$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" \
10459          0 \
10460          -s "found use_srtp extension" \
10461          -s "found srtp profile" \
10462          -s "selected srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" \
10463          -s "server hello, adding use_srtp extension" \
10464          -s "DTLS-SRTP key material is"\
10465          -c "SRTP profile: SRTP_NULL_SHA1_32"
10466
10467requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10468requires_gnutls
10469requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10470run_test  "DTLS-SRTP server and Client support only one matching profile. gnutls client." \
10471          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10472          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
10473          0 \
10474          -s "found use_srtp extension" \
10475          -s "found srtp profile" \
10476          -s "selected srtp profile" \
10477          -s "server hello, adding use_srtp extension" \
10478          -s "DTLS-SRTP key material is"\
10479          -c "SRTP profile: SRTP_AES128_CM_HMAC_SHA1_32"
10480
10481requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10482requires_gnutls
10483requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10484run_test  "DTLS-SRTP server and Client support only one different profile. gnutls client." \
10485          "$P_SRV dtls=1 use_srtp=1 srtp_force_profile=1 debug_level=3" \
10486          "$G_CLI -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32 --insecure 127.0.0.1" \
10487          0 \
10488          -s "found use_srtp extension" \
10489          -s "found srtp profile" \
10490          -S "selected srtp profile" \
10491          -S "server hello, adding use_srtp extension" \
10492          -S "DTLS-SRTP key material is"\
10493          -C "SRTP profile:"
10494
10495requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10496requires_gnutls
10497requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10498run_test  "DTLS-SRTP server doesn't support use_srtp extension. gnutls client" \
10499          "$P_SRV dtls=1 debug_level=3" \
10500          "$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" \
10501          0 \
10502          -s "found use_srtp extension" \
10503          -S "server hello, adding use_srtp extension" \
10504          -S "DTLS-SRTP key material is"\
10505          -C "SRTP profile:"
10506
10507requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10508requires_gnutls
10509requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10510run_test  "DTLS-SRTP all profiles supported. gnutls server" \
10511          "$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" \
10512          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10513          0 \
10514          -c "client hello, adding use_srtp extension" \
10515          -c "found use_srtp extension" \
10516          -c "found srtp profile" \
10517          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
10518          -c "DTLS-SRTP key material is"\
10519          -C "error"
10520
10521requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10522requires_gnutls
10523requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10524run_test  "DTLS-SRTP server supports all profiles. Client supports all profiles, in different order. gnutls server." \
10525          "$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" \
10526          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10527          0 \
10528          -c "client hello, adding use_srtp extension" \
10529          -c "found use_srtp extension" \
10530          -c "found srtp profile" \
10531          -c "selected srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" \
10532          -c "DTLS-SRTP key material is"\
10533          -C "error"
10534
10535requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10536requires_gnutls
10537requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10538run_test  "DTLS-SRTP server supports all profiles. Client supports one profile. gnutls server." \
10539          "$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" \
10540          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10541          0 \
10542          -c "client hello, adding use_srtp extension" \
10543          -c "found use_srtp extension" \
10544          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10545          -c "selected srtp profile" \
10546          -c "DTLS-SRTP key material is"\
10547          -C "error"
10548
10549requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10550requires_gnutls
10551requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10552run_test  "DTLS-SRTP server supports one profile. Client supports all profiles. gnutls server." \
10553          "$G_SRV -u --srtp-profiles=SRTP_NULL_HMAC_SHA1_80" \
10554          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10555          0 \
10556          -c "client hello, adding use_srtp extension" \
10557          -c "found use_srtp extension" \
10558          -c "found srtp profile: MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" \
10559          -c "selected srtp profile" \
10560          -c "DTLS-SRTP key material is"\
10561          -C "error"
10562
10563requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10564requires_gnutls
10565requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10566run_test  "DTLS-SRTP server and Client support only one matching profile. gnutls server." \
10567          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32" \
10568          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=2 debug_level=3" \
10569          0 \
10570          -c "client hello, adding use_srtp extension" \
10571          -c "found use_srtp extension" \
10572          -c "found srtp profile: MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" \
10573          -c "selected srtp profile" \
10574          -c "DTLS-SRTP key material is"\
10575          -C "error"
10576
10577requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10578requires_gnutls
10579requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10580run_test  "DTLS-SRTP server and Client support only one different profile. gnutls server." \
10581          "$G_SRV -u --srtp-profiles=SRTP_AES128_CM_HMAC_SHA1_32" \
10582          "$P_CLI dtls=1 use_srtp=1 srtp_force_profile=6 debug_level=3" \
10583          0 \
10584          -c "client hello, adding use_srtp extension" \
10585          -C "found use_srtp extension" \
10586          -C "found srtp profile" \
10587          -C "selected srtp profile" \
10588          -C "DTLS-SRTP key material is"\
10589          -C "error"
10590
10591requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10592requires_gnutls
10593requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10594run_test  "DTLS-SRTP server doesn't support use_srtp extension. gnutls server" \
10595          "$G_SRV -u" \
10596          "$P_CLI dtls=1 use_srtp=1 debug_level=3" \
10597          0 \
10598          -c "client hello, adding use_srtp extension" \
10599          -C "found use_srtp extension" \
10600          -C "found srtp profile" \
10601          -C "selected srtp profile" \
10602          -C "DTLS-SRTP key material is"\
10603          -C "error"
10604
10605requires_config_enabled MBEDTLS_SSL_DTLS_SRTP
10606requires_gnutls
10607requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10608run_test  "DTLS-SRTP all profiles supported. mki used. gnutls server." \
10609          "$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" \
10610          "$P_CLI dtls=1 use_srtp=1 mki=542310ab34290481 debug_level=3" \
10611          0 \
10612          -c "client hello, adding use_srtp extension" \
10613          -c "found use_srtp extension" \
10614          -c "found srtp profile" \
10615          -c "selected srtp profile" \
10616          -c "DTLS-SRTP key material is"\
10617          -c "DTLS-SRTP mki value:"\
10618          -c "dumping 'sending mki' (8 bytes)" \
10619          -c "dumping 'received mki' (8 bytes)" \
10620          -C "error"
10621
10622# Tests for specific things with "unreliable" UDP connection
10623
10624not_with_valgrind # spurious resend due to timeout
10625requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10626run_test    "DTLS proxy: reference" \
10627            -p "$P_PXY" \
10628            "$P_SRV dtls=1 debug_level=2 hs_timeout=10000-20000" \
10629            "$P_CLI dtls=1 debug_level=2 hs_timeout=10000-20000" \
10630            0 \
10631            -C "replayed record" \
10632            -S "replayed record" \
10633            -C "Buffer record from epoch" \
10634            -S "Buffer record from epoch" \
10635            -C "ssl_buffer_message" \
10636            -S "ssl_buffer_message" \
10637            -C "discarding invalid record" \
10638            -S "discarding invalid record" \
10639            -S "resend" \
10640            -s "Extra-header:" \
10641            -c "HTTP/1.0 200 OK"
10642
10643not_with_valgrind # spurious resend due to timeout
10644requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10645run_test    "DTLS proxy: duplicate every packet" \
10646            -p "$P_PXY duplicate=1" \
10647            "$P_SRV dtls=1 dgram_packing=0 debug_level=2 hs_timeout=10000-20000" \
10648            "$P_CLI dtls=1 dgram_packing=0 debug_level=2 hs_timeout=10000-20000" \
10649            0 \
10650            -c "replayed record" \
10651            -s "replayed record" \
10652            -c "record from another epoch" \
10653            -s "record from another epoch" \
10654            -S "resend" \
10655            -s "Extra-header:" \
10656            -c "HTTP/1.0 200 OK"
10657
10658requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10659run_test    "DTLS proxy: duplicate every packet, server anti-replay off" \
10660            -p "$P_PXY duplicate=1" \
10661            "$P_SRV dtls=1 dgram_packing=0 debug_level=2 anti_replay=0" \
10662            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
10663            0 \
10664            -c "replayed record" \
10665            -S "replayed record" \
10666            -c "record from another epoch" \
10667            -s "record from another epoch" \
10668            -c "resend" \
10669            -s "resend" \
10670            -s "Extra-header:" \
10671            -c "HTTP/1.0 200 OK"
10672
10673requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10674run_test    "DTLS proxy: multiple records in same datagram" \
10675            -p "$P_PXY pack=50" \
10676            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
10677            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
10678            0 \
10679            -c "next record in same datagram" \
10680            -s "next record in same datagram"
10681
10682requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10683run_test    "DTLS proxy: multiple records in same datagram, duplicate every packet" \
10684            -p "$P_PXY pack=50 duplicate=1" \
10685            "$P_SRV dtls=1 dgram_packing=0 debug_level=2" \
10686            "$P_CLI dtls=1 dgram_packing=0 debug_level=2" \
10687            0 \
10688            -c "next record in same datagram" \
10689            -s "next record in same datagram"
10690
10691requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10692run_test    "DTLS proxy: inject invalid AD record, default badmac_limit" \
10693            -p "$P_PXY bad_ad=1" \
10694            "$P_SRV dtls=1 dgram_packing=0 debug_level=1" \
10695            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
10696            0 \
10697            -c "discarding invalid record (mac)" \
10698            -s "discarding invalid record (mac)" \
10699            -s "Extra-header:" \
10700            -c "HTTP/1.0 200 OK" \
10701            -S "too many records with bad MAC" \
10702            -S "Verification of the message MAC failed"
10703
10704requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10705run_test    "DTLS proxy: inject invalid AD record, badmac_limit 1" \
10706            -p "$P_PXY bad_ad=1" \
10707            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=1" \
10708            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
10709            1 \
10710            -C "discarding invalid record (mac)" \
10711            -S "discarding invalid record (mac)" \
10712            -S "Extra-header:" \
10713            -C "HTTP/1.0 200 OK" \
10714            -s "too many records with bad MAC" \
10715            -s "Verification of the message MAC failed"
10716
10717requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10718run_test    "DTLS proxy: inject invalid AD record, badmac_limit 2" \
10719            -p "$P_PXY bad_ad=1" \
10720            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=2" \
10721            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100" \
10722            0 \
10723            -c "discarding invalid record (mac)" \
10724            -s "discarding invalid record (mac)" \
10725            -s "Extra-header:" \
10726            -c "HTTP/1.0 200 OK" \
10727            -S "too many records with bad MAC" \
10728            -S "Verification of the message MAC failed"
10729
10730requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10731run_test    "DTLS proxy: inject invalid AD record, badmac_limit 2, exchanges 2"\
10732            -p "$P_PXY bad_ad=1" \
10733            "$P_SRV dtls=1 dgram_packing=0 debug_level=1 badmac_limit=2 exchanges=2" \
10734            "$P_CLI dtls=1 dgram_packing=0 debug_level=1 read_timeout=100 exchanges=2" \
10735            1 \
10736            -c "discarding invalid record (mac)" \
10737            -s "discarding invalid record (mac)" \
10738            -s "Extra-header:" \
10739            -c "HTTP/1.0 200 OK" \
10740            -s "too many records with bad MAC" \
10741            -s "Verification of the message MAC failed"
10742
10743requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10744run_test    "DTLS proxy: delay ChangeCipherSpec" \
10745            -p "$P_PXY delay_ccs=1" \
10746            "$P_SRV dtls=1 debug_level=1 dgram_packing=0" \
10747            "$P_CLI dtls=1 debug_level=1 dgram_packing=0" \
10748            0 \
10749            -c "record from another epoch" \
10750            -s "record from another epoch" \
10751            -s "Extra-header:" \
10752            -c "HTTP/1.0 200 OK"
10753
10754# Tests for reordering support with DTLS
10755
10756requires_certificate_authentication
10757requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10758run_test    "DTLS reordering: Buffer out-of-order handshake message on client" \
10759            -p "$P_PXY delay_srv=ServerHello" \
10760            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
10761            hs_timeout=2500-60000" \
10762            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10763            hs_timeout=2500-60000" \
10764            0 \
10765            -c "Buffering HS message" \
10766            -c "Next handshake message has been buffered - load"\
10767            -S "Buffering HS message" \
10768            -S "Next handshake message has been buffered - load"\
10769            -C "Injecting buffered CCS message" \
10770            -C "Remember CCS message" \
10771            -S "Injecting buffered CCS message" \
10772            -S "Remember CCS message"
10773
10774requires_certificate_authentication
10775requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10776run_test    "DTLS reordering: Buffer out-of-order handshake message fragment on client" \
10777            -p "$P_PXY delay_srv=ServerHello" \
10778            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
10779            hs_timeout=2500-60000" \
10780            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10781            hs_timeout=2500-60000" \
10782            0 \
10783            -c "Buffering HS message" \
10784            -c "found fragmented DTLS handshake message"\
10785            -c "Next handshake message 1 not or only partially bufffered" \
10786            -c "Next handshake message has been buffered - load"\
10787            -S "Buffering HS message" \
10788            -S "Next handshake message has been buffered - load"\
10789            -C "Injecting buffered CCS message" \
10790            -C "Remember CCS message" \
10791            -S "Injecting buffered CCS message" \
10792            -S "Remember CCS message"
10793
10794# The client buffers the ServerKeyExchange before receiving the fragmented
10795# Certificate message; at the time of writing, together these are aroudn 1200b
10796# in size, so that the bound below ensures that the certificate can be reassembled
10797# while keeping the ServerKeyExchange.
10798requires_certificate_authentication
10799requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 1300
10800requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10801run_test    "DTLS reordering: Buffer out-of-order hs msg before reassembling next" \
10802            -p "$P_PXY delay_srv=Certificate delay_srv=Certificate" \
10803            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
10804            hs_timeout=2500-60000" \
10805            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10806            hs_timeout=2500-60000" \
10807            0 \
10808            -c "Buffering HS message" \
10809            -c "Next handshake message has been buffered - load"\
10810            -C "attempt to make space by freeing buffered messages" \
10811            -S "Buffering HS message" \
10812            -S "Next handshake message has been buffered - load"\
10813            -C "Injecting buffered CCS message" \
10814            -C "Remember CCS message" \
10815            -S "Injecting buffered CCS message" \
10816            -S "Remember CCS message"
10817
10818# The size constraints ensure that the delayed certificate message can't
10819# be reassembled while keeping the ServerKeyExchange message, but it can
10820# when dropping it first.
10821requires_certificate_authentication
10822requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 900
10823requires_config_value_at_most "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 1299
10824requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10825run_test    "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg" \
10826            -p "$P_PXY delay_srv=Certificate delay_srv=Certificate" \
10827            "$P_SRV mtu=512 dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
10828            hs_timeout=2500-60000" \
10829            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10830            hs_timeout=2500-60000" \
10831            0 \
10832            -c "Buffering HS message" \
10833            -c "attempt to make space by freeing buffered future messages" \
10834            -c "Enough space available after freeing buffered HS messages" \
10835            -S "Buffering HS message" \
10836            -S "Next handshake message has been buffered - load"\
10837            -C "Injecting buffered CCS message" \
10838            -C "Remember CCS message" \
10839            -S "Injecting buffered CCS message" \
10840            -S "Remember CCS message"
10841
10842requires_certificate_authentication
10843requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10844run_test    "DTLS reordering: Buffer out-of-order handshake message on server" \
10845            -p "$P_PXY delay_cli=Certificate" \
10846            "$P_SRV dgram_packing=0 auth_mode=required cookies=0 dtls=1 debug_level=2 \
10847            hs_timeout=2500-60000" \
10848            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10849            hs_timeout=2500-60000" \
10850            0 \
10851            -C "Buffering HS message" \
10852            -C "Next handshake message has been buffered - load"\
10853            -s "Buffering HS message" \
10854            -s "Next handshake message has been buffered - load" \
10855            -C "Injecting buffered CCS message" \
10856            -C "Remember CCS message" \
10857            -S "Injecting buffered CCS message" \
10858            -S "Remember CCS message"
10859
10860requires_certificate_authentication
10861requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10862run_test    "DTLS reordering: Buffer out-of-order CCS message on client"\
10863            -p "$P_PXY delay_srv=NewSessionTicket" \
10864            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
10865            hs_timeout=2500-60000" \
10866            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10867            hs_timeout=2500-60000" \
10868            0 \
10869            -C "Buffering HS message" \
10870            -C "Next handshake message has been buffered - load"\
10871            -S "Buffering HS message" \
10872            -S "Next handshake message has been buffered - load" \
10873            -c "Injecting buffered CCS message" \
10874            -c "Remember CCS message" \
10875            -S "Injecting buffered CCS message" \
10876            -S "Remember CCS message"
10877
10878requires_certificate_authentication
10879requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10880run_test    "DTLS reordering: Buffer out-of-order CCS message on server"\
10881            -p "$P_PXY delay_cli=ClientKeyExchange" \
10882            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
10883            hs_timeout=2500-60000" \
10884            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10885            hs_timeout=2500-60000" \
10886            0 \
10887            -C "Buffering HS message" \
10888            -C "Next handshake message has been buffered - load"\
10889            -S "Buffering HS message" \
10890            -S "Next handshake message has been buffered - load" \
10891            -C "Injecting buffered CCS message" \
10892            -C "Remember CCS message" \
10893            -s "Injecting buffered CCS message" \
10894            -s "Remember CCS message"
10895
10896requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10897run_test    "DTLS reordering: Buffer encrypted Finished message" \
10898            -p "$P_PXY delay_ccs=1" \
10899            "$P_SRV dgram_packing=0 cookies=0 dtls=1 debug_level=2 \
10900            hs_timeout=2500-60000" \
10901            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 \
10902            hs_timeout=2500-60000" \
10903            0 \
10904            -s "Buffer record from epoch 1" \
10905            -s "Found buffered record from current epoch - load" \
10906            -c "Buffer record from epoch 1" \
10907            -c "Found buffered record from current epoch - load"
10908
10909# In this test, both the fragmented NewSessionTicket and the ChangeCipherSpec
10910# from the server are delayed, so that the encrypted Finished message
10911# is received and buffered. When the fragmented NewSessionTicket comes
10912# in afterwards, the encrypted Finished message must be freed in order
10913# to make space for the NewSessionTicket to be reassembled.
10914# This works only in very particular circumstances:
10915# - MBEDTLS_SSL_DTLS_MAX_BUFFERING must be large enough to allow buffering
10916#   of the NewSessionTicket, but small enough to also allow buffering of
10917#   the encrypted Finished message.
10918# - The MTU setting on the server must be so small that the NewSessionTicket
10919#   needs to be fragmented.
10920# - All messages sent by the server must be small enough to be either sent
10921#   without fragmentation or be reassembled within the bounds of
10922#   MBEDTLS_SSL_DTLS_MAX_BUFFERING. Achieve this by testing with a PSK-based
10923#   handshake, omitting CRTs.
10924requires_config_value_at_least "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 190
10925requires_config_value_at_most "MBEDTLS_SSL_DTLS_MAX_BUFFERING" 230
10926requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10927run_test    "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket" \
10928            -p "$P_PXY delay_srv=NewSessionTicket delay_srv=NewSessionTicket delay_ccs=1" \
10929            "$P_SRV mtu=140 response_size=90 dgram_packing=0 psk=abc123 psk_identity=foo cookies=0 dtls=1 debug_level=2" \
10930            "$P_CLI dgram_packing=0 dtls=1 debug_level=2 force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 psk=abc123 psk_identity=foo" \
10931            0 \
10932            -s "Buffer record from epoch 1" \
10933            -s "Found buffered record from current epoch - load" \
10934            -c "Buffer record from epoch 1" \
10935            -C "Found buffered record from current epoch - load" \
10936            -c "Enough space available after freeing future epoch record"
10937
10938# Tests for "randomly unreliable connection": try a variety of flows and peers
10939
10940client_needs_more_time 2
10941requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10942run_test    "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
10943            -p "$P_PXY drop=5 delay=5 duplicate=5" \
10944            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
10945             psk=abc123" \
10946            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
10947             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
10948            0 \
10949            -s "Extra-header:" \
10950            -c "HTTP/1.0 200 OK"
10951
10952client_needs_more_time 2
10953requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10954run_test    "DTLS proxy: 3d, \"short\" RSA handshake" \
10955            -p "$P_PXY drop=5 delay=5 duplicate=5" \
10956            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none" \
10957            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 \
10958             force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
10959            0 \
10960            -s "Extra-header:" \
10961            -c "HTTP/1.0 200 OK"
10962
10963client_needs_more_time 2
10964requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10965run_test    "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
10966            -p "$P_PXY drop=5 delay=5 duplicate=5" \
10967            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none" \
10968            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0" \
10969            0 \
10970            -s "Extra-header:" \
10971            -c "HTTP/1.0 200 OK"
10972
10973client_needs_more_time 2
10974requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10975run_test    "DTLS proxy: 3d, FS, client auth" \
10976            -p "$P_PXY drop=5 delay=5 duplicate=5" \
10977            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=required" \
10978            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0" \
10979            0 \
10980            -s "Extra-header:" \
10981            -c "HTTP/1.0 200 OK"
10982
10983client_needs_more_time 2
10984requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10985run_test    "DTLS proxy: 3d, FS, ticket" \
10986            -p "$P_PXY drop=5 delay=5 duplicate=5" \
10987            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1 auth_mode=none" \
10988            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1" \
10989            0 \
10990            -s "Extra-header:" \
10991            -c "HTTP/1.0 200 OK"
10992
10993client_needs_more_time 2
10994requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
10995run_test    "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
10996            -p "$P_PXY drop=5 delay=5 duplicate=5" \
10997            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1 auth_mode=required" \
10998            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=1" \
10999            0 \
11000            -s "Extra-header:" \
11001            -c "HTTP/1.0 200 OK"
11002
11003client_needs_more_time 2
11004requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11005run_test    "DTLS proxy: 3d, max handshake, nbio" \
11006            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11007            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 nbio=2 tickets=1 \
11008             auth_mode=required" \
11009            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 nbio=2 tickets=1" \
11010            0 \
11011            -s "Extra-header:" \
11012            -c "HTTP/1.0 200 OK"
11013
11014client_needs_more_time 4
11015requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11016requires_config_enabled MBEDTLS_SSL_CACHE_C
11017run_test    "DTLS proxy: 3d, min handshake, resumption" \
11018            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11019            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11020             psk=abc123 debug_level=3" \
11021            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11022             debug_level=3 reconnect=1 skip_close_notify=1 read_timeout=1000 max_resend=10 \
11023             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11024            0 \
11025            -s "a session has been resumed" \
11026            -c "a session has been resumed" \
11027            -s "Extra-header:" \
11028            -c "HTTP/1.0 200 OK"
11029
11030client_needs_more_time 4
11031requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11032requires_config_enabled MBEDTLS_SSL_CACHE_C
11033run_test    "DTLS proxy: 3d, min handshake, resumption, nbio" \
11034            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11035            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11036             psk=abc123 debug_level=3 nbio=2" \
11037            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11038             debug_level=3 reconnect=1 skip_close_notify=1 read_timeout=1000 max_resend=10 \
11039             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
11040            0 \
11041            -s "a session has been resumed" \
11042            -c "a session has been resumed" \
11043            -s "Extra-header:" \
11044            -c "HTTP/1.0 200 OK"
11045
11046client_needs_more_time 4
11047requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11048requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11049run_test    "DTLS proxy: 3d, min handshake, client-initiated renego" \
11050            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11051            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11052             psk=abc123 renegotiation=1 debug_level=2" \
11053            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11054             renegotiate=1 debug_level=2 \
11055             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11056            0 \
11057            -c "=> renegotiate" \
11058            -s "=> renegotiate" \
11059            -s "Extra-header:" \
11060            -c "HTTP/1.0 200 OK"
11061
11062client_needs_more_time 4
11063requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11064requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11065run_test    "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
11066            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11067            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11068             psk=abc123 renegotiation=1 debug_level=2" \
11069            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11070             renegotiate=1 debug_level=2 \
11071             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11072            0 \
11073            -c "=> renegotiate" \
11074            -s "=> renegotiate" \
11075            -s "Extra-header:" \
11076            -c "HTTP/1.0 200 OK"
11077
11078client_needs_more_time 4
11079requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11080requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11081run_test    "DTLS proxy: 3d, min handshake, server-initiated renego" \
11082            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11083            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11084             psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
11085             debug_level=2" \
11086            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11087             renegotiation=1 exchanges=4 debug_level=2 \
11088             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11089            0 \
11090            -c "=> renegotiate" \
11091            -s "=> renegotiate" \
11092            -s "Extra-header:" \
11093            -c "HTTP/1.0 200 OK"
11094
11095client_needs_more_time 4
11096requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
11097requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11098run_test    "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
11099            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11100            "$P_SRV dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 auth_mode=none \
11101             psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
11102             debug_level=2 nbio=2" \
11103            "$P_CLI dtls=1 dgram_packing=0 hs_timeout=500-10000 tickets=0 psk=abc123 \
11104             renegotiation=1 exchanges=4 debug_level=2 nbio=2 \
11105             force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
11106            0 \
11107            -c "=> renegotiate" \
11108            -s "=> renegotiate" \
11109            -s "Extra-header:" \
11110            -c "HTTP/1.0 200 OK"
11111
11112## The three tests below require 1.1.1a or higher version of openssl, otherwise
11113## it might trigger a bug due to openssl (https://github.com/openssl/openssl/issues/6902)
11114## Besides, openssl should use dtls1_2 or dtls, otherwise it will cause "SSL alert number 70" error
11115requires_openssl_next
11116client_needs_more_time 6
11117not_with_valgrind # risk of non-mbedtls peer timing out
11118requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11119run_test    "DTLS proxy: 3d, openssl server" \
11120            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
11121            "$O_NEXT_SRV -dtls1_2 -mtu 2048" \
11122            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 tickets=0" \
11123            0 \
11124            -c "HTTP/1.0 200 OK"
11125
11126requires_openssl_next
11127client_needs_more_time 8
11128not_with_valgrind # risk of non-mbedtls peer timing out
11129requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11130run_test    "DTLS proxy: 3d, openssl server, fragmentation" \
11131            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
11132            "$O_NEXT_SRV -dtls1_2 -mtu 768" \
11133            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 tickets=0" \
11134            0 \
11135            -c "HTTP/1.0 200 OK"
11136
11137requires_openssl_next
11138client_needs_more_time 8
11139not_with_valgrind # risk of non-mbedtls peer timing out
11140requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11141run_test    "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
11142            -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
11143            "$O_NEXT_SRV -dtls1_2 -mtu 768" \
11144            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 nbio=2 tickets=0" \
11145            0 \
11146            -c "HTTP/1.0 200 OK"
11147
11148requires_gnutls
11149client_needs_more_time 6
11150not_with_valgrind # risk of non-mbedtls peer timing out
11151requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11152run_test    "DTLS proxy: 3d, gnutls server" \
11153            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11154            "$G_SRV -u --mtu 2048 -a" \
11155            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000" \
11156            0 \
11157            -s "Extra-header:" \
11158            -c "Extra-header:"
11159
11160requires_gnutls_next
11161client_needs_more_time 8
11162not_with_valgrind # risk of non-mbedtls peer timing out
11163requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11164run_test    "DTLS proxy: 3d, gnutls server, fragmentation" \
11165            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11166            "$G_NEXT_SRV -u --mtu 512" \
11167            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000" \
11168            0 \
11169            -s "Extra-header:" \
11170            -c "Extra-header:"
11171
11172requires_gnutls_next
11173client_needs_more_time 8
11174not_with_valgrind # risk of non-mbedtls peer timing out
11175requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11176run_test    "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
11177            -p "$P_PXY drop=5 delay=5 duplicate=5" \
11178            "$G_NEXT_SRV -u --mtu 512" \
11179            "$P_CLI dgram_packing=0 dtls=1 hs_timeout=500-60000 nbio=2" \
11180            0 \
11181            -s "Extra-header:" \
11182            -c "Extra-header:"
11183
11184requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
11185run_test    "export keys functionality" \
11186            "$P_SRV eap_tls=1 debug_level=3" \
11187            "$P_CLI eap_tls=1 debug_level=3" \
11188            0 \
11189            -c "EAP-TLS key material is:"\
11190            -s "EAP-TLS key material is:"\
11191            -c "EAP-TLS IV is:" \
11192            -s "EAP-TLS IV is:"
11193
11194# openssl feature tests: check if tls1.3 exists.
11195requires_openssl_tls1_3
11196run_test    "TLS 1.3: Test openssl tls1_3 feature" \
11197            "$O_NEXT_SRV -tls1_3 -msg" \
11198            "$O_NEXT_CLI -tls1_3 -msg" \
11199            0 \
11200            -c "TLS 1.3" \
11201            -s "TLS 1.3"
11202
11203# gnutls feature tests: check if TLS 1.3 is supported as well as the NO_TICKETS and DISABLE_TLS13_COMPAT_MODE options.
11204requires_gnutls_tls1_3
11205requires_gnutls_next_no_ticket
11206requires_gnutls_next_disable_tls13_compat
11207run_test    "TLS 1.3: Test gnutls tls1_3 feature" \
11208            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert " \
11209            "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
11210            0 \
11211            -s "Version: TLS1.3" \
11212            -c "Version: TLS1.3"
11213
11214# TLS1.3 test cases
11215requires_openssl_tls1_3
11216requires_config_enabled MBEDTLS_DEBUG_C
11217requires_config_enabled MBEDTLS_SSL_CLI_C
11218requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11219                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11220run_test    "TLS 1.3: minimal feature sets - openssl" \
11221            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
11222            "$P_CLI debug_level=3" \
11223            0 \
11224            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11225            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11226            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11227            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11228            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11229            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11230            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11231            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11232            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11233            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11234            -c "<= ssl_tls13_process_server_hello" \
11235            -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
11236            -c "ECDH curve: x25519" \
11237            -c "=> ssl_tls13_process_server_hello" \
11238            -c "<= parse encrypted extensions" \
11239            -c "Certificate verification flags clear" \
11240            -c "=> parse certificate verify" \
11241            -c "<= parse certificate verify" \
11242            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11243            -c "<= parse finished message" \
11244            -c "Protocol is TLSv1.3" \
11245            -c "HTTP/1.0 200 ok"
11246
11247requires_gnutls_tls1_3
11248requires_gnutls_next_no_ticket
11249requires_config_enabled MBEDTLS_DEBUG_C
11250requires_config_enabled MBEDTLS_SSL_CLI_C
11251requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11252                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11253run_test    "TLS 1.3: minimal feature sets - gnutls" \
11254            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
11255            "$P_CLI debug_level=3" \
11256            0 \
11257            -s "SERVER HELLO was queued" \
11258            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11259            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11260            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11261            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11262            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11263            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11264            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11265            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11266            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11267            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11268            -c "<= ssl_tls13_process_server_hello" \
11269            -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
11270            -c "ECDH curve: x25519" \
11271            -c "=> ssl_tls13_process_server_hello" \
11272            -c "<= parse encrypted extensions" \
11273            -c "Certificate verification flags clear" \
11274            -c "=> parse certificate verify" \
11275            -c "<= parse certificate verify" \
11276            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11277            -c "<= parse finished message" \
11278            -c "Protocol is TLSv1.3" \
11279            -c "HTTP/1.0 200 OK"
11280
11281requires_openssl_tls1_3
11282requires_config_enabled MBEDTLS_DEBUG_C
11283requires_config_enabled MBEDTLS_SSL_CLI_C
11284requires_config_enabled MBEDTLS_SSL_ALPN
11285requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11286                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11287run_test    "TLS 1.3: alpn - openssl" \
11288            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -alpn h2" \
11289            "$P_CLI debug_level=3 alpn=h2" \
11290            0 \
11291            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11292            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11293            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11294            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11295            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11296            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11297            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11298            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11299            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11300            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11301            -c "<= ssl_tls13_process_server_hello" \
11302            -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
11303            -c "ECDH curve: x25519" \
11304            -c "=> ssl_tls13_process_server_hello" \
11305            -c "<= parse encrypted extensions" \
11306            -c "Certificate verification flags clear" \
11307            -c "=> parse certificate verify" \
11308            -c "<= parse certificate verify" \
11309            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11310            -c "<= parse finished message" \
11311            -c "Protocol is TLSv1.3" \
11312            -c "HTTP/1.0 200 ok" \
11313            -c "Application Layer Protocol is h2"
11314
11315requires_gnutls_tls1_3
11316requires_gnutls_next_no_ticket
11317requires_config_enabled MBEDTLS_DEBUG_C
11318requires_config_enabled MBEDTLS_SSL_CLI_C
11319requires_config_enabled MBEDTLS_SSL_ALPN
11320requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11321                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11322run_test    "TLS 1.3: alpn - gnutls" \
11323            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert --alpn=h2" \
11324            "$P_CLI debug_level=3 alpn=h2" \
11325            0 \
11326            -s "SERVER HELLO was queued" \
11327            -c "client state: MBEDTLS_SSL_HELLO_REQUEST" \
11328            -c "client state: MBEDTLS_SSL_SERVER_HELLO" \
11329            -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
11330            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
11331            -c "client state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
11332            -c "client state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
11333            -c "client state: MBEDTLS_SSL_SERVER_FINISHED" \
11334            -c "client state: MBEDTLS_SSL_CLIENT_FINISHED" \
11335            -c "client state: MBEDTLS_SSL_FLUSH_BUFFERS" \
11336            -c "client state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
11337            -c "<= ssl_tls13_process_server_hello" \
11338            -c "server hello, chosen ciphersuite: ( 1301 ) - TLS1-3-AES-128-GCM-SHA256" \
11339            -c "ECDH curve: x25519" \
11340            -c "=> ssl_tls13_process_server_hello" \
11341            -c "<= parse encrypted extensions" \
11342            -c "Certificate verification flags clear" \
11343            -c "=> parse certificate verify" \
11344            -c "<= parse certificate verify" \
11345            -c "mbedtls_ssl_tls13_process_certificate_verify() returned 0" \
11346            -c "<= parse finished message" \
11347            -c "Protocol is TLSv1.3" \
11348            -c "HTTP/1.0 200 OK" \
11349            -c "Application Layer Protocol is h2"
11350
11351requires_openssl_tls1_3
11352requires_config_enabled MBEDTLS_DEBUG_C
11353requires_config_enabled MBEDTLS_SSL_SRV_C
11354requires_config_enabled MBEDTLS_SSL_ALPN
11355requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11356run_test    "TLS 1.3: server alpn - openssl" \
11357            "$P_SRV debug_level=3 tickets=0 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 alpn=h2" \
11358            "$O_NEXT_CLI -msg -tls1_3 -no_middlebox -alpn h2" \
11359            0 \
11360            -s "found alpn extension" \
11361            -s "server side, adding alpn extension" \
11362            -s "Protocol is TLSv1.3" \
11363            -s "HTTP/1.0 200 OK" \
11364            -s "Application Layer Protocol is h2"
11365
11366requires_gnutls_tls1_3
11367requires_config_enabled MBEDTLS_DEBUG_C
11368requires_config_enabled MBEDTLS_SSL_SRV_C
11369requires_config_enabled MBEDTLS_SSL_ALPN
11370requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11371run_test    "TLS 1.3: server alpn - gnutls" \
11372            "$P_SRV debug_level=3 tickets=0 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 alpn=h2" \
11373            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V --alpn h2" \
11374            0 \
11375            -s "found alpn extension" \
11376            -s "server side, adding alpn extension" \
11377            -s "Protocol is TLSv1.3" \
11378            -s "HTTP/1.0 200 OK" \
11379            -s "Application Layer Protocol is h2"
11380
11381requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11382requires_config_enabled MBEDTLS_DEBUG_C
11383requires_config_enabled MBEDTLS_SSL_CLI_C
11384skip_handshake_stage_check
11385requires_gnutls_tls1_3
11386run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.0" \
11387            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0 -d 4" \
11388            "$P_CLI debug_level=4" \
11389            1 \
11390            -s "Client's version: 3.3" \
11391            -S "Version: TLS1.0" \
11392            -C "Protocol is TLSv1.0"
11393
11394requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11395requires_config_enabled MBEDTLS_DEBUG_C
11396requires_config_enabled MBEDTLS_SSL_CLI_C
11397skip_handshake_stage_check
11398requires_gnutls_tls1_3
11399run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.1" \
11400            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.1 -d 4" \
11401            "$P_CLI debug_level=4" \
11402            1 \
11403            -s "Client's version: 3.3" \
11404            -S "Version: TLS1.1" \
11405            -C "Protocol is TLSv1.1"
11406
11407requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11408requires_config_enabled MBEDTLS_DEBUG_C
11409requires_config_enabled MBEDTLS_SSL_CLI_C
11410skip_handshake_stage_check
11411requires_gnutls_tls1_3
11412run_test    "TLS 1.3: Not supported version check:gnutls: srv max TLS 1.2" \
11413            "$G_NEXT_SRV --priority=NORMAL:-VERS-TLS-ALL:+VERS-TLS1.2 -d 4" \
11414            "$P_CLI force_version=tls13 debug_level=4" \
11415            1 \
11416            -s "Client's version: 3.3" \
11417            -c "is a fatal alert message (msg 40)" \
11418            -S "Version: TLS1.2" \
11419            -C "Protocol is TLSv1.2"
11420
11421requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11422requires_config_enabled MBEDTLS_DEBUG_C
11423requires_config_enabled MBEDTLS_SSL_CLI_C
11424skip_handshake_stage_check
11425requires_openssl_next
11426run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.0" \
11427            "$O_NEXT_SRV -msg -tls1" \
11428            "$P_CLI debug_level=4" \
11429            1 \
11430            -s "fatal protocol_version" \
11431            -c "is a fatal alert message (msg 70)" \
11432            -S "Version: TLS1.0" \
11433            -C "Protocol  : TLSv1.0"
11434
11435requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11436requires_config_enabled MBEDTLS_DEBUG_C
11437requires_config_enabled MBEDTLS_SSL_CLI_C
11438skip_handshake_stage_check
11439requires_openssl_next
11440run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.1" \
11441            "$O_NEXT_SRV -msg -tls1_1" \
11442            "$P_CLI debug_level=4" \
11443            1 \
11444            -s "fatal protocol_version" \
11445            -c "is a fatal alert message (msg 70)" \
11446            -S "Version: TLS1.1" \
11447            -C "Protocol  : TLSv1.1"
11448
11449requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
11450requires_config_enabled MBEDTLS_DEBUG_C
11451requires_config_enabled MBEDTLS_SSL_CLI_C
11452skip_handshake_stage_check
11453requires_openssl_next
11454run_test    "TLS 1.3: Not supported version check:openssl: srv max TLS 1.2" \
11455            "$O_NEXT_SRV -msg -tls1_2" \
11456            "$P_CLI force_version=tls13 debug_level=4" \
11457            1 \
11458            -s "fatal protocol_version" \
11459            -c "is a fatal alert message (msg 70)" \
11460            -S "Version: TLS1.2" \
11461            -C "Protocol  : TLSv1.2"
11462
11463requires_openssl_tls1_3
11464requires_config_enabled MBEDTLS_DEBUG_C
11465requires_config_enabled MBEDTLS_SSL_CLI_C
11466requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11467                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11468run_test    "TLS 1.3: Client authentication, no client certificate - openssl" \
11469            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -verify 10" \
11470            "$P_CLI debug_level=4 crt_file=none key_file=none" \
11471            0 \
11472            -c "got a certificate request" \
11473            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11474            -s "TLS 1.3" \
11475            -c "HTTP/1.0 200 ok" \
11476            -c "Protocol is TLSv1.3"
11477
11478requires_gnutls_tls1_3
11479requires_gnutls_next_no_ticket
11480requires_config_enabled MBEDTLS_DEBUG_C
11481requires_config_enabled MBEDTLS_SSL_CLI_C
11482requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11483                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11484run_test    "TLS 1.3: Client authentication, no client certificate - gnutls" \
11485            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --verify-client-cert" \
11486            "$P_CLI debug_level=3 crt_file=none key_file=none" \
11487            0 \
11488            -c "got a certificate request" \
11489            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE"\
11490            -s "Version: TLS1.3" \
11491            -c "HTTP/1.0 200 OK" \
11492            -c "Protocol is TLSv1.3"
11493
11494
11495requires_openssl_tls1_3
11496requires_config_enabled MBEDTLS_DEBUG_C
11497requires_config_enabled MBEDTLS_SSL_CLI_C
11498requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11499run_test    "TLS 1.3: Client authentication, no server middlebox compat - openssl" \
11500            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10 -no_middlebox" \
11501            "$P_CLI debug_level=4 crt_file=data_files/cli2.crt key_file=data_files/cli2.key" \
11502            0 \
11503            -c "got a certificate request" \
11504            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11505            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11506            -c "Protocol is TLSv1.3"
11507
11508requires_gnutls_tls1_3
11509requires_gnutls_next_no_ticket
11510requires_config_enabled MBEDTLS_DEBUG_C
11511requires_config_enabled MBEDTLS_SSL_CLI_C
11512requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11513run_test    "TLS 1.3: Client authentication, no server middlebox compat - gnutls" \
11514            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE" \
11515            "$P_CLI debug_level=3 crt_file=data_files/cli2.crt \
11516                    key_file=data_files/cli2.key" \
11517            0 \
11518            -c "got a certificate request" \
11519            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11520            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11521            -c "Protocol is TLSv1.3"
11522
11523requires_openssl_tls1_3
11524requires_config_enabled MBEDTLS_DEBUG_C
11525requires_config_enabled MBEDTLS_SSL_CLI_C
11526requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11527                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11528run_test    "TLS 1.3: Client authentication, ecdsa_secp256r1_sha256 - openssl" \
11529            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11530            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp256r1.crt \
11531                    key_file=data_files/ecdsa_secp256r1.key" \
11532            0 \
11533            -c "got a certificate request" \
11534            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11535            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11536            -c "Protocol is TLSv1.3"
11537
11538requires_gnutls_tls1_3
11539requires_gnutls_next_no_ticket
11540requires_config_enabled MBEDTLS_DEBUG_C
11541requires_config_enabled MBEDTLS_SSL_CLI_C
11542requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11543                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11544run_test    "TLS 1.3: Client authentication, ecdsa_secp256r1_sha256 - gnutls" \
11545            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11546            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp256r1.crt \
11547                    key_file=data_files/ecdsa_secp256r1.key" \
11548            0 \
11549            -c "got a certificate request" \
11550            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11551            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11552            -c "Protocol is TLSv1.3"
11553
11554requires_openssl_tls1_3
11555requires_config_enabled MBEDTLS_DEBUG_C
11556requires_config_enabled MBEDTLS_SSL_CLI_C
11557requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11558                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11559run_test    "TLS 1.3: Client authentication, ecdsa_secp384r1_sha384 - openssl" \
11560            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11561            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp384r1.crt \
11562                    key_file=data_files/ecdsa_secp384r1.key" \
11563            0 \
11564            -c "got a certificate request" \
11565            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11566            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11567            -c "Protocol is TLSv1.3"
11568
11569requires_gnutls_tls1_3
11570requires_gnutls_next_no_ticket
11571requires_config_enabled MBEDTLS_DEBUG_C
11572requires_config_enabled MBEDTLS_SSL_CLI_C
11573requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11574                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11575run_test    "TLS 1.3: Client authentication, ecdsa_secp384r1_sha384 - gnutls" \
11576            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11577            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp384r1.crt \
11578                    key_file=data_files/ecdsa_secp384r1.key" \
11579            0 \
11580            -c "got a certificate request" \
11581            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11582            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11583            -c "Protocol is TLSv1.3"
11584
11585requires_openssl_tls1_3
11586requires_config_enabled MBEDTLS_DEBUG_C
11587requires_config_enabled MBEDTLS_SSL_CLI_C
11588requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11589                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11590run_test    "TLS 1.3: Client authentication, ecdsa_secp521r1_sha512 - openssl" \
11591            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11592            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp521r1.crt \
11593                    key_file=data_files/ecdsa_secp521r1.key" \
11594            0 \
11595            -c "got a certificate request" \
11596            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11597            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11598            -c "Protocol is TLSv1.3"
11599
11600requires_gnutls_tls1_3
11601requires_gnutls_next_no_ticket
11602requires_config_enabled MBEDTLS_DEBUG_C
11603requires_config_enabled MBEDTLS_SSL_CLI_C
11604requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11605                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11606run_test    "TLS 1.3: Client authentication, ecdsa_secp521r1_sha512 - gnutls" \
11607            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11608            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
11609                    key_file=data_files/ecdsa_secp521r1.key" \
11610            0 \
11611            -c "got a certificate request" \
11612            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11613            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11614            -c "Protocol is TLSv1.3"
11615
11616requires_openssl_tls1_3
11617requires_config_enabled MBEDTLS_DEBUG_C
11618requires_config_enabled MBEDTLS_SSL_CLI_C
11619requires_config_enabled MBEDTLS_RSA_C
11620requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11621                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11622run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha256 - openssl" \
11623            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11624            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
11625                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256" \
11626            0 \
11627            -c "got a certificate request" \
11628            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11629            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11630            -c "Protocol is TLSv1.3"
11631
11632requires_gnutls_tls1_3
11633requires_gnutls_next_no_ticket
11634requires_config_enabled MBEDTLS_DEBUG_C
11635requires_config_enabled MBEDTLS_SSL_CLI_C
11636requires_config_enabled MBEDTLS_RSA_C
11637requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11638                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11639run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha256 - gnutls" \
11640            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11641            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
11642                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256" \
11643            0 \
11644            -c "got a certificate request" \
11645            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11646            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11647            -c "Protocol is TLSv1.3"
11648
11649requires_openssl_tls1_3
11650requires_config_enabled MBEDTLS_DEBUG_C
11651requires_config_enabled MBEDTLS_SSL_CLI_C
11652requires_config_enabled MBEDTLS_RSA_C
11653requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11654                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11655run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha384 - openssl" \
11656            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11657            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
11658                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384" \
11659            0 \
11660            -c "got a certificate request" \
11661            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11662            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11663            -c "Protocol is TLSv1.3"
11664
11665requires_gnutls_tls1_3
11666requires_gnutls_next_no_ticket
11667requires_config_enabled MBEDTLS_DEBUG_C
11668requires_config_enabled MBEDTLS_SSL_CLI_C
11669requires_config_enabled MBEDTLS_RSA_C
11670requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11671                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11672run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha384 - gnutls" \
11673            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11674            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
11675                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384" \
11676            0 \
11677            -c "got a certificate request" \
11678            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11679            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11680            -c "Protocol is TLSv1.3"
11681
11682requires_openssl_tls1_3
11683requires_config_enabled MBEDTLS_DEBUG_C
11684requires_config_enabled MBEDTLS_SSL_CLI_C
11685requires_config_enabled MBEDTLS_RSA_C
11686requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11687                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11688run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha512 - openssl" \
11689            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11690            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
11691                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512" \
11692            0 \
11693            -c "got a certificate request" \
11694            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11695            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11696            -c "Protocol is TLSv1.3"
11697
11698requires_gnutls_tls1_3
11699requires_gnutls_next_no_ticket
11700requires_config_enabled MBEDTLS_DEBUG_C
11701requires_config_enabled MBEDTLS_SSL_CLI_C
11702requires_config_enabled MBEDTLS_RSA_C
11703requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11704                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11705run_test    "TLS 1.3: Client authentication, rsa_pss_rsae_sha512 - gnutls" \
11706            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11707            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
11708                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512" \
11709            0 \
11710            -c "got a certificate request" \
11711            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11712            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11713            -c "Protocol is TLSv1.3"
11714
11715requires_openssl_tls1_3
11716requires_config_enabled MBEDTLS_DEBUG_C
11717requires_config_enabled MBEDTLS_SSL_CLI_C
11718requires_config_enabled MBEDTLS_RSA_C
11719requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11720                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11721run_test    "TLS 1.3: Client authentication, client alg not in server list - openssl" \
11722            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10
11723                -sigalgs ecdsa_secp256r1_sha256" \
11724            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
11725                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512" \
11726            1 \
11727            -c "got a certificate request" \
11728            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11729            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11730            -c "no suitable signature algorithm" \
11731            -C "unknown pk type"
11732
11733requires_gnutls_tls1_3
11734requires_gnutls_next_no_ticket
11735requires_config_enabled MBEDTLS_DEBUG_C
11736requires_config_enabled MBEDTLS_SSL_CLI_C
11737requires_config_enabled MBEDTLS_RSA_C
11738requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11739                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11740run_test    "TLS 1.3: Client authentication, client alg not in server list - gnutls" \
11741            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:-SIGN-ALL:+SIGN-ECDSA-SECP256R1-SHA256:%NO_TICKETS" \
11742            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
11743                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512" \
11744            1 \
11745            -c "got a certificate request" \
11746            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11747            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11748            -c "no suitable signature algorithm" \
11749            -C "unknown pk type"
11750
11751# Test using an opaque private key for client authentication
11752requires_openssl_tls1_3
11753requires_config_enabled MBEDTLS_DEBUG_C
11754requires_config_enabled MBEDTLS_SSL_CLI_C
11755requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11756requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11757run_test    "TLS 1.3: Client authentication - opaque key, no server middlebox compat - openssl" \
11758            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10 -no_middlebox" \
11759            "$P_CLI debug_level=4 crt_file=data_files/cli2.crt key_file=data_files/cli2.key key_opaque=1" \
11760            0 \
11761            -c "got a certificate request" \
11762            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11763            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11764            -c "Protocol is TLSv1.3"
11765
11766requires_gnutls_tls1_3
11767requires_gnutls_next_no_ticket
11768requires_config_enabled MBEDTLS_DEBUG_C
11769requires_config_enabled MBEDTLS_SSL_CLI_C
11770requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11771requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11772run_test    "TLS 1.3: Client authentication - opaque key, no server middlebox compat - gnutls" \
11773            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE" \
11774            "$P_CLI debug_level=3 crt_file=data_files/cli2.crt \
11775                    key_file=data_files/cli2.key key_opaque=1" \
11776            0 \
11777            -c "got a certificate request" \
11778            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11779            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11780            -c "Protocol is TLSv1.3"
11781
11782requires_openssl_tls1_3
11783requires_config_enabled MBEDTLS_DEBUG_C
11784requires_config_enabled MBEDTLS_SSL_CLI_C
11785requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11786requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11787                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11788run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp256r1_sha256 - openssl" \
11789            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11790            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp256r1.crt \
11791                    key_file=data_files/ecdsa_secp256r1.key key_opaque=1" \
11792            0 \
11793            -c "got a certificate request" \
11794            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11795            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11796            -c "Protocol is TLSv1.3"
11797
11798requires_gnutls_tls1_3
11799requires_gnutls_next_no_ticket
11800requires_config_enabled MBEDTLS_DEBUG_C
11801requires_config_enabled MBEDTLS_SSL_CLI_C
11802requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11803requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11804                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11805run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp256r1_sha256 - gnutls" \
11806            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11807            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp256r1.crt \
11808                    key_file=data_files/ecdsa_secp256r1.key key_opaque=1" \
11809            0 \
11810            -c "got a certificate request" \
11811            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11812            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11813            -c "Protocol is TLSv1.3"
11814
11815requires_openssl_tls1_3
11816requires_config_enabled MBEDTLS_DEBUG_C
11817requires_config_enabled MBEDTLS_SSL_CLI_C
11818requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11819requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11820                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11821run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp384r1_sha384 - openssl" \
11822            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11823            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp384r1.crt \
11824                    key_file=data_files/ecdsa_secp384r1.key key_opaque=1" \
11825            0 \
11826            -c "got a certificate request" \
11827            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11828            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11829            -c "Protocol is TLSv1.3"
11830
11831requires_gnutls_tls1_3
11832requires_gnutls_next_no_ticket
11833requires_config_enabled MBEDTLS_DEBUG_C
11834requires_config_enabled MBEDTLS_SSL_CLI_C
11835requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
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 - opaque key, ecdsa_secp384r1_sha384 - gnutls" \
11839            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11840            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp384r1.crt \
11841                    key_file=data_files/ecdsa_secp384r1.key key_opaque=1" \
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_openssl_tls1_3
11849requires_config_enabled MBEDTLS_DEBUG_C
11850requires_config_enabled MBEDTLS_SSL_CLI_C
11851requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
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 - opaque key, ecdsa_secp521r1_sha512 - openssl" \
11855            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11856            "$P_CLI debug_level=4 crt_file=data_files/ecdsa_secp521r1.crt \
11857                    key_file=data_files/ecdsa_secp521r1.key key_opaque=1" \
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_gnutls_tls1_3
11865requires_gnutls_next_no_ticket
11866requires_config_enabled MBEDTLS_DEBUG_C
11867requires_config_enabled MBEDTLS_SSL_CLI_C
11868requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11869requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11870                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11871run_test    "TLS 1.3: Client authentication - opaque key, ecdsa_secp521r1_sha512 - gnutls" \
11872            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11873            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
11874                    key_file=data_files/ecdsa_secp521r1.key key_opaque=1" \
11875            0 \
11876            -c "got a certificate request" \
11877            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11878            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11879            -c "Protocol is TLSv1.3"
11880
11881requires_openssl_tls1_3
11882requires_config_enabled MBEDTLS_DEBUG_C
11883requires_config_enabled MBEDTLS_SSL_CLI_C
11884requires_config_enabled MBEDTLS_RSA_C
11885requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11886requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11887                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11888run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha256 - openssl" \
11889            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11890            "$P_CLI debug_level=4 crt_file=data_files/cert_sha256.crt \
11891                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256 key_opaque=1" \
11892            0 \
11893            -c "got a certificate request" \
11894            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11895            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11896            -c "Protocol is TLSv1.3"
11897
11898requires_gnutls_tls1_3
11899requires_gnutls_next_no_ticket
11900requires_config_enabled MBEDTLS_DEBUG_C
11901requires_config_enabled MBEDTLS_SSL_CLI_C
11902requires_config_enabled MBEDTLS_RSA_C
11903requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11904requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11905                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11906run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha256 - gnutls" \
11907            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11908            "$P_CLI debug_level=3 crt_file=data_files/server2-sha256.crt \
11909                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha256 key_opaque=1" \
11910            0 \
11911            -c "got a certificate request" \
11912            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11913            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11914            -c "Protocol is TLSv1.3"
11915
11916requires_openssl_tls1_3
11917requires_config_enabled MBEDTLS_DEBUG_C
11918requires_config_enabled MBEDTLS_SSL_CLI_C
11919requires_config_enabled MBEDTLS_RSA_C
11920requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11921requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11922                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11923run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha384 - openssl" \
11924            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11925            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
11926                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384 key_opaque=1" \
11927            0 \
11928            -c "got a certificate request" \
11929            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11930            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11931            -c "Protocol is TLSv1.3"
11932
11933requires_gnutls_tls1_3
11934requires_gnutls_next_no_ticket
11935requires_config_enabled MBEDTLS_DEBUG_C
11936requires_config_enabled MBEDTLS_SSL_CLI_C
11937requires_config_enabled MBEDTLS_RSA_C
11938requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11939requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11940                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11941run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha384 - gnutls" \
11942            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11943            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
11944                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha384 key_opaque=1" \
11945            0 \
11946            -c "got a certificate request" \
11947            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11948            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11949            -c "Protocol is TLSv1.3"
11950
11951requires_openssl_tls1_3
11952requires_config_enabled MBEDTLS_DEBUG_C
11953requires_config_enabled MBEDTLS_SSL_CLI_C
11954requires_config_enabled MBEDTLS_RSA_C
11955requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11956requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11957                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11958run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha512 - openssl" \
11959            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10" \
11960            "$P_CLI debug_level=4 force_version=tls13 crt_file=data_files/cert_sha256.crt \
11961                    key_file=data_files/server1.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512 key_opaque=1" \
11962            0 \
11963            -c "got a certificate request" \
11964            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11965            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11966            -c "Protocol is TLSv1.3"
11967
11968requires_gnutls_tls1_3
11969requires_gnutls_next_no_ticket
11970requires_config_enabled MBEDTLS_DEBUG_C
11971requires_config_enabled MBEDTLS_SSL_CLI_C
11972requires_config_enabled MBEDTLS_RSA_C
11973requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11974requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11975                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11976run_test    "TLS 1.3: Client authentication - opaque key, rsa_pss_rsae_sha512 - gnutls" \
11977            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS" \
11978            "$P_CLI debug_level=3 force_version=tls13 crt_file=data_files/server2-sha256.crt \
11979                    key_file=data_files/server2.key sig_algs=ecdsa_secp256r1_sha256,rsa_pss_rsae_sha512 key_opaque=1" \
11980            0 \
11981            -c "got a certificate request" \
11982            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
11983            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
11984            -c "Protocol is TLSv1.3"
11985
11986requires_openssl_tls1_3
11987requires_config_enabled MBEDTLS_DEBUG_C
11988requires_config_enabled MBEDTLS_SSL_CLI_C
11989requires_config_enabled MBEDTLS_RSA_C
11990requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
11991requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
11992                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
11993run_test    "TLS 1.3: Client authentication - opaque key, client alg not in server list - openssl" \
11994            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache -Verify 10
11995                -sigalgs ecdsa_secp256r1_sha256" \
11996            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
11997                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512 key_opaque=1" \
11998            1 \
11999            -c "got a certificate request" \
12000            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12001            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12002            -c "no suitable signature algorithm" \
12003            -C "unkown pk type"
12004
12005requires_gnutls_tls1_3
12006requires_gnutls_next_no_ticket
12007requires_config_enabled MBEDTLS_DEBUG_C
12008requires_config_enabled MBEDTLS_SSL_CLI_C
12009requires_config_enabled MBEDTLS_RSA_C
12010requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
12011requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12012                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12013run_test    "TLS 1.3: Client authentication - opaque key, client alg not in server list - gnutls" \
12014            "$G_NEXT_SRV --debug=4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:-SIGN-ALL:+SIGN-ECDSA-SECP256R1-SHA256:%NO_TICKETS" \
12015            "$P_CLI debug_level=3 crt_file=data_files/ecdsa_secp521r1.crt \
12016                    key_file=data_files/ecdsa_secp521r1.key sig_algs=ecdsa_secp256r1_sha256,ecdsa_secp521r1_sha512 key_opaque=1" \
12017            1 \
12018            -c "got a certificate request" \
12019            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE" \
12020            -c "client state: MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY" \
12021            -c "no suitable signature algorithm" \
12022            -C "unkown pk type"
12023
12024requires_openssl_tls1_3
12025requires_config_enabled MBEDTLS_DEBUG_C
12026requires_config_enabled MBEDTLS_SSL_CLI_C
12027requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12028                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12029run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_128_GCM_SHA256 - openssl" \
12030            "$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" \
12031            "$P_CLI debug_level=4" \
12032            0 \
12033            -c "received HelloRetryRequest message" \
12034            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12035            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12036            -c "Protocol is TLSv1.3" \
12037            -c "HTTP/1.0 200 ok"
12038
12039requires_openssl_tls1_3
12040requires_config_enabled MBEDTLS_DEBUG_C
12041requires_config_enabled MBEDTLS_SSL_CLI_C
12042requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12043                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12044run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_256_GCM_SHA384 - openssl" \
12045            "$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" \
12046            "$P_CLI debug_level=4" \
12047            0 \
12048            -c "received HelloRetryRequest message" \
12049            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12050            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12051            -c "Protocol is TLSv1.3" \
12052            -c "HTTP/1.0 200 ok"
12053
12054requires_gnutls_tls1_3
12055requires_gnutls_next_no_ticket
12056requires_config_enabled MBEDTLS_DEBUG_C
12057requires_config_enabled MBEDTLS_SSL_CLI_C
12058requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12059                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12060run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_128_GCM_SHA256 - gnutls" \
12061            "$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" \
12062            "$P_CLI debug_level=4" \
12063            0 \
12064            -c "received HelloRetryRequest message" \
12065            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12066            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12067            -c "Protocol is TLSv1.3" \
12068            -c "HTTP/1.0 200 OK"
12069
12070requires_gnutls_tls1_3
12071requires_gnutls_next_no_ticket
12072requires_config_enabled MBEDTLS_DEBUG_C
12073requires_config_enabled MBEDTLS_SSL_CLI_C
12074requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12075                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12076run_test    "TLS 1.3: HRR check, ciphersuite TLS_AES_256_GCM_SHA384 - gnutls" \
12077            "$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" \
12078            "$P_CLI debug_level=4" \
12079            0 \
12080            -c "received HelloRetryRequest message" \
12081            -c "<= ssl_tls13_process_server_hello ( HelloRetryRequest )" \
12082            -c "client state: MBEDTLS_SSL_CLIENT_HELLO" \
12083            -c "Protocol is TLSv1.3" \
12084            -c "HTTP/1.0 200 OK"
12085
12086requires_openssl_tls1_3
12087requires_config_enabled MBEDTLS_DEBUG_C
12088requires_config_enabled MBEDTLS_SSL_SRV_C
12089requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12090run_test    "TLS 1.3: Server side check - openssl" \
12091            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12092            "$O_NEXT_CLI -msg -debug -tls1_3 -no_middlebox" \
12093            0 \
12094            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12095            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12096            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12097            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12098            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12099            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12100            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
12101            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP"
12102
12103requires_openssl_tls1_3
12104requires_config_enabled MBEDTLS_DEBUG_C
12105requires_config_enabled MBEDTLS_SSL_SRV_C
12106requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12107run_test    "TLS 1.3: Server side check - openssl with client authentication" \
12108            "$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" \
12109            "$O_NEXT_CLI -msg -debug -cert data_files/server5.crt -key data_files/server5.key -tls1_3 -no_middlebox" \
12110            0 \
12111            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12112            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12113            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12114            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12115            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12116            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12117            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12118            -s "=> write certificate request" \
12119            -s "=> parse client hello" \
12120            -s "<= parse client hello"
12121
12122requires_gnutls_tls1_3
12123requires_gnutls_next_no_ticket
12124requires_config_enabled MBEDTLS_DEBUG_C
12125requires_config_enabled MBEDTLS_SSL_SRV_C
12126requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12127run_test    "TLS 1.3: Server side check - gnutls" \
12128            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12129            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12130            0 \
12131            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12132            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12133            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12134            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12135            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12136            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12137            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
12138            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12139            -c "HTTP/1.0 200 OK"
12140
12141requires_gnutls_tls1_3
12142requires_gnutls_next_no_ticket
12143requires_config_enabled MBEDTLS_DEBUG_C
12144requires_config_enabled MBEDTLS_SSL_SRV_C
12145requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12146run_test    "TLS 1.3: Server side check - gnutls with client authentication" \
12147            "$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" \
12148            "$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" \
12149            0 \
12150            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12151            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12152            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12153            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12154            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12155            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12156            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12157            -s "=> write certificate request" \
12158            -s "=> parse client hello" \
12159            -s "<= parse client hello"
12160
12161requires_config_enabled MBEDTLS_DEBUG_C
12162requires_config_enabled MBEDTLS_SSL_SRV_C
12163requires_config_enabled MBEDTLS_SSL_CLI_C
12164requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12165run_test    "TLS 1.3: Server side check - mbedtls" \
12166            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12167            "$P_CLI debug_level=4 force_version=tls13" \
12168            0 \
12169            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12170            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12171            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12172            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12173            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12174            -s "tls13 server state: MBEDTLS_SSL_CERTIFICATE_VERIFY" \
12175            -s "tls13 server state: MBEDTLS_SSL_SERVER_FINISHED" \
12176            -s "tls13 server state: MBEDTLS_SSL_CLIENT_FINISHED" \
12177            -s "tls13 server state: MBEDTLS_SSL_HANDSHAKE_WRAPUP" \
12178            -c "HTTP/1.0 200 OK"
12179
12180requires_config_enabled MBEDTLS_DEBUG_C
12181requires_config_enabled MBEDTLS_SSL_SRV_C
12182requires_config_enabled MBEDTLS_SSL_CLI_C
12183requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12184run_test    "TLS 1.3: Server side check - mbedtls with client authentication" \
12185            "$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" \
12186            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13" \
12187            0 \
12188            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12189            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12190            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12191            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12192            -s "=> write certificate request" \
12193            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12194            -s "=> parse client hello" \
12195            -s "<= parse client hello"
12196
12197requires_config_enabled MBEDTLS_DEBUG_C
12198requires_config_enabled MBEDTLS_SSL_SRV_C
12199requires_config_enabled MBEDTLS_SSL_CLI_C
12200requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12201run_test    "TLS 1.3: Server side check - mbedtls with client empty certificate" \
12202            "$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" \
12203            "$P_CLI debug_level=4 crt_file=none key_file=none force_version=tls13" \
12204            1 \
12205            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12206            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12207            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12208            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12209            -s "=> write certificate request" \
12210            -s "SSL - No client certification received from the client, but required by the authentication mode" \
12211            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12212            -s "=> parse client hello" \
12213            -s "<= parse client hello"
12214
12215requires_config_enabled MBEDTLS_DEBUG_C
12216requires_config_enabled MBEDTLS_SSL_SRV_C
12217requires_config_enabled MBEDTLS_SSL_CLI_C
12218requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12219run_test    "TLS 1.3: Server side check - mbedtls with optional client authentication" \
12220            "$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" \
12221            "$P_CLI debug_level=4 force_version=tls13 crt_file=none key_file=none" \
12222            0 \
12223            -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12224            -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12225            -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12226            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12227            -s "=> write certificate request" \
12228            -c "client state: MBEDTLS_SSL_CERTIFICATE_REQUEST" \
12229            -s "=> parse client hello" \
12230            -s "<= parse client hello"
12231
12232requires_config_enabled MBEDTLS_DEBUG_C
12233requires_config_enabled MBEDTLS_SSL_CLI_C
12234requires_config_enabled MBEDTLS_SSL_SRV_C
12235requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12236run_test "TLS 1.3: server: HRR check - mbedtls" \
12237         "$P_SRV debug_level=4 force_version=tls13 curves=secp384r1" \
12238         "$P_CLI debug_level=4 force_version=tls13 curves=secp256r1,secp384r1" \
12239         0 \
12240        -s "tls13 server state: MBEDTLS_SSL_CLIENT_HELLO" \
12241        -s "tls13 server state: MBEDTLS_SSL_SERVER_HELLO" \
12242        -s "tls13 server state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12243        -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
12244        -c "client state: MBEDTLS_SSL_ENCRYPTED_EXTENSIONS" \
12245        -s "selected_group: secp384r1" \
12246        -s "=> write hello retry request" \
12247        -s "<= write hello retry request"
12248
12249requires_config_enabled MBEDTLS_DEBUG_C
12250requires_config_enabled MBEDTLS_SSL_SRV_C
12251requires_config_enabled MBEDTLS_SSL_CLI_C
12252requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12253run_test    "TLS 1.3: Server side check, no server certificate available" \
12254            "$P_SRV debug_level=4 crt_file=none key_file=none force_version=tls13" \
12255            "$P_CLI debug_level=4 force_version=tls13" \
12256            1 \
12257            -s "tls13 server state: MBEDTLS_SSL_SERVER_CERTIFICATE" \
12258            -s "No certificate available."
12259
12260requires_openssl_tls1_3
12261requires_config_enabled MBEDTLS_DEBUG_C
12262requires_config_enabled MBEDTLS_SSL_SRV_C
12263requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12264                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12265run_test    "TLS 1.3: Server side check - openssl with sni" \
12266            "$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 \
12267             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,-,-,-" \
12268            "$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" \
12269            0 \
12270            -s "parse ServerName extension" \
12271            -s "HTTP/1.0 200 OK"
12272
12273requires_gnutls_tls1_3
12274requires_config_enabled MBEDTLS_DEBUG_C
12275requires_config_enabled MBEDTLS_SSL_SRV_C
12276requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12277                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12278run_test    "TLS 1.3: Server side check - gnutls with sni" \
12279            "$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 \
12280             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,-,-,-" \
12281            "$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" \
12282            0 \
12283            -s "parse ServerName extension" \
12284            -s "HTTP/1.0 200 OK"
12285
12286requires_config_enabled MBEDTLS_DEBUG_C
12287requires_config_enabled MBEDTLS_SSL_SRV_C
12288requires_config_enabled MBEDTLS_SSL_CLI_C
12289requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12290                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12291run_test    "TLS 1.3: Server side check - mbedtls with sni" \
12292            "$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 \
12293             sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
12294            "$P_CLI debug_level=4 server_name=localhost crt_file=data_files/server5.crt key_file=data_files/server5.key \
12295            force_version=tls13" \
12296            0 \
12297            -s "parse ServerName extension" \
12298            -s "HTTP/1.0 200 OK"
12299
12300for i in opt-testcases/*.sh
12301do
12302    TEST_SUITE_NAME=${i##*/}
12303    TEST_SUITE_NAME=${TEST_SUITE_NAME%.*}
12304    . "$i"
12305done
12306unset TEST_SUITE_NAME
12307
12308# Test 1.3 compatibility mode
12309requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12310requires_config_enabled MBEDTLS_DEBUG_C
12311requires_config_enabled MBEDTLS_SSL_SRV_C
12312requires_config_enabled MBEDTLS_SSL_CLI_C
12313requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12314run_test    "TLS 1.3 m->m both peers do not support middlebox compatibility" \
12315            "$P_SRV debug_level=4 force_version=tls13 tickets=0" \
12316            "$P_CLI debug_level=4" \
12317            0 \
12318            -s "Protocol is TLSv1.3" \
12319            -c "Protocol is TLSv1.3" \
12320            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12321            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12322
12323requires_config_enabled MBEDTLS_DEBUG_C
12324requires_config_enabled MBEDTLS_SSL_SRV_C
12325requires_config_enabled MBEDTLS_SSL_CLI_C
12326requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12327                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12328run_test    "TLS 1.3 m->m both with middlebox compat support" \
12329            "$P_SRV debug_level=4 force_version=tls13 tickets=0" \
12330            "$P_CLI debug_level=4" \
12331            0 \
12332            -s "Protocol is TLSv1.3" \
12333            -c "Protocol is TLSv1.3" \
12334            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12335            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12336
12337requires_openssl_tls1_3
12338requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12339requires_config_enabled MBEDTLS_DEBUG_C
12340requires_config_enabled MBEDTLS_SSL_CLI_C
12341requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12342run_test    "TLS 1.3 m->O both peers do not support middlebox compatibility" \
12343            "$O_NEXT_SRV -msg -tls1_3 -no_middlebox -num_tickets 0 -no_resume_ephemeral -no_cache" \
12344            "$P_CLI debug_level=4" \
12345            0 \
12346            -c "Protocol is TLSv1.3" \
12347            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12348            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12349
12350requires_openssl_tls1_3
12351requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12352requires_config_enabled MBEDTLS_DEBUG_C
12353requires_config_enabled MBEDTLS_SSL_CLI_C
12354requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12355run_test    "TLS 1.3 m->O server with middlebox compat support, not client" \
12356            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12357            "$P_CLI debug_level=4" \
12358            1 \
12359            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12360
12361requires_openssl_tls1_3
12362requires_config_enabled MBEDTLS_DEBUG_C
12363requires_config_enabled MBEDTLS_SSL_CLI_C
12364requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12365                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12366run_test    "TLS 1.3 m->O both with middlebox compat support" \
12367            "$O_NEXT_SRV -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12368            "$P_CLI debug_level=4" \
12369            0 \
12370            -c "Protocol is TLSv1.3" \
12371            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12372
12373requires_gnutls_tls1_3
12374requires_gnutls_next_no_ticket
12375requires_gnutls_next_disable_tls13_compat
12376requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12377requires_config_enabled MBEDTLS_DEBUG_C
12378requires_config_enabled MBEDTLS_SSL_CLI_C
12379requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12380run_test    "TLS 1.3 m->G both peers do not support middlebox compatibility" \
12381            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert" \
12382            "$P_CLI debug_level=4" \
12383            0 \
12384            -c "Protocol is TLSv1.3" \
12385            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12386            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12387
12388requires_gnutls_tls1_3
12389requires_gnutls_next_no_ticket
12390requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12391requires_config_enabled MBEDTLS_DEBUG_C
12392requires_config_enabled MBEDTLS_SSL_CLI_C
12393requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12394run_test    "TLS 1.3 m->G server with middlebox compat support, not client" \
12395            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
12396            "$P_CLI debug_level=4" \
12397            1 \
12398            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12399
12400requires_gnutls_tls1_3
12401requires_gnutls_next_no_ticket
12402requires_config_enabled MBEDTLS_DEBUG_C
12403requires_config_enabled MBEDTLS_SSL_CLI_C
12404requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12405                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12406run_test    "TLS 1.3 m->G both with middlebox compat support" \
12407            "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
12408            "$P_CLI debug_level=4" \
12409            0 \
12410            -c "Protocol is TLSv1.3" \
12411            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12412
12413requires_openssl_tls1_3
12414requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12415requires_config_enabled MBEDTLS_DEBUG_C
12416requires_config_enabled MBEDTLS_SSL_SRV_C
12417requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12418run_test    "TLS 1.3 O->m both peers do not support middlebox compatibility" \
12419            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12420            "$O_NEXT_CLI -msg -debug -no_middlebox" \
12421            0 \
12422            -s "Protocol is TLSv1.3" \
12423            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12424            -C "14 03 03 00 01"
12425
12426requires_openssl_tls1_3
12427requires_config_enabled MBEDTLS_DEBUG_C
12428requires_config_enabled MBEDTLS_SSL_SRV_C
12429requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12430                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12431run_test    "TLS 1.3 O->m server with middlebox compat support, not client" \
12432            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12433            "$O_NEXT_CLI -msg -debug -no_middlebox" \
12434            0 \
12435            -s "Protocol is TLSv1.3" \
12436            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO"
12437
12438requires_openssl_tls1_3
12439requires_config_enabled MBEDTLS_DEBUG_C
12440requires_config_enabled MBEDTLS_SSL_SRV_C
12441requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12442                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12443run_test    "TLS 1.3 O->m both with middlebox compat support" \
12444            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12445            "$O_NEXT_CLI -msg -debug" \
12446            0 \
12447            -s "Protocol is TLSv1.3" \
12448            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12449            -c "14 03 03 00 01"
12450
12451requires_gnutls_tls1_3
12452requires_gnutls_next_no_ticket
12453requires_gnutls_next_disable_tls13_compat
12454requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12455requires_config_enabled MBEDTLS_DEBUG_C
12456requires_config_enabled MBEDTLS_SSL_SRV_C
12457requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12458run_test    "TLS 1.3 G->m both peers do not support middlebox compatibility" \
12459            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12460            "$G_NEXT_CLI localhost --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12461            0 \
12462            -s "Protocol is TLSv1.3" \
12463            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12464            -C "SSL 3.3 ChangeCipherSpec packet received"
12465
12466requires_gnutls_tls1_3
12467requires_gnutls_next_no_ticket
12468requires_gnutls_next_disable_tls13_compat
12469requires_config_enabled MBEDTLS_DEBUG_C
12470requires_config_enabled MBEDTLS_SSL_SRV_C
12471requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12472                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12473run_test    "TLS 1.3 G->m server with middlebox compat support, not client" \
12474            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12475            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12476            0 \
12477            -s "Protocol is TLSv1.3" \
12478            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12479            -c "SSL 3.3 ChangeCipherSpec packet received" \
12480            -c "discarding change cipher spec in TLS1.3"
12481
12482requires_gnutls_tls1_3
12483requires_gnutls_next_no_ticket
12484requires_gnutls_next_disable_tls13_compat
12485requires_config_enabled MBEDTLS_DEBUG_C
12486requires_config_enabled MBEDTLS_SSL_SRV_C
12487requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12488                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12489run_test    "TLS 1.3 G->m both with middlebox compat support" \
12490            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=0" \
12491            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12492            0 \
12493            -s "Protocol is TLSv1.3" \
12494            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO" \
12495            -c "SSL 3.3 ChangeCipherSpec packet received"
12496
12497requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12498requires_config_enabled MBEDTLS_DEBUG_C
12499requires_config_enabled MBEDTLS_SSL_SRV_C
12500requires_config_enabled MBEDTLS_SSL_CLI_C
12501requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12502run_test    "TLS 1.3 m->m HRR both peers do not support middlebox compatibility" \
12503            "$P_SRV debug_level=4 force_version=tls13 curves=secp384r1 tickets=0" \
12504            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12505            0 \
12506            -s "Protocol is TLSv1.3" \
12507            -c "Protocol is TLSv1.3" \
12508            -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
12509            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12510            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12511
12512requires_config_enabled MBEDTLS_DEBUG_C
12513requires_config_enabled MBEDTLS_SSL_SRV_C
12514requires_config_enabled MBEDTLS_SSL_CLI_C
12515requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12516                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12517run_test    "TLS 1.3 m->m HRR both with middlebox compat support" \
12518            "$P_SRV debug_level=4 force_version=tls13 curves=secp384r1 tickets=0" \
12519            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12520            0 \
12521            -s "Protocol is TLSv1.3" \
12522            -c "Protocol is TLSv1.3" \
12523            -s "tls13 server state: MBEDTLS_SSL_HELLO_RETRY_REQUEST" \
12524            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12525            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12526
12527requires_openssl_tls1_3
12528requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12529requires_config_enabled MBEDTLS_DEBUG_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 m->O HRR both peers do not support middlebox compatibility" \
12533            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -no_middlebox -num_tickets 0 -no_cache" \
12534            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12535            0 \
12536            -c "Protocol is TLSv1.3" \
12537            -c "received HelloRetryRequest message" \
12538            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12539            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12540
12541requires_openssl_tls1_3
12542requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12543requires_config_enabled MBEDTLS_DEBUG_C
12544requires_config_enabled MBEDTLS_SSL_CLI_C
12545requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12546run_test    "TLS 1.3 m->O HRR server with middlebox compat support, not client" \
12547            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -num_tickets 0 -no_cache" \
12548            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12549            1 \
12550            -c "received HelloRetryRequest message" \
12551            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12552
12553requires_openssl_tls1_3
12554requires_config_enabled MBEDTLS_DEBUG_C
12555requires_config_enabled MBEDTLS_SSL_CLI_C
12556requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12557                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12558run_test    "TLS 1.3 m->O HRR both with middlebox compat support" \
12559            "$O_NEXT_SRV -msg -tls1_3 -groups P-384 -num_tickets 0 -no_resume_ephemeral -no_cache" \
12560            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12561            0 \
12562            -c "Protocol is TLSv1.3" \
12563            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12564
12565requires_gnutls_tls1_3
12566requires_gnutls_next_no_ticket
12567requires_gnutls_next_disable_tls13_compat
12568requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12569requires_config_enabled MBEDTLS_DEBUG_C
12570requires_config_enabled MBEDTLS_SSL_CLI_C
12571requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12572run_test    "TLS 1.3 m->G HRR both peers do not support middlebox compatibility" \
12573            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert" \
12574            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12575            0 \
12576            -c "Protocol is TLSv1.3" \
12577            -c "received HelloRetryRequest message" \
12578            -C "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode" \
12579            -C "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12580
12581requires_gnutls_tls1_3
12582requires_gnutls_next_no_ticket
12583requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12584requires_config_enabled MBEDTLS_DEBUG_C
12585requires_config_enabled MBEDTLS_SSL_CLI_C
12586requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12587run_test    "TLS 1.3 m->G HRR server with middlebox compat support, not client" \
12588            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:%NO_TICKETS --disable-client-cert" \
12589            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12590            1 \
12591            -c "received HelloRetryRequest message" \
12592            -c "ChangeCipherSpec invalid in TLS 1.3 without compatibility mode"
12593
12594requires_gnutls_tls1_3
12595requires_gnutls_next_no_ticket
12596requires_config_enabled MBEDTLS_DEBUG_C
12597requires_config_enabled MBEDTLS_SSL_CLI_C
12598requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12599                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12600run_test    "TLS 1.3 m->G HRR both with middlebox compat support" \
12601            "$G_NEXT_SRV --priority=NORMAL:-GROUP-ALL:+GROUP-SECP384R1:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%NO_TICKETS --disable-client-cert" \
12602            "$P_CLI debug_level=4 curves=secp256r1,secp384r1" \
12603            0 \
12604            -c "Protocol is TLSv1.3" \
12605            -c "Ignore ChangeCipherSpec in TLS 1.3 compatibility mode"
12606
12607requires_openssl_tls1_3
12608requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12609requires_config_enabled MBEDTLS_DEBUG_C
12610requires_config_enabled MBEDTLS_SSL_SRV_C
12611requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12612run_test    "TLS 1.3 O->m HRR both peers do not support middlebox compatibility" \
12613            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12614            "$O_NEXT_CLI -msg -debug -groups P-256:P-384 -no_middlebox" \
12615            0 \
12616            -s "Protocol is TLSv1.3" \
12617            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12618            -C "14 03 03 00 01"
12619
12620requires_openssl_tls1_3
12621requires_config_enabled MBEDTLS_DEBUG_C
12622requires_config_enabled MBEDTLS_SSL_SRV_C
12623requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12624                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12625run_test    "TLS 1.3 O->m HRR server with middlebox compat support, not client" \
12626            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12627            "$O_NEXT_CLI -msg -debug -groups P-256:P-384 -no_middlebox" \
12628            0 \
12629            -s "Protocol is TLSv1.3" \
12630            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12631
12632requires_openssl_tls1_3
12633requires_config_enabled MBEDTLS_DEBUG_C
12634requires_config_enabled MBEDTLS_SSL_SRV_C
12635requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12636                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12637run_test    "TLS 1.3 O->m HRR both with middlebox compat support" \
12638            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12639            "$O_NEXT_CLI -msg -debug -groups P-256:P-384" \
12640            0 \
12641            -s "Protocol is TLSv1.3" \
12642            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12643            -c "14 03 03 00 01"
12644
12645requires_gnutls_tls1_3
12646requires_gnutls_next_no_ticket
12647requires_gnutls_next_disable_tls13_compat
12648requires_config_disabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
12649requires_config_enabled MBEDTLS_DEBUG_C
12650requires_config_enabled MBEDTLS_SSL_SRV_C
12651requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12652run_test    "TLS 1.3 G->m HRR both peers do not support middlebox compatibility" \
12653            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12654            "$G_NEXT_CLI localhost --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12655            0 \
12656            -s "Protocol is TLSv1.3" \
12657            -S "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12658            -C "SSL 3.3 ChangeCipherSpec packet received"
12659
12660requires_gnutls_tls1_3
12661requires_gnutls_next_no_ticket
12662requires_gnutls_next_disable_tls13_compat
12663requires_config_enabled MBEDTLS_DEBUG_C
12664requires_config_enabled MBEDTLS_SSL_SRV_C
12665requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12666                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12667run_test    "TLS 1.3 G->m HRR server with middlebox compat support, not client" \
12668            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12669            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12670            0 \
12671            -s "Protocol is TLSv1.3" \
12672            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12673            -c "SSL 3.3 ChangeCipherSpec packet received" \
12674            -c "discarding change cipher spec in TLS1.3"
12675
12676requires_gnutls_tls1_3
12677requires_gnutls_next_no_ticket
12678requires_gnutls_next_disable_tls13_compat
12679requires_config_enabled MBEDTLS_DEBUG_C
12680requires_config_enabled MBEDTLS_SSL_SRV_C
12681requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12682                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12683run_test    "TLS 1.3 G->m HRR both with middlebox compat support" \
12684            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 curves=secp384r1 tickets=0" \
12685            "$G_NEXT_CLI localhost --debug=10 --priority=NORMAL:-GROUP-ALL:+GROUP-SECP256R1:+GROUP-SECP384R1:%NO_TICKETS:%DISABLE_TLS13_COMPAT_MODE -V" \
12686            0 \
12687            -s "Protocol is TLSv1.3" \
12688            -s "tls13 server state: MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST" \
12689            -c "SSL 3.3 ChangeCipherSpec packet received"
12690
12691requires_openssl_tls1_3
12692requires_config_enabled MBEDTLS_DEBUG_C
12693requires_config_enabled MBEDTLS_SSL_CLI_C
12694requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12695                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12696run_test    "TLS 1.3: Check signature algorithm order, m->O" \
12697            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
12698                                 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache
12699                                 -Verify 10 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp256r1_sha256" \
12700            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
12701                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12702            0 \
12703            -c "Protocol is TLSv1.3" \
12704            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
12705            -c "HTTP/1.0 200 [Oo][Kk]"
12706
12707requires_gnutls_tls1_3
12708requires_config_enabled MBEDTLS_DEBUG_C
12709requires_config_enabled MBEDTLS_SSL_CLI_C
12710requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12711                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12712run_test    "TLS 1.3: Check signature algorithm order, m->G" \
12713            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
12714                    -d 4
12715                    --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 " \
12716            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
12717                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12718            0 \
12719            -c "Protocol is TLSv1.3" \
12720            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
12721            -c "HTTP/1.0 200 [Oo][Kk]"
12722
12723requires_config_enabled MBEDTLS_DEBUG_C
12724requires_config_enabled MBEDTLS_SSL_SRV_C
12725requires_config_enabled MBEDTLS_SSL_CLI_C
12726requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12727                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12728run_test    "TLS 1.3: Check signature algorithm order, m->m" \
12729            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
12730                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
12731                    crt_file=data_files/server5.crt key_file=data_files/server5.key
12732                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
12733            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
12734                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12735            0 \
12736            -c "Protocol is TLSv1.3" \
12737            -c "CertificateVerify signature with rsa_pss_rsae_sha512" \
12738            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
12739            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512" \
12740            -c "HTTP/1.0 200 [Oo][Kk]"
12741
12742requires_openssl_tls1_3
12743requires_config_enabled MBEDTLS_DEBUG_C
12744requires_config_enabled MBEDTLS_SSL_SRV_C
12745requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12746                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12747run_test    "TLS 1.3: Check signature algorithm order, O->m" \
12748            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
12749                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
12750                    crt_file=data_files/server5.crt key_file=data_files/server5.key
12751                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
12752            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
12753                                 -cert data_files/server2-sha256.crt -key data_files/server2.key \
12754                                 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp256r1_sha256"  \
12755            0 \
12756            -c "TLSv1.3" \
12757            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
12758            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512"
12759
12760requires_gnutls_tls1_3
12761requires_config_enabled MBEDTLS_DEBUG_C
12762requires_config_enabled MBEDTLS_SSL_SRV_C
12763requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12764                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12765run_test    "TLS 1.3: Check signature algorithm order, G->m" \
12766            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
12767                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
12768                    crt_file=data_files/server5.crt key_file=data_files/server5.key
12769                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
12770            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
12771                                 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key \
12772                                 --priority=NORMAL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-RSA-PSS-RSAE-SHA384"  \
12773            0 \
12774            -c "Negotiated version: 3.4" \
12775            -c "HTTP/1.0 200 [Oo][Kk]" \
12776            -s "CertificateVerify signature with rsa_pss_rsae_sha512" \
12777            -s "ssl_tls13_pick_key_cert:selected signature algorithm rsa_pss_rsae_sha512"
12778
12779requires_gnutls_tls1_3
12780requires_config_enabled MBEDTLS_DEBUG_C
12781requires_config_enabled MBEDTLS_SSL_SRV_C
12782requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12783                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12784run_test    "TLS 1.3: Check server no suitable signature algorithm, G->m" \
12785            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
12786                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
12787                    crt_file=data_files/server5.crt key_file=data_files/server5.key
12788                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256 " \
12789            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
12790                                 --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key \
12791                                 --priority=NORMAL:-SIGN-ALL:+SIGN-RSA-SHA512:+SIGN-RSA-PSS-RSAE-SHA512:+SIGN-ECDSA-SECP521R1-SHA512"  \
12792            1 \
12793            -S "ssl_tls13_pick_key_cert:check signature algorithm"
12794
12795requires_openssl_tls1_3
12796requires_config_enabled MBEDTLS_DEBUG_C
12797requires_config_enabled MBEDTLS_SSL_SRV_C
12798requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12799                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12800run_test    "TLS 1.3: Check server no suitable signature algorithm, O->m" \
12801            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
12802                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
12803                    crt_file=data_files/server5.crt key_file=data_files/server5.key
12804                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256" \
12805            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
12806                                 -cert data_files/server2-sha256.crt -key data_files/server2.key \
12807                                 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:ecdsa_secp521r1_sha512"  \
12808            1 \
12809            -S "ssl_tls13_pick_key_cert:check signature algorithm"
12810
12811requires_config_enabled MBEDTLS_DEBUG_C
12812requires_config_enabled MBEDTLS_SSL_SRV_C
12813requires_config_enabled MBEDTLS_SSL_CLI_C
12814requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12815                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12816run_test    "TLS 1.3: Check server no suitable signature algorithm, m->m" \
12817            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
12818                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
12819                    crt_file=data_files/server5.crt key_file=data_files/server5.key
12820                    sig_algs=rsa_pkcs1_sha512,ecdsa_secp256r1_sha256 " \
12821            "$P_CLI allow_sha1=0 debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key \
12822                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,ecdsa_secp521r1_sha512" \
12823            1 \
12824            -S "ssl_tls13_pick_key_cert:check signature algorithm"
12825
12826requires_gnutls_tls1_3
12827requires_config_enabled MBEDTLS_DEBUG_C
12828requires_config_enabled MBEDTLS_SSL_SRV_C
12829requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12830                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12831run_test    "TLS 1.3: Check server no suitable certificate, G->m" \
12832            "$P_SRV debug_level=4 force_version=tls13
12833                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
12834                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
12835            "$G_NEXT_CLI_NO_CERT localhost -d 4 --x509cafile data_files/test-ca_cat12.crt \
12836                                 --priority=NORMAL:-SIGN-ALL:+SIGN-ECDSA-SECP521R1-SHA512:+SIGN-ECDSA-SECP256R1-SHA256"  \
12837            1 \
12838            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
12839
12840requires_openssl_tls1_3
12841requires_config_enabled MBEDTLS_DEBUG_C
12842requires_config_enabled MBEDTLS_SSL_SRV_C
12843requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12844                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12845run_test    "TLS 1.3: Check server no suitable certificate, O->m" \
12846            "$P_SRV debug_level=4 force_version=tls13
12847                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
12848                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
12849            "$O_NEXT_CLI_NO_CERT -msg -CAfile data_files/test-ca_cat12.crt \
12850                                 -sigalgs ecdsa_secp521r1_sha512:ecdsa_secp256r1_sha256"  \
12851            1 \
12852            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
12853
12854requires_config_enabled MBEDTLS_DEBUG_C
12855requires_config_enabled MBEDTLS_SSL_SRV_C
12856requires_config_enabled MBEDTLS_SSL_CLI_C
12857requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12858                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12859run_test    "TLS 1.3: Check server no suitable certificate, m->m" \
12860            "$P_SRV debug_level=4 force_version=tls13
12861                    crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
12862                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256 " \
12863            "$P_CLI allow_sha1=0 debug_level=4 \
12864                    sig_algs=ecdsa_secp521r1_sha512,ecdsa_secp256r1_sha256" \
12865            1 \
12866            -s "ssl_tls13_pick_key_cert:no suitable certificate found"
12867
12868requires_openssl_tls1_3
12869requires_config_enabled MBEDTLS_DEBUG_C
12870requires_config_enabled MBEDTLS_SSL_CLI_C
12871requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12872                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12873run_test    "TLS 1.3: Check client no signature algorithm, m->O" \
12874            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
12875                                 -msg -tls1_3 -num_tickets 0 -no_resume_ephemeral -no_cache
12876                                 -Verify 10 -sigalgs rsa_pkcs1_sha512:rsa_pss_rsae_sha512:rsa_pss_rsae_sha384:ecdsa_secp521r1_sha512" \
12877            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
12878                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12879            1 \
12880            -c "no suitable signature algorithm"
12881
12882requires_gnutls_tls1_3
12883requires_config_enabled MBEDTLS_DEBUG_C
12884requires_config_enabled MBEDTLS_SSL_CLI_C
12885requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12886                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12887run_test    "TLS 1.3: Check client no signature algorithm, m->G" \
12888            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
12889                    -d 4
12890                    --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 " \
12891            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
12892                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12893            1 \
12894            -c "no suitable signature algorithm"
12895
12896requires_config_enabled MBEDTLS_DEBUG_C
12897requires_config_enabled MBEDTLS_SSL_SRV_C
12898requires_config_enabled MBEDTLS_SSL_CLI_C
12899requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12900                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
12901run_test    "TLS 1.3: Check client no signature algorithm, m->m" \
12902            "$P_SRV debug_level=4 force_version=tls13 auth_mode=required
12903                    crt_file2=data_files/server2-sha256.crt key_file2=data_files/server2.key
12904                    crt_file=data_files/server5.crt key_file=data_files/server5.key
12905                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp521r1_sha512" \
12906            "$P_CLI debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key \
12907                    sig_algs=rsa_pkcs1_sha512,rsa_pss_rsae_sha512,rsa_pss_rsae_sha384,ecdsa_secp256r1_sha256" \
12908            1 \
12909            -c "no suitable signature algorithm"
12910
12911requires_openssl_tls1_3
12912requires_config_enabled MBEDTLS_DEBUG_C
12913requires_config_enabled MBEDTLS_SSL_CLI_C
12914requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12915                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
12916                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
12917run_test    "TLS 1.3: NewSessionTicket: Basic check, m->O" \
12918            "$O_NEXT_SRV -msg -tls1_3 -no_resume_ephemeral -no_cache --num_tickets 4" \
12919            "$P_CLI debug_level=1 reco_mode=1 reconnect=1" \
12920            0 \
12921            -c "Protocol is TLSv1.3" \
12922            -c "got new session ticket." \
12923            -c "Saving session for reuse... ok" \
12924            -c "Reconnecting with saved session" \
12925            -c "HTTP/1.0 200 ok"
12926
12927requires_gnutls_tls1_3
12928requires_config_enabled MBEDTLS_DEBUG_C
12929requires_config_enabled MBEDTLS_SSL_CLI_C
12930requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12931                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
12932                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
12933run_test    "TLS 1.3: NewSessionTicket: Basic check, m->G" \
12934            "$G_NEXT_SRV -d 10 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 --disable-client-cert" \
12935            "$P_CLI debug_level=1 reco_mode=1 reconnect=1" \
12936            0 \
12937            -c "Protocol is TLSv1.3" \
12938            -c "got new session ticket." \
12939            -c "Saving session for reuse... ok" \
12940            -c "Reconnecting with saved session" \
12941            -c "HTTP/1.0 200 OK" \
12942            -s "This is a resumed session"
12943
12944requires_openssl_tls1_3
12945requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
12946requires_config_enabled MBEDTLS_SSL_SRV_C
12947requires_config_enabled MBEDTLS_DEBUG_C
12948requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12949                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
12950                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
12951# https://github.com/openssl/openssl/issues/10714
12952# Until now, OpenSSL client does not support reconnect.
12953skip_next_test
12954run_test    "TLS 1.3: NewSessionTicket: Basic check, O->m" \
12955            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4" \
12956            "$O_NEXT_CLI -msg -debug -tls1_3 -reconnect" \
12957            0 \
12958            -s "=> write NewSessionTicket msg" \
12959            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
12960            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH"
12961
12962requires_gnutls_tls1_3
12963requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
12964requires_config_enabled MBEDTLS_SSL_SRV_C
12965requires_config_enabled MBEDTLS_DEBUG_C
12966requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12967                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
12968                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
12969run_test    "TLS 1.3: NewSessionTicket: Basic check, G->m" \
12970            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4" \
12971            "$G_NEXT_CLI localhost -d 4 --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -r" \
12972            0 \
12973            -c "Connecting again- trying to resume previous session" \
12974            -c "NEW SESSION TICKET (4) was received" \
12975            -s "=> write NewSessionTicket msg" \
12976            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
12977            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" \
12978            -s "key exchange mode: ephemeral" \
12979            -s "key exchange mode: psk_ephemeral" \
12980            -s "found pre_shared_key extension"
12981
12982requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
12983requires_config_enabled MBEDTLS_SSL_SRV_C
12984requires_config_enabled MBEDTLS_SSL_CLI_C
12985requires_config_enabled MBEDTLS_DEBUG_C
12986requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
12987                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
12988                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
12989run_test    "TLS 1.3: NewSessionTicket: Basic check, m->m" \
12990            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4" \
12991            "$P_CLI debug_level=4 reco_mode=1 reconnect=1" \
12992            0 \
12993            -c "Protocol is TLSv1.3" \
12994            -c "got new session ticket ( 3 )" \
12995            -c "Saving session for reuse... ok" \
12996            -c "Reconnecting with saved session" \
12997            -c "HTTP/1.0 200 OK"    \
12998            -s "=> write NewSessionTicket msg" \
12999            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13000            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" \
13001            -s "key exchange mode: ephemeral" \
13002            -s "key exchange mode: psk_ephemeral" \
13003            -s "found pre_shared_key extension"
13004
13005requires_openssl_tls1_3
13006requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13007requires_config_enabled MBEDTLS_DEBUG_C
13008requires_config_enabled MBEDTLS_SSL_CLI_C
13009run_test    "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->O" \
13010            "$O_NEXT_SRV_NO_CERT -cert data_files/server2-sha256.crt -key data_files/server2.key
13011                                 -msg -tls1_2
13012                                 -Verify 10 " \
13013            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13014                    sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13015                    min_version=tls12 max_version=tls13 " \
13016            0 \
13017            -c "Protocol is TLSv1.2" \
13018            -c "HTTP/1.0 200 [Oo][Kk]"
13019
13020
13021requires_gnutls_tls1_3
13022requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13023requires_config_enabled MBEDTLS_DEBUG_C
13024requires_config_enabled MBEDTLS_SSL_CLI_C
13025run_test    "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->G" \
13026            "$G_NEXT_SRV_NO_CERT --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key
13027                    -d 4
13028                    --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
13029            "$P_CLI debug_level=4 crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key
13030                    sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13031                    min_version=tls12 max_version=tls13 " \
13032            0 \
13033            -c "Protocol is TLSv1.2" \
13034            -c "HTTP/1.0 200 [Oo][Kk]"
13035
13036requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13037requires_config_enabled MBEDTLS_SSL_SRV_C
13038requires_config_enabled MBEDTLS_SSL_CLI_C
13039requires_config_enabled MBEDTLS_DEBUG_C
13040requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13041                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13042                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13043run_test    "TLS 1.3: NewSessionTicket: servername check, m->m" \
13044            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4 \
13045            sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
13046            "$P_CLI debug_level=4 server_name=localhost reco_mode=1 reconnect=1" \
13047            0 \
13048            -c "Protocol is TLSv1.3" \
13049            -c "got new session ticket." \
13050            -c "Saving session for reuse... ok" \
13051            -c "Reconnecting with saved session" \
13052            -c "HTTP/1.0 200 OK"    \
13053            -s "=> write NewSessionTicket msg" \
13054            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13055            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" \
13056            -s "key exchange mode: ephemeral" \
13057            -s "key exchange mode: psk_ephemeral" \
13058            -s "found pre_shared_key extension"
13059
13060requires_config_enabled MBEDTLS_SSL_SESSION_TICKETS
13061requires_config_enabled MBEDTLS_SSL_SRV_C
13062requires_config_enabled MBEDTLS_SSL_CLI_C
13063requires_config_enabled MBEDTLS_DEBUG_C
13064requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE \
13065                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED \
13066                             MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
13067run_test    "TLS 1.3: NewSessionTicket: servername negative check, m->m" \
13068            "$P_SRV debug_level=4 crt_file=data_files/server5.crt key_file=data_files/server5.key force_version=tls13 tickets=4 \
13069            sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
13070            "$P_CLI debug_level=4 server_name=localhost reco_server_name=remote reco_mode=1 reconnect=1" \
13071            1 \
13072            -c "Protocol is TLSv1.3" \
13073            -c "got new session ticket." \
13074            -c "Saving session for reuse... ok" \
13075            -c "Reconnecting with saved session" \
13076            -c "Hostname mismatch the session ticket, disable session resumption."    \
13077            -s "=> write NewSessionTicket msg" \
13078            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET" \
13079            -s "server state: MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH"
13080
13081# Test heap memory usage after handshake
13082requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13083requires_config_enabled MBEDTLS_MEMORY_DEBUG
13084requires_config_enabled MBEDTLS_MEMORY_BUFFER_ALLOC_C
13085requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
13086requires_max_content_len 16384
13087run_tests_memory_after_hanshake
13088
13089# Final report
13090
13091echo "------------------------------------------------------------------------"
13092
13093if [ $FAILS = 0 ]; then
13094    printf "PASSED"
13095else
13096    printf "FAILED"
13097fi
13098PASSES=$(( $TESTS - $FAILS ))
13099echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
13100
13101exit $FAILS
13102