RestSharp: Could not create ssl/tls secure channel
Expected Behavior
Successful response from server with the collection of data expected without the need of adding any certificate
Actual Behavior
error message: Could not create ssl/tls secure channel
Steps to Reproduce the Problem
- Execute the following code
var client = new RestClient("https://url/api");
var credential = new HawkCredential
{
Id = "id",
Algorithm = "sha256",
Key = "key"
};
client.Authenticator = new HawkNetAuthenticator(credential);
var request = new RestRequest("endpointapi/", Method.GET);
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
IRestResponse response = client.Execute(request);
Also created the following class to do the custom Hawk Auth
public class HawkNetAuthenticator : IAuthenticator
{
private readonly HawkCredential _credential;
public HawkNetAuthenticator(HawkCredential credential)
{
_credential = credential;
}
public void Authenticate(IRestClient client, IRestRequest request)
{
var uri = client.BuildUri(request);
var portSuffix = uri.Port != 80 ? ":" + uri.Port : "";
var host = uri.Host + portSuffix;
var method = request.Method.ToString();
var header = Hawk.GetAuthorizationHeader(host, method, uri, _credential);
request.AddHeader("Authorization", "Hawk " + header);
}
}
- Debug the call to the api
Specifications
- Version: 105.2.3.0
- Platform: .NET
StackTrace
Anulada la solicitud: No se puede crear un canal seguro SSL/TLS
Could not create ssl/tls secure channel
Hope you guys can help me with this
Best Regards
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (4 by maintainers)
I found solation after more searching 😃
Replace
httpstohttpI ran into this today. We’re on .net 4.6.1 with RestSharp 106.6.3.0 and this is still an issue there. Adding the following line of code prior to my first request resolves the issue for me
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;Here’s a configuration based solution (and some good commentary about the root cause) if you don’t want to or can’t add code: https://stackoverflow.com/questions/43872575/net-framework-4-6-1-not-defaulting-to-tls-1-2
Edit: After further research, there appears to be a recommended solution of setting the following in your web.config but that appears to not work for asp.net applications.
<configuration> <runtime> <AppContextSwitchOverrides value="Switch.System.Net.DontEnableSystemDefaultTlsVersions=false" /> </runtime> </configuration>I also tried adding it as an AppSetting but that also failed. Back to hard-coding TLS 1.2
It seems like an issue with your specific environment, where you have a proxy, which requires authentication. I cannot reproduce this because I haven’t seen places that use http proxy for years. I think you get more luck on StackOverflow.
Thanks a lot for the feedback Henry @driekus77 , it’s nice to get some support when giving your first steps, unfortunately I had tried it already and have something like this
I’m usign: .NET -> 4.5.2 .Net Core -> Not installed (couldn’t find the folder)
Don’t know RestSharp that wel but maybe this code example will help?:
Googleing on this showed me that it makes a different which .NET Framework / Core / Standard you use. If you still have issues point out which one you use.
I had the same issue when downgrading to .NET 4.5 from version 4.6.2.
I went back to 4.6.2 and the problem solved!