带有通配符证书的 Kestrel HTTPS 端点

Kestrel HTTPS Endpoint with Wildcard Certificate

我们在使用以下 appsettings.json 文件为 Kestrel ASP.NET Web API 主机加载通配符证书时遇到问题:

"Kestrel": {
  "EndPoints": {
    "HttpsInlineCertStore": {
      "Url": "https://test.my.host.com:443",
      "Certificate": {
        "Subject": "*.host.com",
        "Store": "My",
        "Location": "LocalMachine",
        "AllowInvalid": "true"
      }
    }
  }
}

在 Chrome 中,我们收到 NET::ERR_CERT_COMMON_NAME_INVALID 错误,而在 Firefox SSL_ERROR_BAD_CERT_DOMAIN.

当然 URL 中的域与通配符证书不一致,但我们不确定如何纠正此问题。

原来这个问题与域的级别和通配符 * 的位置有关。

*.host.com只会匹配sub-domains的单个级别,而不是“sub-sub-domains”。

所以 testmy.host.com 有效,但 test.my.host.com 无效。要使后者工作,需要另一个通配符证书 *.my.host.com