2015-04-01 107 views
3

我有2个应用程序在IIS内运行 - 客户端和服务。服务运行得很好,但客户端不是。在wcf的客户端禁用认证验证

他们通过WCF与消息安全中继证书(它不是传输安全性,它只是消息安全性)通信。两者都使用自签名证书。

但客户最终错误:

System.IdentityModel.Tokens.SecurityTokenValidationException: The X.509 certificate ... is not in the trusted people store. The X.509 certificate ... chain building failed. The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider

我知道如何在服务端禁用证书验证,我做到了,但我怎么能在客户端禁用CA验证?

回答

8

如果您从客户端应用程序向服务器发送请求,请在执行服务请求之前调用以下行以避免进行认证检查。

使用此代码将绕过由于自签名证书导致的SSL验证错误。

System.Net.ServicePointManager.ServerCertificateValidationCallback = 
       delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
       { return true; }; 

Note: Use this for testing purpose only, for actual application use a valid SSL certificate.

+1

这无疑是解决问题的引用最普遍的做法。虽然我对自签名证书被称为无效有轻微的不满。自签名证书仍然具有相同的功能。问题在于自然界的自签名证书不可信,因为它们未能通过签名层次结构检查,但它们当然是有效的 - 根据应用程序的上下文,证书固定可能是一个合适的选择,整个信任链可能会在提供CA签名证书的相同核心功能时被绕过。 – 2015-04-02 02:39:30

2

通过sudhAnsu63提出应该为你工作的解决方案。如果您步伐,“受信任的根证书颁发机构”自签名证书

<serviceCertificate> 
    <authentication certificateValidationMode="None" /> 
</serviceCertificate> 
+1

重要的是要注意,这只适用于使用消息安全性而不使用SSL的情况。 http://webservices20.blogspot.com/2008/12/wcf-gotcha-disabling-ssl-validation.html – Boric 2015-07-24 18:27:29

+0

这已经在答案中注明。 “或者,因为您正在使用'Message'安全性...”。对不起,这不是你的解决方案。 ** sudhAnsu63 **提供的其他解决方案是否有效? – 2015-07-24 18:34:24

+0

是的,另一个解决方案工作。 – Boric 2015-07-24 18:43:50

-1

,就可以避免证书错误:

另外,由于使用的是Message安全性,你可以添加给客户配置文件。

+0

这个问题似乎表明,OP没有能力指示用户调整他们的计算机那样。因此,我不认为这是一个正确的答案。此外,如果您有问题,请在此单独提出:http://stackoverflow.com/questions/ask,而不是回答另一个问题。 – KHeaney 2015-04-02 17:17:12

+0

这实际上似乎并不适用于我,即使当我尝试这样做时 – 2017-05-06 05:11:39

-1

在代码中使用这样的:

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; 
+0

表面上不起作用 – user1034912 2018-01-25 06:52:12