【问题标题】:WCF Communication through SSL : Issue with WCF access due to Third-party Trusted Root Certification Authorities通过 SSL 进行 WCF 通信:由于第三方受信任的根证书颁发机构导致的 WCF 访问问题
【发布时间】:2014-05-11 11:52:36
【问题描述】:

我有一个 WCF 服务,它使用具有传输安全性的证书身份验证。该服务部署在windows服务中,使用wshttp绑定。

当我尝试在调试模式下访问服务或在本地机器上部署为服务后,我总是收到错误“HTTP 请求被禁止使用客户端身份验证方案匿名”

头疼了一个星期后,我偶然发现了这篇来自 Microsoft 的知识库文章

http://support.microsoft.com/kb/2801679

KB 931125 软件包安装了 330 多个第三方根证书颁发机构。目前,Schannel 安全包支持的受信任证书颁发机构列表的最大大小为 16 KB。拥有大量第三方根证书颁发机构将超过 16k 限制,您将遇到 TLS/SSL 通信问题。

我尝试了他们删除第三方信任机构的解决方案,发现我什至无法浏览 Google 或任何支持 https 的网站。

但解决方案有效,我能够调用我的 WCF 服务。

现在我已经从知识库链接http://support.microsoft.com/kb/931125 恢复了第三方受信任的权限,因为我无法访问许多站点,并且 vpn、电子邮件无法正常工作。

还原后,我再次无法访问我的 WCF 服务。

解决此问题的最佳方法是什么?

我现在得到了解决方案,需要执行以下操作

来源http://windowssecrets.com/forums/showthread.php/156768-KB-931125-being-installed-with-no-easy-removal

【问题讨论】:

    标签: .net wcf security ssl


    【解决方案1】:

    解决这个问题的最佳方法是什么?

    在 .Net 中,我们可以使用一个 CA 而不是整个商店的 330+ 个 CA。 Juval Lowy 的Programming WCF Services 在第 570 页左右讨论了使用服务器的证书。Lowy 讨论了验证以及 IEndpointBehavior 和 X509ServiceCertificateAuthentication。

    但是,我无法判断 WCF 是否具有 SslStream 和 ServicePointManager 中的 RemoteCertificateValidationCallback?如果可用,请使用您需要的一个 CA 并从文件系统加载它:

    static bool VerifyServerCertificate(object sender, X509Certificate certificate,
        X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        try
        {
            String CA_FILE = "ca-cert.der";
            X509Certificate2 ca = new X509Certificate2(CA_FILE);
    
            X509Chain chain2 = new X509Chain();
            chain2.ChainPolicy.ExtraStore.Add(ca);
    
            // Check all properties
            chain2.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
    
            // This setup does not have revocation information
            chain2.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
    
            // Build the chain
            chain2.Build(new X509Certificate2(certificate));
    
            // Are there any failures from building the chain?
            if (chain2.ChainStatus.Length == 0)
                return true;
    
            // If there is a status, verify the status is NoError
            bool result = chain2.ChainStatus[0].Status == X509ChainStatusFlags.NoError;
            Debug.Assert(result == true);
    
            return result;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    
        return false;
    }
    

    我没有弄清楚如何默认使用这个链(上面的chain2),这样就不需要回调了。也就是说,将它安装在 ssl 套接字上,连接将“正常工作”。而且我没有弄清楚如何安装它以便将其传递到回调中。也就是说,我必须为回调的每次调用构建链。我认为这些是 .Net 中的架构缺陷,但我可能遗漏了一些明显的东西。

    类似的答案出现在像Verify Remote Server X509Certificate using CA Certificate File 这样的几个问题中。

    【讨论】:

    • 我遇到的问题是客户端无法进行握手,因此无法将证书发送给呼叫。我的代码中已经有这个用于测试 System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { return true; };
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 2018-06-13
    • 2018-04-20
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多