コード例 #1
0
ファイル: SaslSwtHandler.cs プロジェクト: modulexcite/IL2JS
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: SaslPlainHandler.cs プロジェクト: modulexcite/IL2JS
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 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);
 }
コード例 #8
0
        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);
        }
コード例 #9
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);
        }
コード例 #10
0
 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);
     }
 }
コード例 #11
0
ファイル: SaslPlainHandler.cs プロジェクト: modulexcite/IL2JS
 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);
     }
 }
コード例 #12
0
 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);
 }
コード例 #13
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);
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
 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);
     }
 }
コード例 #17
0
ファイル: SaslHandler.cs プロジェクト: modulexcite/IL2JS
        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);
            }
        }
コード例 #18
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);
        }
コード例 #19
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);
        }
コード例 #20
0
ファイル: SaslHandler.cs プロジェクト: modulexcite/IL2JS
 protected abstract void OnStart(SaslInit init, bool isClient);
コード例 #21
0
 protected abstract void OnStart(SaslInit init, bool isClient);
コード例 #22
0
ファイル: SaslNegotiator.cs プロジェクト: modulexcite/IL2JS
        /// <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);
        }
コード例 #23
0
ファイル: SaslNegotiator.cs プロジェクト: modulexcite/IL2JS
        /// <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);
        }