我发现当我使用HttpWebRequest来建立SSL\TLS连接时,调用时需要近30秒的时间
request.GetRequestStream()
当我启用了带有堆栈跟踪的跟踪功能时,我发现寻找代理需要2秒钟的时间,因此我在app.config中禁用了它:
<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>
下一个点在大约28秒内到达
at System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]& thumbPrint)
在检查方法体之后,我发现调用了X509Chain.Build()方法,并且建立证书链花费了将近25秒。
有趣的是,当您构造新的HttpWebReqest并再次尝试(无需重新启动应用程序),执行请求只需要几毫秒。
有人能提供建议吗?缓存请求不是一个选项,必须从应用程序运行时开始就很快。
更新:
我发现在X509Chain.BuildChain()中需要30秒的调用是:
if (!CAPISafe.CertGetCertificateChain(hChainEngine, pCertContext, ref pTime, invalidHandle, ref cert_chain_para, dwFlags, IntPtr.Zero, ref ppChainContext))
CAPISafe中声明的方法如下:
[DllImport("crypt32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern bool CertGetCertificateChain([In] IntPtr hChainEngine, [In] SafeCertContextHandle pCertContext, [In] ref System.Runtime.InteropServices.ComTypes.FILETIME pTime, [In] SafeCertStoreHandle hAdditionalStore, [In] ref CAPIBase.CERT_CHAIN_PARA pChainPara, [In] uint dwFlags, [In] IntPtr pvReserved, [In, Out] ref SafeCertChainHandle ppChainContext);
所以,这是加密API函数CertGetCertificateChain。仍然不知道下一步该怎么做...
更新:
我尝试禁用CRL和OCSP检查,但仍然没有效果:
Add to App.config
<runtime> <generatePublisherEvidence enabled="false"/> </runtime>
Machine-wide: Control Panel -> Internet Options -> Advanced -> Under security, uncheck the Check for publisher's certificate revocation option
In registry:
[HKEY_USERS\S-1-5-20\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing] "State"=dword:00023e00