mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
Fixed: TLS Timeout
This commit is contained in:
parent
9c1d979111
commit
2ce8113644
@ -6,6 +6,7 @@ using NLog;
|
||||
using S22.Sasl;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
@ -336,28 +337,43 @@ namespace FabAccessAPI
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Injects SSL as Midlayer in TCPRPCConnection
|
||||
/// </summary>
|
||||
/// <exception cref="ConnectionException"></exception>
|
||||
private Stream InjectSSL(Stream tcpstream)
|
||||
{
|
||||
SslStream sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
|
||||
try
|
||||
{
|
||||
sslStream.ReadTimeout = 2000;
|
||||
sslStream.AuthenticateAsClient("bffhd");
|
||||
sslStream.ReadTimeout = -1;
|
||||
|
||||
return sslStream;
|
||||
}
|
||||
catch (System.Security.Authentication.AuthenticationException exception)
|
||||
{
|
||||
sslStream.Close();
|
||||
Log.Warn(exception);
|
||||
throw new ConnectionException("TLS failed", exception);
|
||||
}
|
||||
catch(IOException exception)
|
||||
{
|
||||
sslStream.Close();
|
||||
Log.Warn(exception);
|
||||
throw new ConnectionException("TLS failed", new Exceptions.TimeoutException("TLS timeout", exception));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect async to a server with ConnectionData
|
||||
/// </summary>
|
||||
/// <exception cref="ConnectionException">Based on RPC Exception</exception>
|
||||
private async Task _ConnectAsync(TcpRpcClient tcprpcClient, ConnectionData connectionData)
|
||||
{
|
||||
tcprpcClient.InjectMidlayer((tcpstream) =>
|
||||
{
|
||||
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
|
||||
try
|
||||
{
|
||||
sslStream.AuthenticateAsClient("bffhd");
|
||||
return sslStream;
|
||||
}
|
||||
catch (System.Security.Authentication.AuthenticationException exception)
|
||||
{
|
||||
sslStream.Close();
|
||||
Log.Warn(exception);
|
||||
throw new ConnectionException("TLS failed", exception);
|
||||
}
|
||||
});
|
||||
|
||||
tcprpcClient.InjectMidlayer(InjectSSL);
|
||||
|
||||
try
|
||||
{
|
||||
Task timeoutTask = Task.Delay(3000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user