2015-04-01 108 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