Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL Failures - Receiving SSL/TLS exception when using HttpWebRequest with client certificate

I have a Windows 2008 Server with IIS 7 which using a .NET C# Application to send requests to PayPal to process payments. A few months ago I installed a Certificate which was purchased by Verisign. After installation, I was able to run my WebClient code to create SSL Connections successfully, and process payments via the PayPal NVP API (Name Value Pair).

Recently, I have been receiving an error during SSL Transaction. The specific error is as follows:

Could not create SSL/TLS secure channel

I've checked everything I could think of, and read many articles on StackOverflow and other places on the net.

The best resource I found was this:

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

Lookup the error in this article http://support.microsoft.com/kb/915599 Resolution J. It also may be that you are not supplying a client certificate. Most likely this is an issue with TLS or SSL3 being used and the server not understanding it.

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

And here is a list of all the other resources I've tried reading and implimenting their solutions:

Various Links I've Tried:

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

I have tried the following solutions:

  1. Reinstall the certificate, and placed it into various stores (Personal, LocalComputer)
  2. Added this ServiceManager code:

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    
  3. Enabled logging to gain more verbose details

  4. Various other solutions listed in the above links

What is so frustrating is that this was working fine a few months ago, and now I receive this error. At first, I thought the cert expired, but it appears to be fine.

It could be a Service Pack or Hotfix for Windows Server has created a new setting or scenario which breaks SSL. I figured that re-installing the cert would solve that.

It is important to note that when I reinstalled, I simply added it to the various stores (Double Click the cert and install). I did not create a "Certificate Request". Since its already installed and bound to the SSL Port of my IIS Application, it should be ok.

This is the code that creates the web request:

     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; 
    }

Here are a collection of screen shots to show the various components of the SSL Machine:

This is the SSL Binding Settings in IIS: SSL Bindings

Here is an overview of the installed Certs: certs1

This is the Error I receive: SSL Error

certs2

Certs Installed: enter image description here

Certificate Details enter image description here

Any advice on fixing this error would be most appreciated. Some possibilities I've considered but not addressed are:

  1. Could the request be taking too long? It seems fast enough... but I've read this could be a problem.
  2. 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?
  3. Is there a simple test I can perform with a HTTP request of some kind to help narrow down the source of the problem?
  4. Could this have anything to do with PayPal? Is it possible paypal is rejecting the request due to credentials on their end?
  5. Would implementing an ICertificatePolicy Interface be of any help in debugging the issue? I'm hoping I can just fix it.

I would think that either the SSL would work or not, it has no bearing/dependency on PayPal at all... but I could be wrong.

I feel like I should be able to just use the Name Value Pair URL which is built by the WebClient class, and send that over the pipe via IE and receive a response.

like image 346
Shawn J. Molloy Avatar asked Feb 11 '12 18:02

Shawn J. Molloy


1 Answers

I think there is a chance that the problem is not in your client certificate, but in the one of PayPal.

On your question:

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?

No, this means that the server certificate of PayPal is verified by your browser, i.e. the PayPal's certificate is signed by someone added as you certification authority. However, the PayPal's certificate is not added to your trusted certificates.

I noticed also, that PayPal's current certificate has validity from 23.3.2011. Maybe until then your application was working, and now that it was changed the application has stopped working.

Based on this I recommend trying to install PayPal's own certificate as a server certificate.

like image 124
nettle Avatar answered Sep 19 '22 12:09

nettle