FullFramework (.Net 4.7.2) Client with .Net 5 gRPC Serivce and kestrel -- How to get the communication working (SSL)
See original GitHub issueAt 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:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
You aren’t using a supported version of Windows.
Grpc.Net.Client uses HttpClient internally. It automatically handles HTTPS related tasks.