Search code examples
sslhttpsssl-certificate

How do Common Names (CN) and Subject Alternative Names (SAN) work together?


Assuming the Subject Alternative Name (SAN) property of an SSL certificate contains two DNS names

  1. domain.example
  2. host.domain.example

but the Common Name (CN) is set to only one of both: CN=domain.example.

  • Does this setup have a special meaning, or any [dis]advantages over setting both CNs?
  • What happens on server-side if the other one, host.domain.example, is being requested?

Specifically, how does OpenSSL 0.9.8b+ handle the given scenario?


Solution

  • This depends on implementation, but the general rule is that the domain is checked against all SANs and the common name. If the domain is found there, then the certificate is OK for connection.

    RFC 5280, section 4.1.2.6 says "The subject name MAY be carried in the subject field and/or the subjectAltName extension". This means that the domain name must be checked against both SubjectAltName extension and Subject property (namely its common name parameter) of the certificate. These two places complement each other, not duplicate each other. And SubjectAltName is a proper place to put additional names, such as www.domain.example or www2.domain.example

    Update: as per RFC 6125, published in 2011, the validator must check SAN first, and if SAN exists, then CN should not be checked. Note that RFC 6125 is relatively recent and there still exist certificates and CAs that issue certificates, which include the "main" domain name in CN and alternative domain names in SAN. In other words, by excluding CN from validation if SAN is present, you can deny some otherwise valid certificate.