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 System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
@ -337,17 +338,18 @@ namespace FabAccessAPI
}
/// <summary>
/// Connect async to a server with ConnectionData
/// Injects SSL as Midlayer in TCPRPCConnection
/// </summary>
/// <exception cref="ConnectionException">Based on RPC Exception</exception>
private async Task _ConnectAsync(TcpRpcClient tcprpcClient, ConnectionData connectionData)
/// <exception cref="ConnectionException"></exception>
private Stream InjectSSL(Stream tcpstream)
{
tcprpcClient.InjectMidlayer((tcpstream) =>
{
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
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)
@ -356,7 +358,21 @@ namespace FabAccessAPI
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(InjectSSL);
try
{