Код: Выделить всё
using Grpc.Net.Client;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public GrpcChannel CreateSecureChannel(string address, string clientCertPath, string clientKeyPath, string caFilePath)
{
var handler = new SocketsHttpHandler();
var clientCertificate = LoadClientCertificate(clientCertPath, clientKeyPath);
handler.SslOptions = new SslClientAuthenticationOptions
{
ClientCertificates = new X509CertificateCollection { clientCertificate },
RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
// how do we validate the server certificate?
}
};
var httpClient = new HttpClient(handler);
return GrpcChannel.ForAddress(address, new GrpcChannelOptions { HttpClient = httpClient });
}
Я имею опыт работы с Java , и я не помню, чтобы это было так сложно реализовать.
Буду благодарен за любую помощь!
Подробнее здесь: https://stackoverflow.com/questions/791 ... ttphandler
Мобильная версия