The SSL connection could not be established

Copper Contributor

We have developed an application using Microsoft.Net Core. The application has a function that generates tokens and executes an API call.

 

Suddenly the application is throwing an error while generating the token. When we test the application, the same application is working on Windows applications but not on Windows servers.

 

It would be helpful if anyone could guide us on how to resolve this issue

 

Exception from server:

 

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (590615): The context has expired and can no longer be used.
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellation(CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpMessageHandlerStage.Send(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpMessageHandlerStage.Send(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.SocketsHttpHandler.Send(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpMessageInvoker.Send(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.Send(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at System.Net.HttpWebRequest.SendRequest(Boolean async)
at System.Net.HttpWebRequest.GetResponse()

6 Replies
I am facing a similar issue with a .NET call to another application. It works in test but not prod. The SSL cert on the other end is fine and I can get to site from server browser.
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (590615): The context has expired and can no longer be used.

@rjminick 

 

Estou com o mesmo problema, ao realizar uma comunicação MTLs ele informa que

 

{ Error = True, Data = System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.)
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (0x80090326): Mensagem recebida inesperada ou formatada incorretamente. 

 

Se algume tiver uma ideia do que pode ser, ou uma documentação que possa ajudar, já estou a alguns dias vendo doc's forums

@MOHANDHASGANDHI 

The error message indicates that the SSL connection could not be established, leading to an authentication failure. The specific exception "System.ComponentModel.Win32Exception (590615): The context has expired and can no longer be used" suggests a problem with SSL/TLS negotiation.

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();
    }
}

@rjminick@MOHANDHASGANDHI did you ever solve this problem?

@fabod001 If I remember correctly our issue was related to our F5. I am not sure exactly what my co-worker changed but think it may have been related to ciphers allowed. Test was not on the F5.