【问题标题】:"The remote certificate is invalid according to the validation procedure", but only from same server call“根据验证程序,远程证书无效”,但仅来自同一服务器调用
【发布时间】:2021-09-28 11:26:15
【问题描述】:

TLDR: 通过 https 的 Web 服务调用在另一台计算机上工作,但从本地服务器(本身)它给出“System.Security.Authentication.AuthenticationException, System.Net.WebException The remote certificate is invalid 根据验证程序”。

我有一个 网站(编辑:网站本身不在 https 上,只是在 http 上。它是通过通过 IIS 绑定绑定到网站的 dns 名称访问的。)和一个网络服务,都在具有主机名ip-address服务器上运行。 (我可能不允许透露实际姓名和地址)。
公司 CA CA 颁发了证书,具有以下属性(以及其他):

Issuer: CA
Subject: CN = hostname
Subject Alternative Name: IP Address =  ip-address

我在 IIS 中删除了 webservice 的 http 绑定,只留下了 https。

Type Host Name Port IP Address Binding Information
https 443 ip address

网站使用网址调用服务
https://ip-address/服务.asmx
和代码:

using (WebResponse webResponse = request.GetResponse()) {
    do stuff...
}

“GetResponse()”函数连续抛出多个错误:

Exception thrown: 'System.Security.Authentication.AuthenticationException' in System.dll
Exception thrown: 'System.Security.Authentication.AuthenticationException' in System.dll
Exception thrown: 'System.Security.Authentication.AuthenticationException' in System.dll
Exception thrown: 'System.Security.Authentication.AuthenticationException' in System.dll
Exception thrown: 'System.Security.Authentication.AuthenticationException' in System.dll
Exception thrown: 'System.ObjectDisposedException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll

异常信息是:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

内部异常:

The remote certificate is invalid according to the validation procedure.

我有 网站 - website_local 的精确副本,它调用相同的服务。这使它成为一个远程调用(从我的电脑到服务器)。 而且它毫无例外地工作。不再有 http 绑定,所以连接不可能不安全。

如果我从我的电脑和服务器使用 Chrome 访问“https://ip-address/service.asmx”它表示连接是安全的,并且证书有效且受信任(因为 CA 证书存在于“受信任的根”中)

到目前为止我做了什么:

  1. 服务器上,将证书放入“LocalComputer\Personal”和“LocalComputer\Trusted Root Certification Authorities”中
  2. localhost 证书放入“LocalComputer\Trusted Root Certification Authorities”(它已经存在于“Personal”中)
  3. 确保 CA 证书 在“LocalComputer\Trusted Root Certification Authorities”中
  4. 对于 LocalComputer\Personal 中的 证书 做了:“所有任务 -> 管理私钥 -> 添加 -> IIS_IUSRS -> 完全控制和读取”。 (本地主机证书已经具有该设置)。
  5. 尝试将 url 从“https://ip-address/service.asmx”切换到“https://localhost/service .asmx”和“https://hostname/service.asmx” - 在代码和 Chrome(我的电脑和 服务器)中不起作用,现在连接不安全并且 NET::ERR_CERT_COMMON_NAME_INVALID。

所以问题是: 为什么来自我的本地网站的调用适用于服务(远程调用),但当实际的网站调用相同的服务时失败服务(同一个服务器调用)?

UPD 1:如果我尝试使用启用 SSL 验证的 Postman 调用相同的服务,它会显示:“无法验证第一个证书”。 那么为什么它可以在代码中工作呢?
我可以向公司的 CA 申请另一个证书,但我需要规范。
有人可以详细说明吗?当前的证书同时具有主机名ip地址,并且应该对该网站上的任何服务都有效,不是吗?

【问题讨论】:

  • 您的证书是否也有 127.0.0.1 和 ::1 地址?因为很可能当您通过 Web 调用 self 时,底层 TCP 堆栈只是在 DNS 解析后循环回来。
  • 一般来说,使用 HTTP 与运行在同一个盒子上的东西进行通信是一种奇怪的设计。

标签: c# .net ssl https certificate


【解决方案1】:

这就是我们最终做到的方式:

  1. 在公司局域网内注册了一个 dns 名称;
  2. 为该特定名称颁发了新证书,没有将其绑定到服务器的 IP 地址
  3. 在 IIS 中添加了新的 dns 名称作为主机名并添加了新证书。
  4. 将连接字符串更改为 https://dns-name/service.asmx

它有效!

我最好的猜测是,@zaitsman 关于为什么它不能在服务器本身上工作,但在我的电脑上工作的原因是正确的。

您的证书是否也有 127.0.0.1 和 ::1 地址?因为很可能 > 当您通过 Web 调用 self 时,底层 TCP 堆栈只是在 DNS >解析之后循环回来。

【讨论】:

    猜你喜欢
    • 2016-12-20
    • 2010-10-21
    • 2011-03-28
    • 2016-11-28
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    相关资源
    最近更新 更多