Skip to content

CSR: count custom extensions in the output buffer estimate - #82

Open
kojo1 wants to merge 2 commits into
wolfSSL:mainfrom
kojo1:csr-cap-ext
Open

kojo1 wants to merge 2 commits into
wolfSSL:mainfrom
kojo1:csr-cap-ext

Conversation

@kojo1

@kojo1 kojo1 commented Nov 30, 2026 •

Copy link
Copy Markdown

wolfcert_csr_build_ex() sizes the DER buffer from the key, the SAN and
the subject only. Extensions added by the customize callback
(wc_SetCustomExtension, the extCustom request extension) are not
counted, so a large one - e.g. attestation evidence per
draft-ietf-lamps-csr-attestation, 1.5 KB and more - makes
wc_MakeCertReq_ex() fail with a buffer error.

Add their encoded size (OID, value, 16 bytes of headers) to the
estimate. The fields exist with WOLFSSL_CUSTOM_OID only.

Add csr_carries_large_custom_ext: a 3000-byte custom extension from
the customize callback.

Note for CI

None of the CI wolfSSL configs in scripts/ci/build-wolfssl.sh defines
WOLFSSL_CUSTOM_OID, so CI does not run the new test. Adding
-DWOLFSSL_CUSTOM_OID -DHAVE_OID_ENCODING to _base_flags (or to a single
config) would cover it. That changes the wolfSSL build cache key, so I left
it out of this PR. Happy to add it here or in a follow-up, whichever you
prefer.

Copilot AI balanced review requested due to automatic review settings November 30, 2026 00:36

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.

🟡 Changes recommended

The custom-extension test and its registration are missing the WOLFSSL_ASN_TEMPLATE and HAVE_OID_ENCODING guards, causing supported custom-OID configurations to call an unavailable function and fail the unit-test build.

1 open issue
What changed in this PR

This PR updates wolfCert’s certificate signing request (CSR) buffer estimate to account for custom extensions, preventing buffer errors when customization callbacks add large payloads such as attestation evidence.

Changes:

  • Include custom-extension OIDs, values, and encoding overhead in the DER buffer estimate.
  • Add a regression test that verifies a CSR contains a 3,000-byte custom extension.
File Description
tests/​unit/​test_csr.c Adds and registers the large custom-extension regression test.
src/​csr.c Counts custom-extension sizes when allocating the CSR output buffer.

Review effort: Balanced

Comment thread tests/unit/test_csr.c Resolved

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

No active review issues are reported for the CSR buffer-sizing update.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix looks right, and cmake-full-all already runs the new test since --enable-all defines WOLFSSL_CUSTOM_OID, so no CI change is needed.

Comment thread src/csr.c
sz += (size_t)ext->valSz;
sz += 16;
}
if (cert->extCustom.oidSz > 0 || cert->extCustom.valSz > 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nothing sets cert->extCustom, so this branch is untested; add a case whose callback fills extCustom with a few KB, or drop the term. wolfSSL only encodes extCustom when oidSz > 0, so the valSz check can go.

Comment thread src/csr.c
return rc;
}

/* Encoded size bound of the extensions a customize callback can add on top

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sbjRaw is only set on renewal, so the estimate does not count a subject from meta (a known gap), and custom_ext_size covers only the WOLFSSL_CUSTOM_OID fields. Something like /* Encoded size of the custom OID extensions the customize callback set. */ would be accurate.

Comment thread tests/unit/test_csr.c

#if defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ASN_TEMPLATE) && \
defined(HAVE_OID_ENCODING)
/* A customize callback adding a large custom extension (e.g. attestation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Per CONTRIBUTING this should be one or two lines naming input and outcome, such as /* 3000-byte custom extension from customize: the CSR carries it. */. The L782 comment can go too, since extnValue holds any DER and wolfSSL adds the OCTET STRING wrapper.

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.

3 participants