Added: Simple TLS

This commit is contained in:
TheJoKlLa 2022-03-15 00:35:00 +01:00
parent 9103a5959f
commit fbdbc90f1d

View File

@ -10,6 +10,9 @@ using Borepin.Service.BFFH.Exceptions;
using Borepin.Service.Storage.Exceptions;
using Capnp.Rpc;
using FabAccessAPI.Exceptions;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Security.Authentication;
namespace Borepin.Service.BFFH
{
@ -278,9 +281,29 @@ namespace Borepin.Service.BFFH
#endregion
#region Private Methods
private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
private async Task<TcpRpcClient> _ConnectAsync(string host, int port)
{
TcpRpcClient rpcClient = new TcpRpcClient();
rpcClient.InjectMidlayer((tcpstream) =>
{
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
try
{
sslStream.AuthenticateAsClient("bffhd");
return sslStream;
}
catch (AuthenticationException)
{
sslStream.Close();
throw;
}
});
rpcClient.Connect(host, port);
await rpcClient.WhenConnected.ConfigureAwait(false);