Start interagtion of new API Class

This commit is contained in:
TheJoKlLa
2022-05-16 16:07:33 +02:00
parent 0d5ad01496
commit 4f3521eec3
27 changed files with 224 additions and 763 deletions

View File

@ -119,11 +119,7 @@ namespace FabAccessAPI
ConnectionData = null;
ConnectionInfo = null;
EventHandler<ConnectionStatusChange> eventHandler = ConnectionStatusChanged;
if (eventHandler != null)
{
eventHandler(this, ConnectionStatusChange.Disconnected);
}
ConnectionStatusChanged?.Invoke(this, ConnectionStatusChange.Disconnected);
return Task.CompletedTask;
}
@ -135,11 +131,7 @@ namespace FabAccessAPI
await Connect(ConnectionData);
}
EventHandler<ConnectionStatusChange> eventHandler = ConnectionStatusChanged;
if (eventHandler != null)
{
eventHandler(this, ConnectionStatusChange.Reconnected);
}
ConnectionStatusChanged?.Invoke(this, ConnectionStatusChange.Reconnected);
}
public async Task<ConnectionInfo> TestConnection(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null)
@ -172,7 +164,7 @@ namespace FabAccessAPI
/// Validate Certificate
/// TODO: Do some validation
/// </summary>
private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
private static bool _RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
// TODO Cert Check
return true;
@ -188,7 +180,7 @@ namespace FabAccessAPI
{
rpcClient.InjectMidlayer((tcpstream) =>
{
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback));
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
try
{
sslStream.AuthenticateAsClient("bffhd");
@ -236,19 +228,9 @@ namespace FabAccessAPI
/// <exception cref="AuthenticationFailedException"></exception>
private async Task<Session> _Authenticate(ConnectionData connectionData)
{
Dictionary<string, object> joinedProperties = new Dictionary<string, object>();
foreach(KeyValuePair<string, object> keyValuePair in connectionData.Properties)
{
joinedProperties.Add(keyValuePair.Key, keyValuePair.Value);
}
foreach (KeyValuePair<string, object> keyValuePair in connectionData.SecretProperties)
{
joinedProperties.Add(keyValuePair.Key, keyValuePair.Value);
}
IAuthentication? authentication = await _Bootstrap.CreateSession(MechanismString.ToString(connectionData.Mechanism)).ConfigureAwait(false);
return await _SASLAuthenticate(authentication, MechanismString.ToString(connectionData.Mechanism), joinedProperties).ConfigureAwait(false);
return await _SASLAuthenticate(authentication, MechanismString.ToString(connectionData.Mechanism), connectionData.Properties).ConfigureAwait(false);
}
/// <summary>
@ -257,7 +239,7 @@ namespace FabAccessAPI
/// <exception cref="BadMechanismException"></exception>
/// <exception cref="InvalidCredentialsException"></exception>
/// <exception cref="AuthenticationFailedException"></exception>
public async Task<Session> _SASLAuthenticate(IAuthentication authentication, string mech, Dictionary<string, object> properties)
private async Task<Session> _SASLAuthenticate(IAuthentication authentication, string mech, Dictionary<string, object> properties)
{
SaslMechanism? saslMechanism = SaslFactory.Create(mech);
foreach (KeyValuePair<string, object> entry in properties)

View File

@ -9,7 +9,25 @@ namespace FabAccessAPI
public Mechanism Mechanism;
public string Username;
public Dictionary<string, object> Properties;
public Dictionary<string, object> SecretProperties;
public DateTime LastTime;
public override bool Equals(object? obj)
{
return obj is ConnectionData data &&
EqualityComparer<Uri>.Default.Equals(Host, data.Host) &&
Mechanism == data.Mechanism &&
Username == data.Username &&
EqualityComparer<Dictionary<string, object>>.Default.Equals(Properties, data.Properties);
}
public override int GetHashCode()
{
int hashCode = -1151110446;
hashCode = hashCode * -1521134295 + EqualityComparer<Uri>.Default.GetHashCode(Host);
hashCode = hashCode * -1521134295 + Mechanism.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Username);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<string, object>>.Default.GetHashCode(Properties);
return hashCode;
}
}
}