我遇到 SslStream.AuthenticateAsClient 需要“长时间”(~15 秒)的问题。这是一个已知问题,在此 MSDN blog post 中进行了解释.
它给出了两种可能的解决方案
Summing up, this behavior is by design. Options we have are: 1) Install the root CA cert locally so we don’t need to go to the Internet for the list of trusted root CA certs. 2) Disable the Automatic Root Certificates Update feature via GPO so we don’t go to the Internet in any case.
有人告诉我,从安全角度来看,选项 2 不是一个好主意,所以我需要执行选项 1。
问题是我不知道如何获得根 CA 证书。获得它后,我可能会弄清楚如何使用 certutil 来安装它。
我可以在这个函数中中断我的执行
private static bool CertificateValidationCallback(
object oSender,
X509Certificate oCertificate,
X509Chain oChain,
SslPolicyErrors oSslPolicyErrors)
{
}
所以我想我的问题是:
如何获得根 CA 证书? 我需要什么信息才能得到它? 我从哪里获得这些信息?
最佳答案
X509 标准的权限信息访问扩展包含根 CA 证书的位置信息 (URL),但它是一个可选字段。
https://www.rfc-editor.org/rfc/rfc5280#section-4.2.2.1
var cert = new X509Certificate2(certData);
var authInfoExtnsions = from ext in cert.Extensions.Cast<X509Extension>()
where ext.Oid.Value == "1.3.6.1.5.5.7.1.1"
select ext;
foreach (var authInfoExtnsion in authInfoExtnsions)
{
Console.WriteLine(Encoding.UTF8.GetString(authInfoExtnsion.RawData));
}
authInfoExtnsion.RawData
是一个复杂的 ASN.1 结构(您可以在 X509 标准中找到详细信息)并且此代码不会为您提供根 CA 证书的 URL。您需要解析并获取 URL。正如我所说,权限信息访问是一个可选扩展,但如果它存在,您会注意到可以在控制台中读取 Root Ca Certficate 的 URL。
关于c# - 如何获取和安装根 CA 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14403002/