Reputation: 1
Every other answer to "The request was aborted: Could not create SSL/TLS secure channel" essentially says "make sure TLS 1.2 is on". This has not worked, and I have the Wireshark captures to back it up.
Now, I have a .NET Framework 4.7.2 ASP.NET Web API running in IIS. I am trying to interact with a 3rd-party API that requires a client certificate for mTLS. When my api sends the initial login request, I get the error The request was aborted: Could not create SSL/TLS secure channel.
The exception does not seem to contain any details about cause and does not have an inner exception.
The crazy part is, I only get this error when my API is running in IIS on a Windows 2022 server (AWS EC2). I do not get the error when I test locally. Furthermore, I do not get the error when I copy the exact code from my API into a console app and run that on the same server that the API runs on.
The certificate is loaded like so:
using (var s3Client = new AmazonS3Client())
{
var response = s3Client.GetObject(bucket, key);
using (response.ResponseStream)
using (var file = new MemoryStream())
{
response.ResponseStream.CopyTo(file);
cert = new X509Certificate2(file.ToArray(), certPassword);
}
}
and used like so:
var httpClientHandler = new HttpClientHandler();
httpClientHandler.ClientCertificates.Add(cert);
_httpClient = new HttpClient(httpClientHandler)
{
BaseAddress = _config.BaseUri
};
In Wireshark, it seems like the conversation just cuts off.
Here is what success looks like (console app): Success
Here is what failure looks like (ASP.NET Web API 2) Failure
ServicePointManager.SecurityProtocol = SecurityProtocolType.tls12
to the code.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true
to the code.Nothing made any difference and Wireshark shows TLSv1.2 is happening.
Upvotes: 0
Views: 21