Пример #1
0
 public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider, bool isInitiator)
 {
     this.transport = transport;
     this.provider = provider;
     this.isInitiator = isInitiator;
     this.state = SaslState.Start;
 }
Пример #2
0
 public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider, bool isInitiator)
 {
     this.transport   = transport;
     this.provider    = provider;
     this.isInitiator = isInitiator;
     this.state       = SaslState.Start;
 }
Пример #3
0
 void HandleException(string action, Exception exception)
 {
     AmqpTrace.Provider.AmqpLogError(this, action, exception.Message);
     this.state             = SaslState.End;
     this.completeException = exception;
     this.CompleteTransport();
 }
Пример #4
0
        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);
            }
        }
Пример #5
0
 public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider)
 {
     this.transport = transport;
     this.provider = provider;
     this.onReadFrameComplete = this.OnReadFrameComplete;
     this.onWriteFrameComplete = this.OnWriteFrameComplete;
     this.state = SaslState.Start;
 }
Пример #6
0
 public SaslNegotiator(SaslTransport transport, SaslTransportProvider provider)
 {
     this.transport            = transport;
     this.provider             = provider;
     this.onReadFrameComplete  = this.OnReadFrameComplete;
     this.onWriteFrameComplete = this.OnWriteFrameComplete;
     this.state = SaslState.Start;
 }
Пример #7
0
        /// <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);
        }
Пример #8
0
        /// <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);
        }
Пример #9
0
 /// <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()));
     }
 }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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;
        }
Пример #14
0
        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);
        }
Пример #15
0
        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;
        }
Пример #16
0
        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();
            }
        }
Пример #17
0
        /// <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);
        }
Пример #18
0
        /// <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);
        }
Пример #19
0
        /// <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);
        }
Пример #20
0
        /// <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);
        }
Пример #21
0
        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);
        }
Пример #22
0
        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);
            }
        }
Пример #23
0
        /// <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);
        }
Пример #24
0
 /// <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()));
     }
 }
Пример #25
0
        /// <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);
        }
Пример #26
0
 void HandleException(string action, Exception exception)
 {
     AmqpTrace.Provider.AmqpLogError(this, action, exception.Message);
     this.state = SaslState.End;
     this.completeException = exception;
     this.CompleteTransport();
 }
Пример #27
0
        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);
        }
Пример #28
0
        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();
            }
        }