c# - SslStream.AuthenticateAsClient() 使用未缓存的 CRL 非常慢

标签 c# .net-3.5 ssl

我连接的服务器最近更改了它的 SSL 证书。自更改以来,在下载证书吊销列表时,SSL 身份验证需要超过 10 秒的时间才能完成。

我正在使用 RemoteCertificateChainCallback 来验证证书,但是在调用回调之前发生了延迟,因此不是证书链的构建或那里的任何其他操作导致了延迟

只有当 CRL 未缓存时才会出现此问题,即我需要删除 CRL 缓存(Documents&settings/[user]AppData/Microsoft/CertificateUrlCache 或类似内容)以多次重现它在一天内。

如果我在 AuthenticateAsClient() 调用中禁用 CRL 检查,身份验证会很快。

使用网络嗅探器,我可以看到最终请求 CRL 时,它几乎是瞬间下载,因此延迟不是网络延迟(至少不是 CRL 服务器)。

我在网络嗅探器中看到的一件奇怪的事情是,在从服务器检索初始 SSL 证书之后,有五秒钟的延迟,直到下载 CRL。**

有没有人对这个阶段可能发生的事情有任何建议,延迟可能是由什么引起的?

谢谢!

更新:好的,我已经使用反射器和内存分析器进行了深入研究。验证为客户端。看起来大部分时间都花在构建证书链上,即:

if (!CAPISafe.CertGetCertificateChain(hChainEngine, pCertContext, ref pTime, invalidHandle, ref cert_chain_para, dwFlags, IntPtr.Zero, ref ppChainContext))

如果我不请求 CRL 验证,那么这几乎会立即返回,启用 CRL 检查,大约 4 秒。

我怀疑如果我手动尝试在我的 RemoteCertificateValidationCallback 中构建链,我会看到相同的延迟。

如果缓存了 CRL,这就不是真正的问题,但似乎这种缓存不适用于 Windows7 用户。 为什么?好吧,我想这是下一个任务......

谁能解释一下是什么导致链构建花费这么长时间?

最佳答案

看来这个问题的答案是:

https://blogs.msdn.microsoft.com/alejacma/2011/09/27/big-delay-when-calling-sslstream-authenticateasclient/

Digging a bit further to understand why CertGetCertificateChain took so long, I saw that we were trying to download the following file from the Internet:

http://www.download.windowsupdate.com/msdownload/update/v3/static/trustedr/en/authrootstl.cab

Why were we downloading this file? Well, this will happen by default on Windows when we build the chain of a cert which root CA cert is not installed in the system. This is called the Automatic Root Certificates Update feature, and it is available on Windows XP/Server 2003 and later OS versions, including Windows 7/Server 2008 R2.

关于c# - SslStream.AuthenticateAsClient() 使用未缓存的 CRL 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7907874/

相关文章:

c# - 使用 (LINQ/Predicate) 将 DataTable 的所有列名放入字符串数组

C# 3 个新功能帖子(与 .Net 3.5 功能无关)

java - 访问被拒绝 ("javax.net.ssl.SSLPermission" "setDefaultSSLContext")

ajax - 通过 ssl 的 phonegap ajax 请求错误

iis - 如何在 IIS 中将 SSL 证书续订多年?

c# - 如何从 blob 容器中删除文件?

c# - 尝试按原样编译 Microsoft 提供的 .NET 源代码,出现数百个错误

c# - 将包含数组的 JSON 数据发布到 Controller 操作

c# - 元组数组不起作用

c# - 严肃的高性能服务器的 Tcp 可靠性与 Udp 负担