@@ -650,8 +650,14 @@ static int DNS_to_GENERAL_NAME(WOLFSSL_GENERAL_NAME* gn, DNS_entry* dns)
650650 /* @TODO extract dir name info from DNS_entry */
651651 break;
652652
653- #ifdef WOLFSSL_RID_ALT_NAME
654653 case WOLFSSL_GEN_RID:
654+ /* registeredID is parsed into altNames unconditionally so
655+ * ConfirmNameConstraints can enforce RID name constraints
656+ * (RFC 5280 Sec. 4.2.1.10). The body uses only the raw OID
657+ * bytes carried in dns->name/dns->len and constructs a
658+ * proper ASN1_OBJECT, so this case is independent of
659+ * WOLFSSL_RID_ALT_NAME (which only gates the human-readable
660+ * ridString form). */
655661 gn->type = dns->type;
656662 /* wolfSSL_GENERAL_NAME_new() mallocs this by default */
657663 wolfSSL_ASN1_STRING_free(gn->d.ia5);
@@ -681,7 +687,6 @@ static int DNS_to_GENERAL_NAME(WOLFSSL_GENERAL_NAME* gn, DNS_entry* dns)
681687 gn->d.registeredID->dynamic |= WOLFSSL_ASN1_DYNAMIC_DATA;
682688 gn->d.registeredID->grp = oidCertExtType;
683689 break;
684- #endif
685690
686691 case WOLFSSL_GEN_X400:
687692 /* Unsupported: fall through */
@@ -2533,8 +2538,12 @@ void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509, int nid, int* c,
25332538 gn->d.iPAddress->type = WOLFSSL_V_ASN1_OCTET_STRING;
25342539 break;
25352540
2536- #ifdef WOLFSSL_RID_ALT_NAME
25372541 case ASN_RID_TYPE:
2542+ /* Always handle registeredID: the union
2543+ * member d.registeredID is populated from
2544+ * raw OID body bytes. WOLFSSL_RID_ALT_NAME
2545+ * only gates the human-readable ridString,
2546+ * which this path does not need. */
25382547 gn->type = dns->type;
25392548 /* Free ia5 before using union for registeredID */
25402549 wolfSSL_ASN1_STRING_free(gn->d.ia5);
@@ -2567,7 +2576,6 @@ void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509, int nid, int* c,
25672576 WOLFSSL_ASN1_DYNAMIC_DATA;
25682577 gn->d.registeredID->grp = oidCertExtType;
25692578 break;
2570- #endif /* WOLFSSL_RID_ALT_NAME */
25712579
25722580 default:
25732581 gn->type = dns->type;
@@ -4262,24 +4270,35 @@ char* wolfSSL_X509_get_next_altname(WOLFSSL_X509* cert)
42624270 return NULL;
42634271 }
42644272
4265- #ifndef WOLFSSL_IP_ALT_NAME
42664273 /* In default builds iPAddress entries hold raw 4/16 octet payloads
4267- * (no human-readable ipString), so returning them as a C string would
4268- * truncate at any embedded NUL byte. Such entries are still parsed
4269- * into altNames for name-constraint enforcement; skip them here so
4274+ * and registeredID entries hold raw OID body bytes (no human-readable
4275+ * ipString/ridString), so returning them as a C string would truncate
4276+ * at any embedded NUL byte. Such entries are still parsed into
4277+ * altNames for name-constraint enforcement; skip them here so
42704278 * string-iteration callers see the same set of entries as before.
42714279 *
42724280 * With WOLFSSL_MULTICIRCULATE_ALTNAMELIST, a list consisting only of
4273- * iPAddress entries collapses to "no entries" on the first pass and
4281+ * skipped entries collapses to "no entries" on the first pass and
42744282 * resets to head on the next call; the cycle shape matches the
42754283 * pre-fix behavior where such entries were never parsed. */
4276- while (cert->altNamesNext != NULL &&
4277- cert->altNamesNext->type == ASN_IP_TYPE) {
4284+ #if !defined(WOLFSSL_IP_ALT_NAME) || !defined(WOLFSSL_RID_ALT_NAME)
4285+ while (cert->altNamesNext != NULL) {
4286+ int skip = 0;
4287+ #ifndef WOLFSSL_IP_ALT_NAME
4288+ if (cert->altNamesNext->type == ASN_IP_TYPE)
4289+ skip = 1;
4290+ #endif
4291+ #ifndef WOLFSSL_RID_ALT_NAME
4292+ if (cert->altNamesNext->type == ASN_RID_TYPE)
4293+ skip = 1;
4294+ #endif
4295+ if (!skip)
4296+ break;
42784297 cert->altNamesNext = cert->altNamesNext->next;
42794298 }
42804299 if (cert->altNamesNext == NULL)
42814300 return NULL;
4282- #endif
4301+ #endif /* !WOLFSSL_IP_ALT_NAME || !WOLFSSL_RID_ALT_NAME */
42834302
42844303 /* unsafe cast required for ABI compatibility. */
42854304 ret = (char *)(wc_ptr_t)cert->altNamesNext->name;
@@ -4288,6 +4307,12 @@ char* wolfSSL_X509_get_next_altname(WOLFSSL_X509* cert)
42884307 if (cert->altNamesNext->type == ASN_IP_TYPE) {
42894308 ret = cert->altNamesNext->ipString;
42904309 }
4310+ #endif
4311+ #ifdef WOLFSSL_RID_ALT_NAME
4312+ /* return the registeredID as a string */
4313+ if (cert->altNamesNext->type == ASN_RID_TYPE) {
4314+ ret = cert->altNamesNext->ridString;
4315+ }
42914316#endif
42924317 cert->altNamesNext = cert->altNamesNext->next;
42934318
@@ -6903,6 +6928,14 @@ static int X509_print_name_entry(WOLFSSL_BIO* bio,
69036928 len = XSNPRINTF(scratch, MAX_WIDTH, "IP Address:%s",
69046929 entry->ipString);
69056930 }
6931+ #else
6932+ else if (entry->type == ASN_IP_TYPE) {
6933+ /* iPAddress entries are now always parsed into altNames so
6934+ * name constraints can be enforced. Without the
6935+ * human-readable ipString field, emit a fixed label so this
6936+ * print path does not fail. */
6937+ len = XSNPRINTF(scratch, MAX_WIDTH, "IP Address:<unavailable>");
6938+ }
69066939 #endif /* OPENSSL_ALL || WOLFSSL_IP_ALT_NAME */
69076940 else if (entry->type == ASN_RFC822_TYPE) {
69086941 len = XSNPRINTF(scratch, MAX_WIDTH, "email:%s",
@@ -6915,12 +6948,20 @@ static int X509_print_name_entry(WOLFSSL_BIO* bio,
69156948 len = XSNPRINTF(scratch, MAX_WIDTH, "URI:%s",
69166949 entry->name);
69176950 }
6918- #if defined(OPENSSL_ALL)
6951+ #ifdef WOLFSSL_RID_ALT_NAME
69196952 else if (entry->type == ASN_RID_TYPE) {
69206953 len = XSNPRINTF(scratch, MAX_WIDTH, "Registered ID:%s",
69216954 entry->ridString);
69226955 }
6923- #endif
6956+ #else
6957+ else if (entry->type == ASN_RID_TYPE) {
6958+ /* registeredID entries are now always parsed into altNames
6959+ * so name constraints can be enforced. Without the
6960+ * human-readable ridString field, emit a fixed label so
6961+ * this print path does not fail. */
6962+ len = XSNPRINTF(scratch, MAX_WIDTH, "Registered ID:<unavailable>");
6963+ }
6964+ #endif /* WOLFSSL_RID_ALT_NAME */
69246965 else if (entry->type == ASN_OTHER_TYPE) {
69256966 len = XSNPRINTF(scratch, MAX_WIDTH,
69266967 "othername <unsupported>");
0 commit comments