【问题标题】:Random "The remote certificate is invalid according to the validation procedure." Exceptions随机“根据验证程序,远程证书无效。”例外
【发布时间】:2014-12-08 19:56:25
【问题描述】:

我们有一个网络应用程序,它偶尔会向第三方网络服务发出 HTTPS 请求。大多数时候,这些工作没有问题。然而,有时应用程序会开始对每个请求抛出异常:

System.Net.WebException: The underlying connection was closed: Could not establish
                         trust relationship for the SSL/TLS secure channel. --->
System.Security.Authentication.AuthenticationException: The remote certificate is
                         invalid according to the validation procedure.
  at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
  at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
  ...etc...

现在奇怪的是,当我们回收 Web 应用程序时,异常停止被抛出。反正有一段时间了。

【问题讨论】:

    标签: asp.net iis ssl


    【解决方案1】:

    我们确定某个库偶尔会将 System.Net.ServicePointManager.ServerCertificateValidationCallback 设置为未正确验证证书的方法。看起来随机的原因是证书验证在使用库并设置回调之前一直有效。

    解决方案是修复库。作为一般规则,永远不要在生产代码中全局设置ServerCertificateValidationCallback

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-28
      • 2016-11-28
      • 2013-08-08
      • 2012-07-20
      • 2015-03-17
      • 2021-05-30
      相关资源
      最近更新 更多