NAME_CONSTRAINTS_CHECK(3ossl)
π NAME_CONSTRAINTS_CHECK(3ossl) π
okay so bestie, welcome to the OpenSSL manual, section 3ossl, and specifically the page for NAME_CONSTRAINTS_check and NAME_CONSTRAINTS_check_CN. this is the vibe check your certificate's names have to pass before the name-constraints bouncer lets them in. let's get into it π«Ά
πΈ NAME πΈ
NAME_CONSTRAINTS_check, NAME_CONSTRAINTS_check_CN β check a certificate's names against a name constraints extension. that's it, that's the whole job, and honestly? iconic. β¨
π SYNOPSIS π
#include <openssl/x509v3.h>
int NAME_CONSTRAINTS_check(const X509 *x, NAME_CONSTRAINTS *nc);
int NAME_CONSTRAINTS_check_CN(const X509 *x, NAME_CONSTRAINTS *nc);
π DESCRIPTION π
okay so NAME_CONSTRAINTS_check() tests whether the names asserted by certificate x satisfy the name constraints nc. it implements the matching primitive of RFC 5280 section 4.2.1.10: you hand it a constraint set (a NAME_CONSTRAINTS structure containing zero or more permittedSubtrees and excludedSubtrees) plus a candidate certificate, and it decides whether the certificate's names fall within the permitted subtrees and outside the excluded subtrees. permitted = slay, excluded = blocked, no in-between π
the names it actually looks at are:
- the certificate's subject distinguished name, matched as a
directoryNamegeneral-name type. the subject is considered only when it is nonempty β empty subject? nothing to check, moving on. - each
emailAddressattribute appearing within the subject distinguished name, matched as anrfc822Namegeneral-name type. these attributes are the historical, pre-SAN way of expressing an email address in a certificate's subject, and RFC 5280 requires that they be subjected to name-constraint checking. yes bestie, the old way still counts π - each entry in the certificate's subject alternative name extension, matched according to its declared general-name type.
NAME_CONSTRAINTS_check() implements matching for these general-name types: directoryName, dNSName, rfc822Name, uniformResourceIdentifier, and iPAddress. the otherName form id-on-SmtpUTF8Mailbox (RFC 8398) is additionally matched against rfc822Name subtrees. any other general-name type β including x400Address, ediPartyName, registeredID, and other otherName forms β yields X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE. not supported, not sorry, it will tell you so.
for each name considered, the function evaluates two conditions:
- if
nccontains at least onepermittedSubtreeof the same general-name type as the name, the name must match at least one of those permitted subtrees. ifnccontains no permitted subtrees of that type, no permitted-subtrees test is imposed on names of that type. (no list, no rules, we chill π) - the name must not match any
excludedSubtreeof the same general-name type innc. periodt.
the function returns at the first violation encountered; it does not collect or report multiple failures. one strike and you're out, it's giving strict π
for dNSName entries, matching follows the byte/label algorithm of RFC 5280 section 4.2.1.10, which RFC 5280 mandates when no protocol-specific matching rules apply. because this match is performed without awareness of any specific higher-level protocol, additional matching rules defined by later or more specific protocols must be applied independently of this function to the certificate chain. iykyk π
NAME_CONSTRAINTS_check() performs only the constraint match for a single certificate against a single constraint set. it does not perform the chain-wide enforcement of RFC 5280 section 6.1.4(g)-(j): callers wishing to enforce name constraints across an entire certification path must walk the chain themselves and apply each ancestor's constraint set to certificates lower in the chain, observing the usual exceptions (for example, self-issued intermediate certificates are exempt from constraints imposed by certificates above them, except when they are the leaf of the chain). for full RFC 5280 name-constraint enforcement integrated with chain validation, applications should use X509_verify_cert(3), which performs this internally. don't do the chain walk yourself unless you truly want to π«
NAME_CONSTRAINTS_check() enforces an implementation limit on the product of the certificate's name count and the constraint set's subtree count, to prevent computationally expensive matching on pathological input. if that limit is exceeded the function returns X509_V_ERR_UNSPECIFIED without performing any matching. the current limit is 2**20 (1,048,576) on the product of the name count (subject DN entries plus subjectAltName entries) and the subtree count (permittedSubtrees plus excludedSubtrees). math is the bouncer here, lowkey π₯
β RETURN VALUES β
NAME_CONSTRAINTS_check() returns X509_V_OK if every name considered satisfies the constraints. all good, chef's kiss, we ate π
otherwise it returns one of these X509_V_ERR_* codes:
X509_V_ERR_PERMITTED_VIOLATIONβ a name of a type for whichnccontains at least one permitted subtree failed to match any of those subtrees. it was supposed to be on the list and it wasn't πX509_V_ERR_EXCLUDED_VIOLATIONβ a name matched an excluded subtree. you were literally told not to be here πX509_V_ERR_SUBTREE_MINMAXβ a subtree inncspecified a minimum other than0or a maximum at all. RFC 5280 requires that theseGeneralSubtreefields not be used, and a constraint set that uses them cannot be processed. nope, cannot be processed, full stop.X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPEβ a general-name type for which matching is not implemented was encountered. the list of supported types is given in the DESCRIPTION above, bestie, scroll up πX509_V_ERR_UNSUPPORTED_NAME_SYNTAXβ a name in the certificate is encoded in a way that cannot be matched (for example, anemailAddressattribute in the subject that is not encoded as anIA5String). encoding said no πX509_V_ERR_UNSPECIFIEDβ the product of the certificate's name count and the constraint set's subtree count exceeded the implementation limit; no matching was performed. too much math, we're out π«
other X509_V_ERR_* codes may be returned by deeper name-matching helpers (for example, codes arising from individual general-name type comparisons). callers should treat the return value as the authoritative success/failure signal and treat any value other than X509_V_OK as a failure, rather than enumerating the specific codes above. do not be out here writing a switch over every single code, that's not the move, fr fr β¨
π¦ NOTES π¦
NAME_CONSTRAINTS_check() does not match the certificate's commonName against dNSName name constraints; that check is provided by a separate function, NAME_CONSTRAINTS_check_CN(). the commonName-as-DNS-identity practice is a legacy concern: modern certificates assert DNS identities through dNSName entries in the subject alternative name extension, which NAME_CONSTRAINTS_check() already covers. NAME_CONSTRAINTS_check_CN() is required only for older certificates that express a DNS identity through their commonName instead of, or in addition to, the SAN; for certificates conforming to modern profiles a call to NAME_CONSTRAINTS_check() alone is generally sufficient. so if you're on modern certs, you're good, no extra call needed πΈ
π BUGS π
RFC 9525's wildcard semantics apply only to presented-identifier matching for TLS service identity, and explicitly call out they are not valid for any other purpose; they do not define wildcard handling for name-constraint matching. NAME_CONSTRAINTS_check() therefore follows RFC 5280's requirements for when this is undefined, and treats the * character in a dNSName as a literal label component, per the RFC 5280 algorithm, which is often contrary to caller expectation. yes bestie, * is not a magic wildcard here, it's just a star, and that surprises people literally all the time π
even if specified in the future, due to the "fallback implementation" nature of matching wildcards in SAN dNSName entries specified by RFC 5280, name constraint behaviour in the presence of wildcards should not be strictly relied upon across implementations and protocols. this matters most for the use of excluded names constraints, which should not be relied upon to reliably constrain signing certificates for a PKI in a security dependent manner unless the consumers of these certificates are themselves known to be constrained by other means to only use implementations that provide different semantics, or the PKI can be constrained by other means to ensure that wildcards are never issued from such signing certificates. read that twice, it's a security thing, not a vibe. π¨
π SEE ALSO π
π HISTORY π
NAME_CONSTRAINTS_check()was added in OpenSSL1.0.0.NAME_CONSTRAINTS_check_CN()was added in OpenSSL1.1.0.
π COPYRIGHT π
Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie π this was OpenSSL 3.5.9, dated 2026-09-29, and it's the NAME_CONSTRAINTS_CHECK(3ossl) manual β go forth and constrain your names responsibly, mwah π«Άβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms