This recommends a "wire form" (ASN.1 SEQUENCE) order of RDN components
within a DN. That order can be important if the DN refers to an actual
directory in which it represents the name name of some object. Thus
LDAP DNs do have to be properly ordered and the ASN.1 (wire) form
of such DNs does have "C" first, then "ST", then "L", ... "O" before
"OU", and has its "DC" DNS name components ordered with the TLD first!
In case it is helpful, here's Gemini's response to a prompt that
solicits confirmation of this fact.
https://g.co/gemini/share/2d4618fd872a
In an X.509 certificate, one is of course free to order the components
however one sees fit, which mostly doesn't matter, unless there are
relevant name constraints in scope (actual X.509 name constaints on
Directory Names are not at all common). Hypothentical name constraints
aside, X.509 DNs are matched against expected values in their original
order, whatever it might be.
This specifies a human-readable "presentation form" for LDAP DNs, that
puts the most specific RDNs first. Thus one might see "C=AU" last, and
DC components in the usual DNS order "DC=host, DC=example, DC=com".
That form is not the "oneline" form historically used by OpenSSL, which
uses "/" rather than "," as a separator, does not reverse the RDN order,
and IIRC may not always round-trip faithfully when parsed in the "-subj"
option of openssl-req(1), openssl-x509(1) and openssl-ca(1).
> So a DN represented as a string "ST = California, C = US" would be in the
> proper order, because the `countryName` would normally be seen as a parent to
> the `stateOrProvinceName`.
That's RFC4514, not X509_NAME_oneline(3).
> What I find that seems to work in practice in OpenSSL, though, is the reverse
> of that expected representation. For example, if I define a
> `distinguished_name` section in a config file as:
>
> distinguished_name = req_distinguished_name
>
> [ req_distinguished_name ]
> C = US
> ST = California
> CN = foo
Well, now you're not looking at neither RFC4514, nor the oneline form.
Instead this this is "config section" syntax to *specify* (rather than
display) a DN, and the order of RDNs is the order in which they'll end
up in the ASN.1 DER sequence. This is consistent with other "section"
forms such as:
subjectAltName = @altNames
[altNames]
DNS.1 =
foo.example.com
DNS.2 =
bar.example.org
...
> and in the CA config, a name constraint:
>
> nameConstraints = critical, @name_constraints
>
> [ name_constraints ]
> permitted;dirName = dir_section
>
> [ dir_section ]
> C = US
> ST = California
And now the mythical dirName name constraints, again specified in their
physical (DER encoding) order, this is not a display form.
> the certificate chain verifies. But not if I reverse the order of all the
> RDN lines.
That would not be correct. I hope the above helps to make clear why.
> Is this correct as is? Is it a known issue? The manual pages don't really
> talk about it. I'm not familiar with the historical LDAP usages.
We're actually working on switching to RFC4514 as the display form
(which will require parsing that in "-subj" options when the value does
not start with a "/", with the legacy oneline form as a fallback).
--
Viktor. 🇺🇦 Слава Україні!