public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider, bool isInitiator) { this.transport = transport; this.provider = provider; this.isInitiator = isInitiator; this.state = SaslNegotiator.SaslState.Start; }
private void HandleException(string action, Exception exception) { MessagingClientEtwProvider.TraceClient <SaslNegotiator, string, Exception>((SaslNegotiator source, string op, Exception ex) => MessagingClientEtwProvider.Provider.EventWriteAmqpLogError(source, op, ex.Message), this, action, exception); this.state = SaslNegotiator.SaslState.End; this.completeException = exception; this.CompleteTransport(); }
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); }
private void SendServerMechanisms() { List <AmqpSymbol> amqpSymbols = new List <AmqpSymbol>(); foreach (string mechanism in this.provider.Mechanisms) { amqpSymbols.Add(new AmqpSymbol(mechanism)); } SaslMechanisms saslMechanism = new SaslMechanisms() { SaslServerMechanisms = new Multiple <AmqpSymbol>(amqpSymbols) }; this.state = SaslNegotiator.SaslState.WaitingForInit; this.WriteFrame(saslMechanism, true); }
public bool Start() { this.reader = new AsyncIO.FrameBufferReader(this, this.transport); this.writer = new AsyncIO.AsyncBufferWriter(this.transport); if (this.isInitiator) { this.state = SaslNegotiator.SaslState.WaitingForServerMechanisms; MessagingClientEtwProvider.TraceClient <SaslNegotiator>((SaslNegotiator source) => { }, this); this.ReadFrame(); } else { this.SendServerMechanisms(); } return(false); }
public void CompleteNegotiation(SaslCode code, Exception exception) { this.state = SaslNegotiator.SaslState.End; this.completeException = exception; if (this.isInitiator) { this.CompleteTransport(); return; } SaslOutcome saslOutcome = new SaslOutcome() { OutcomeCode = new SaslCode?(code) }; if (code == SaslCode.Ok) { saslOutcome.AdditionalData = new ArraySegment <byte>(System.Text.Encoding.UTF8.GetBytes(SaslNegotiator.welcome)); } this.WriteFrame(saslOutcome, false); }
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); }