.net - SSL 失败 - 将 HttpWebRequest 与客户端证书一起使用时收到 SSL/TLS 异常

标签 .net security ssl certificate

我有一个带有 IIS 7 的 Windows 2008 Server,它使用 .NET C# 应用程序向 PayPal 发送请求以处理付款。几个月前,我安装了一个由 Verisign 购买的证书。安装后,我能够运行我的 WebClient 代码以成功创建 SSL 连接,并通过 PayPal NVP API(名称值对)处理付款。

最近,我在 SSL 交易期间收到错误消息。具体报错如下:

无法创建 SSL/TLS 安全通道

我检查了所有我能想到的东西,并在 StackOverflow 和网络上的其他地方阅读了很多文章。

我找到的最好的资源是:

请求被中止:无法创建 SSL/TLS 安全通道

查找本文错误http://support.microsoft.com/kb/915599决议 J。也可能是因为您没有提供客户端证书。这很可能是使用了 TLS 或 SSL3 而服务器不理解它的问题。

http://blogs.msdn.com/b/jpsanders/archive/2009/01/07/you-receive-one-or-more-error-messages-when-you-try-to-make-an-http-request-in-an-application-that-is-built-on-the-net-framework-2-0.aspx

这里是我尝试阅读和实现他们的解决方案的所有其他资源的列表:

我试过的各种链接:

http://support.microsoft.com/kb/901183

Could not create SSL/TLS secure channel - Could the problem be a proxy server?

The request was aborted: Could not create SSL/TLS secure channel

The request was aborted: Could not create SSL/TLS secure channel - Decrypt returned SEC_I_RENEGOTIATE

http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/99d49286-5c3a-4311-a1e3-499f035ce979/

http://blogs.msdn.com/b/jpsanders/archive/2009/01/07/you-receive-one-or-more-error-messages-when-you-try-to-make-an-http-request-in-an-application-that-is-built-on-the-net-framework-2-0.aspx

http://forums.iis.net/t/1156690.aspx

我尝试了以下解决方案:

  1. 重新安装证书,并将其放入各种商店(个人、本地计算机)
  2. 添加了这个 ServiceManager 代码:

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    
  3. 启用日志记录以获得更详细的详细信息

  4. 上述链接中列出的各种其他解决方案

令人沮丧的是,几个月前它运行良好,现在我收到此错误。起初,我以为证书已过期,但看起来没问题。

可能是 Windows Server 的服务包或修补程序创建了破坏 SSL 的新设置或方案。我认为重新安装证书可以解决这个问题。

重要的是要注意,当我重新安装时,我只是将它添加到各个商店(双击证书并安装)。我没有创建“证书请求”。因为它已经安装并绑定(bind)到我的 IIS 应用程序的 SSL 端口,所以应该没问题。

这是创建网络请求的代码:

     public static Hashtable DoWebReq(string strNVP, string strNVPSandboxServer)
    {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

        string _strNVP = strNVP; 

        //Create web request and web response objects, make sure you using the correct server (sandbox/live)
        var wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
        wrWebRequest.Method = "POST"; // POST

        var requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());


        requestWriter.Write(_strNVP);
        requestWriter.Close();

        // Get the response.
        var hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
        var responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());

        //and read the response
        string responseData = responseReader.ReadToEnd();
        responseReader.Close();

        string result = System.Web.HttpContext.Current.Server.UrlDecode(responseData);

        string[] arrResult = result.Split('&');
        Hashtable htResponse = new Hashtable();
        string[] responseItemArray;
        foreach (string responseItem in arrResult)
        {
            responseItemArray = responseItem.Split('=');
            htResponse.Add(responseItemArray[0], responseItemArray[1]);
        }

        return htResponse; 
    }

以下是一组屏幕截图,显示了 SSL 机器的各个组件:

这是 IIS 中的 SSL 绑定(bind)设置: SSL Bindings

以下是已安装证书的概述: certs1

这是我收到的错误: SSL Error

certs2

安装的证书: enter image description here

证书详情 enter image description here

如有任何关于修复此错误的建议,我们将不胜感激。我考虑但 Unresolved 一些可能性是:

  1. 请求是否会花费太长时间?它似乎足够快...但我读到这可能是个问题。
  2. 在 Internet Explorer 中,我确实看到了绿色的“SSL 栏”,它表明该站点已通过安全验证。这告诉我证书安装正确,这是真的吗?
  3. 是否可以通过某种 HTTP 请求执行简单的测试来帮助缩小问题的根源?
  4. 这与 PayPal 有什么关系吗? Paypal 是否有可能因为他们的凭据而拒绝请求?
  5. 会实现 ICertificatePolicy Interface对调试问题有帮助吗?我希望我能解决它。

我认为 SSL 是否有效,它与 PayPal 完全没有关系/依赖性......但我可能错了。

我觉得我应该能够只使用由 WebClient 类构建的名称值对 URL,并通过 IE 通过管道发送它并接收响应。

最佳答案

我认为问题可能不在您的客户端证书中,而在 PayPal 中。

关于你的问题:

In Internet Explorer, I do see the Green "SSL Bar" which shows this site is verified as being secure. This tells me the Cert is installed correctly, is this true?

不是,这意味着PayPal的服务器证书是由您的浏览器验证的,即PayPal的证书是由添加为您的证书颁发机构的人签署的。但是,PayPal 的证书不会添加到您的信任证书中。

我还注意到,PayPal 当前的证书从 2011 年 3 月 23 日起有效。也许在那之前您的应用程序一直在工作,而现在它已更改,应用程序已停止工作。

基于此我建议尝试安装PayPal自己的证书作为服务器证书。

关于.net - SSL 失败 - 将 HttpWebRequest 与客户端证书一起使用时收到 SSL/TLS 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9242724/

相关文章:

c# - 具有复杂类型的数据协定序列化

java - 有没有办法在柑橘框架中关闭 ssl 验证?

加密后的 SSL 缓冲区大小

c# - LINQ to XML 查询同级元素

.net - 为什么.Net Framework和.Net Core中的ComputeSignature会产生不同的结果

mysql - 如果 "function.mysql-connect"出现在我的网站搜索数据中,人们在试图破解什么?

javascript - 使用 eval 使用字符串输入按名称将函数分配给变量有哪些风险?

javascript - Nashorn/jjs 安全 : executing a user's script on server side

asp.net-mvc - ASP.NET MVC 2 和请求客户端证书(智能卡身份验证)

c# - 为什么此代码不产生撕裂读取?