question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GRPC C-Core clients can connect to .NET Core server built on Linux, but not on Windows

See original GitHub issue

I’ve already asked this question on StackOverflow, but I thought I’d repost it here.

I’m trying to get a GRPC server (written in .NET core) and client (written in C++) to communicate over a SSL/TLS-secured channel.

The server targets “netcoreapp3.1”, and depends on “Grpc.AspNetCore” version 2.28.0. The server code itself is basically copied from some simple online examples. The Startup.cs and Program.cs are not too interesting on their own & probably aren’t the problems, so I just uploaded them to a gist (do note the call to UseHttps though). Everything builds, and I know that it works because I wrote a .NET core GRPC client which connects over HTTPS just fine (sources for that here, also very simple).

Unfortunately, I need to be using a C++ client to make the connection. Theoretically, the process is simple: get the .pfx file corresponding to the certificate passed to the UseHttps call, use it to create a server.crt via openssl, and use that to create a secure channel for the C++ client like so:

grpc::SslCredentialsOptions sslOpts{};
sslOpts.pem_root_certs = file_to_string(path_to_server_crt);
auto creds = grpc::SslCredentials(sslOpts);
auto channel = grpc::CreateChannel("localhost:50052", creds);

I’ve used the client successfully with a C++ grpc server, so there’s no lingering bugs on that side either. When I point it at my .NET core server though, things break. The client side info isn’t interesting, just a GRPC error 14. When the server is set to log things at Trace though, something pops out

dbug: Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer[2] 
  Connection id "0HM6UG4PBICBP" accepted.
dbug: Microsoft.AspNetCore.Server.Kestrel[1]
      Connection id "0HM6UG4PBICBP" started.
dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[1]
      Failed to authenticate HTTPS connection.
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (0x80090367): No common application protocol exists between the client and the server. Application protocol negotiation failed.
--- End of inner exception stack trace ---
// Some detailed stack trace, pretty sure it's garbage
dbug: Microsoft.AspNetCore.Server.Kestrel[2]
    Connection id "0HM6UG4PBICBP" stopped.
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
    Connection id "0HM6UG4PBICBP" sending FIN because: "The Socket transport's send loop completed gracefully

No common application protocol exists between the client and the server, that’s certainly interesting: the server must be rejecting whatever protocol the C++ client is trying to use? What’s the solution to this problem?

Note: I should mention that the C++ client is being compiled/run from WSL 1 (Ubuntu 18.04) whereas the server is being run on Windows Server 2019 Datacenter.

EDIT: Just bumped the app to target netcore5.0 and use Grpc.AspNetCore version 2.3.5 and tried again. Nothing changes on the server side, but the client now prints the following error. I don’t think it reveals anything new, but I thought I’d add it

 E0303 14:28:14.976078900    1126 ssl_transport_security.cc:1458] Handshake failed with fatal error SSL_ERROR_SSL: error:10000410:SSL routines:OPENSSL_internal:SSLV3_ALERT_HANDSHAKE_FAILURE.

The stack trace I describe as “garbage” earlier also gets quite a bit shorter, becoming

     at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
     at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(ConnectionContext context)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
anlshcommented, Mar 12, 2021

Just a final update: I set a repro repo earlier this week, and was unable to reproduce the issue on other machines. Whatever the issue was, it appears to have been some sort of misconfiguration on my end

0reactions
JamesNKcommented, Mar 8, 2021

@anlsh Create an issue at the link above and reference this issue.

Whatever the cause is here, it isn’t related to the Grpc.AspNetCore. The cause is lower-level in Kestrel’s TLS support.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Please continue to support grpc.core because there is no ...
Client which supports .NET Core and .NET Framework. Unfortunately Grpc.Net.Client does not support HTTP/2 on Windows 10 with the NET Framework.
Read more >
Unable to connect to net core gRPC service hosted in Docker
I am trying to deploy a Net core gRPC service into Linux docker container and accessing it from locally from VS console app....
Read more >
Tutorial: Create a gRPC client and server in ASP.NET Core
This tutorial shows how to create a gRPC Service and gRPC client on ASP.NET Core. Learn how to create a gRPC Service project,...
Read more >
gRPC on .NET supported platforms
Client package supports gRPC calls over HTTP/2 on .NET Core 3 and .NET 5 or later. Limited support is available for gRPC over...
Read more >
Technical articles - PEER Group
NET/C# development languages and communicate with the gRPC wire protocol. ... NET Core 3. It is not based on the gRPC C core...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found