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

Jürgen Thelen picture Jürgen Thelen · May 9, 2011 · Viewed 119.9k times · Source

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

  1. domain.tld
  2. host.domain.tld

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

  • 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.tld, is being requested?

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

Answer

Eugene Mayevski 'Callback picture Eugene Mayevski 'Callback · May 9, 2011

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 it's common name parameter) of the certificate. These two places complement each other, and not duplicate it. And SubjectAltName is a proper place to put additional names, such as www.domain.com or www2.domain.com

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. I.e. by excluding CN from validation if SAN is present, you can deny some otherwise valid certificate.