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;
@ -337,17 +338,18 @@ namespace FabAccessAPI
} }
/// <summary> /// <summary>
/// Connect async to a server with ConnectionData /// Injects SSL as Midlayer in TCPRPCConnection
/// </summary> /// </summary>
/// <exception cref="ConnectionException">Based on RPC Exception</exception> /// <exception cref="ConnectionException"></exception>
private async Task _ConnectAsync(TcpRpcClient tcprpcClient, ConnectionData connectionData) private Stream InjectSSL(Stream tcpstream)
{ {
tcprpcClient.InjectMidlayer((tcpstream) => SslStream sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
{
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
try try
{ {
sslStream.ReadTimeout = 2000;
sslStream.AuthenticateAsClient("bffhd"); sslStream.AuthenticateAsClient("bffhd");
sslStream.ReadTimeout = -1;
return sslStream; return sslStream;
} }
catch (System.Security.Authentication.AuthenticationException exception) catch (System.Security.Authentication.AuthenticationException exception)
@ -356,7 +358,21 @@ namespace FabAccessAPI
Log.Warn(exception); Log.Warn(exception);
throw new ConnectionException("TLS failed", 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(InjectSSL);
try try
{ {