Beispiel #1
0
 public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider, bool isInitiator)
 {
     this.transport   = transport;
     this.provider    = provider;
     this.isInitiator = isInitiator;
     this.state       = SaslNegotiator.SaslState.Start;
 }
Beispiel #2
0
 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();
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 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);
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }