Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
C509 heap-allocation paths violate the zero-allocation contract and cause the mandatory check to fail every make test run, even with C509 disabled.
4 open issues
What changed in this PR
Adds opt-in C509 certificate support to wolfCOSE, using its CBOR codec and wolfCrypt for signature verification.
Changes:
- Adds public-key extraction, signature verification, and type-3 DER reconstruction.
- Adds build controls, error codes, and test-runner integration.
- Documents the API and adds AddressSanitizer CI coverage.
| File | Description |
|---|---|
| tests/test_suite.h | Declares the C509 test entry point. |
| tests/test_main.c | Runs C509 tests. |
| src/wolfcose_c509.c | Implements C509 decoding and verification. |
| README.md | Introduces C509 support and build usage. |
| Makefile | Adds the module and opt-in build flag. |
| include/wolfcose/wolfcose.h | Adds memory and malformed-certificate errors. |
| include/wolfcose/c509.h | Defines the public API and configuration limits. |
| docs/Project-Structure.md | Lists the new module and header. |
| docs/Macros.md | Documents C509 configuration options. |
| docs/API-Reference.md | Documents APIs and error codes. |
| ChangeLog.md | Records the new feature. |
| .github/workflows/c509.yml | Tests with type-3 support enabled and disabled. |
Review effort: Balanced
0ba3dbd to
e2ef9ee
Compare
| # pattern. The define is part of the build-config hash below, so toggling C509 | ||
| # forces the affected objects to rebuild. | ||
| ifeq ($(C509),1) | ||
| override CFLAGS += -DWOLFCOSE_ENABLE_C509 |
There was a problem hiding this comment.
make C509=1 enables C509 without WOLFCOSE_EXPERIMENTAL since C509 is still a draft can we require both flags in settings.h and add a compile test that fails with WOLFCOSE_ENABLE_C509 alone and passes with both?
| if (c509_dec_array(d, &count) != 0) { | ||
| ret = ASN_PARSE_E; | ||
| } | ||
| else if ((count == 0) || ((count % 2) != 0)) { |
There was a problem hiding this comment.
A device certificate can carry its entire identity in a critical subjectAltName. The draft encodes its empty subject as []. I checked a CA-signed P-256 certificate with that profile: ToDer returns WOLFCOSE_E_UNSUPPORTED. Can we emit the empty DER Name for the subject and add a round-trip test?
| if (truncated) { | ||
| /* A 64-bit epoch beyond word32: reject rather than silently | ||
| * saturate it to 0xFFFFFFFF (year 2106). */ | ||
| ret = ASN_PARSE_E; |
There was a problem hiding this comment.
The 32-bit limit here also applies to certificate timestamps. A type-3 certificate expiring in 2110 returns WOLFCOSE_E_C509_MALFORMED. Section 3.1.5 allows that date. Can we decode validity as a 64-bit value and keep the 32-bit limit for buffer lengths?
| -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wvla \ | ||
| -Werror=vla -I./include -I$WOLFSSL_DIR/include" | ||
| make clean | ||
| make C509=1 test CFLAGS="$WOLFCOSE_CFLAGS" \ |
There was a problem hiding this comment.
The ASan job runs the C509 tests, but the line-coverage jobs leave C509 disabled and the coverage script skips missing files. Can we run coverage with C509 enabled and require a result for wolfcose_c509.c so we keep the full coverage?
aidangarske
left a comment
There was a problem hiding this comment.
Skoll Multi-Scan Review
Modes: review-security + review
Overall recommendation: REQUEST_CHANGES
Findings: 11 total — 11 posted, 0 skipped
11 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] [review] C509 bypasses the mandatory experimental-feature gate —
include/wolfcose/c509.h:49-55 - [High] [review] Scratch macros allocate from the heap under SMALL_STACK —
src/wolfcose_c509.c:2567-2574 - [High] [review] SMALL_STACK verification contradicts its public size contract —
src/wolfcose_c509.c:4583-4600 - [High] [review] GetPubKey accepts a non-C509 certificate type —
src/wolfcose_c509.c:3461-3472 - [High] [review-security+review] C509 objects do not depend on their public header —
Makefile:201-204 - [Medium] [review-security+review] Type-3 RSA support is narrower than the documented algorithm matrix —
src/wolfcose_c509.c:767-776 - [Medium] [review] The new MISRA consumer block is never enabled —
tests/misra_consumer.c:159-166 - [Medium] [review] Strict C99 validation never compiles the C509 implementation —
.github/workflows/c509.yml:71-76 - [Medium] [review] Positive tests do not mirror the implementation capability gates —
tests/test_c509.c:3496-3511 - [Medium] [review] Public return contracts omit reachable error codes —
include/wolfcose/c509.h:176-177 - [Low] [review-security] Minimal C509 builds omit the constant-compare helper —
src/wolfcose_c509.c:3506-3508
Review generated by Skoll
d509f9d to
271c47e
Compare
Add a self-contained C509 (draft-ietf-cose-cbor-encoded-cert) module that decodes and verifies CBOR-encoded certificates, ported into wolfCOSE from the wolfSSL cert_c509 branch and re-skinned to wolfCOSE conventions. It is opt-in (WOLFCOSE_ENABLE_C509, `make C509=1`) and backed only by general wolfCrypt (ASN.1/RSA/ECC/EdDSA), not by wolfSSL's own C509. Public API (include/wolfcose/c509.h, wc_CoseC509_*): - GetPubKey / GetPubKeyEx: extract the subject public key (Ed25519/Ed448, NIST + brainpool EC incl. compressed-point decompression, RSA modulus), reporting a wc_CoseC509KeyType. - Verify / VerifyEx / VerifyEx2: check the issuer signature of a natively signed (type-2) or CBOR-re-encoded X.509 (type-3) certificate, with an optional explicit issuer key type and heap/devId for offload. - ToDer: reconstruct the byte-exact DER of a type-3 certificate (compile-time optional via WOLFCOSE_NO_C509_TYPE3). Design notes: - Decodes through wolfCOSE's wolfcose_cbor codec (strict RFC 8949 preferred serialization), replacing the original hand-rolled CBOR parsing. - Public boundaries normalize wolfCrypt return codes to WOLFCOSE_E_* via a single mapper; internal code keeps wolfCrypt codes so == comparisons hold. Adds WOLFCOSE_E_MEMORY and WOLFCOSE_E_C509_MALFORMED; LENGTH_ONLY_E is kept as the size-query sentinel. - House style: WOLFCOSE_API/LOCAL visibility, no goto, detailed Doxygen (\brief/\param/\return) in the header and brief comments in the .c. - Keyed on the linked wolfSSL's hardening for WOLFCOSE_C509_RSA_MIN_BITS (1024 default, 2048 at HARDEN_TLS>=112, 3072 at >=128). Tests: tests/test_c509.c (21 sub-tests, 69 fixtures) covering type-2/type-3 decode/verify across the supported key families, malformed-input rejection, size queries, and the type-3-disabled build; wired into the test runner. Build/CI/docs: Makefile C509=1 knob (adds -DWOLFCOSE_ENABLE_C509), a c509.yml workflow building a C509-capable wolfSSL and running the suite under ASan in both type-3-on and WOLFCOSE_NO_C509_TYPE3 arms, and ChangeLog / README / Project-Structure / Macros / API-Reference entries.


Add a self-contained C509 (draft-ietf-cose-cbor-encoded-cert) module that decodes and verifies CBOR-encoded certificates, ported into wolfCOSE from the wolfSSL cert_c509 branch and re-skinned to wolfCOSE conventions. It is opt-in (WOLFCOSE_ENABLE_C509,
make C509=1) and backed only by general wolfCrypt (ASN.1/RSA/ECC/EdDSA), not by wolfSSL's own C509.Public API (include/wolfcose/c509.h, wc_CoseC509_*):
Design notes:
Tests: tests/test_c509.c (21 sub-tests, 69 fixtures) covering type-2/type-3 decode/verify across the supported key families, malformed-input rejection, size queries, and the type-3-disabled build; wired into the test runner.
Build/CI/docs: Makefile C509=1 knob (adds -DWOLFCOSE_ENABLE_C509), a c509.yml workflow building a C509-capable wolfSSL and running the suite under ASan in both type-3-on and WOLFCOSE_NO_C509_TYPE3 arms, and ChangeLog / README / Project-Structure / Macros / API-Reference entries.
Closes #84