我在IIS中运行了2个应用程序 - 客户端和服务。服务运行得很好,但客户不是。
他们通过WCF互相交谈,并在证书上传递消息安全性(它不是传输安全性,它只是消息安全性)。两者都使用自签名证书。
但客户最终会收到错误:
System.IdentityModel.Tokens.SecurityTokenValidationException:X.509证书...不在受信任的人员商店中。 X.509证书......连锁建筑失败。使用的证书具有无法验证的信任链。替换证书或更改certificateValidationMode。已处理证书链,但终止于信任提供程序不信任的根证书
我知道如何在服务端禁用证书验证,我做了,但是如何在客户端禁用CA验证?
答案 0 :(得分:11)
如果您要从客户端应用程序向服务器发出请求,请在发出服务请求之前调用以下行以避免进行认证检查。
使用此代码将因自签名证书而绕过SSL验证错误。
System.Net.ServicePointManager.ServerCertificateValidationCallback =
delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
注意:仅用于测试目的,实际应用程序使用有效的SSL证书。
答案 1 :(得分:2)
sudhAnsu63 提供的解决方案应该适合您。
或者,由于您使用Message
安全性,因此可以将其添加到客户端配置文件中:
<serviceCertificate>
<authentication certificateValidationMode="None" />
</serviceCertificate>
答案 2 :(得分:0)
在代码中使用此:
using System.ServiceModel; // (to ChannelFactory)
using System.IdentityModel;
ConfigChannel = new ChannelFactory<xxxxxx>(binding, endPoint);
ConfigChannel.Credentials.UserName.UserName = _userName;
ConfigChannel.Credentials.UserName.Password = _password;
ConfigChannel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
答案 3 :(得分:-1)
如果您在&#34;受信任的根证书颁发机构&#34;中调整自签名证书,则可以避免证书错误。