Skip to content

X509 API: fix issues#10548

Open
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:x509_fixups_1
Open

X509 API: fix issues#10548
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:x509_fixups_1

Conversation

@SparkiDev
Copy link
Copy Markdown
Contributor

Description

  1. BasicConstraints pathLenConstraint absent vs. 0 — get_ext_d2i/set_ext/V3_EXT_d2i now distinguish "no constraint" from 0 per RFC 5280 §4.2.1.9, using the existing basicConstPlSet flag.
  2. GENERAL_NAME_print GEN_DIRNAME — added missing return-value normalization so the directory name is actually printed (was emitting only DirName:).
  3. GENERAL_NAME_print GEN_DNS — use ASN1_STRING_print like the EMAIL/URI cases, avoiding NULL-strData deref and NUL-truncation.
  4. X509_print BasicConstraints — print , pathlen:N to match OpenSSL.
  5. X509_print Extended Key Usage — print Any Extended Key Usage (was omitted).
  6. get_ext_d2i CRL_DIST_OID double-free — null gn immediately after ownership transfers to dp, so an error from the next push doesn't free it twice.
  7. X509V3_EXT_print SAN truncation/failure — match XSNPRINTF size cap to the allocation; was truncating at indent==1 and failing at indent>=2.
  8. X509V3_EXT_print AUTH_KEY/SUBJ_KEY NULL deref — NULL-check i2s_ASN1_STRING return before passing to %s.
  9. X509_add_ext SAN type confusion — reject DIRNAME/RID/X400/EDIPARTY; only the ASN1_STRING*-backed types are read via gn->d.ia5. Was performing a wild-pointer XMEMCPY in add_altname_ex.

Also: extracted the SAN and WOLFSSL_CUSTOM_OID arms of X509_add_ext into static helpers (behavior-preserving).

Regression tests added for #1–5 and #9; existing GENERAL_NAME_print test hardened (gives GEN_DIRNAME a real directoryName, eliminating an OOB read that the print fix would otherwise expose).

Testing

./configure --disable-shared --enable-opensslall

@SparkiDev SparkiDev self-assigned this May 28, 2026
1. BasicConstraints pathLenConstraint absent vs. 0 —
get_ext_d2i/set_ext/V3_EXT_d2i now distinguish "no constraint" from 0
per RFC 5280 §4.2.1.9, using the existing basicConstPlSet flag.
2. GENERAL_NAME_print GEN_DIRNAME — added missing return-value
normalization so the directory name is actually printed (was emitting
only DirName:).
3. GENERAL_NAME_print GEN_DNS — use ASN1_STRING_print like the EMAIL/URI
cases, avoiding NULL-strData deref and NUL-truncation.
4. X509_print BasicConstraints — print , pathlen:N to match OpenSSL.
5. X509_print Extended Key Usage — print Any Extended Key Usage (was
omitted).
6. get_ext_d2i CRL_DIST_OID double-free — null gn immediately after
ownership transfers to dp, so an error from the next push doesn't free
it twice.
7. X509V3_EXT_print SAN truncation/failure — match XSNPRINTF size cap to
the allocation; was truncating at indent==1 and failing at indent>=2.
8. X509V3_EXT_print AUTH_KEY/SUBJ_KEY NULL deref — NULL-check
i2s_ASN1_STRING return before passing to %s.
9. X509_add_ext SAN type confusion — reject DIRNAME/RID/X400/EDIPARTY;
only the ASN1_STRING*-backed types are read via gn->d.ia5. Was
performing a wild-pointer XMEMCPY in add_altname_ex.

Also: extracted the SAN and WOLFSSL_CUSTOM_OID arms of X509_add_ext into
static helpers (behavior-preserving).

Regression tests added for #1–5 and wolfSSL#9; existing GENERAL_NAME_print test
hardened (gives GEN_DIRNAME a real directoryName, eliminating an OOB
read that the print fix would otherwise expose).
@SparkiDev
Copy link
Copy Markdown
Contributor Author

Jenkins: retest this please

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a set of OpenSSL-compatibility and safety issues in the X509 extension APIs and printing paths (BasicConstraints, SubjectAltName, GENERAL_NAME_print, and X509_print), and adds regression tests to prevent reintroduction.

Changes:

  • Correctly distinguish BasicConstraints pathLenConstraint “absent” vs 0 across get/set/print paths (per RFC 5280) and align printed output with OpenSSL.
  • Harden GENERAL_NAME / extension printing (DirName rendering, DNS printing via ASN1_STRING_print, NULL checks, and buffer sizing fixes).
  • Refactor wolfSSL_X509_add_ext() SAN + custom-OID handling into helpers and add regression tests (including SAN type rejection).

Reviewed changes

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

File Description
tests/api/test_ossl_x509_ext.h Registers new API-level regression tests for BasicConstraints and SAN rejection.
tests/api/test_ossl_x509_ext.c Adds tests for DirName SAN rejection and BasicConstraints pathlen absent vs 0 semantics.
tests/api.c Hardens GENERAL_NAME_print test inputs and adds X509_print output regression tests (BasicConstraints + EKU).
src/x509.c Implements BasicConstraints semantics/printing fixes, GENERAL_NAME_print fixes, SAN rejection hardening, and refactors add_ext logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/x509.c
Comment on lines +1325 to +1328
if ((ext->obj == NULL) || (ext->value.length == 0)) {
WOLFSSL_MSG("Extension has insufficient information.");
return WOLFSSL_FAILURE;
}
Comment thread src/x509.c
Comment on lines 1576 to +1584
val = (char*)XMALLOC(len + indent, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (val == NULL) {
WOLFSSL_MSG("Memory error");
return rc;
}
valLen = XSNPRINTF(val, (size_t)len, "%*s%s", indent, "",
str->strData);
if ((valLen < 0) || (valLen >= len)
valLen = XSNPRINTF(val, (size_t)len + indent,
"%*s%s", indent, "", str->strData);
if ((valLen < 0) || (valLen >= len + indent)
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