我需要连接外部服务,并且客户端身份验证存在问题。该服务需要证书,用户名和密码以及请求。
我正在使用Windows Server 2008 R2。
我已经收到带有证书的PKCS#7软件包并导入:
我已在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和身份验证的文章,但是我经历了很多文章,却没有找到关于我做错事情的任何信息。
答案 0 :(得分:0)
我们最好不要指定TLS版本,而是配置代码以让操作系统决定。通信中使用的特定TLS版本将由服务器和客户端环境共同决定。
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls
传输安全模式要求在通信之前建立服务器与客户端之间的信任关系。
我认为该错误通常表示客户端未正确安装服务器证书。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
只有服务器端添加Servicemetadata行为,我们才能访问服务定义(WSDL)。
通常,客户端提供足以证明其身份的证书,而无需再次提供用户名/密码。就像生成的客户端配置一样,我们只需要提供一个证书即可。如何专门调用服务,我们必须知道服务器或WSDL文件的配置。
随时让我知道是否有什么可以帮助您的。