Forum Discussion
The SSL connection could not be established
The error message indicates that the SSL connection could not be established, leading to an authentication failure. The specific exception "System.ComponentModelhttps://crackaction.com/protegent-antivirus-crack-free/Win32Exception (590615): The context has expired and can no longer be used" suggests a problem with SSL/TLS negotiation.
- fabod001Apr 07, 2024Copper Contributor
I'm also getting this "The context has expired and can no longer be used" exception from a .NET application that's authenticating against an API using mTLS. The certificate being attached to the request is read off of a smart card. ...on the call to HttpClient.GetAsync.
The API hits worked about 10 times during testing in my dev environment before getting the error. Using a browser works.
I've tried and failed to learn what context is being referred to. Is it an HttpClient HttpContext? An SslStream TransportContext?
string responseBody;
X509Certificate2 smartCardCertificate = GetSmartCardCertificate();
using (var httpClientHandler = new HttpClientHandler())
{
httpClientHandler.ClientCertificates.Add(smartCardCertificate);
httpClientHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
httpClientHandler.SslProtocols = SslProtocols.None;
using (var httpClient = new HttpClient(httpClientHandler))
{
HttpResponseMessage response;
response = await httpClient.GetAsync(my_special_url);
response.EnsureSuccessStatusCode();
responseBody = await response.Content.ReadAsStringAsync();
}
}