Skip to content

Match SCEP signer keys by SPKI and require a CA for roll-over - #83

Merged
yosuke-wolfssl merged 2 commits into
wolfSSL:mainfrom
Frauschi:scep-spki
Dec 3, 2026
Merged

yosuke-wolfssl merged 2 commits into
wolfSSL:mainfrom
Frauschi:scep-spki

Conversation

@Frauschi

Copy link
Copy Markdown
Member

SCEP signer checks now use one rule for "this certificate holds that key": the whole SubjectPublicKeyInfo, found by the DER walk #72 added. A GetNextCACert reply is accepted only when its signer's key belongs to a CA certificate in the caller's bundle, as RFC 8894 section 4.7.1 requires, so an RA key can no longer install a new CA.

Changes

  • wolfcert_spki_match() compares SubjectPublicKeyInfo bytes; the CertRep signer check and the test server's PKCSReq, resend and GetCertInitial checks use it
  • wolfcert_extract_spki() and the server's signer_matches_key() are removed
  • The same key under a different AlgorithmIdentifier (RSA-PSS vs rsaEncryption) no longer matches
  • wolfcert_scep_verify_rep_signer() takes ca_only; GetNextCACert counts only bundle certificates with basicConstraints cA set
  • scep.h names the SPKI rule and WOLFCERT_ERR_AUTH for pkcs_req and get_next_ca_cert; a refused roll-over sets an error message
  • The test server's signer-check OOM fault and the 500 branches only it reached are removed

Testing

  • test_cert_rep_signer_trust: an RA certificate relabelled id-RSASSA-PSS is refused
  • test_next_ca_response_signer_trust: a roll-over signed by the RA of an [RA, CA] bundle gets WOLFCERT_ERR_AUTH, with an OOM sweep over the CA check
  • test_scep_roundtrip: a PKCSReq signed with a key other than the CSR's gets badRequest
  • test_scep_poll_roundtrip drops the signer-check OOM cases

Copilot AI balanced review requested due to automatic review settings November 30, 2026 14:23
@Frauschi Frauschi self-assigned this Nov 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The review reports no active issues with the SCEP signer-validation changes.

No open issues 🎉

What changed in this PR

This PR strengthens wolfCert’s SCEP signer validation by reusing the DER-based SubjectPublicKeyInfo comparison introduced in #72 and requiring a trusted CA key for certificate roll-over.

Changes:

  • Unifies signer-key checks around full SubjectPublicKeyInfo bytes, including the AlgorithmIdentifier.
  • Restricts GetNextCACert signers to keys held by trusted bundle certificates with basicConstraints cA set.
  • Adds regression coverage and removes obsolete signer-check allocation-failure handling.
File Description
wolfcert/​scep.h Documents signer matching and roll-over authorization requirements.
tests/​unit/​test_scep_msg.c Tests algorithm-identifier mismatches, RA roll-over rejection, and CA-check allocation failures.
tests/​integration/​test_scep_roundtrip.c Tests rejection when the request signer and CSR keys differ.
tests/​integration/​test_scep_poll_roundtrip.c Removes obsolete signer-check allocation-failure cases.
src/​scep/​scep_server.c Uses shared SPKI matching for enrollment, resends, and polling.
src/​scep/​scep_msg.c Enforces CA-only roll-over trust and reports authorization failures.
src/​scep/​scep_client.c Updates CertRep validation to the revised signer-check interface.
src/​pkcs7_util.c Adds allocation-free comparison of complete SPKI encodings.
src/​internal.h Updates helper declarations, contracts, and fault-injection documentation.

Review effort: Balanced

@Frauschi

Copy link
Copy Markdown
Member Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread src/scep/scep_msg.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #83

Scan targets checked: wolfcert-src, wolfcert-bugs
Not reviewed (no scan target covers them): src/internal.h, src/pkcs7_util.c
Coverage: 7 of 7 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Nov 30, 2026
Two rules decided whether a certificate or CSR holds a given key. The
issued-certificate match from wolfSSL#72 compares the SubjectPublicKeyInfo found
by a DER walk, while the SCEP CertRep signer check and the test server's
PKCSReq, resend and GetCertInitial checks went through
wolfcert_extract_spki(), which ran wc_ParseCert and compared only
DecodedCert.publicKey, the key without its AlgorithmIdentifier.

wolfcert_spki_match() compares the SubjectPublicKeyInfo bytes that the
same DER walk finds, and both SCEP paths now use it, so
wolfcert_extract_spki() goes. The comparison no longer allocates or
parses the whole certificate. That drops the out-of-memory path of the
CertRep signer check and its OOM sweep, and the test server's
signer-check OOM fault together with the 500 branches only it reached.

A signer certificate whose AlgorithmIdentifier differs from the CSR's,
such as RSA-PSS against rsaEncryption for the same key, no longer
matches. The SCEP transactionID and the RA candidate hashes still cover
DecodedCert.publicKey, since RFC 8894 defines the transactionID over the
key alone. The CertRep signer test relabels an RA certificate's key as
id-RSASSA-PSS, which the old rule still matched, and a PKCSReq signed
with a key other than the CSR's now has a test of its badRequest reply.

Fixes F-19178.
RFC 8894 section 4.7.1 has the current CA sign the GetNextCACert reply.
wolfcert_scep_verify_next_ca_response() reused the CertRep check, which
accepts a signer whose key matches any certificate in current_ca_der.
scep.h tells callers to pass the GetCACert bundle there, and from a
CA/RA deployment that bundle holds the RA certificate too, so whoever
held the RA key could hand the client a new CA of their choosing.

wolfcert_scep_verify_rep_signer() takes ca_only, and with it a matching
bundle certificate counts only when its basicConstraints has cA set.
GetNextCACert passes 1 and the CertRep check 0. A v1 CA certificate
without basicConstraints can no longer vouch for a roll-over; RFC 5280
section 4.2.1.9 requires cA on any certificate that signs others.

The test signs a roll-over with a self-signed non-CA certificate placed
first in an [RA, CA] bundle and expects WOLFCERT_ERR_AUTH, and the OOM
sweep covers the parse behind the CA check. A refused roll-over now
leaves a message for wolfcert_last_error_message().

Fixes F-18384.
@yosuke-wolfssl
yosuke-wolfssl merged commit a57151b into wolfSSL:main Dec 3, 2026
37 checks passed
@Frauschi
Frauschi deleted the scep-spki branch December 3, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants