mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-13 07:11:56 +01:00
Added: Simple TLS
This commit is contained in:
parent
9103a5959f
commit
fbdbc90f1d
@ -10,6 +10,9 @@ using Borepin.Service.BFFH.Exceptions;
|
|||||||
using Borepin.Service.Storage.Exceptions;
|
using Borepin.Service.Storage.Exceptions;
|
||||||
using Capnp.Rpc;
|
using Capnp.Rpc;
|
||||||
using FabAccessAPI.Exceptions;
|
using FabAccessAPI.Exceptions;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Authentication;
|
||||||
|
|
||||||
namespace Borepin.Service.BFFH
|
namespace Borepin.Service.BFFH
|
||||||
{
|
{
|
||||||
@ -278,9 +281,29 @@ namespace Borepin.Service.BFFH
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#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)
|
private async Task<TcpRpcClient> _ConnectAsync(string host, int port)
|
||||||
{
|
{
|
||||||
TcpRpcClient rpcClient = new TcpRpcClient();
|
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);
|
rpcClient.Connect(host, port);
|
||||||
await rpcClient.WhenConnected.ConfigureAwait(false);
|
await rpcClient.WhenConnected.ConfigureAwait(false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user