I am attempting to create a gRPC server and client using ssl (with .NET 5 and VS2019).
I want to use a generated X509Certificate2 as a root certificate to generate other client certificates. For that, I wrote a helper class CertificateUtil
, following these threads:
How can I create a self-signed certificate using C#?
Generate and Sign Certificate Request using pure .net Framework.
Next, the root certificate should be registered as a custom trust store in the startup settings of the gRPC server, and the client should connect using the generated client certificate.
I have the following question:
Is it possible to register a custom trust store in gRPC?
- If not, what is a good alternative?
- If yes, what part of the process I explain below is incorrect?
Currently, I am getting the following errors: client: "Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. IOException: Received an unexpected EOF or 0 bytes from the transport stream." server: "The local security authority (LSA) is unreachable"
Steps to reproduce:
- Pull the following MWE: https://github.com/Renopph/GrpcServerClient
- Uncomment lines 10 and 11 in
GprcCert/Program.cs
and run. This should create two certificate files,GrpcServer.pfx
andGrpcClient.pfx
. Set both files' properties to Copy always. Do NOT register these certificates in your system's trust store. - Place
GrpcClient.pfx
in the root of theGrpcClient
project. - Comment out lines 10 and 11, and uncomment line 12 in
GprcCert/Program.cs
. - Right click the Solution, open
Properties
. Select "Multiple startup projects" and set bothGrpcCert
andGrpcClient
to "Start". Then run the solution (should run GrpcCert first, then GrpcClient). - The client and server both show the aforementioned errors.
I also tried leaving out the KestrelServerOptions
in the Startup.cs
of the server. This allowed any client to connect, even without the certificate.