runtime: Failed to setup SSL connection with .NET8 Linux-Container Image with failure "Received an unexpected EOF or 0 bytes from the transport stream"

Description

  • We are using http client to ping external website with below code snippets:
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
client.Timeout = TimeSpan.FromMilliseconds(5000);
try
{
    var url = "https://data.ad-score.com/img?pid=1000943&tt=g&tid=27152&l1=229666&l2=3090&l3=8070911";
    var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
    var statusCode = (int)response.StatusCode;
    var statusCodeString = response.StatusCode.ToString();
    Console.WriteLine($"{DateTime.UtcNow} RunTasks: Status code of Impression Tracking Url is {statusCode} {statusCodeString}");
}
catch ( Exception ex )
{
    Console.WriteLine($"{DateTime.UtcNow} RunTasks: thrown exception {ex}");
}
  • The target framework is net80 in csproj
  • When running this code on Windows, no issue reported
  • When running this code with .NET8 linux container,
FROM mcr.microsoft.com/dotnet/aspnet:8.0
...
CMD ["dotnet", "yinghttpconnectiontest.dll"]

I got exception below:

2/22/2024 8:03:33 AM RunTasks: thrown exception System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
   at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken)
   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)
   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(QueueItem queueItem)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
...
  • When running this code with .NET7 Linux container as base + copy .NET8 runtime to add .NET8 support
FROM mcr.microsoft.com/dotnet/aspnet:7.0
COPY --from=mcr.microsoft.com/dotnet/aspnet:8.0 /usr/share/dotnet /usr/share/dotnet
...

It works good again with above setting. I can’t distinguish whether it is an issue for .NET runtime, or anything wrong in mcr.microsoft.com/dotnet/aspnet8.0 image itself

=============

To support the debug, we collected below information:

  • a tcpdump when accessing the url but failed: tcpdump.txt ==> please rename to *.cap to open in wireshark
  • the ssl trace log for “System.Net.Security” when it worked successfully in .NET7 base image net7base.good.txt
  • the ssl trace log for “System.Net.Security” when it failed in .NET8 base image net8base.bad.txt

I expect to understand why .NET8 linux container can’t run this code pieces correctly

Reproduction Steps

see description above

Expected behavior

see description above

Actual behavior

see description above

Regression?

yes, works in .net7

Known Workarounds

No response

Configuration

No response

Other information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 20 (14 by maintainers)

Most upvoted comments

maybe the constant is ok. But we do not respect setting the OS has e.g. openssl s_client works but SslStream does not. Perhaps we need more adjustments for OpenSSL 3 and their default configurations.

Asking openssl.cnf modifications on client is problematic IMHO as the applications typically don’t own the OS (and should not IMHO as I would be pissed personally if each app install changes my crypto)

I also check Edge browser on Windows and it offers 16 cipherusptes including TLS_RSA_AES_128_GCM_SHA256 so it probably is not that bad. Perhaps we should have different defaults for client & server? I don’t really see good reason why HttpClient needs to drop anything different than browser.

Since this is now also our default docker image I feel it is going to be problematic unless we do something.

The list that we have as our default was assigned by the Microsoft Crypto Board. We can’t add insecure ciphersuites to it. Anyone who needs a less secure ciphersuite has to change system configuration, or use the per-call configuration options.

I am not sure yet, that’s what I want to investigate.