1

I've a ASP.NET core web application that uses built in kestrel server and configurations to setup a https connection. Here's how the configutarion (settings.json) looks like

{
  "Kestrel": {
    "Endpoints": {
      "Https": {
        "Url": "https://localhost:5001"
        }
      },
    "Certificates": {
      "Default": {
          "Subject": "localhost", //default cert generated by visual studio 
          "Store": "My",
          "Location": "LocalMachine",
          "AllowInvalid": "true"
                }
                  }
              }
}

The server expectes a client certificate

.ConfigureKestrel(options =>
                {
    options.ConfigureHttpsDefaults(o =>
    {
        // certificate is an X509Certificate2
        o.ServerCertificate = cert;
        o.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
    });
 
}).UseUrls($"https://*:{int.Parse(Configuration["Port"])}")

This is the error trace

    Unable to retrieve products from https://localhost:5001/api/Products. Exception: 
The SSL connection could not be established, see inner exception.
System.IO.IOException:  Received an unexpected EOF or 0 bytes from the transport stream.

I'm pretty sure the configuration looks fine and it might be an external thing that is terminating the SSL connection like windows defender firewall because it works in a different system. Can I get some suggestions to identify the factor that might close the connection before SSL connection is established?

SQLProfiler
  • 109
  • 7

1 Answers1

0

Kestrel uses TLS version 1.1 or 1.2 by default. You could try to enable higher version by configure the program.cs

var builder = WebApplication.CreateBuilder();
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
{
    serverOptions.ConfigureHttpsDefaults(listenOptions =>
    {
        listenOptions.OnAuthenticate = (context, sslOptions) =>
        {
            sslOptions.EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls13;
        };
    });
});

Reference :https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/5.0/kestrel-default-supported-tls-protocol-versions-changed#recommended-action

Qiang Fu
  • 1,401
  • 1
  • 2
  • 8