Skip to content

Decode the WOLFSSL_CERT_NAME_ALL subject components - #11438

Open
Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:fix-cert-name-all-subject-decode
Open

Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:fix-cert-name-all-subject-decode

Conversation

@Frauschi

Copy link
Copy Markdown
Member

Description

certNameSubject[] is indexed by id - 3 and, without WOLFSSL_CERT_NAME_ALL, covers DN tag ids 3 through 18. The four entries WOLFSSL_CERT_NAME_ALL appends are labelled name, givenName, initials and dnQualifier - ids 41, 42, 43 and 46 - but appending them puts them at positions that make them ids 19, 20, 21 and 22.

Two consequences, in opposite directions:

  • The four components are dropped. GetRDN() finds no entry for the real ids, leaves typeStr NULL and never calls SetSubject(), so subjectN, subjectGN, subjectI and subjectDNQ are never populated.
  • Four unrelated components are decoded under the wrong name. 2.5.4.19 through 2.5.4.22 - physicalDeliveryOfficeName, telephoneNumber, teletexTerminalIdentifier, x121Address - match those entries instead, landing in the wrong DecodedCert field, under the wrong tag string, with the wrong X509_NAME NID.

Affects WOLFSSL_CERT_NAME_ALL builds: --enable-all and the openvpn, nginx, haproxy, hitch, bind and rsyslog recipes.

Fix

Drop the four misplaced entries and give the ids their own branches in GetRDN() and SetSubject(), beside the ASN_X500_UNIQUE_ID branch already there for a component outside the contiguous range. The tag-string macros are already defined in asn.h under the same guard. Without WOLFSSL_CERT_NAME_ALL the table already stopped at id 18, so ids 19 to 22 go back to being unrecognised there, as they were.

Testing

Adds test_wc_CertNameAllSubject() to the asn group: generates a self-signed cert carrying all four RDNs, re-parses it, and asserts each lands in the matching DecodedCert field and appears in dCert.subject. Nothing covered these paths before - no cert under certs/ carries any of the four OIDs, and no test referenced the fields.

make check green under --enable-all, and the new test fails when asn.c is restored from master, so it pins the indexing rather than passing vacuously.

Note for the reviewer

The subject string uses /N= and /GN=, matching the legacy asn_orig.c decoder, while RebuildFullName() regenerates it from obj->sName ("name", "givenName"). That divergence is pre-existing and mirrors the SN vs surname split in ssl_asn1.c, but this change makes it reachable in template builds for the first time. Left alone since aligning them is a user-visible output change; happy to do it separately.

@Frauschi Frauschi self-assigned this Sep 11, 2026
@Frauschi Frauschi added the For This Release Release version 5.9.4 label Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Sep 11, 2026
certNameSubject[] is indexed by id - 3 and holds 20 entries, covering DN
tag ids 3 through 22. The four entries WOLFSSL_CERT_NAME_ALL appends are
labelled name, givenName, initials and dnQualifier - ids 41, 42, 43 and 46
- but they sit at array positions that make them ids 19, 20, 21 and 22.

Two consequences. GetRDN() finds no table entry for the real ids, leaves
typeStr NULL and never calls SetSubject(), so subjectN, subjectGN,
subjectI and subjectDNQ are never populated and those RDNs are dropped
from a parsed certificate or CSR. And a certificate carrying 2.5.4.19
through 2.5.4.22 - physicalDeliveryOfficeName, telephoneNumber,
teletexTerminalIdentifier, x121Address - matches those entries instead and
is decoded under the wrong name, including into the wrong DecodedCert
field and the wrong X509_NAME NID.

Drop the four misplaced entries and give the ids their own branches in
GetRDN() and SetSubject(), beside the ASN_X500_UNIQUE_ID branch already
there for a component whose id falls outside the contiguous range. Without
WOLFSSL_CERT_NAME_ALL the table already stopped at id 18, so ids 19 to 22
go back to being unrecognised there, as they were.

Add test_wc_CertNameAllSubject(), which generates a self-signed
certificate carrying all four RDNs and asserts they come back out of
wc_ParseCert() in the matching DecodedCert fields and in the subject
string. Nothing covered these paths before: no certificate under certs/
carries any of the four OIDs, and no test referenced the fields. The test
fails against the pre-fix decoder.

The WOLFSSL_NAME, WOLFSSL_GIVEN_NAME, WOLFSSL_INITIALS and
WOLFSSL_DNQUALIFIER macros GetRDN() needs are already defined in asn.h
under the same guard, so no new definitions are required.
@Frauschi
Frauschi force-pushed the fix-cert-name-all-subject-decode branch from c06fb93 to 49da941 Compare September 14, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For This Release Release version 5.9.4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants