Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestSharp & TLS 1.1

Are there any known issues with using RestSharp & TLS 1.1? We currently use RestSharp to send post requests to a vendor. This vendor is no longer going to accept TLS 1.0 connections and changing to TLS 1.1.

The problem is when they switch from TLS 1.0 to TLS 1.1 then the RestSharp code we have no longer works.

I've tested this on 2008 R2 (after enabling registry settings for 1.1 and 1.2) and also on Windows 8.1. They switch to TLS 1.1 and the RestResponse is:

"The underlying connection was closed: An unexpected error occurred on a send"

Switch back to TLS 1.0 and no problem. I've tested access their site using Google Chrome and it does show TLS 1.1 so the server and client workstation are able to use TLS 1.1. It just seems to be RestSharp that is the issue...

like image 562
Jacob Dixon Avatar asked May 23 '15 05:05

Jacob Dixon


People also ask

What is RestSharp?

RestSharp is a C# library used to build and send API requests, and interpret the responses. It is used as part of the C#Bot API testing framework to build the requests, send them to the server, and interpret the responses so assertions can be made.

Is RestSharp better than HttpClient?

The main conclusion is that one is not better than the other, and we shouldn't compare them since RestSharp is a wrapper around HttpClient. The decision between using one of the two tools depends on the use case and the situation.

What is RestSharp in C#?

RestSharp is an open-source HTTP Client library that we can use to consume APIs easily. RestSharp features automatic serialization and deserialization, request and response type identification, and numerous authentication inbuilt patterns.

Is RestSharp asynchronous?

The main purpose of RestSharp is to make synchronous and asynchronous calls to remote resources over HTTP. As the name suggests, the main audience of RestSharp are developers who use REST APIs.


2 Answers

I haven't found any way to configure RestSharp to use different protocol. But you can override default protocol in ServicePointManager before making requests:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

This solve the issue. You can also change Windows Registry settings to use TLS 1.1/1.2 by default. Here is more info in related question.

like image 121
Vladislav Kostenko Avatar answered Oct 06 '22 21:10

Vladislav Kostenko


RestSharp already documented this issue:

The exception is thrown by WebRequest so you need to tell the .NET Framework to accept more certificate types than it does by default. Adding this line somewhere in your application, where it gets called once, should solve the issue:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

Therefore, consider adding the line above at Program.cs.

like image 1
Guilherme Moschen Avatar answered Oct 06 '22 21:10

Guilherme Moschen