public static Func <string, string, IOStrategy, IByteConverter, ISaslMechanism> GetFactory3() { return((username, password, strategy, converter) => { ISaslMechanism saslMechanism = null; var connection = strategy.ConnectionPool.Acquire(); try { var saslListResult = strategy.Execute(new SaslList(converter), connection); if (saslListResult.Success) { if (saslListResult.Value.Contains("CRAM-MD5")) { saslMechanism = new CramMd5Mechanism(strategy, username, password, converter); } else { saslMechanism = new PlainTextMechanism(strategy, username, password, converter); } } } catch (Exception e) { Log.Error(e); } if (saslMechanism != null) { saslMechanism.IOStrategy = strategy; } return saslMechanism; }); }
/// <summary> /// Closes the connection. /// </summary> /// <returns></returns> public async Task CloseAsync() { if (this.isDisposed || this.State == XmppTransportState.Closed || this.State == XmppTransportState.Closing) { return; } try { await SoftCloseAsync().ConfigureAwait(false); } catch { } finally { this.DisposeSubscriptions(); this.transport = null; this.saslMechanism = null; this.connectionString = null; this.userAddress = null; this.people = null; this.activity = null; this.capabilities = null; this.personalEventing = null; this.presence = null; this.serverCapabilities = null; this.serverFeatures = ServerFeatures.None; this.ReleaseSubjects(); } }
private async Task OnStartSaslNegotiationAsync() { this.State = XmppTransportState.Authenticating; this.saslMechanism = this.CreateSaslMechanism(); await this.SendAsync(this.saslMechanism.StartSaslNegotiation()).ConfigureAwait(false); }
public const uint DefaultTimeout = 2500; //2.5sec public static Func <string, string, IOStrategy, ITypeTranscoder, ISaslMechanism> GetFactory3() { return((username, password, strategy, transcoder) => { ISaslMechanism saslMechanism = null; var connection = strategy.ConnectionPool.Acquire(); try { var saslListResult = strategy.Execute(new SaslList(transcoder, DefaultTimeout), connection); if (saslListResult.Success) { if (saslListResult.Value.Contains("CRAM-MD5")) { saslMechanism = new CramMd5Mechanism(strategy, username, password, transcoder); } else { saslMechanism = new PlainTextMechanism(strategy, username, password, transcoder); } } } catch (Exception e) { Log.Error(e); } finally { strategy.ConnectionPool.Release(connection); } return saslMechanism; }); }
private async Task SoftCloseAsync() { if (this.isDisposed || this.State == XmppTransportState.Closed || this.State == XmppTransportState.Closing) { return; } try { this.State = XmppTransportState.Closing; // Send the XMPP stream close tag await this.CloseStreamAsync().ConfigureAwait(false); #warning TODO: Wait until the server sends the stream close tag // Close the underlying transport this.CloseTransport(); } catch { } finally { this.transport = null; this.saslMechanism = null; this.serverFeatures = ServerFeatures.None; this.State = XmppTransportState.Closed; } }
/// <summary> /// Disposes the specified disposing. /// </summary> /// <param name="disposing">if set to <c>true</c> [disposing].</param> private void Dispose(bool disposing) { if (!this.isDisposed) { if (disposing) { // Release managed resources here this.CloseAsync().GetAwaiter().GetResult(); } // Call the appropriate methods to clean up // unmanaged resources here. // If disposing is false, // only the following code is executed. this.connectionString = null; this.userAddress = null; this.saslMechanism = null; this.people = null; this.activity = null; this.capabilities = null; this.personalEventing = null; this.presence = null; this.serverCapabilities = null; this.serverFeatures = ServerFeatures.None; this.state = XmppTransportState.Closed; this.CloseTransport(); this.DisposeSubscriptions(); this.ReleaseSubjects(); } this.isDisposed = true; }
public SocketAsyncStrategy(IConnectionPool connectionPool, SocketAsyncPool socketAsyncPool, ISaslMechanism saslMechanism, IByteConverter converter) { _connectionPool = connectionPool; _socketAsyncPool = socketAsyncPool; _saslMechanism = saslMechanism; _saslMechanism.IOStrategy = this; _converter = converter; }
/// <summary> /// Initializes a new instance of the <see cref="PooledIOService"/> class. /// </summary> /// <param name="connectionPool">The connection pool.</param> /// <param name="saslMechanism">The sasl mechanism.</param> public PooledIOService(IConnectionPool connectionPool, ISaslMechanism saslMechanism) { Log.Debug("Creating PooledIOService {0}", Identity); ConnectionPool = connectionPool; SaslMechanism = saslMechanism; var conn = connectionPool.Acquire(); CheckEnabledServerFeatures(conn); }
private async Task OnSaslSuccessAsync(SaslSuccess success) { if (this.saslMechanism.ProcessSuccess(success)) { this.State = XmppTransportState.Authenticated; this.saslMechanism = null; await this.transport.ResetStreamAsync().ConfigureAwait(false); } else { this.OnSaslFailure("Server reponse cannot be verified."); } }
public const uint DefaultTimeout = 2500; //2.5sec public static Func <string, string, IConnectionPool, ITypeTranscoder, ISaslMechanism> GetFactory() { return((username, password, pool, transcoder) => { ISaslMechanism saslMechanism = null; IConnection connection = null; try { if (pool.Configuration?.ForceSaslPlain ?? false) { return new PlainTextMechanism(username, password, transcoder); } connection = pool.Acquire(); var saslListResult = Execute(new SaslList(transcoder, DefaultTimeout), connection); if (saslListResult.Success) { if (saslListResult.Value.Contains("SCRAM-SHA1")) { return new ScramShaMechanism(transcoder, username, password, MechanismType.ScramSha1); } if (saslListResult.Value.Contains("CRAM-MD5")) { return new CramMd5Mechanism(username, password, transcoder); } if (saslListResult.Value.Contains("PLAIN")) { return new PlainTextMechanism(username, password, transcoder); } } } catch (Exception e) { Log.Error(e); } finally { if (connection != null) { pool.Release(connection); } } return saslMechanism; }); }
private ISaslMechanism CreateSaslMechanism() { ISaslMechanism mechanism = null; if (this.Supports(ServerFeatures.SaslScramSha1)) { mechanism = new SaslScramSha1Mechanism(this.ConnectionString); } else if (this.Supports(ServerFeatures.SaslDigestMD5)) { mechanism = new SaslDigestMechanism(this.ConnectionString); } else if (this.Supports(ServerFeatures.SaslPlain)) { mechanism = new SaslPlainMechanism(this.ConnectionString); } return(mechanism); }
// constructors /// <summary> /// Initializes a new instance of the <see cref="SaslAuthenticationProtocol" /> class. /// </summary> /// <param name="mechanism">The mechanism.</param> public SaslAuthenticationProtocol(ISaslMechanism mechanism) { _mechanism = mechanism; }
public DefaultIOStrategy(IConnectionPool connectionPool, ISaslMechanism saslMechanism) { _connectionPool = connectionPool; _saslMechanism = saslMechanism; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultIOStrategy"/> class. /// </summary> /// <param name="connectionPool">The connection pool.</param> /// <param name="saslMechanism">The sasl mechanism.</param> public DefaultIOStrategy(IConnectionPool connectionPool, ISaslMechanism saslMechanism) { Log.Debug(m => m("Creating DefaultIOStrategy {0}", _identity)); _connectionPool = connectionPool; _saslMechanism = saslMechanism; }
// constructors /// <summary> /// Initializes a new instance of the <see cref="SaslAuthenticator"/> class. /// </summary> /// <param name="mechanism">The mechanism.</param> protected SaslAuthenticator(ISaslMechanism mechanism) { _mechanism = Ensure.IsNotNull(mechanism, "mechanism"); }
public SocketAsyncStrategy(IConnectionPool connectionPool, ISaslMechanism saslMechanism) : this(connectionPool, new SocketAsyncPool(connectionPool, SocketAsyncFactory.GetSocketAsyncFunc()), saslMechanism, new AutoByteConverter()) { }
public SharedPooledIOService(IConnectionPool connectionPool, ISaslMechanism saslMechanism) : base(connectionPool, saslMechanism) { }
// constructors /// <summary> /// Initializes a new instance of the <see cref="SaslAuthenticationMethod" /> class. /// </summary> /// <param name="mechanism">The mechanism.</param> public SaslAuthenticationMethod(ISaslMechanism mechanism) { _mechanism = mechanism; }
/// <summary> /// Initializes a new instance of the <see cref="SaslAuthenticator"/> class. /// </summary> /// <param name="mechanism">The mechanism.</param> /// <param name="serverApi">The server API.</param> protected SaslAuthenticator(ISaslMechanism mechanism, ServerApi serverApi) { _mechanism = Ensure.IsNotNull(mechanism, nameof(mechanism)); _serverApi = serverApi; // can be null }
public void AddMechanism(ISaslMechanism mechanism) { mechanisms.Add(mechanism.Name, mechanism); }
public AuthenticationState GenericTest(ISaslMechanism client, ISaslMechanism server) { return(GenericTest(client.InitialStep, server.InitialStep)); }
public MultiplexingIOService(IConnectionPool connectionPool, ISaslMechanism saslMechanism) : this(connectionPool) { SaslMechanism = saslMechanism; }
public AuthenticationState GenericTest(ISaslMechanism client, ISaslMechanism server) { return GenericTest(client.InitialStep, server.InitialStep); }
// constructors protected SaslAuthenticator(ISaslMechanism mechanism) { _mechanism = Ensure.IsNotNull(mechanism, "mechanism"); }
/// <summary> /// Initializes a new instance of the <see cref="PooledIOService"/> class. /// </summary> /// <param name="connectionPool">The connection pool.</param> /// <param name="saslMechanism">The sasl mechanism.</param> public PooledIOService(IConnectionPool connectionPool, ISaslMechanism saslMechanism) { Log.Debug(m => m("Creating PooledIOService {0}", _identity)); _connectionPool = connectionPool; _saslMechanism = saslMechanism; }
protected SaslAuthenticator(ISaslMechanism mechanism) : this(mechanism, serverApi : null) { }