public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider, bool isInitiator) { this.transport = transport; this.provider = provider; this.isInitiator = isInitiator; this.state = SaslState.Start; }
void HandleException(string action, Exception exception) { AmqpTrace.Provider.AmqpLogError(this, action, exception.Message); this.state = SaslState.End; this.completeException = exception; this.CompleteTransport(); }
public void CompleteNegotiation(SaslCode code, Exception exception) { if (!this.transport.IsInitiator) { SaslOutcome outcome = new SaslOutcome(); outcome.OutcomeCode = code; if (code == SaslCode.Ok) { outcome.AdditionalData = new ArraySegment <byte>(Encoding.UTF8.GetBytes(welcome)); } Utils.Trace(TraceLevel.Info, "{0}: sending sasl outcome {1}", this.transport, code); this.WriteFrame(outcome, false); } this.state = SaslState.End; if (exception != null) { this.transport.OnNegotiationFail(exception); } else { this.transport.OnNegotiationSucceed(this.saslHandler.Principal); } }
public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider) { this.transport = transport; this.provider = provider; this.onReadFrameComplete = this.OnReadFrameComplete; this.onWriteFrameComplete = this.OnWriteFrameComplete; this.state = SaslState.Start; }
/// <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(AmqpErrorCode.IllegalState, AmqpResources.GetString(AmqpResources.AmqpIllegalOperationState, "R:SASL-INIT", this.state)); } this.state = SaslState.Negotiating; this.saslHandler = this.provider.GetHandler(init.Mechanism.Value, true); this.saslHandler.Start(this, init, false); }
/// <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); }
/// <summary> /// Client receives the sasl outcome from the server. /// </summary> void OnSaslOutcome(SaslOutcome outcome) { Utils.Trace(TraceLevel.Verbose, "{0}: on sasl outcome. code: {1}", this.transport, outcome.OutcomeCode.Value); this.state = SaslState.End; if (outcome.OutcomeCode.Value == SaslCode.Ok) { this.transport.OnNegotiationSucceed(null); } else { this.transport.OnNegotiationFail(new UnauthorizedAccessException(outcome.OutcomeCode.Value.ToString())); } }
void SendServerMechanisms() { List <AmqpSymbol> mechanisms = new List <AmqpSymbol>(); foreach (string mechanism in this.provider.Mechanisms) { mechanisms.Add(new AmqpSymbol(mechanism)); } SaslMechanisms salsMechanisms = new SaslMechanisms(); salsMechanisms.SaslServerMechanisms = new Multiple <AmqpSymbol>(mechanisms); this.state = SaslState.WaitingForInit; this.WriteFrame(salsMechanisms, true); }
void SendServerMechanisms() { List <AmqpSymbol> mechanisms = new List <AmqpSymbol>(); foreach (string mechanism in this.provider.Mechanisms) { mechanisms.Add(new AmqpSymbol(mechanism)); } SaslMechanisms salsMechanisms = new SaslMechanisms(); salsMechanisms.SaslServerMechanisms = new Multiple <AmqpSymbol>(mechanisms); this.state = SaslState.WaitingForInit; this.WriteFrame(salsMechanisms, true); Utils.Trace(TraceLevel.Verbose, "{0}: sent server mechanisms", this.transport); }
public bool Start() { this.reader = new AsyncIO.FrameBufferReader(transport); this.writer = new AsyncIO.AsyncBufferWriter(transport); if (!this.transport.IsInitiator) { this.SendServerMechanisms(); } else { Utils.Trace(TraceLevel.Info, "{0}: waiting for server mechanisms", this); this.state = SaslState.WaitingForServerMechanisms; this.ReadFrame(); } return(false); }
public bool Start() { this.reader = new AsyncIO.FrameBufferReader(this, transport, this.provider.MaxFrameSize); this.writer = new AsyncIO.AsyncBufferWriter(transport); if (!this.isInitiator) { this.SendServerMechanisms(); } else { this.state = SaslState.WaitingForServerMechanisms; AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Execute, "WaitingForServerMechanisms"); this.ReadFrame(); } return false; }
public bool Start() { this.reader = new AsyncIO.FrameBufferReader(this, transport, this.provider.MaxFrameSize); this.writer = new AsyncIO.AsyncBufferWriter(transport); if (!this.isInitiator) { this.SendServerMechanisms(); } else { this.state = SaslState.WaitingForServerMechanisms; AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Execute, "WaitingForServerMechanisms"); this.ReadFrame(); } return(false); }
public bool Start() { this.reader = new AsyncIO.FrameBufferReader(transport); this.writer = new AsyncIO.AsyncBufferWriter(transport); if (!this.transport.IsInitiator) { this.SendServerMechanisms(); } else { Utils.Trace(TraceLevel.Info, "{0}: waiting for server mechanisms", this); this.state = SaslState.WaitingForServerMechanisms; this.ReadFrame(); } return false; }
public void CompleteNegotiation(SaslCode code, Exception exception) { this.state = SaslState.End; this.completeException = exception; if (!this.isInitiator) { SaslOutcome outcome = new SaslOutcome(); outcome.OutcomeCode = code; if (code == SaslCode.Ok) { outcome.AdditionalData = new ArraySegment <byte>(Encoding.UTF8.GetBytes(welcome)); } // transported is completed in the callback this.WriteFrame(outcome, false); } else { this.CompleteTransport(); } }
/// <summary> /// Client receives the announced server mechanisms. /// </summary> void OnSaslServerMechanisms(SaslMechanisms mechanisms) { if (this.state != SaslState.WaitingForServerMechanisms) { throw new AmqpException(AmqpErrorCode.IllegalState, AmqpResources.GetString(AmqpResources.AmqpIllegalOperationState, "R:SASL-MECH", this.state)); } 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( AmqpErrorCode.NotFound, AmqpResources.GetString(AmqpResources.AmqpNotSupportMechanism, mechanisms.SaslServerMechanisms.ToString(), string.Join(",", this.provider.Mechanisms))); } this.state = SaslState.Negotiating; this.saslHandler = this.provider.GetHandler(mechanismToUse, true); SaslInit init = new SaslInit(); init.Mechanism = mechanismToUse; this.saslHandler.Start(this, init, 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); }
void SendServerMechanisms() { List<AmqpSymbol> mechanisms = new List<AmqpSymbol>(); foreach (string mechanism in this.provider.Mechanisms) { mechanisms.Add(new AmqpSymbol(mechanism)); } SaslMechanisms salsMechanisms = new SaslMechanisms(); salsMechanisms.SaslServerMechanisms = new Multiple<AmqpSymbol>(mechanisms); this.state = SaslState.WaitingForInit; this.WriteFrame(salsMechanisms, true); }
public void CompleteNegotiation(SaslCode code, Exception exception) { if (!this.transport.IsInitiator) { SaslOutcome outcome = new SaslOutcome(); outcome.OutcomeCode = code; if (code == SaslCode.Ok) { outcome.AdditionalData = new ArraySegment<byte>(Encoding.UTF8.GetBytes(welcome)); } Utils.Trace(TraceLevel.Info, "{0}: sending sasl outcome {1}", this.transport, code); this.WriteFrame(outcome, false); } this.state = SaslState.End; if (exception != null) { this.transport.OnNegotiationFail(exception); } else { this.transport.OnNegotiationSucceed(this.saslHandler.Principal); } }
void SendServerMechanisms() { List<AmqpSymbol> mechanisms = new List<AmqpSymbol>(); foreach (string mechanism in this.provider.Mechanisms) { mechanisms.Add(new AmqpSymbol(mechanism)); } SaslMechanisms salsMechanisms = new SaslMechanisms(); salsMechanisms.SaslServerMechanisms = new Multiple<AmqpSymbol>(mechanisms); this.state = SaslState.WaitingForInit; this.WriteFrame(salsMechanisms, true); Utils.Trace(TraceLevel.Verbose, "{0}: sent server mechanisms", this.transport); }
public void CompleteNegotiation(SaslCode code, Exception exception) { this.state = SaslState.End; this.completeException = exception; if (!this.isInitiator) { SaslOutcome outcome = new SaslOutcome(); outcome.OutcomeCode = code; if (code == SaslCode.Ok) { outcome.AdditionalData = new ArraySegment<byte>(Encoding.UTF8.GetBytes(welcome)); } // transported is completed in the callback this.WriteFrame(outcome, false); } else { this.CompleteTransport(); } }