c# - TLS 致命 : Handshake Failure

标签 c# wcf ssl ssl-certificate windows-server-2008-r2

我需要连接外部服务,但客户端身份验证有问题。该服务需要证书、用户名和密码以及请求。

我使用的是 Windows Server 2008 R2。

我已经收到带有证书的 PKCS#7 包并导入:

  • 本地计算机/个人的 SSL 证书(只有公钥)
  • LocalComputer/TrustedRootCertificationAuthorities 的中间 CA 和根 CA

我已经在 Windows 注册中启用了 TLS 1.0、1.1、1.2 客户端: Windows Register

我正在尝试使用 WCF 客户端和 Web 浏览器(IE 和 Chrome)连接到服务器。

WCF 客户端(.NET 4.6.1):

App.config:

<bindings>     
    <wsHttpBinding>
        <binding name="WSHttpBinding_ICalculator" >
            <security mode="Transport">
                <transport clientCredentialType="Certificate" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>
<behaviors>
    <endpointBehaviors>
        <behavior name="endpointCredentialBehavior">
            <clientCredentials>
                <clientCertificate findValue="<thumbprint>"
                           storeLocation="LocalMachine"
                           storeName="My"
                           x509FindType="FindByThumbprint" />
            </clientCredentials>
        </behavior>
    </endpointBehaviors>
</behaviors>

程序.cs:

ServicePointManager.Expect100Continue = true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
           | SecurityProtocolType.Tls11
           | SecurityProtocolType.Tls12;

using (var client = new ServiceClient())
{
    client.ClientCredentials.UserName.UserName = "username";
    client.ClientCredentials.UserName.Password = "pwd";

    client.Open();
    var response = client.DoSth();
}

我得到一个错误:

"Could not establish secure channel for SSL/TLS with authority ...".

Internet Explorer 显示: IE error

Chrome 显示: Chrome error

我还尝试通过 Wireshark 对其进行调试。对我来说,怀疑来自客户端的“证书”消息不包含任何证书(既不使用 WCF 客户端也不使用 Web 浏览器)。是否应在此处添加证书,如果是,可能会导致什么问题?

Wireshark packages

我知道在 stackoverflow 和 Google 上有很多关于 TLS 和身份验证的文章,但我浏览了很多,但没有找到任何关于我做错了什么的信息。

最佳答案

我们最好不要指定 TLS 版本,配置您的代码让操作系统决定。通信中使用的具体TLS版本将由服务器和客户端环境共同决定。
https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls
传输安全模式要求服务端与客户端之间在通信之前建立信任关系。
在我看来,该错误通常表示客户端没有正确安装服务器证书。
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
只有服务器端添加Servicemetadata行为,我们才能访问服务定义(WSDL)。
通常客户端提供足以表明其身份的证书,无需再次提供用户名/密码。就像生成的客户端配置一样,我们只需要提供证书即可。服务具体是怎么调用的,要知道服务器的配置或者WSDL文件。
如果有什么我可以帮忙的,请随时告诉我。

关于c# - TLS 致命 : Handshake Failure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57413155/

相关文章:

c# - 如何将 Windows 身份验证添加到 WCF 应用程序

apache - .htaccess 目录子目录的不同 RewriteRule

全局配置设置的C#线程安全

c# - Blazor 父组件在子组件发生 onclick 事件后意外得到重新初始化

C# 无法从父类访问 Form 的公共(public)成员

wcf - WCF检查邮件

c# - Visual Studio 调试器 : Skip over FaultExceptions being thrown

c# - 使用c#在wpf中的弹出定位

python - 使用 Django 在 Google App Engine 上永久将 http 重定向到 https

ssl - SSL 会导致更多带宽吗?