I am trying to use REST services from corporative (inner) site. That system is outsourcing (we can't change anything in it) and uses TLS 1.3. Issuer is
RapidSSL Global TLS RSA4096 SHA256 2022 CA1
and algorithm is SHA256withRSA
I have tried all the possible libraries including RestSharp, Flurl and HttpClient. Passing Tls13 protocol as parameter. The same problem exists with .NET Core 7 preview (which should have better TLS support).
My code looks like this:
var options = new RestClientOptions("https://xx.xxx.com/auth/login")
{
ThrowOnAnyError = true,
Timeout = 1000,
Expect100Continue = true,
};
var client = new RestClient(options);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
var response = client.Post(new RestRequest().AddJsonBody(new { user = "xxx@xxx.com", password = "123456" }));
or this code :
var tokenrequest = new TokenRequest() { User = "xxx", Password = "123" };
HttpClient _httpClient;
var httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
_httpClient = new HttpClient(httpClientHandler);
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls13;
var response = await _httpClient.PostAsync("https://yyy.com", CreateHttpContent<TokenRequest>(tokenrequest));
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
In all cases I get the same error:
Authentication failed because the remote party sent a TLS alert: 'HandshakeFailure'.
The message received was unexpected or badly formatted.
Fiddler detailed error message says:
HTTPS handshake to yyy.com (for #7) failed. System.Security.Authentication.AuthenticationException A call to SSPI failed, see inner exception. < The message received was unexpected or badly formatted
Win32 (SChannel) Native Error Code: 0x80090326