我们很难与从我们的 .Net 应用程序禁用 SSL3 协议(protocol)的远程机器(如 PayPal vb.)建立 https 连接。我们在 HttpWebRequest 实例的 GetResponse 方法上遇到以下异常。
The request was aborted: Could not create SSL/TLS secure channel.
当我们使用 WireShark 深入跟踪网络日志时,我们看到远程机器返回以下错误
TLSv1.2 Alert (Level: Fatal, Description: Handshake Failure) Handshake Failure 40
比较有趣的情况是当我尝试在浏览器中输入PayPal地址时,可以成功打开页面,这意味着可以建立连接, 我们也尝试用OpenSSL命令工具连接,结果再次连接成功。
当我们比较 InternetExplorer 和 .Net 应用程序的 WireShark 日志时,我们可以看到 Internet Explorer 发送的可用密码套件比 .Net 应用程序多, 并且 PayPal 正在选择以下不在 .Net 应用程序请求中的密码。
TLS_RSA_WITH_RC4_128_SHA
以下是从 WireShark 抓取的日志:
ServerMachine:.Net application Client Hello ServerMachine:.Net 应用服务器响应 ServerMachine:InternetExplorer 客户端你好 ServerMachine:InternetExplorer 服务器你好
以下内容是从我们的开发机器上捕获的,该机器运行正常。 DevMachine:.Net application Client Hello DevMachine:.Net 应用服务器你好
我们认为 PayPal 不喜欢我们根据 .Net 应用程序的“Client Hello”请求发送的密码套件。
更有趣的情况是这个问题只发生在我们运行 Windows 2008 R2 的生产机器上,一切都在我们的开发环境中使用 Windows Server 2008 R2 和 Windows 8 pcs。
请给我们一些想法来解决这个问题。
以下是我们连接 PayPal api 的 C# 代码。
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("https://api-3t.sandbox.paypal.com/2.0/");
wr.Method = "POST";
wr.ContentType = "application/x-www-form-urlencoded";
string output = null;
try
{
WebResponse wres = wr.GetResponse();
Stream ress = wres.GetResponseStream();
StreamReader ressr = new StreamReader(ress, Encoding.UTF8);
output = ressr.ReadToEnd();
}
catch (System.Net.WebException webEx)
{
if (webEx.Response != null)
{
WebResponse wres = webEx.Response;
Stream ress = wres.GetResponseStream();
StreamReader ressr = new StreamReader(ress);
output = ressr.ReadToEnd();
}
else
throw webEx;
}
catch (Exception ex)
{
throw ex;
}
最好的问候
最佳答案
What we think that PayPal doesn't like our Cipher Suites that we send on "Client Hello" request from .Net application.
这是正确的。如果你看ssllabs您会看到,api-3t.sandbox.paypal.com 仅支持 RC4-SHA (TLS_RSA_WITH_RC4_128_SHA),它不包含在您的密码集中。
More more interesting situation is this problem only occured on our production machines which are running Windows 2008 R2
您可能已对生产系统添加了一些强化措施并禁用了 RC4-SHA,因为此密码被认为是不安全的。参见 Microsoft Technet对于您可能已经实现的匹配建议。
关于c# - TLS 连接握手失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26802089/