【问题标题】:intermittent error could not establish secure channel for ssl/tls间歇性错误无法为 ssl/tls 建立安全通道
【发布时间】:2020-03-06 10:45:46
【问题描述】:

我的 WPF(桌面)应用程序正在调用两种类型的服务 - 一种 WCF 服务托管在我们的内部环境中,另一种是第 3 方 Web 服务。

我的应用程序正在使用 .Net framework 4.0。由于最近在组织上应用了一些 Windows 更新,我的第 3 方网络服务停止工作,我开始收到此错误

"System.ServiceModel.Security.SecurityNegotiationException: Could not establish secure channel for SSL/TLS with authority 'abc.net'. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. "

为了解决我在调用 3rd 方网络服务之前添加了这一行。

  ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; 

而且,它开始完美运行。但是,它影响了我内部托管的 WCF 服务。我的 WCF 服务开始出现同样的错误。奇怪的是,我每次都没有得到错误,它突然发生,当我们重新启动应用程序时,WCF 服务调用再次开始正常工作。

错误:

"System.ServiceModel.Security.SecurityNegotiationException: Could not establish secure channel for SSL/TLS with authority 'abc.net'. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel."

一些 WCF 服务配置细节:

 <bindings>
      <wsHttpBinding>
        <binding maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
----
 <serviceBehaviors>
        <behavior name="WcfServerSyncService.LocalDataCacheSyncServiceBehavior">
          <serviceMetadata httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WcfServerSyncService.CustomValidator,WcfServerSyncService" />
          </serviceCredentials>
        </behavior>

 <serviceBehaviors>

而且,只有特定的一组用户会收到此错误,而不是全部。但是,对于这些用户来说,这有时会起作用,有时不会。

有什么建议吗?

【问题讨论】:

    标签: wcf wcf-security


    【解决方案1】:

    TLS1.2需要操作系统和SDK的支持,所以建议你安装DotNet框架,目标是高版本的DotNet Runtime。
    https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls
    基于传输层安全的最佳实践,我们在调用受 SSL 证书保护的 WCF 服务时最好不要指定TLSversion。操作系统将决定 TLS 版本。

    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls13 | System.Net.SecurityProtocolType.Tls;
    

    另外,托管在 WPF 中的 WCF 服务器端不会产生通信错误,该错误只发生在客户端。唯一的错误可能是运行 WPF 的帐户没有访问证书的权限。传输层安全需要将证书绑定到用于发布服务的服务端口。
    最后,由于 WCF 服务器通过自定义验证对客户端进行身份验证,这不可避免地会导致某些错误。
    如果有什么可以帮助的,请随时告诉我。

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 2023-03-14
      • 1970-01-01
      • 2020-08-05
      • 2018-04-06
      • 1970-01-01
      • 2011-04-28
      • 2012-03-12
      • 2017-05-25
      相关资源
      最近更新 更多