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.

FullFramework (.Net 4.7.2) Client with .Net 5 gRPC Serivce and kestrel -- How to get the communication working (SSL)

See original GitHub issue

At the moment we need that an old application(.net 4.7.2) request data from a new application (.net 5.0) via gRPC. However the client for the full framework seems not to send the certificate to the server automatically, therefore we are doing it manually (at the moment), like so (taken from https://stackoverflow.com/questions/58125102/grpc-net-client-fails-to-connect-to-server-with-ssl) :

CallCredentials credentials = CallCredentials.FromInterceptor((context, metadata) =>
                                                                                          {
                                                                                              metadata.Add("SecurityTokenId", "someKey");
                                                                                              
                                                                                              return Task.CompletedTask;
                                                                                          });

           ChannelCredentials channelCredentials = ChannelCredentials.Create(new SslCredentials(certificate), credentials);

           Channel channel = new Channel("localhost", 44301, channelCredentials);

           ProjectInlayDataService.ProjectInlayDataServiceClient client = new ProjectInlayDataService.ProjectInlayDataServiceClient(channel);
           
           GetProjectInlayDataResponse result = client.GetProjectInlayDataAsync(new GetProjectInlayDataRequest {
                                                                                                                   PackageIds =
                                                                                                                   {
                                                                                                                       "test"
                                                                                                                   }
                                                                                                               }).Ge

public static string GetRootCertificates()
       {
           StringBuilder builder = new StringBuilder();

           X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

           try
           {
               store.Open(OpenFlags.ReadOnly);

               foreach (X509Certificate2 mCert in store.Certificates)
               {
                   builder.AppendLine(
                       "# Issuer: " + mCert.Issuer + "\n" +
                       "# Subject: " + mCert.Subject + "\n" +
                       "# Label: " + mCert.FriendlyName + "\n" +
                       "# Serial: " + mCert.SerialNumber + "\n" +
                       "# SHA1 Fingerprint: " + mCert.GetCertHashString() + "\n" +
                       ExportToPem(mCert) + "\n");
               }
           }
           catch (Exception exception)
           {
               Console.WriteLine("Get Root Certificates fails: " + exception);
               throw;
           }

           string certificates = builder.ToString();

           return certificates;
       }

       public static string ExportToPem(X509Certificate cert)
       {
           StringBuilder builder = new StringBuilder();

           builder.AppendLine("-----BEGIN CERTIFICATE-----");
           builder.AppendLine(Convert.ToBase64String(cert.Export(X509ContentType.Cert), Base64FormattingOptions.InsertLineBreaks));
           builder.AppendLine("-----END CERTIFICATE-----");

           return builder.ToString();
       }

This works fine, but when the grpc client and the grpc server are on different computer this does not work (of course) --> and now my question is how is this implemented in the grpcClient for .Net Core/.Net 5.0, because there it’s working out of the box, some advice would be highly appreciated!

We don’t want to store the certifiacte (pem) on the client and then read it from the disk and then use it, because everytime the certificate changes we would have to change the pem on the client as well (and we have a lot of services on different servers and also different stages).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, May 19, 2021

You aren’t using a supported version of Windows.

1reaction
JamesNKcommented, Feb 3, 2021

Grpc.Net.Client uses HttpClient internally. It automatically handles HTTPS related tasks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to access gRPC service from WPF running .NET 4.7.2?
NET Framework 4.7.2 WPF-Client (using old C wrapper grpc package). The main problem was to find a solution to accept a self-signed SSL...
Read more >
gRPC services with ASP.NET Core
gRPC requires HTTP/2. gRPC for ASP.NET Core validates HttpRequest.Protocol is HTTP/2 . Kestrel supports HTTP/2 on most modern operating systems.
Read more >
.NET & GRPC What they forgot to tell you | FAESEL.COM
NET Framework client app consume a .NET Core GRPC server? How to debug with tools, call an endpoint; Authentication and authorization; Can you ......
Read more >
Getting Started with gRPC and .NET - InfoQ
The text is illustrated with a step-by-step tutorial on how to use gRPC to develop streaming services in .NET.
Read more >
gRPC : Running Multiple processes on the same port in . ...
The answer boils down to whether ASP.NET Core supports port sharing between multiple process (as gRPC server is just a special type of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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