Skip to content

scep: set keyUsage on the self-signed enrollee certificate - #19

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:mainfrom
yosuke-wolfssl:fix/f_9799
Open

scep: set keyUsage on the self-signed enrollee certificate#19
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:mainfrom
yosuke-wolfssl:fix/f_9799

Conversation

@yosuke-wolfssl

Copy link
Copy Markdown

Problem

RFC 8894 §1 requires that a SCEP client with no existing certificate sign its
pkiMessage with a self-signed certificate carrying a keyUsage extension
asserting digitalSignature and keyEncipherment.
wolfcert_scep_self_signed_rsa() in src/scep/scep_msg.c built that
certificate without one: it set selfSigned, sigType and daysValid,
copied the CSR subject, then called wc_MakeSelfCert() directly. The
certificate goes on the wire in the SignedData certificates field via
wc_PKCS7_InitWithCert(), so every enrollment presented a non-conformant
signer identity to the CA. Reached from four call sites in
src/scep/scep_client.c — the blocking and non-blocking PKCSReq paths and
the GetCertInitial fallback signer — so it affected all SCEP enrollments,
and a CA that enforces the requirement rejects them. Standards conformance;
no memory-safety impact.

Fix (src/scep/scep_msg.c)

Set the usage before the certificate is signed:

    rc = wc_SetKeyUsage(cert, "digitalSignature,keyEncipherment");
    if (rc != 0) {
        wc_CertFree(cert);
        return WOLFCERT_ERR_WC(rc, "scep", "SetKeyUsage");
    }

Reuses the function's existing rc local and its wc_CertFree() +
early-return cleanup style. No #ifdef WOLFSSL_CERT_EXT guard is needed —
wolfcert/check_config.h already hard-errors when wolfSSL lacks it.

Closes f-9799.

Tests

test_signer_key_usage() in tests/unit/test_scep_msg.c builds a CSR,
generates the signer certificate, parses it, and requires extKeyUsageSet
plus both the KEYUSE_DIGITAL_SIG and KEYUSE_KEY_ENCIPHER bits.

Verification

  • Build clean, no warnings.
  • Negative control: the new test fails on the unpatched tree at the
    extKeyUsageSet assertion, passes after the fix.
  • Full suite: 26/26 ctest pass, including scep_roundtrip,
    scep_poll_roundtrip, scep_async_roundtrip and parse_negative, which
    drive the real signer path end to end.

- wolfcert_scep_self_signed_rsa() calls wc_SetKeyUsage() with
  digitalSignature,keyEncipherment before wc_MakeSelfCert(), and
  returns WOLFCERT_ERR_WC on failure after freeing the Cert.
- tests/unit/test_scep_msg.c gains test_signer_key_usage(), which
  builds a CSR, generates the signer certificate and requires the
  parsed certificate to carry the keyUsage extension with both the
  digitalSignature and keyEncipherment bits.

Issue: F-9799
@yosuke-wolfssl yosuke-wolfssl self-assigned this Aug 21, 2026
Copilot AI lite review requested due to automatic review settings August 21, 2026 01:39

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.

Pull request overview

Updates SCEP self-signed enrollee certificates to include RFC 8894-required key usages.

Changes:

  • Sets digitalSignature and keyEncipherment before signing.
  • Adds unit coverage for both key-usage bits.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/unit/test_scep_msg.c Tests the generated certificate’s key usages.
src/scep/scep_msg.c Adds the required key-usage extension and error handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@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 #19

Scan targets checked: wolfcert-bugs, wolfcert-src

No new issues found in the changed files. ✅

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.

4 participants