void OnInit(SaslInit init) { SaslCode code = SaslCode.Ok; if (init.InitialResponse.Count > 0) { string token = Encoding.UTF8.GetString(init.InitialResponse.Array, init.InitialResponse.Offset, init.InitialResponse.Count); Utils.Trace(TraceLevel.Verbose, "Received token: {0}", token); if (this.tokenAuthenticator != null) { try { string[] claimSet = this.tokenAuthenticator(token); this.Principal = new GenericPrincipal( new GenericIdentity("acs-client", SaslSwtHandler.Name), claimSet); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } code = SaslCode.Auth; } } } this.Negotiator.CompleteNegotiation(code, null); }
void OnInit(SaslInit init) { // the client message is specified by RFC4616 // message = [authzid] UTF8NUL authcid UTF8NUL passwd // authcid and passwd should be prepared [SASLPrep] before // the verification process. string password = null; if (init.InitialResponse.Count > 0) { string message = Encoding.UTF8.GetString(init.InitialResponse.Array, init.InitialResponse.Offset, init.InitialResponse.Count); string[] items = message.Split('\0'); if (items.Length != 3) { throw new UnauthorizedAccessException(SaslPlainHandler.InvalidCredential); } this.AuthorizationIdentity = items[0]; this.AuthenticationIdentity = items[1]; password = items[2]; } if (string.IsNullOrEmpty(this.AuthenticationIdentity)) { throw new UnauthorizedAccessException(SaslPlainHandler.InvalidCredential); } if (this.authenticator != null) { this.Principal = this.authenticator.Authenticate(this.AuthenticationIdentity, password); } this.Negotiator.CompleteNegotiation(SaslCode.Ok, null); }
private void OnInit(SaslInit init) { string str = null; if (init.InitialResponse.Count > 0) { System.Text.Encoding uTF8 = System.Text.Encoding.UTF8; byte[] array = init.InitialResponse.Array; int offset = init.InitialResponse.Offset; ArraySegment <byte> initialResponse = init.InitialResponse; string str1 = uTF8.GetString(array, offset, initialResponse.Count); string[] strArrays = str1.Split(new char[1]); if ((int)strArrays.Length != 3) { throw new UnauthorizedAccessException(SaslPlainHandler.InvalidCredential); } this.AuthorizationIdentity = strArrays[0]; this.AuthenticationIdentity = strArrays[1]; str = strArrays[2]; } if (string.IsNullOrEmpty(this.AuthenticationIdentity)) { throw new UnauthorizedAccessException(SaslPlainHandler.InvalidCredential); } if (this.authenticator != null) { base.Principal = this.authenticator.Authenticate(this.AuthenticationIdentity, str); } base.Negotiator.CompleteNegotiation(SaslCode.Ok, null); }
private void OnInit(SaslInit init) { SaslCode saslCode = SaslCode.Ok; if (init.InitialResponse.Count > 0) { System.Text.Encoding uTF8 = System.Text.Encoding.UTF8; byte[] array = init.InitialResponse.Array; int offset = init.InitialResponse.Offset; ArraySegment <byte> initialResponse = init.InitialResponse; string str = uTF8.GetString(array, offset, initialResponse.Count); MessagingClientEtwProvider.TraceClient(() => { }); if (this.tokenAuthenticator != null) { try { string[] strArrays = this.tokenAuthenticator(str); base.Principal = new GenericPrincipal(new GenericIdentity("acs-client", SaslSwtHandler.Name), strArrays); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } saslCode = SaslCode.Auth; } } } base.Negotiator.CompleteNegotiation(saslCode, null); }
protected override void OnStart(SaslInit init, bool isClient) { if (isClient) { base.Negotiator.WriteFrame(init, true); return; } base.Principal = new GenericPrincipal(new GenericIdentity("dummy-identity", "dummy-identity"), null); base.Negotiator.CompleteNegotiation(SaslCode.Ok, null); }
protected override void OnStart(SaslInit init, bool isClient) { if (!isClient) { this.OnInit(init); return; } string clientMessage = this.GetClientMessage(); init.InitialResponse = new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes(clientMessage)); base.Negotiator.WriteFrame(init, true); }
/// <summary> /// Server receives the client init that may contain the initial response message. /// </summary> void OnSaslInit(SaslInit init) { if (this.state != SaslState.WaitingForInit) { throw new AmqpException(AmqpError.IllegalState, SRClient.AmqpIllegalOperationState("R:SASL-INIT", this.state)); } Utils.Trace(TraceLevel.Verbose, "{0}: on sasl init. mechanism: {1}", this.transport, init.Mechanism.Value); this.state = SaslState.Negotiating; this.saslHandler = this.provider.GetHandler(init.Mechanism.Value, true); this.saslHandler.Start(this, init, false); }
protected override void OnStart(SaslInit init, bool isClient) { if (isClient) { string message = this.GetClientMessage(); init.InitialResponse = new ArraySegment <byte>(Encoding.UTF8.GetBytes(message)); this.Negotiator.WriteFrame(init, true); } else { this.OnInit(init); } }
protected override void OnStart(SaslInit init, bool isClient) { if (isClient) { string message = this.GetClientMessage(); init.InitialResponse = new ArraySegment<byte>(Encoding.UTF8.GetBytes(message)); this.Negotiator.WriteFrame(init, true); } else { this.OnInit(init); } }
protected override void OnStart(SaslInit init, bool isClient) { if (!isClient) { base.Negotiator.CompleteNegotiation(SaslCode.Ok, null); return; } if (this.Identity != null) { init.InitialResponse = new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes(this.Identity)); } base.Negotiator.WriteFrame(init, true); }
private void OnSaslInit(SaslInit init) { if (this.state != SaslNegotiator.SaslState.WaitingForInit) { throw new AmqpException(AmqpError.IllegalState, SRAmqp.AmqpIllegalOperationState("R:SASL-INIT", this.state)); } this.state = SaslNegotiator.SaslState.Negotiating; SaslTransportProvider saslTransportProvider = this.provider; AmqpSymbol mechanism = init.Mechanism; this.saslHandler = saslTransportProvider.GetHandler(mechanism.Value, true); this.saslHandler.Start(this, init, false); }
protected override void OnStart(SaslInit init, bool isClient) { if (isClient) { if (this.Identity != null) { init.InitialResponse = new ArraySegment <byte>(Encoding.UTF8.GetBytes(this.Identity)); } this.Negotiator.WriteFrame(init, true); } else { // server side. send outcome this.Negotiator.CompleteNegotiation(SaslCode.Ok, null); } }
protected override void OnStart(SaslInit init, bool isClient) { if (isClient) { if (this.Identity != null) { init.InitialResponse = new ArraySegment<byte>(Encoding.UTF8.GetBytes(this.Identity)); } this.Negotiator.WriteFrame(init, true); } else { // server side. send outcome this.Negotiator.CompleteNegotiation(SaslCode.Ok, null); } }
public void Start(SaslNegotiator saslNegotiator, SaslInit init, bool isClient) { this.saslNegotiator = saslNegotiator; try { this.OnStart(init, isClient); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.saslNegotiator.CompleteNegotiation(SaslCode.Sys, exception); } }
public void Start(SaslNegotiator saslNegotiator, SaslInit init, bool isClient) { this.saslNegotiator = saslNegotiator; try { this.OnStart(init, isClient); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.saslNegotiator.CompleteNegotiation(SaslCode.Sys, exception); } }
private void OnSaslServerMechanisms(SaslMechanisms mechanisms) { if (this.state != SaslNegotiator.SaslState.WaitingForServerMechanisms) { throw new AmqpException(AmqpError.IllegalState, SRAmqp.AmqpIllegalOperationState("R:SASL-MECH", this.state)); } string str = null; using (IEnumerator <string> enumerator = this.provider.Mechanisms.GetEnumerator()) { do { if (!enumerator.MoveNext()) { break; } string current = enumerator.Current; if (!mechanisms.SaslServerMechanisms.Contains(new AmqpSymbol(current))) { continue; } str = current; break; }while (str == null); } if (str == null) { throw new AmqpException(AmqpError.NotFound, SRAmqp.AmqpNotSupportMechanism); } this.state = SaslNegotiator.SaslState.Negotiating; this.saslHandler = this.provider.GetHandler(str, true); SaslInit saslInit = new SaslInit() { Mechanism = str }; this.saslHandler.Start(this, saslInit, true); }
/// <summary> /// Client receives the announced server mechanisms. /// </summary> void OnSaslServerMechanisms(SaslMechanisms mechanisms) { if (this.state != SaslState.WaitingForServerMechanisms) { throw new AmqpException(AmqpError.IllegalState, SRClient.AmqpIllegalOperationState("R:SASL-MECH", this.state)); } Utils.Trace(TraceLevel.Verbose, "{0}: on sasl server mechanisms", this.transport); string mechanismToUse = null; foreach (string mechanism in this.provider.Mechanisms) { if (mechanisms.SaslServerMechanisms.Contains(new AmqpSymbol(mechanism))) { mechanismToUse = mechanism; break; } if (mechanismToUse != null) { break; } } if (mechanismToUse == null) { throw new AmqpException(AmqpError.NotFound, SRClient.AmqpNotSupportMechanism); } this.state = SaslState.Negotiating; this.saslHandler = this.provider.GetHandler(mechanismToUse, false); SaslInit init = new SaslInit(); init.Mechanism = mechanismToUse; this.saslHandler.Start(this, init, true); }
protected abstract void OnStart(SaslInit init, bool isClient);