由于证书上的 CN 与 SNI 导致 SMTP 问题?

由于证书上的 CN 与 SNI 导致 SMTP 问题?

我有一个场景,我使用共享邮件服务器 (cPanel) 在多个域上为多个客户端提供 SMTP。我遇到了一个问题,Ruby 的 OpenSSL 库抱怨hostname "smtp.domain2.tld" does not match the server certificate.

在这种情况下,我认为问题在于证书的主要 CN 是“domain2.tld”,而“mail.domain2.tld”是可接受的 DNS SAN,但它不是主要 CN,如果没有请求 SNI,则会失败...

例如:如果我使用openssl没有“servername”指令进行连接,那么我得到的证书是服务器本身的 server.main-domain.tld:

$ openssl s_client -connect mail.domain2.tld:587 -starttls smtp -showcerts | grep CN=

depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify error:num=20:unable to get local issuer certificate
verify return:0
250 HELP
0 s:/OU=Domain Control Validated/OU=PositiveSSL/CN=server.main-domain.tld
i:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
1 s:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
2 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
i:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
subject=/OU=Domain Control Validated/OU=PositiveSSL/CN=server.main-domain.tld
issuer=/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority

请注意,证书是server.main-domain.tld而不是domain2.tldmail.domain2.tld

但是,如果我们使用 -servername 指定 SNI 名称:

$ openssl s_client -connect server.main-domain.tld:587 -servername mail.domain2.tld -starttls smtp -showcerts | grep CN=

depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify error:num=20:unable to get local issuer certificate
verify return:0
250 HELP
0 s:/CN=domain2.tld
i:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
1 s:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
2 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
i:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
subject=/CN=domain2.tld
issuer=/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority

似乎有些测试(例如swaks) 不会强制进行 SNI 查找(因此它可以通过 SMTP 顺利发送电子邮件),但也许 Ruby 的 OpenSSL 库对此的处理方式略有不同……

我应该怎么做才能正确设置证书或服务器以避免产生此问题?

答案1

看起来某些测试(例如 swaks)并没有强制进行 SNI 查找...

没有“SNI 查找”。客户端要么在 TLS 握手中使用 SNI 通过扩展指定目标主机名,server_name要么不使用。但一般来说,SMTP 中 SNI 的使用并不常见,而且支持情况参差不齐。这包括通常不支持同一 IP 地址上的多个证书的邮件服务器,以及一些使用 SNI 而其他不使用的邮件客户端。

至少目前来说,最好不要依赖 SMTP 的 SNI。这意味着要么使用一个证书通过主题备用名称覆盖所有可能的名称,要么为不同的证书设置不同的 IP 地址。

相关内容