SSL握手超时

时间:2012-02-15 16:41:22

标签: c# ssl certificate

我有2个由同一证书颁发机构颁发的客户端身份验证证书。其中一个使我能够连接到HTTPS Web服务,但是当我使用类似于以下内容的代码时,另一个不能:

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create( endPointUrl );
X509Store store = new X509Store( StoreName.My, StoreLocation.LocalMachine );
store.Open( OpenFlags.MaxAllowed );
X509CertificateCollection col = (X509CertificateCollection)store.Certificates.Find( X509FindType.FindBySerialNumber, certificateSerialNumber, true );
httpWebRequest.ClientCertificates.Add( col[0] );
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
httpWebRequest.KeepAlive = false;
httpWebRequest.Timeout = 3000;
httpWebRequest.ContentLength = message.Length;
httpRequestStream = httpWebRequest.GetRequestStream();

当尝试获取请求流时,我收到InvalidOperationException,并显示消息“操作已超时”。

我尝试连接失败的证书并且日志在“尝试使用用户提供的证书重新启动会话之前”和第一个InitializeSecurityContext之后显示连接超时时使用了System.Net.trace。 / p>

Wireshark显示以下内容:

"TCP","j-link > https [SYN] Seq=0 Win=65535 Len=0 MSS=1260 SACK_PERM=1"
"TCP","https > j-link [SYN, ACK] Seq=0 Ack=1 Win=32768 Len=0 MSS=1380"
"TCP","j-link > https [ACK] Seq=1 Ack=1 Win=65535 Len=0"
"TLSv1","Client Hello"
"TLSv1","Server Hello"
"TCP","[TCP segment of a reassembled PDU]"
"TCP","j-link > https [ACK] Seq=78 Ack=2521 Win=65535 Len=0"
"TLSv1","Certificate, Certificate Request, Server Hello Done"
"TCP","j-link > https [ACK] Seq=78 Ack=3187 Win=64869 Len=0"
"TCP","j-link > https [FIN, ACK] Seq=78 Ack=3187 Win=64869 Len=0"
"TCP","https > j-link [ACK] Seq=3187 Ack=79 Win=32768 Len=0"
"TLSv1","Alert (Level: Warning, Description: Close Notify)"
"TCP","j-link > https [RST, ACK] Seq=79 Ack=3194 Win=0 Len=0"

我可以在导出它们并将它们转换为PEM格式后,使用两个证书从命令行使用OpenSSL进行连接。

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:1)

感谢Shawn's question帮助我解决了超时问题,这是因为连接失败超过60秒。

然后我得到了“请求被中止:无法创建SSL / TLS安全通道。”错误,这是通过使用Windows HTTP Services Certificate Configuration Tool和我获得的信息here解决的。