Esempio n. 1
0
        public override byte[] EvaluateChallenge(byte[] challenge)
        {
            if (challenge == null || challenge.Length == 0)
            {
                throw new ArgumentNullException("challenge");
            }

            NameCallback     nameCB = new NameCallback(AuthorizationId);
            PasswordCallback pwdCB  = new PasswordCallback();

            ISaslCallback[] callbacks = { nameCB, pwdCB };
            Handler.Handle(callbacks);

            string username = nameCB.Text;
            string passwd   = pwdCB.Text.PadRight(MinPwdLen, '\0');

            byte[] secret = Encoding.UTF8.GetBytes(passwd);

            //using ( HMAC hmac = new HMACMD5(secret) )
            using (MD5HMAC hmac = new MD5HMAC(secret))
            {
                byte[] value   = hmac.ComputeHash(challenge);
                string encoded = ToHex(value);
                SetComplete();
                return(Encoding.UTF8.GetBytes(username + " " + encoded));
            }
        }
Esempio n. 2
0
        void ChangeNamesRecursive(
            Dictionary <Material, BrushDescriptor> lookup,
            NameCallback callback,
            Transform t)
        {
            var filter   = t.GetComponent <MeshFilter>();
            var renderer = t.GetComponent <MeshRenderer>();

            if (filter != null && renderer != null)
            {
                var mesh     = filter.sharedMesh;
                var material = renderer.sharedMaterial;
                if (mesh != null)
                {
                    BrushDescriptor desc;
                    if (lookup.TryGetValue(material, out desc))
                    {
                        string oldName = callback(desc);
                        mesh.name = oldName;
                        filter.gameObject.name = oldName;
                    }
                }
            }

            foreach (Transform child in t)
            {
                ChangeNamesRecursive(lookup, callback, child);
            }
        }
      public override byte[] EvaluateChallenge(byte[] challenge)
      {
        if ( challenge == null || challenge.Length == 0 )
            throw new ArgumentNullException("challenge");


        NameCallback nameCB = new NameCallback(AuthorizationId);
        PasswordCallback pwdCB = new PasswordCallback();
        ISaslCallback[] callbacks = { nameCB, pwdCB };
        Handler.Handle(callbacks);

        string username = nameCB.Text;
        
        //Encode the Hashed Password as Hex
        byte[] passwd = Encoding.UTF8.GetBytes(ToHex(pwdCB.HashedText));

        string s = System.Text.UTF8Encoding.UTF8.GetString(challenge);
        
        using ( HMAC hmac = new HMACMD5(passwd) )
         {
            byte[] value = hmac.ComputeHash(challenge);
            string encoded = ToHex(value);
            SetComplete();
            return Encoding.UTF8.GetBytes(username + " " + encoded);
         }
      }
Esempio n. 4
0
        public override byte[] EvaluateChallenge(byte[] challenge)
        {
            if (challenge == null || challenge.Length == 0)
            {
                throw new ArgumentNullException("challenge");
            }


            NameCallback     nameCB = new NameCallback(AuthorizationId);
            PasswordCallback pwdCB  = new PasswordCallback();

            ISaslCallback[] callbacks = { nameCB, pwdCB };
            Handler.Handle(callbacks);

            string username = nameCB.Text;

            //Encode the Hashed Password as Hex
            byte[] passwd = Encoding.UTF8.GetBytes(ToHex(pwdCB.HashedText));

            string s = System.Text.UTF8Encoding.UTF8.GetString(challenge);

            using (HMAC hmac = new HMACMD5(passwd))
            {
                byte[] value   = hmac.ComputeHash(challenge);
                string encoded = ToHex(value);
                SetComplete();
                return(Encoding.UTF8.GetBytes(username + " " + encoded));
            }
        }
Esempio n. 5
0
      public override byte[] EvaluateChallenge(byte[] challenge)
      {
         if ( challenge == null || challenge.Length == 0 )
            throw new ArgumentNullException("challenge");

         NameCallback nameCB = new NameCallback(AuthorizationId);
         PasswordCallback pwdCB = new PasswordCallback();
         ISaslCallback[] callbacks = { nameCB, pwdCB };
         Handler.Handle(callbacks);

         string username = nameCB.Text;
         string passwd = pwdCB.Text.PadRight(MinPwdLen, '\0');

         byte[] secret = Encoding.UTF8.GetBytes(passwd);

         //using ( HMAC hmac = new HMACMD5(secret) )
         using ( MD5HMAC hmac = new MD5HMAC(secret) )
         {
            byte[] value = hmac.ComputeHash(challenge);
            string encoded = ToHex(value);
            SetComplete();
            return Encoding.UTF8.GetBytes(username + " " + encoded);
         }

      }
Esempio n. 6
0
 /// <exception cref="Javax.Security.Sasl.SaslException"/>
 public virtual byte[] EvaluateResponse(byte[] response)
 {
     if (completed)
     {
         throw new InvalidOperationException("PLAIN authentication has completed");
     }
     if (response == null)
     {
         throw new ArgumentException("Received null response");
     }
     try
     {
         string payload;
         try
         {
             payload = Runtime.GetStringForBytes(response, "UTF-8");
         }
         catch (Exception e)
         {
             throw new ArgumentException("Received corrupt response", e);
         }
         // [ authz, authn, password ]
         string[] parts = payload.Split("\u0000", 3);
         if (parts.Length != 3)
         {
             throw new ArgumentException("Received corrupt response");
         }
         if (parts[0].IsEmpty())
         {
             // authz = authn
             parts[0] = parts[1];
         }
         NameCallback nc = new NameCallback("SASL PLAIN");
         nc.SetName(parts[1]);
         PasswordCallback pc = new PasswordCallback("SASL PLAIN", false);
         pc.SetPassword(parts[2].ToCharArray());
         AuthorizeCallback ac = new AuthorizeCallback(parts[1], parts[0]);
         cbh.Handle(new Javax.Security.Auth.Callback.Callback[] { nc, pc, ac });
         if (ac.IsAuthorized())
         {
             authz = ac.GetAuthorizedID();
         }
     }
     catch (Exception e)
     {
         throw new SaslException("PLAIN auth failed: " + e.Message);
     }
     finally
     {
         completed = true;
     }
     return(null);
 }
Esempio n. 7
0
            /// <exception cref="System.IO.IOException"/>
            /// <exception cref="Javax.Security.Auth.Callback.UnsupportedCallbackException"/>
            public void Handle(Javax.Security.Auth.Callback.Callback[] callbacks)
            {
                NameCallback     nc = null;
                PasswordCallback pc = null;
                RealmCallback    rc = null;

                foreach (Javax.Security.Auth.Callback.Callback callback in callbacks)
                {
                    if (callback is RealmChoiceCallback)
                    {
                        continue;
                    }
                    else
                    {
                        if (callback is NameCallback)
                        {
                            nc = (NameCallback)callback;
                        }
                        else
                        {
                            if (callback is PasswordCallback)
                            {
                                pc = (PasswordCallback)callback;
                            }
                            else
                            {
                                if (callback is RealmCallback)
                                {
                                    rc = (RealmCallback)callback;
                                }
                                else
                                {
                                    throw new UnsupportedCallbackException(callback, "Unrecognized SASL client callback"
                                                                           );
                                }
                            }
                        }
                    }
                }
                if (nc != null)
                {
                    nc.SetName(userName);
                }
                if (pc != null)
                {
                    pc.SetPassword(password);
                }
                if (rc != null)
                {
                    rc.SetText(rc.GetDefaultText());
                }
            }
            /// <exception cref="System.IO.IOException"/>
            /// <exception cref="Javax.Security.Auth.Callback.UnsupportedCallbackException"/>
            public void Handle(Javax.Security.Auth.Callback.Callback[] callbacks)
            {
                NameCallback      nc = null;
                PasswordCallback  pc = null;
                AuthorizeCallback ac = null;

                foreach (Javax.Security.Auth.Callback.Callback callback in callbacks)
                {
                    if (callback is AuthorizeCallback)
                    {
                        ac = (AuthorizeCallback)callback;
                    }
                    else
                    {
                        if (callback is PasswordCallback)
                        {
                            pc = (PasswordCallback)callback;
                        }
                        else
                        {
                            if (callback is NameCallback)
                            {
                                nc = (NameCallback)callback;
                            }
                            else
                            {
                                if (callback is RealmCallback)
                                {
                                    continue;
                                }
                                else
                                {
                                    // realm is ignored
                                    throw new UnsupportedCallbackException(callback, "Unrecognized SASL DIGEST-MD5 Callback: "
                                                                           + callback);
                                }
                            }
                        }
                    }
                }
                if (pc != null)
                {
                    pc.SetPassword(passwordFunction.Apply(nc.GetDefaultName()));
                }
                if (ac != null)
                {
                    ac.SetAuthorized(true);
                    ac.SetAuthorizedID(ac.GetAuthorizationID());
                }
            }
        //
        // Private Methods
        //

        /// <summary>
        /// Process the first challenge from the server
        /// and calculate a response
        /// </summary>
        /// <param name="challenge">The server issued challenge</param>
        /// <returns>Client response</returns>
        private byte[] OnInitialChallenge(byte[] challenge)
        {
            DigestChallenge dch =
                DigestChallenge.Parse(_encoding.GetString(challenge));

            // validate input challenge
            if (dch.Nonce == null || dch.Nonce.Length == 0)
            {
                throw new SaslException("Nonce value missing in server challenge");
            }
            if (dch.Algorithm != "md5-sess")
            {
                throw new SaslException("Invalid or missing algorithm value in server challenge");
            }


            NameCallback     nameCB  = new NameCallback(AuthorizationId);
            PasswordCallback pwdCB   = new PasswordCallback();
            RealmCallback    realmCB = new RealmCallback(dch.Realm);

            ISaslCallback[] callbacks = { nameCB, pwdCB, realmCB };
            Handler.Handle(callbacks);

            DigestResponse response = new DigestResponse();

            response.Username   = nameCB.Text;
            response.Realm      = realmCB.Text;
            response.Nonce      = dch.Nonce;
            response.Cnonce     = Cnonce;
            response.NonceCount = 1;
            response.Qop        = DigestQop.Auth; // only auth supported for now
            response.DigestUri  = Protocol.ToLower() + "/" + ServerName;
            response.MaxBuffer  = dch.MaxBuffer;
            response.Charset    = dch.Charset;
            response.Cipher     = null; // not supported for now
            response.Authzid    = AuthorizationId;
            response.AuthParam  = dch.AuthParam;

            response.Response = CalculateResponse(
                nameCB.Text, realmCB.Text, pwdCB.Text,
                dch.Nonce, response.NonceCount, response.Qop, response.DigestUri
                );

            return(_encoding.GetBytes(response.ToString()));
        }
Esempio n. 10
0
      public override byte[] EvaluateChallenge(byte[] challenge)
      {
         // ignore challenge

         NameCallback nameCB = new NameCallback();
         PasswordCallback pwdCB = new PasswordCallback();
         ISaslCallback[] callbacks = { nameCB, pwdCB };
         Handler.Handle(callbacks);

         string username = nameCB.Text;
         string authid = AuthorizationId;
         string passwd = pwdCB.Text;

         string response = 
            string.Format("{0}\0{1}\0{2}", authid, username, passwd);
         SetComplete();
         return Encoding.UTF8.GetBytes(response);
      }
Esempio n. 11
0
        public override byte[] EvaluateChallenge(byte[] challenge)
        {
            // ignore challenge

            NameCallback     nameCB = new NameCallback();
            PasswordCallback pwdCB  = new PasswordCallback();

            ISaslCallback[] callbacks = { nameCB, pwdCB };
            Handler.Handle(callbacks);

            string username = nameCB.Text;
            string authid   = AuthorizationId;
            string passwd   = pwdCB.Text;

            string response =
                string.Format("{0}\0{1}\0{2}", authid, username, passwd);

            SetComplete();
            return(Encoding.UTF8.GetBytes(response));
        }
 public void handle(Callback [] callbacks)
 {
     for (int i = 0; i < callbacks.Length; i++)
     {
         if (callbacks [i] is NameCallback)
         {
             NameCallback nc = (NameCallback)callbacks [i];
             nc.setName(_username);
         }
         else if (callbacks [i] is PasswordCallback)
         {
             PasswordCallback pc = (PasswordCallback)callbacks [i];
             pc.setPassword(_password.ToCharArray());
         }
         else
         {
             throw new UnsupportedCallbackException(callbacks [i], "Unrecognized Callback");
         }
     }
 }
Esempio n. 13
0
            /// <exception cref="Javax.Security.Auth.Callback.UnsupportedCallbackException"/>
            public virtual void Handle(Javax.Security.Auth.Callback.Callback[] callbacks)
            {
                NameCallback     nc = null;
                PasswordCallback pc = null;
                RealmCallback    rc = null;

                foreach (Javax.Security.Auth.Callback.Callback callback in callbacks)
                {
                    if (callback is RealmChoiceCallback)
                    {
                        continue;
                    }
                    else
                    {
                        if (callback is NameCallback)
                        {
                            nc = (NameCallback)callback;
                        }
                        else
                        {
                            if (callback is PasswordCallback)
                            {
                                pc = (PasswordCallback)callback;
                            }
                            else
                            {
                                if (callback is RealmCallback)
                                {
                                    rc = (RealmCallback)callback;
                                }
                                else
                                {
                                    throw new UnsupportedCallbackException(callback, "Unrecognized SASL client callback"
                                                                           );
                                }
                            }
                        }
                    }
                }
                if (nc != null)
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("SASL client callback: setting username: "******"SASL client callback: setting userPassword");
                    }
                    pc.SetPassword(userPassword);
                }
                if (rc != null)
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("SASL client callback: setting realm: " + rc.GetDefaultText());
                    }
                    rc.SetText(rc.GetDefaultText());
                }
            }
Esempio n. 14
0
            /// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken"/>
            /// <exception cref="Javax.Security.Auth.Callback.UnsupportedCallbackException"/>
            /// <exception cref="Org.Apache.Hadoop.Ipc.StandbyException"/>
            /// <exception cref="Org.Apache.Hadoop.Ipc.RetriableException"/>
            /// <exception cref="System.IO.IOException"/>
            public virtual void Handle(Javax.Security.Auth.Callback.Callback[] callbacks)
            {
                NameCallback      nc = null;
                PasswordCallback  pc = null;
                AuthorizeCallback ac = null;

                foreach (Javax.Security.Auth.Callback.Callback callback in callbacks)
                {
                    if (callback is AuthorizeCallback)
                    {
                        ac = (AuthorizeCallback)callback;
                    }
                    else
                    {
                        if (callback is NameCallback)
                        {
                            nc = (NameCallback)callback;
                        }
                        else
                        {
                            if (callback is PasswordCallback)
                            {
                                pc = (PasswordCallback)callback;
                            }
                            else
                            {
                                if (callback is RealmCallback)
                                {
                                    continue;
                                }
                                else
                                {
                                    // realm is ignored
                                    throw new UnsupportedCallbackException(callback, "Unrecognized SASL DIGEST-MD5 Callback"
                                                                           );
                                }
                            }
                        }
                    }
                }
                if (pc != null)
                {
                    TokenIdentifier tokenIdentifier = GetIdentifier(nc.GetDefaultName(), secretManager
                                                                    );
                    char[] password           = GetPassword(tokenIdentifier);
                    UserGroupInformation user = null;
                    user = tokenIdentifier.GetUser();
                    // may throw exception
                    connection.attemptingUser = user;
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("SASL server DIGEST-MD5 callback: setting password " + "for client: " +
                                  tokenIdentifier.GetUser());
                    }
                    pc.SetPassword(password);
                }
                if (ac != null)
                {
                    string authid  = ac.GetAuthenticationID();
                    string authzid = ac.GetAuthorizationID();
                    if (authid.Equals(authzid))
                    {
                        ac.SetAuthorized(true);
                    }
                    else
                    {
                        ac.SetAuthorized(false);
                    }
                    if (ac.IsAuthorized())
                    {
                        if (Log.IsDebugEnabled())
                        {
                            string username = GetIdentifier(authzid, secretManager).GetUser().GetUserName();
                            Log.Debug("SASL server DIGEST-MD5 callback: setting " + "canonicalized client ID: "
                                      + username);
                        }
                        ac.SetAuthorizedID(authzid);
                    }
                }
            }
Esempio n. 15
0
      //
      // Private Methods
      //

      /// <summary>
      /// Process the first challenge from the server
      /// and calculate a response
      /// </summary>
      /// <param name="challenge">The server issued challenge</param>
      /// <returns>Client response</returns>
      private byte[] OnInitialChallenge(byte[] challenge)
      {
         DigestChallenge dch = 
            DigestChallenge.Parse(_encoding.GetString(challenge));
         // validate input challenge
         if ( dch.Nonce == null || dch.Nonce.Length == 0 )
            throw new SaslException("Nonce value missing in server challenge");
         if ( dch.Algorithm != "md5-sess" )
            throw new SaslException("Invalid or missing algorithm value in server challenge");


         NameCallback nameCB = new NameCallback(AuthorizationId);
         PasswordCallback pwdCB = new PasswordCallback();
         RealmCallback realmCB = new RealmCallback(dch.Realm);
         ISaslCallback[] callbacks = { nameCB, pwdCB, realmCB };
         Handler.Handle(callbacks);

         DigestResponse response = new DigestResponse();
         response.Username = nameCB.Text;
         response.Realm = realmCB.Text;
         response.Nonce = dch.Nonce;
         response.Cnonce = Cnonce;
         response.NonceCount = 1;
         response.Qop = DigestQop.Auth; // only auth supported for now
         response.DigestUri = Protocol.ToLower() + "/" + ServerName;
         response.MaxBuffer = dch.MaxBuffer;
         response.Charset = dch.Charset;
         response.Cipher = null; // not supported for now
         response.Authzid = AuthorizationId;
         response.AuthParam = dch.AuthParam;

         response.Response = CalculateResponse(
            nameCB.Text, realmCB.Text, pwdCB.Text, 
            dch.Nonce, response.NonceCount, response.Qop, response.DigestUri
            );

         return _encoding.GetBytes(response.ToString());
      }