SSL握手超时
本文关键字:超时 SSL | 更新日期: 2023-09-27 18:24:55
我有两个由同一证书颁发机构颁发的客户端身份验证证书。其中一个使我能够连接到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,消息为"操作已超时"。
我在尝试连接失败的证书时使用了System.Net.trace,并且日志显示在"尝试使用用户提供的证书重新启动会话"之前和第一个InitializeSecurityContext之后的连接超时。
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进行连接。
如有任何建议,我们将不胜感激。
感谢Shawn的问题,这个问题帮助我解决了超时问题,因为连接需要60多秒才能失败。
然后我得到了一个"请求被中止:无法创建SSL/TLS安全通道。"错误,通过使用Windows HTTP服务证书配置工具和我在这里获得的信息解决了这个问题。