Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .github/workflows/mbedtls-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Comment thread
Frauschi marked this conversation as resolved.
Resolved

Expand All @@ -51,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
90 changes: 59 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ?=
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) \
Expand Down Expand Up @@ -291,43 +300,53 @@ 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 ==="; \
rm -rf .store test/.store; \
./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

# Mbed TLS repo, for its test data and sample programs
MBEDTLS_PATH ?= ../mbedtls

# 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_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))) \
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-<name> runs <name> 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)
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)
$(MAKE) -C test/mbedtls_compat WOLFPSA_PATH=$(CURDIR) \
WOLFSSL_PATH=$(abspath $(WOLFSSL_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_TESTS): $(LIBNAME)
$(MBEDTLS_COMPAT_TARGETS): mbedtls-compat-%:
$(MBEDTLS_COMPAT_MAKE) $*
else
$(MBEDTLS_COMPAT_TESTS):
$(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
Expand Down Expand Up @@ -367,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)
43 changes: 38 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -240,12 +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:

- `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, 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
Expand All @@ -255,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, 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
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)

Expand Down
Loading
Loading