Ejemplo n.º 1
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());
                }
            }
        //
        // 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()));
        }
Ejemplo n.º 3
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());
                }
            }
Ejemplo n.º 4
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());
      }