gpt4 book ai didi

.net - 通过 SSL : Issue with WCF access due to Third-party Trusted Root Certification Authorities 的 WCF 通信

转载 作者:太空宇宙 更新时间:2023-11-03 13:41:02 25 4
gpt4 key购买 nike

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

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

在折腾了一个星期之后,我偶然发现了这篇来自微软的知识库文章

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

KB 931125 Package installed more than 330 Third-party Root Certication Authorities. Currently, the maximum size of the trusted certificate authorities list that the Schannel security package supports is 16 kilobytes (KB). Having a large amount of Third-party Root Certication Authorities will go over the 16k limit, and you will experience TLS/SSL communication problems.

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

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

现在我已经从 KB 链接 http://support.microsoft.com/kb/931125 恢复了第三方可信机构因为我不能访问很多网站,而且 vpn,电子邮件不起作用。

恢复后,我再次无法访问我的 WCF 服务。

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

我现在得到了解决方案,需要做以下事情

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

最佳答案

What is the best way to resolve this?

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

但是,我无法判断 WCF 是否具有 SslStreamServicePointManager 中的 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 .

关于.net - 通过 SSL : Issue with WCF access due to Third-party Trusted Root Certification Authorities 的 WCF 通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22773480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com