Fixed: TLS Timeout

This commit is contained in:
TheJoKlLa 2023-01-31 14:14:33 +01:00
parent 9c1d979111
commit 2ce8113644

View File

@ -6,6 +6,7 @@ using NLog;
using S22.Sasl; using S22.Sasl;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Net.Security; using System.Net.Security;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
@ -336,27 +337,42 @@ namespace FabAccessAPI
return true; 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> /// <summary>
/// Connect async to a server with ConnectionData /// Connect async to a server with ConnectionData
/// </summary> /// </summary>
/// <exception cref="ConnectionException">Based on RPC Exception</exception> /// <exception cref="ConnectionException">Based on RPC Exception</exception>
private async Task _ConnectAsync(TcpRpcClient tcprpcClient, ConnectionData connectionData) private async Task _ConnectAsync(TcpRpcClient tcprpcClient, ConnectionData connectionData)
{ {
tcprpcClient.InjectMidlayer((tcpstream) => tcprpcClient.InjectMidlayer(InjectSSL);
{
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);
}
});
try try
{ {