From c27594212f2f89f5fc2e94faa8748215e993712d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Fri, 13 Nov 2026 09:28:22 +0100 Subject: [PATCH 1/2] Make wolfcert_buffer_free_secure public The test server is about to hand out its CA private key in a WolfCertBuffer, and freeing that with wolfcert_buffer_free() leaves the key bytes in freed heap. Export the wiping variant the library already uses internally. wolfcert_buffer_free() stays a plain free, so certificate and response buffers pay no wiping cost. --- src/internal.h | 2 -- wolfcert/types.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal.h b/src/internal.h index 65d9f74..2e9a4a1 100644 --- a/src/internal.h +++ b/src/internal.h @@ -107,8 +107,6 @@ WOLFCERT_TEST_VIS int wolfcert_ca_load(WolfCertCa* ca, WolfCertStoreOps* store, void* heap); int wolfcert_ca_save(const WolfCertCa* ca, WolfCertStoreOps* store); WOLFCERT_TEST_VIS void wolfcert_ca_free(WolfCertCa* ca); -/* wolfcert_buffer_free() after wiping: for a buffer that held key material. */ -void wolfcert_buffer_free_secure(WolfCertBuffer* buf); /* Rebuild an issued certificate's subject from a decoded CSR. */ WOLFCERT_TEST_VIS int wolfcert_copy_csr_subject(const DecodedCert* dc, Cert* nc); diff --git a/wolfcert/types.h b/wolfcert/types.h index 9cad4e4..f2d3b1a 100644 --- a/wolfcert/types.h +++ b/wolfcert/types.h @@ -244,6 +244,8 @@ typedef struct { } WolfCertBuffer; WOLFCERT_API void wolfcert_buffer_free(WolfCertBuffer* buf); +/* wolfcert_buffer_free() after wiping data, for a buffer holding a key. */ +WOLFCERT_API void wolfcert_buffer_free_secure(WolfCertBuffer* buf); #ifdef __cplusplus } From da1d30f68d1ba24f9ebbebbb9ab518b73d3e88fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Fri, 13 Nov 2026 09:28:22 +0100 Subject: [PATCH 2/2] Remove the store; give the test server its CA as buffers Drop WolfCertStoreOps, wolfcert/store.h, src/store.c with its POSIX and in-memory backends, the WOLFCERT_ENABLE_POSIX_STORE / --enable-posix-store option and the WOLFCERT_HAVE_POSIX_STORE / WOLFCERT_NO_POSIX_STORE check in check_config.h. Nothing on the client side used the store: enroll, the CLI client, the examples and the Zephyr sample all handle their own files. The key and cert helpers were wolfcert_key_to_pem / wolfcert_key_from_pem plus one vtable call, which applications can already make. The vtable could not help where persistence is hard on a device either: a renewal has to replace the certificate and key together, which per-object writes cannot guarantee across a power cut, and a key held in a CryptoCb backend cannot be exported into it. Once in 1.0 it would have been frozen ABI; a store can still be added later without breaking anyone. The test server was the only user, for CA persistence. Its config loses ca_store and gains ca_cert / ca_key (PEM or DER, copied at start; both NULL generates a CA, one without the other is WOLFCERT_ERR_BAD_ARG), and wolfcert_server_get_ca() copies out the CA a server issues from, so a caller can keep a generated one for the next start. wolfcert_ca_load() now takes the two buffers and wolfcert_ca_save() is gone. The key is decoded and re-encoded, so a PKCS#8 RSA or ECC key comes back out under the PEM label that matches its body; a DER certificate or key with trailing bytes is refused rather than half-read. Removing ca_store from the middle of WolfCertServerCfgSrv breaks the ABI; the SOVERSION bump planned for 1.0 covers it. test_server_ca_store becomes test_server_ca and covers the DER and PEM round trip, a half or empty pair, the get_ca arguments, every algorithm reloading from both encodings, a PKCS#8 key, an ECC key without its public point, a padded certificate or key, mixed encodings, get_ca on a split-RA SCEP server, and the OOM sweep on the load path. The integration tests share one CA per process, minted with mint_self_id() and set through TEST_CA_CFG in tls_test_util.h, instead of a memory store. test_store and the Zephyr wolfcert.unit.store suite are removed. --- .github/workflows/nightly.yml | 4 +- .github/workflows/pr.yml | 3 +- .github/workflows/sanitizers.yml | 2 +- .github/workflows/zephyr.yml | 2 +- AGENTS.md | 8 +- CMakeLists.txt | 6 +- Makefile.am | 14 +- README.md | 5 +- configure.ac | 9 - docs/ARCHITECTURE.md | 46 +- docs/EMBEDDED.md | 12 +- docs/MIGRATING-FROM-WOLFSCEP.md | 1 - examples/user_settings.h.example | 5 +- scripts/ci/compile-freestanding.sh | 6 +- scripts/ci/freestanding-user_settings.h | 3 +- scripts/ci/wolfcert-only-user_settings.h | 1 - src/ca_issue.c | 212 +++-- src/internal.h | 7 +- src/server.c | 42 +- src/store.c | 463 ---------- tests/CMakeLists.txt | 12 +- tests/integration/test_est_async_roundtrip.c | 6 +- .../integration/test_est_chunked_robustness.c | 6 +- .../test_est_csr_attrs_apply_roundtrip.c | 4 +- .../integration/test_est_csr_attrs_enforce.c | 10 +- .../test_est_csr_attrs_roundtrip.c | 6 +- tests/integration/test_est_mldsa_roundtrip.c | 4 +- tests/integration/test_est_mtls_roundtrip.c | 33 +- .../integration/test_est_pending_roundtrip.c | 4 +- tests/integration/test_est_pha_roundtrip.c | 6 +- tests/integration/test_est_roundtrip.c | 6 +- tests/integration/test_est_tls_roundtrip.c | 31 +- tests/integration/test_scep_async_roundtrip.c | 24 +- tests/integration/test_scep_get_cert.c | 6 +- tests/integration/test_scep_poll_roundtrip.c | 8 +- tests/integration/test_scep_roundtrip.c | 14 +- tests/integration/test_server_stop_idle.c | 45 +- tests/integration/tls_test_util.h | 79 +- ...est_server_ca_store.c => test_server_ca.c} | 797 ++++++++---------- tests/unit/test_store.c | 122 --- wolfcert/check_config.h | 3 - wolfcert/options.h.in | 1 - wolfcert/server.h | 25 +- wolfcert/store.h | 81 -- wolfcert/wolfcert.h | 1 - zephyr/CMakeLists.txt | 3 - zephyr/README.md | 3 +- zephyr/include.am | 3 - .../tests/wolfcert_unit_store/CMakeLists.txt | 12 - zephyr/tests/wolfcert_unit_store/prj.conf | 4 - .../tests/wolfcert_unit_store/testcase.yaml | 14 - 51 files changed, 739 insertions(+), 1485 deletions(-) delete mode 100644 src/store.c rename tests/unit/{test_server_ca_store.c => test_server_ca.c} (53%) delete mode 100644 tests/unit/test_store.c delete mode 100644 wolfcert/store.h delete mode 100644 zephyr/tests/wolfcert_unit_store/CMakeLists.txt delete mode 100644 zephyr/tests/wolfcert_unit_store/prj.conf delete mode 100644 zephyr/tests/wolfcert_unit_store/testcase.yaml diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 337de17..d6d462c 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -44,8 +44,8 @@ jobs: - { name: cmake-mldsa-44off, os: ubuntu-latest, build: cmake, wolfssl: mldsa-44off } - { name: cmake-mldsa-65off, os: ubuntu-latest, build: cmake, wolfssl: mldsa-65off } - { name: cmake-mldsa-87off, os: ubuntu-latest, build: cmake, wolfssl: mldsa-87off } - # Platform pieces compiled out (transport/store gates) - - { name: cmake-no-builtin-transport, os: ubuntu-latest, build: cmake, wolfssl: full, cmake_extra: "-DWOLFCERT_ENABLE_BUILTIN_TRANSPORT=OFF -DWOLFCERT_ENABLE_POSIX_STORE=OFF -DWOLFCERT_ENABLE_CLI=OFF -DWOLFCERT_ENABLE_SERVER=OFF" } + # Platform pieces compiled out (transport gate) + - { name: cmake-no-builtin-transport, os: ubuntu-latest, build: cmake, wolfssl: full, cmake_extra: "-DWOLFCERT_ENABLE_BUILTIN_TRANSPORT=OFF -DWOLFCERT_ENABLE_CLI=OFF -DWOLFCERT_ENABLE_SERVER=OFF" } # Constrained builds (unit tests only: single-thread / no-malloc) - { name: cmake-static-mem, os: ubuntu-latest, build: cmake, wolfssl: static-mem, cmake_extra: -DWOLFCERT_ENABLE_SERVER=OFF, ctest_exclude: "http|tls|roundtrip" } # No TLS and no test server over a static pool; stop_idle and get_cert diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0212ae8..0113197 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -115,7 +115,7 @@ jobs: os: ubuntu-latest build: cmake wolfssl: mldsa-87off - # Platform pieces compiled out (the transport/store gates) + # Platform pieces compiled out (the transport gate) - name: cmake-no-builtin-transport os: ubuntu-latest build: cmake @@ -124,7 +124,6 @@ jobs: # skip themselves. cmake_extra: >- -DWOLFCERT_ENABLE_BUILTIN_TRANSPORT=OFF - -DWOLFCERT_ENABLE_POSIX_STORE=OFF -DWOLFCERT_ENABLE_CLI=OFF -DWOLFCERT_ENABLE_SERVER=OFF # Constrained builds (unit tests only: single-thread / no-malloc) diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 08e9b55..b05d381 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -117,7 +117,7 @@ jobs: # No roundtrips: wolfSSL's asm crypto gives false Memcheck reports # without a suppression file. rc=0 - for bin in test_smoke test_keygen test_csr test_store test_parse_negative \ + for bin in test_smoke test_keygen test_csr test_parse_negative \ test_scep_msg; do path="build/tests/$bin" [ -x "$path" ] || { echo "skip (not built): $bin"; continue; } diff --git a/.github/workflows/zephyr.yml b/.github/workflows/zephyr.yml index 69a04ad..10e9945 100644 --- a/.github/workflows/zephyr.yml +++ b/.github/workflows/zephyr.yml @@ -74,7 +74,7 @@ jobs: "${{ github.workspace }}/scripts/ci/twister-assert-ran.py" \ "$HOME/twister-unit/twister.json" \ wolfcert.unit.smoke wolfcert.unit.keygen wolfcert.unit.csr \ - wolfcert.unit.csr_attrs wolfcert.unit.store \ + wolfcert.unit.csr_attrs \ wolfcert.unit.parse_negative wolfcert.unit.scep_msg - name: Start the host EST server diff --git a/AGENTS.md b/AGENTS.md index db1f622..5b12f6d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -91,12 +91,11 @@ install provides the library, the public headers, a generated | `WOLFCERT_ENABLE_SERVER` | `--enable-server` | on | Minimal EST/SCEP test server | | `WOLFCERT_ENABLE_CLI` | `--enable-cli` | on | `wolfcert-client`, `wolfcert-server` | | `WOLFCERT_ENABLE_BUILTIN_TRANSPORT` | `--enable-builtin-transport` | on | POSIX socket transport; turn off on targets with no sockets | -| `WOLFCERT_ENABLE_POSIX_STORE` | `--enable-posix-store` | on | File-based cert/key store | | `WOLFCERT_BUILD_SHARED` | (libtool `--enable-shared`) | on | Shared vs static library | | `WOLFCERT_USER_SETTINGS` | `--enable-user-settings` | off | Read features from `user_settings.h` instead of the generated `options.h` | A device build usually turns off the server and CLI, and the built-in -transport and POSIX store where the target has no sockets or filesystem. +transport where the target has no sockets. ## Configuration model @@ -185,9 +184,8 @@ wolfcert_cleanup(); | `wolfcert/wolfcert.h` | Umbrella header, `wolfcert_init` / `wolfcert_cleanup` | | `wolfcert/client.h` | High-level `wolfcert_client_*` API | | `wolfcert/est.h`, `wolfcert/scep.h` | Protocol one-shots, sessions, non-blocking `_nb` sessions | -| `wolfcert/types.h` | `WolfCertServerCfg`, `WolfCertKeyCfg`, `WolfCertCertMeta`, `WolfCertEncoding` (PEM or DER output), `WolfCertTransport`, `wolfcert_buffer_free` | +| `wolfcert/types.h` | `WolfCertServerCfg`, `WolfCertKeyCfg`, `WolfCertCertMeta`, `WolfCertEncoding` (PEM or DER output), `WolfCertTransport`, `wolfcert_buffer_free` / `_secure` | | `wolfcert/keygen.h`, `wolfcert/csr.h` | Key generation, import / export, CSR building | -| `wolfcert/store.h` | `WolfCertStoreOps` storage vtable, POSIX and in-memory backends | | `wolfcert/errors.h`, `wolfcert/status.h`, `wolfcert/log.h` | Error codes, last-error detail, log callback | | `wolfcert/memory.h` | Default heap hint, allocation macros | | `examples/` | `enroll_est.c`, `enroll_scep.c`, `enroll_cryptocb.c`, `user_settings.h.example` | @@ -204,7 +202,7 @@ contract, alone or in a group comment. |---|---|---| | Static memory / custom heap | `wolfcert_init(heap)` sets the default heap hint; per-call `heap` fields override it, and the hint reaches every wolfSSL call | `wolfcert/memory.h`, README "Integrating with a wolfSSL static-memory pool" | | Network stack without BSD sockets (lwIP, NetX, FreeRTOS+TCP, wolfIP) | Fill `WolfCertServerCfg.transport` (`WolfCertTransport`); TLS records go through it too | `wolfcert/types.h`, `docs/EMBEDDED.md` section 7 | -| Persistence in flash / NVM | Implement `WolfCertStoreOps` (`read` / `write` / `remove`) | `wolfcert/store.h` | +| Persistence in flash / NVM | Store the buffers from `wolfcert_key_to_pem` / `_to_der` and the enroll result; wolfCert does no storage | `wolfcert/keygen.h` | | Keys in a TPM, HSM, PKCS#11 token or secure element | Register a backend with `wc_CryptoCb_RegisterDevice`, pass its id as `WolfCertKeyCfg.dev_id` | `docs/ARCHITECTURE.md` section 4.2, `examples/enroll_cryptocb.c` | | Event loop / no blocking | `wolfcert_est_session_open` / `wolfcert_scep_session_open`, then the `_nb` calls until they stop returning `WOLFCERT_ERR_WANT_READ` / `_WANT_WRITE`; `*_session_fd` gives the descriptor to poll | `wolfcert/est.h`, `wolfcert/scep.h` | | Logging | `wolfcert_set_log_cb` (e.g. to a UART) | `wolfcert/log.h` | diff --git a/CMakeLists.txt b/CMakeLists.txt index 34a2c92..ebe9a56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,6 @@ option(WOLFCERT_ENABLE_SERVER "Build the minimal EST/SCEP test server" ON) option(WOLFCERT_ENABLE_CLI "Build wolfcert-client / wolfcert-server" ON) option(WOLFCERT_ENABLE_TESTS "Build unit and integration tests" OFF) option(WOLFCERT_ENABLE_EXAMPLES "Build example programs" OFF) -option(WOLFCERT_ENABLE_POSIX_STORE "Build the POSIX file storage backend" ON) option(WOLFCERT_ENABLE_BUILTIN_TRANSPORT "Build the built-in POSIX socket transport" ON) option(WOLFCERT_WERROR "Treat warnings as errors" OFF) @@ -312,8 +311,6 @@ if(NOT WOLFCERT_USER_SETTINGS) _wc_opt(WOLFCERT_OPT_EST "${WOLFCERT_ENABLE_EST}" WOLFCERT_HAVE_EST) _wc_opt(WOLFCERT_OPT_SCEP "${WOLFCERT_ENABLE_SCEP}" WOLFCERT_HAVE_SCEP) _wc_opt(WOLFCERT_OPT_SERVER "${WOLFCERT_ENABLE_SERVER}" WOLFCERT_HAVE_SERVER) - _wc_plat(WOLFCERT_OPT_POSIX_STORE "${WOLFCERT_ENABLE_POSIX_STORE}" - WOLFCERT_HAVE_POSIX_STORE WOLFCERT_NO_POSIX_STORE) _wc_plat(WOLFCERT_OPT_BUILTIN_TRANSPORT "${WOLFCERT_ENABLE_BUILTIN_TRANSPORT}" WOLFCERT_HAVE_BUILTIN_TRANSPORT WOLFCERT_NO_BUILTIN_TRANSPORT) @@ -335,7 +332,6 @@ set(WOLFCERT_SOURCES src/key_algs.c src/keygen.c src/csr.c - src/store.c src/http.c src/client.c) @@ -641,6 +637,6 @@ endif() message(STATUS "wolfCert ${PROJECT_VERSION}: EST=${WOLFCERT_ENABLE_EST}, " "SCEP=${WOLFCERT_ENABLE_SCEP}, server=${WOLFCERT_ENABLE_SERVER}, " - "cli=${WOLFCERT_ENABLE_CLI}, posix_store=${WOLFCERT_ENABLE_POSIX_STORE}, " + "cli=${WOLFCERT_ENABLE_CLI}, " "builtin_transport=${WOLFCERT_ENABLE_BUILTIN_TRANSPORT}, " "user_settings=${WOLFCERT_USER_SETTINGS}") diff --git a/Makefile.am b/Makefile.am index 5b5ae96..1562a98 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,6 @@ libwolfcert_la_SOURCES = \ src/key_algs.h \ src/keygen.c \ src/csr.c \ - src/store.c \ src/http.c \ src/client.c @@ -68,7 +67,6 @@ wolfcertinclude_HEADERS = \ wolfcert/types.h \ wolfcert/keygen.h \ wolfcert/csr.h \ - wolfcert/store.h \ wolfcert/http.h \ wolfcert/est.h \ wolfcert/scep.h \ @@ -106,7 +104,7 @@ endif if WOLFCERT_BUILD_TESTS check_PROGRAMS = \ - test_smoke test_keygen test_csr test_store test_http test_transport \ + test_smoke test_keygen test_csr test_http test_transport \ test_parse_negative test_tls_http if WOLFCERT_HAVE_BUILTIN_TRANSPORT check_PROGRAMS += test_net @@ -119,8 +117,6 @@ test_keygen_LDADD = libwolfcert.la $(WOLFSSL_LIBS) test_csr_SOURCES = tests/unit/test_csr.c test_csr_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src test_csr_LDADD = libwolfcert.la $(WOLFSSL_LIBS) -test_store_SOURCES = tests/unit/test_store.c -test_store_LDADD = libwolfcert.la $(WOLFSSL_LIBS) test_transport_SOURCES = tests/unit/test_transport.c test_transport_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src test_transport_LDADD = libwolfcert.la $(WOLFSSL_LIBS) @@ -201,13 +197,13 @@ endif # Protocol-agnostic server tests. if WOLFCERT_HAVE_SERVER -check_PROGRAMS += test_server_stop_idle test_server_ca_store +check_PROGRAMS += test_server_stop_idle test_server_ca test_server_stop_idle_SOURCES = tests/integration/test_server_stop_idle.c test_server_stop_idle_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src test_server_stop_idle_LDADD = libwolfcert.la $(WOLFSSL_LIBS) -lpthread -test_server_ca_store_SOURCES = tests/unit/test_server_ca_store.c -test_server_ca_store_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src -test_server_ca_store_LDADD = libwolfcert.la $(WOLFSSL_LIBS) -lpthread +test_server_ca_SOURCES = tests/unit/test_server_ca.c +test_server_ca_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src +test_server_ca_LDADD = libwolfcert.la $(WOLFSSL_LIBS) -lpthread endif TESTS = $(check_PROGRAMS) diff --git a/README.md b/README.md index 1ba93fe..7387c88 100644 --- a/README.md +++ b/README.md @@ -219,8 +219,9 @@ All `WolfCertBuffer` outputs remember which heap they came from, so the same included, so a non-BSD-sockets stack (FreeRTOS+TCP, NetX, lwIP, wolfIP) needs one small glue file and no wolfCert change; the POSIX transport is the default instance and can be compiled out. -- **Storage:** file-based cert/key store with atomic writes and 0600 key-file - mode; pluggable via the `WolfCertStoreOps` vtable. +- **Storage is the application's:** keys export as PEM or DER + (`wolfcert_key_to_pem` / `_to_der`) and certificates come back as buffers, + to keep in a file, flash slot or secure element as the device requires. - **Test servers + CLIs** for Linux/macOS (`wolfcert-server`, `wolfcert-client`). The servers are for development and interop testing, not production CA use. diff --git a/configure.ac b/configure.ac index d1b9895..2aa8e6f 100644 --- a/configure.ac +++ b/configure.ac @@ -79,12 +79,6 @@ cannot supply a custom one])]) round-trip tests drive the client over real sockets])]) ]) -# Only the POSIX backend inside store.c is gated, so no AM_CONDITIONAL. -AC_ARG_ENABLE([posix-store], - [AS_HELP_STRING([--disable-posix-store], - [do not build the POSIX file storage backend])], - [enable_posix_store=$enableval], [enable_posix_store=yes]) - AC_ARG_ENABLE([tests], [AS_HELP_STRING([--enable-tests], [build unit and integration tests])], [enable_tests=$enableval], [enable_tests=no]) @@ -307,8 +301,6 @@ AS_IF([test "x$have_rsa" = "xno" && test "x$have_ecc" = "xno" \ WOLFCERT_OPT([WOLFCERT_OPT_EST], [$enable_est], [WOLFCERT_HAVE_EST]) WOLFCERT_OPT([WOLFCERT_OPT_SCEP], [$enable_scep], [WOLFCERT_HAVE_SCEP]) WOLFCERT_OPT([WOLFCERT_OPT_SERVER], [$enable_server], [WOLFCERT_HAVE_SERVER]) -WOLFCERT_PLAT([WOLFCERT_OPT_POSIX_STORE], [$enable_posix_store], - [WOLFCERT_HAVE_POSIX_STORE], [WOLFCERT_NO_POSIX_STORE]) WOLFCERT_PLAT([WOLFCERT_OPT_BUILTIN_TRANSPORT], [$enable_builtin_transport], [WOLFCERT_HAVE_BUILTIN_TRANSPORT], [WOLFCERT_NO_BUILTIN_TRANSPORT]) WOLFCERT_OPT([WOLFCERT_OPT_RSA], [$have_rsa], [WOLFCERT_HAVE_RSA]) @@ -363,7 +355,6 @@ AC_MSG_NOTICE([ Ed448=$have_ed448 ML-DSA=$have_mldsa TLS 1.2/1.3 : $have_tls12 / $have_tls13 Test server : $enable_server - POSIX store : $enable_posix_store Builtin transp: $enable_builtin_transport User settings : $enable_user_settings CLI tools : $enable_cli diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index f70d7db..f48530c 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -44,7 +44,7 @@ A few constraints shape the whole library: CryptoCb itself. The application registers its own (TPM, HSM, PKCS#11, custom) and passes the resulting `devId` through `WolfCertKeyCfg.dev_id`; wolfCert threads that into every wolfSSL crypto call on the key. -4. **Pluggable storage and protocol handling via vtables** (see +4. **Pluggable algorithms, transport and protocol handling via vtables** (see [section 5](#5-extension-points)). 5. **Event-loop-friendly I/O.** Every keep-alive session (HTTP, EST, SCEP) takes non-blocking `_nb` calls that surface `WOLFCERT_ERR_WANT_READ` / @@ -80,7 +80,7 @@ wolfCert is organised in four layers, top to bottom: +----------------------------------------------------------------------+ | public API headers (wolfcert/*.h) | | wolfcert.h (umbrella) client.h est.h scep.h http.h | - | keygen.h csr.h store.h server.h memory.h errors.h status.h | + | keygen.h csr.h server.h memory.h errors.h status.h | +----------------------------------------------------------------------+ | +----------------------------------------------------------------------+ @@ -91,7 +91,7 @@ wolfCert is organised in four layers, top to bottom: +----------------------------------------------------------------------+ | subsystem layer | | keygen / key_algs csr http (TLS + keep-alive + async) | - | store pkcs7_util server + ca_issue memory / errors / logging | + | pkcs7_util server + ca_issue memory / errors / logging | +----------------------------------------------------------------------+ | +----------------------------------------------------------------------+ @@ -432,27 +432,16 @@ Key points: its in-flight state; don't mutate the request/response between calls. - **One in-flight request per session** — pipelining is not supported. -### 4.4 Pluggable storage for flash / NVM +### 4.4 Persisting keys and certificates -Populate a `WolfCertStoreOps` with your backend and hand it to the store -helpers: - -```c -WolfCertStoreOps flash_ops = { - .read = flash_read, - .write = flash_write, - .remove = flash_remove, - .heap = my_heap, - .ctx = &my_flash_state, -}; -wolfcert_store_write_cert(&flash_ops, "device.crt", cert.data, cert.len); -``` - -Keys are opaque strings — map them to flash slots, handles, or paths however -your storage layer prefers. `sensitive = 1` on a write tells you the blob is -private-key material; enforce whatever access-control or encryption policy the -device needs. `wolfcert_store_write_key` / `_read_key` round-trip a -`WolfCertKey` via PEM and always mark the write sensitive. +wolfCert does not store anything. An enroll returns the certificate in a +`WolfCertBuffer`, `wolfcert_key_to_pem` / `_to_der` export a software key, and +`wolfcert_key_from_pem` reads one back. Write them wherever the device keeps +credentials. A renewal replaces the certificate and, on a rekey, the key, so +keep the old pair until both new halves are written. Keep exported keys +readable only by the device's own process, and free their buffers with +`wolfcert_buffer_free_secure()`. A key that stays in a CryptoCb backend is not +exported; keep the reference the backend needs. ### 4.5 Logging & errors on targets without stdio @@ -613,9 +602,8 @@ wolfcert_est_session_open(&srv, &s); run_nb_loop(s); /* pattern from section 4.3 */ wolfcert_est_session_close(s); -/* 5. Persist to flash through our storage backend */ -wolfcert_store_write_cert(&flash_ops, "device.crt", cert.data, cert.len); -/* key stays behind the CryptoCb; persist its label instead */ +/* 5. Persist the certificate; the key stays behind the CryptoCb */ +flash_write("device.crt", cert.data, cert.len); /* 6. Shutdown */ wolfcert_key_free(key); @@ -626,7 +614,7 @@ wolfcert_cleanup(); ## 5. Extension points -Four small vtables carry all of wolfCert's pluggability. Each is a "fill in a +Three small vtables carry all of wolfCert's pluggability. Each is a "fill in a struct, no library changes" extension: - **`WolfCertKeyAlg`** (`src/key_algs.c`) — algorithm dispatch. Adding a key @@ -634,10 +622,6 @@ struct, no library changes" extension: wolfSSL constants and `alloc_init` / `make` / `priv_decode` / `priv_to_der` / `free_` callbacks, plus an optional `WOLFCERT_HAVE_` compile guard. No edits to `keygen.c`, `csr.c`, or `ca_issue.c`. -- **`WolfCertStoreOps`** (`wolfcert/store.h`) — storage backend. Supply - `read` / `write` / `remove` callbacks and a private `ctx`; keys are opaque - strings. Shipped backends: POSIX files (atomic write, 0600 key mode) and - in-memory. See [section 4.4](#44-pluggable-storage-for-flash--nvm). - **`WolfCertTransport`** (`wolfcert/types.h`) — the bytes on the wire. Supply `connect` / `read` / `write` / `disconnect` and a private `ctx` to run wolfCert on a non-BSD-sockets stack; TLS rides the same callbacks through an diff --git a/docs/EMBEDDED.md b/docs/EMBEDDED.md index 24f2e88..b39bf24 100644 --- a/docs/EMBEDDED.md +++ b/docs/EMBEDDED.md @@ -303,17 +303,17 @@ with ECC or a PQC algorithm, disabling SCEP avoids pulling in RSA. ## 7. Targets without BSD sockets or a filesystem -Two platform pieces can be compiled out entirely, so a target that has -neither a socket API nor a filesystem links neither. +The one platform piece, the socket transport, can be compiled out entirely, +so a target without a socket API does not link it. wolfCert never touches a +filesystem. | Macro | Off means | Build flags | `user_settings.h` | |---|---|---|---| | `WOLFCERT_HAVE_BUILTIN_TRANSPORT` | `src/net_posix.c` is not compiled | `-DWOLFCERT_ENABLE_BUILTIN_TRANSPORT=OFF` / `--disable-builtin-transport` | `#define WOLFCERT_NO_BUILTIN_TRANSPORT` | -| `WOLFCERT_HAVE_POSIX_STORE` | the POSIX file store backend is stubbed out | `-DWOLFCERT_ENABLE_POSIX_STORE=OFF` / `--disable-posix-store` | `#define WOLFCERT_NO_POSIX_STORE` | -Each pair is mandatory-one-of: `check_config.h` fails the build when a +The pair is mandatory-one-of: `check_config.h` fails the build when a config defines neither the `WOLFCERT_HAVE_*` nor the `WOLFCERT_NO_*` form, -so compiling a backend out is always an explicit decision. The configure +so compiling the transport out is always an explicit decision. The configure builds emit the right macro automatically; only a `user_settings.h` build writes it by hand. @@ -322,8 +322,6 @@ leaving it NULL is `WOLFCERT_ERR_BAD_ARG`. Writing one is a small glue file in your own tree - `connect` / `read` / `write` / `disconnect` over your stack, no TLS code - described in [`ARCHITECTURE.md` section 4.6](ARCHITECTURE.md#46-pluggable-transport). -With the store off, `wolfcert_store_posix_open()` returns NULL and the -in-memory backend or your own `WolfCertStoreOps` carries persistence. The CLI tools and the built-in test server both need real sockets, so both build systems reject enabling them alongside `--disable-builtin-transport`. diff --git a/docs/MIGRATING-FROM-WOLFSCEP.md b/docs/MIGRATING-FROM-WOLFSCEP.md index 09c96c9..8d5fcc5 100644 --- a/docs/MIGRATING-FROM-WOLFSCEP.md +++ b/docs/MIGRATING-FROM-WOLFSCEP.md @@ -191,7 +191,6 @@ Link against `libwolfcert` and include ``, which pulls in t - **EST (RFC 7030)** for the same lifecycle over TLS, with ECC, Ed25519, Ed448 and ML-DSA keys, none of which SCEP permits. - **Keep-alive sessions with `_nb` calls**, so several operations share one connection and an event loop can drive them through `WOLFCERT_ERR_WANT_READ` and `WOLFCERT_ERR_WANT_WRITE`. - **CryptoCb offload.** Register your TPM, HSM or PKCS#11 backend with wolfSSL and pass the resulting `dev_id` in `WolfCertKeyCfg`; the private key never has to be in memory. -- **Pluggable storage** through `WolfCertStoreOps` for flash and NVM targets. - **Static memory.** Every allocation carries a heap hint, so wolfCert runs on a wolfSSL built `WOLFSSL_NO_MALLOC` with a static pool. - **A tested interop matrix**, described in `INTEROP.md`. diff --git a/examples/user_settings.h.example b/examples/user_settings.h.example index abbf035..63394fb 100644 --- a/examples/user_settings.h.example +++ b/examples/user_settings.h.example @@ -38,9 +38,8 @@ #define WOLFCERT_HAVE_SCEP 1 /* SCEP (RFC 8894) - requires WOLFCERT_HAVE_RSA */ #define WOLFCERT_HAVE_SERVER 1 /* built-in EST/SCEP test server */ -/* Platform: each needs its HAVE or WOLFCERT_NO_* form; NO_* compiles the - * backend out and the application supplies its own transport / store ops. */ -#define WOLFCERT_HAVE_POSIX_STORE 1 +/* Platform: needs its HAVE or WOLFCERT_NO_* form; NO_* compiles the + * transport out and the application supplies its own. */ #define WOLFCERT_HAVE_BUILTIN_TRANSPORT 1 /* Key algorithms (at least one) */ diff --git a/scripts/ci/compile-freestanding.sh b/scripts/ci/compile-freestanding.sh index 5e87917..8f54a80 100755 --- a/scripts/ci/compile-freestanding.sh +++ b/scripts/ci/compile-freestanding.sh @@ -2,9 +2,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later # # Compile every portable wolfCert source for a bare-metal ARM target: no POSIX -# headers, no built-in transport, no POSIX store, no test server. This keeps -# src/http.c, src/csr.c and src/store.c free of syscalls, so wolfCert can run on -# a non-BSD-sockets stack through a caller-supplied WolfCertTransport. +# headers, no built-in transport, no test server. This keeps src/http.c and +# src/csr.c free of syscalls, so wolfCert can run on a non-BSD-sockets stack +# through a caller-supplied WolfCertTransport. # # Compile-only, so it wants a wolfSSL checkout for headers rather than a build, # and finishes in seconds. Feature set: freestanding-user_settings.h alongside. diff --git a/scripts/ci/freestanding-user_settings.h b/scripts/ci/freestanding-user_settings.h index 7e423a7..33d6e5e 100644 --- a/scripts/ci/freestanding-user_settings.h +++ b/scripts/ci/freestanding-user_settings.h @@ -18,7 +18,7 @@ */ /* Combined wolfSSL + wolfCert config for compile-freestanding.sh. The - * built-in transport, POSIX store, server and HAVE_SNI stay out on purpose. */ + * built-in transport, server and HAVE_SNI stay out on purpose. */ #ifndef WOLFSSL_USER_SETTINGS_H #define WOLFSSL_USER_SETTINGS_H @@ -67,7 +67,6 @@ /* wolfCert: no sockets, no filesystem */ #define WOLFCERT_NO_SNI #define WOLFCERT_NO_BUILTIN_TRANSPORT -#define WOLFCERT_NO_POSIX_STORE #define WOLFCERT_HAVE_EST 1 /* EST (RFC 7030) */ #define WOLFCERT_HAVE_SCEP 1 /* SCEP (RFC 8894) - requires WOLFCERT_HAVE_RSA */ #define WOLFCERT_HAVE_RSA 1 diff --git a/scripts/ci/wolfcert-only-user_settings.h b/scripts/ci/wolfcert-only-user_settings.h index 2d022d8..d25f596 100644 --- a/scripts/ci/wolfcert-only-user_settings.h +++ b/scripts/ci/wolfcert-only-user_settings.h @@ -30,7 +30,6 @@ #define WOLFCERT_HAVE_SCEP 1 #define WOLFCERT_HAVE_SERVER 1 -#define WOLFCERT_HAVE_POSIX_STORE 1 #define WOLFCERT_HAVE_BUILTIN_TRANSPORT 1 #define WOLFCERT_HAVE_RSA 1 diff --git a/src/ca_issue.c b/src/ca_issue.c index f9da5cd..62e9274 100644 --- a/src/ca_issue.c +++ b/src/ca_issue.c @@ -17,7 +17,7 @@ * along with wolfCert. If not, see . */ -/* Test-server CA: generation, persistence and issuance from a CSR. */ +/* Test-server CA: generation, loading and issuance from a CSR. */ #define _POSIX_C_SOURCE 200809L #define _DEFAULT_SOURCE @@ -183,7 +183,7 @@ int wolfcert_ca_generate(WolfCertCa* ca, WolfCertKeyType type, int param, void* return rc; } - /* Kept as DER for wolfcert_ca_save and the SCEP server's PKCS#7 calls. */ + /* Kept as DER for wolfcert_ca_export and the SCEP server's PKCS#7 calls. */ size_t kcap = alg->der_cap_hint + 2048; ca->key_der = (uint8_t*)WOLFCERT_XMALLOC(kcap, heap); if (ca->key_der == NULL) { @@ -210,10 +210,9 @@ int wolfcert_ca_generate(WolfCertCa* ca, WolfCertKeyType type, int param, void* return WOLFCERT_OK; } -/* Check the stored cert is a CA holding the public half of the stored key. */ -static int ca_check_stored_pair(const WolfCertKeyAlg* alg, WolfCertKey* key, - const uint8_t* cert_der, size_t cert_len, - void* heap) +/* Check the cert is a CA holding the public half of the key. */ +static int ca_check_pair(const WolfCertKeyAlg* alg, WolfCertKey* key, + const uint8_t* cert_der, size_t cert_len, void* heap) { DecodedCert* dc = (DecodedCert*)WOLFCERT_XMALLOC(sizeof(*dc), heap); if (dc == NULL) @@ -222,25 +221,28 @@ static int ca_check_stored_pair(const WolfCertKeyAlg* alg, WolfCertKey* key, wc_InitDecodedCert(dc, cert_der, (word32)cert_len, heap); int rc = wc_ParseCert(dc, CERT_TYPE, NO_VERIFY, NULL); - if (rc != 0) { + if (rc == MEMORY_E) { + rc = WOLFCERT_ERR_MEMORY; + } + else if (rc != 0) { rc = WOLFCERT_ERR(WOLFCERT_ERR_PARSE, "ca", - "stored CA certificate does not parse"); + "CA certificate does not parse"); } else if (!dc->isCA || (dc->extKeyUsageSet && (dc->extKeyUsage & KEYUSE_KEY_CERT_SIGN) == 0)) { rc = WOLFCERT_ERR(WOLFCERT_ERR_PARSE, "ca", - "stored CA certificate is not a CA " + "CA certificate is not a CA " "(basicConstraints/keyUsage)"); } else if (dc->keyOID != (word32)alg->key_oid || dc->publicKey == NULL) { rc = WOLFCERT_ERR(WOLFCERT_ERR_PARSE, "ca", - "stored CA certificate and key use different algorithms"); + "CA certificate and key use different algorithms"); } else { rc = alg->pub_check(key, dc->publicKey, dc->pubKeySize); - if (rc != WOLFCERT_OK) + if (rc != WOLFCERT_OK && rc != WOLFCERT_ERR_MEMORY) rc = WOLFCERT_ERR(rc, "ca", - "stored CA certificate does not match the stored key"); + "CA certificate does not match the CA key"); } wc_FreeDecodedCert(dc); @@ -248,103 +250,143 @@ static int ca_check_stored_pair(const WolfCertKeyAlg* alg, WolfCertKey* key, return rc; } -int wolfcert_ca_load(WolfCertCa* ca, WolfCertStoreOps* store, void* heap) +static int ca_copy(const uint8_t* in, size_t in_len, WolfCertBuffer* out, + void* heap) +{ + out->data = (uint8_t*)WOLFCERT_XMALLOC(in_len, heap); + if (out->data == NULL) + return WOLFCERT_ERR_MEMORY; + + memcpy(out->data, in, in_len); + out->len = in_len; + out->heap = heap; + return WOLFCERT_OK; +} + +/* 1 when in is exactly one DER element. */ +static int ca_der_single(const uint8_t* in, size_t in_len) +{ + word32 idx = 1; + int len = 0; + + return (size_t)(word32)in_len == in_len && + GetLength(in, &idx, &len, (word32)in_len) >= 0 && + (size_t)idx + (size_t)len == in_len; +} + +static int ca_cert_der(const uint8_t* in, size_t in_len, WolfCertBuffer* out, + void* heap) +{ + if (!wolfcert_buffer_is_der(in, in_len)) + return wolfcert_pem_cert_to_der(in, in_len, out, heap); + + if (!ca_der_single(in, in_len)) + return WOLFCERT_ERR_PARSE; + + return ca_copy(in, in_len, out, heap); +} + +int wolfcert_ca_load(WolfCertCa* ca, const uint8_t* cert, size_t cert_len, + const uint8_t* key, size_t key_len, void* heap) { - if (ca == NULL || store == NULL) + if (ca == NULL || cert == NULL || cert_len == 0 || key == NULL || + key_len == 0) return WOLFCERT_ERR_BAD_ARG; + if (heap == NULL) + heap = wolfcert_default_heap(); + memset(ca, 0, sizeof(*ca)); ca->heap = heap; WolfCertBuffer cert_buf = { .heap = heap }; WolfCertBuffer key_buf = { .heap = heap }; + WolfCertKey* k = NULL; + const WolfCertKeyAlg* alg = NULL; - int cert_rc = store->read(store->ctx, "ca.cert.der", &cert_buf); - int key_rc = store->read(store->ctx, "ca.key.der", &key_buf); - int rc; - - if (cert_rc != WOLFCERT_OK || key_rc != WOLFCERT_OK) { - wolfcert_buffer_free(&cert_buf); - wolfcert_buffer_free_secure(&key_buf); + int rc = ca_cert_der(cert, cert_len, &cert_buf, heap); + if (rc != WOLFCERT_OK && rc != WOLFCERT_ERR_MEMORY) + rc = WOLFCERT_ERR(rc, "ca", "ca_cert is not a PEM or DER certificate"); - if (cert_rc == WOLFCERT_ERR_NOT_FOUND && key_rc == WOLFCERT_ERR_NOT_FOUND) - return WOLFCERT_ERR_NOT_FOUND; - - /* An absent half is only damage once the other half read back. */ - if (cert_rc != WOLFCERT_OK && cert_rc != WOLFCERT_ERR_NOT_FOUND) - return WOLFCERT_ERR(cert_rc, "ca", "CA store read failed"); - if (key_rc != WOLFCERT_OK && key_rc != WOLFCERT_ERR_NOT_FOUND) - return WOLFCERT_ERR(key_rc, "ca", "CA store read failed"); - - /* Reporting NOT_FOUND for half a pair would let the caller mint a - * new CA over the survivor. */ - return WOLFCERT_ERR(WOLFCERT_ERR_PARSE, "ca", - "CA store is incomplete: %s is missing", - cert_rc == WOLFCERT_ERR_NOT_FOUND ? "ca.cert.der" : "ca.key.der"); + if (rc == WOLFCERT_OK) { + if (wolfcert_buffer_is_der(key, key_len) && + !ca_der_single(key, key_len)) + rc = WOLFCERT_ERR_PARSE; + else + rc = wolfcert_key_from_pem(key, key_len, heap, &k); + if (rc != WOLFCERT_OK && rc != WOLFCERT_ERR_MEMORY) + rc = WOLFCERT_ERR(rc, "ca", "ca_key is not a supported PEM or " + "DER private key"); } - /* Find the algorithm whose private-key decoder accepts the stored key. */ - const WolfCertKeyAlg* const* list = wolfcert_key_algs_all(); + /* The pair check restores an ECC public point that the re-encode needs. */ + if (rc == WOLFCERT_OK) { + alg = wolfcert_key_alg(k->type); + rc = (alg == NULL) ? WOLFCERT_ERR_UNSUPPORTED + : ca_check_pair(alg, k, cert_buf.data, cert_buf.len, + heap); + } - for (; *list != NULL; ++list) { - const WolfCertKeyAlg* a = *list; - WolfCertKey shim; + /* Re-encode so a PKCS#8 key matches alg->pem_type. */ + if (rc == WOLFCERT_OK) + rc = wolfcert_key_to_der(k, &key_buf); - memset(&shim, 0, sizeof(shim)); - shim.type = a->type; - shim.heap = heap; - shim.dev_id = WOLFCERT_DEVID_SOFTWARE; - - if (a->alloc_init(&shim) != WOLFCERT_OK) - continue; - - if (a->priv_decode(&shim, key_buf.data, (word32)key_buf.len) == WOLFCERT_OK) { - rc = ca_check_stored_pair(a, &shim, cert_buf.data, cert_buf.len, heap); - if (rc != WOLFCERT_OK) { - a->free_(&shim); - wolfcert_buffer_free(&cert_buf); - wolfcert_buffer_free_secure(&key_buf); - return rc; - } - - ca->type = a->type; - ca->impl = shim.impl; - ca->cert_der = cert_buf.data; - ca->cert_der_len = cert_buf.len; - ca->key_der = key_buf.data; - ca->key_der_len = key_buf.len; - cert_buf.data = NULL; - key_buf.data = NULL; - return WOLFCERT_OK; - } - a->free_(&shim); + if (rc == WOLFCERT_OK) { + ca->type = k->type; + ca->impl = k->impl; + ca->cert_der = cert_buf.data; + ca->cert_der_len = cert_buf.len; + ca->key_der = key_buf.data; + ca->key_der_len = key_buf.len; + k->impl = NULL; + cert_buf.data = NULL; + key_buf.data = NULL; } + wolfcert_key_free(k); wolfcert_buffer_free(&cert_buf); wolfcert_buffer_free_secure(&key_buf); - return WOLFCERT_ERR(WOLFCERT_ERR_PARSE, "ca", - "stored CA key does not decode as any supported algorithm"); + return rc; } -int wolfcert_ca_save(const WolfCertCa* ca, WolfCertStoreOps* store) +static int ca_encode(const uint8_t* der, size_t der_len, WolfCertEncoding enc, + int pem_type, WolfCertBuffer* out, void* heap) { - if (ca == NULL || store == NULL) - return WOLFCERT_ERR_BAD_ARG; + if (enc == WOLFCERT_ENCODING_DER) + return ca_copy(der, der_len, out, heap); - int rc = store->write(store->ctx, "ca.cert.der", ca->cert_der, ca->cert_der_len, 0); - if (rc != WOLFCERT_OK) - return rc; + size_t cap = der_len * 2 + 256; + uint8_t* pem = (uint8_t*)WOLFCERT_XMALLOC(cap, heap); + if (pem == NULL) + return WOLFCERT_ERR_MEMORY; - rc = store->write(store->ctx, "ca.key.der", ca->key_der, ca->key_der_len, 1); - if (rc == WOLFCERT_OK) - return rc; + int n = wc_DerToPem(der, (word32)der_len, pem, (word32)cap, pem_type); + if (n <= 0) { + wc_ForceZero(pem, (word32)cap); + WOLFCERT_XFREE(pem, heap); + return WOLFCERT_ERR_RC_WC(WOLFCERT_ERR_CRYPTO, n, "ca", "DerToPem"); + } + + out->data = pem; + out->len = (size_t)n; + out->heap = heap; + return WOLFCERT_OK; +} - /* A certificate without its key is a store every later load rejects. */ - if (store->remove == NULL || - store->remove(store->ctx, "ca.cert.der") != WOLFCERT_OK) - return WOLFCERT_ERR(rc, "ca", - "CA key write failed and ca.cert.der could not be rolled back: " - "the store is left incomplete and must be cleared before restart"); +int wolfcert_ca_export(const WolfCertCa* ca, WolfCertEncoding enc, + WolfCertBuffer* out_cert, WolfCertBuffer* out_key) +{ + const WolfCertKeyAlg* alg = wolfcert_key_alg(ca->type); + int rc; + + rc = ca_encode(ca->cert_der, ca->cert_der_len, enc, CERT_TYPE, out_cert, + ca->heap); + if (rc == WOLFCERT_OK && out_key != NULL) { + rc = ca_encode(ca->key_der, ca->key_der_len, enc, alg->pem_type, + out_key, ca->heap); + if (rc != WOLFCERT_OK) + wolfcert_buffer_free(out_cert); + } return rc; } diff --git a/src/internal.h b/src/internal.h index 2e9a4a1..d63d1a5 100644 --- a/src/internal.h +++ b/src/internal.h @@ -103,9 +103,12 @@ typedef struct { } WolfCertCa; int wolfcert_ca_generate(WolfCertCa* ca, WolfCertKeyType type, int param, void* heap); -WOLFCERT_TEST_VIS int wolfcert_ca_load(WolfCertCa* ca, WolfCertStoreOps* store, +WOLFCERT_TEST_VIS int wolfcert_ca_load(WolfCertCa* ca, + const uint8_t* cert, size_t cert_len, + const uint8_t* key, size_t key_len, void* heap); -int wolfcert_ca_save(const WolfCertCa* ca, WolfCertStoreOps* store); +int wolfcert_ca_export(const WolfCertCa* ca, WolfCertEncoding enc, + WolfCertBuffer* out_cert, WolfCertBuffer* out_key); WOLFCERT_TEST_VIS void wolfcert_ca_free(WolfCertCa* ca); /* Rebuild an issued certificate's subject from a decoded CSR. */ diff --git a/src/server.c b/src/server.c index 1c4563f..a358426 100644 --- a/src/server.c +++ b/src/server.c @@ -445,6 +445,12 @@ int wolfcert_server_start(const WolfCertServerCfgSrv* cfg, WolfCertServer** out) return WOLFCERT_ERR(WOLFCERT_ERR_BAD_ARG, "server", "post-handshake auth is supported only for EST"); + if ((cfg->ca_cert == NULL) != (cfg->ca_key == NULL) || + (cfg->ca_cert == NULL) != (cfg->ca_cert_len == 0) || + (cfg->ca_key == NULL) != (cfg->ca_key_len == 0)) + return WOLFCERT_ERR(WOLFCERT_ERR_BAD_ARG, "server", + "ca_cert and ca_key must both be set, or both NULL"); + struct in_addr bind_addr = { .s_addr = htonl(INADDR_ANY) }; if (cfg->bind_host != NULL && inet_pton(AF_INET, cfg->bind_host, &bind_addr) != 1) @@ -490,19 +496,14 @@ int wolfcert_server_start(const WolfCertServerCfgSrv* cfg, WolfCertServer** out) } int rc; - int have_ca = 0; - - if (cfg->ca_store != NULL) { - rc = wolfcert_ca_load(&s->ca, cfg->ca_store, heap); - if (rc == WOLFCERT_OK) - have_ca = 1; - /* Only an empty store means no CA yet; any other failure must not - * replace the stored CA. */ - else if (rc != WOLFCERT_ERR_NOT_FOUND) + + if (cfg->ca_cert != NULL) { + rc = wolfcert_ca_load(&s->ca, cfg->ca_cert, cfg->ca_cert_len, + cfg->ca_key, cfg->ca_key_len, heap); + if (rc != WOLFCERT_OK) goto fail; } - - if (!have_ca) { + else { WolfCertKeyType kt = cfg->ca_key_type ? cfg->ca_key_type : WOLFCERT_DEFAULT_KEY_TYPE; int kp = cfg->ca_key_param; @@ -510,13 +511,6 @@ int wolfcert_server_start(const WolfCertServerCfgSrv* cfg, WolfCertServer** out) rc = wolfcert_ca_generate(&s->ca, kt, kp, heap); if (rc != WOLFCERT_OK) goto fail; - - if (cfg->ca_store != NULL) { - /* Not re-wrapped: it would lose ca_save's rollback diagnostic. */ - rc = wolfcert_ca_save(&s->ca, cfg->ca_store); - if (rc != WOLFCERT_OK) - goto fail; - } } rc = ops->start(cfg, s); @@ -722,6 +716,18 @@ uint16_t wolfcert_server_port(const WolfCertServer* srv) return srv ? srv->cfg.bind_port : 0; } +int wolfcert_server_get_ca(const WolfCertServer* srv, WolfCertEncoding enc, + WolfCertBuffer* out_cert, WolfCertBuffer* out_key) +{ + if (srv == NULL || out_cert == NULL) + return WOLFCERT_ERR_BAD_ARG; + if (enc != WOLFCERT_ENCODING_PEM && enc != WOLFCERT_ENCODING_DER) + return WOLFCERT_ERR(WOLFCERT_ERR_BAD_ARG, "server", "bad encoding %d", + (int)enc); + + return wolfcert_ca_export(&srv->ca, enc, out_cert, out_key); +} + #if defined(WOLFCERT_BUILD_TESTING) WOLFCERT_TEST_VIS void wolfcert_server_set_request_timeout(WolfCertServer* srv, int ms) diff --git a/src/store.c b/src/store.c deleted file mode 100644 index 25cc2ce..0000000 --- a/src/store.c +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright (C) 2026 wolfSSL Inc. - * - * This file is part of wolfCert. - * - * wolfCert 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. - * - * wolfCert 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 wolfCert. If not, see . - */ - -/* Precedes every system header, so not gated on WOLFCERT_HAVE_POSIX_STORE. */ -#define _POSIX_C_SOURCE 200809L -#define _DEFAULT_SOURCE - -#include -#include -#include "internal.h" - -#include - -#include - -#ifdef WOLFCERT_HAVE_POSIX_STORE -#include -#include -#include -#include -#endif - -#ifdef WOLFCERT_HAVE_POSIX_STORE - -typedef struct { - char* root; -} PosixCtx; - -static int posix_join(const char* root, const char* key, char** out, void* heap) -{ - size_t rl = strlen(root); - size_t kl = strlen(key); - - char* p = (char*)WOLFCERT_XMALLOC(rl + 1 + kl + 1, heap); - if (p == NULL) - return WOLFCERT_ERR_MEMORY; - - memcpy(p, root, rl); - p[rl] = '/'; - memcpy(p + rl + 1, key, kl + 1); - *out = p; - - return WOLFCERT_OK; -} - -static int posix_read(void* ctx_, const char* key, WolfCertBuffer* out) -{ - PosixCtx* ctx = (PosixCtx*)ctx_; - char* path = NULL; - FILE* f = NULL; - uint8_t* buf = NULL; - long len = 0; - size_t n = 0; - int rc = posix_join(ctx->root, key, &path, out->heap); - if (rc != WOLFCERT_OK) - return rc; - - f = fopen(path, "rb"); - if (f == NULL) - rc = (errno == ENOENT) ? WOLFCERT_ERR_NOT_FOUND : WOLFCERT_ERR_IO; - - if (rc == WOLFCERT_OK && fseek(f, 0, SEEK_END) != 0) - rc = WOLFCERT_ERR_IO; - - if (rc == WOLFCERT_OK) { - len = ftell(f); - rewind(f); - if (len < 0) - rc = WOLFCERT_ERR_IO; - } - - if (rc == WOLFCERT_OK) { - buf = (uint8_t*)WOLFCERT_XMALLOC((size_t)len, out->heap); - if (buf == NULL) - rc = WOLFCERT_ERR_MEMORY; - } - - if (rc == WOLFCERT_OK) { - n = fread(buf, 1, (size_t)len, f); - if (n != (size_t)len) - rc = WOLFCERT_ERR_IO; - } - - if (rc == WOLFCERT_OK) { - out->data = buf; - out->len = (size_t)len; - buf = NULL; /* ownership moves to out */ - } - - if (f != NULL) - fclose(f); - WOLFCERT_XFREE(path, out->heap); - WOLFCERT_XFREE(buf, out->heap); - return rc; -} - -static int posix_write(void* ctx_, const char* key, - const uint8_t* data, size_t len, int sensitive) -{ - PosixCtx* ctx = (PosixCtx*)ctx_; - char* path = NULL; - int rc = posix_join(ctx->root, key, &path, NULL); - if (rc != WOLFCERT_OK) - return rc; - - size_t plen = strlen(path); - char* tmp = (char*)WOLFCERT_XMALLOC(plen + 8, NULL); - if (tmp == NULL) { - WOLFCERT_XFREE(path, NULL); - return WOLFCERT_ERR_MEMORY; - } - - memcpy(tmp, path, plen); - memcpy(tmp + plen, ".XXXXXX", 8); - - int fd = mkstemp(tmp); - if (fd < 0) { - WOLFCERT_XFREE(tmp, NULL); - WOLFCERT_XFREE(path, NULL); - return WOLFCERT_ERR_IO; - } - - if (fchmod(fd, sensitive ? 0600 : 0644) != 0) - goto fail; - - size_t off = 0; - while (off < len) { - ssize_t w = write(fd, data + off, len - off); - if (w < 0) { - if (errno == EINTR) - continue; - goto fail; - } - off += (size_t)w; - } - - if (fsync(fd) != 0) - goto fail; - - if (close(fd) != 0) { - unlink(tmp); - goto fail_free; - } - - if (rename(tmp, path) != 0) { - unlink(tmp); - goto fail_free; - } - - WOLFCERT_XFREE(tmp, NULL); - WOLFCERT_XFREE(path, NULL); - - return WOLFCERT_OK; - -fail: - close(fd); - unlink(tmp); - -fail_free: - WOLFCERT_XFREE(tmp, NULL); - WOLFCERT_XFREE(path, NULL); - - return WOLFCERT_ERR_IO; -} - -static int posix_remove(void* ctx_, const char* key) -{ - PosixCtx* ctx = (PosixCtx*)ctx_; - char* path = NULL; - - int rc = posix_join(ctx->root, key, &path, NULL); - if (rc != WOLFCERT_OK) - return rc; - - if (unlink(path) != 0 && errno != ENOENT) - rc = WOLFCERT_ERR_IO; - - WOLFCERT_XFREE(path, NULL); - return rc; -} - -WolfCertStoreOps* wolfcert_store_posix_open(const char* root_dir, void* heap) -{ - if (root_dir == NULL) - return NULL; - - if (heap == NULL) - heap = wolfcert_default_heap(); - - WolfCertStoreOps* ops = (WolfCertStoreOps*)WOLFCERT_XMALLOC(sizeof(*ops), heap); - if (ops == NULL) - return NULL; - - PosixCtx* ctx = (PosixCtx*)WOLFCERT_XMALLOC(sizeof(*ctx), heap); - if (ctx == NULL) { - WOLFCERT_XFREE(ops, heap); - return NULL; - } - - ctx->root = wolfcert_strdup(root_dir, heap); - if (ctx->root == NULL) { - WOLFCERT_XFREE(ctx, heap); - WOLFCERT_XFREE(ops, heap); - return NULL; - } - - ops->read = posix_read; - ops->write = posix_write; - ops->remove = posix_remove; - ops->heap = heap; - ops->ctx = ctx; - - return ops; -} - -void wolfcert_store_posix_close(WolfCertStoreOps* ops) -{ - if (ops == NULL) - return; - - PosixCtx* ctx = (PosixCtx*)ops->ctx; - if (ctx) { - WOLFCERT_XFREE(ctx->root, ops->heap); - WOLFCERT_XFREE(ctx, ops->heap); - } - - WOLFCERT_XFREE(ops, ops->heap); -} - -#else /* !WOLFCERT_HAVE_POSIX_STORE */ - -WolfCertStoreOps* wolfcert_store_posix_open(const char* root_dir, void* heap) -{ - (void)root_dir; - (void)heap; - - WOLFCERT_ERR(WOLFCERT_ERR_UNSUPPORTED, "store", - "wolfCert was built without the POSIX file backend"); - return NULL; -} - -void wolfcert_store_posix_close(WolfCertStoreOps* ops) -{ - (void)ops; -} - -#endif /* WOLFCERT_HAVE_POSIX_STORE */ - -typedef struct MemEntry { - char* key; - uint8_t* data; - size_t len; - struct MemEntry* next; -} MemEntry; - -typedef struct { - MemEntry* head; -} MemCtx; - -static MemEntry** find_slot(MemCtx* ctx, const char* key) -{ - MemEntry** p = &ctx->head; - while (*p) { - if (strcmp((*p)->key, key) == 0) - return p; - p = &(*p)->next; - } - return p; -} - -static int mem_read(void* ctx_, const char* key, WolfCertBuffer* out) -{ - MemCtx* ctx = (MemCtx*)ctx_; - MemEntry** slot = find_slot(ctx, key); - if (*slot == NULL) - return WOLFCERT_ERR_NOT_FOUND; - - uint8_t* buf = (uint8_t*)WOLFCERT_XMALLOC((*slot)->len, out->heap); - if (buf == NULL) - return WOLFCERT_ERR_MEMORY; - - memcpy(buf, (*slot)->data, (*slot)->len); - out->data = buf; - out->len = (*slot)->len; - - return WOLFCERT_OK; -} - -static int mem_write(void* ctx_, const char* key, - const uint8_t* data, size_t len, int sensitive) -{ - (void)sensitive; - MemCtx* ctx = (MemCtx*)ctx_; - MemEntry** slot = find_slot(ctx, key); - void* heap = NULL; /* memory backend uses default heap */ - - if (*slot != NULL) { - WOLFCERT_XFREE((*slot)->data, heap); - (*slot)->data = (uint8_t*)WOLFCERT_XMALLOC(len, heap); - if ((*slot)->data == NULL) { - (*slot)->len = 0; - return WOLFCERT_ERR_MEMORY; - } - - memcpy((*slot)->data, data, len); - (*slot)->len = len; - - return WOLFCERT_OK; - } - - MemEntry* e = (MemEntry*)WOLFCERT_XMALLOC(sizeof(*e), heap); - if (e == NULL) - return WOLFCERT_ERR_MEMORY; - - memset(e, 0, sizeof(*e)); - e->key = wolfcert_strdup(key, heap); - e->data = (uint8_t*)WOLFCERT_XMALLOC(len, heap); - if (e->key == NULL || e->data == NULL) { - WOLFCERT_XFREE(e->key, heap); - WOLFCERT_XFREE(e->data, heap); - WOLFCERT_XFREE(e, heap); - return WOLFCERT_ERR_MEMORY; - } - - memcpy(e->data, data, len); - e->len = len; - e->next = ctx->head; - ctx->head = e; - - return WOLFCERT_OK; -} - -static int mem_remove(void* ctx_, const char* key) -{ - MemCtx* ctx = (MemCtx*)ctx_; - MemEntry** slot = find_slot(ctx, key); - if (*slot == NULL) - return WOLFCERT_OK; - - MemEntry* e = *slot; - *slot = e->next; - WOLFCERT_XFREE(e->key, NULL); - WOLFCERT_XFREE(e->data, NULL); - WOLFCERT_XFREE(e, NULL); - - return WOLFCERT_OK; -} - -WolfCertStoreOps* wolfcert_store_memory_open(void* heap) -{ - if (heap == NULL) - heap = wolfcert_default_heap(); - - WolfCertStoreOps* ops = (WolfCertStoreOps*)WOLFCERT_XMALLOC(sizeof(*ops), heap); - if (ops == NULL) - return NULL; - - MemCtx* ctx = (MemCtx*)WOLFCERT_XMALLOC(sizeof(*ctx), heap); - if (ctx == NULL) { - WOLFCERT_XFREE(ops, heap); - return NULL; - } - - memset(ctx, 0, sizeof(*ctx)); - ops->read = mem_read; - ops->write = mem_write; - ops->remove = mem_remove; - ops->heap = heap; - ops->ctx = ctx; - - return ops; -} - -void wolfcert_store_memory_close(WolfCertStoreOps* ops) -{ - if (ops == NULL) - return; - - MemCtx* ctx = (MemCtx*)ops->ctx; - while (ctx->head) { - MemEntry* e = ctx->head; - ctx->head = e->next; - WOLFCERT_XFREE(e->key, NULL); - WOLFCERT_XFREE(e->data, NULL); - WOLFCERT_XFREE(e, NULL); - } - - WOLFCERT_XFREE(ctx, ops->heap); - WOLFCERT_XFREE(ops, ops->heap); -} - -int wolfcert_store_write_cert(WolfCertStoreOps* store, const char* key, - const uint8_t* cert, size_t len) -{ - if (store == NULL || key == NULL) - return WOLFCERT_ERR_BAD_ARG; - - return store->write(store->ctx, key, cert, len, 0); -} - -int wolfcert_store_read_cert(WolfCertStoreOps* store, const char* key, - WolfCertBuffer* out) -{ - if (store == NULL || key == NULL || out == NULL) - return WOLFCERT_ERR_BAD_ARG; - - memset(out, 0, sizeof(*out)); - out->heap = store->heap; - - return store->read(store->ctx, key, out); -} - -int wolfcert_store_write_key(WolfCertStoreOps* store, const char* key_name, - const WolfCertKey* key) -{ - if (store == NULL || key_name == NULL || key == NULL) - return WOLFCERT_ERR_BAD_ARG; - - WolfCertBuffer pem = { 0 }; - int rc = wolfcert_key_to_pem(key, &pem); - if (rc != WOLFCERT_OK) - return rc; - - rc = store->write(store->ctx, key_name, pem.data, pem.len, 1); - wolfcert_buffer_free_secure(&pem); - - return rc; -} - -int wolfcert_store_read_key(WolfCertStoreOps* store, const char* key_name, - WolfCertKey** out_key) -{ - if (store == NULL || key_name == NULL || out_key == NULL) - return WOLFCERT_ERR_BAD_ARG; - - WolfCertBuffer pem = { 0 }; - pem.heap = store->heap; - - int rc = store->read(store->ctx, key_name, &pem); - if (rc != WOLFCERT_OK) - return rc; - - rc = wolfcert_key_from_pem(pem.data, pem.len, store->heap, out_key); - wolfcert_buffer_free_secure(&pem); - - return rc; -} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3c8da4b..65fb8fe 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,10 +14,6 @@ target_include_directories(test_csr PRIVATE ${CMAKE_SOURCE_DIR}/src) target_link_libraries(test_csr PRIVATE wolfcert) add_test(NAME csr COMMAND test_csr) -add_executable(test_store unit/test_store.c) -target_link_libraries(test_store PRIVATE wolfcert) -add_test(NAME store COMMAND test_store) - if(WOLFCERT_ENABLE_BUILTIN_TRANSPORT) add_executable(test_net unit/test_net.c) target_include_directories(test_net PRIVATE ${CMAKE_SOURCE_DIR}/src) @@ -119,10 +115,10 @@ if(WOLFCERT_ENABLE_SERVER) # A stop that cannot interrupt an idle peer hangs the serving thread. set_tests_properties(server_stop_idle PROPERTIES TIMEOUT 90) - add_executable(test_server_ca_store unit/test_server_ca_store.c) - target_include_directories(test_server_ca_store PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_link_libraries(test_server_ca_store PRIVATE wolfcert Threads::Threads) - add_test(NAME server_ca_store COMMAND test_server_ca_store) + add_executable(test_server_ca unit/test_server_ca.c) + target_include_directories(test_server_ca PRIVATE ${CMAKE_SOURCE_DIR}/src) + target_link_libraries(test_server_ca PRIVATE wolfcert Threads::Threads) + add_test(NAME server_ca COMMAND test_server_ca) endif() if(WOLFCERT_ENABLE_SCEP) diff --git a/tests/integration/test_est_async_roundtrip.c b/tests/integration/test_est_async_roundtrip.c index bff4f22..06fe883 100644 --- a/tests/integration/test_est_async_roundtrip.c +++ b/tests/integration/test_est_async_roundtrip.c @@ -123,7 +123,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, .tls_client_ca_pem = cli_cert, .tls_client_ca_pem_len = cli_cert_len, @@ -185,7 +185,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .http_basic_user = "alice", .http_basic_pass = "hunter2", .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, @@ -255,7 +255,7 @@ int main(void) free(tls_key); free(cli_cert); free(cli_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); if (pha_skipped) return 77; diff --git a/tests/integration/test_est_chunked_robustness.c b/tests/integration/test_est_chunked_robustness.c index 2688e51..56530c0 100644 --- a/tests/integration/test_est_chunked_robustness.c +++ b/tests/integration/test_est_chunked_robustness.c @@ -551,7 +551,7 @@ static int no_sigpipe_on_response(void) WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .est_allow_anonymous_enroll = 1, }; WolfCertServer* srv = NULL; @@ -613,7 +613,7 @@ int main(void) WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = g_tls_cert, .tls_cert_pem_len = g_tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, .est_allow_anonymous_enroll = 1, @@ -659,7 +659,7 @@ int main(void) if (rc != 0) return rc; - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_est_csr_attrs_apply_roundtrip.c b/tests/integration/test_est_csr_attrs_apply_roundtrip.c index 7fee0fc..650aed8 100644 --- a/tests/integration/test_est_csr_attrs_apply_roundtrip.c +++ b/tests/integration/test_est_csr_attrs_apply_roundtrip.c @@ -260,7 +260,7 @@ int main(void) WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .csr_attributes_der = policy.data, .csr_attributes_len = policy.len, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, @@ -293,7 +293,7 @@ int main(void) if (rc != 0) return rc; - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_est_csr_attrs_enforce.c b/tests/integration/test_est_csr_attrs_enforce.c index 28376ff..8de562e 100644 --- a/tests/integration/test_est_csr_attrs_enforce.c +++ b/tests/integration/test_est_csr_attrs_enforce.c @@ -367,7 +367,7 @@ int main(void) WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .csr_attributes_der = policy.data, .csr_attributes_len = policy.len, .est_require_csr_attributes = 1, @@ -396,7 +396,7 @@ int main(void) WolfCertServerCfgSrv cfg2 = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .csr_attributes_der = policy2.data, .csr_attributes_len = policy2.len, .est_require_csr_attributes = 1, @@ -424,7 +424,7 @@ int main(void) WolfCertServerCfgSrv cfg_raw = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .csr_attributes_der = policy_raw.data, .csr_attributes_len = policy_raw.len, .est_require_csr_attributes = 1, @@ -452,7 +452,7 @@ int main(void) WolfCertServerCfgSrv cfg_bare = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .http_basic_user = "alice", .http_basic_pass = "secret", .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, @@ -472,7 +472,7 @@ int main(void) if (rc != 0) return rc; - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_est_csr_attrs_roundtrip.c b/tests/integration/test_est_csr_attrs_roundtrip.c index 596604f..a2daf99 100644 --- a/tests/integration/test_est_csr_attrs_roundtrip.c +++ b/tests/integration/test_est_csr_attrs_roundtrip.c @@ -102,7 +102,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .csr_attributes_der = blob.data, .csr_attributes_len = blob.len, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, @@ -178,7 +178,7 @@ int main(void) WolfCertServerCfgSrv cfg2 = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, .est_allow_anonymous_enroll = 1, @@ -232,7 +232,7 @@ int main(void) wolfcert_buffer_free(&blob); free(tls_cert); free(tls_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_est_mldsa_roundtrip.c b/tests/integration/test_est_mldsa_roundtrip.c index 6ded64b..9dfb238 100644 --- a/tests/integration/test_est_mldsa_roundtrip.c +++ b/tests/integration/test_est_mldsa_roundtrip.c @@ -114,7 +114,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .http_basic_user = "alice", .http_basic_pass = "hunter2", .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, @@ -158,7 +158,7 @@ int main(void) wolfcert_buffer_free(&ca_pem); free(tls_cert); free(tls_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); if (rc == 0) diff --git a/tests/integration/test_est_mtls_roundtrip.c b/tests/integration/test_est_mtls_roundtrip.c index 9d12b02..dbcda5e 100644 --- a/tests/integration/test_est_mtls_roundtrip.c +++ b/tests/integration/test_est_mtls_roundtrip.c @@ -319,10 +319,10 @@ static int test_reenroll_server_issued(const uint8_t* tls_cert, size_t tls_cert_ .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, .tls_client_ca_pem = cli_cert, .tls_client_ca_pem_len = cli_cert_len, + TEST_CA_CFG, }; - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); WolfCertServer* srv = NULL; - WolfCertBuffer ca_der = { 0 }; + const TestCa* ca = test_ca(); WolfCertBuffer csr = { 0 }; WolfCertEstResult issued = { 0 }; WolfCertEstResult renewed = { 0 }; @@ -330,10 +330,9 @@ static int test_reenroll_server_issued(const uint8_t* tls_cert, size_t tls_cert_ WolfCertKey* k1 = NULL; WolfCertKey* k2 = NULL; uint8_t* bundle = NULL; - size_t bundle_cap; + size_t bundle_len; pthread_t tid; char url[128]; - int pem_len; int rc; #ifdef HAVE_ECC uint8_t crit_csr[4096]; @@ -341,23 +340,13 @@ static int test_reenroll_server_issued(const uint8_t* tls_cert, size_t tls_cert_ int crit_len; #endif - /* The first start mints the CA into the store; the second adopts it. */ - REQUIRE(store != NULL); - cfg.ca_store = store; - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); - wolfcert_server_free(srv); - srv = NULL; - REQUIRE(store->read(store->ctx, "ca.cert.der", &ca_der) == WOLFCERT_OK); - - bundle_cap = cli_cert_len + ca_der.len * 2 + 256; - bundle = (uint8_t*)malloc(bundle_cap); + bundle_len = cli_cert_len + ca->cert_len; + bundle = (uint8_t*)malloc(bundle_len); REQUIRE(bundle != NULL); memcpy(bundle, cli_cert, cli_cert_len); - pem_len = wc_DerToPem(ca_der.data, (word32)ca_der.len, bundle + cli_cert_len, - (word32)(bundle_cap - cli_cert_len), CERT_TYPE); - REQUIRE(pem_len > 0); + memcpy(bundle + cli_cert_len, ca->cert, ca->cert_len); cfg.tls_client_ca_pem = bundle; - cfg.tls_client_ca_pem_len = cli_cert_len + (size_t)pem_len; + cfg.tls_client_ca_pem_len = bundle_len; REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); REQUIRE(pthread_create(&tid, NULL, server_thread, srv) == 0); @@ -415,11 +404,9 @@ static int test_reenroll_server_issued(const uint8_t* tls_cert, size_t tls_cert_ wolfcert_server_stop(srv); pthread_join(tid, NULL); wolfcert_server_free(srv); - wolfcert_store_memory_close(store); wolfcert_est_result_free(&renewed); wolfcert_est_result_free(&issued); wolfcert_buffer_free(&csr); - wolfcert_buffer_free(&ca_der); wolfcert_key_free(k2); wolfcert_key_free(k1); free(bundle); @@ -443,7 +430,7 @@ static int test_reenroll_under_approval(const uint8_t* tls_cert, size_t tls_cert .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, .tls_client_ca_pem = cli_cert, .tls_client_ca_pem_len = cli_cert_len, @@ -581,7 +568,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, .tls_client_ca_pem = cli_cert, .tls_client_ca_pem_len = cli_cert_len, @@ -695,7 +682,7 @@ int main(void) free(tls_key); free(cli_cert); free(cli_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_est_pending_roundtrip.c b/tests/integration/test_est_pending_roundtrip.c index 7ac1a73..e9c70dc 100644 --- a/tests/integration/test_est_pending_roundtrip.c +++ b/tests/integration/test_est_pending_roundtrip.c @@ -461,7 +461,7 @@ int main(void) WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .est_require_approval = 1, .est_retry_after_sec = 1, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, @@ -479,7 +479,7 @@ int main(void) free(tls_cert); free(tls_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); if (rc != 0) return rc; diff --git a/tests/integration/test_est_pha_roundtrip.c b/tests/integration/test_est_pha_roundtrip.c index e55f4f6..b96605e 100644 --- a/tests/integration/test_est_pha_roundtrip.c +++ b/tests/integration/test_est_pha_roundtrip.c @@ -114,7 +114,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, @@ -145,7 +145,7 @@ int main(void) free(tls_key); free(cli_cert); free(cli_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); return 77; } @@ -342,7 +342,7 @@ int main(void) free(tls_key); free(cli_cert); free(cli_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_est_roundtrip.c b/tests/integration/test_est_roundtrip.c index 9cef800..e38fcb7 100644 --- a/tests/integration/test_est_roundtrip.c +++ b/tests/integration/test_est_roundtrip.c @@ -238,7 +238,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .http_basic_user = "alice", .http_basic_pass = "hunter2", .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, @@ -363,7 +363,7 @@ int main(void) WolfCertServerCfgSrv acfg = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .http_basic_user = "alice", .http_basic_pass = "hunter", .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, @@ -416,7 +416,7 @@ int main(void) wolfcert_buffer_free(&ca_pem); free(tls_cert); free(tls_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK (%d transport connects)\n", g_connect_calls); return 0; diff --git a/tests/integration/test_est_tls_roundtrip.c b/tests/integration/test_est_tls_roundtrip.c index 9809257..4706d93 100644 --- a/tests/integration/test_est_tls_roundtrip.c +++ b/tests/integration/test_est_tls_roundtrip.c @@ -162,7 +162,7 @@ static int test_client_reenroll_keeps_identity(const uint8_t* tls_cert, .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, }; @@ -297,33 +297,26 @@ int main(void) size_t tls_key_len = 0; REQUIRE(gen_server_identity(&tls_cert, &tls_cert_len, &tls_key, &tls_key_len) == 0); - /* An EST listener without a TLS identity is refused at start. */ - WolfCertStoreOps* plain_store = wolfcert_store_memory_open(NULL); - REQUIRE(plain_store != NULL); + /* An EST listener without a TLS identity is refused at start, before the + * CA is loaded: this one does not parse. */ + static const uint8_t junk_ca[] = "not a CA"; WolfCertServerCfgSrv plain = { - .protocol = WOLFCERT_PROTO_EST, - .bind_host = "127.0.0.1", - .bind_port = 0, - .ca_store = plain_store, + .protocol = WOLFCERT_PROTO_EST, + .bind_host = "127.0.0.1", + .bind_port = 0, + .ca_cert = junk_ca, .ca_cert_len = sizeof(junk_ca) - 1, + .ca_key = junk_ca, .ca_key_len = sizeof(junk_ca) - 1, }; WolfCertServer* plain_srv = NULL; REQUIRE(wolfcert_server_start(&plain, &plain_srv) == WOLFCERT_ERR_TLS); REQUIRE(plain_srv == NULL); - /* The refusal comes before a CA is minted into the store. */ - WolfCertBuffer leftover = { 0 }; - REQUIRE(plain_store->read(plain_store->ctx, "ca.cert.der", &leftover) - == WOLFCERT_ERR_NOT_FOUND); - REQUIRE(plain_store->read(plain_store->ctx, "ca.key.der", &leftover) - == WOLFCERT_ERR_NOT_FOUND); - wolfcert_store_memory_close(plain_store); - /* An EST listener with no way to authenticate a client is refused too. */ WolfCertServerCfgSrv open_cfg = { .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, }; @@ -361,7 +354,7 @@ int main(void) .protocol = WOLFCERT_PROTO_EST, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .tls_cert_pem = tls_cert, .tls_cert_pem_len = tls_cert_len, .tls_key_pem = tls_key, .tls_key_pem_len = tls_key_len, .est_allow_anonymous_enroll = 1, @@ -457,7 +450,7 @@ int main(void) wolfcert_key_free(dk); free(tls_cert); free(tls_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_scep_async_roundtrip.c b/tests/integration/test_scep_async_roundtrip.c index a8da75d..2ad3593 100644 --- a/tests/integration/test_scep_async_roundtrip.c +++ b/tests/integration/test_scep_async_roundtrip.c @@ -1223,7 +1223,7 @@ int main(void) /* Scenario A: auto-approve server. */ WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s1 = NULL; REQUIRE(wolfcert_server_start(&cfg, &s1) == WOLFCERT_OK); pthread_t t1; @@ -1238,7 +1238,7 @@ int main(void) /* Scenario B: approval-required server (PENDING -> poll). */ WolfCertServerCfgSrv cfg_pending = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_require_approval = 1 }; WolfCertServer* s2 = NULL; REQUIRE(wolfcert_server_start(&cfg_pending, &s2) == WOLFCERT_OK); @@ -1254,7 +1254,7 @@ int main(void) /* Scenario C: auto-approve server, async enroll -> async RenewalReq. */ WolfCertServerCfgSrv cfg_renew = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s3 = NULL; REQUIRE(wolfcert_server_start(&cfg_renew, &s3) == WOLFCERT_OK); pthread_t t3; @@ -1269,7 +1269,7 @@ int main(void) /* Scenario D: auto-approve server, session misuse guards. */ WolfCertServerCfgSrv cfg_guard = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s4 = NULL; REQUIRE(wolfcert_server_start(&cfg_guard, &s4) == WOLFCERT_OK); pthread_t t4; @@ -1284,7 +1284,7 @@ int main(void) /* Scenario E: approval-required server, blocking PENDING -> poll. */ WolfCertServerCfgSrv cfg_bpoll = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_require_approval = 1 }; WolfCertServer* s5 = NULL; REQUIRE(wolfcert_server_start(&cfg_bpoll, &s5) == WOLFCERT_OK); @@ -1300,7 +1300,7 @@ int main(void) /* Scenario F: auto-approve server, session over base64 GET. */ WolfCertServerCfgSrv cfg_get = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s6 = NULL; REQUIRE(wolfcert_server_start(&cfg_get, &s6) == WOLFCERT_OK); pthread_t t6; @@ -1320,7 +1320,7 @@ int main(void) /* Scenario H: auto-approve server, non-RSA signer rejection. */ WolfCertServerCfgSrv cfg_nonrsa = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s7 = NULL; REQUIRE(wolfcert_server_start(&cfg_nonrsa, &s7) == WOLFCERT_OK); pthread_t t7; @@ -1336,7 +1336,7 @@ int main(void) /* Scenario I: approval-required server, renewal poll with signer_cert. */ WolfCertServerCfgSrv cfg_rpoll = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_require_approval = 1 }; WolfCertServer* s8 = NULL; REQUIRE(wolfcert_server_start(&cfg_rpoll, &s8) == WOLFCERT_OK); @@ -1352,7 +1352,7 @@ int main(void) /* Scenario J: auto-approve server for bootstrap, then the 500 stub. */ WolfCertServerCfgSrv cfg_500 = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s9 = NULL; REQUIRE(wolfcert_server_start(&cfg_500, &s9) == WOLFCERT_OK); pthread_t t9; @@ -1367,7 +1367,7 @@ int main(void) /* Scenario K: auto-approve server, argument-validation guards. */ WolfCertServerCfgSrv cfg_neg = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s10 = NULL; REQUIRE(wolfcert_server_start(&cfg_neg, &s10) == WOLFCERT_OK); pthread_t t10; @@ -1383,7 +1383,7 @@ int main(void) * GetCert over a session. */ WolfCertServerCfgSrv cfg_get_ops = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_enable_next_ca = 1, .scep_enable_get_cert = 1 }; WolfCertServer* s11 = NULL; @@ -1397,7 +1397,7 @@ int main(void) if (rc != 0) return rc; - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_scep_get_cert.c b/tests/integration/test_scep_get_cert.c index 88308fa..5a8fd5d 100644 --- a/tests/integration/test_scep_get_cert.c +++ b/tests/integration/test_scep_get_cert.c @@ -374,7 +374,7 @@ int main(void) WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_enable_get_cert = 1, }; WolfCertServer* s = NULL; @@ -394,7 +394,7 @@ int main(void) WolfCertServerCfgSrv cfg_off = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, }; WolfCertServer* s_off = NULL; REQUIRE(wolfcert_server_start(&cfg_off, &s_off) == WOLFCERT_OK); @@ -409,7 +409,7 @@ int main(void) if (rc != 0) return rc; - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_scep_poll_roundtrip.c b/tests/integration/test_scep_poll_roundtrip.c index 467afde..63b8bb6 100644 --- a/tests/integration/test_scep_poll_roundtrip.c +++ b/tests/integration/test_scep_poll_roundtrip.c @@ -630,7 +630,7 @@ static int next_ca_disabled_path(void) /* GetNextCACert is not advertised and answers WOLFCERT_ERR_NOT_FOUND. */ WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s = NULL; REQUIRE(wolfcert_server_start(&cfg, &s) == WOLFCERT_OK); pthread_t tid; @@ -672,7 +672,7 @@ int main(void) WolfCertServerCfgSrv cfg_pending = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_require_approval = 1, }; WolfCertServer* s1 = NULL; @@ -691,7 +691,7 @@ int main(void) WolfCertServerCfgSrv cfg_next = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_enable_next_ca = 1, }; WolfCertServer* s2 = NULL; @@ -709,7 +709,7 @@ int main(void) if (rc != 0) return rc; - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_scep_roundtrip.c b/tests/integration/test_scep_roundtrip.c index 9cc1386..efafb03 100644 --- a/tests/integration/test_scep_roundtrip.c +++ b/tests/integration/test_scep_roundtrip.c @@ -1821,7 +1821,7 @@ static int test_split_ra(void) { WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .scep_split_ra = 1 }; WolfCertKeyCfg kcfg = { .type = WOLFCERT_KEY_RSA, .param = 2048, .dev_id = WOLFCERT_DEVID_SOFTWARE }; @@ -1971,7 +1971,7 @@ int main(void) WolfCertServerCfgSrv cfg = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s = NULL; REQUIRE(wolfcert_server_start(&cfg, &s) == WOLFCERT_OK); REQUIRE(wolfcert_scep_server_set_bundle_fault(s, 2) @@ -2257,7 +2257,7 @@ int main(void) /* Challenge password (RFC 8894 section 2.9). */ WolfCertServerCfgSrv cfg2 = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store(), + TEST_CA_CFG, .challenge_password = "correct-horse" }; WolfCertServer* s2 = NULL; REQUIRE(wolfcert_server_start(&cfg2, &s2) == WOLFCERT_OK); @@ -2391,7 +2391,7 @@ int main(void) /* A CertRep with no recipientNonce is rejected (RFC 8894 3.2.1.2). */ WolfCertServerCfgSrv cfg3 = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s3 = NULL; REQUIRE(wolfcert_server_start(&cfg3, &s3) == WOLFCERT_OK); wolfcert_scep_server_set_faults(s3, 1 /* omit recipientNonce */, 0, 0); @@ -2434,7 +2434,7 @@ int main(void) /* A CertRep signed by a key other than the CA's is rejected. */ WolfCertServerCfgSrv cfg4 = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s4 = NULL; REQUIRE(wolfcert_server_start(&cfg4, &s4) == WOLFCERT_OK); wolfcert_scep_server_set_faults(s4, 0, 1 /* sign with wrong key */, 0); @@ -2477,7 +2477,7 @@ int main(void) /* A failed senderNonce RNG draw on the server answers HTTP 500. */ WolfCertServerCfgSrv cfg5 = { .protocol = WOLFCERT_PROTO_SCEP, .bind_host = "127.0.0.1", .bind_port = 0, - .ca_store = test_ca_store() }; + TEST_CA_CFG }; WolfCertServer* s5 = NULL; REQUIRE(wolfcert_server_start(&cfg5, &s5) == WOLFCERT_OK); wolfcert_scep_server_set_faults(s5, 0, 0, 1 /* RNG draw fails */); @@ -2523,7 +2523,7 @@ int main(void) wolfcert_buffer_free(&csr); wolfcert_scep_result_free(&issued); wolfcert_key_free(dk); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("OK\n"); return 0; diff --git a/tests/integration/test_server_stop_idle.c b/tests/integration/test_server_stop_idle.c index b5353c9..1bb2466 100644 --- a/tests/integration/test_server_stop_idle.c +++ b/tests/integration/test_server_stop_idle.c @@ -250,16 +250,17 @@ int main(void) REQUIRE(gen_server_identity(&tls_cert, &tls_cert_len, &tls_key, &tls_key_len) == 0); - memset(&cfg, 0, sizeof(cfg)); - cfg.protocol = TLS_LISTENER_PROTO; - cfg.bind_host = "127.0.0.1"; - cfg.bind_port = 0; - cfg.ca_store = test_ca_store(); - cfg.tls_cert_pem = tls_cert; - cfg.tls_cert_pem_len = tls_cert_len; - cfg.tls_key_pem = tls_key; - cfg.tls_key_pem_len = tls_key_len; - cfg.est_allow_anonymous_enroll = 1; + cfg = (WolfCertServerCfgSrv){ + .protocol = TLS_LISTENER_PROTO, + .bind_host = "127.0.0.1", + .bind_port = 0, + TEST_CA_CFG, + .tls_cert_pem = tls_cert, + .tls_cert_pem_len = tls_cert_len, + .tls_key_pem = tls_key, + .tls_key_pem_len = tls_key_len, + .est_allow_anonymous_enroll = 1, + }; /* 1. Parked in wolfSSL_accept() after answering the ClientHello. */ memset(&ctx, 0, sizeof(ctx)); @@ -298,11 +299,12 @@ int main(void) #ifdef WOLFCERT_HAVE_SCEP /* 3. Parked in recv() on a plaintext listener. */ - memset(&cfg, 0, sizeof(cfg)); - cfg.protocol = WOLFCERT_PROTO_SCEP; - cfg.bind_host = "127.0.0.1"; - cfg.bind_port = 0; - cfg.ca_store = test_ca_store(); + cfg = (WolfCertServerCfgSrv){ + .protocol = WOLFCERT_PROTO_SCEP, + .bind_host = "127.0.0.1", + .bind_port = 0, + TEST_CA_CFG, + }; memset(&ctx, 0, sizeof(ctx)); REQUIRE(wolfcert_server_start(&cfg, &ctx.srv) == WOLFCERT_OK); @@ -427,11 +429,12 @@ int main(void) #ifdef WOLFCERT_HAVE_SCEP /* 8. The next client is served behind a silent plaintext peer. */ - memset(&cfg, 0, sizeof(cfg)); - cfg.protocol = WOLFCERT_PROTO_SCEP; - cfg.bind_host = "127.0.0.1"; - cfg.bind_port = 0; - cfg.ca_store = test_ca_store(); + cfg = (WolfCertServerCfgSrv){ + .protocol = WOLFCERT_PROTO_SCEP, + .bind_host = "127.0.0.1", + .bind_port = 0, + TEST_CA_CFG, + }; memset(&ctx, 0, sizeof(ctx)); REQUIRE(wolfcert_server_start(&cfg, &ctx.srv) == WOLFCERT_OK); @@ -456,7 +459,7 @@ int main(void) free(tls_cert); free(tls_key); - test_ca_store_close(); + test_ca_close(); wolfcert_cleanup(); printf("server stop idle: OK\n"); diff --git a/tests/integration/tls_test_util.h b/tests/integration/tls_test_util.h index 098d803..d4cd810 100644 --- a/tests/integration/tls_test_util.h +++ b/tests/integration/tls_test_util.h @@ -23,6 +23,9 @@ #define WOLFCERT_TLS_TEST_UTIL_H #include +#ifdef WOLFCERT_HAVE_SERVER +#include +#endif #include /* pid_t, referenced by wolfssl/wolfcrypt/random.h */ @@ -101,10 +104,13 @@ static inline int black_hole_listener(uint16_t* out_port) typedef RsaKey test_signkey; #define TEST_CERT_SIGTYPE CTC_SHA256wRSA #define TEST_KEY_PEM_TYPE PRIVATEKEY_TYPE + #define TEST_CA_KEY_USAGE \ + "keyCertSign,cRLSign,digitalSignature,keyEncipherment" #elif defined(HAVE_ECC) typedef ecc_key test_signkey; #define TEST_CERT_SIGTYPE CTC_SHA256wECDSA #define TEST_KEY_PEM_TYPE ECC_PRIVATEKEY_TYPE + #define TEST_CA_KEY_USAGE "keyCertSign,cRLSign,digitalSignature" #else #error "tls_test_util: tests need RSA or ECC for a signing identity" #endif @@ -187,7 +193,7 @@ static inline int test_signkey_to_der(test_signkey* key, uint8_t* der, } /* Self-signed cert + key (PEM) for `cn`. A leaf gets an iPAddress SAN for - * 127.0.0.1, a CA none. The caller frees both with free(). */ + * 127.0.0.1, a CA keyUsage instead. The caller frees both with free(). */ static inline int mint_self_id(const char* cn, int is_ca, uint8_t** cert_pem, size_t* cert_pem_len, uint8_t** key_pem, size_t* key_pem_len) @@ -215,7 +221,11 @@ static inline int mint_self_id(const char* cn, int is_ca, cert.sigType = TEST_CERT_SIGTYPE; cert.daysValid = 1; cert.isCA = is_ca ? 1 : 0; - if (!is_ca) { + if (is_ca) { + if (wc_SetKeyUsage(&cert, TEST_CA_KEY_USAGE) != 0) + goto fail; + } + else { memcpy(cert.altNames, san_seq, sizeof(san_seq)); cert.altNamesSz = (int)sizeof(san_seq); } @@ -249,44 +259,57 @@ static inline int mint_self_id(const char* cn, int is_ca, return -1; } -static inline WolfCertStoreOps** test_ca_store_slot(void) +/* Self-signed TLS server identity (cert + key, PEM) for 127.0.0.1. */ +static inline int gen_server_identity(uint8_t** cert_pem, size_t* cert_pem_len, + uint8_t** key_pem, size_t* key_pem_len) { - static WolfCertStoreOps* store = NULL; - - return &store; + return mint_self_id("127.0.0.1", 0, cert_pem, cert_pem_len, + key_pem, key_pem_len); } -/* One CA store for every test server in the process, so only the first - * server start generates a CA. */ -static inline WolfCertStoreOps* test_ca_store(void) +#ifdef WOLFCERT_HAVE_SERVER +typedef struct { + uint8_t* cert; + size_t cert_len; + uint8_t* key; + size_t key_len; +} TestCa; + +static inline TestCa* test_ca_slot(void) { - WolfCertStoreOps** store = test_ca_store_slot(); - - if (*store == NULL) { - *store = wolfcert_store_memory_open(NULL); - if (*store == NULL) { - fprintf(stderr, "test_ca_store: cannot open the memory store\n"); - exit(1); - } - } - return *store; + static TestCa ca; + + return &ca; } -static inline void test_ca_store_close(void) +/* One CA per process, handed to every server the test starts. */ +static inline const TestCa* test_ca(void) { - WolfCertStoreOps** store = test_ca_store_slot(); + TestCa* ca = test_ca_slot(); - wolfcert_store_memory_close(*store); - *store = NULL; + if (ca->cert == NULL && + mint_self_id("wolfCert Test CA", 1, &ca->cert, &ca->cert_len, + &ca->key, &ca->key_len) != 0) { + fprintf(stderr, "test_ca: cannot generate the shared CA\n"); + exit(1); + } + return ca; } -/* Self-signed TLS server identity (cert + key, PEM) for 127.0.0.1. */ -static inline int gen_server_identity(uint8_t** cert_pem, size_t* cert_pem_len, - uint8_t** key_pem, size_t* key_pem_len) +/* Designated initializers that give a server config the shared CA. */ +#define TEST_CA_CFG \ + .ca_cert = test_ca()->cert, .ca_cert_len = test_ca()->cert_len, \ + .ca_key = test_ca()->key, .ca_key_len = test_ca()->key_len + +static inline void test_ca_close(void) { - return mint_self_id("127.0.0.1", 0, cert_pem, cert_pem_len, - key_pem, key_pem_len); + TestCa* ca = test_ca_slot(); + + free(ca->cert); + free(ca->key); + memset(ca, 0, sizeof(*ca)); } +#endif /* WOLFCERT_HAVE_SERVER */ /* Raw TLS client; each test_tls_write() is one TLS record, so one * wolfSSL_read() on the server, which the split-request tests need. */ diff --git a/tests/unit/test_server_ca_store.c b/tests/unit/test_server_ca.c similarity index 53% rename from tests/unit/test_server_ca_store.c rename to tests/unit/test_server_ca.c index 3a6bd8b..8f2b28c 100644 --- a/tests/unit/test_server_ca_store.c +++ b/tests/unit/test_server_ca.c @@ -49,25 +49,27 @@ /* SCEP is absent from NO_RSA builds, and EST needs a server identity. */ #if defined(WOLFCERT_HAVE_EST) - #define CA_STORE_PROTO WOLFCERT_PROTO_EST - #define CA_STORE_NEEDS_TLS 1 + #define CA_TEST_PROTO WOLFCERT_PROTO_EST + #define CA_TEST_NEEDS_TLS 1 #else - #define CA_STORE_PROTO WOLFCERT_PROTO_SCEP - #define CA_STORE_NEEDS_TLS 0 + #define CA_TEST_PROTO WOLFCERT_PROTO_SCEP + #define CA_TEST_NEEDS_TLS 0 #endif -#if CA_STORE_NEEDS_TLS +#if CA_TEST_NEEDS_TLS static uint8_t* srv_cert_pem; static size_t srv_cert_pem_len; static uint8_t* srv_key_pem; static size_t srv_key_pem_len; #endif -static void ca_store_cfg(WolfCertServerCfgSrv* cfg, WolfCertStoreOps* store) +/* A server config issuing from cert and key; both NULL generates a CA. */ +static void ca_cfg(WolfCertServerCfgSrv* cfg, const WolfCertBuffer* cert, + const WolfCertBuffer* key) { memset(cfg, 0, sizeof(*cfg)); - cfg->protocol = CA_STORE_PROTO; -#if CA_STORE_NEEDS_TLS + cfg->protocol = CA_TEST_PROTO; +#if CA_TEST_NEEDS_TLS cfg->tls_cert_pem = srv_cert_pem; cfg->tls_cert_pem_len = srv_cert_pem_len; cfg->tls_key_pem = srv_key_pem; @@ -75,336 +77,181 @@ static void ca_store_cfg(WolfCertServerCfgSrv* cfg, WolfCertStoreOps* store) cfg->est_allow_anonymous_enroll = 1; #endif cfg->bind_host = "127.0.0.1"; - cfg->ca_store = store; cfg->ca_key_type = CA_KEY_TYPE; cfg->ca_key_param = CA_KEY_PARAM; + if (cert != NULL) { + cfg->ca_cert = cert->data; + cfg->ca_cert_len = cert->len; + } + if (key != NULL) { + cfg->ca_key = key->data; + cfg->ca_key_len = key->len; + } } -/* Stub backend whose reads and writes all return the configured error. */ -typedef struct { - int read_rc; - int write_rc; -} StubCtx; - -static int stub_read(void* ctx_, const char* key, WolfCertBuffer* out) -{ - (void)key; - (void)out; - return ((StubCtx*)ctx_)->read_rc; -} - -static int stub_write(void* ctx_, const char* key, const uint8_t* data, - size_t len, int sensitive) -{ - (void)key; - (void)data; - (void)len; - (void)sensitive; - return ((StubCtx*)ctx_)->write_rc; -} - -static int stub_remove(void* ctx_, const char* key) -{ - (void)ctx_; - (void)key; - return WOLFCERT_OK; -} - -static void stub_store(WolfCertStoreOps* ops, StubCtx* ctx) -{ - memset(ops, 0, sizeof(*ops)); - ops->read = stub_read; - ops->write = stub_write; - ops->remove = stub_remove; - ops->ctx = ctx; -} - -static int test_corrupt_ca_rejected(void) +static int ca_key_param(WolfCertKeyType t) { - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); - REQUIRE(store != NULL); - - const uint8_t junk[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - REQUIRE(store->write(store->ctx, "ca.cert.der", junk, sizeof(junk), 0) == WOLFCERT_OK); - REQUIRE(store->write(store->ctx, "ca.key.der", junk, sizeof(junk), 1) == WOLFCERT_OK); - - WolfCertServerCfgSrv cfg; - WolfCertServer* srv = NULL; - - ca_store_cfg(&cfg, store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_PARSE); - REQUIRE(srv == NULL); - - wolfcert_store_memory_close(store); + if (t == WOLFCERT_KEY_RSA) + return 2048; + if (t == WOLFCERT_KEY_ECC) + return 256; return 0; } -static int test_load_io_error_rejected(void) +/* A server start generates a CA of type; the pair is copied out as enc. */ +static int generate_ca(WolfCertKeyType type, WolfCertEncoding enc, + WolfCertBuffer* cert, WolfCertBuffer* key) { - StubCtx ctx = { WOLFCERT_ERR_IO, WOLFCERT_OK }; - WolfCertStoreOps store; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; + int rc; - stub_store(&store, &ctx); - ca_store_cfg(&cfg, &store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_IO); - REQUIRE(srv == NULL); + ca_cfg(&cfg, NULL, NULL); + cfg.ca_key_type = type; + cfg.ca_key_param = ca_key_param(type); + REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + rc = wolfcert_server_get_ca(srv, enc, cert, key); + wolfcert_server_free(srv); + REQUIRE(rc == WOLFCERT_OK); return 0; } -static int test_save_failure_rejected(void) +/* A server start with cert and key gets want and, on failure, no server. */ +static int start_gets(const WolfCertBuffer* cert, const WolfCertBuffer* key, + int want) { - StubCtx ctx = { WOLFCERT_ERR_NOT_FOUND, WOLFCERT_ERR_IO }; - WolfCertStoreOps store; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; - stub_store(&store, &ctx); - ca_store_cfg(&cfg, &store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_IO); - REQUIRE(srv == NULL); + ca_cfg(&cfg, cert, key); + REQUIRE(wolfcert_server_start(&cfg, &srv) == want); + if (want != WOLFCERT_OK) + REQUIRE(srv == NULL); + wolfcert_server_free(srv); return 0; } -/* Stub backend whose certificate and key reads fail differently. */ -typedef struct { - int cert_rc; - int key_rc; -} SplitCtx; - -static int split_read(void* ctx_, const char* key, WolfCertBuffer* out) +static int test_corrupt_ca_rejected(void) { - SplitCtx* ctx = (SplitCtx*)ctx_; + uint8_t junk[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; + WolfCertBuffer bad = { junk, sizeof(junk), NULL }; - (void)out; - return strcmp(key, "ca.cert.der") == 0 ? ctx->cert_rc : ctx->key_rc; + return start_gets(&bad, &bad, WOLFCERT_ERR_PARSE); } -/* wolfcert_server_start with cert and key reads returning cert_rc and key_rc - * gets want and no server. */ -static int mixed_read_failure(int cert_rc, int key_rc, int want) +/* One half of the pair, or an empty half, is refused before any work. */ +static int test_half_ca_rejected(void) { - SplitCtx ctx = { cert_rc, key_rc }; - WolfCertStoreOps store; + uint8_t der[] = { 0x30, 0x03, 0x02, 0x01, 0x01 }; + WolfCertBuffer half = { der, sizeof(der), NULL }; + WolfCertBuffer empty = { der, 0, NULL }; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; - memset(&store, 0, sizeof(store)); - store.read = split_read; - store.write = stub_write; - store.remove = stub_remove; - store.ctx = &ctx; - - ca_store_cfg(&cfg, &store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == want); - REQUIRE(srv == NULL); - return 0; -} - -static int test_mixed_read_failure(void) -{ - if (mixed_read_failure(WOLFCERT_ERR_NOT_FOUND, WOLFCERT_ERR_IO, - WOLFCERT_ERR_IO)) + if (start_gets(&half, NULL, WOLFCERT_ERR_BAD_ARG)) return 1; - if (mixed_read_failure(WOLFCERT_ERR_IO, WOLFCERT_ERR_NOT_FOUND, - WOLFCERT_ERR_IO)) + if (start_gets(NULL, &half, WOLFCERT_ERR_BAD_ARG)) return 1; - if (mixed_read_failure(WOLFCERT_ERR_NOT_FOUND, WOLFCERT_ERR_MEMORY, - WOLFCERT_ERR_MEMORY)) + if (start_gets(&half, &empty, WOLFCERT_ERR_BAD_ARG)) + return 1; + if (start_gets(&empty, &half, WOLFCERT_ERR_BAD_ARG)) return 1; - /* Cert NOT_FOUND beside a good key read: start gets PARSE. */ - return mixed_read_failure(WOLFCERT_ERR_NOT_FOUND, WOLFCERT_OK, - WOLFCERT_ERR_PARSE); -} - -/* Backend that forwards to a real store but fails the nth write. */ -typedef struct { - WolfCertStoreOps* inner; - int writes; - int fail_at; -} FlakyCtx; - -static int flaky_read(void* ctx_, const char* key, WolfCertBuffer* out) -{ - WolfCertStoreOps* in = ((FlakyCtx*)ctx_)->inner; - - return in->read(in->ctx, key, out); -} - -static int flaky_write(void* ctx_, const char* key, const uint8_t* data, - size_t len, int sensitive) -{ - FlakyCtx* ctx = (FlakyCtx*)ctx_; - - if (++ctx->writes == ctx->fail_at) - return WOLFCERT_ERR_IO; - - return ctx->inner->write(ctx->inner->ctx, key, data, len, sensitive); -} - -static int flaky_remove(void* ctx_, const char* key) -{ - WolfCertStoreOps* in = ((FlakyCtx*)ctx_)->inner; - - return in->remove(in->ctx, key); -} - -static int failing_remove(void* ctx_, const char* key) -{ - (void)ctx_; - (void)key; - return WOLFCERT_ERR_IO; + /* A length without its pointer is not a request to generate a CA. */ + ca_cfg(&cfg, NULL, NULL); + cfg.ca_cert_len = sizeof(der); + cfg.ca_key_len = sizeof(der); + REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_BAD_ARG); + REQUIRE(srv == NULL); + return 0; } -/* A failed key write removes the certificate already written. */ -static int test_save_rollback(void) +/* A generated CA handed back in, as DER or PEM, is the one the server uses. */ +static int test_ca_round_trip(void) { - WolfCertStoreOps* mem = wolfcert_store_memory_open(NULL); - FlakyCtx fctx; - WolfCertStoreOps store; + WolfCertBuffer der_cert = { 0 }; + WolfCertBuffer der_key = { 0 }; + WolfCertBuffer pem_cert = { 0 }; + WolfCertBuffer pem_key = { 0 }; + WolfCertBuffer again = { 0 }; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; - WolfCertBuffer left = { 0 }; - - REQUIRE(mem != NULL); - - memset(&fctx, 0, sizeof(fctx)); - fctx.inner = mem; - fctx.fail_at = 2; + int rc; - memset(&store, 0, sizeof(store)); - store.read = flaky_read; - store.write = flaky_write; - store.remove = flaky_remove; - store.ctx = &fctx; + ca_cfg(&cfg, NULL, NULL); + REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + REQUIRE(wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, &der_cert, + &der_key) == WOLFCERT_OK); + REQUIRE(wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_PEM, &pem_cert, + &pem_key) == WOLFCERT_OK); + wolfcert_server_free(srv); + srv = NULL; + REQUIRE(der_cert.data[0] == 0x30 && der_key.data[0] == 0x30); + REQUIRE(memcmp(pem_cert.data, "-----BEGIN CERTIFICATE-----", 27) == 0); + REQUIRE(memcmp(pem_key.data, "-----BEGIN ", 11) == 0); - ca_store_cfg(&cfg, &store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_IO); - REQUIRE(srv == NULL); - REQUIRE(mem->read(mem->ctx, "ca.cert.der", &left) == WOLFCERT_ERR_NOT_FOUND); + ca_cfg(&cfg, &pem_cert, &pem_key); + REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, &again, NULL); + wolfcert_server_free(srv); + srv = NULL; + REQUIRE(rc == WOLFCERT_OK); + REQUIRE(again.len == der_cert.len); + REQUIRE(memcmp(again.data, der_cert.data, der_cert.len) == 0); + wolfcert_buffer_free(&again); - /* The store is still empty, so the next start bootstraps normally. */ - fctx.fail_at = 0; + ca_cfg(&cfg, &der_cert, &der_key); REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, &again, NULL); wolfcert_server_free(srv); - REQUIRE(mem->read(mem->ctx, "ca.cert.der", &left) == WOLFCERT_OK); + srv = NULL; + REQUIRE(rc == WOLFCERT_OK); + REQUIRE(again.len == der_cert.len); + REQUIRE(memcmp(again.data, der_cert.data, der_cert.len) == 0); + wolfcert_buffer_free(&again); - wolfcert_buffer_free(&left); - wolfcert_store_memory_close(mem); + /* Each half may use its own encoding. */ + ca_cfg(&cfg, &pem_cert, &der_key); + REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, &again, NULL); + wolfcert_server_free(srv); + REQUIRE(rc == WOLFCERT_OK); + REQUIRE(again.len == der_cert.len); + REQUIRE(memcmp(again.data, der_cert.data, der_cert.len) == 0); + + wolfcert_buffer_free(&again); + wolfcert_buffer_free(&der_cert); + wolfcert_buffer_free_secure(&der_key); + wolfcert_buffer_free(&pem_cert); + wolfcert_buffer_free_secure(&pem_key); return 0; } -/* Key write fails with remove absent or failing: IO, a "rolled back" - * message, and the next start gets PARSE. */ -static int rollback_unavailable(int have_remove) +static int test_get_ca_args(void) { - WolfCertStoreOps* mem = wolfcert_store_memory_open(NULL); - FlakyCtx fctx; - WolfCertStoreOps store; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; - WolfCertBuffer left = { 0 }; - - REQUIRE(mem != NULL); - - memset(&fctx, 0, sizeof(fctx)); - fctx.inner = mem; - fctx.fail_at = 2; - - memset(&store, 0, sizeof(store)); - store.read = flaky_read; - store.write = flaky_write; - store.remove = have_remove ? failing_remove : NULL; - store.ctx = &fctx; - - ca_store_cfg(&cfg, &store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_IO); - REQUIRE(srv == NULL); - REQUIRE(strstr(wolfcert_last_error_message(), "rolled back") != NULL); - - /* The certificate really is still there, and the next start refuses it. */ - REQUIRE(mem->read(mem->ctx, "ca.cert.der", &left) == WOLFCERT_OK); - wolfcert_buffer_free(&left); - - fctx.fail_at = 0; - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_PARSE); - REQUIRE(srv == NULL); - - wolfcert_store_memory_close(mem); - return 0; -} - -static int test_rollback_unavailable(void) -{ - if (rollback_unavailable(0)) - return 1; + WolfCertBuffer cert = { 0 }; + WolfCertBuffer key = { 0 }; - return rollback_unavailable(1); -} + ca_cfg(&cfg, NULL, NULL); + REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); -/* A store holding one half of the pair fails to start. */ -static int partial_store_rejected(const char* present) -{ - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); - const uint8_t stored[] = { 0x30, 0x03, 0x02, 0x01, 0x01 }; - WolfCertBuffer left = { 0 }; - WolfCertServerCfgSrv cfg; - WolfCertServer* srv = NULL; + REQUIRE(wolfcert_server_get_ca(NULL, WOLFCERT_ENCODING_DER, &cert, &key) + == WOLFCERT_ERR_BAD_ARG); + REQUIRE(wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, NULL, &key) + == WOLFCERT_ERR_BAD_ARG); + REQUIRE(wolfcert_server_get_ca(srv, (WolfCertEncoding)7, &cert, &key) + == WOLFCERT_ERR_BAD_ARG); + REQUIRE(strstr(wolfcert_last_error_message(), "encoding") != NULL); + REQUIRE(cert.data == NULL && key.data == NULL); - REQUIRE(store != NULL); - REQUIRE(store->write(store->ctx, present, stored, sizeof(stored), 0) + REQUIRE(wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_PEM, &cert, NULL) == WOLFCERT_OK); + REQUIRE(cert.data != NULL && cert.len > 0); - ca_store_cfg(&cfg, store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_PARSE); - REQUIRE(srv == NULL); - - /* The survivor is still exactly what was stored. */ - REQUIRE(store->read(store->ctx, present, &left) == WOLFCERT_OK); - REQUIRE(left.len == sizeof(stored)); - REQUIRE(memcmp(left.data, stored, left.len) == 0); - - wolfcert_buffer_free(&left); - wolfcert_store_memory_close(store); - return 0; -} - -static int test_partial_store_rejected(void) -{ - if (partial_store_rejected("ca.cert.der")) - return 1; - - return partial_store_rejected("ca.key.der"); -} - -static int test_ca_persists_across_starts(void) -{ - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); - REQUIRE(store != NULL); - - WolfCertServerCfgSrv cfg; - WolfCertServer* srv = NULL; - WolfCertBuffer first = { 0 }; - WolfCertBuffer second = { 0 }; - - ca_store_cfg(&cfg, store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); - wolfcert_server_free(srv); - srv = NULL; - REQUIRE(store->read(store->ctx, "ca.cert.der", &first) == WOLFCERT_OK); - - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + wolfcert_buffer_free(&cert); wolfcert_server_free(srv); - REQUIRE(store->read(store->ctx, "ca.cert.der", &second) == WOLFCERT_OK); - - REQUIRE(first.len == second.len); - REQUIRE(memcmp(first.data, second.data, first.len) == 0); - - wolfcert_buffer_free(&first); - wolfcert_buffer_free(&second); - wolfcert_store_memory_close(store); return 0; } @@ -432,7 +279,8 @@ static void* fail_one_realloc(void* ptr, size_t sz) /* A start that survives any single failed allocation keeps every credential. */ static int test_start_oom_keeps_credentials(void) { - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); + WolfCertBuffer cert = { 0 }; + WolfCertBuffer key = { 0 }; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; wolfSSL_Malloc_cb mf; @@ -441,25 +289,27 @@ static int test_start_oom_keeps_credentials(void) int fail_at; int rc; - REQUIRE(store != NULL); - ca_store_cfg(&cfg, store); + if (generate_ca(CA_KEY_TYPE, WOLFCERT_ENCODING_PEM, &cert, &key)) + return 1; + ca_cfg(&cfg, &cert, &key); cfg.http_basic_user = "alice"; cfg.http_basic_pass = "secret"; cfg.challenge_password = "otp"; - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); - wolfcert_server_free(srv); REQUIRE(wolfSSL_GetAllocators(&mf, &ff, &rf) == 0); for (fail_at = 0; ; fail_at++) { srv = NULL; g_fail_at = fail_at; g_allocs = 0; + wolfcert_clear_error(); REQUIRE(wolfSSL_SetAllocators(fail_one_malloc, fail_one_free, fail_one_realloc) == 0); rc = wolfcert_server_start(&cfg, &srv); REQUIRE(wolfSSL_SetAllocators(mf, ff, rf) == 0); if (rc != WOLFCERT_OK) { REQUIRE(srv == NULL); + REQUIRE(strstr(wolfcert_last_error_message(), "does not match") + == NULL); continue; } REQUIRE(srv->cfg_basic_user != NULL && @@ -475,7 +325,8 @@ static int test_start_oom_keeps_credentials(void) g_fail_at = -1; REQUIRE(fail_at > 4); - wolfcert_store_memory_close(store); + wolfcert_buffer_free(&cert); + wolfcert_buffer_free_secure(&key); return 0; } #endif @@ -506,18 +357,8 @@ static const WolfCertKeyType CA_KEY_TYPES[] = { #endif }; -static int ca_key_param(WolfCertKeyType t) -{ - if (t == WOLFCERT_KEY_RSA) - return 2048; - if (t == WOLFCERT_KEY_ECC) - return 256; - return 0; -} - -/* The CA reloaded from store issues a leaf that verifies against it; the - * cert/key match on load alone passes a key with no public half. */ -static int reloaded_ca_signs(WolfCertStoreOps* store) +/* The loaded CA issues a leaf that verifies against it. */ +static int loaded_ca_signs(const WolfCertBuffer* cert, const WolfCertBuffer* key) { /* Any compiled algorithm serves as the leaf; the first entry always is. */ WolfCertKeyCfg kcfg = { .type = CA_KEY_TYPES[0], @@ -536,7 +377,8 @@ static int reloaded_ca_signs(WolfCertStoreOps* store) REQUIRE(wolfcert_csr_build(leaf_key, &meta, &csr) == WOLFCERT_OK); wolfcert_key_free(leaf_key); - REQUIRE(wolfcert_ca_load(&ca, store, NULL) == WOLFCERT_OK); + REQUIRE(wolfcert_ca_load(&ca, cert->data, cert->len, key->data, key->len, + NULL) == WOLFCERT_OK); rc = wolfcert_ca_issue(&ca, csr.data, csr.len, &issued, &issued_len); wolfcert_buffer_free(&csr); REQUIRE(rc == WOLFCERT_OK); @@ -556,78 +398,132 @@ static int reloaded_ca_signs(WolfCertStoreOps* store) return 0; } +/* Every algorithm's CA loads back from both encodings and still signs. */ static int test_every_alg_reloads(void) { size_t i; + int e; for (i = 0; i < sizeof(CA_KEY_TYPES) / sizeof(CA_KEY_TYPES[0]); ++i) { - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); + WolfCertBuffer cert[2] = { { 0 }, { 0 } }; + WolfCertBuffer key[2] = { { 0 }, { 0 } }; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; + int rc; - REQUIRE(store != NULL); - ca_store_cfg(&cfg, store); + ca_cfg(&cfg, NULL, NULL); cfg.ca_key_type = CA_KEY_TYPES[i]; cfg.ca_key_param = ca_key_param(CA_KEY_TYPES[i]); REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, &cert[0], + &key[0]); + if (rc == WOLFCERT_OK) + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_PEM, &cert[1], + &key[1]); wolfcert_server_free(srv); - srv = NULL; + REQUIRE(rc == WOLFCERT_OK); + + for (e = 0; e < 2; ++e) { + if (start_gets(&cert[e], &key[e], WOLFCERT_OK)) + return 1; + if (loaded_ca_signs(&cert[e], &key[e])) + return 1; + wolfcert_buffer_free(&cert[e]); + wolfcert_buffer_free_secure(&key[e]); + } + } + return 0; +} - /* Second start reloads the saved pair and checks the cert/key match. */ - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); - wolfcert_server_free(srv); +#ifdef WOLFCERT_HAVE_ECC +/* A SEC1 CA key without its optional public point still loads. */ +static int test_ecc_key_without_public_point(void) +{ + WolfCertBuffer cert = { 0 }; + WolfCertBuffer key = { 0 }; + WolfCertBuffer bare = { 0 }; + ecc_key ek; + word32 idx = 0; + uint8_t der[256]; + int n; - if (reloaded_ca_signs(store)) - return 1; + if (generate_ca(WOLFCERT_KEY_ECC, WOLFCERT_ENCODING_DER, &cert, &key)) + return 1; + REQUIRE(wc_ecc_init(&ek) == 0); + REQUIRE(wc_EccPrivateKeyDecode(key.data, &idx, &ek, (word32)key.len) == 0); + n = wc_EccPrivateKeyToDer(&ek, der, sizeof(der)); + wc_ecc_free(&ek); + REQUIRE(n > 0 && (size_t)n < key.len); + + bare.data = der; + bare.len = (size_t)n; + if (start_gets(&cert, &bare, WOLFCERT_OK)) + return 1; - wolfcert_store_memory_close(store); - } + wc_ForceZero(der, sizeof(der)); + wolfcert_buffer_free(&cert); + wolfcert_buffer_free_secure(&key); return 0; } +#endif -/* A server start generates a CA into `store`; the pair is copied out. */ -static int generate_ca_into(WolfCertStoreOps* store, WolfCertKeyType type, - WolfCertBuffer* cert, WolfCertBuffer* key) +#ifdef WOLFCERT_HAVE_SCEP +/* With a split RA, get_ca returns the CA, not the RA certificate. */ +static int test_split_ra_get_ca_is_ca(void) { WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; + WolfCertBuffer cert = { 0 }; + DecodedCert dc; + int rc; - ca_store_cfg(&cfg, store); - cfg.ca_key_type = type; - cfg.ca_key_param = ca_key_param(type); + ca_cfg(&cfg, NULL, NULL); + cfg.protocol = WOLFCERT_PROTO_SCEP; + cfg.ca_key_type = WOLFCERT_KEY_RSA; + cfg.ca_key_param = 2048; + cfg.scep_split_ra = 1; REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, &cert, NULL); wolfcert_server_free(srv); + REQUIRE(rc == WOLFCERT_OK); - REQUIRE(store->read(store->ctx, "ca.cert.der", cert) == WOLFCERT_OK); - REQUIRE(store->read(store->ctx, "ca.key.der", key) == WOLFCERT_OK); + wc_InitDecodedCert(&dc, cert.data, (word32)cert.len, NULL); + rc = wc_ParseCert(&dc, CERT_TYPE, NO_VERIFY, NULL); + if (rc == 0 && !dc.isCA) + rc = -1; + wc_FreeDecodedCert(&dc); + wolfcert_buffer_free(&cert); + REQUIRE(rc == 0); return 0; } +#endif -/* Have the CA in store issue a CSR carrying san; *rc_out is the issue result. */ -static int issue_with_san(WolfCertStoreOps* store, const uint8_t* san, - size_t san_len, int* rc_out, uint8_t** issued, - size_t* issued_len) +/* Have the CA in cert/key issue a CSR carrying san; *rc_out is the result. */ +static int issue_with_san(const WolfCertBuffer* cert, const WolfCertBuffer* key, + const uint8_t* san, size_t san_len, int* rc_out, + uint8_t** issued, size_t* issued_len) { WolfCertCa ca; WC_RNG rng; - test_signkey key; + test_signkey skey; Cert req; uint8_t csr[CTC_MAX_ALT_SIZE + 4096]; int csr_len; REQUIRE(wc_InitRng(&rng) == 0); - REQUIRE(test_signkey_make(&key, &rng) == 0); + REQUIRE(test_signkey_make(&skey, &rng) == 0); REQUIRE(wc_InitCert(&req) == 0); strncpy(req.subject.commonName, "san-leaf", CTC_NAME_SIZE - 1); memcpy(req.altNames, san, san_len); req.altNamesSz = (int)san_len; req.sigType = TEST_CERT_SIGTYPE; - csr_len = test_sign_certreq(&req, csr, (int)sizeof(csr), &key, &rng); - test_signkey_free(&key); + csr_len = test_sign_certreq(&req, csr, (int)sizeof(csr), &skey, &rng); + test_signkey_free(&skey); wc_FreeRng(&rng); REQUIRE(csr_len > 0); - REQUIRE(wolfcert_ca_load(&ca, store, NULL) == WOLFCERT_OK); + REQUIRE(wolfcert_ca_load(&ca, cert->data, cert->len, key->data, key->len, + NULL) == WOLFCERT_OK); *rc_out = wolfcert_ca_issue(&ca, csr, (size_t)csr_len, issued, issued_len); wolfcert_ca_free(&ca); return 0; @@ -648,7 +544,6 @@ static int test_issued_san_verbatim(void) 0xa4, 0x10, 0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x03, 'd', 'i', 'r' }; - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); WolfCertBuffer ca_cert = { 0 }; WolfCertBuffer ca_key = { 0 }; uint8_t* issued = NULL; @@ -660,13 +555,11 @@ static int test_issued_san_verbatim(void) size_t big_len = 4; int rc = -1; - REQUIRE(store != NULL); - REQUIRE(generate_ca_into(store, CA_KEY_TYPES[0], &ca_cert, &ca_key) == 0); - wolfcert_buffer_free(&ca_cert); - wolfcert_buffer_free(&ca_key); + if (generate_ca(CA_KEY_TYPES[0], WOLFCERT_ENCODING_DER, &ca_cert, &ca_key)) + return 1; - REQUIRE(issue_with_san(store, dir_san, sizeof(dir_san), &rc, &issued, - &issued_len) == 0); + REQUIRE(issue_with_san(&ca_cert, &ca_key, dir_san, sizeof(dir_san), &rc, + &issued, &issued_len) == 0); REQUIRE(rc == WOLFCERT_ERR_UNSUPPORTED); /* Over 8 KB of SAN in few entries, so a static-memory pool can parse it. */ @@ -684,14 +577,15 @@ static int test_issued_san_verbatim(void) big_san[1] = 0x82; big_san[2] = (uint8_t)((big_len - 4) >> 8); big_san[3] = (uint8_t)(big_len - 4); - REQUIRE(issue_with_san(store, big_san, big_len, &rc, &issued, + REQUIRE(issue_with_san(&ca_cert, &ca_key, big_san, big_len, &rc, &issued, &issued_len) == 0); REQUIRE(rc == WOLFCERT_OK); - WOLFCERT_XFREE(issued, NULL); + WOLFCERT_XFREE(issued, wolfcert_default_heap()); issued = NULL; - REQUIRE(issue_with_san(store, san, sizeof(san), &rc, &issued, + REQUIRE(issue_with_san(&ca_cert, &ca_key, san, sizeof(san), &rc, &issued, &issued_len) == 0); - wolfcert_store_memory_close(store); + wolfcert_buffer_free(&ca_cert); + wolfcert_buffer_free_secure(&ca_key); REQUIRE(rc == WOLFCERT_OK); wc_InitDecodedCert(&dc, issued, (word32)issued_len, NULL); @@ -702,51 +596,31 @@ static int test_issued_san_verbatim(void) memcmp(got, san, sizeof(san)) != 0)) rc = -1; wc_FreeDecodedCert(&dc); - WOLFCERT_XFREE(issued, NULL); + WOLFCERT_XFREE(issued, wolfcert_default_heap()); REQUIRE(rc == 0); return 0; } static int mismatched_ca_rejected(WolfCertKeyType type) { - WolfCertStoreOps* src_a = wolfcert_store_memory_open(NULL); - WolfCertStoreOps* src_b = wolfcert_store_memory_open(NULL); - WolfCertStoreOps* mixed = wolfcert_store_memory_open(NULL); WolfCertBuffer cert_a = { 0 }; WolfCertBuffer key_a = { 0 }; WolfCertBuffer cert_b = { 0 }; WolfCertBuffer key_b = { 0 }; - WolfCertServerCfgSrv cfg; - WolfCertServer* srv = NULL; - - REQUIRE(src_a != NULL); - REQUIRE(src_b != NULL); - REQUIRE(mixed != NULL); - if (generate_ca_into(src_a, type, &cert_a, &key_a)) + if (generate_ca(type, WOLFCERT_ENCODING_DER, &cert_a, &key_a)) return 1; - if (generate_ca_into(src_b, type, &cert_b, &key_b)) + if (generate_ca(type, WOLFCERT_ENCODING_DER, &cert_b, &key_b)) return 1; REQUIRE(key_a.len != key_b.len || memcmp(key_a.data, key_b.data, key_a.len) != 0); - REQUIRE(mixed->write(mixed->ctx, "ca.cert.der", cert_a.data, cert_a.len, 0) - == WOLFCERT_OK); - REQUIRE(mixed->write(mixed->ctx, "ca.key.der", key_b.data, key_b.len, 1) - == WOLFCERT_OK); - - ca_store_cfg(&cfg, mixed); - cfg.ca_key_type = type; - cfg.ca_key_param = ca_key_param(type); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_PARSE); - REQUIRE(srv == NULL); + if (start_gets(&cert_a, &key_b, WOLFCERT_ERR_PARSE)) + return 1; wolfcert_buffer_free(&cert_a); - wolfcert_buffer_free(&key_a); + wolfcert_buffer_free_secure(&key_a); wolfcert_buffer_free(&cert_b); - wolfcert_buffer_free(&key_b); - wolfcert_store_memory_close(src_a); - wolfcert_store_memory_close(src_b); - wolfcert_store_memory_close(mixed); + wolfcert_buffer_free_secure(&key_b); return 0; } @@ -764,15 +638,12 @@ static int test_mismatched_ca_rejected(void) /* The generated CA's key usages and critical basicConstraints. */ static int ca_key_usage_set(WolfCertKeyType type) { - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); WolfCertBuffer cert = { 0 }; WolfCertBuffer key = { 0 }; DecodedCert dc; int rc = 0; - REQUIRE(store != NULL); - - if (generate_ca_into(store, type, &cert, &key)) + if (generate_ca(type, WOLFCERT_ENCODING_DER, &cert, &key)) return 1; wc_InitDecodedCert(&dc, cert.data, (word32)cert.len, NULL); @@ -795,8 +666,7 @@ static int ca_key_usage_set(WolfCertKeyType type) wc_FreeDecodedCert(&dc); wolfcert_buffer_free(&cert); - wolfcert_buffer_free(&key); - wolfcert_store_memory_close(store); + wolfcert_buffer_free_secure(&key); REQUIRE(rc == 0); return 0; @@ -815,35 +685,120 @@ static int test_ca_key_usage(void) static int test_corrupt_ca_cert_rejected(void) { - WolfCertStoreOps* src = wolfcert_store_memory_open(NULL); - WolfCertStoreOps* mixed = wolfcert_store_memory_open(NULL); + uint8_t junk[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; + WolfCertBuffer bad = { junk, sizeof(junk), NULL }; WolfCertBuffer cert = { 0 }; WolfCertBuffer key = { 0 }; - const uint8_t junk[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - WolfCertServerCfgSrv cfg; - WolfCertServer* srv = NULL; + WolfCertBuffer padded = { 0 }; - REQUIRE(src != NULL); - REQUIRE(mixed != NULL); + if (generate_ca(CA_KEY_TYPE, WOLFCERT_ENCODING_DER, &cert, &key)) + return 1; + if (start_gets(&bad, &key, WOLFCERT_ERR_PARSE)) + return 1; + REQUIRE(strstr(wolfcert_last_error_message(), "ca_cert") != NULL); + if (start_gets(&cert, &bad, WOLFCERT_ERR_PARSE)) + return 1; + REQUIRE(strstr(wolfcert_last_error_message(), "ca_key") != NULL); - if (generate_ca_into(src, CA_KEY_TYPE, &cert, &key)) + /* DER that is not a certificate fails the same way. */ + if (start_gets(&key, &key, WOLFCERT_ERR_PARSE)) return 1; - REQUIRE(mixed->write(mixed->ctx, "ca.cert.der", junk, sizeof(junk), 0) - == WOLFCERT_OK); - REQUIRE(mixed->write(mixed->ctx, "ca.key.der", key.data, key.len, 1) - == WOLFCERT_OK); + /* So does a certificate with bytes after it. */ + padded.data = (uint8_t*)malloc(cert.len + 1); + REQUIRE(padded.data != NULL); + memcpy(padded.data, cert.data, cert.len); + padded.data[cert.len] = 0; + padded.len = cert.len + 1; + if (start_gets(&padded, &key, WOLFCERT_ERR_PARSE)) + return 1; + free(padded.data); + + /* And a DER key with bytes after it. */ + padded.data = (uint8_t*)malloc(key.len + 1); + REQUIRE(padded.data != NULL); + memcpy(padded.data, key.data, key.len); + padded.data[key.len] = 0; + padded.len = key.len + 1; + if (start_gets(&cert, &padded, WOLFCERT_ERR_PARSE)) + return 1; + REQUIRE(strstr(wolfcert_last_error_message(), "ca_key") != NULL); + wc_ForceZero(padded.data, (word32)padded.len); + free(padded.data); - ca_store_cfg(&cfg, mixed); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_PARSE); - REQUIRE(srv == NULL); + wolfcert_buffer_free(&cert); + wolfcert_buffer_free_secure(&key); + return 0; +} + +#if !defined(NO_PKCS8) && \ + (defined(WOLFCERT_HAVE_RSA) || defined(WOLFCERT_HAVE_ECC)) +/* A PKCS#8 CA key comes back in the form its PEM label names. */ +static int test_pkcs8_ca_key_normalized(void) +{ +#ifdef WOLFCERT_HAVE_RSA + const WolfCertKeyType type = WOLFCERT_KEY_RSA; + const int algo = RSAk; + const byte* curve = NULL; + word32 curve_sz = 0; + const char* label = "-----BEGIN RSA PRIVATE KEY-----"; +#else + const WolfCertKeyType type = WOLFCERT_KEY_ECC; + const int algo = ECDSAk; + const byte* curve = NULL; + word32 curve_sz = 0; + const char* label = "-----BEGIN EC PRIVATE KEY-----"; +#endif + WolfCertBuffer cert = { 0 }; + WolfCertBuffer key = { 0 }; + WolfCertBuffer p8 = { 0 }; + WolfCertBuffer out_cert = { 0 }; + WolfCertBuffer out_key = { 0 }; + WolfCertServerCfgSrv cfg; + WolfCertServer* srv = NULL; + word32 p8_len = 0; + int rc; + + if (generate_ca(type, WOLFCERT_ENCODING_DER, &cert, &key)) + return 1; +#ifndef WOLFCERT_HAVE_RSA + REQUIRE(wc_ecc_get_oid(ECC_SECP256R1_OID, &curve, &curve_sz) > 0); +#endif + REQUIRE(wc_CreatePKCS8Key(NULL, &p8_len, key.data, (word32)key.len, algo, + curve, curve_sz) == LENGTH_ONLY_E); + p8.data = (uint8_t*)malloc(p8_len); + REQUIRE(p8.data != NULL); + rc = wc_CreatePKCS8Key(p8.data, &p8_len, key.data, (word32)key.len, algo, + curve, curve_sz); + REQUIRE(rc > 0); + p8.len = (size_t)rc; + REQUIRE(p8.len != key.len || memcmp(p8.data, key.data, key.len) != 0); + + ca_cfg(&cfg, &cert, &p8); + REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_DER, &out_cert, + &out_key); + REQUIRE(rc == WOLFCERT_OK); + REQUIRE(out_key.len == key.len && + memcmp(out_key.data, key.data, key.len) == 0); + wolfcert_buffer_free(&out_cert); + wolfcert_buffer_free_secure(&out_key); + rc = wolfcert_server_get_ca(srv, WOLFCERT_ENCODING_PEM, &out_cert, + &out_key); + wolfcert_server_free(srv); + REQUIRE(rc == WOLFCERT_OK); + REQUIRE(out_key.len > strlen(label) && + memcmp(out_key.data, label, strlen(label)) == 0); + + wolfcert_buffer_free(&out_cert); + wolfcert_buffer_free_secure(&out_key); + free(p8.data); wolfcert_buffer_free(&cert); - wolfcert_buffer_free(&key); - wolfcert_store_memory_close(src); - wolfcert_store_memory_close(mixed); + wolfcert_buffer_free_secure(&key); return 0; } +#endif #ifdef WOLFCERT_HAVE_ECC /* A self-signed non-CA certificate and its key. */ @@ -893,28 +848,16 @@ static int make_leaf_pair(WolfCertBuffer* cert_out, WolfCertBuffer* key_out) static int test_leaf_ca_rejected(void) { - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); WolfCertBuffer cert = { 0 }; WolfCertBuffer key = { 0 }; - WolfCertServerCfgSrv cfg; - WolfCertServer* srv = NULL; - REQUIRE(store != NULL); if (make_leaf_pair(&cert, &key)) return 1; - - REQUIRE(store->write(store->ctx, "ca.cert.der", cert.data, cert.len, 0) - == WOLFCERT_OK); - REQUIRE(store->write(store->ctx, "ca.key.der", key.data, key.len, 1) - == WOLFCERT_OK); - - ca_store_cfg(&cfg, store); - REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_PARSE); - REQUIRE(srv == NULL); + if (start_gets(&cert, &key, WOLFCERT_ERR_PARSE)) + return 1; wolfcert_buffer_free(&cert); - wolfcert_buffer_free(&key); - wolfcert_store_memory_close(store); + wolfcert_buffer_free_secure(&key); return 0; } #endif /* WOLFCERT_HAVE_ECC */ @@ -926,26 +869,17 @@ static int test_bad_bind_host_rejected(void) }; WolfCertServerCfgSrv cfg; WolfCertServer* srv = NULL; - WolfCertBuffer left = { 0 }; size_t i; for (i = 0; i < sizeof(hosts) / sizeof(hosts[0]); i++) { - WolfCertStoreOps* mem = wolfcert_store_memory_open(NULL); - REQUIRE(mem != NULL); - - ca_store_cfg(&cfg, mem); + ca_cfg(&cfg, NULL, NULL); cfg.bind_host = hosts[i]; REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_ERR_BAD_ARG); REQUIRE(srv == NULL); - REQUIRE(mem->read(mem->ctx, "ca.cert.der", &left) == - WOLFCERT_ERR_NOT_FOUND); - REQUIRE(mem->read(mem->ctx, "ca.key.der", &left) == - WOLFCERT_ERR_NOT_FOUND); - wolfcert_store_memory_close(mem); } /* NULL binds every interface and must still start. */ - ca_store_cfg(&cfg, NULL); + ca_cfg(&cfg, NULL, NULL); cfg.bind_host = NULL; REQUIRE(wolfcert_server_start(&cfg, &srv) == WOLFCERT_OK); REQUIRE(wolfcert_server_port(srv) != 0); @@ -959,26 +893,18 @@ int main(void) REQUIRE(test_static_mem_init() == 0); REQUIRE(wolfcert_init(test_heap_hint()) == WOLFCERT_OK); -#if CA_STORE_NEEDS_TLS +#if CA_TEST_NEEDS_TLS REQUIRE(gen_server_identity(&srv_cert_pem, &srv_cert_pem_len, &srv_key_pem, &srv_key_pem_len) == 0); #endif if (test_corrupt_ca_rejected()) return 1; - if (test_load_io_error_rejected()) - return 1; - if (test_save_failure_rejected()) - return 1; - if (test_save_rollback()) - return 1; - if (test_rollback_unavailable()) - return 1; - if (test_mixed_read_failure()) + if (test_half_ca_rejected()) return 1; - if (test_partial_store_rejected()) + if (test_ca_round_trip()) return 1; - if (test_ca_persists_across_starts()) + if (test_get_ca_args()) return 1; #if defined(USE_WOLFSSL_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY) && \ !defined(WOLFSSL_DEBUG_MEMORY) @@ -987,10 +913,23 @@ int main(void) #endif if (test_every_alg_reloads()) return 1; +#ifdef WOLFCERT_HAVE_ECC + if (test_ecc_key_without_public_point()) + return 1; +#endif +#ifdef WOLFCERT_HAVE_SCEP + if (test_split_ra_get_ca_is_ca()) + return 1; +#endif if (test_mismatched_ca_rejected()) return 1; if (test_corrupt_ca_cert_rejected()) return 1; +#if !defined(NO_PKCS8) && \ + (defined(WOLFCERT_HAVE_RSA) || defined(WOLFCERT_HAVE_ECC)) + if (test_pkcs8_ca_key_normalized()) + return 1; +#endif if (test_issued_san_verbatim()) return 1; #ifdef WOLFCERT_HAVE_ECC @@ -1002,7 +941,7 @@ int main(void) if (test_bad_bind_host_rejected()) return 1; -#if CA_STORE_NEEDS_TLS +#if CA_TEST_NEEDS_TLS free(srv_cert_pem); free(srv_key_pem); #endif diff --git a/tests/unit/test_store.c b/tests/unit/test_store.c deleted file mode 100644 index 2b513a7..0000000 --- a/tests/unit/test_store.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2026 wolfSSL Inc. - * - * This file is part of wolfCert. - * - * wolfCert 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. - * - * wolfCert 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 wolfCert. If not, see . - */ - -#define _POSIX_C_SOURCE 200809L -#define _DEFAULT_SOURCE -#define _DARWIN_C_SOURCE /* expose memmem/strcasestr/INADDR_LOOPBACK on macOS */ - -#include -#include "../test_static_mem.h" - -#include "../integration/tls_test_util.h" - -#include -#include -#include -#include -#include - -#define REQUIRE(cond) \ - do { \ - if (!(cond)) { \ - fprintf(stderr, "FAIL %s:%d %s\n", __FILE__, __LINE__, #cond); \ - return 1; \ - } \ - } while (0) - -#ifdef WOLFCERT_HAVE_POSIX_STORE -static int test_posix(void) -{ - char dir[] = "/tmp/wolfcert_store_XXXXXX"; - REQUIRE(mkdtemp(dir) != NULL); - - WolfCertStoreOps* store = wolfcert_store_posix_open(dir, NULL); - REQUIRE(store != NULL); - - WolfCertKeyCfg cfg = { .type = TEST_ENROLL_KEY_TYPE, .param = TEST_ENROLL_KEY_PARAM, - .dev_id = WOLFCERT_DEVID_SOFTWARE }; - WolfCertKey* k = NULL; - REQUIRE(wolfcert_key_generate(&cfg, &k) == WOLFCERT_OK); - REQUIRE(wolfcert_store_write_key(store, "device.key.pem", k) == WOLFCERT_OK); - - struct stat st; - char p[512]; - snprintf(p, sizeof(p), "%s/device.key.pem", dir); - REQUIRE(stat(p, &st) == 0); - REQUIRE((st.st_mode & 0777) == 0600); - - WolfCertKey* k2 = NULL; - REQUIRE(wolfcert_store_read_key(store, "device.key.pem", &k2) == WOLFCERT_OK); - REQUIRE(k2 != NULL); - - const uint8_t fake_cert[] = "-----BEGIN CERTIFICATE-----\nMIIB\n-----END CERTIFICATE-----\n"; - REQUIRE(wolfcert_store_write_cert(store, "device.crt", fake_cert, sizeof(fake_cert)-1) == WOLFCERT_OK); - WolfCertBuffer rb = { 0 }; - REQUIRE(wolfcert_store_read_cert(store, "device.crt", &rb) == WOLFCERT_OK); - REQUIRE(rb.len == sizeof(fake_cert)-1); - REQUIRE(memcmp(rb.data, fake_cert, rb.len) == 0); - - wolfcert_buffer_free(&rb); - wolfcert_key_free(k); - wolfcert_key_free(k2); - wolfcert_store_posix_close(store); - - char p2[512]; - snprintf(p2, sizeof(p2), "%s/device.crt", dir); - unlink(p); - unlink(p2); - rmdir(dir); - return 0; -} - -#endif /* WOLFCERT_HAVE_POSIX_STORE */ - -static int test_memory(void) -{ - WolfCertStoreOps* store = wolfcert_store_memory_open(NULL); - REQUIRE(store != NULL); - - const uint8_t d[] = "hello"; - REQUIRE(wolfcert_store_write_cert(store, "x", d, sizeof(d)-1) == WOLFCERT_OK); - WolfCertBuffer r = { 0 }; - REQUIRE(wolfcert_store_read_cert(store, "x", &r) == WOLFCERT_OK); - REQUIRE(r.len == sizeof(d)-1 && memcmp(r.data, d, r.len) == 0); - wolfcert_buffer_free(&r); - - REQUIRE(store->remove(store->ctx, "x") == WOLFCERT_OK); - REQUIRE(wolfcert_store_read_cert(store, "x", &r) == WOLFCERT_ERR_NOT_FOUND); - - wolfcert_store_memory_close(store); - return 0; -} - -int main(void) -{ - REQUIRE(test_static_mem_init() == 0); - REQUIRE(wolfcert_init(test_heap_hint()) == WOLFCERT_OK); -#ifdef WOLFCERT_HAVE_POSIX_STORE - if (test_posix()) - return 1; -#endif - if (test_memory()) - return 1; - wolfcert_cleanup(); - printf("OK\n"); - return 0; -} diff --git a/wolfcert/check_config.h b/wolfcert/check_config.h index b4699b7..71e9ebe 100644 --- a/wolfcert/check_config.h +++ b/wolfcert/check_config.h @@ -56,9 +56,6 @@ !defined(WOLFCERT_NO_BUILTIN_TRANSPORT) #error "Define WOLFCERT_HAVE_BUILTIN_TRANSPORT for the built-in POSIX socket transport, or WOLFCERT_NO_BUILTIN_TRANSPORT to confirm every config supplies its own WolfCertTransport." #endif -#if !defined(WOLFCERT_HAVE_POSIX_STORE) && !defined(WOLFCERT_NO_POSIX_STORE) -#error "Define WOLFCERT_HAVE_POSIX_STORE for the POSIX file store, or WOLFCERT_NO_POSIX_STORE to confirm you supply your own WolfCertStoreOps." -#endif /* Required wolfSSL feature set */ diff --git a/wolfcert/options.h.in b/wolfcert/options.h.in index fc3c51a..145990f 100644 --- a/wolfcert/options.h.in +++ b/wolfcert/options.h.in @@ -28,7 +28,6 @@ @WOLFCERT_OPT_SERVER@ /* Platform */ -@WOLFCERT_OPT_POSIX_STORE@ @WOLFCERT_OPT_BUILTIN_TRANSPORT@ /* Key algorithms */ diff --git a/wolfcert/server.h b/wolfcert/server.h index 9df2d6b..1063ce9 100644 --- a/wolfcert/server.h +++ b/wolfcert/server.h @@ -21,7 +21,6 @@ #define WOLFCERT_SERVER_H #include -#include #ifdef __cplusplus extern "C" { @@ -37,14 +36,12 @@ typedef struct { const char* bind_host; /* numeric IPv4, NULL = all * interfaces */ uint16_t bind_port; - WolfCertStoreOps* ca_store; /* optional CA persistence; NULL = - new CA on each start. A store - error fails the start. */ const char* challenge_password; /* SCEP challengePassword to accept; NULL disables */ const char* http_basic_user; /* EST HTTP Basic credentials to accept; NULL disables */ const char* http_basic_pass; /* must be non-empty when http_basic_user is set */ - /* CA configuration. NULL/zero values fall back to library defaults. */ + /* Key for each CA the server generates, including for GetNextCACert. + * NULL/zero values fall back to library defaults. */ WolfCertKeyType ca_key_type; /* WOLFCERT_KEY_RSA default */ int ca_key_param; /* 2048 default for RSA, 256 for ECC */ @@ -104,9 +101,16 @@ typedef struct { /* Lets EST start with neither Basic nor tls_client_ca_pem. */ int est_allow_anonymous_enroll; - /* SCEP split CA/RA: the CA issues a new RA certificate at every start and - * ca_store does not keep it; the RA decrypts and signs SCEP messages. */ + /* SCEP split CA/RA: the CA issues a new RA certificate at every start to + * decrypt and sign SCEP messages. */ int scep_split_ra; + + /* CA to issue from: one certificate and its key, PEM or DER, copied at + * start. Both NULL generates a CA; one alone is WOLFCERT_ERR_BAD_ARG. */ + const uint8_t* ca_cert; + size_t ca_cert_len; + const uint8_t* ca_key; + size_t ca_key_len; } WolfCertServerCfgSrv; WOLFCERT_API int wolfcert_server_start(const WolfCertServerCfgSrv* cfg, WolfCertServer** out); @@ -119,6 +123,13 @@ WOLFCERT_API void wolfcert_server_free(WolfCertServer* srv); /* Returns the port the server is bound to. Useful after binding on port 0. */ WOLFCERT_API uint16_t wolfcert_server_port(const WolfCertServer* srv); +/* Copies out the CA the server issues from, e.g. to keep a generated one. + * out_key may be NULL; free the key with wolfcert_buffer_free_secure(). */ +WOLFCERT_API int wolfcert_server_get_ca(const WolfCertServer* srv, + WolfCertEncoding enc, + WolfCertBuffer* out_cert, + WolfCertBuffer* out_key); + /* Service exactly one request on an already-accepted connection; the caller * closes fd. WOLFCERT_SERVER_REQUEST_TIMEOUT_MS does not apply. The fd carries * no TLS, so EST enrollment on it needs http_basic_user or diff --git a/wolfcert/store.h b/wolfcert/store.h deleted file mode 100644 index d4e3184..0000000 --- a/wolfcert/store.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2026 wolfSSL Inc. - * - * This file is part of wolfCert. - * - * wolfCert 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. - * - * wolfCert 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 wolfCert. If not, see . - */ - -#ifndef WOLFCERT_STORE_H -#define WOLFCERT_STORE_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Pluggable storage backend: a vtable plus an opaque context, with slots - * addressed by caller-defined string keys (e.g. "device.crt", "slot/3"). */ - -typedef struct { - /* Read key into a newly allocated buffer; WOLFCERT_ERR_NOT_FOUND if - * absent. */ - int (*read) (void* ctx, const char* key, WolfCertBuffer* out); - /* Write or replace key atomically; sensitive marks a secret value that - * needs tight access modes. */ - int (*write)(void* ctx, const char* key, - const uint8_t* data, size_t len, int sensitive); - /* Remove `key` if present; not-an-error if already absent. */ - int (*remove)(void* ctx, const char* key); - /* Heap hint forwarded into wolfcert allocations done by the backend. */ - void* heap; - /* Backend-private state. */ - void* ctx; -} WolfCertStoreOps; - -/* POSIX-file backend under an existing root_dir; a '/' in a key names a - * subdirectory, which must already exist. Returns NULL on failure or in a - * build without WOLFCERT_HAVE_POSIX_STORE. */ -WOLFCERT_API WolfCertStoreOps* wolfcert_store_posix_open(const char* root_dir, - void* heap); -WOLFCERT_API void wolfcert_store_posix_close(WolfCertStoreOps* ops); - -/* In-memory backend, for tests or an application that persists the output - * itself. */ -WOLFCERT_API WolfCertStoreOps* wolfcert_store_memory_open(void* heap); -WOLFCERT_API void wolfcert_store_memory_close(WolfCertStoreOps* ops); - -/* Cert and key helpers over a store. */ - -WOLFCERT_API int wolfcert_store_write_cert(WolfCertStoreOps* store, - const char* key, - const uint8_t* cert, size_t len); -WOLFCERT_API int wolfcert_store_read_cert(WolfCertStoreOps* store, - const char* key, - WolfCertBuffer* out); - -WOLFCERT_API int wolfcert_store_write_key(WolfCertStoreOps* store, - const char* key_name, - const WolfCertKey* key); -WOLFCERT_API int wolfcert_store_read_key(WolfCertStoreOps* store, - const char* key_name, - WolfCertKey** out_key); - -#ifdef __cplusplus -} -#endif - -#endif /* WOLFCERT_STORE_H */ diff --git a/wolfcert/wolfcert.h b/wolfcert/wolfcert.h index 42be200..b8e15c7 100644 --- a/wolfcert/wolfcert.h +++ b/wolfcert/wolfcert.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #ifdef WOLFCERT_HAVE_EST # include diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index e8d914e..c9c6148 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -26,8 +26,6 @@ if(CONFIG_WOLFCERT) _wc_opt(WOLFCERT_OPT_SCEP "${CONFIG_WOLFCERT_SCEP}" WOLFCERT_HAVE_SCEP) # Host-only; zephyr/README.md says why. _wc_opt(WOLFCERT_OPT_SERVER "OFF" WOLFCERT_HAVE_SERVER) - _wc_plat(WOLFCERT_OPT_POSIX_STORE "OFF" - WOLFCERT_HAVE_POSIX_STORE WOLFCERT_NO_POSIX_STORE) _wc_plat(WOLFCERT_OPT_BUILTIN_TRANSPORT "${CONFIG_WOLFCERT_BUILTIN_TRANSPORT}" WOLFCERT_HAVE_BUILTIN_TRANSPORT WOLFCERT_NO_BUILTIN_TRANSPORT) _wc_opt(WOLFCERT_OPT_RSA "${CONFIG_WOLFCERT_RSA}" WOLFCERT_HAVE_RSA) @@ -55,7 +53,6 @@ if(CONFIG_WOLFCERT) ${WOLFCERT_DIR}/src/key_algs.c ${WOLFCERT_DIR}/src/keygen.c ${WOLFCERT_DIR}/src/csr.c - ${WOLFCERT_DIR}/src/store.c ${WOLFCERT_DIR}/src/http.c ${WOLFCERT_DIR}/src/client.c) diff --git a/zephyr/README.md b/zephyr/README.md index 1b58ad1..894fe55 100644 --- a/zephyr/README.md +++ b/zephyr/README.md @@ -227,8 +227,7 @@ needs changing. `prj.conf` leaves these to the board: clock — [`docs/EMBEDDED.md` section 8](../docs/EMBEDDED.md#8-zephyr) explains why. - **Keeping the key and certificate.** They are freed here. A real device - writes them through a `WolfCertStoreOps` — on Zephyr, one over NVS or the - settings subsystem. + writes them to NVS or the settings subsystem. ## Running the tests diff --git a/zephyr/include.am b/zephyr/include.am index bce8f8e..34d4a39 100644 --- a/zephyr/include.am +++ b/zephyr/include.am @@ -42,7 +42,4 @@ EXTRA_DIST += zephyr/tests/wolfcert_unit_scep_msg/testcase.yaml EXTRA_DIST += zephyr/tests/wolfcert_unit_smoke/CMakeLists.txt EXTRA_DIST += zephyr/tests/wolfcert_unit_smoke/prj.conf EXTRA_DIST += zephyr/tests/wolfcert_unit_smoke/testcase.yaml -EXTRA_DIST += zephyr/tests/wolfcert_unit_store/CMakeLists.txt -EXTRA_DIST += zephyr/tests/wolfcert_unit_store/prj.conf -EXTRA_DIST += zephyr/tests/wolfcert_unit_store/testcase.yaml EXTRA_DIST += zephyr/wolfssl_user_settings.h diff --git a/zephyr/tests/wolfcert_unit_store/CMakeLists.txt b/zephyr/tests/wolfcert_unit_store/CMakeLists.txt deleted file mode 100644 index c08f0e1..0000000 --- a/zephyr/tests/wolfcert_unit_store/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later -cmake_minimum_required(VERSION 3.20.0) - -set(CONF_FILE - ${CMAKE_CURRENT_LIST_DIR}/../common/wolfcert.conf - ${CMAKE_CURRENT_LIST_DIR}/prj.conf) - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(wolfcert_unit_store) - -include(${ZEPHYR_WOLFCERT_MODULE_DIR}/zephyr/tests/common/unit_test.cmake) -wolfcert_zephyr_unit_test(test_store) diff --git a/zephyr/tests/wolfcert_unit_store/prj.conf b/zephyr/tests/wolfcert_unit_store/prj.conf deleted file mode 100644 index b7e9b38..0000000 --- a/zephyr/tests/wolfcert_unit_store/prj.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_WOLFCERT_EST=y -CONFIG_WOLFCERT_RSA=y -CONFIG_WOLFCERT_ECC=y -CONFIG_WOLFCERT_ED25519=y diff --git a/zephyr/tests/wolfcert_unit_store/testcase.yaml b/zephyr/tests/wolfcert_unit_store/testcase.yaml deleted file mode 100644 index 5be1f10..0000000 --- a/zephyr/tests/wolfcert_unit_store/testcase.yaml +++ /dev/null @@ -1,14 +0,0 @@ -common: - tags: - - wolfcert - harness: console - harness_config: - type: one_line - regex: - - "WOLFCERT TEST RESULT: 0" -tests: - wolfcert.unit.store: - timeout: 180 - platform_allow: qemu_x86 - integration_platforms: - - qemu_x86