Skip to content

Run Mbed TLS's TLS unit test against the compat layer - #55

Open
padelsbach wants to merge 14 commits into
wolfSSL:masterfrom
padelsbach:mbedtls-ssl-suite
Open

padelsbach wants to merge 14 commits into
wolfSSL:masterfrom
padelsbach:mbedtls-ssl-suite

Conversation

@padelsbach

@padelsbach padelsbach commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow up to #54. Merge that first.

Isolate the MbedTLS unit tests which run with the public API, and enable them to run on wolfPSA's MbedTLS compat layer.

make MBEDTLS_COMPAT=1 mbedtls-compat-suite runs the tests on wolfPSA
make MBEDTLS_COMPAT=1 mbedtls-compat-suite-ref runs the tests on MbedTLS

New cases.txt file contains the list of expected pass/fail results per test.

Copilot AI balanced review requested due to automatic review settings November 13, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Custom wolfSSL settings can bypass the configured TLS 1.2 minimum, while the test runner suppresses sanitizer and wrapper failures.

2 open issues
What changed in this PR

Building on #54’s compatibility APIs, this PR enables selected Mbed TLS public-API TLS tests to run against wolfPSA and against Mbed TLS as a reference.

Changes:

  • Adds test selection, public-API helper replacements, and expected outcomes in cases.txt.
  • Integrates TLS, networking, and PEM compatibility support with builds and lifecycle management.
  • Expands compatibility tests, CI coverage, and usage documentation.
File Description
wolfpsa/​tf-psa-crypto/​build_info.h Adds version and signature capability macros.
wolfpsa/​mbedtls/​threading.h Includes private-access compatibility macros.
wolfpsa/​mbedtls/​private_access.h Adds private-member annotation support.
wolfpsa/​mbedtls/​platform_util.h Adds deprecation and return-value annotations.
wolfpsa/​mbedtls_compat/​mbedtls/​version.h Exposes compatibility version macros.
wolfpsa/​mbedtls_compat/​mbedtls/​timing.h Adds a timing header placeholder.
wolfpsa/​mbedtls_compat/​mbedtls/​ssl.h Declares TLS compatibility types and APIs.
wolfpsa/​mbedtls_compat/​mbedtls/​ssl_ciphersuites.h Defines cipher-suite identifiers and capabilities.
wolfpsa/​mbedtls_compat/​mbedtls/​psa_util.h Provides a PSA utility header placeholder.
wolfpsa/​mbedtls_compat/​mbedtls/​pem.h Declares PEM decoding APIs.
wolfpsa/​mbedtls_compat/​mbedtls/​net_sockets.h Declares networking compatibility APIs.
wolfpsa/​mbedtls_compat/​mbedtls/​error.h Defines shared compatibility error codes.
wolfpsa/​mbedtls_compat/​mbedtls/​debug.h Provides the debug compatibility header.
wolfpsa/​mbedtls_compat/​mbedtls/​build_info.h Derives X.509 and TLS capability macros.
wolfpsa.map Exports networking, PEM, and TLS symbols.
user_settings.h Enables wolfSSL TLS for compatibility builds.
tools/​psa_want_probe.c Detects compatibility feature availability.
test/​psa_server/​psa_track_memory_test.c Checks PEM/TLS allocation and library cleanup.
test/​mbedtls_compat/​ssl_suite/​ssl_helpers_port.h Declares the helper-port interface.
test/​mbedtls_compat/​ssl_suite/​ssl_helpers_port.c Replaces internal helpers with public-API calls.
test/​mbedtls_compat/​ssl_suite/​shim/​threading_internal.h Supplies a threading header shim.
test/​mbedtls_compat/​ssl_suite/​shim/​psa_crypto_helpers.c Stubs the internal key-slot leak check.
test/​mbedtls_compat/​ssl_suite/​shim/​mbedtls/​private/​pk_private.h Supplies test key-type constants.
test/​mbedtls_compat/​ssl_suite/​shim/​mbedtls/​private/​error_common.h Redirects tests to compatibility errors.
test/​mbedtls_compat/​ssl_suite/​shim/​mbedtls/​private/​entropy.h Maps the entropy failure code.
test/​mbedtls_compat/​ssl_suite/​shim/​mbedtls/​private/​ctr_drbg.h Supplies an unused-header placeholder.
test/​mbedtls_compat/​ssl_suite/​select.py Selects cases and checks upstream consistency.
test/​mbedtls_compat/​ssl_suite/​mbedtls.patch Adapts upstream tests and helpers.
test/​mbedtls_compat/​ssl_suite/​CMakeLists.txt Builds the Mbed TLS reference suite.
test/​mbedtls_compat/​ssl_suite/​check.py Compares outcomes with expected results.
test/​mbedtls_compat/​ssl_suite/​cases.txt Records cases, expectations, and exclusions.
test/​mbedtls_compat/​ssl_suite/​cases.py Parses and validates the case list.
test/​mbedtls_compat/​programs.sh Runs sample-program interoperability checks.
test/​mbedtls_compat/​pem_test.c Tests PEM decoding and error handling.
test/​mbedtls_compat/​Makefile Builds and runs compatibility test targets.
test/​mbedtls_compat/​client-tls-mbedtls.c Adds a migration-guide TLS test client.
test/​Makefile Configures compatibility memory-tracking builds.
src/​psa_crypto.c Manages wolfSSL initialization and cleanup.
src/​mbedtls/​ssl.c Implements TLS compatibility over wolfSSL.
src/​mbedtls/​pem.c Implements PEM decoding over wolfCrypt.
src/​mbedtls/​net.c Implements socket compatibility functions.
src/​mbedtls/​mbedtls_compat_internal.h Shares internal I/O conversion helpers.
README.md Documents APIs, limitations, and test workflows.
Makefile Integrates TLS sources and compatibility targets.
.github/​workflows/​test-psa-api.yml Disables compatibility for stable wolfSSL testing.
.github/​workflows/​mbedtls-compat.yml Expands compatibility and reference-suite CI.

Review effort: Balanced

Comment thread src/mbedtls/ssl.c Resolved
Comment thread test/mbedtls_compat/Makefile Resolved
@padelsbach
padelsbach requested a review from Frauschi November 13, 2026 22:02
@padelsbach padelsbach changed the title Run Mbed TLS's TLS unit test against the compat layer" Run Mbed TLS's TLS unit test against the compat layer Nov 13, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 comments inline, nothing blocking.

# Certificate and key parsing, on Mbed TLS's test data
# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MBEDTLS_REF is an untagged development commit, 136 commits past mbedtls-4.2.0, so unit and programs now test unreleased Mbed TLS while the headers say 4.2.0. Pin the 4.2.0 tag if the suite allows it, or say in the README why it needs a later commit.

$(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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suite-patch has no prerequisite on $(SUITE_PATCHED), so on a clone that unit or programs made it saves an unpatched diff over mbedtls.patch and then touches the stamp. Make it depend on $(SUITE_PATCHED).

$(WARNFLAGS) -c -o $@ $<

$(MBEDTLS_STAMP):
rm -rf $(MBEDTLS_CLONE) $(MBEDTLS_CLONE)-*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With BUILD_DIR unset this recipe runs rm -rf /mbedtls /mbedtls-*, and the file only guards WOLFPSA_PATH. Add BUILD_DIR to the ifndef check at the top.

echo "$@: uses Mbed TLS's public headers"; rm $@; exit 1; \
fi

$(SUITE_NAME): $(SUITE_OBJS) $(CERTS) $(WOLFPSA_LIB) $(SUITE_NAME).datax

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README says the suite always uses the clone, but it links $(CERTS), built from $(MBEDTLS_PATH)/tests/src/certs.c. Build the suite's copy from $(MBEDTLS_CLONE).

git -C ../mbedtls submodule update --init --depth 1 framework

- name: Build and run the compatibility tests
run: make MBEDTLS_COMPAT=1 ${{ matrix.options }} mbedtls-compat-test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ASan lane, programs.sh kills the Mbed TLS servers without checking their log, so a sanitizer report from the TLS server code still passes (from #54). Fail the case when the server log contains ERROR: AddressSanitizer.

* 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MBEDTLS_X509_USE_C and MBEDTLS_X509_RSASSA_PSS_SUPPORT now reach every compat user, but x509.h has none of the mbedtls_x509_* functions they gate in Mbed TLS. Define them in the suite's flags instead.

$(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/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUITE_PUBLIC_HEADERS puts the clone path into a grep -E pattern unescaped, so with a + or ( in the build path the public-header check never matches and passes silently. Escape the path first.

name = re.search(r'\nvoid\s+(\w+)\s*\(', m.group(0)).group(1)
bodies[name] = m.group(0)

upstream = {desc: func for desc, func, _ in data}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cases are keyed by description across both .data files, so a description repeated upstream would collapse into one result in check.py. Mbed TLS has none today; fail here if one appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants