【发布时间】:2019-12-16 04:44:58
【问题描述】:
我需要连接外部服务,但客户端身份验证有问题。该服务在请求时需要证书、用户名和密码。
我使用的是 Windows Server 2008 R2。
我已收到带有证书的 PKCS#7 包并已导入:
- 本地计算机/个人的 SSL 证书(只有公钥)
- LocalComputer/TrustedRootCertificationAuthorities 的中间 CA 和根 CA
我已在 Windows Register 中启用了 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>
Program.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();
}
我得到一个错误:
“无法为具有权限的 SSL/TLS 建立安全通道......”。
Internet Explorer 显示: IE error
Chrome 显示: Chrome error
我也尝试通过 Wireshark 对其进行调试。对我来说,怀疑来自客户端的“证书”消息不包含任何证书(既不使用 WCF 客户端也不使用 Web 浏览器)。是否应该在此处添加证书,如果是,可能会导致什么问题?
我知道在 stackoverflow 和 Google 上有很多关于 TLS 和身份验证的文章,但是我浏览了很多,但没有找到任何关于我做错了什么的信息。
【问题讨论】:
-
您确定
ServiceClient使用的是配置文件中的设置吗?从 .Net 4.5 开始,WCF 非常擅长假装一切正常,但很高兴地忽略了您的配置设置。启用 WCF 跟踪和日志记录以查看是否加载了任何配置。请使用详细日志记录。 -
@rene 我能够检查客户端的对象,我看到它包含从配置文件加载的信息,因此绑定和 clientCredentials。我想知道为什么网络浏览器无法访问服务或 ?wsdl 信息。
标签: c# wcf ssl ssl-certificate windows-server-2008-r2