C# GRPC Certificate client dont found

0

In this site (https://docs.microsoft.com/es-es/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.0&tabs=visual-studio) Microsoft writes about the use of GRPC, and publishes examples to download. One example is Certifier. The certifier shows how to configure the client and the server to use a TLS client certificate with a gRPC call. The server is configured to require a client certificate using ASP.NET Core client certificate authentication.

In my code, I write clienta, replacement original client, in solution explorer I cant read two files, client.pfx and clienta.pfx generated form IIS. The code is:

private static HttpClient CreateHttpClient(bool includeClientCertificate)
{
var handler = new HttpClientHandler();
if (includeClientCertificate)
{
// Load client certificate
var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);
// var certPath = Path.Combine(basePath!, "Certs", "client.pfx");
var certPath = Path.Combine(basePath!, "Certs", "clienta.pfx");
//  var clientCertificate = new X509Certificate2(certPath, "1111");
var clientCertificate = new X509Certificate2(certPath, "Javier", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.EphemeralKeySet);
handler.ClientCertificates.Add(clientCertificate);
}
// Create client
return new HttpClient(handler);
}

And de error is

Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException
HResult=0x80070002
Mensaje = El sistema no puede encontrar el archivo especificado.
Origen = System.Security.Cryptography.X509Certificates
Seguimiento de la pila:
at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
at   System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
 at Client.Program.CreateHttpClient(Boolean includeClientCertificate) in C:\Users\HP\Source\Repos\Grpc Ejemplos\grpc-dotnet\examples\Certifier\Client\Program.cs:line 87
c#
ssl-certificate
grpc
credentials
channel
asked on Stack Overflow Oct 14, 2019 by Javier Marcuzzi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0