我有一个Visual Basic客户端程序获取"请求被中止:无法创建SSL / TLS安全通道。"在GetRequestStream
的实例上执行HttpWebRequest
时出现异常。当服务器允许的协议是" SSLProtocol all -SSLv2 -SSLv3"并且客户端程序没有设置ServicePointManager.SecurityProtocol
属性
服务器已更改为允许" SSLProtocol + TLSv1.2 -TLSv1.1 -TLSv1 -SSLv2 -SSLv3"。最初该程序没有设置ServicePointManager.SecurityProtocol
。服务器更改后我得到了上述异常,所以我添加了
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
但仍然得到上述例外。
使用VB.NET,VS2013以及我看到的4.5框架是TLS 1.2所必需的。
异常状态为
SecureChannelFailure {10}
System.Net.WebExceptionStatus
我看到一篇关于日志记录并打开详细跟踪的帖子,我可以看到与证书的握手。下面是它失败的迹线的尾部:
System.Net信息:0:[6792] SecureChannel#54616604 - 证书的类型为X509Certificate2,包含私钥。
System.Net Information:0:[6792] AcquireCredentialsHandle(package = Microsoft统一安全协议提供程序,intent = Outbound,scc = System.Net.SecureCredential)
System.Net信息:0:[6792] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY,context = 1bb58fc0:1cff780,targetName = paygate-dev1.eaglesoa.com,inFlags = ReplayDetect,SequenceDetect,Confidentiality,AllocateMemory, InitManualCredValidation)
System.Net信息:0:[6792] InitializeSecurityContext(In-Buffers count = 2,Out-Buffer length = 173, 返回代码= ContinueNeeded)。
System.Net信息:0:[6792] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY,context = 1bb58fc0:1cff780, targetName = paygate-dev1.eaglesoa.com,inFlags = ReplayDetect, SequenceDetect,Confidentiality,AllocateMemory, InitManualCredValidation)
System.Net信息:0:[6792] InitializeSecurityContext(In-Buffers count = 2,Out-Buffer length = 0, 返回代码= IllegalMessage)。
System.Net错误:0:[6792] HttpWebRequest中的异常#63403007 :: - 请求已中止:无法创建SSL / TLS安全通道..
System.Net错误:0:[6792] HttpWebRequest中的异常#63403007 :: EndGetRequestStream - 请求是 已中止:无法创建SSL / TLS安全通道..
以下是客户端程序的一小部分:我还尝试使用SecurityProtocol
列表中的tls和ssl3,Expect100Continue
True
和False
(在其他地方看到此内容)帖子),AutoRedirect
True
和False
。在loWebRequest.GetRequestStream()
显示的最后一个语句上发生异常。当它工作时,使用相同的证书。如果服务器将其允许的协议更改回原始值(参见上文),则可以正常工作。我还将证书添加到证书库。关于我需要在客户端做什么的任何想法?
Dim loDataToSend As System.IO.Stream
Dim loWebRequest As HttpWebRequest
ServicePointManager.SecurityProtocol = SecurityProtocolType.tls or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
ServicePointManager.Expect100Continue = True
loWebRequest = DirectCast(HttpWebRequest.Create(lsSystemURL), HttpWebRequest)
With loWebRequest
.Method = "POST"
.ClientCertificates = lcCertificates
.Credentials = CredentialCache.DefaultCredentials
.UseDefaultCredentials = False
.ContentLength = lsRequest.Length
.KeepAlive = False
.AllowAutoRedirect = True
.Timeout = 100000
End With
loDataToSend = loWebRequest.GetRequestStream()