6

Is there a particular order in which the subject attributes - C, ST, L, O, OU, CN have to specified. openssl does not seem to enforce an order.

And while generating the Distinguished Name do we pick up all the subject attributes configured in the certificate? Does the ordering of the attributes matter ?

Bharath Shetty
  • 109
  • 1
  • 8

2 Answers2

5

In theory, it doesn't matter but in practice, some crypto libraries are not able to build a chain if the order of tokens in the subject of parent certificate is different than the order of tokens in issuer field in child certificate. They should be exactly the same if you don't want to have any strange issues.

For example, even the windows 10 tool (mmc) doesn't display correctly the chain if the order of tokens in the subject/issuer field is different.

Lukasz
  • 103
  • 1
  • 3
  • 2
    Same with java. In `sun.security.pkcs12.PKCS12KeyStore` the chain validation fails if the subject(-string) resp. issuer(-string) are encoding the actual attributes in different orders. – Kai Huppmann Oct 23 '19 at 09:47
4

Is there a particular order in which the subject attributes - C, ST, L, O, OU, CN have to specified.

There is no order specified as far as I know. Order that you specify will be used and in this order will DN be generated in i.e. PKCS#10 request.

And while generating the Distinguished Name do we pick up all the subject attributes configured in the certificate?

CA may (and most probably will) use DN from your PKCS#10 request when issuing certificate but it can decide on a different order. Some RDNs (Relative Distinguished Names) can be moved to extensions, i.e. emailAddress or copied to extensions like CN to SubjectAlternativeName when issuing SSL server certificate.

Does the ordering of the attributes matter ?

Ordering does not IMHO matter. It might matter to some application that is consuming the certificate but in general ordering does not matter.

pepo
  • 8,644
  • 2
  • 27
  • 42
  • 2
    Here is an article describing the issue. tltr: order matters: https://frasertweedale.github.io/blog-redhat/posts/2019-05-28-a-dn-is-not-a-string.html – Jens Baitinger Feb 08 '21 at 16:44
  • Per IETF RFC 5280 sec 7.1, ordering matters. `Two distinguished names DN1 and DN2 match if they have the same number of RDNs, for each RDN in DN1 there is a matching RDN in DN2, and the matching RDNs appear in the same order in both DNs.` https://www.rfc-editor.org/rfc/rfc5280#section-7.1 – Cheeso Jul 20 '23 at 19:06