Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The SSL connection could not be established

I am using a third party library (Splunk c# SDK ) in my ASP.NET core application. I am trying to connect to my localhost Splunk service via this SDK, but I get an exception saying:

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

And The inner exception says:

The remote certificate is invalid according to the validation procedure.

This SDK uses HTTP client under the hood, but I don't have access to this object to configure HttpClientHandler.

All my search on google ends up using ServicePointManager to bypass the SSL validation, but this solution doesn't work in Asp.Net core.

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; 

Is there any way to bypass this validation in asp.Net core?

like image 780
MVafa Avatar asked Oct 22 '18 23:10

MVafa


People also ask

What does it mean can't connect to SSL?

This error is caused by an issue with the website's SSL certificate – it's missing, or it's expired, or it wasn't issued by a legitimate certificate authority, or the client can't access it for some other reason. SSL certificates are necessary for serving websites over secure HTTPS connections.

What causes an SSL error?

An SSL certificate error occurs when the browser cannot verify the SSL certificates returned by the server. When the error happens, the browser blocks the website and warns the user that the website cannot be trusted as shown below. These warnings will negatively impact the user's trust in your website.


2 Answers

Yes, you can Bypass the certificate using below code...

HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };  // Pass the handler to httpclient(from you are calling api) HttpClient client = new HttpClient(clientHandler); 
like image 92
Rohit Jangid Avatar answered Oct 11 '22 17:10

Rohit Jangid


As I worked with the identity server (.net core) and a web api (.net core) on my developer machine, I realized, that I need to trust the ssl certification of localhost. That command does the job for me:

dotnet dev-certs https --trust 
like image 23
Daniel Michelfelder Avatar answered Oct 11 '22 19:10

Daniel Michelfelder