From 2342e22e370228f6405ae0a77ab53ff06d687de2 Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 09:38:21 -0800 Subject: [PATCH 01/10] Clone Mbed TLS for the compatibility tests, add missing conf functions --- .github/workflows/mbedtls-compat.yml | 7 ------- Makefile | 5 ++--- README.md | 7 ++++--- test/mbedtls_compat/Makefile | 24 ++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.github/workflows/mbedtls-compat.yml b/.github/workflows/mbedtls-compat.yml index 0006f54..4422fe6 100644 --- a/.github/workflows/mbedtls-compat.yml +++ b/.github/workflows/mbedtls-compat.yml @@ -30,13 +30,6 @@ jobs: - name: Clone sibling wolfSSL run: git clone --depth 1 --branch ${{ matrix.wolfssl-ref }} https://github.com/wolfSSL/wolfssl ../wolfssl - # The tests need framework's data files, and tf-psa-crypto's headers for - # the test certificates - - name: Clone sibling Mbed TLS - run: | - git clone --depth 1 --branch mbedtls-4.2.0 https://github.com/Mbed-TLS/mbedtls ../mbedtls - git -C ../mbedtls submodule update --init --depth 1 framework tf-psa-crypto - - name: Build and run the compatibility tests run: make MBEDTLS_COMPAT=1 ${{ matrix.options }} mbedtls-compat-test diff --git a/Makefile b/Makefile index 3ae2e24..43441d4 100644 --- a/Makefile +++ b/Makefile @@ -305,8 +305,7 @@ unit-run: all @$(MAKE) -C test $(UNIT_TESTS) @$(MAKE) run-tests -# Mbed TLS repo, for its test data and sample programs -MBEDTLS_PATH ?= ../mbedtls +# Without MBEDTLS_PATH, test/mbedtls_compat clones Mbed TLS # mbedtls-compat-test runs mbedtls-compat-unit, our own tests of the API, and # mbedtls-compat-programs, Mbed TLS's sample programs with wolfSSL peers. Each @@ -317,7 +316,7 @@ ifeq ($(MBEDTLS_COMPAT),1) $(MBEDTLS_COMPAT_TESTS): mbedtls-compat-%: $(LIBNAME) $(MAKE) -C test/mbedtls_compat WOLFPSA_PATH=$(CURDIR) \ WOLFSSL_PATH=$(abspath $(WOLFSSL_PATH)) \ - MBEDTLS_PATH=$(abspath $(MBEDTLS_PATH)) \ + $(if $(MBEDTLS_PATH),MBEDTLS_PATH=$(abspath $(MBEDTLS_PATH))) \ BUILD_DIR=$(abspath $(BUILD_DIR))/mbedtls_compat \ PSA_CONFIG_DIR=$(abspath $(dir $(PSA_CONFIG))) \ WOLFSSL_FLAGS="-I$(abspath $(WOLFSSL_PATH)) \ diff --git a/README.md b/README.md index 7ef43ed..0034aca 100644 --- a/README.md +++ b/README.md @@ -243,9 +243,10 @@ runs these against `libwolfpsa.a`. Each is also a target of its own. Notes: -- `MBEDTLS_PATH` (default `../mbedtls`) is an Mbed TLS 4.x checkout with - its `framework` and `tf-psa-crypto` submodules, for its test data and - sample programs. +- The tests clone Mbed TLS at `MBEDTLS_REF` (set in + `test/mbedtls_compat/Makefile`) into the build directory, so the first + run needs network access. `MBEDTLS_PATH` uses an Mbed TLS 4.x checkout + with its `framework` and `tf-psa-crypto` submodules instead. - The example server and client come from a wolfSSL configured out of tree from `WOLFSSL_PATH`, which must not be configured in place. The tests use the certificates in its `certs/`. This needs autoconf, automake and diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index 124f638..4256eee 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -23,6 +23,14 @@ LAYER_FLAGS += -DMBEDTLS_THREADING_C LAYER_LIBS += -pthread endif +# Mbed TLS 4.x: MBEDTLS_PATH, or by default a shallow clone of MBEDTLS_REF +MBEDTLS_URL := https://github.com/Mbed-TLS/mbedtls.git +MBEDTLS_REF := ba07f72f934a002021731a2bb5e564e5905f6569 +MBEDTLS_CLONE := $(BUILD_DIR)/mbedtls +MBEDTLS_PATH ?= $(MBEDTLS_CLONE) +# Named with the ref, so a new MBEDTLS_REF clones again +MBEDTLS_STAMP := $(MBEDTLS_CLONE)-$(MBEDTLS_REF) + # Mbed TLS's test data DATA := $(MBEDTLS_PATH)/framework/data_files # Certificate, key and PEM parsing, and TLS return codes and verify results @@ -115,6 +123,22 @@ $(CERTS): $(MBEDTLS_PATH)/tests/src/certs.c $(CERTS_H) $(CC) $(MBEDTLS_FLAGS) $(CPPFLAGS) $(CFLAGS) $(SANITIZE_FLAGS) \ $(WARNFLAGS) -c -o $@ $< +$(MBEDTLS_STAMP): + rm -rf $(MBEDTLS_CLONE) $(MBEDTLS_CLONE)-* + git init -q $(MBEDTLS_CLONE) + git -C $(MBEDTLS_CLONE) fetch -q --depth 1 $(MBEDTLS_URL) $(MBEDTLS_REF) + git -C $(MBEDTLS_CLONE) checkout -q FETCH_HEAD + git -C $(MBEDTLS_CLONE) submodule update -q --init --depth 1 + touch $@ + +ifeq ($(MBEDTLS_PATH),$(MBEDTLS_CLONE)) +$(PROGRAMS) $(CERTS) $(CERTS_H): $(MBEDTLS_STAMP) +data-check: | $(MBEDTLS_STAMP) +# Files from the clone exist once it is made +.PRECIOUS: $(MBEDTLS_CLONE)/% +$(MBEDTLS_CLONE)/%: | $(MBEDTLS_STAMP) ; +endif + # configure refuses a clone that is configured in place. autogen.sh only adds # files git ignores. wolfssl-check: From d7ff095de87befe3f55ed2a8442acb8737d2936e Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 10:14:01 -0800 Subject: [PATCH 02/10] Add defines in header files --- wolfpsa/mbedtls/platform_util.h | 32 ++++++++ wolfpsa/mbedtls/private_access.h | 34 +++++++++ wolfpsa/mbedtls/threading.h | 1 + wolfpsa/mbedtls_compat/mbedtls/build_info.h | 17 ++++- wolfpsa/mbedtls_compat/mbedtls/error.h | 4 + wolfpsa/mbedtls_compat/mbedtls/ssl.h | 75 +++++++++++++++++++ .../mbedtls_compat/mbedtls/ssl_ciphersuites.h | 11 +++ wolfpsa/tf-psa-crypto/build_info.h | 49 ++++++++++++ 8 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 wolfpsa/mbedtls/private_access.h diff --git a/wolfpsa/mbedtls/platform_util.h b/wolfpsa/mbedtls/platform_util.h index b2a485f..12303af 100644 --- a/wolfpsa/mbedtls/platform_util.h +++ b/wolfpsa/mbedtls/platform_util.h @@ -26,6 +26,38 @@ #include +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) + #define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else + #define MBEDTLS_DEPRECATED +#endif /* MBEDTLS_DEPRECATED_WARNING */ +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ + +#if !defined(MBEDTLS_CHECK_RETURN) +#if defined(__GNUC__) + #define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__)) +#elif defined(_MSC_VER) && _MSC_VER >= 1700 + #include + #define MBEDTLS_CHECK_RETURN _Check_return_ +#else + #define MBEDTLS_CHECK_RETURN +#endif /* __GNUC__ */ +#endif /* !MBEDTLS_CHECK_RETURN */ + +#define MBEDTLS_CHECK_RETURN_CRITICAL MBEDTLS_CHECK_RETURN +#if defined(MBEDTLS_CHECK_RETURN_WARNING) + #define MBEDTLS_CHECK_RETURN_TYPICAL MBEDTLS_CHECK_RETURN +#else + #define MBEDTLS_CHECK_RETURN_TYPICAL +#endif /* MBEDTLS_CHECK_RETURN_WARNING */ +#define MBEDTLS_CHECK_RETURN_OPTIONAL + +/* (void) alone does not silence GCC's warn_unused_result */ +#if !defined(MBEDTLS_IGNORE_RETURN) + #define MBEDTLS_IGNORE_RETURN(result) ((void)!(result)) +#endif /* !MBEDTLS_IGNORE_RETURN */ + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ diff --git a/wolfpsa/mbedtls/private_access.h b/wolfpsa/mbedtls/private_access.h new file mode 100644 index 0000000..f6fee59 --- /dev/null +++ b/wolfpsa/mbedtls/private_access.h @@ -0,0 +1,34 @@ +/* private_access.h + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* For code that marks private struct members, such as Mbed TLS's tests */ + +#ifndef MBEDTLS_PRIVATE_ACCESS_H +#define MBEDTLS_PRIVATE_ACCESS_H + +#if defined(MBEDTLS_ALLOW_PRIVATE_ACCESS) + #define MBEDTLS_PRIVATE(member) member + #define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS +#else + #define MBEDTLS_PRIVATE(member) private_##member +#endif /* MBEDTLS_ALLOW_PRIVATE_ACCESS */ + +#endif /* MBEDTLS_PRIVATE_ACCESS_H */ diff --git a/wolfpsa/mbedtls/threading.h b/wolfpsa/mbedtls/threading.h index 6815411..6992bc5 100644 --- a/wolfpsa/mbedtls/threading.h +++ b/wolfpsa/mbedtls/threading.h @@ -25,6 +25,7 @@ #ifndef MBEDTLS_THREADING_H #define MBEDTLS_THREADING_H +#include "mbedtls/private_access.h" #include "tf-psa-crypto/build_info.h" #if defined(MBEDTLS_THREADING_PTHREAD) diff --git a/wolfpsa/mbedtls_compat/mbedtls/build_info.h b/wolfpsa/mbedtls_compat/mbedtls/build_info.h index bdc3f49..57f3f9c 100644 --- a/wolfpsa/mbedtls_compat/mbedtls/build_info.h +++ b/wolfpsa/mbedtls_compat/mbedtls/build_info.h @@ -35,8 +35,21 @@ #define MBEDTLS_VERSION_STRING "4.2.0" #define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 4.2.0" -/* MBEDTLS_X509_CRT_PARSE_C is in the generated config, with - * MBEDTLS_COMPAT=1 */ +/* MBEDTLS_X509_CRT_PARSE_C and MBEDTLS_SSL_* are in the generated config */ +#if defined(MBEDTLS_X509_CRT_PARSE_C) + #define MBEDTLS_X509_USE_C +#endif /* MBEDTLS_X509_CRT_PARSE_C */ +#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(PSA_WANT_ALG_ECDH) + #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && PSA_WANT_ALG_ECDH */ +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && defined(PSA_WANT_ALG_ECDH) +#if defined(PSA_HAVE_ALG_RSA_PKCS1V15_SIGN) + #define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED +#endif /* PSA_HAVE_ALG_RSA_PKCS1V15_SIGN */ +#if defined(PSA_HAVE_ALG_ECDSA_SIGN) + #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +#endif /* PSA_HAVE_ALG_ECDSA_SIGN */ +#endif /* MBEDTLS_SSL_PROTO_TLS1_2 && PSA_WANT_ALG_ECDH */ /* No mbedtls_x509_crt_info() and friends yet */ #ifndef MBEDTLS_X509_REMOVE_INFO #define MBEDTLS_X509_REMOVE_INFO diff --git a/wolfpsa/mbedtls_compat/mbedtls/error.h b/wolfpsa/mbedtls_compat/mbedtls/error.h index b1f33ba..27dc6b2 100644 --- a/wolfpsa/mbedtls_compat/mbedtls/error.h +++ b/wolfpsa/mbedtls_compat/mbedtls/error.h @@ -25,5 +25,9 @@ #define MBEDTLS_ERROR_H #include "mbedtls/build_info.h" +#include "psa/crypto.h" + +#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED PSA_ERROR_HARDWARE_FAILURE +#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED PSA_ERROR_CORRUPTION_DETECTED #endif /* MBEDTLS_ERROR_H */ diff --git a/wolfpsa/mbedtls_compat/mbedtls/ssl.h b/wolfpsa/mbedtls_compat/mbedtls/ssl.h index 102ca38..5becfd6 100644 --- a/wolfpsa/mbedtls_compat/mbedtls/ssl.h +++ b/wolfpsa/mbedtls_compat/mbedtls/ssl.h @@ -23,6 +23,7 @@ #define MBEDTLS_SSL_H #include "mbedtls/build_info.h" +#include "mbedtls/platform_util.h" #include "mbedtls/ssl_ciphersuites.h" #include "mbedtls/x509_crt.h" /* From wolfPSA, as Mbed TLS takes it from TF-PSA-Crypto */ @@ -46,13 +47,52 @@ #define MBEDTLS_SSL_VERIFY_NONE 0 #define MBEDTLS_SSL_VERIFY_REQUIRED 2 #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 +#define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 +#define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 +#define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 +#define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 +#define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 +#define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 +#define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0 +#define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1 +#define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2 +#define MBEDTLS_SSL_EARLY_DATA_DISABLED 0 +#define MBEDTLS_SSL_EARLY_DATA_ENABLED 1 + +#define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20 +#define MBEDTLS_SSL_MSG_ALERT 21 +#define MBEDTLS_SSL_MSG_HANDSHAKE 22 +#define MBEDTLS_SSL_MSG_APPLICATION_DATA 23 +#define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1 +#define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2 +#define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 + +/* IANA TLS NamedGroup values */ +#define MBEDTLS_SSL_IANA_TLS_GROUP_NONE 0 +#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 0x0016 +#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 0x0017 +#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 0x0018 +#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1 0x0019 +#define MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1 0x001A +#define MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1 0x001B +#define MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1 0x001C +#define MBEDTLS_SSL_IANA_TLS_GROUP_X25519 0x001D +#define MBEDTLS_SSL_IANA_TLS_GROUP_X448 0x001E +#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048 0x0100 +#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072 0x0101 +#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096 0x0102 +#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144 0x0103 +#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192 0x0104 #define MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME -0x5D80 #define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 +#define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00 #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 #define MBEDTLS_ERR_SSL_WANT_READ -0x6900 #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 +#define MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE -0x6E00 +#define MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION -0x6E80 #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 @@ -61,6 +101,7 @@ #define MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET -0x7B00 #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA PSA_ERROR_INVALID_ARGUMENT +#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL PSA_ERROR_BUFFER_TOO_SMALL #define MBEDTLS_ERR_SSL_ALLOC_FAILED PSA_ERROR_INSUFFICIENT_MEMORY typedef enum { @@ -69,6 +110,40 @@ typedef enum { MBEDTLS_SSL_VERSION_TLS1_3 = 0x0304 } mbedtls_ssl_protocol_version; +/* Handshake states, in Mbed TLS's order */ +typedef enum { + MBEDTLS_SSL_HELLO_REQUEST, + MBEDTLS_SSL_CLIENT_HELLO, + MBEDTLS_SSL_SERVER_HELLO, + MBEDTLS_SSL_SERVER_CERTIFICATE, + MBEDTLS_SSL_SERVER_KEY_EXCHANGE, + MBEDTLS_SSL_CERTIFICATE_REQUEST, + MBEDTLS_SSL_SERVER_HELLO_DONE, + MBEDTLS_SSL_CLIENT_CERTIFICATE, + MBEDTLS_SSL_CLIENT_KEY_EXCHANGE, + MBEDTLS_SSL_CERTIFICATE_VERIFY, + MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC, + MBEDTLS_SSL_CLIENT_FINISHED, + MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC, + MBEDTLS_SSL_SERVER_FINISHED, + MBEDTLS_SSL_FLUSH_BUFFERS, + MBEDTLS_SSL_HANDSHAKE_WRAPUP, + MBEDTLS_SSL_NEW_SESSION_TICKET, + MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT, + MBEDTLS_SSL_HELLO_RETRY_REQUEST, + MBEDTLS_SSL_ENCRYPTED_EXTENSIONS, + MBEDTLS_SSL_END_OF_EARLY_DATA, + MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY, + MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED, + MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO, + MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO, + MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO, + MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST, + MBEDTLS_SSL_HANDSHAKE_OVER, + MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET, + MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH +} mbedtls_ssl_states; + /* wolfSSL objects, opaque to the application */ struct WOLFSSL_CTX; struct WOLFSSL; diff --git a/wolfpsa/mbedtls_compat/mbedtls/ssl_ciphersuites.h b/wolfpsa/mbedtls_compat/mbedtls/ssl_ciphersuites.h index c0fd067..ac79f42 100644 --- a/wolfpsa/mbedtls_compat/mbedtls/ssl_ciphersuites.h +++ b/wolfpsa/mbedtls_compat/mbedtls/ssl_ciphersuites.h @@ -50,4 +50,15 @@ #define MBEDTLS_TLS1_3_AES_128_CCM_SHA256 0x1304 #define MBEDTLS_TLS1_3_AES_128_CCM_8_SHA256 0x1305 +#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \ + defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) + #define MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED +#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED || + * MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */ +#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) || \ + defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED) + #define MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED +#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED || + * MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED */ + #endif /* MBEDTLS_SSL_CIPHERSUITES_H */ diff --git a/wolfpsa/tf-psa-crypto/build_info.h b/wolfpsa/tf-psa-crypto/build_info.h index 2f01839..c366a04 100644 --- a/wolfpsa/tf-psa-crypto/build_info.h +++ b/wolfpsa/tf-psa-crypto/build_info.h @@ -28,6 +28,14 @@ #include "psa/crypto_config.h" +/* The TF-PSA-Crypto API version wolfPSA follows, from Mbed TLS 4.2.0 */ +#define TF_PSA_CRYPTO_VERSION_MAJOR 1 +#define TF_PSA_CRYPTO_VERSION_MINOR 2 +#define TF_PSA_CRYPTO_VERSION_PATCH 0 +#define TF_PSA_CRYPTO_VERSION_NUMBER 0x01020000 +#define TF_PSA_CRYPTO_VERSION_STRING "1.2.0" +#define TF_PSA_CRYPTO_VERSION_STRING_FULL "TF-PSA-Crypto 1.2.0" + #define MBEDTLS_PSA_CRYPTO_C #define MBEDTLS_PSA_CRYPTO_CLIENT /* MBEDTLS_ENTROPY_C and MBEDTLS_CTR_DRBG_C come from crypto_config.h */ @@ -57,6 +65,47 @@ #define MBEDTLS_CIPHER_MODE_CTR #endif /* PSA_WANT_ALG_CTR */ +/* Signature algorithms with the key types they need */ +#if defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA) + #define PSA_HAVE_ALG_SOME_ECDSA +#endif /* PSA_WANT_ALG_ECDSA || PSA_WANT_ALG_DETERMINISTIC_ECDSA */ +#if defined(PSA_HAVE_ALG_SOME_ECDSA) && \ + defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC) + #define PSA_HAVE_ALG_ECDSA_SIGN +#endif /* PSA_HAVE_ALG_SOME_ECDSA && PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC */ +#if defined(PSA_HAVE_ALG_SOME_ECDSA) && \ + defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) + #define PSA_HAVE_ALG_ECDSA_VERIFY +#endif /* PSA_HAVE_ALG_SOME_ECDSA && PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */ +#if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN) && \ + defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) + #define PSA_HAVE_ALG_RSA_PKCS1V15_SIGN +#endif /* PSA_WANT_ALG_RSA_PKCS1V15_SIGN && + * PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */ +#if defined(PSA_WANT_ALG_RSA_PSS) && \ + defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) + #define PSA_HAVE_ALG_RSA_PSS_SIGN +#endif /* PSA_WANT_ALG_RSA_PSS && PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */ +#if defined(PSA_HAVE_ALG_RSA_PKCS1V15_SIGN) || \ + defined(PSA_HAVE_ALG_RSA_PSS_SIGN) + #define PSA_HAVE_ALG_SOME_RSA_SIGN +#endif /* PSA_HAVE_ALG_RSA_PKCS1V15_SIGN || PSA_HAVE_ALG_RSA_PSS_SIGN */ +#if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN) && \ + defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) + #define PSA_HAVE_ALG_RSA_PKCS1V15_VERIFY +#endif /* PSA_WANT_ALG_RSA_PKCS1V15_SIGN && PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */ +#if defined(PSA_WANT_ALG_RSA_PSS) && defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) + #define PSA_HAVE_ALG_RSA_PSS_VERIFY +#endif /* PSA_WANT_ALG_RSA_PSS && PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */ +#if defined(PSA_HAVE_ALG_RSA_PKCS1V15_VERIFY) || \ + defined(PSA_HAVE_ALG_RSA_PSS_VERIFY) + #define PSA_HAVE_ALG_SOME_RSA_VERIFY +#endif /* PSA_HAVE_ALG_RSA_PKCS1V15_VERIFY || PSA_HAVE_ALG_RSA_PSS_VERIFY */ +#if defined(PSA_HAVE_ALG_SOME_RSA_SIGN) || \ + defined(PSA_HAVE_ALG_SOME_RSA_VERIFY) + #define PSA_HAVE_ALG_SOME_RSA_SIGN_OR_VERIFY +#endif /* PSA_HAVE_ALG_SOME_RSA_SIGN || PSA_HAVE_ALG_SOME_RSA_VERIFY */ + /* pthreads, the one implementation of MBEDTLS_THREADING_C */ #if defined(MBEDTLS_THREADING_C) && !defined(MBEDTLS_THREADING_PTHREAD) && \ !defined(__ZEPHYR__) From 405732920a947cb9acd9eaf5cad8f16381daf5ed Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 11:39:01 -0800 Subject: [PATCH 03/10] Add Mbed TLS ssl suite harness, run from mbedtls-compat-test --- Makefile | 32 +- test/mbedtls_compat/Makefile | 85 ++++- test/mbedtls_compat/ssl_suite/cases.txt | 258 ++++++++++++++ test/mbedtls_compat/ssl_suite/check.py | 76 ++++ test/mbedtls_compat/ssl_suite/mbedtls.patch | 336 ++++++++++++++++++ test/mbedtls_compat/ssl_suite/select.py | 105 ++++++ .../ssl_suite/shim/mbedtls/private/ctr_drbg.h | 22 ++ .../ssl_suite/shim/mbedtls/private/entropy.h | 31 ++ .../shim/mbedtls/private/error_common.h | 24 ++ .../shim/mbedtls/private/pk_private.h | 32 ++ .../ssl_suite/shim/psa_crypto_helpers.c | 31 ++ .../ssl_suite/shim/threading_internal.h | 29 ++ .../ssl_suite/ssl_helpers_port.c | 65 ++++ .../ssl_suite/ssl_helpers_port.h | 36 ++ 14 files changed, 1144 insertions(+), 18 deletions(-) create mode 100644 test/mbedtls_compat/ssl_suite/cases.txt create mode 100644 test/mbedtls_compat/ssl_suite/check.py create mode 100644 test/mbedtls_compat/ssl_suite/mbedtls.patch create mode 100644 test/mbedtls_compat/ssl_suite/select.py create mode 100644 test/mbedtls_compat/ssl_suite/shim/mbedtls/private/ctr_drbg.h create mode 100644 test/mbedtls_compat/ssl_suite/shim/mbedtls/private/entropy.h create mode 100644 test/mbedtls_compat/ssl_suite/shim/mbedtls/private/error_common.h create mode 100644 test/mbedtls_compat/ssl_suite/shim/mbedtls/private/pk_private.h create mode 100644 test/mbedtls_compat/ssl_suite/shim/psa_crypto_helpers.c create mode 100644 test/mbedtls_compat/ssl_suite/shim/threading_internal.h create mode 100644 test/mbedtls_compat/ssl_suite/ssl_helpers_port.c create mode 100644 test/mbedtls_compat/ssl_suite/ssl_helpers_port.h diff --git a/Makefile b/Makefile index 43441d4..21a3f92 100644 --- a/Makefile +++ b/Makefile @@ -306,24 +306,26 @@ unit-run: all @$(MAKE) run-tests # Without MBEDTLS_PATH, test/mbedtls_compat clones Mbed TLS - -# mbedtls-compat-test runs mbedtls-compat-unit, our own tests of the API, and -# mbedtls-compat-programs, Mbed TLS's sample programs with wolfSSL peers. Each -# runs the target of the same name in test/mbedtls_compat. -MBEDTLS_COMPAT_TESTS := $(addprefix mbedtls-compat-,test unit programs) -.PHONY: $(MBEDTLS_COMPAT_TESTS) +MBEDTLS_COMPAT_MAKE = $(MAKE) -C test/mbedtls_compat WOLFPSA_PATH=$(CURDIR) \ + WOLFSSL_PATH=$(abspath $(WOLFSSL_PATH)) \ + $(if $(MBEDTLS_PATH),MBEDTLS_PATH=$(abspath $(MBEDTLS_PATH))) \ + BUILD_DIR=$(abspath $(BUILD_DIR))/mbedtls_compat \ + PSA_CONFIG_DIR=$(abspath $(dir $(PSA_CONFIG))) \ + WOLFSSL_FLAGS="-I$(abspath $(WOLFSSL_PATH)) \ + -I$(abspath $(USER_SETTINGS_PATH)) $(WOLFSSL_CPPFLAGS)" \ + SANITIZE_FLAGS="$(SANITIZE_FLAGS)" WOLFPSA_LDFLAGS="$(LDFLAGS)" + +# mbedtls-compat- runs in test/mbedtls_compat +MBEDTLS_COMPAT_TESTS := $(addprefix mbedtls-compat-,test unit programs suite) +.PHONY: $(MBEDTLS_COMPAT_TESTS) mbedtls-compat-suite-patch ifeq ($(MBEDTLS_COMPAT),1) $(MBEDTLS_COMPAT_TESTS): mbedtls-compat-%: $(LIBNAME) - $(MAKE) -C test/mbedtls_compat WOLFPSA_PATH=$(CURDIR) \ - WOLFSSL_PATH=$(abspath $(WOLFSSL_PATH)) \ - $(if $(MBEDTLS_PATH),MBEDTLS_PATH=$(abspath $(MBEDTLS_PATH))) \ - BUILD_DIR=$(abspath $(BUILD_DIR))/mbedtls_compat \ - PSA_CONFIG_DIR=$(abspath $(dir $(PSA_CONFIG))) \ - WOLFSSL_FLAGS="-I$(abspath $(WOLFSSL_PATH)) \ - -I$(abspath $(USER_SETTINGS_PATH)) $(WOLFSSL_CPPFLAGS)" \ - SANITIZE_FLAGS="$(SANITIZE_FLAGS)" WOLFPSA_LDFLAGS="$(LDFLAGS)" $* + $(MBEDTLS_COMPAT_MAKE) $* + +mbedtls-compat-suite-patch: + $(MBEDTLS_COMPAT_MAKE) suite-patch else -$(MBEDTLS_COMPAT_TESTS): +$(MBEDTLS_COMPAT_TESTS) mbedtls-compat-suite-patch: @echo "Run make MBEDTLS_COMPAT=1 $@"; exit 1 endif diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index 4256eee..e0cc4ab 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -66,6 +66,26 @@ MBEDTLS_FLAGS := -I$(BUILD_DIR)/include -I$(MBEDTLS_PATH)/include \ $(addprefix -I$(MBEDTLS_PATH)/tf-psa-crypto/,include core \ drivers/builtin/include) +# Mbed TLS's ssl suite: the cases in cases.txt, on the clone and its patch +SUITE := $(CURDIR)/ssl_suite +SUITE_BUILD := $(BUILD_DIR)/ssl_suite +SUITE_PATCHED := $(MBEDTLS_CLONE)-patched +SUITE_NAME := $(SUITE_BUILD)/test_suite_ssl_public +SUITE_OUTCOME := $(SUITE_BUILD)/outcome.csv +SUITE_LOG := $(SUITE_BUILD)/test_suite_ssl_public.log +SUITE_HELPERS := $(addprefix $(SUITE_BUILD)/,helpers.o random.o \ + threading_helpers.o test_memory.o) +SUITE_OBJS := $(SUITE_NAME).o $(SUITE_BUILD)/ssl_helpers.o \ + $(SUITE_BUILD)/ssl_helpers_port.o $(SUITE_BUILD)/psa_crypto_helpers.o \ + $(SUITE_HELPERS) +SUITE_TEMPLATES := $(MBEDTLS_CLONE)/tf-psa-crypto/tests/suites +# wolfPSA's headers first; Mbed TLS's public headers are not on the path +SUITE_FLAGS := $(LAYER_FLAGS) -I$(SUITE) -I$(SUITE)/shim \ + $(addprefix -I$(MBEDTLS_CLONE)/,framework/tests/include tests/include \ + tf-psa-crypto/tests/include framework/tests/src) \ + -idirafter $(MBEDTLS_CLONE)/tf-psa-crypto/core +SUITE_PUBLIC_HEADERS := $(MBEDTLS_CLONE)/(tf-psa-crypto/)?include/ + # $(call link,flags,libraries) links the C source and objects among the # prerequisites link = $(CC) $(1) $(CPPFLAGS) $(CFLAGS) $(SANITIZE_FLAGS) $(WARNFLAGS) \ @@ -78,9 +98,9 @@ export BUILD_DIR WOLFSSL_PATH WOLFSSL_SERVER WOLFSSL_CLIENT MBEDTLS_PATH \ ASAN_LINK_ORDER := verify_asan_link_order=0 export ASAN_OPTIONS := $(if $(ASAN_OPTIONS),$(ASAN_OPTIONS):)$(ASAN_LINK_ORDER) -.PHONY: test unit programs data-check wolfssl-check FORCE +.PHONY: test unit programs suite suite-patch data-check wolfssl-check FORCE -test: unit programs +test: unit programs suite unit: $(UNIT) | data-check @fails=0; for t in $(UNIT); do \ @@ -92,6 +112,25 @@ programs: $(CLIENT) $(PROGRAMS) $(WOLFSSL_SERVER) $(WOLFSSL_CLIENT) | \ data-check ./programs.sh +# check.py compares each case with cases.txt, not the suite's exit code +suite: $(SUITE_NAME) + @rm -f $(SUITE_OUTCOME) + cd $(MBEDTLS_CLONE)/tests && \ + MBEDTLS_TEST_OUTCOME_FILE=$(SUITE_OUTCOME) $(WRAP) $< \ + $<.datax > $(SUITE_LOG) 2>&1 || true + @echo "Mbed TLS ssl suite, $(MBEDTLS_REF)" + @python3 $(SUITE)/check.py $(SUITE)/cases.txt $(SUITE_OUTCOME) || \ + { echo "Log: $(SUITE_LOG)"; exit 1; } + +# Saves the clone's changes to mbedtls.patch, below its license lines +suite-patch: + @mkdir -p $(SUITE_BUILD) + { sed '/^diff --git/,$$d' $(SUITE)/mbedtls.patch; \ + git -C $(MBEDTLS_CLONE) -c diff.suppressBlankEmpty=true \ + diff --no-ext-diff; } > $(SUITE_BUILD)/mbedtls.patch + mv $(SUITE_BUILD)/mbedtls.patch $(SUITE)/mbedtls.patch + touch $(SUITE_PATCHED) + data-check: @if [ ! -f $(DATA)/server5.crt ]; then \ echo "$(DATA) not found, run git submodule update --init" \ @@ -134,10 +173,50 @@ $(MBEDTLS_STAMP): ifeq ($(MBEDTLS_PATH),$(MBEDTLS_CLONE)) $(PROGRAMS) $(CERTS) $(CERTS_H): $(MBEDTLS_STAMP) data-check: | $(MBEDTLS_STAMP) +endif # Files from the clone exist once it is made .PRECIOUS: $(MBEDTLS_CLONE)/% $(MBEDTLS_CLONE)/%: | $(MBEDTLS_STAMP) ; -endif + +# A newer patch resets the clone, dropping edits made there +$(SUITE_PATCHED): $(SUITE)/mbedtls.patch $(MBEDTLS_STAMP) + git -C $(MBEDTLS_CLONE) reset -q --hard + git -C $(MBEDTLS_CLONE) apply $< + touch $@ + +# One recipe writes the .c and the .datax +$(SUITE_NAME).datax: $(SUITE_NAME).c ; +$(SUITE_NAME).c: $(SUITE)/select.py $(SUITE)/cases.txt $(SUITE_PATCHED) + @mkdir -p $(@D) + python3 $< $(SUITE)/cases.txt $(MBEDTLS_CLONE)/tests/suites $(@D) + python3 $(MBEDTLS_CLONE)/framework/scripts/generate_test_code.py \ + -f $(SUITE_NAME).function -d $(SUITE_NAME).data \ + -t $(SUITE_TEMPLATES)/main_test.function \ + -p $(SUITE_TEMPLATES)/host_test.function -s $(SUITE_TEMPLATES) \ + --helpers-file $(SUITE_TEMPLATES)/helpers.function -o $(@D) + +$(SUITE_HELPERS): $(SUITE_BUILD)/%.o: $(MBEDTLS_CLONE)/framework/tests/src/%.c +$(SUITE_BUILD)/ssl_helpers.o: \ + $(MBEDTLS_CLONE)/tests/src/test_helpers/ssl_helpers.c +$(SUITE_BUILD)/ssl_helpers_port.o: $(SUITE)/ssl_helpers_port.c +$(SUITE_BUILD)/psa_crypto_helpers.o: $(SUITE)/shim/psa_crypto_helpers.c +$(SUITE_NAME).o: $(SUITE_NAME).c +# The header's static functions include some for cases left out +$(SUITE_NAME).o: WARNFLAGS += -Wno-unused-function +$(SUITE_OBJS): $(SUITE_PATCHED) + @mkdir -p $(@D) + $(CC) $(SUITE_FLAGS) $(CPPFLAGS) $(CFLAGS) $(SANITIZE_FLAGS) \ + $(WARNFLAGS) -MD -MP -c -o $@ $(filter %.c,$^) + @if grep -q -E '$(SUITE_PUBLIC_HEADERS)' $(@:.o=.d); then \ + grep -o -E '$(SUITE_PUBLIC_HEADERS)[^ :]*' $(@:.o=.d) | \ + sort -u; \ + echo "$@: uses Mbed TLS's public headers"; rm $@; exit 1; \ + fi + +$(SUITE_NAME): $(SUITE_OBJS) $(CERTS) $(WOLFPSA_LIB) $(SUITE_NAME).datax + $(call link,,$(LAYER_LIBS)) + +-include $(SUITE_OBJS:.o=.d) # configure refuses a clone that is configured in place. autogen.sh only adds # files git ignores. diff --git a/test/mbedtls_compat/ssl_suite/cases.txt b/test/mbedtls_compat/ssl_suite/cases.txt new file mode 100644 index 0000000..46a868e --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/cases.txt @@ -0,0 +1,258 @@ +# Mbed TLS ssl suite cases run against libwolfpsa.a, by their description in +# test_suite_ssl.data or test_suite_ssl.tls-defrag.data. select.py fails when +# a case of a test function used here is missing. +# +# Group: target and api use the public API, target through the test +# helpers; mock tests the helpers' mock transport. +# +# Expect: pass must PASS. fail must FAIL or SKIP: mark it pass once it +# passes. notrun is left out of the run. +# +# Waits on, for fail: +# port the ssl_helpers.c port +# pss MBEDTLS_X509_RSASSA_PSS_SUPPORT +# session mbedtls_ssl_session_save and _load +# ticket session tickets, then session save and load +# exporter mbedtls_ssl_export_keying_material +# dtls DTLS +# mfl max fragment length +# psk PSK +# opaque opaque keys +# renegotiation DTLS renegotiation +# context mbedtls_ssl_context_save and _load, DTLS +# defaults a config without mbedtls_ssl_config_defaults +# timing MBEDTLS_TIMING_C +# cid DTLS connection ID +# Why, for notrun: +# ccm TLS-ECDHE-ECDSA-WITH-AES-256-CCM: not in wolfSSL +# internal sets or reads Mbed TLS internals +# tls12-off needs TLS 1.2 or 1.3 off: Mbed TLS's default build skips +# tls13-off it too +# get_hostname calls mbedtls_ssl_, which wolfPSA does not have, so +# tls_prf its test function is not built +# group_list +# +# Columns: group, expect, waits on or why, description +api fail psk Attempt to register multiple PSKs +api fail psk Attempt to register multiple PSKS, incl. opaque PSK, #0 +api fail psk Attempt to register multiple PSKs, incl. opaque PSK, #1 +api fail psk Attempt to register multiple PSKs, incl. opaque PSK, #2 +mock pass - Test callback buffer sanity +mock pass - Callback buffer test: Exercise simple write/read +mock pass - Callback buffer test: Filling up the buffer +mock pass - Callback buffer test: Filling up the buffer in two steps +mock pass - Callback buffer test: Reading out the buffer in two steps +mock pass - Callback buffer test: Data wraps in buffer +mock pass - Callback buffer test: Data starts at the end +mock pass - Callback buffer test: Can write less than requested +mock pass - Callback buffer test: Can read less than requested +mock pass - Callback buffer test: Writing to full buffer +mock pass - Callback buffer test: Reading from empty buffer +mock pass - Test mock socket sanity +mock pass - Test mock blocking TCP connection +mock pass - Test mock non-blocking TCP connection +mock pass - Test mock blocking TCP connection (interleaving) +mock pass - Test mock non-blocking TCP connection (interleaving) +mock pass - Message queue - sanity +mock pass - Message queue - basic test +mock pass - Message queue - overflow/underflow +mock pass - Message queue - interleaved +mock pass - Message queue - insufficient buffer +mock pass - Message transport mock - uninitialized structures +mock pass - Message transport mock - basic test +mock pass - Message transport mock - queue overflow/underflow +mock pass - Message transport mock - socket overflow +mock pass - Message transport mock - truncated message +mock pass - Message transport mock - socket read error +mock pass - Message transport mock - one-way interleaved sends/reads +mock pass - Message transport mock - two-way interleaved sends/reads +target fail port Test mbedtls_endpoint sanity for the client +target fail port Test mbedtls_endpoint sanity for the server +target fail port Handshake, tls1_2 +target fail pss Handshake, tls1_3 +target fail port Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 +target fail port Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 +target fail port Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 +target notrun ccm Handshake, ECDHE-ECDSA-WITH-AES-256-CCM +target fail psk Handshake, PSK-WITH-AES-128-CBC-SHA +target fail psk DTLS Handshake, PSK-WITH-AES-128-CBC-SHA +target fail dtls DTLS Handshake, tls1_2 +target fail dtls DTLS Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 +target fail dtls DTLS Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 +target fail dtls DTLS Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 +target notrun ccm DTLS Handshake, ECDHE-ECDSA-WITH-AES-256-CCM +target fail context DTLS Handshake with serialization, tls1_2 +target fail dtls DTLS Handshake fragmentation, MFL=512 +target fail dtls DTLS Handshake fragmentation, MFL=1024 +target notrun tls13-off Handshake min/max version check, all -> 1.2 +target fail pss Handshake min/max version check, all -> 1.3 +target fail port Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, non-opaque +target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_ANY_HASH +target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_SHA_384 +target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, invalid alg +target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, bad alg +target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, bad usage +target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, non-opaque +target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, PSA_ALG_ANY_HASH +target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, PSA_ALG_SHA_256 +target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, bad alg +target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, bad usage +target notrun internal Handshake: DTLS 1.2, badmac_seen on client +target notrun internal Handshake: DTLS 1.2, badmac_seen on server +target fail mfl Sending app data via TLS, MFL=512 without fragmentation +target fail mfl Sending app data via TLS, MFL=512 with fragmentation +target fail mfl Sending app data via TLS, MFL=1024 without fragmentation +target fail mfl Sending app data via TLS, MFL=1024 with fragmentation +target fail mfl Sending app data via TLS, MFL=2048 without fragmentation +target fail mfl Sending app data via TLS, MFL=2048 with fragmentation +target fail mfl Sending app data via TLS, MFL=4096 without fragmentation +target fail mfl Sending app data via TLS, MFL=4096 with fragmentation +target fail port Sending app data via TLS without MFL and without fragmentation +target fail port Sending app data via TLS without MFL and with fragmentation +target fail dtls Sending app data via DTLS, MFL=512 without fragmentation +target fail dtls Sending app data via DTLS, MFL=512 with fragmentation +target fail dtls Sending app data via DTLS, MFL=1024 without fragmentation +target fail dtls Sending app data via DTLS, MFL=1024 with fragmentation +target fail dtls Sending app data via DTLS, MFL=2048 without fragmentation +target fail dtls Sending app data via DTLS, MFL=2048 with fragmentation +target fail dtls Sending app data via DTLS, MFL=4096 without fragmentation +target fail dtls Sending app data via DTLS, MFL=4096 with fragmentation +target fail dtls Sending app data via DTLS, without MFL and without fragmentation +target fail dtls Sending app data via DTLS, without MFL and with fragmentation +target fail renegotiation DTLS renegotiation: no legacy renegotiation +target fail renegotiation DTLS renegotiation: legacy renegotiation +target fail renegotiation DTLS renegotiation: legacy break handshake +target notrun internal DTLS renegotiation: after bad MAC on client +target notrun internal DTLS renegotiation: after bad MAC on server +api notrun get_hostname SSL SET_HOSTNAME memory leak: call ssl_set_hostname twice +target fail session SSL session serialization: Wrong major version +target fail session SSL session serialization: Wrong minor version +target fail session SSL session serialization: Wrong patch version +target fail session SSL session serialization: Wrong config +target fail ticket TLS 1.3: CLI: session serialization: Wrong major version +target fail ticket TLS 1.3: CLI: session serialization: Wrong minor version +target fail ticket TLS 1.3: CLI: session serialization: Wrong patch version +target fail ticket TLS 1.3: CLI: session serialization: Wrong config +target fail ticket TLS 1.3: SRV: session serialization: Wrong major version +target fail ticket TLS 1.3: SRV: session serialization: Wrong minor version +target fail ticket TLS 1.3: SRV: session serialization: Wrong patch version +target fail ticket TLS 1.3: SRV: session serialization: Wrong config +api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_NONE +api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA384 +api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA256 +api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA384 SHA-384 not enabled +api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA256 SHA-256 not enabled +target fail session Session serialization, load-save: no ticket, no cert +target fail ticket Session serialization, load-save: small ticket, no cert +target fail ticket Session serialization, load-save: large ticket, no cert +target fail session Session serialization, load-save: no ticket, cert +target fail ticket Session serialization, load-save: small ticket, cert +target fail ticket Session serialization, load-save: large ticket, cert +target fail ticket TLS 1.3: CLI: Session serialization, load-save: no ticket +target fail ticket TLS 1.3: CLI: Session serialization, load-save: small ticket +target fail ticket TLS 1.3: CLI: Session serialization, load-save: large ticket +target fail ticket TLS 1.3: SRV: Session serialization, load-save +target fail session Session serialization, save buffer size: no ticket, no cert +target fail ticket Session serialization, save buffer size: small ticket, no cert +target fail ticket Session serialization, save buffer size: large ticket, no cert +target fail session Session serialization, save buffer size: no ticket, cert +target fail ticket Session serialization, save buffer size: small ticket, cert +target fail ticket Session serialization, save buffer size: large ticket, cert +target fail ticket TLS 1.3: CLI: Session serialization, save buffer size: no ticket +target fail ticket TLS 1.3: CLI: Session serialization, save buffer size: small ticket +target fail ticket TLS 1.3: CLI: Session serialization, save buffer size: large ticket +target fail ticket TLS 1.3: SRV: Session serialization, save buffer size +target fail session Session serialization, load buffer size: no ticket, no cert +target fail ticket Session serialization, load buffer size: small ticket, no cert +target fail ticket Session serialization, load buffer size: large ticket, no cert +target fail session Session serialization, load buffer size: no ticket, cert +target fail ticket Session serialization, load buffer size: small ticket, cert +target fail ticket Session serialization, load buffer size: large ticket, cert +target fail ticket TLS 1.3: CLI: Session serialization, load buffer size: no ticket +target fail ticket TLS 1.3: CLI: Session serialization, load buffer size: small ticket +target fail ticket TLS 1.3: CLI: Session serialization, load buffer size: large ticket +target fail ticket TLS 1.3: SRV: Session serialization, load buffer size +api notrun internal Test configuration of EC groups through mbedtls_ssl_conf_groups() +api notrun group_list Get supported group list: x25519, positive +api notrun group_list Get supported group list: x25519, negative +api notrun group_list Get supported group list: secp256r1, positive +api notrun group_list Get supported group list: secp256r1, negative +api notrun group_list Get supported group list: secp384r1, positive +api notrun group_list Get supported group list: secp384r1, negative +api notrun group_list Get supported group list: x448, positive +api notrun group_list Get supported group list: x448, negative +api notrun group_list Get supported group list: secp521r1, positive +api notrun group_list Get supported group list: secp521r1, negative +api notrun group_list Get supported group list: brainpool256r1, positive +api notrun group_list Get supported group list: brainpool256r1, negative +api notrun group_list Get supported group list: brainpool384r1, positive +api notrun group_list Get supported group list: brainpool384r1, negative +api notrun group_list Get supported group list: brainpool512r1, positive +api notrun group_list Get supported group list: brainpool512r1, negative +api notrun group_list Get supported group list: ffdhe2048, positive +api notrun group_list Get supported group list: ffdhe2048, negative +api notrun group_list Get supported group list: ffdhe3072, positive +api notrun group_list Get supported group list: ffdhe3072, negative +api notrun group_list Get supported group list: ffdhe4096, positive +api notrun group_list Get supported group list: ffdhe4096, negative +api notrun group_list Get supported group list: ffdhe6144, positive +api notrun group_list Get supported group list: ffdhe6144, negative +api notrun group_list Get supported group list: ffdhe8192, positive +api notrun group_list Get supported group list: ffdhe8192, negative +api fail defaults Version config: valid client TLS 1.2 only +api fail defaults Version config: valid client DTLS 1.2 only +api fail defaults Version config: valid server TLS 1.2 only +api fail defaults Version config: valid server DTLS 1.2 only +api notrun tls12-off Version config: invalid client TLS 1.2 only +api notrun tls12-off Version config: invalid client DTLS 1.2 only +api notrun tls12-off Version config: invalid server TLS 1.2 only +api notrun tls12-off Version config: invalid server DTLS 1.2 only +api fail defaults Version config: valid client TLS 1.3 only +api fail defaults Version config: unsupported client DTLS 1.3 only +api fail defaults Version config: valid server TLS 1.3 only +api fail defaults Version config: unsupported server DTLS 1.3 only +api notrun tls13-off Version config: invalid client TLS 1.3 only +api notrun tls13-off Version config: invalid client DTLS 1.3 only +api notrun tls13-off Version config: invalid server TLS 1.3 only +api notrun tls13-off Version config: invalid server DTLS 1.3 only +api fail defaults Version config: valid client hybrid TLS 1.2/3 +api fail defaults Version config: unsupported client hybrid DTLS 1.2/3 +api fail defaults Version config: valid server hybrid TLS 1.2/3 +api fail defaults Version config: unsupported server hybrid DTLS 1.2/3 +api notrun tls12-off Version config: valid client hybrid TLS 1.2/3, no TLS 1.2 +api notrun tls12-off Version config: unsupported client hybrid DTLS 1.2/3, no TLS 1.2 +api notrun tls12-off Version config: valid server hybrid TLS 1.2/3, no TLS 1.2 +api notrun tls12-off Version config: unsupported server hybrid DTLS 1.2/3, no TLS 1.2 +api notrun tls13-off Version config: valid client hybrid TLS 1.2/3, no TLS 1.3 +api notrun tls13-off Version config: unsupported client hybrid DTLS 1.2/3, no TLS 1.3 +api notrun tls13-off Version config: valid server hybrid TLS 1.2/3, no TLS 1.3 +api notrun tls13-off Version config: unsupported server hybrid DTLS 1.2/3, no TLS 1.3 +api fail defaults Version config: invalid minimum version +api fail defaults Version config: invalid maximum version +api fail timing Test accessor into timing_delay_context +api fail cid Sanity test cid functions +api notrun internal Test Elliptic curves' info parsing +target fail exporter TLS 1.2 Keying Material Exporter: Consistent results, no context +target fail exporter TLS 1.2 Keying Material Exporter: Consistent results, with context +target fail exporter TLS 1.2 Keying Material Exporter: Consistent results, large keys +target fail exporter TLS 1.2 Keying Material Exporter: Uses label +target fail exporter TLS 1.2 Keying Material Exporter: Uses context +target fail exporter TLS 1.2 Keying Material Exporter: Context too long +target fail exporter TLS 1.2 Keying Material Exporter: Handshake not done +target fail exporter TLS 1.3 Keying Material Exporter: Consistent results, no context +target fail exporter TLS 1.3 Keying Material Exporter: Consistent results, with context +target fail exporter TLS 1.3 Keying Material Exporter: Consistent results, large keys +target fail exporter TLS 1.3 Keying Material Exporter: Uses label +target fail exporter TLS 1.3 Keying Material Exporter: Uses context +target fail exporter TLS 1.3 Keying Material Exporter: Uses length +target fail exporter TLS 1.3 Keying Material Exporter: Exported key too long +target fail exporter TLS 1.3 Keying Material Exporter: Label too long +target fail exporter TLS 1.3 Keying Material Exporter: Handshake not done +target notrun internal Send large fragmented ClientHello: reassembled 1 byte larger than the buffer +target notrun internal Send large fragmented ClientHello: would just fit except for overhead +target notrun internal Send large fragmented ClientHello: would fit except for overhead (1) +target notrun internal Send large fragmented ClientHello: would fit except for overhead (2) +target notrun internal Send large fragmented ClientHello: would fit except for overhead (3) +target notrun internal Send large fragmented ClientHello: would fit except for overhead (4) +target notrun internal Send large fragmented ClientHello: just fits +target notrun internal Send large fragmented ClientHello: length doesn't fit in two bytes diff --git a/test/mbedtls_compat/ssl_suite/check.py b/test/mbedtls_compat/ssl_suite/check.py new file mode 100644 index 0000000..e6b2bc4 --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/check.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2026 wolfSSL Inc. +# SPDX-License-Identifier: GPL-3.0-or-later +# +# Prints what passes per group and what the rest waits on, then each case +# whose outcome differs from cases.txt, and exits 1 if there is one. +# +# Usage: check.py CASES OUTCOME + +import collections +import sys + +GROUPS = ('target', 'api', 'mock') + + +def main(): + if len(sys.argv) != 3: + sys.exit('Usage: check.py CASES OUTCOME') + cases_path, outcome_path = sys.argv[1:] + + cases = {} + with open(cases_path, encoding='ascii') as f: + for line in f: + if line.strip() and not line.startswith('#'): + group, expect, waits, desc = line.split(None, 3) + cases[desc.strip()] = (group, expect, waits) + + results = {} + try: + with open(outcome_path, encoding='latin-1') as f: + for line in f: + fields = line.rstrip('\n').split(';', 5) + results[fields[3]] = (fields[4], fields[5]) + except FileNotFoundError: + pass + + bad = [] + for desc, (result, reason) in results.items(): + if desc not in cases: + bad.append('not in cases.txt: ' + desc) + elif cases[desc][1] == 'notrun': + bad.append('run, but marked notrun: ' + desc) + for desc, (group, expect, waits) in cases.items(): + if expect == 'notrun': + continue + if desc not in results: + bad.append('not run: ' + desc) + continue + result, reason = results[desc] + if expect == 'pass' and result != 'PASS': + bad.append('%s, expected pass: %s (%s)' % (result, desc, reason)) + elif expect == 'fail' and result == 'PASS': + bad.append('PASS, expected fail: ' + desc) + + for group in GROUPS: + run = [(d, c) for d, c in cases.items() + if c[0] == group and c[1] != 'notrun'] + passed = sum(results.get(d, ('',))[0] == 'PASS' for d, _ in run) + notrun = sum(c[0] == group and c[1] == 'notrun' + for c in cases.values()) + line = ' %-7s %d of %d pass' % (group, passed, len(run)) + print(line + (', %d not run' % notrun if notrun else '')) + waits = collections.Counter(c[2] for _, c in run if c[1] == 'fail') + if waits: + print(' not yet: ' + ', '.join( + '%s %d' % w for w in waits.most_common())) + + if bad: + print('Not as in cases.txt:') + print('\n'.join(' ' + b for b in bad)) + sys.exit(1) + + +if __name__ == '__main__': + main() diff --git a/test/mbedtls_compat/ssl_suite/mbedtls.patch b/test/mbedtls_compat/ssl_suite/mbedtls.patch new file mode 100644 index 0000000..573d00f --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/mbedtls.patch @@ -0,0 +1,336 @@ +Changes to Mbed TLS's ssl suite and test helpers, applied to the clone by +test/mbedtls_compat/Makefile. Same license as the files they change: +SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +diff --git a/tests/src/test_helpers/ssl_helpers.c b/tests/src/test_helpers/ssl_helpers.c +index ebb9103..4a99a38 100644 +--- a/tests/src/test_helpers/ssl_helpers.c ++++ b/tests/src/test_helpers/ssl_helpers.c +@@ -9,7 +9,7 @@ + */ + + #include +-#include ++#include "ssl_helpers_port.h" + #include + #include "mbedtls/psa_util.h" + +@@ -608,25 +608,7 @@ static int set_ciphersuite(mbedtls_test_ssl_endpoint *ep, + int ok = 0; + + TEST_CALLOC(ep->ciphersuites, 2); +- ep->ciphersuites[0] = mbedtls_ssl_get_ciphersuite_id(cipher); +- ep->ciphersuites[1] = 0; +- +- const mbedtls_ssl_ciphersuite_t *ciphersuite_info = +- mbedtls_ssl_ciphersuite_from_id(ep->ciphersuites[0]); +- +- TEST_ASSERT(ciphersuite_info != NULL); +- TEST_ASSERT(ciphersuite_info->min_tls_version <= ep->conf.max_tls_version); +- TEST_ASSERT(ciphersuite_info->max_tls_version >= ep->conf.min_tls_version); +- +- if (ep->conf.max_tls_version > ciphersuite_info->max_tls_version) { +- ep->conf.max_tls_version = (mbedtls_ssl_protocol_version) ciphersuite_info->max_tls_version; +- } +- if (ep->conf.min_tls_version < ciphersuite_info->min_tls_version) { +- ep->conf.min_tls_version = (mbedtls_ssl_protocol_version) ciphersuite_info->min_tls_version; +- } +- +- mbedtls_ssl_conf_ciphersuites(&ep->conf, ep->ciphersuites); +- ok = 1; ++ NOT_PORTED("cipher suite by name"); + + exit: + return ok; +@@ -648,9 +630,6 @@ static void test_ssl_endpoint_certificate_free(mbedtls_test_ssl_endpoint *ep) + ep->cert = NULL; + } + if (ep->pkey != NULL) { +- if (mbedtls_pk_get_type(ep->pkey) == MBEDTLS_PK_OPAQUE) { +- psa_destroy_key(ep->pkey->priv_id); +- } + mbedtls_pk_free(ep->pkey); + mbedtls_free(ep->pkey); + ep->pkey = NULL; +@@ -727,7 +706,6 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, + int i = 0; + int ret = -1; + int ok = 0; +- mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT; + + if (ep == NULL) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; +@@ -760,20 +738,10 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, + } + + if (opaque_alg != 0) { +- psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; +- /* Use a fake key usage to get a successful initial guess for the PSA attributes. */ +- TEST_EQUAL(mbedtls_pk_get_psa_attributes(ep->pkey, PSA_KEY_USAGE_SIGN_HASH, +- &key_attr), 0); +- /* Then manually usage, alg and alg2 as requested by the test. */ +- psa_set_key_usage_flags(&key_attr, opaque_usage); +- psa_set_key_algorithm(&key_attr, opaque_alg); +- if (opaque_alg2 != PSA_ALG_NONE) { +- psa_set_key_enrollment_algorithm(&key_attr, opaque_alg2); +- } +- TEST_EQUAL(mbedtls_pk_import_into_psa(ep->pkey, &key_attr, &key_slot), 0); +- mbedtls_pk_free(ep->pkey); +- mbedtls_pk_init(ep->pkey); +- TEST_EQUAL(mbedtls_pk_wrap_psa(ep->pkey, key_slot), 0); ++ (void) opaque_alg2; ++ (void) opaque_usage; ++ NOT_PORTED("opaque keys"); ++ goto exit; + } + + mbedtls_ssl_conf_ca_chain(&(ep->conf), ep->ca_chain, NULL); +@@ -817,16 +785,8 @@ int mbedtls_test_ssl_endpoint_init_conf( + mbedtls_ssl_config_init(&(ep->conf)); + mbedtls_test_message_socket_init(&ep->dtls_context); + +- TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&ep->conf) == NULL); +- TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf), 0); +- TEST_ASSERT(mbedtls_ssl_get_user_data_p(&ep->ssl) == NULL); +- TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), 0); +- +- (void) mbedtls_test_rnd_std_rand(NULL, +- (void *) &ep->user_data_cookie, +- sizeof(ep->user_data_cookie)); +- mbedtls_ssl_conf_set_user_data_n(&ep->conf, ep->user_data_cookie); +- mbedtls_ssl_set_user_data_n(&ep->ssl, ep->user_data_cookie); ++ NOT_PORTED("user data"); ++ goto exit; + + mbedtls_test_mock_socket_init(&(ep->socket)); + +@@ -864,7 +824,8 @@ int mbedtls_test_ssl_endpoint_init_conf( + } + + if (options->group_list != NULL) { +- mbedtls_ssl_conf_groups(&(ep->conf), options->group_list); ++ NOT_PORTED("mbedtls_ssl_conf_groups"); ++ goto exit; + } + + if (MBEDTLS_SSL_IS_SERVER == endpoint_type) { +@@ -960,11 +921,8 @@ int mbedtls_test_ssl_endpoint_init_conf( + } + #endif + +- TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf), +- ep->user_data_cookie); +- mbedtls_ssl_conf_set_user_data_p(&ep->conf, ep); +- +- return 0; ++ NOT_PORTED("user data"); ++ goto exit; + + exit: + if (ret == 0) { +@@ -1007,10 +965,8 @@ int mbedtls_test_ssl_endpoint_init_ssl( + NULL); + } + +- TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), ep->user_data_cookie); +- mbedtls_ssl_set_user_data_p(&ep->ssl, ep); +- +- return 0; ++ NOT_PORTED("user data"); ++ goto exit; + + exit: + if (ret == 0) { +@@ -1037,14 +993,7 @@ void mbedtls_test_ssl_endpoint_free( + { + // mbedtls_ssl_session_reset() requires the SSL to be setup. + if (ep->ssl.conf != NULL) { +- mbedtls_ssl_context ssl_before; +- +- /* Dump the SSL context before resetting it */ +- memcpy(&ssl_before, &(ep->ssl), sizeof(mbedtls_ssl_context)); +- +- mbedtls_ssl_session_reset(&(ep->ssl)); +- /* Check that required fields were properly reset */ +- mbedtls_test_ssl_check_context_after_session_reset(&ssl_before, &(ep->ssl)); ++ NOT_PORTED("session reset check"); + } + mbedtls_ssl_free(&(ep->ssl)); + mbedtls_ssl_config_free(&(ep->conf)); +@@ -1081,6 +1030,8 @@ exit: + return ret; + } + ++/* Replaced in ssl_helpers_port.c */ ++#if defined(TEST_SSL_INTERNALS) + int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, + mbedtls_ssl_context *second_ssl, + int state) +@@ -1116,6 +1067,7 @@ int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, + + return (max_steps >= 0) ? ret : -1; + } ++#endif /* TEST_SSL_INTERNALS */ + + #endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */ + +@@ -1207,6 +1159,8 @@ exit: + return -1; + } + ++/* Record transforms and MACs: internal cases only */ ++#if defined(TEST_SSL_INTERNALS) + #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ + defined(PSA_WANT_ALG_CBC_NO_PADDING) && defined(PSA_WANT_KEY_TYPE_AES) + int mbedtls_test_psa_cipher_encrypt_helper(mbedtls_ssl_transform *transform, +@@ -1704,7 +1658,10 @@ exit: + return -1; + } + #endif /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */ ++#endif /* TEST_SSL_INTERNALS */ + ++/* Replaced in ssl_helpers_port.c */ ++#if defined(TEST_SSL_INTERNALS) + #if defined(MBEDTLS_SSL_PROTO_TLS1_2) + int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session, + int ticket_len, +@@ -1885,6 +1842,7 @@ int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session, + return 0; + } + #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ ++#endif /* TEST_SSL_INTERNALS */ + + int mbedtls_test_ssl_exchange_data( + mbedtls_ssl_context *ssl_1, +@@ -2018,7 +1976,9 @@ static int check_ssl_version( + /* First check that both sides have chosen the same version. + * If so, we can make more sanity checks just on one side. + * If not, something is deeply wrong. */ +- TEST_EQUAL(client->tls_version, server->tls_version); ++ (void) server; ++ NOT_PORTED("negotiated version"); ++ goto exit; + + /* Make further checks on the client to validate that the + * reported data about the version is correct. */ +@@ -2026,8 +1986,6 @@ static int check_ssl_version( + mbedtls_ssl_protocol_version version_number = + mbedtls_ssl_get_version_number(client); + +- TEST_EQUAL(client->tls_version, expected_negotiated_version); +- + if (client->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { + TEST_EQUAL(version_string[0], 'D'); + ++version_string; +@@ -2102,12 +2060,8 @@ int mbedtls_test_ssl_do_handshake_with_endpoints( + if (ret != 0 && ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { + return ret; + } +- if (!mbedtls_ssl_is_handshake_over(&client_ep->ssl) || +- !mbedtls_ssl_is_handshake_over(&server_ep->ssl)) { +- return -1; +- } +- +- return 0; ++ NOT_PORTED("handshake state"); ++ return -1; + } + #endif /* defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) */ + +@@ -2310,7 +2264,8 @@ int mbedtls_test_ssl_perform_connection( + goto exit; + } + +- TEST_EQUAL(mbedtls_ssl_is_handshake_over(&client->ssl), 1); ++ NOT_PORTED("handshake state"); ++ goto exit; + + /* Make sure server state is moved to HANDSHAKE_OVER also. */ + TEST_EQUAL(mbedtls_test_move_handshake_to_state(&(server->ssl), +@@ -2318,16 +2273,14 @@ int mbedtls_test_ssl_perform_connection( + MBEDTLS_SSL_HANDSHAKE_OVER), + 0); + +- TEST_EQUAL(mbedtls_ssl_is_handshake_over(&server->ssl), 1); +- + /* Check that both sides have negotiated the expected version. */ + TEST_ASSERT(check_ssl_version(options->expected_negotiated_version, + &client->ssl, + &server->ssl)); + + if (options->expected_ciphersuite != 0) { +- TEST_EQUAL(server->ssl.session->ciphersuite, +- options->expected_ciphersuite); ++ NOT_PORTED("negotiated cipher suite"); ++ goto exit; + } + + if (options->post_handshake_fun != NULL) { +@@ -2417,10 +2370,8 @@ void mbedtls_test_ssl_perform_handshake( + + TEST_ASSERT(mbedtls_test_ssl_perform_connection(options, client, server)); + +- TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&client->conf) == client); +- TEST_ASSERT(mbedtls_ssl_get_user_data_p(&client->ssl) == client); +- TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&server->conf) == server); +- TEST_ASSERT(mbedtls_ssl_get_user_data_p(&server->ssl) == server); ++ NOT_PORTED("user data"); ++ goto exit; + + if (options->pre_shutdown_fun != NULL) { + options->pre_shutdown_fun(client, server, options->pre_shutdown_param); +diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function +index 7a9a03a..c70bd31 100644 +--- a/tests/suites/test_suite_ssl.function ++++ b/tests/suites/test_suite_ssl.function +@@ -1,18 +1,11 @@ + /* BEGIN_HEADER */ +-#include ++#include + #include + #include + #include +-#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER) + #include +-#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */ +-#include +-#include +-#include + #include +-#include + +-#include + #include + + #define SSL_MESSAGE_QUEUE_INIT { NULL, 0, 0, 0 } +@@ -203,8 +196,9 @@ typedef struct { + static void pre_handshake_tweak_context(mbedtls_ssl_context *ssl, + int tweaks) + { ++ (void) ssl; + if (tweaks & PRE_HANDSHAKE_BADMAC_SEEN) { +- ssl->badmac_seen = 1; ++ mbedtls_test_fail("badmac_seen is internal", __LINE__, __FILE__); + } + } + +@@ -273,15 +267,10 @@ static void simulate_badmac_seen_on(mbedtls_test_ssl_endpoint *client, + mbedtls_test_ssl_endpoint *server, + void *param) + { +- int on = *(int *) param; +- switch (on) { +- case MBEDTLS_SSL_IS_CLIENT: +- client->ssl.badmac_seen = 1; +- break; +- case MBEDTLS_SSL_IS_SERVER: +- server->ssl.badmac_seen = 1; +- break; +- } ++ (void) client; ++ (void) server; ++ (void) param; ++ mbedtls_test_fail("badmac_seen is internal", __LINE__, __FILE__); + } + #endif + diff --git a/test/mbedtls_compat/ssl_suite/select.py b/test/mbedtls_compat/ssl_suite/select.py new file mode 100644 index 0000000..eca3fdc --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/select.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2026 wolfSSL Inc. +# SPDX-License-Identifier: GPL-3.0-or-later +# +# Writes test_suite_ssl_public.function and .data: the ssl suite's header, the +# test functions the cases in CASES need, and those cases, unchanged. Fails +# when CASES and Mbed TLS differ on the cases of those test functions. +# +# Usage: select.py CASES SUITES_DIR OUT_DIR (SUITES_DIR: the clone's +# tests/suites) + +import os +import re +import sys + +FUNCTION = 'test_suite_ssl.function' +DATA = ('test_suite_ssl.data', 'test_suite_ssl.tls-defrag.data') +OUT = 'test_suite_ssl_public' +EXPECT = ('pass', 'fail', 'notrun') + + +def read_cases(path): + """Return {description: expect} from cases.txt.""" + cases = {} + with open(path, encoding='ascii') as f: + for num, line in enumerate(f, 1): + line = line.strip() + if not line or line.startswith('#'): + continue + fields = line.split(None, 3) + if len(fields) != 4 or fields[1] not in EXPECT: + sys.exit('%s:%d: bad line' % (path, num)) + if fields[3] in cases: + sys.exit('%s:%d: case listed twice' % (path, num)) + cases[fields[3]] = fields[1] + return cases + + +def read_data(path): + """Return [(description, function, text)] for each case in a .data.""" + out = [] + with open(path, encoding='latin-1') as f: + blocks = re.split(r'\n\s*\n', f.read()) + for block in blocks: + lines = [l for l in block.strip().split('\n') + if l.strip() and not l.startswith('#')] + if len(lines) < 2: + continue + func = lines[-1].split(':', 1)[0] + out.append((lines[0], func, '\n'.join(lines))) + return out + + +def main(): + if len(sys.argv) != 4: + sys.exit('Usage: select.py CASES SUITES_DIR OUT_DIR') + cases_path, suites, out_dir = sys.argv[1:] + cases = read_cases(cases_path) + + data = [] + for name in DATA: + data += read_data(os.path.join(suites, name)) + with open(os.path.join(suites, FUNCTION), encoding='latin-1') as f: + src = f.read() + + header = re.search(r'/\* BEGIN_HEADER \*/.*?/\* END_HEADER \*/\n', + src, re.S).group(0) + deps = re.search(r'/\* BEGIN_DEPENDENCIES.*?END_DEPENDENCIES\n \*/\n', + src, re.S).group(0) + bodies = {} + for m in re.finditer(r'/\* BEGIN_CASE[^*]*\*/.*?/\* END_CASE \*/\n', + src, re.S): + name = re.search(r'\nvoid\s+(\w+)\s*\(', m.group(0)).group(1) + bodies[name] = m.group(0) + + upstream = {desc for desc, _, _ in data} + listed_funcs = {func for desc, func, _ in data if desc in cases} + errors = ['listed, not in Mbed TLS: ' + desc + for desc in cases if desc not in upstream] + errors += ['not listed: ' + desc for desc, func, _ in data + if func in listed_funcs and desc not in cases] + if errors: + sys.exit('%s:\n %s' % (cases_path, '\n '.join(errors))) + + run = [(func, text) for desc, func, text in data + if cases.get(desc, 'notrun') != 'notrun'] + funcs = {func for func, _ in run} + todo = list(funcs) + while todo: + for called in re.findall(r'\btest_(\w+)\s*\(', bodies[todo.pop()]): + if called in bodies and called not in funcs: + funcs.add(called) + todo.append(called) + + with open(os.path.join(out_dir, OUT + '.function'), 'w') as f: + f.write(header + '\n' + deps) + f.writelines('\n' + body for name, body in bodies.items() + if name in funcs) + with open(os.path.join(out_dir, OUT + '.data'), 'w') as f: + f.write('\n\n'.join(text for _, text in run) + '\n') + + +if __name__ == '__main__': + main() diff --git a/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/ctr_drbg.h b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/ctr_drbg.h new file mode 100644 index 0000000..ac7abc7 --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/ctr_drbg.h @@ -0,0 +1,22 @@ +/* ctr_drbg.h + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Stand-in: the test helpers include it, the ssl suite uses none of it */ diff --git a/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/entropy.h b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/entropy.h new file mode 100644 index 0000000..b191a09 --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/entropy.h @@ -0,0 +1,31 @@ +/* entropy.h + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Stand-in: the test helpers' random.c returns this error */ + +#ifndef SHIM_MBEDTLS_PRIVATE_ENTROPY_H +#define SHIM_MBEDTLS_PRIVATE_ENTROPY_H + +#include + +#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED PSA_ERROR_INSUFFICIENT_ENTROPY + +#endif /* SHIM_MBEDTLS_PRIVATE_ENTROPY_H */ diff --git a/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/error_common.h b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/error_common.h new file mode 100644 index 0000000..437b269 --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/error_common.h @@ -0,0 +1,24 @@ +/* error_common.h + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Stand-in: the generated suite includes it */ + +#include diff --git a/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/pk_private.h b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/pk_private.h new file mode 100644 index 0000000..cdc6ae5 --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/shim/mbedtls/private/pk_private.h @@ -0,0 +1,32 @@ +/* pk_private.h + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Stand-in: the key types the ssl suite and its helpers use */ + +#ifndef SHIM_MBEDTLS_PRIVATE_PK_PRIVATE_H +#define SHIM_MBEDTLS_PRIVATE_PK_PRIVATE_H + +#include + +#define MBEDTLS_PK_RSA 1 +#define MBEDTLS_PK_ECDSA 3 + +#endif /* SHIM_MBEDTLS_PRIVATE_PK_PRIVATE_H */ diff --git a/test/mbedtls_compat/ssl_suite/shim/psa_crypto_helpers.c b/test/mbedtls_compat/ssl_suite/shim/psa_crypto_helpers.c new file mode 100644 index 0000000..5e8d1da --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/shim/psa_crypto_helpers.c @@ -0,0 +1,31 @@ +/* psa_crypto_helpers.c + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Stand-ins for psa_crypto_helpers.c, which reads Mbed TLS's key slots */ + +#include + +int mbedtls_test_fail_if_psa_leaking(int line_no, const char *filename) +{ + (void)line_no; + (void)filename; + return 0; +} diff --git a/test/mbedtls_compat/ssl_suite/shim/threading_internal.h b/test/mbedtls_compat/ssl_suite/shim/threading_internal.h new file mode 100644 index 0000000..0784a86 --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/shim/threading_internal.h @@ -0,0 +1,29 @@ +/* threading_internal.h + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Stand-in for threading_helpers.c: no check of wolfPSA's mutex use */ + +#ifndef SHIM_THREADING_INTERNAL_H +#define SHIM_THREADING_INTERNAL_H + +#include + +#endif /* SHIM_THREADING_INTERNAL_H */ diff --git a/test/mbedtls_compat/ssl_suite/ssl_helpers_port.c b/test/mbedtls_compat/ssl_suite/ssl_helpers_port.c new file mode 100644 index 0000000..bcd9219 --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/ssl_helpers_port.c @@ -0,0 +1,65 @@ +/* ssl_helpers_port.c + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* Replacements for the ssl test helpers that use Mbed TLS internals */ + +#include "ssl_helpers_port.h" + +#if defined(MBEDTLS_SSL_TLS_C) + +#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) +int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, + mbedtls_ssl_context *second_ssl, int state) +{ + (void)ssl; + (void)second_ssl; + (void)state; + NOT_PORTED("handshake state"); + return -1; +} +#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */ + +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) +int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session, + int ticket_len, int endpoint_type, const char *crt_file) +{ + (void)session; + (void)ticket_len; + (void)endpoint_type; + (void)crt_file; + NOT_PORTED("session fields"); + return -1; +} +#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ + +#if defined(MBEDTLS_SSL_PROTO_TLS1_3) +int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session, + int ticket_len, int endpoint_type) +{ + (void)session; + (void)ticket_len; + (void)endpoint_type; + NOT_PORTED("session fields"); + return -1; +} +#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ + +#endif /* MBEDTLS_SSL_TLS_C */ diff --git a/test/mbedtls_compat/ssl_suite/ssl_helpers_port.h b/test/mbedtls_compat/ssl_suite/ssl_helpers_port.h new file mode 100644 index 0000000..0f324dd --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/ssl_helpers_port.h @@ -0,0 +1,36 @@ +/* ssl_helpers_port.h + * + * Copyright (C) 2026 wolfSSL Inc. + * + * This file is part of wolfPSA. + * + * wolfPSA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfPSA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +/* In place of ssl_helpers_internal.h; TEST_SSL_INTERNALS is never defined */ + +#ifndef SSL_HELPERS_PORT_H +#define SSL_HELPERS_PORT_H + +#include +#include +#include +#include + +/* Fails the case where the port to the public API is not done yet */ +#define NOT_PORTED(what) \ + mbedtls_test_fail("not ported: " what, __LINE__, __FILE__) + +#endif /* SSL_HELPERS_PORT_H */ From 683a2ccdc31cdd21fccabf263a911f15adc1ce03 Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 13:22:40 -0800 Subject: [PATCH 04/10] Port Mbed TLS ssl test helpers, add user data and handshake-over calls --- test/mbedtls_compat/Makefile | 5 +- test/mbedtls_compat/ssl_suite/cases.txt | 22 +- test/mbedtls_compat/ssl_suite/mbedtls.patch | 330 +++++++++--------- .../ssl_suite/ssl_helpers_port.c | 216 ++++++++++-- 4 files changed, 368 insertions(+), 205 deletions(-) diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index e0cc4ab..f9a2959 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -79,8 +79,9 @@ SUITE_OBJS := $(SUITE_NAME).o $(SUITE_BUILD)/ssl_helpers.o \ $(SUITE_BUILD)/ssl_helpers_port.o $(SUITE_BUILD)/psa_crypto_helpers.o \ $(SUITE_HELPERS) SUITE_TEMPLATES := $(MBEDTLS_CLONE)/tf-psa-crypto/tests/suites -# wolfPSA's headers first; Mbed TLS's public headers are not on the path -SUITE_FLAGS := $(LAYER_FLAGS) -I$(SUITE) -I$(SUITE)/shim \ +# wolfPSA's headers first; Mbed TLS's public headers are not on the path. +# TEST_WOLFPSA leaves out the helpers' calls that wolfPSA does not have yet. +SUITE_FLAGS := $(LAYER_FLAGS) -DTEST_WOLFPSA -I$(SUITE) -I$(SUITE)/shim \ $(addprefix -I$(MBEDTLS_CLONE)/,framework/tests/include tests/include \ tf-psa-crypto/tests/include framework/tests/src) \ -idirafter $(MBEDTLS_CLONE)/tf-psa-crypto/core diff --git a/test/mbedtls_compat/ssl_suite/cases.txt b/test/mbedtls_compat/ssl_suite/cases.txt index 46a868e..ce7d09f 100644 --- a/test/mbedtls_compat/ssl_suite/cases.txt +++ b/test/mbedtls_compat/ssl_suite/cases.txt @@ -9,9 +9,9 @@ # passes. notrun is left out of the run. # # Waits on, for fail: -# port the ssl_helpers.c port # pss MBEDTLS_X509_RSASSA_PSS_SUPPORT -# session mbedtls_ssl_session_save and _load +# session mbedtls_ssl_session_save and _load; PSK too for a session +# without a certificate # ticket session tickets, then session save and load # exporter mbedtls_ssl_export_keying_material # dtls DTLS @@ -66,13 +66,13 @@ mock pass - Message transport mock - truncated message mock pass - Message transport mock - socket read error mock pass - Message transport mock - one-way interleaved sends/reads mock pass - Message transport mock - two-way interleaved sends/reads -target fail port Test mbedtls_endpoint sanity for the client -target fail port Test mbedtls_endpoint sanity for the server -target fail port Handshake, tls1_2 +target pass - Test mbedtls_endpoint sanity for the client +target pass - Test mbedtls_endpoint sanity for the server +target pass - Handshake, tls1_2 target fail pss Handshake, tls1_3 -target fail port Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 -target fail port Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 -target fail port Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 +target pass - Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 +target pass - Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 +target pass - Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 target notrun ccm Handshake, ECDHE-ECDSA-WITH-AES-256-CCM target fail psk Handshake, PSK-WITH-AES-128-CBC-SHA target fail psk DTLS Handshake, PSK-WITH-AES-128-CBC-SHA @@ -86,7 +86,7 @@ target fail dtls DTLS Handshake fragmentation, MFL=512 target fail dtls DTLS Handshake fragmentation, MFL=1024 target notrun tls13-off Handshake min/max version check, all -> 1.2 target fail pss Handshake min/max version check, all -> 1.3 -target fail port Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, non-opaque +target pass - Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, non-opaque target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_ANY_HASH target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_SHA_384 target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, invalid alg @@ -107,8 +107,8 @@ target fail mfl Sending app data via TLS, MFL=2048 without fragmenta target fail mfl Sending app data via TLS, MFL=2048 with fragmentation target fail mfl Sending app data via TLS, MFL=4096 without fragmentation target fail mfl Sending app data via TLS, MFL=4096 with fragmentation -target fail port Sending app data via TLS without MFL and without fragmentation -target fail port Sending app data via TLS without MFL and with fragmentation +target pass - Sending app data via TLS without MFL and without fragmentation +target pass - Sending app data via TLS without MFL and with fragmentation target fail dtls Sending app data via DTLS, MFL=512 without fragmentation target fail dtls Sending app data via DTLS, MFL=512 with fragmentation target fail dtls Sending app data via DTLS, MFL=1024 without fragmentation diff --git a/test/mbedtls_compat/ssl_suite/mbedtls.patch b/test/mbedtls_compat/ssl_suite/mbedtls.patch index 573d00f..9ccfb7e 100644 --- a/test/mbedtls_compat/ssl_suite/mbedtls.patch +++ b/test/mbedtls_compat/ssl_suite/mbedtls.patch @@ -3,7 +3,7 @@ test/mbedtls_compat/Makefile. Same license as the files they change: SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later diff --git a/tests/src/test_helpers/ssl_helpers.c b/tests/src/test_helpers/ssl_helpers.c -index ebb9103..4a99a38 100644 +index ebb9103..6608d62 100644 --- a/tests/src/test_helpers/ssl_helpers.c +++ b/tests/src/test_helpers/ssl_helpers.c @@ -9,7 +9,7 @@ @@ -15,149 +15,103 @@ index ebb9103..4a99a38 100644 #include #include "mbedtls/psa_util.h" -@@ -608,25 +608,7 @@ static int set_ciphersuite(mbedtls_test_ssl_endpoint *ep, - int ok = 0; +@@ -611,19 +611,17 @@ static int set_ciphersuite(mbedtls_test_ssl_endpoint *ep, + ep->ciphersuites[0] = mbedtls_ssl_get_ciphersuite_id(cipher); + ep->ciphersuites[1] = 0; - TEST_CALLOC(ep->ciphersuites, 2); -- ep->ciphersuites[0] = mbedtls_ssl_get_ciphersuite_id(cipher); -- ep->ciphersuites[1] = 0; -- - const mbedtls_ssl_ciphersuite_t *ciphersuite_info = - mbedtls_ssl_ciphersuite_from_id(ep->ciphersuites[0]); -- ++ /* TLS 1.3 suites are named TLS1-3-*, the others are TLS 1.2 only */ ++ mbedtls_ssl_protocol_version suite_version = ++ strncmp(cipher, "TLS1-3-", 7) == 0 ? MBEDTLS_SSL_VERSION_TLS1_3 : ++ MBEDTLS_SSL_VERSION_TLS1_2; + - TEST_ASSERT(ciphersuite_info != NULL); - TEST_ASSERT(ciphersuite_info->min_tls_version <= ep->conf.max_tls_version); - TEST_ASSERT(ciphersuite_info->max_tls_version >= ep->conf.min_tls_version); -- ++ TEST_ASSERT(ep->ciphersuites[0] != 0); ++ TEST_ASSERT(suite_version <= ep->conf.max_tls_version); ++ TEST_ASSERT(suite_version >= ep->conf.min_tls_version); + - if (ep->conf.max_tls_version > ciphersuite_info->max_tls_version) { - ep->conf.max_tls_version = (mbedtls_ssl_protocol_version) ciphersuite_info->max_tls_version; - } - if (ep->conf.min_tls_version < ciphersuite_info->min_tls_version) { - ep->conf.min_tls_version = (mbedtls_ssl_protocol_version) ciphersuite_info->min_tls_version; - } -- -- mbedtls_ssl_conf_ciphersuites(&ep->conf, ep->ciphersuites); -- ok = 1; -+ NOT_PORTED("cipher suite by name"); - - exit: - return ok; -@@ -648,9 +630,6 @@ static void test_ssl_endpoint_certificate_free(mbedtls_test_ssl_endpoint *ep) ++ mbedtls_ssl_conf_min_tls_version(&ep->conf, suite_version); ++ mbedtls_ssl_conf_max_tls_version(&ep->conf, suite_version); + + mbedtls_ssl_conf_ciphersuites(&ep->conf, ep->ciphersuites); + ok = 1; +@@ -648,9 +646,11 @@ static void test_ssl_endpoint_certificate_free(mbedtls_test_ssl_endpoint *ep) ep->cert = NULL; } if (ep->pkey != NULL) { -- if (mbedtls_pk_get_type(ep->pkey) == MBEDTLS_PK_OPAQUE) { -- psa_destroy_key(ep->pkey->priv_id); -- } ++#if !defined(TEST_WOLFPSA) + if (mbedtls_pk_get_type(ep->pkey) == MBEDTLS_PK_OPAQUE) { + psa_destroy_key(ep->pkey->priv_id); + } ++#endif /* !TEST_WOLFPSA */ mbedtls_pk_free(ep->pkey); mbedtls_free(ep->pkey); ep->pkey = NULL; -@@ -727,7 +706,6 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, +@@ -727,7 +727,9 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, int i = 0; int ret = -1; int ok = 0; -- mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT; ++#if !defined(TEST_WOLFPSA) + mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT; ++#endif /* !TEST_WOLFPSA */ if (ep == NULL) { return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; -@@ -760,20 +738,10 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, +@@ -760,6 +762,12 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, } if (opaque_alg != 0) { -- psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; -- /* Use a fake key usage to get a successful initial guess for the PSA attributes. */ -- TEST_EQUAL(mbedtls_pk_get_psa_attributes(ep->pkey, PSA_KEY_USAGE_SIGN_HASH, -- &key_attr), 0); -- /* Then manually usage, alg and alg2 as requested by the test. */ -- psa_set_key_usage_flags(&key_attr, opaque_usage); -- psa_set_key_algorithm(&key_attr, opaque_alg); -- if (opaque_alg2 != PSA_ALG_NONE) { -- psa_set_key_enrollment_algorithm(&key_attr, opaque_alg2); -- } -- TEST_EQUAL(mbedtls_pk_import_into_psa(ep->pkey, &key_attr, &key_slot), 0); -- mbedtls_pk_free(ep->pkey); -- mbedtls_pk_init(ep->pkey); -- TEST_EQUAL(mbedtls_pk_wrap_psa(ep->pkey, key_slot), 0); ++#if defined(TEST_WOLFPSA) + (void) opaque_alg2; + (void) opaque_usage; + NOT_PORTED("opaque keys"); + goto exit; ++#else + psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; + /* Use a fake key usage to get a successful initial guess for the PSA attributes. */ + TEST_EQUAL(mbedtls_pk_get_psa_attributes(ep->pkey, PSA_KEY_USAGE_SIGN_HASH, +@@ -774,6 +782,7 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep, + mbedtls_pk_free(ep->pkey); + mbedtls_pk_init(ep->pkey); + TEST_EQUAL(mbedtls_pk_wrap_psa(ep->pkey, key_slot), 0); ++#endif /* TEST_WOLFPSA */ } mbedtls_ssl_conf_ca_chain(&(ep->conf), ep->ca_chain, NULL); -@@ -817,16 +785,8 @@ int mbedtls_test_ssl_endpoint_init_conf( - mbedtls_ssl_config_init(&(ep->conf)); - mbedtls_test_message_socket_init(&ep->dtls_context); - -- TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&ep->conf) == NULL); -- TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf), 0); -- TEST_ASSERT(mbedtls_ssl_get_user_data_p(&ep->ssl) == NULL); -- TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), 0); -- -- (void) mbedtls_test_rnd_std_rand(NULL, -- (void *) &ep->user_data_cookie, -- sizeof(ep->user_data_cookie)); -- mbedtls_ssl_conf_set_user_data_n(&ep->conf, ep->user_data_cookie); -- mbedtls_ssl_set_user_data_n(&ep->ssl, ep->user_data_cookie); -+ NOT_PORTED("user data"); -+ goto exit; - - mbedtls_test_mock_socket_init(&(ep->socket)); - -@@ -864,7 +824,8 @@ int mbedtls_test_ssl_endpoint_init_conf( +@@ -864,7 +873,12 @@ int mbedtls_test_ssl_endpoint_init_conf( } if (options->group_list != NULL) { -- mbedtls_ssl_conf_groups(&(ep->conf), options->group_list); ++#if defined(TEST_WOLFPSA) + NOT_PORTED("mbedtls_ssl_conf_groups"); + goto exit; ++#else + mbedtls_ssl_conf_groups(&(ep->conf), options->group_list); ++#endif /* TEST_WOLFPSA */ } if (MBEDTLS_SSL_IS_SERVER == endpoint_type) { -@@ -960,11 +921,8 @@ int mbedtls_test_ssl_endpoint_init_conf( - } - #endif +@@ -1043,8 +1057,10 @@ void mbedtls_test_ssl_endpoint_free( + memcpy(&ssl_before, &(ep->ssl), sizeof(mbedtls_ssl_context)); -- TEST_EQUAL(mbedtls_ssl_conf_get_user_data_n(&ep->conf), -- ep->user_data_cookie); -- mbedtls_ssl_conf_set_user_data_p(&ep->conf, ep); -- -- return 0; -+ NOT_PORTED("user data"); -+ goto exit; - - exit: - if (ret == 0) { -@@ -1007,10 +965,8 @@ int mbedtls_test_ssl_endpoint_init_ssl( - NULL); - } - -- TEST_EQUAL(mbedtls_ssl_get_user_data_n(&ep->ssl), ep->user_data_cookie); -- mbedtls_ssl_set_user_data_p(&ep->ssl, ep); -- -- return 0; -+ NOT_PORTED("user data"); -+ goto exit; - - exit: - if (ret == 0) { -@@ -1037,14 +993,7 @@ void mbedtls_test_ssl_endpoint_free( - { - // mbedtls_ssl_session_reset() requires the SSL to be setup. - if (ep->ssl.conf != NULL) { -- mbedtls_ssl_context ssl_before; -- -- /* Dump the SSL context before resetting it */ -- memcpy(&ssl_before, &(ep->ssl), sizeof(mbedtls_ssl_context)); -- -- mbedtls_ssl_session_reset(&(ep->ssl)); -- /* Check that required fields were properly reset */ -- mbedtls_test_ssl_check_context_after_session_reset(&ssl_before, &(ep->ssl)); -+ NOT_PORTED("session reset check"); + mbedtls_ssl_session_reset(&(ep->ssl)); ++#if defined(TEST_SSL_INTERNALS) + /* Check that required fields were properly reset */ + mbedtls_test_ssl_check_context_after_session_reset(&ssl_before, &(ep->ssl)); ++#endif /* TEST_SSL_INTERNALS */ } mbedtls_ssl_free(&(ep->ssl)); mbedtls_ssl_config_free(&(ep->conf)); -@@ -1081,6 +1030,8 @@ exit: +@@ -1081,6 +1097,8 @@ exit: return ret; } @@ -166,7 +120,7 @@ index ebb9103..4a99a38 100644 int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, mbedtls_ssl_context *second_ssl, int state) -@@ -1116,6 +1067,7 @@ int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, +@@ -1116,6 +1134,7 @@ int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, return (max_steps >= 0) ? ret : -1; } @@ -174,7 +128,7 @@ index ebb9103..4a99a38 100644 #endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */ -@@ -1207,6 +1159,8 @@ exit: +@@ -1207,6 +1226,8 @@ exit: return -1; } @@ -183,7 +137,7 @@ index ebb9103..4a99a38 100644 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ defined(PSA_WANT_ALG_CBC_NO_PADDING) && defined(PSA_WANT_KEY_TYPE_AES) int mbedtls_test_psa_cipher_encrypt_helper(mbedtls_ssl_transform *transform, -@@ -1704,7 +1658,10 @@ exit: +@@ -1704,7 +1725,10 @@ exit: return -1; } #endif /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */ @@ -194,7 +148,7 @@ index ebb9103..4a99a38 100644 #if defined(MBEDTLS_SSL_PROTO_TLS1_2) int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session, int ticket_len, -@@ -1885,6 +1842,7 @@ int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session, +@@ -1885,6 +1909,7 @@ int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session, return 0; } #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ @@ -202,85 +156,104 @@ index ebb9103..4a99a38 100644 int mbedtls_test_ssl_exchange_data( mbedtls_ssl_context *ssl_1, -@@ -2018,7 +1976,9 @@ static int check_ssl_version( +@@ -2018,7 +2043,8 @@ static int check_ssl_version( /* First check that both sides have chosen the same version. * If so, we can make more sanity checks just on one side. * If not, something is deeply wrong. */ - TEST_EQUAL(client->tls_version, server->tls_version); -+ (void) server; -+ NOT_PORTED("negotiated version"); -+ goto exit; ++ TEST_EQUAL(mbedtls_ssl_get_version_number(client), ++ mbedtls_ssl_get_version_number(server)); /* Make further checks on the client to validate that the * reported data about the version is correct. */ -@@ -2026,8 +1986,6 @@ static int check_ssl_version( +@@ -2026,7 +2052,7 @@ static int check_ssl_version( mbedtls_ssl_protocol_version version_number = mbedtls_ssl_get_version_number(client); - TEST_EQUAL(client->tls_version, expected_negotiated_version); -- ++ TEST_EQUAL(version_number, expected_negotiated_version); + if (client->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { TEST_EQUAL(version_string[0], 'D'); - ++version_string; -@@ -2102,12 +2060,8 @@ int mbedtls_test_ssl_do_handshake_with_endpoints( - if (ret != 0 && ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { - return ret; - } -- if (!mbedtls_ssl_is_handshake_over(&client_ep->ssl) || -- !mbedtls_ssl_is_handshake_over(&server_ep->ssl)) { -- return -1; -- } -- -- return 0; -+ NOT_PORTED("handshake state"); -+ return -1; - } - #endif /* defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) */ +@@ -2124,24 +2150,30 @@ static int test_renegotiation(const mbedtls_test_handshake_test_options *options + (void) options; // only used in some configurations -@@ -2310,7 +2264,8 @@ int mbedtls_test_ssl_perform_connection( - goto exit; - } + /* Start test with renegotiation */ ++#if defined(TEST_SSL_INTERNALS) + TEST_EQUAL(server->ssl.renego_status, + MBEDTLS_SSL_INITIAL_HANDSHAKE); + TEST_EQUAL(client->ssl.renego_status, + MBEDTLS_SSL_INITIAL_HANDSHAKE); ++#endif /* TEST_SSL_INTERNALS */ + + /* After calling this function for the server, it only sends a handshake + * request. All renegotiation should happen during data exchanging */ + TEST_EQUAL(mbedtls_ssl_renegotiate(&(server->ssl)), 0); ++#if defined(TEST_SSL_INTERNALS) + TEST_EQUAL(server->ssl.renego_status, + MBEDTLS_SSL_RENEGOTIATION_PENDING); + TEST_EQUAL(client->ssl.renego_status, + MBEDTLS_SSL_INITIAL_HANDSHAKE); ++#endif /* TEST_SSL_INTERNALS */ + + TEST_EQUAL(exchange_data(&(client->ssl), &(server->ssl)), 0); ++#if defined(TEST_SSL_INTERNALS) + TEST_EQUAL(server->ssl.renego_status, + MBEDTLS_SSL_RENEGOTIATION_DONE); + TEST_EQUAL(client->ssl.renego_status, + MBEDTLS_SSL_RENEGOTIATION_DONE); ++#endif /* TEST_SSL_INTERNALS */ -- TEST_EQUAL(mbedtls_ssl_is_handshake_over(&client->ssl), 1); -+ NOT_PORTED("handshake state"); -+ goto exit; - - /* Make sure server state is moved to HANDSHAKE_OVER also. */ - TEST_EQUAL(mbedtls_test_move_handshake_to_state(&(server->ssl), -@@ -2318,16 +2273,14 @@ int mbedtls_test_ssl_perform_connection( - MBEDTLS_SSL_HANDSHAKE_OVER), - 0); - -- TEST_EQUAL(mbedtls_ssl_is_handshake_over(&server->ssl), 1); -- - /* Check that both sides have negotiated the expected version. */ - TEST_ASSERT(check_ssl_version(options->expected_negotiated_version, - &client->ssl, + /* After calling mbedtls_ssl_renegotiate for the client, + * all renegotiation should happen inside this function. +@@ -2160,16 +2192,20 @@ static int test_renegotiation(const mbedtls_test_handshake_test_options *options + TEST_ASSERT(ret == 0 || + ret == MBEDTLS_ERR_SSL_WANT_READ || + ret == MBEDTLS_ERR_SSL_WANT_WRITE); ++#if defined(TEST_SSL_INTERNALS) + TEST_EQUAL(server->ssl.renego_status, + MBEDTLS_SSL_RENEGOTIATION_DONE); + TEST_EQUAL(client->ssl.renego_status, + MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS); ++#endif /* TEST_SSL_INTERNALS */ + + TEST_EQUAL(exchange_data(&(client->ssl), &(server->ssl)), 0); ++#if defined(TEST_SSL_INTERNALS) + TEST_EQUAL(server->ssl.renego_status, + MBEDTLS_SSL_RENEGOTIATION_DONE); + TEST_EQUAL(client->ssl.renego_status, + MBEDTLS_SSL_RENEGOTIATION_DONE); ++#endif /* TEST_SSL_INTERNALS */ + #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) + /* Validate buffer sizes after renegotiation */ + if (options->resize_buffers != 0) { +@@ -2326,7 +2362,7 @@ int mbedtls_test_ssl_perform_connection( &server->ssl)); if (options->expected_ciphersuite != 0) { - TEST_EQUAL(server->ssl.session->ciphersuite, -- options->expected_ciphersuite); -+ NOT_PORTED("negotiated cipher suite"); -+ goto exit; ++ TEST_EQUAL(mbedtls_ssl_get_ciphersuite_id_from_ssl(&server->ssl), + options->expected_ciphersuite); } - if (options->post_handshake_fun != NULL) { -@@ -2417,10 +2370,8 @@ void mbedtls_test_ssl_perform_handshake( - - TEST_ASSERT(mbedtls_test_ssl_perform_connection(options, client, server)); +@@ -2580,6 +2616,8 @@ int mbedtls_test_ticket_parse(void *p_ticket, mbedtls_ssl_session *session, + } + #endif /* MBEDTLS_SSL_SESSION_TICKETS */ -- TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&client->conf) == client); -- TEST_ASSERT(mbedtls_ssl_get_user_data_p(&client->ssl) == client); -- TEST_ASSERT(mbedtls_ssl_conf_get_user_data_p(&server->conf) == server); -- TEST_ASSERT(mbedtls_ssl_get_user_data_p(&server->ssl) == server); -+ NOT_PORTED("user data"); -+ goto exit; ++/* Internal cases only */ ++#if defined(TEST_SSL_INTERNALS) + #if defined(MBEDTLS_SSL_CLI_C) && defined(MBEDTLS_SSL_SRV_C) && \ + defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS) && \ + defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) +@@ -2641,5 +2679,6 @@ exit: + #endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_SSL_SRV_C && + MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS && + MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */ ++#endif /* TEST_SSL_INTERNALS */ - if (options->pre_shutdown_fun != NULL) { - options->pre_shutdown_fun(client, server, options->pre_shutdown_param); + #endif /* MBEDTLS_SSL_TLS_C */ diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function -index 7a9a03a..c70bd31 100644 +index 7a9a03a..903815e 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -1,18 +1,11 @@ @@ -303,7 +276,24 @@ index 7a9a03a..c70bd31 100644 #include #define SSL_MESSAGE_QUEUE_INIT { NULL, 0, 0, 0 } -@@ -203,8 +196,9 @@ typedef struct { +@@ -97,6 +90,8 @@ static int failing_ticket_write_unset_lifetime( + PSA_WANT_ALG_SHA_256 && PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY && + MBEDTLS_CAN_HANDLE_RSA_TEST_KEY */ + ++/* Internal cases only */ ++#if defined(TEST_SSL_INTERNALS) + #if defined(MBEDTLS_SSL_TLS_C) && defined(MBEDTLS_DEBUG_C) && \ + defined(MBEDTLS_SSL_CLI_C) && defined(MBEDTLS_SSL_SRV_C) && \ + defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) && \ +@@ -143,6 +138,7 @@ static void tls_abort_transcript(void *ctx, int level, + #endif + } + #endif ++#endif /* TEST_SSL_INTERNALS */ + + #if (!defined(MBEDTLS_SSL_PROTO_TLS1_2)) && \ + defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C) && \ +@@ -203,8 +199,9 @@ typedef struct { static void pre_handshake_tweak_context(mbedtls_ssl_context *ssl, int tweaks) { @@ -314,23 +304,19 @@ index 7a9a03a..c70bd31 100644 } } -@@ -273,15 +267,10 @@ static void simulate_badmac_seen_on(mbedtls_test_ssl_endpoint *client, - mbedtls_test_ssl_endpoint *server, +@@ -274,12 +271,12 @@ static void simulate_badmac_seen_on(mbedtls_test_ssl_endpoint *client, void *param) { -- int on = *(int *) param; -- switch (on) { -- case MBEDTLS_SSL_IS_CLIENT: + int on = *(int *) param; ++ (void) client; ++ (void) server; + switch (on) { + case MBEDTLS_SSL_IS_CLIENT: - client->ssl.badmac_seen = 1; - break; -- case MBEDTLS_SSL_IS_SERVER: + case MBEDTLS_SSL_IS_SERVER: - server->ssl.badmac_seen = 1; -- break; -- } -+ (void) client; -+ (void) server; -+ (void) param; -+ mbedtls_test_fail("badmac_seen is internal", __LINE__, __FILE__); ++ mbedtls_test_fail("badmac_seen is internal", __LINE__, __FILE__); + break; + } } - #endif - diff --git a/test/mbedtls_compat/ssl_suite/ssl_helpers_port.c b/test/mbedtls_compat/ssl_suite/ssl_helpers_port.c index bcd9219..f5f033d 100644 --- a/test/mbedtls_compat/ssl_suite/ssl_helpers_port.c +++ b/test/mbedtls_compat/ssl_suite/ssl_helpers_port.c @@ -23,43 +23,219 @@ #include "ssl_helpers_port.h" -#if defined(MBEDTLS_SSL_TLS_C) +#include -#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) +#if defined(MBEDTLS_SSL_TLS_C) && \ + defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) + +static int Waiting(int ret) +{ + return ret == MBEDTLS_ERR_SSL_WANT_READ || + ret == MBEDTLS_ERR_SSL_WANT_WRITE; +} + +/* The handshake state is not public. HANDSHAKE_OVER runs both handshakes + * until mbedtls_ssl_handshake() on ssl returns 0; an earlier state stops + * after one round. */ int mbedtls_test_move_handshake_to_state(mbedtls_ssl_context *ssl, mbedtls_ssl_context *second_ssl, int state) { - (void)ssl; - (void)second_ssl; - (void)state; - NOT_PORTED("handshake state"); - return -1; + int rounds = (state == MBEDTLS_SSL_HANDSHAKE_OVER) ? 1000 : 1; + int ret; + + if (ssl == NULL || second_ssl == NULL) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + } + do { + if (!mbedtls_ssl_is_handshake_over(second_ssl)) { + ret = mbedtls_ssl_handshake(second_ssl); + if (ret != 0 && !Waiting(ret)) { + return ret; + } + } + ret = mbedtls_ssl_handshake(ssl); + if (ret != 0 && !Waiting(ret)) { + return ret; + } + } while (ret != 0 && --rounds > 0); + + if (state == MBEDTLS_SSL_HANDSHAKE_OVER && ret != 0) { + return -1; + } + return ret; +} + +#if defined(MBEDTLS_SSL_SESSION_TICKETS) +typedef struct { + mbedtls_ssl_session *session; /* gets the server's session, then NULL */ + size_t ticketLen; + int ret; +} TicketParam; + +/* No public copy: a save and a load */ +static int CopySession(mbedtls_ssl_session *dst, + const mbedtls_ssl_session *src) +{ + unsigned char *buf = NULL; + size_t len = 0; + int ret = mbedtls_ssl_session_save(src, NULL, 0, &len); + + if (ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) { + buf = mbedtls_calloc(1, len); + ret = (buf == NULL) ? MBEDTLS_ERR_SSL_ALLOC_FAILED : + mbedtls_ssl_session_save(src, buf, len, &len); + } + if (ret == 0) { + ret = mbedtls_ssl_session_load(dst, buf, len); + } + mbedtls_free(buf); + return ret; +} + +/* A ticket of ticketLen bytes, filled as Mbed TLS's helper filled it */ +static int TicketWrite(void *p_ticket, const mbedtls_ssl_session *session, + unsigned char *start, const unsigned char *end, size_t *tlen, + uint32_t *lifetime) +{ + TicketParam *param = (TicketParam *)p_ticket; + + if (param->session != NULL) { + param->ret = CopySession(param->session, session); + param->session = NULL; + } + if ((size_t)(end - start) < param->ticketLen) { + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL; + } + memset(start, 33, param->ticketLen); + *tlen = param->ticketLen; + *lifetime = 86401; + return 0; +} +#endif /* MBEDTLS_SSL_SESSION_TICKETS */ + +#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS) +static int ReadTicket(mbedtls_ssl_context *ssl) +{ + unsigned char buf[1]; + int ret = MBEDTLS_ERR_SSL_WANT_READ; + int i; + + for (i = 0; i < 10 && ret == MBEDTLS_ERR_SSL_WANT_READ; i++) { + ret = mbedtls_ssl_read(ssl, buf, sizeof(buf)); + } + return (ret == MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET) ? 0 : ret; +} +#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */ + +/* A session from a handshake on the mock transport, where Mbed TLS sets the + * session's fields. The server's comes from the ticket callback, as + * mbedtls_ssl_get_session() is client only. Without withCert, a PSK + * handshake: no peer certificate. */ +static int PopulateSession(mbedtls_ssl_session *session, + mbedtls_ssl_protocol_version version, int endpoint_type, + size_t ticketLen, int withCert) +{ +#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED) + static uint8_t pskKey[] = "populate_session"; + data_t psk = { pskKey, sizeof(pskKey) - 1 }; +#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */ +#if defined(MBEDTLS_SSL_SESSION_TICKETS) + TicketParam param = { NULL, 0, 0 }; +#endif /* MBEDTLS_SSL_SESSION_TICKETS */ + mbedtls_test_handshake_test_options options; + mbedtls_test_ssl_endpoint client; + mbedtls_test_ssl_endpoint server; + int ok = 0; + + memset(&client, 0, sizeof(client)); + memset(&server, 0, sizeof(server)); + mbedtls_test_init_handshake_options(&options); + options.client_min_version = version; + options.client_max_version = version; + options.server_min_version = version; + options.server_max_version = version; + options.expected_negotiated_version = version; + /* server5.crt, the crt_file of the cases with a certificate */ + options.pk_alg = MBEDTLS_PK_ECDSA; + /* The server's certificate only, and no data */ + options.srv_auth_mode = MBEDTLS_SSL_VERIFY_NONE; + options.cli_msg_len = 0; + options.srv_msg_len = 0; + + TEST_ASSERT(endpoint_type == MBEDTLS_SSL_IS_CLIENT || + endpoint_type == MBEDTLS_SSL_IS_SERVER); + if (!withCert) { +#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED) + options.psk_str = &psk; + options.cipher = "TLS-PSK-WITH-AES-128-GCM-SHA256"; +#else + TEST_FAIL("a session without a certificate needs PSK"); +#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */ + } + + TEST_EQUAL(mbedtls_test_ssl_endpoint_init(&client, MBEDTLS_SSL_IS_CLIENT, + &options), 0); + TEST_EQUAL(mbedtls_test_ssl_endpoint_init(&server, MBEDTLS_SSL_IS_SERVER, + &options), 0); + + if (ticketLen > 0 || endpoint_type == MBEDTLS_SSL_IS_SERVER) { +#if defined(MBEDTLS_SSL_SESSION_TICKETS) + param.ticketLen = ticketLen; + if (endpoint_type == MBEDTLS_SSL_IS_SERVER) { + param.session = session; + } + mbedtls_ssl_conf_session_tickets_cb(&server.conf, TicketWrite, + mbedtls_test_ticket_parse, + ¶m); +#else + TEST_FAIL("needs session tickets"); +#endif /* MBEDTLS_SSL_SESSION_TICKETS */ + } + + TEST_ASSERT(mbedtls_test_ssl_perform_connection(&options, &client, + &server)); + + if (endpoint_type == MBEDTLS_SSL_IS_SERVER) { +#if defined(MBEDTLS_SSL_SESSION_TICKETS) + TEST_ASSERT(param.session == NULL); + TEST_EQUAL(param.ret, 0); +#endif /* MBEDTLS_SSL_SESSION_TICKETS */ + } + else { +#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS) + if (version == MBEDTLS_SSL_VERSION_TLS1_3) { + TEST_EQUAL(ReadTicket(&client.ssl), 0); + } +#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */ + TEST_EQUAL(mbedtls_ssl_get_session(&client.ssl, session), 0); + } + ok = 1; + +exit: + mbedtls_test_ssl_endpoint_free(&client); + mbedtls_test_ssl_endpoint_free(&server); + mbedtls_test_free_handshake_options(&options); + return ok ? 0 : -1; } -#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */ #if defined(MBEDTLS_SSL_PROTO_TLS1_2) +/* crt_file is empty, NULL or server5.crt */ int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session, int ticket_len, int endpoint_type, const char *crt_file) { - (void)session; - (void)ticket_len; - (void)endpoint_type; - (void)crt_file; - NOT_PORTED("session fields"); - return -1; + return PopulateSession(session, MBEDTLS_SSL_VERSION_TLS1_2, endpoint_type, + (size_t)ticket_len, crt_file != NULL && crt_file[0] != '\0'); } #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */ #if defined(MBEDTLS_SSL_PROTO_TLS1_3) +/* A TLS 1.3 session is a ticket, so never an empty one */ int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session, int ticket_len, int endpoint_type) { - (void)session; - (void)ticket_len; - (void)endpoint_type; - NOT_PORTED("session fields"); - return -1; + return PopulateSession(session, MBEDTLS_SSL_VERSION_TLS1_3, endpoint_type, + (ticket_len > 0) ? (size_t)ticket_len : 1, 1); } #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ -#endif /* MBEDTLS_SSL_TLS_C */ +#endif /* MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */ From 3b69d57684404170f379c23be7a108a53239648f Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 16:15:42 -0800 Subject: [PATCH 05/10] Run our test suite against Mbed --- Makefile | 7 ++- test/mbedtls_compat/Makefile | 46 +++++++++++++++----- test/mbedtls_compat/ssl_suite/CMakeLists.txt | 35 +++++++++++++++ test/mbedtls_compat/ssl_suite/cases.txt | 5 +-- test/mbedtls_compat/ssl_suite/check.py | 15 +++++-- wolfpsa/mbedtls_compat/mbedtls/build_info.h | 3 ++ 6 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 test/mbedtls_compat/ssl_suite/CMakeLists.txt diff --git a/Makefile b/Makefile index 21a3f92..1e4b046 100644 --- a/Makefile +++ b/Makefile @@ -324,8 +324,13 @@ $(MBEDTLS_COMPAT_TESTS): mbedtls-compat-%: $(LIBNAME) mbedtls-compat-suite-patch: $(MBEDTLS_COMPAT_MAKE) suite-patch + +# The suite on Mbed TLS's own libraries, without wolfSSL or wolfPSA +mbedtls-compat-suite-ref: + $(MBEDTLS_COMPAT_MAKE) suite-ref else -$(MBEDTLS_COMPAT_TESTS) mbedtls-compat-suite-patch: +$(MBEDTLS_COMPAT_TESTS) mbedtls-compat-suite-patch \ + mbedtls-compat-suite-ref: @echo "Run make MBEDTLS_COMPAT=1 $@"; exit 1 endif diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index f9a2959..97d7d2f 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -71,8 +71,6 @@ SUITE := $(CURDIR)/ssl_suite SUITE_BUILD := $(BUILD_DIR)/ssl_suite SUITE_PATCHED := $(MBEDTLS_CLONE)-patched SUITE_NAME := $(SUITE_BUILD)/test_suite_ssl_public -SUITE_OUTCOME := $(SUITE_BUILD)/outcome.csv -SUITE_LOG := $(SUITE_BUILD)/test_suite_ssl_public.log SUITE_HELPERS := $(addprefix $(SUITE_BUILD)/,helpers.o random.o \ threading_helpers.o test_memory.o) SUITE_OBJS := $(SUITE_NAME).o $(SUITE_BUILD)/ssl_helpers.o \ @@ -86,6 +84,22 @@ SUITE_FLAGS := $(LAYER_FLAGS) -DTEST_WOLFPSA -I$(SUITE) -I$(SUITE)/shim \ tf-psa-crypto/tests/include framework/tests/src) \ -idirafter $(MBEDTLS_CLONE)/tf-psa-crypto/core SUITE_PUBLIC_HEADERS := $(MBEDTLS_CLONE)/(tf-psa-crypto/)?include/ +# The same suite and ssl_helpers_port.c on Mbed TLS's CMake build of the clone +REF_BUILD := $(BUILD_DIR)/ssl_suite_ref +REF_NAME := $(REF_BUILD)/test_suite_ssl_public + +# $(call run_suite,title,check.py options) runs the suite $< from the clone's +# tests/, for the .data's ../framework/data_files paths. check.py compares +# each case with cases.txt, not the suite's exit code. +define run_suite +@rm -f $(dir $<)outcome.csv +cd $(MBEDTLS_CLONE)/tests && \ + MBEDTLS_TEST_OUTCOME_FILE=$(dir $<)outcome.csv $(WRAP) $< \ + $(SUITE_NAME).datax > $<.log 2>&1 || true +@echo "$(1), $(MBEDTLS_REF)" +@python3 $(SUITE)/check.py $(2) $(SUITE)/cases.txt $(dir $<)outcome.csv || \ + { echo "Log: $<.log"; exit 1; } +endef # $(call link,flags,libraries) links the C source and objects among the # prerequisites @@ -99,7 +113,8 @@ export BUILD_DIR WOLFSSL_PATH WOLFSSL_SERVER WOLFSSL_CLIENT MBEDTLS_PATH \ ASAN_LINK_ORDER := verify_asan_link_order=0 export ASAN_OPTIONS := $(if $(ASAN_OPTIONS),$(ASAN_OPTIONS):)$(ASAN_LINK_ORDER) -.PHONY: test unit programs suite suite-patch data-check wolfssl-check FORCE +.PHONY: test unit programs suite suite-ref suite-patch data-check \ + wolfssl-check FORCE test: unit programs suite @@ -113,15 +128,13 @@ programs: $(CLIENT) $(PROGRAMS) $(WOLFSSL_SERVER) $(WOLFSSL_CLIENT) | \ data-check ./programs.sh -# check.py compares each case with cases.txt, not the suite's exit code suite: $(SUITE_NAME) - @rm -f $(SUITE_OUTCOME) - cd $(MBEDTLS_CLONE)/tests && \ - MBEDTLS_TEST_OUTCOME_FILE=$(SUITE_OUTCOME) $(WRAP) $< \ - $<.datax > $(SUITE_LOG) 2>&1 || true - @echo "Mbed TLS ssl suite, $(MBEDTLS_REF)" - @python3 $(SUITE)/check.py $(SUITE)/cases.txt $(SUITE_OUTCOME) || \ - { echo "Log: $(SUITE_LOG)"; exit 1; } + $(call run_suite,Mbed TLS ssl suite) + +# Run our modified suite on Mbed TLS's own libraries. Every case must pass, +# which shows the ported helpers still test what upstream's do. +suite-ref: $(REF_NAME) + $(call run_suite,Mbed TLS ssl suite on Mbed TLS,--all-pass) # Saves the clone's changes to mbedtls.patch, below its license lines suite-patch: @@ -217,6 +230,17 @@ $(SUITE_OBJS): $(SUITE_PATCHED) $(SUITE_NAME): $(SUITE_OBJS) $(CERTS) $(WOLFPSA_LIB) $(SUITE_NAME).datax $(call link,,$(LAYER_LIBS)) +# Mbed TLS's CMake build needs tf-psa-crypto's own framework submodule, and +# Python's jinja2 and jsonschema +$(REF_BUILD)/CMakeCache.txt: $(MBEDTLS_STAMP) | $(SUITE_PATCHED) + git -C $(MBEDTLS_CLONE) submodule update -q --init --depth 1 --recursive + cmake -S $(SUITE) -B $(REF_BUILD) -DCMAKE_BUILD_TYPE=Release \ + -DMBEDTLS_DIR=$(MBEDTLS_CLONE) -DSUITE_C=$(SUITE_NAME).c + +# CMake tracks the sources +$(REF_NAME): $(REF_BUILD)/CMakeCache.txt $(SUITE_NAME).datax FORCE + +cmake --build $(REF_BUILD) --target $(@F) + -include $(SUITE_OBJS:.o=.d) # configure refuses a clone that is configured in place. autogen.sh only adds diff --git a/test/mbedtls_compat/ssl_suite/CMakeLists.txt b/test/mbedtls_compat/ssl_suite/CMakeLists.txt new file mode 100644 index 0000000..365265b --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/CMakeLists.txt @@ -0,0 +1,35 @@ +# The selected ssl suite against Mbed TLS itself: the patched clone's +# libraries and test helpers, with ssl_helpers_port.c. Built by +# make MBEDTLS_COMPAT=1 mbedtls-compat-suite-ref. +# +# Copyright (C) 2026 wolfSSL Inc. +# SPDX-License-Identifier: GPL-3.0-or-later +# +# MBEDTLS_DIR: the clone. SUITE_C: the generated test_suite_ssl_public.c. + +cmake_minimum_required(VERSION 3.10.2) +project(ssl_suite_ref C) + +set(ENABLE_PROGRAMS OFF CACHE BOOL "") +set(ENABLE_TESTING ON CACHE BOOL "") +add_subdirectory(${MBEDTLS_DIR} mbedtls) + +# The patched ssl_helpers.c includes ssl_helpers_port.h +target_include_directories(mbedtls_test_helpers + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + +# As Mbed TLS's own suites, see add_test_suite in its tests/CMakeLists.txt. +# The helpers' options: set_base_compile_options needs Mbed TLS's variables. +add_executable(test_suite_ssl_public ${SUITE_C} ssl_helpers_port.c + $ $) +target_compile_options(test_suite_ssl_public PRIVATE + $) +target_include_directories(test_suite_ssl_public PRIVATE + $) +target_compile_definitions(test_suite_ssl_public + PRIVATE _POSIX_C_SOURCE=200809L) +target_link_libraries(test_suite_ssl_public mbedtls) +set_target_properties(test_suite_ssl_public PROPERTIES C_STANDARD 11) +# The header's static functions include some for cases left out +set_source_files_properties(${SUITE_C} + PROPERTIES COMPILE_OPTIONS -Wno-unused-function) diff --git a/test/mbedtls_compat/ssl_suite/cases.txt b/test/mbedtls_compat/ssl_suite/cases.txt index ce7d09f..5fbb1d2 100644 --- a/test/mbedtls_compat/ssl_suite/cases.txt +++ b/test/mbedtls_compat/ssl_suite/cases.txt @@ -9,7 +9,6 @@ # passes. notrun is left out of the run. # # Waits on, for fail: -# pss MBEDTLS_X509_RSASSA_PSS_SUPPORT # session mbedtls_ssl_session_save and _load; PSK too for a session # without a certificate # ticket session tickets, then session save and load @@ -69,7 +68,7 @@ mock pass - Message transport mock - two-way interleaved sends/r target pass - Test mbedtls_endpoint sanity for the client target pass - Test mbedtls_endpoint sanity for the server target pass - Handshake, tls1_2 -target fail pss Handshake, tls1_3 +target pass - Handshake, tls1_3 target pass - Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 target pass - Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 target pass - Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 @@ -85,7 +84,7 @@ target fail context DTLS Handshake with serialization, tls1_2 target fail dtls DTLS Handshake fragmentation, MFL=512 target fail dtls DTLS Handshake fragmentation, MFL=1024 target notrun tls13-off Handshake min/max version check, all -> 1.2 -target fail pss Handshake min/max version check, all -> 1.3 +target pass - Handshake min/max version check, all -> 1.3 target pass - Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, non-opaque target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_ANY_HASH target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_SHA_384 diff --git a/test/mbedtls_compat/ssl_suite/check.py b/test/mbedtls_compat/ssl_suite/check.py index e6b2bc4..9709f6f 100644 --- a/test/mbedtls_compat/ssl_suite/check.py +++ b/test/mbedtls_compat/ssl_suite/check.py @@ -5,8 +5,9 @@ # # Prints what passes per group and what the rest waits on, then each case # whose outcome differs from cases.txt, and exits 1 if there is one. +# --all-pass: every case that runs must pass, as against Mbed TLS itself. # -# Usage: check.py CASES OUTCOME +# Usage: check.py [--all-pass] CASES OUTCOME import collections import sys @@ -15,15 +16,21 @@ def main(): - if len(sys.argv) != 3: - sys.exit('Usage: check.py CASES OUTCOME') - cases_path, outcome_path = sys.argv[1:] + args = sys.argv[1:] + all_pass = args[:1] == ['--all-pass'] + if all_pass: + args = args[1:] + if len(args) != 2: + sys.exit('Usage: check.py [--all-pass] CASES OUTCOME') + cases_path, outcome_path = args cases = {} with open(cases_path, encoding='ascii') as f: for line in f: if line.strip() and not line.startswith('#'): group, expect, waits, desc = line.split(None, 3) + if all_pass and expect == 'fail': + expect = 'pass' cases[desc.strip()] = (group, expect, waits) results = {} diff --git a/wolfpsa/mbedtls_compat/mbedtls/build_info.h b/wolfpsa/mbedtls_compat/mbedtls/build_info.h index 57f3f9c..b4c057a 100644 --- a/wolfpsa/mbedtls_compat/mbedtls/build_info.h +++ b/wolfpsa/mbedtls_compat/mbedtls/build_info.h @@ -38,6 +38,9 @@ /* MBEDTLS_X509_CRT_PARSE_C and MBEDTLS_SSL_* are in the generated config */ #if defined(MBEDTLS_X509_CRT_PARSE_C) #define MBEDTLS_X509_USE_C +#if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) && defined(PSA_WANT_ALG_RSA_PSS) + #define MBEDTLS_X509_RSASSA_PSS_SUPPORT +#endif /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY && PSA_WANT_ALG_RSA_PSS */ #endif /* MBEDTLS_X509_CRT_PARSE_C */ #if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(PSA_WANT_ALG_ECDH) #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED From 81905fff5a349fc2e8a33eec1a26c0a6bf770c16 Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 16:35:27 -0800 Subject: [PATCH 06/10] Split Mbed TLS compat tests into unit, programs and suite targets, add help --- Makefile | 76 +++++++++++++++++++++++------------- test/mbedtls_compat/Makefile | 7 ++-- 2 files changed, 53 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 1e4b046..ab4e33a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ -# Simple static build for wolfPSA +# Simple static build for wolfPSA. make help lists the "## " lines: options +# and targets. +## WOLFSSL_PATH=dir: wolfSSL source tree, default ../wolfssl WOLFSSL_PATH ?= ../wolfssl USER_SETTINGS_PATH ?= $(CURDIR)/wolfpsa PSA_INCLUDE ?= @@ -79,8 +81,9 @@ WOLFCRYPT_SRC := \ WOLFCRYPT_OBJ := $(patsubst $(WOLFSSL_PATH)/wolfcrypt/src/%.c,$(OBJDIR)/wolfcrypt_%.o,$(WOLFCRYPT_SRC)) WOLFCRYPT_OBJ_PIC := $(patsubst $(WOLFSSL_PATH)/wolfcrypt/src/%.c,$(OBJDIR_PIC)/wolfcrypt_%.o,$(WOLFCRYPT_SRC)) -# MBEDTLS_COMPAT=1 adds the Mbed TLS 4.x TLS, X.509 and network API, on -# wolfSSL's TLS compiled from WOLFSSL_PATH like wolfCrypt. See src/mbedtls/. +## MBEDTLS_COMPAT=1: add the Mbed TLS 4.x API, for mbedtls-compat-* +# The TLS, X.509 and network API, on wolfSSL's TLS compiled from WOLFSSL_PATH +# like wolfCrypt. See src/mbedtls/. WOLFSSL_TLS_SRC := ifeq ($(MBEDTLS_COMPAT),1) CPPFLAGS += -DWOLFPSA_MBEDTLS_COMPAT -I$(CURDIR)/wolfpsa/mbedtls_compat @@ -92,8 +95,8 @@ WOLFSSL_TLS_OBJ := $(patsubst $(WOLFSSL_PATH)/src/%.c,$(OBJDIR)/wolfssl_%.o, \ WOLFSSL_TLS_OBJ_PIC := $(patsubst $(WOLFSSL_PATH)/src/%.c, \ $(OBJDIR_PIC)/wolfssl_%.o,$(WOLFSSL_TLS_SRC)) -# MBEDTLS_THREADING_C=1 builds a thread safe library, as in Mbed TLS. See -# user_settings.h. Applications define MBEDTLS_THREADING_C too. +## MBEDTLS_THREADING_C=1: thread safe library, as in Mbed TLS +# See user_settings.h. Applications define MBEDTLS_THREADING_C too. ifeq ($(MBEDTLS_THREADING_C),1) CPPFLAGS += -DMBEDTLS_THREADING_C LDFLAGS += -pthread @@ -117,20 +120,23 @@ DEPFLAGS := -MMD -MP CFLAGS ?= -O2 WARNFLAGS ?= -Wall -Wextra -Werror CFLAGS += $(WARNFLAGS) +## DEBUG=1: build with -ggdb DEBUG_FLAGS := ifeq ($(DEBUG),1) DEBUG_FLAGS = -ggdb endif +## ASAN=1: build with AddressSanitizer SANITIZE_FLAGS := ifeq ($(ASAN),1) SANITIZE_FLAGS = -fsanitize=address endif -# AES_FAST=1 waives the PSA constant-time AES requirement and takes -# wolfCrypt's faster T-table core instead. See src/psa_config.h. +## AES_FAST=1: faster AES, not constant time +# Waives the PSA constant-time AES requirement and takes wolfCrypt's faster +# T-table core instead. See src/psa_config.h. ifeq ($(AES_FAST),1) CPPFLAGS += -DWOLFPSA_AES_FAST endif -# ENROLLMENT_ALG=1 allows the Mbed TLS enrollment algorithm on volatile keys +## ENROLLMENT_ALG=1: Mbed TLS enrollment algorithm on volatile keys ifeq ($(ENROLLMENT_ALG),1) CPPFLAGS += -DWOLFPSA_ENROLLMENT_ALG endif @@ -149,10 +155,12 @@ LDFLAGS += --coverage endif .PHONY: all clean psa-objects unit-run run-tests cov covclean \ - want-surface-test + want-surface-test help +## all: build libwolfpsa.a and libwolfpsa.so all: $(LIBNAME) $(SHLIBNAME) +## psa-objects: compile wolfPSA's own sources only # Compile only wolfPSA's own sources, skipping the wolfCrypt sources pulled # in from WOLFSSL_PATH. Used by build-config-matrix lanes that exercise a # configuration where wolfPSA's own exclusions are the point and the @@ -184,6 +192,7 @@ $(OBJ) $(OBJ_PIC) $(WOLFCRYPT_OBJ) $(WOLFCRYPT_OBJ_PIC) $(WOLFSSL_TLS_OBJ) \ FORCE: +## want-surface-test: build and run psa_want_surface_test want-surface-test: $(LIBNAME) $(SHLIBNAME) $(CC) $(CPPFLAGS) $(CFLAGS) -o $(BUILD_DIR)/psa_want_surface_test \ test/psa_server/psa_want_surface_test.c $(LIBNAME) $(LDFLAGS) \ @@ -291,8 +300,9 @@ UNIT_TESTS := psa_api_test \ psa_tf_psa_threading_test \ psa_track_memory_test -# Run the unit test loop from the repo root (psa_rsa_pss_interop_test reads -# its certificate relative to the root). Assumes the tests are already built. +## run-tests: run the unit tests, already built +# From the repo root: psa_rsa_pss_interop_test reads its certificate relative +# to the root. run-tests: @for t in $(UNIT_TESTS); do \ echo "=== $$t ==="; \ @@ -300,12 +310,19 @@ run-tests: ./test/$$t || exit 1; \ done -# Build the library and the unit tests, then run every unit test. +## unit-run: build the library and the unit tests, run them unit-run: all @$(MAKE) -C test $(UNIT_TESTS) @$(MAKE) run-tests -# Without MBEDTLS_PATH, test/mbedtls_compat clones Mbed TLS +## MBEDTLS_PATH=dir: Mbed TLS tree for unit and programs, or a clone +## WRAP=cmd: compat test programs run under cmd, like valgrind +## mbedtls-compat-test: unit, programs and suite +## mbedtls-compat-unit: our own tests of the Mbed TLS API +## mbedtls-compat-programs: Mbed TLS's sample programs, with wolfSSL peers +## mbedtls-compat-suite: Mbed TLS's ssl tests, as we modified them +## mbedtls-compat-suite-ref: the modified ssl tests, on Mbed TLS itself +## mbedtls-compat-suite-patch: save the clone's edits to mbedtls.patch MBEDTLS_COMPAT_MAKE = $(MAKE) -C test/mbedtls_compat WOLFPSA_PATH=$(CURDIR) \ WOLFSSL_PATH=$(abspath $(WOLFSSL_PATH)) \ $(if $(MBEDTLS_PATH),MBEDTLS_PATH=$(abspath $(MBEDTLS_PATH))) \ @@ -314,26 +331,22 @@ MBEDTLS_COMPAT_MAKE = $(MAKE) -C test/mbedtls_compat WOLFPSA_PATH=$(CURDIR) \ WOLFSSL_FLAGS="-I$(abspath $(WOLFSSL_PATH)) \ -I$(abspath $(USER_SETTINGS_PATH)) $(WOLFSSL_CPPFLAGS)" \ SANITIZE_FLAGS="$(SANITIZE_FLAGS)" WOLFPSA_LDFLAGS="$(LDFLAGS)" - -# mbedtls-compat- runs in test/mbedtls_compat +# mbedtls-compat- runs in test/mbedtls_compat. These test +# libwolfpsa.a; suite-ref and suite-patch do not use it. MBEDTLS_COMPAT_TESTS := $(addprefix mbedtls-compat-,test unit programs suite) -.PHONY: $(MBEDTLS_COMPAT_TESTS) mbedtls-compat-suite-patch +MBEDTLS_COMPAT_TARGETS := $(MBEDTLS_COMPAT_TESTS) \ + $(addprefix mbedtls-compat-,suite-ref suite-patch) +.PHONY: $(MBEDTLS_COMPAT_TARGETS) ifeq ($(MBEDTLS_COMPAT),1) -$(MBEDTLS_COMPAT_TESTS): mbedtls-compat-%: $(LIBNAME) +$(MBEDTLS_COMPAT_TESTS): $(LIBNAME) +$(MBEDTLS_COMPAT_TARGETS): mbedtls-compat-%: $(MBEDTLS_COMPAT_MAKE) $* - -mbedtls-compat-suite-patch: - $(MBEDTLS_COMPAT_MAKE) suite-patch - -# The suite on Mbed TLS's own libraries, without wolfSSL or wolfPSA -mbedtls-compat-suite-ref: - $(MBEDTLS_COMPAT_MAKE) suite-ref else -$(MBEDTLS_COMPAT_TESTS) mbedtls-compat-suite-patch \ - mbedtls-compat-suite-ref: +$(MBEDTLS_COMPAT_TARGETS): @echo "Run make MBEDTLS_COMPAT=1 $@"; exit 1 endif +## cov: unit test coverage report, in build/coverage # Build everything with gcov instrumentation, run the unit tests, and emit an # HTML coverage report for src/*.c (the bundled wolfCrypt sources are # excluded by the -f filter). The instrumented objects are dropped once the @@ -373,15 +386,24 @@ cov: exit 1; \ fi -# Remove gcov artifacts and the coverage report. +## covclean: remove gcov files and the coverage report covclean: find $(wildcard $(OBJDIR) $(OBJDIR_PIC)) test \ \( -name '*.gcda' -o -name '*.gcno' \) -delete rm -rf $(COV_DIR) +## clean: remove the build directory and the libraries clean: rm -rf $(BUILD_DIR) $(LIBNAME) $(SHLIBNAME) +## help: list these options and targets +help: + @awk '/^## / { i = index($$0, ": "); n = substr($$0, 4, i - 4); \ + l = sprintf(" %-27s %s\n", n, substr($$0, i + 2)); \ + if (n ~ /=/) o = o l; else t = t l } \ + END { printf "Options:\n%sTargets:\n%s", o, t }' \ + $(firstword $(MAKEFILE_LIST)) + -include $(OBJ:.o=.d) $(WOLFCRYPT_OBJ:.o=.d) $(WOLFSSL_TLS_OBJ:.o=.d) -include $(OBJ_PIC:.o=.d) $(WOLFCRYPT_OBJ_PIC:.o=.d) \ $(WOLFSSL_TLS_OBJ_PIC:.o=.d) diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index 97d7d2f..2ca163b 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -1,6 +1,6 @@ -# Build and run the Mbed TLS compatibility tests. Run by the -# mbedtls-compat-test, mbedtls-compat-unit and mbedtls-compat-programs -# targets in the wolfPSA root, which set the paths, all absolute. +# Build and run the Mbed TLS compatibility tests. Run by the mbedtls-compat-* +# targets in the wolfPSA root (make help there), which set the paths, all +# absolute. ifndef WOLFPSA_PATH $(error Run make MBEDTLS_COMPAT=1 mbedtls-compat-test in the wolfPSA root) @@ -116,6 +116,7 @@ export ASAN_OPTIONS := $(if $(ASAN_OPTIONS),$(ASAN_OPTIONS):)$(ASAN_LINK_ORDER) .PHONY: test unit programs suite suite-ref suite-patch data-check \ wolfssl-check FORCE +# Everything that tests wolfPSA test: unit programs suite unit: $(UNIT) | data-check From ceb76a46f5f222ebb1fbc112d0bec880b49c6004 Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 17:02:24 -0800 Subject: [PATCH 07/10] Update CI to run new tests --- .github/workflows/mbedtls-compat.yml | 22 ++++++++++++++-- README.md | 38 +++++++++++++++++++++++++--- test/mbedtls_compat/Makefile | 2 +- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/.github/workflows/mbedtls-compat.yml b/.github/workflows/mbedtls-compat.yml index 4422fe6..1f6d9a3 100644 --- a/.github/workflows/mbedtls-compat.yml +++ b/.github/workflows/mbedtls-compat.yml @@ -6,8 +6,8 @@ on: jobs: # make MBEDTLS_COMPAT=1 mbedtls-compat-test: the Mbed TLS 4.x API on - # wolfSSL, tested with Mbed TLS's sample programs and test data. See the - # README. + # wolfSSL, tested with our tests, Mbed TLS's sample programs and its ssl + # suite. See the README. mbedtls-compat: runs-on: ubuntu-latest timeout-minutes: 15 @@ -44,3 +44,21 @@ jobs: WOLFSSL_CPPFLAGS="-DWOLFSSL_USER_SETTINGS -DNO_WOLFSSL_$side" \ want-surface-test done + + # make MBEDTLS_COMPAT=1 mbedtls-compat-suite-ref: the same ssl suite on Mbed + # TLS's own libraries, where every case must pass. No wolfSSL. + mbedtls-compat-suite-ref: + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: Check out wolfPSA + uses: actions/checkout@v4 + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential cmake python3-jinja2 python3-jsonschema + + - name: Build Mbed TLS and run the ssl suite on it + run: make -j"$(nproc)" MBEDTLS_COMPAT=1 mbedtls-compat-suite-ref diff --git a/README.md b/README.md index 0034aca..0be2768 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,8 @@ Known differences from Mbed TLS: make MBEDTLS_COMPAT=1 mbedtls-compat-test ``` -runs these against `libwolfpsa.a`. Each is also a target of its own. +runs these against `libwolfpsa.a`. Each is also a target of its own; +`make help` lists them all. - `mbedtls-compat-unit`: `test/mbedtls_compat/x509_crt_test.c`, `pk_test.c` and `pem_test.c` parse Mbed TLS's test certificates and keys. @@ -240,13 +241,16 @@ runs these against `libwolfpsa.a`. Each is also a target of its own. TLS's server programs run against the wolfSSL example client. With `MBEDTLS_THREADING_C=1`, `ssl_pthread_server` serves clients at the same time. +- `mbedtls-compat-suite`: Mbed TLS's TLS unit tests, the cases that test + the public API (below). Notes: - The tests clone Mbed TLS at `MBEDTLS_REF` (set in `test/mbedtls_compat/Makefile`) into the build directory, so the first run needs network access. `MBEDTLS_PATH` uses an Mbed TLS 4.x checkout - with its `framework` and `tf-psa-crypto` submodules instead. + with its `framework` and `tf-psa-crypto` submodules instead, for unit and + programs. The suite always uses the clone, since it changes it. - The example server and client come from a wolfSSL configured out of tree from `WOLFSSL_PATH`, which must not be configured in place. The tests use the certificates in its `certs/`. This needs autoconf, automake and @@ -256,7 +260,35 @@ Notes: - `WRAP` prefixes each test program, for example `WRAP=valgrind`. Server programs are stopped by the script, so their exit codes are not checked. - `libwolfpsa.a` has no Mbed TLS code. The tests link Mbed TLS's test - certificate data. + certificate data, and the suite its test code, changed by + `test/mbedtls_compat/ssl_suite/mbedtls.patch` (Mbed TLS's license). + +Most of Mbed TLS's TLS unit tests check its internals: the record layer, +the handshake state machine, the key schedule. `mbedtls-compat-suite` runs +the cases whose test logic uses the public API. `ssl_suite/cases.txt` +lists them with the result each should have: pass; fail, with the feature +it waits on; or not run, with the reason. The target prints how many pass +and what the rest wait on, and fails when a result differs. A case that +passes where fail is listed is an error too, so the change that adds a +feature also marks its cases pass. + +- Mbed TLS's test helpers (`ssl_helpers.c`) reach its internals. + `mbedtls.patch` turns those parts off and `ssl_helpers_port.c` does the + same through the public API. For example, the session the save and load + cases use comes from a handshake, where Mbed TLS's helper sets its + fields. +- `mbedtls-compat-suite-ref` runs the same cases on Mbed TLS's own + libraries, built from the clone with CMake, and every case must pass. + This shows the changed helpers still test what Mbed TLS's do. It needs + no wolfSSL, but needs cmake and python3 with jinja2 and jsonschema. +- To change the patch, edit the clone (`build/mbedtls_compat/mbedtls` by + default), then run `make MBEDTLS_COMPAT=1 mbedtls-compat-suite-patch`. A + newer `mbedtls.patch` resets the clone, dropping edits made there. +- After a change of `MBEDTLS_REF`, the suite build fails when `cases.txt` + lists a case Mbed TLS dropped, or lacks a new case of a test function it + uses. If the patch does not apply, `git apply --reject` in the clone + leaves the parts that fail in `.rej` files; fix them, then save the + patch. ## Testing (PSA Architecture Test Suite) diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index 2ca163b..cfd040d 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -142,7 +142,7 @@ suite-patch: @mkdir -p $(SUITE_BUILD) { sed '/^diff --git/,$$d' $(SUITE)/mbedtls.patch; \ git -C $(MBEDTLS_CLONE) -c diff.suppressBlankEmpty=true \ - diff --no-ext-diff; } > $(SUITE_BUILD)/mbedtls.patch + diff --no-ext-diff HEAD; } > $(SUITE_BUILD)/mbedtls.patch mv $(SUITE_BUILD)/mbedtls.patch $(SUITE)/mbedtls.patch touch $(SUITE_PATCHED) From d47c6fb8117c4157c38f28e0a290be077d782b07 Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Wed, 11 Nov 2026 17:21:51 -0800 Subject: [PATCH 08/10] Add function column in cases.txt --- README.md | 10 +- test/mbedtls_compat/Makefile | 5 +- test/mbedtls_compat/ssl_suite/cases.py | 29 ++ test/mbedtls_compat/ssl_suite/cases.txt | 468 ++++++++++++------------ test/mbedtls_compat/ssl_suite/check.py | 38 +- test/mbedtls_compat/ssl_suite/select.py | 38 +- 6 files changed, 313 insertions(+), 275 deletions(-) create mode 100644 test/mbedtls_compat/ssl_suite/cases.py diff --git a/README.md b/README.md index 0be2768..41fe18f 100644 --- a/README.md +++ b/README.md @@ -266,11 +266,11 @@ Notes: Most of Mbed TLS's TLS unit tests check its internals: the record layer, the handshake state machine, the key schedule. `mbedtls-compat-suite` runs the cases whose test logic uses the public API. `ssl_suite/cases.txt` -lists them with the result each should have: pass; fail, with the feature -it waits on; or not run, with the reason. The target prints how many pass -and what the rest wait on, and fails when a result differs. A case that -passes where fail is listed is an error too, so the change that adds a -feature also marks its cases pass. +lists them, each with its test function and the result it should have: +pass; fail, with the feature it waits on; or not run, with the reason. +The target prints how many pass and what the rest wait on, and fails when +a result differs. A case that passes where fail is listed is an error too, +so the change that adds a feature also marks its cases pass. - Mbed TLS's test helpers (`ssl_helpers.c`) reach its internals. `mbedtls.patch` turns those parts off and `ssl_helpers_port.c` does the diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index cfd040d..3fbce45 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -112,6 +112,8 @@ export BUILD_DIR WOLFSSL_PATH WOLFSSL_SERVER WOLFSSL_CLIENT MBEDTLS_PATH \ # With ASAN=1: let a preloaded library, such as faketime's, come first ASAN_LINK_ORDER := verify_asan_link_order=0 export ASAN_OPTIONS := $(if $(ASAN_OPTIONS),$(ASAN_OPTIONS):)$(ASAN_LINK_ORDER) +# select.py and check.py import cases.py: no __pycache__ in the source tree +export PYTHONDONTWRITEBYTECODE := 1 .PHONY: test unit programs suite suite-ref suite-patch data-check \ wolfssl-check FORCE @@ -201,7 +203,8 @@ $(SUITE_PATCHED): $(SUITE)/mbedtls.patch $(MBEDTLS_STAMP) # One recipe writes the .c and the .datax $(SUITE_NAME).datax: $(SUITE_NAME).c ; -$(SUITE_NAME).c: $(SUITE)/select.py $(SUITE)/cases.txt $(SUITE_PATCHED) +$(SUITE_NAME).c: $(SUITE)/select.py $(SUITE)/cases.py $(SUITE)/cases.txt \ + $(SUITE_PATCHED) @mkdir -p $(@D) python3 $< $(SUITE)/cases.txt $(MBEDTLS_CLONE)/tests/suites $(@D) python3 $(MBEDTLS_CLONE)/framework/scripts/generate_test_code.py \ diff --git a/test/mbedtls_compat/ssl_suite/cases.py b/test/mbedtls_compat/ssl_suite/cases.py new file mode 100644 index 0000000..d78b69c --- /dev/null +++ b/test/mbedtls_compat/ssl_suite/cases.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2026 wolfSSL Inc. +# SPDX-License-Identifier: GPL-3.0-or-later +# +# Reads cases.txt, for select.py and check.py. + +import collections +import sys + +EXPECT = ('pass', 'fail', 'notrun') + +Case = collections.namedtuple('Case', 'group expect waits function') + + +def read(path): + """Return {description: Case} from cases.txt, in file order.""" + cases = {} + with open(path, encoding='ascii') as f: + for num, line in enumerate(f, 1): + line = line.strip() + if not line or line.startswith('#'): + continue + fields = line.split(None, 4) + if len(fields) != 5 or fields[1] not in EXPECT: + sys.exit('%s:%d: bad line' % (path, num)) + if fields[4] in cases: + sys.exit('%s:%d: case listed twice' % (path, num)) + cases[fields[4]] = Case(*fields[:4]) + return cases diff --git a/test/mbedtls_compat/ssl_suite/cases.txt b/test/mbedtls_compat/ssl_suite/cases.txt index 5fbb1d2..883dfd7 100644 --- a/test/mbedtls_compat/ssl_suite/cases.txt +++ b/test/mbedtls_compat/ssl_suite/cases.txt @@ -8,6 +8,9 @@ # Expect: pass must PASS. fail must FAIL or SKIP: mark it pass once it # passes. notrun is left out of the run. # +# Function: the test function in test_suite_ssl.function that runs the case. +# select.py fails when it differs from Mbed TLS's. +# # Waits on, for fail: # session mbedtls_ssl_session_save and _load; PSK too for a session # without a certificate @@ -29,229 +32,244 @@ # tls13-off it too # get_hostname calls mbedtls_ssl_, which wolfPSA does not have, so # tls_prf its test function is not built -# group_list +# group_list the same for mbedtls_ssl_get_supported_group_list or +# MBEDTLS_SSL_IANA_TLS_GROUPS_INFO # -# Columns: group, expect, waits on or why, description -api fail psk Attempt to register multiple PSKs -api fail psk Attempt to register multiple PSKS, incl. opaque PSK, #0 -api fail psk Attempt to register multiple PSKs, incl. opaque PSK, #1 -api fail psk Attempt to register multiple PSKs, incl. opaque PSK, #2 -mock pass - Test callback buffer sanity -mock pass - Callback buffer test: Exercise simple write/read -mock pass - Callback buffer test: Filling up the buffer -mock pass - Callback buffer test: Filling up the buffer in two steps -mock pass - Callback buffer test: Reading out the buffer in two steps -mock pass - Callback buffer test: Data wraps in buffer -mock pass - Callback buffer test: Data starts at the end -mock pass - Callback buffer test: Can write less than requested -mock pass - Callback buffer test: Can read less than requested -mock pass - Callback buffer test: Writing to full buffer -mock pass - Callback buffer test: Reading from empty buffer -mock pass - Test mock socket sanity -mock pass - Test mock blocking TCP connection -mock pass - Test mock non-blocking TCP connection -mock pass - Test mock blocking TCP connection (interleaving) -mock pass - Test mock non-blocking TCP connection (interleaving) -mock pass - Message queue - sanity -mock pass - Message queue - basic test -mock pass - Message queue - overflow/underflow -mock pass - Message queue - interleaved -mock pass - Message queue - insufficient buffer -mock pass - Message transport mock - uninitialized structures -mock pass - Message transport mock - basic test -mock pass - Message transport mock - queue overflow/underflow -mock pass - Message transport mock - socket overflow -mock pass - Message transport mock - truncated message -mock pass - Message transport mock - socket read error -mock pass - Message transport mock - one-way interleaved sends/reads -mock pass - Message transport mock - two-way interleaved sends/reads -target pass - Test mbedtls_endpoint sanity for the client -target pass - Test mbedtls_endpoint sanity for the server -target pass - Handshake, tls1_2 -target pass - Handshake, tls1_3 -target pass - Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 -target pass - Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 -target pass - Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 -target notrun ccm Handshake, ECDHE-ECDSA-WITH-AES-256-CCM -target fail psk Handshake, PSK-WITH-AES-128-CBC-SHA -target fail psk DTLS Handshake, PSK-WITH-AES-128-CBC-SHA -target fail dtls DTLS Handshake, tls1_2 -target fail dtls DTLS Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 -target fail dtls DTLS Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 -target fail dtls DTLS Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 -target notrun ccm DTLS Handshake, ECDHE-ECDSA-WITH-AES-256-CCM -target fail context DTLS Handshake with serialization, tls1_2 -target fail dtls DTLS Handshake fragmentation, MFL=512 -target fail dtls DTLS Handshake fragmentation, MFL=1024 -target notrun tls13-off Handshake min/max version check, all -> 1.2 -target pass - Handshake min/max version check, all -> 1.3 -target pass - Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, non-opaque -target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_ANY_HASH -target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_SHA_384 -target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, invalid alg -target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, bad alg -target fail opaque Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, bad usage -target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, non-opaque -target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, PSA_ALG_ANY_HASH -target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, PSA_ALG_SHA_256 -target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, bad alg -target notrun ccm Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, bad usage -target notrun internal Handshake: DTLS 1.2, badmac_seen on client -target notrun internal Handshake: DTLS 1.2, badmac_seen on server -target fail mfl Sending app data via TLS, MFL=512 without fragmentation -target fail mfl Sending app data via TLS, MFL=512 with fragmentation -target fail mfl Sending app data via TLS, MFL=1024 without fragmentation -target fail mfl Sending app data via TLS, MFL=1024 with fragmentation -target fail mfl Sending app data via TLS, MFL=2048 without fragmentation -target fail mfl Sending app data via TLS, MFL=2048 with fragmentation -target fail mfl Sending app data via TLS, MFL=4096 without fragmentation -target fail mfl Sending app data via TLS, MFL=4096 with fragmentation -target pass - Sending app data via TLS without MFL and without fragmentation -target pass - Sending app data via TLS without MFL and with fragmentation -target fail dtls Sending app data via DTLS, MFL=512 without fragmentation -target fail dtls Sending app data via DTLS, MFL=512 with fragmentation -target fail dtls Sending app data via DTLS, MFL=1024 without fragmentation -target fail dtls Sending app data via DTLS, MFL=1024 with fragmentation -target fail dtls Sending app data via DTLS, MFL=2048 without fragmentation -target fail dtls Sending app data via DTLS, MFL=2048 with fragmentation -target fail dtls Sending app data via DTLS, MFL=4096 without fragmentation -target fail dtls Sending app data via DTLS, MFL=4096 with fragmentation -target fail dtls Sending app data via DTLS, without MFL and without fragmentation -target fail dtls Sending app data via DTLS, without MFL and with fragmentation -target fail renegotiation DTLS renegotiation: no legacy renegotiation -target fail renegotiation DTLS renegotiation: legacy renegotiation -target fail renegotiation DTLS renegotiation: legacy break handshake -target notrun internal DTLS renegotiation: after bad MAC on client -target notrun internal DTLS renegotiation: after bad MAC on server -api notrun get_hostname SSL SET_HOSTNAME memory leak: call ssl_set_hostname twice -target fail session SSL session serialization: Wrong major version -target fail session SSL session serialization: Wrong minor version -target fail session SSL session serialization: Wrong patch version -target fail session SSL session serialization: Wrong config -target fail ticket TLS 1.3: CLI: session serialization: Wrong major version -target fail ticket TLS 1.3: CLI: session serialization: Wrong minor version -target fail ticket TLS 1.3: CLI: session serialization: Wrong patch version -target fail ticket TLS 1.3: CLI: session serialization: Wrong config -target fail ticket TLS 1.3: SRV: session serialization: Wrong major version -target fail ticket TLS 1.3: SRV: session serialization: Wrong minor version -target fail ticket TLS 1.3: SRV: session serialization: Wrong patch version -target fail ticket TLS 1.3: SRV: session serialization: Wrong config -api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_NONE -api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA384 -api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA256 -api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA384 SHA-384 not enabled -api notrun tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA256 SHA-256 not enabled -target fail session Session serialization, load-save: no ticket, no cert -target fail ticket Session serialization, load-save: small ticket, no cert -target fail ticket Session serialization, load-save: large ticket, no cert -target fail session Session serialization, load-save: no ticket, cert -target fail ticket Session serialization, load-save: small ticket, cert -target fail ticket Session serialization, load-save: large ticket, cert -target fail ticket TLS 1.3: CLI: Session serialization, load-save: no ticket -target fail ticket TLS 1.3: CLI: Session serialization, load-save: small ticket -target fail ticket TLS 1.3: CLI: Session serialization, load-save: large ticket -target fail ticket TLS 1.3: SRV: Session serialization, load-save -target fail session Session serialization, save buffer size: no ticket, no cert -target fail ticket Session serialization, save buffer size: small ticket, no cert -target fail ticket Session serialization, save buffer size: large ticket, no cert -target fail session Session serialization, save buffer size: no ticket, cert -target fail ticket Session serialization, save buffer size: small ticket, cert -target fail ticket Session serialization, save buffer size: large ticket, cert -target fail ticket TLS 1.3: CLI: Session serialization, save buffer size: no ticket -target fail ticket TLS 1.3: CLI: Session serialization, save buffer size: small ticket -target fail ticket TLS 1.3: CLI: Session serialization, save buffer size: large ticket -target fail ticket TLS 1.3: SRV: Session serialization, save buffer size -target fail session Session serialization, load buffer size: no ticket, no cert -target fail ticket Session serialization, load buffer size: small ticket, no cert -target fail ticket Session serialization, load buffer size: large ticket, no cert -target fail session Session serialization, load buffer size: no ticket, cert -target fail ticket Session serialization, load buffer size: small ticket, cert -target fail ticket Session serialization, load buffer size: large ticket, cert -target fail ticket TLS 1.3: CLI: Session serialization, load buffer size: no ticket -target fail ticket TLS 1.3: CLI: Session serialization, load buffer size: small ticket -target fail ticket TLS 1.3: CLI: Session serialization, load buffer size: large ticket -target fail ticket TLS 1.3: SRV: Session serialization, load buffer size -api notrun internal Test configuration of EC groups through mbedtls_ssl_conf_groups() -api notrun group_list Get supported group list: x25519, positive -api notrun group_list Get supported group list: x25519, negative -api notrun group_list Get supported group list: secp256r1, positive -api notrun group_list Get supported group list: secp256r1, negative -api notrun group_list Get supported group list: secp384r1, positive -api notrun group_list Get supported group list: secp384r1, negative -api notrun group_list Get supported group list: x448, positive -api notrun group_list Get supported group list: x448, negative -api notrun group_list Get supported group list: secp521r1, positive -api notrun group_list Get supported group list: secp521r1, negative -api notrun group_list Get supported group list: brainpool256r1, positive -api notrun group_list Get supported group list: brainpool256r1, negative -api notrun group_list Get supported group list: brainpool384r1, positive -api notrun group_list Get supported group list: brainpool384r1, negative -api notrun group_list Get supported group list: brainpool512r1, positive -api notrun group_list Get supported group list: brainpool512r1, negative -api notrun group_list Get supported group list: ffdhe2048, positive -api notrun group_list Get supported group list: ffdhe2048, negative -api notrun group_list Get supported group list: ffdhe3072, positive -api notrun group_list Get supported group list: ffdhe3072, negative -api notrun group_list Get supported group list: ffdhe4096, positive -api notrun group_list Get supported group list: ffdhe4096, negative -api notrun group_list Get supported group list: ffdhe6144, positive -api notrun group_list Get supported group list: ffdhe6144, negative -api notrun group_list Get supported group list: ffdhe8192, positive -api notrun group_list Get supported group list: ffdhe8192, negative -api fail defaults Version config: valid client TLS 1.2 only -api fail defaults Version config: valid client DTLS 1.2 only -api fail defaults Version config: valid server TLS 1.2 only -api fail defaults Version config: valid server DTLS 1.2 only -api notrun tls12-off Version config: invalid client TLS 1.2 only -api notrun tls12-off Version config: invalid client DTLS 1.2 only -api notrun tls12-off Version config: invalid server TLS 1.2 only -api notrun tls12-off Version config: invalid server DTLS 1.2 only -api fail defaults Version config: valid client TLS 1.3 only -api fail defaults Version config: unsupported client DTLS 1.3 only -api fail defaults Version config: valid server TLS 1.3 only -api fail defaults Version config: unsupported server DTLS 1.3 only -api notrun tls13-off Version config: invalid client TLS 1.3 only -api notrun tls13-off Version config: invalid client DTLS 1.3 only -api notrun tls13-off Version config: invalid server TLS 1.3 only -api notrun tls13-off Version config: invalid server DTLS 1.3 only -api fail defaults Version config: valid client hybrid TLS 1.2/3 -api fail defaults Version config: unsupported client hybrid DTLS 1.2/3 -api fail defaults Version config: valid server hybrid TLS 1.2/3 -api fail defaults Version config: unsupported server hybrid DTLS 1.2/3 -api notrun tls12-off Version config: valid client hybrid TLS 1.2/3, no TLS 1.2 -api notrun tls12-off Version config: unsupported client hybrid DTLS 1.2/3, no TLS 1.2 -api notrun tls12-off Version config: valid server hybrid TLS 1.2/3, no TLS 1.2 -api notrun tls12-off Version config: unsupported server hybrid DTLS 1.2/3, no TLS 1.2 -api notrun tls13-off Version config: valid client hybrid TLS 1.2/3, no TLS 1.3 -api notrun tls13-off Version config: unsupported client hybrid DTLS 1.2/3, no TLS 1.3 -api notrun tls13-off Version config: valid server hybrid TLS 1.2/3, no TLS 1.3 -api notrun tls13-off Version config: unsupported server hybrid DTLS 1.2/3, no TLS 1.3 -api fail defaults Version config: invalid minimum version -api fail defaults Version config: invalid maximum version -api fail timing Test accessor into timing_delay_context -api fail cid Sanity test cid functions -api notrun internal Test Elliptic curves' info parsing -target fail exporter TLS 1.2 Keying Material Exporter: Consistent results, no context -target fail exporter TLS 1.2 Keying Material Exporter: Consistent results, with context -target fail exporter TLS 1.2 Keying Material Exporter: Consistent results, large keys -target fail exporter TLS 1.2 Keying Material Exporter: Uses label -target fail exporter TLS 1.2 Keying Material Exporter: Uses context -target fail exporter TLS 1.2 Keying Material Exporter: Context too long -target fail exporter TLS 1.2 Keying Material Exporter: Handshake not done -target fail exporter TLS 1.3 Keying Material Exporter: Consistent results, no context -target fail exporter TLS 1.3 Keying Material Exporter: Consistent results, with context -target fail exporter TLS 1.3 Keying Material Exporter: Consistent results, large keys -target fail exporter TLS 1.3 Keying Material Exporter: Uses label -target fail exporter TLS 1.3 Keying Material Exporter: Uses context -target fail exporter TLS 1.3 Keying Material Exporter: Uses length -target fail exporter TLS 1.3 Keying Material Exporter: Exported key too long -target fail exporter TLS 1.3 Keying Material Exporter: Label too long -target fail exporter TLS 1.3 Keying Material Exporter: Handshake not done -target notrun internal Send large fragmented ClientHello: reassembled 1 byte larger than the buffer -target notrun internal Send large fragmented ClientHello: would just fit except for overhead -target notrun internal Send large fragmented ClientHello: would fit except for overhead (1) -target notrun internal Send large fragmented ClientHello: would fit except for overhead (2) -target notrun internal Send large fragmented ClientHello: would fit except for overhead (3) -target notrun internal Send large fragmented ClientHello: would fit except for overhead (4) -target notrun internal Send large fragmented ClientHello: just fits -target notrun internal Send large fragmented ClientHello: length doesn't fit in two bytes +# Columns: group, expect, waits on or why, function, description +api fail psk test_multiple_psks Attempt to register multiple PSKs +api fail psk test_multiple_psks_opaque Attempt to register multiple PSKS, incl. opaque PSK, #0 +api fail psk test_multiple_psks_opaque Attempt to register multiple PSKs, incl. opaque PSK, #1 +api fail psk test_multiple_psks_opaque Attempt to register multiple PSKs, incl. opaque PSK, #2 +mock pass - test_callback_buffer_sanity Test callback buffer sanity +mock pass - test_callback_buffer Callback buffer test: Exercise simple write/read +mock pass - test_callback_buffer Callback buffer test: Filling up the buffer +mock pass - test_callback_buffer Callback buffer test: Filling up the buffer in two steps +mock pass - test_callback_buffer Callback buffer test: Reading out the buffer in two steps +mock pass - test_callback_buffer Callback buffer test: Data wraps in buffer +mock pass - test_callback_buffer Callback buffer test: Data starts at the end +mock pass - test_callback_buffer Callback buffer test: Can write less than requested +mock pass - test_callback_buffer Callback buffer test: Can read less than requested +mock pass - test_callback_buffer Callback buffer test: Writing to full buffer +mock pass - test_callback_buffer Callback buffer test: Reading from empty buffer +mock pass - ssl_mock_sanity Test mock socket sanity +mock pass - ssl_mock_tcp Test mock blocking TCP connection +mock pass - ssl_mock_tcp Test mock non-blocking TCP connection +mock pass - ssl_mock_tcp_interleaving Test mock blocking TCP connection (interleaving) +mock pass - ssl_mock_tcp_interleaving Test mock non-blocking TCP connection (interleaving) +mock pass - ssl_message_queue_sanity Message queue - sanity +mock pass - ssl_message_queue_basic Message queue - basic test +mock pass - ssl_message_queue_overflow_underflow Message queue - overflow/underflow +mock pass - ssl_message_queue_interleaved Message queue - interleaved +mock pass - ssl_message_queue_insufficient_buffer Message queue - insufficient buffer +mock pass - ssl_message_mock_uninitialized Message transport mock - uninitialized structures +mock pass - ssl_message_mock_basic Message transport mock - basic test +mock pass - ssl_message_mock_queue_overflow_underflow Message transport mock - queue overflow/underflow +mock pass - ssl_message_mock_socket_overflow Message transport mock - socket overflow +mock pass - ssl_message_mock_truncated Message transport mock - truncated message +mock pass - ssl_message_mock_socket_read_error Message transport mock - socket read error +mock pass - ssl_message_mock_interleaved_one_way Message transport mock - one-way interleaved sends/reads +mock pass - ssl_message_mock_interleaved_two_ways Message transport mock - two-way interleaved sends/reads +target pass - mbedtls_endpoint_sanity Test mbedtls_endpoint sanity for the client +target pass - mbedtls_endpoint_sanity Test mbedtls_endpoint sanity for the server +target pass - handshake_version Handshake, tls1_2 +target pass - handshake_version Handshake, tls1_3 +target pass - handshake_cipher Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 +target pass - handshake_cipher Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 +target pass - handshake_cipher Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 +target notrun ccm handshake_cipher Handshake, ECDHE-ECDSA-WITH-AES-256-CCM +target fail psk handshake_psk_cipher Handshake, PSK-WITH-AES-128-CBC-SHA +target fail psk handshake_psk_cipher DTLS Handshake, PSK-WITH-AES-128-CBC-SHA +target fail dtls handshake_version DTLS Handshake, tls1_2 +target fail dtls handshake_cipher DTLS Handshake, ECDHE-RSA-WITH-AES-256-GCM-SHA384 +target fail dtls handshake_cipher DTLS Handshake, ECDHE-RSA-WITH-AES-128-CBC-SHA256 +target fail dtls handshake_cipher DTLS Handshake, ECDHE-RSA-WITH-AES-256-CBC-SHA384 +target notrun ccm handshake_cipher DTLS Handshake, ECDHE-ECDSA-WITH-AES-256-CCM +target fail context handshake_serialization DTLS Handshake with serialization, tls1_2 +target fail dtls handshake_fragmentation DTLS Handshake fragmentation, MFL=512 +target fail dtls handshake_fragmentation DTLS Handshake fragmentation, MFL=1024 +target notrun tls13-off handshake_version Handshake min/max version check, all -> 1.2 +target pass - handshake_version Handshake min/max version check, all -> 1.3 +target pass - handshake_ciphersuite_select Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, non-opaque +target fail opaque handshake_ciphersuite_select Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_ANY_HASH +target fail opaque handshake_ciphersuite_select Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, PSA_ALG_SHA_384 +target fail opaque handshake_ciphersuite_select Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, invalid alg +target fail opaque handshake_ciphersuite_select Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, bad alg +target fail opaque handshake_ciphersuite_select Handshake, select ECDHE-RSA-WITH-AES-256-GCM-SHA384, opaque, bad usage +target notrun ccm handshake_ciphersuite_select Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, non-opaque +target notrun ccm handshake_ciphersuite_select Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, PSA_ALG_ANY_HASH +target notrun ccm handshake_ciphersuite_select Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, PSA_ALG_SHA_256 +target notrun ccm handshake_ciphersuite_select Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, bad alg +target notrun ccm handshake_ciphersuite_select Handshake, select ECDHE-ECDSA-WITH-AES-256-CCM, opaque, bad usage +target notrun internal handshake_with_forced_context Handshake: DTLS 1.2, badmac_seen on client +target notrun internal handshake_with_forced_context Handshake: DTLS 1.2, badmac_seen on server +target fail mfl app_data_tls Sending app data via TLS, MFL=512 without fragmentation +target fail mfl app_data_tls Sending app data via TLS, MFL=512 with fragmentation +target fail mfl app_data_tls Sending app data via TLS, MFL=1024 without fragmentation +target fail mfl app_data_tls Sending app data via TLS, MFL=1024 with fragmentation +target fail mfl app_data_tls Sending app data via TLS, MFL=2048 without fragmentation +target fail mfl app_data_tls Sending app data via TLS, MFL=2048 with fragmentation +target fail mfl app_data_tls Sending app data via TLS, MFL=4096 without fragmentation +target fail mfl app_data_tls Sending app data via TLS, MFL=4096 with fragmentation +target pass - app_data_tls Sending app data via TLS without MFL and without fragmentation +target pass - app_data_tls Sending app data via TLS without MFL and with fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=512 without fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=512 with fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=1024 without fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=1024 with fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=2048 without fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=2048 with fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=4096 without fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, MFL=4096 with fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, without MFL and without fragmentation +target fail dtls app_data_dtls Sending app data via DTLS, without MFL and with fragmentation +target fail renegotiation renegotiation DTLS renegotiation: no legacy renegotiation +target fail renegotiation renegotiation DTLS renegotiation: legacy renegotiation +target fail renegotiation renegotiation DTLS renegotiation: legacy break handshake +target notrun internal renegotiation DTLS renegotiation: after bad MAC on client +target notrun internal renegotiation DTLS renegotiation: after bad MAC on server +api notrun get_hostname ssl_set_hostname_twice SSL SET_HOSTNAME memory leak: call ssl_set_hostname twice +target fail session ssl_session_serialize_version_check SSL session serialization: Wrong major version +target fail session ssl_session_serialize_version_check SSL session serialization: Wrong minor version +target fail session ssl_session_serialize_version_check SSL session serialization: Wrong patch version +target fail session ssl_session_serialize_version_check SSL session serialization: Wrong config +target fail ticket ssl_session_serialize_version_check TLS 1.3: CLI: session serialization: Wrong major version +target fail ticket ssl_session_serialize_version_check TLS 1.3: CLI: session serialization: Wrong minor version +target fail ticket ssl_session_serialize_version_check TLS 1.3: CLI: session serialization: Wrong patch version +target fail ticket ssl_session_serialize_version_check TLS 1.3: CLI: session serialization: Wrong config +target fail ticket ssl_session_serialize_version_check TLS 1.3: SRV: session serialization: Wrong major version +target fail ticket ssl_session_serialize_version_check TLS 1.3: SRV: session serialization: Wrong minor version +target fail ticket ssl_session_serialize_version_check TLS 1.3: SRV: session serialization: Wrong patch version +target fail ticket ssl_session_serialize_version_check TLS 1.3: SRV: session serialization: Wrong config +api notrun tls_prf ssl_tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_NONE +api notrun tls_prf ssl_tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA384 +api notrun tls_prf ssl_tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA256 +api notrun tls_prf ssl_tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA384 SHA-384 not enabled +api notrun tls_prf ssl_tls_prf SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_SHA256 SHA-256 not enabled +target fail session ssl_serialize_session_load_save Session serialization, load-save: no ticket, no cert +target fail ticket ssl_serialize_session_load_save Session serialization, load-save: small ticket, no cert +target fail ticket ssl_serialize_session_load_save Session serialization, load-save: large ticket, no cert +target fail session ssl_serialize_session_load_save Session serialization, load-save: no ticket, cert +target fail ticket ssl_serialize_session_load_save Session serialization, load-save: small ticket, cert +target fail ticket ssl_serialize_session_load_save Session serialization, load-save: large ticket, cert +target fail ticket ssl_serialize_session_load_save TLS 1.3: CLI: Session serialization, load-save: no ticket +target fail ticket ssl_serialize_session_load_save TLS 1.3: CLI: Session serialization, load-save: small ticket +target fail ticket ssl_serialize_session_load_save TLS 1.3: CLI: Session serialization, load-save: large ticket +target fail ticket ssl_serialize_session_load_save TLS 1.3: SRV: Session serialization, load-save +target fail session ssl_serialize_session_save_buf_size Session serialization, save buffer size: no ticket, no cert +target fail ticket ssl_serialize_session_save_buf_size Session serialization, save buffer size: small ticket, no cert +target fail ticket ssl_serialize_session_save_buf_size Session serialization, save buffer size: large ticket, no cert +target fail session ssl_serialize_session_save_buf_size Session serialization, save buffer size: no ticket, cert +target fail ticket ssl_serialize_session_save_buf_size Session serialization, save buffer size: small ticket, cert +target fail ticket ssl_serialize_session_save_buf_size Session serialization, save buffer size: large ticket, cert +target fail ticket ssl_serialize_session_save_buf_size TLS 1.3: CLI: Session serialization, save buffer size: no ticket +target fail ticket ssl_serialize_session_save_buf_size TLS 1.3: CLI: Session serialization, save buffer size: small ticket +target fail ticket ssl_serialize_session_save_buf_size TLS 1.3: CLI: Session serialization, save buffer size: large ticket +target fail ticket ssl_serialize_session_save_buf_size TLS 1.3: SRV: Session serialization, save buffer size +target fail session ssl_serialize_session_load_buf_size Session serialization, load buffer size: no ticket, no cert +target fail ticket ssl_serialize_session_load_buf_size Session serialization, load buffer size: small ticket, no cert +target fail ticket ssl_serialize_session_load_buf_size Session serialization, load buffer size: large ticket, no cert +target fail session ssl_serialize_session_load_buf_size Session serialization, load buffer size: no ticket, cert +target fail ticket ssl_serialize_session_load_buf_size Session serialization, load buffer size: small ticket, cert +target fail ticket ssl_serialize_session_load_buf_size Session serialization, load buffer size: large ticket, cert +target fail ticket ssl_serialize_session_load_buf_size TLS 1.3: CLI: Session serialization, load buffer size: no ticket +target fail ticket ssl_serialize_session_load_buf_size TLS 1.3: CLI: Session serialization, load buffer size: small ticket +target fail ticket ssl_serialize_session_load_buf_size TLS 1.3: CLI: Session serialization, load buffer size: large ticket +target fail ticket ssl_serialize_session_load_buf_size TLS 1.3: SRV: Session serialization, load buffer size +api notrun internal conf_group Test configuration of EC groups through mbedtls_ssl_conf_groups() +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: x25519, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: x25519, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: secp256r1, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: secp256r1, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: secp384r1, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: secp384r1, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: x448, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: x448, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: secp521r1, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: secp521r1, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: brainpool256r1, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: brainpool256r1, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: brainpool384r1, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: brainpool384r1, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: brainpool512r1, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: brainpool512r1, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe2048, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe2048, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe3072, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe3072, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe4096, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe4096, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe6144, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe6144, negative +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe8192, positive +api notrun group_list test_mbedtls_ssl_get_supported_group_list Get supported group list: ffdhe8192, negative +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: x25519 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: secp256r1 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: secp256k1 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: secp384r1 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: x448 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: secp521r1 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: brainpoolP256r1 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: brainpoolP384r1 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: brainpoolP512r1 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: ffdhe2048 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: ffdhe3072 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: ffdhe4096 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: ffdhe6144 +api notrun group_list test_mbedtls_tls_id_group_name_table TLS ID <-> group name: ffdhe8192 +api fail defaults conf_version Version config: valid client TLS 1.2 only +api fail defaults conf_version Version config: valid client DTLS 1.2 only +api fail defaults conf_version Version config: valid server TLS 1.2 only +api fail defaults conf_version Version config: valid server DTLS 1.2 only +api notrun tls12-off conf_version Version config: invalid client TLS 1.2 only +api notrun tls12-off conf_version Version config: invalid client DTLS 1.2 only +api notrun tls12-off conf_version Version config: invalid server TLS 1.2 only +api notrun tls12-off conf_version Version config: invalid server DTLS 1.2 only +api fail defaults conf_version Version config: valid client TLS 1.3 only +api fail defaults conf_version Version config: unsupported client DTLS 1.3 only +api fail defaults conf_version Version config: valid server TLS 1.3 only +api fail defaults conf_version Version config: unsupported server DTLS 1.3 only +api notrun tls13-off conf_version Version config: invalid client TLS 1.3 only +api notrun tls13-off conf_version Version config: invalid client DTLS 1.3 only +api notrun tls13-off conf_version Version config: invalid server TLS 1.3 only +api notrun tls13-off conf_version Version config: invalid server DTLS 1.3 only +api fail defaults conf_version Version config: valid client hybrid TLS 1.2/3 +api fail defaults conf_version Version config: unsupported client hybrid DTLS 1.2/3 +api fail defaults conf_version Version config: valid server hybrid TLS 1.2/3 +api fail defaults conf_version Version config: unsupported server hybrid DTLS 1.2/3 +api notrun tls12-off conf_version Version config: valid client hybrid TLS 1.2/3, no TLS 1.2 +api notrun tls12-off conf_version Version config: unsupported client hybrid DTLS 1.2/3, no TLS 1.2 +api notrun tls12-off conf_version Version config: valid server hybrid TLS 1.2/3, no TLS 1.2 +api notrun tls12-off conf_version Version config: unsupported server hybrid DTLS 1.2/3, no TLS 1.2 +api notrun tls13-off conf_version Version config: valid client hybrid TLS 1.2/3, no TLS 1.3 +api notrun tls13-off conf_version Version config: unsupported client hybrid DTLS 1.2/3, no TLS 1.3 +api notrun tls13-off conf_version Version config: valid server hybrid TLS 1.2/3, no TLS 1.3 +api notrun tls13-off conf_version Version config: unsupported server hybrid DTLS 1.2/3, no TLS 1.3 +api fail defaults conf_version Version config: invalid minimum version +api fail defaults conf_version Version config: invalid maximum version +api fail timing timing_final_delay_accessor Test accessor into timing_delay_context +api fail cid cid_sanity Sanity test cid functions +api notrun internal elliptic_curve_get_properties Test Elliptic curves' info parsing +target fail exporter ssl_tls_exporter_consistent_result TLS 1.2 Keying Material Exporter: Consistent results, no context +target fail exporter ssl_tls_exporter_consistent_result TLS 1.2 Keying Material Exporter: Consistent results, with context +target fail exporter ssl_tls_exporter_consistent_result TLS 1.2 Keying Material Exporter: Consistent results, large keys +target fail exporter ssl_tls_exporter_uses_label TLS 1.2 Keying Material Exporter: Uses label +target fail exporter ssl_tls_exporter_uses_context TLS 1.2 Keying Material Exporter: Uses context +target fail exporter ssl_tls_exporter_rejects_bad_parameters TLS 1.2 Keying Material Exporter: Context too long +target fail exporter ssl_tls_exporter_too_early TLS 1.2 Keying Material Exporter: Handshake not done +target fail exporter ssl_tls_exporter_consistent_result TLS 1.3 Keying Material Exporter: Consistent results, no context +target fail exporter ssl_tls_exporter_consistent_result TLS 1.3 Keying Material Exporter: Consistent results, with context +target fail exporter ssl_tls_exporter_consistent_result TLS 1.3 Keying Material Exporter: Consistent results, large keys +target fail exporter ssl_tls_exporter_uses_label TLS 1.3 Keying Material Exporter: Uses label +target fail exporter ssl_tls_exporter_uses_context TLS 1.3 Keying Material Exporter: Uses context +target fail exporter ssl_tls13_exporter_uses_length TLS 1.3 Keying Material Exporter: Uses length +target fail exporter ssl_tls_exporter_rejects_bad_parameters TLS 1.3 Keying Material Exporter: Exported key too long +target fail exporter ssl_tls_exporter_rejects_bad_parameters TLS 1.3 Keying Material Exporter: Label too long +target fail exporter ssl_tls_exporter_too_early TLS 1.3 Keying Material Exporter: Handshake not done +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: reassembled 1 byte larger than the buffer +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: would just fit except for overhead +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: would fit except for overhead (1) +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: would fit except for overhead (2) +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: would fit except for overhead (3) +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: would fit except for overhead (4) +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: just fits +target notrun internal send_large_fragmented_hello Send large fragmented ClientHello: length doesn't fit in two bytes diff --git a/test/mbedtls_compat/ssl_suite/check.py b/test/mbedtls_compat/ssl_suite/check.py index 9709f6f..ce3427c 100644 --- a/test/mbedtls_compat/ssl_suite/check.py +++ b/test/mbedtls_compat/ssl_suite/check.py @@ -12,6 +12,8 @@ import collections import sys +import cases + GROUPS = ('target', 'api', 'mock') @@ -24,14 +26,11 @@ def main(): sys.exit('Usage: check.py [--all-pass] CASES OUTCOME') cases_path, outcome_path = args - cases = {} - with open(cases_path, encoding='ascii') as f: - for line in f: - if line.strip() and not line.startswith('#'): - group, expect, waits, desc = line.split(None, 3) - if all_pass and expect == 'fail': - expect = 'pass' - cases[desc.strip()] = (group, expect, waits) + listed = cases.read(cases_path) + if all_pass: + listed = {desc: case._replace(expect='pass') + if case.expect == 'fail' else case + for desc, case in listed.items()} results = {} try: @@ -44,31 +43,32 @@ def main(): bad = [] for desc, (result, reason) in results.items(): - if desc not in cases: + if desc not in listed: bad.append('not in cases.txt: ' + desc) - elif cases[desc][1] == 'notrun': + elif listed[desc].expect == 'notrun': bad.append('run, but marked notrun: ' + desc) - for desc, (group, expect, waits) in cases.items(): - if expect == 'notrun': + for desc, case in listed.items(): + if case.expect == 'notrun': continue if desc not in results: bad.append('not run: ' + desc) continue result, reason = results[desc] - if expect == 'pass' and result != 'PASS': + if case.expect == 'pass' and result != 'PASS': bad.append('%s, expected pass: %s (%s)' % (result, desc, reason)) - elif expect == 'fail' and result == 'PASS': + elif case.expect == 'fail' and result == 'PASS': bad.append('PASS, expected fail: ' + desc) for group in GROUPS: - run = [(d, c) for d, c in cases.items() - if c[0] == group and c[1] != 'notrun'] + run = [(d, c) for d, c in listed.items() + if c.group == group and c.expect != 'notrun'] passed = sum(results.get(d, ('',))[0] == 'PASS' for d, _ in run) - notrun = sum(c[0] == group and c[1] == 'notrun' - for c in cases.values()) + notrun = sum(c.group == group and c.expect == 'notrun' + for c in listed.values()) line = ' %-7s %d of %d pass' % (group, passed, len(run)) print(line + (', %d not run' % notrun if notrun else '')) - waits = collections.Counter(c[2] for _, c in run if c[1] == 'fail') + waits = collections.Counter(c.waits for _, c in run + if c.expect == 'fail') if waits: print(' not yet: ' + ', '.join( '%s %d' % w for w in waits.most_common())) diff --git a/test/mbedtls_compat/ssl_suite/select.py b/test/mbedtls_compat/ssl_suite/select.py index eca3fdc..74738f7 100644 --- a/test/mbedtls_compat/ssl_suite/select.py +++ b/test/mbedtls_compat/ssl_suite/select.py @@ -5,7 +5,8 @@ # # Writes test_suite_ssl_public.function and .data: the ssl suite's header, the # test functions the cases in CASES need, and those cases, unchanged. Fails -# when CASES and Mbed TLS differ on the cases of those test functions. +# when CASES and Mbed TLS differ on the cases of those test functions, or on +# a case's test function. # # Usage: select.py CASES SUITES_DIR OUT_DIR (SUITES_DIR: the clone's # tests/suites) @@ -14,27 +15,11 @@ import re import sys +import cases + FUNCTION = 'test_suite_ssl.function' DATA = ('test_suite_ssl.data', 'test_suite_ssl.tls-defrag.data') OUT = 'test_suite_ssl_public' -EXPECT = ('pass', 'fail', 'notrun') - - -def read_cases(path): - """Return {description: expect} from cases.txt.""" - cases = {} - with open(path, encoding='ascii') as f: - for num, line in enumerate(f, 1): - line = line.strip() - if not line or line.startswith('#'): - continue - fields = line.split(None, 3) - if len(fields) != 4 or fields[1] not in EXPECT: - sys.exit('%s:%d: bad line' % (path, num)) - if fields[3] in cases: - sys.exit('%s:%d: case listed twice' % (path, num)) - cases[fields[3]] = fields[1] - return cases def read_data(path): @@ -56,7 +41,7 @@ def main(): if len(sys.argv) != 4: sys.exit('Usage: select.py CASES SUITES_DIR OUT_DIR') cases_path, suites, out_dir = sys.argv[1:] - cases = read_cases(cases_path) + listed = cases.read(cases_path) data = [] for name in DATA: @@ -74,17 +59,20 @@ def main(): name = re.search(r'\nvoid\s+(\w+)\s*\(', m.group(0)).group(1) bodies[name] = m.group(0) - upstream = {desc for desc, _, _ in data} - listed_funcs = {func for desc, func, _ in data if desc in cases} + upstream = {desc: func for desc, func, _ in data} + listed_funcs = {func for desc, func, _ in data if desc in listed} errors = ['listed, not in Mbed TLS: ' + desc - for desc in cases if desc not in upstream] + for desc in listed if desc not in upstream] + errors += ['function is %s in Mbed TLS: %s' % (upstream[desc], desc) + for desc, case in listed.items() + if desc in upstream and case.function != upstream[desc]] errors += ['not listed: ' + desc for desc, func, _ in data - if func in listed_funcs and desc not in cases] + if func in listed_funcs and desc not in listed] if errors: sys.exit('%s:\n %s' % (cases_path, '\n '.join(errors))) run = [(func, text) for desc, func, text in data - if cases.get(desc, 'notrun') != 'notrun'] + if desc in listed and listed[desc].expect != 'notrun'] funcs = {func for func, _ in run} todo = list(funcs) while todo: From 41ade7b572f1168ead92863f34e71e2e4878e50c Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Fri, 13 Nov 2026 13:21:57 -0800 Subject: [PATCH 09/10] Fix failing test detection in Makefile --- test/mbedtls_compat/Makefile | 14 ++++++++------ test/mbedtls_compat/ssl_suite/check.py | 16 +++++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index 3fbce45..f167db7 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -90,15 +90,17 @@ REF_NAME := $(REF_BUILD)/test_suite_ssl_public # $(call run_suite,title,check.py options) runs the suite $< from the clone's # tests/, for the .data's ../framework/data_files paths. check.py compares -# each case with cases.txt, not the suite's exit code. +# each case with cases.txt, and the exit status with the outcomes. +# exitcode=23 makes ASan exit 23 on an error or leak, instead of 1 as for a +# failed case. 23 is arbitrary: any value other than 0 or 1 works. define run_suite @rm -f $(dir $<)outcome.csv -cd $(MBEDTLS_CLONE)/tests && \ - MBEDTLS_TEST_OUTCOME_FILE=$(dir $<)outcome.csv $(WRAP) $< \ - $(SUITE_NAME).datax > $<.log 2>&1 || true @echo "$(1), $(MBEDTLS_REF)" -@python3 $(SUITE)/check.py $(2) $(SUITE)/cases.txt $(dir $<)outcome.csv || \ - { echo "Log: $<.log"; exit 1; } +cd $(MBEDTLS_CLONE)/tests && ASAN_OPTIONS=$$ASAN_OPTIONS:exitcode=23 \ + MBEDTLS_TEST_OUTCOME_FILE=$(dir $<)outcome.csv $(WRAP) $< \ + $(SUITE_NAME).datax > $<.log 2>&1; \ + python3 $(SUITE)/check.py $(2) $(SUITE)/cases.txt \ + $(dir $<)outcome.csv $$? || { echo "Log: $<.log"; exit 1; } endef # $(call link,flags,libraries) links the C source and objects among the diff --git a/test/mbedtls_compat/ssl_suite/check.py b/test/mbedtls_compat/ssl_suite/check.py index ce3427c..9f1293a 100644 --- a/test/mbedtls_compat/ssl_suite/check.py +++ b/test/mbedtls_compat/ssl_suite/check.py @@ -4,10 +4,11 @@ # SPDX-License-Identifier: GPL-3.0-or-later # # Prints what passes per group and what the rest waits on, then each case -# whose outcome differs from cases.txt, and exits 1 if there is one. +# whose outcome differs from cases.txt, and exits 1 if there is one. STATUS, +# the suite's exit status, must be 1 if a case failed, else 0. # --all-pass: every case that runs must pass, as against Mbed TLS itself. # -# Usage: check.py [--all-pass] CASES OUTCOME +# Usage: check.py [--all-pass] CASES OUTCOME STATUS import collections import sys @@ -22,9 +23,10 @@ def main(): all_pass = args[:1] == ['--all-pass'] if all_pass: args = args[1:] - if len(args) != 2: - sys.exit('Usage: check.py [--all-pass] CASES OUTCOME') - cases_path, outcome_path = args + if len(args) != 3: + sys.exit('Usage: check.py [--all-pass] CASES OUTCOME STATUS') + cases_path, outcome_path = args[:2] + status = int(args[2]) listed = cases.read(cases_path) if all_pass: @@ -40,6 +42,7 @@ def main(): results[fields[3]] = (fields[4], fields[5]) except FileNotFoundError: pass + expect_status = int(any(r == 'FAIL' for r, _ in results.values())) bad = [] for desc, (result, reason) in results.items(): @@ -76,6 +79,9 @@ def main(): if bad: print('Not as in cases.txt:') print('\n'.join(' ' + b for b in bad)) + if status != expect_status: + print('Exit status %d, expected %d' % (status, expect_status)) + if bad or status != expect_status: sys.exit(1) From a08f3de805264341be3bf28a71379a2eb4258183 Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Mon, 16 Nov 2026 15:25:55 -0800 Subject: [PATCH 10/10] Pin mbed 4.2.0, Makefile fixes, duplicate case detection, enable asan, etc --- test/mbedtls_compat/Makefile | 57 ++++++++++++++------- test/mbedtls_compat/programs.sh | 15 ++++-- test/mbedtls_compat/ssl_suite/mbedtls.patch | 13 +++-- test/mbedtls_compat/ssl_suite/select.py | 8 ++- wolfpsa/mbedtls_compat/mbedtls/build_info.h | 6 --- 5 files changed, 62 insertions(+), 37 deletions(-) diff --git a/test/mbedtls_compat/Makefile b/test/mbedtls_compat/Makefile index f167db7..01fdcb9 100644 --- a/test/mbedtls_compat/Makefile +++ b/test/mbedtls_compat/Makefile @@ -2,7 +2,7 @@ # targets in the wolfPSA root (make help there), which set the paths, all # absolute. -ifndef WOLFPSA_PATH +ifeq ($(and $(WOLFPSA_PATH),$(BUILD_DIR)),) $(error Run make MBEDTLS_COMPAT=1 mbedtls-compat-test in the wolfPSA root) endif @@ -23,9 +23,10 @@ LAYER_FLAGS += -DMBEDTLS_THREADING_C LAYER_LIBS += -pthread endif -# Mbed TLS 4.x: MBEDTLS_PATH, or by default a shallow clone of MBEDTLS_REF +# Mbed TLS 4.x: MBEDTLS_PATH, or by default a shallow clone of MBEDTLS_REF, +# the release in MBEDTLS_VERSION_STRING MBEDTLS_URL := https://github.com/Mbed-TLS/mbedtls.git -MBEDTLS_REF := ba07f72f934a002021731a2bb5e564e5905f6569 +MBEDTLS_REF := mbedtls-4.2.0 MBEDTLS_CLONE := $(BUILD_DIR)/mbedtls MBEDTLS_PATH ?= $(MBEDTLS_CLONE) # Named with the ref, so a new MBEDTLS_REF clones again @@ -58,13 +59,13 @@ ifeq ($(MBEDTLS_THREADING_C),1) PROGRAMS += $(BUILD_DIR)/programs/ssl/ssl_pthread_server endif # Mbed TLS test certificates, data only. certs.c and the generated -# test_certs.h build against the Mbed TLS checkout's own headers. +# test_certs.h build against the headers of their Mbed TLS tree, CERTS_TREE: +# MBEDTLS_PATH for unit and programs, the clone for the suite. CERTS := $(BUILD_DIR)/certs.o CERTS_H := $(BUILD_DIR)/include/test/test_certs.h -MBEDTLS_FLAGS := -I$(BUILD_DIR)/include -I$(MBEDTLS_PATH)/include \ - -I$(MBEDTLS_PATH)/tests/include \ - $(addprefix -I$(MBEDTLS_PATH)/tf-psa-crypto/,include core \ - drivers/builtin/include) +MBEDTLS_FLAGS = -I$(@D)/include $(addprefix -I$(CERTS_TREE)/,include \ + tests/include $(addprefix tf-psa-crypto/,include core \ + drivers/builtin/include)) # Mbed TLS's ssl suite: the cases in cases.txt, on the clone and its patch SUITE := $(CURDIR)/ssl_suite @@ -76,14 +77,21 @@ SUITE_HELPERS := $(addprefix $(SUITE_BUILD)/,helpers.o random.o \ SUITE_OBJS := $(SUITE_NAME).o $(SUITE_BUILD)/ssl_helpers.o \ $(SUITE_BUILD)/ssl_helpers_port.o $(SUITE_BUILD)/psa_crypto_helpers.o \ $(SUITE_HELPERS) +SUITE_CERTS := $(SUITE_BUILD)/certs.o +SUITE_CERTS_H := $(SUITE_BUILD)/include/test/test_certs.h SUITE_TEMPLATES := $(MBEDTLS_CLONE)/tf-psa-crypto/tests/suites # wolfPSA's headers first; Mbed TLS's public headers are not on the path. # TEST_WOLFPSA leaves out the helpers' calls that wolfPSA does not have yet. -SUITE_FLAGS := $(LAYER_FLAGS) -DTEST_WOLFPSA -I$(SUITE) -I$(SUITE)/shim \ +# Cases depend on the X.509 options, which wolfPSA does not define since it +# lacks the functions they enable. +SUITE_FLAGS := $(LAYER_FLAGS) -DTEST_WOLFPSA -DMBEDTLS_X509_USE_C \ + -DMBEDTLS_X509_RSASSA_PSS_SUPPORT -I$(SUITE) -I$(SUITE)/shim \ $(addprefix -I$(MBEDTLS_CLONE)/,framework/tests/include tests/include \ tf-psa-crypto/tests/include framework/tests/src) \ -idirafter $(MBEDTLS_CLONE)/tf-psa-crypto/core -SUITE_PUBLIC_HEADERS := $(MBEDTLS_CLONE)/(tf-psa-crypto/)?include/ +# grep -F options for headers in Mbed TLS's public include directories +SUITE_PUBLIC_HEADERS := $(foreach d,include tf-psa-crypto/include, \ + -e '$(MBEDTLS_CLONE)/$(d)/') # The same suite and ssl_helpers_port.c on Mbed TLS's CMake build of the clone REF_BUILD := $(BUILD_DIR)/ssl_suite_ref REF_NAME := $(REF_BUILD)/test_suite_ssl_public @@ -141,8 +149,12 @@ suite: $(SUITE_NAME) suite-ref: $(REF_NAME) $(call run_suite,Mbed TLS ssl suite on Mbed TLS,--all-pass) -# Saves the clone's changes to mbedtls.patch, below its license lines +# Saves the clone's changes to mbedtls.patch, below its license lines. A +# clone that only unit or programs used has none. suite-patch: + @if git -C $(MBEDTLS_CLONE) diff --quiet HEAD; then \ + echo "No changes in $(MBEDTLS_CLONE)"; exit 1; \ + fi @mkdir -p $(SUITE_BUILD) { sed '/^diff --git/,$$d' $(SUITE)/mbedtls.patch; \ git -C $(MBEDTLS_CLONE) -c diff.suppressBlankEmpty=true \ @@ -171,15 +183,20 @@ $(CLIENT) $(UNIT) $(PROGRAMS): $(WOLFPSA_LIB) @mkdir -p $(@D) $(call link,$(LAYER_FLAGS),$(LAYER_LIBS)) -$(CERTS_H): +$(CERTS) $(CERTS_H): CERTS_TREE := $(MBEDTLS_PATH) +$(SUITE_CERTS) $(SUITE_CERTS_H): CERTS_TREE := $(MBEDTLS_CLONE) +$(SUITE_CERTS_H): $(MBEDTLS_STAMP) +$(CERTS_H) $(SUITE_CERTS_H): @mkdir -p $(@D) - PYTHONPATH=$(MBEDTLS_PATH)/framework/scripts python3 \ - $(MBEDTLS_PATH)/framework/scripts/generate_test_cert_macros.py \ + PYTHONPATH=$(CERTS_TREE)/framework/scripts python3 \ + $(CERTS_TREE)/framework/scripts/generate_test_cert_macros.py \ --output $@ $(CERTS): $(MBEDTLS_PATH)/tests/src/certs.c $(CERTS_H) +$(SUITE_CERTS): $(MBEDTLS_CLONE)/tests/src/certs.c $(SUITE_CERTS_H) +$(CERTS) $(SUITE_CERTS): $(CC) $(MBEDTLS_FLAGS) $(CPPFLAGS) $(CFLAGS) $(SANITIZE_FLAGS) \ - $(WARNFLAGS) -c -o $@ $< + $(WARNFLAGS) -c -o $@ $(filter %.c,$^) $(MBEDTLS_STAMP): rm -rf $(MBEDTLS_CLONE) $(MBEDTLS_CLONE)-* @@ -227,13 +244,15 @@ $(SUITE_OBJS): $(SUITE_PATCHED) @mkdir -p $(@D) $(CC) $(SUITE_FLAGS) $(CPPFLAGS) $(CFLAGS) $(SANITIZE_FLAGS) \ $(WARNFLAGS) -MD -MP -c -o $@ $(filter %.c,$^) - @if grep -q -E '$(SUITE_PUBLIC_HEADERS)' $(@:.o=.d); then \ - grep -o -E '$(SUITE_PUBLIC_HEADERS)[^ :]*' $(@:.o=.d) | \ - sort -u; \ + @hdrs=$$(sed -n 's/:$$//p' $(@:.o=.d) | \ + grep -F $(SUITE_PUBLIC_HEADERS) | sort -u); \ + if [ -n "$$hdrs" ]; then \ + echo "$$hdrs"; \ echo "$@: uses Mbed TLS's public headers"; rm $@; exit 1; \ fi -$(SUITE_NAME): $(SUITE_OBJS) $(CERTS) $(WOLFPSA_LIB) $(SUITE_NAME).datax +$(SUITE_NAME): $(SUITE_OBJS) $(SUITE_CERTS) $(WOLFPSA_LIB) \ + $(SUITE_NAME).datax $(call link,,$(LAYER_LIBS)) # Mbed TLS's CMake build needs tf-psa-crypto's own framework submodule, and diff --git a/test/mbedtls_compat/programs.sh b/test/mbedtls_compat/programs.sh index dbeb9cc..1858e07 100755 --- a/test/mbedtls_compat/programs.sh +++ b/test/mbedtls_compat/programs.sh @@ -16,6 +16,8 @@ DATA=$MBEDTLS_PATH/framework/data_files READY=$BUILD_DIR/server-ready FAILS=0 SKIPS=0 +# A sanitizer report fails a case, whatever the exit code +SANITIZER="ERROR: [A-Za-z]*Sanitizer" if [ ! -f "$DATA/server5.crt" ]; then echo "$DATA not found, run git submodule update --init in $MBEDTLS_PATH" @@ -69,7 +71,8 @@ while IFS='|' read -r name prog args sopts wrap expect want; do start_server "$sopts" out=$(cd "$WOLFSSL_PATH" && $wrap $WRAP "$BUILD_DIR/$prog" $args 2>&1) rc=$? - if [ $rc -eq "$expect" ] && ! echo "$out" | grep -q "not defined" && + if [ $rc -eq "$expect" ] && + ! echo "$out" | grep -q -e "not defined" -e "$SANITIZER" && echo "$out" | grep -qF -- "$want"; then echo "PASS: $name" else @@ -98,7 +101,7 @@ CASES rm -f "$READY" # The server programs listen on port 4433 until stopped. The exit code of a -# server is not checked. +# server is not checked, only its log for sanitizer reports. start_program() { rm -f "$LOG" (cd "$WOLFSSL_PATH" && exec $WRAP "$BUILD_DIR/$1") >"$LOG" 2>&1 & @@ -174,9 +177,15 @@ while IFS='|' read -r name prog clients; do rm -f "$LOG".* done unset IFS + # ssl_fork_server's children exit at their next write, a second later + i=0 + while pgrep -P $srv >/dev/null && [ $i -lt 50 ]; do + i=$((i + 1)) + sleep 0.1 + done kill $srv 2>/dev/null wait $srv 2>/dev/null - if [ -z "$out" ]; then + if [ -z "$out" ] && ! grep -q "$SANITIZER" "$LOG"; then echo "PASS: $name" else echo "FAIL: $name:$out diff --git a/test/mbedtls_compat/ssl_suite/mbedtls.patch b/test/mbedtls_compat/ssl_suite/mbedtls.patch index 9ccfb7e..104c324 100644 --- a/test/mbedtls_compat/ssl_suite/mbedtls.patch +++ b/test/mbedtls_compat/ssl_suite/mbedtls.patch @@ -253,10 +253,10 @@ index ebb9103..6608d62 100644 #endif /* MBEDTLS_SSL_TLS_C */ diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function -index 7a9a03a..903815e 100644 +index c1cf9ba..f768640 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function -@@ -1,18 +1,11 @@ +@@ -1,17 +1,11 @@ /* BEGIN_HEADER */ -#include +#include @@ -268,7 +268,6 @@ index 7a9a03a..903815e 100644 -#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */ -#include -#include --#include #include -#include @@ -276,7 +275,7 @@ index 7a9a03a..903815e 100644 #include #define SSL_MESSAGE_QUEUE_INIT { NULL, 0, 0, 0 } -@@ -97,6 +90,8 @@ static int failing_ticket_write_unset_lifetime( +@@ -61,6 +55,8 @@ static int failing_ticket_write_unset_lifetime( PSA_WANT_ALG_SHA_256 && PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY && MBEDTLS_CAN_HANDLE_RSA_TEST_KEY */ @@ -285,7 +284,7 @@ index 7a9a03a..903815e 100644 #if defined(MBEDTLS_SSL_TLS_C) && defined(MBEDTLS_DEBUG_C) && \ defined(MBEDTLS_SSL_CLI_C) && defined(MBEDTLS_SSL_SRV_C) && \ defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) && \ -@@ -143,6 +138,7 @@ static void tls_abort_transcript(void *ctx, int level, +@@ -107,6 +103,7 @@ static void tls_abort_transcript(void *ctx, int level, #endif } #endif @@ -293,7 +292,7 @@ index 7a9a03a..903815e 100644 #if (!defined(MBEDTLS_SSL_PROTO_TLS1_2)) && \ defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C) && \ -@@ -203,8 +199,9 @@ typedef struct { +@@ -167,8 +164,9 @@ typedef struct { static void pre_handshake_tweak_context(mbedtls_ssl_context *ssl, int tweaks) { @@ -304,7 +303,7 @@ index 7a9a03a..903815e 100644 } } -@@ -274,12 +271,12 @@ static void simulate_badmac_seen_on(mbedtls_test_ssl_endpoint *client, +@@ -238,12 +236,12 @@ static void simulate_badmac_seen_on(mbedtls_test_ssl_endpoint *client, void *param) { int on = *(int *) param; diff --git a/test/mbedtls_compat/ssl_suite/select.py b/test/mbedtls_compat/ssl_suite/select.py index 74738f7..935dadb 100644 --- a/test/mbedtls_compat/ssl_suite/select.py +++ b/test/mbedtls_compat/ssl_suite/select.py @@ -11,6 +11,7 @@ # Usage: select.py CASES SUITES_DIR OUT_DIR (SUITES_DIR: the clone's # tests/suites) +import collections import os import re import sys @@ -61,8 +62,11 @@ def main(): upstream = {desc: func for desc, func, _ in data} listed_funcs = {func for desc, func, _ in data if desc in listed} - errors = ['listed, not in Mbed TLS: ' + desc - for desc in listed if desc not in upstream] + count = collections.Counter(desc for desc, _, _ in data) + errors = ['in Mbed TLS twice: ' + desc + for desc in listed if count[desc] > 1] + errors += ['listed, not in Mbed TLS: ' + desc + for desc in listed if desc not in upstream] errors += ['function is %s in Mbed TLS: %s' % (upstream[desc], desc) for desc, case in listed.items() if desc in upstream and case.function != upstream[desc]] diff --git a/wolfpsa/mbedtls_compat/mbedtls/build_info.h b/wolfpsa/mbedtls_compat/mbedtls/build_info.h index b4c057a..aa725c9 100644 --- a/wolfpsa/mbedtls_compat/mbedtls/build_info.h +++ b/wolfpsa/mbedtls_compat/mbedtls/build_info.h @@ -36,12 +36,6 @@ #define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 4.2.0" /* MBEDTLS_X509_CRT_PARSE_C and MBEDTLS_SSL_* are in the generated config */ -#if defined(MBEDTLS_X509_CRT_PARSE_C) - #define MBEDTLS_X509_USE_C -#if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) && defined(PSA_WANT_ALG_RSA_PSS) - #define MBEDTLS_X509_RSASSA_PSS_SUPPORT -#endif /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY && PSA_WANT_ALG_RSA_PSS */ -#endif /* MBEDTLS_X509_CRT_PARSE_C */ #if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(PSA_WANT_ALG_ECDH) #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED #endif /* MBEDTLS_SSL_PROTO_TLS1_3 && PSA_WANT_ALG_ECDH */