Repository navigation
Run Mbed TLS's TLS unit test against the compat layer - #55
padelsbach wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
🟡 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
5836478 to
ff7fba1
Compare
ff7fba1 to
fa62260
Compare
Frauschi
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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)-* |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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/ |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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.


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-suiteruns the tests on wolfPSAmake MBEDTLS_COMPAT=1 mbedtls-compat-suite-refruns the tests on MbedTLSNew
cases.txtfile contains the list of expected pass/fail results per test.