Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My customer has informed my of issues with their SSL and Internet Explorer. They said they get trust issues when accessing the URL.

I am accessing JSON through HTTPS. The website sits on one server and I am using the console app on my local machine. I am trying to bypass the SSL Cert, however, my code still fails.

Can I alter HttpWebRequest to fix this problem?

I get this error using this code:

    // You must change the URL to point to your Web server.         HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);         req.Method = "GET";         req.AllowAutoRedirect = true;          // allows for validation of SSL conversations         ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };           WebResponse respon = req.GetResponse();         Stream res = respon.GetResponseStream();          string ret = "";         byte[] buffer = new byte[1048];         int read = 0;         while ((read = res.Read(buffer, 0, buffer.Length)) > 0)         {             //Console.Write(Encoding.ASCII.GetString(buffer, 0, read));             ret += Encoding.ASCII.GetString(buffer, 0, read);         }         return ret; 
like image 616
Joseph Anderson Avatar asked May 30 '12 18:05

Joseph Anderson


People also ask

Why the request was aborted could not create SSL TLS secure channel?

The error “The request was aborted: Could not create SSL/TLS secure channel.” can happen during any download HTTP request. This error generally will correspond to firewalls, proxies or DNS filtering blocking the connection or an SSL/TLS cipher misconfiguration.

Can't create SSL TLS secure channel IIS?

However, the "Could not create SSL/TLS secure channel" error usually means that there's something wrong with the server certificate, e.g. the certificate is for a different hostname, or otherwise invalid, or not trusted etc.

What is an SSL TLS secure channel?

TLDR: SSL/TLS encrypts communications between a client and server, primarily web browsers and web sites/applications. SSL (Secure Sockets Layer) encryption, and its more modern and secure replacement, TLS (Transport Layer Security) encryption, protect data sent over the internet or a computer network.


2 Answers

I had to enable other security protocol versions to resolve the issue:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls         | SecurityProtocolType.Tls11         | SecurityProtocolType.Tls12         | SecurityProtocolType.Ssl3; 
like image 86
glm Avatar answered Sep 23 '22 13:09

glm


I enabled logging using this code:

http://blogs.msdn.com/b/dgorti/archive/2005/09/18/471003.aspx

The log was in the bin/debug folder (I was in Debug mode for my console app). You need to add the security protocol type as SSL 3

I received an algorithm mismatch in the log. Here is my new code:

        // You must change the URL to point to your Web server.         HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);         req.Method = "GET";         ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;           // Skip validation of SSL/TLS certificate         ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };           WebResponse respon = req.GetResponse();         Stream res = respon.GetResponseStream();          string ret = "";         byte[] buffer = new byte[1048];         int read = 0;         while ((read = res.Read(buffer, 0, buffer.Length)) > 0)         {             Console.Write(Encoding.ASCII.GetString(buffer, 0, read));             ret += Encoding.ASCII.GetString(buffer, 0, read);         }         return ret; 
like image 31
Joseph Anderson Avatar answered Sep 25 '22 13:09

Joseph Anderson