Example #1
0
        private void init(SASLOTPProfile otpProfile, UserDatabase db, System.String pwd, System.String authorizedId, System.String authenticateId)
        {
            log.debug("OTP Authenticator Initiator Construtor");

            authenticated = authenticateId;
            authorized = authorizedId;
            credential = new System.Collections.Hashtable();
            database = db;

            if (log.isDebugEnabled())
            {
                log.debug("Dict.getA()" + database.AlgorithmName);
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                log.debug("Dict.getA()" + SASLOTPProfile.getAlgorithm(database.AlgorithmName));
            }

            algorithm = SASLOTPProfile.getAlgorithm(database.AlgorithmName);
            profile = otpProfile;
            password = pwd;
            state = STATE_UNKNOWN;

            SupportClass.PutElement(credential, SessionCredential.AUTHENTICATOR_TYPE, SASLOTPProfile.MECHANISM);
            SupportClass.PutElement(credential, SessionCredential.ALGORITHM, algorithm.Name);
            SupportClass.PutElement(credential, SessionCredential.AUTHENTICATOR, authenticateId);

            if ((System.Object) authorizedId == null || authorizedId.Equals(""))
            {
                SupportClass.PutElement(credential, SessionCredential.AUTHORIZED, authenticateId);
            }
            else
            {
                SupportClass.PutElement(credential, SessionCredential.AUTHORIZED, authorizedId);
            }
        }
Example #2
0
        /// <summary> Listener API
        /// 
        /// Receive IDs, respond with a Challenge or Exception
        /// </summary>
        //UPGRADE_NOTE: Synchronized keyword was removed from method 'receiveIDs'. Lock expression was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1027"'
        internal virtual Blob receiveIDs(System.String data)
        {
            lock (this)
            {
                log.debug("OTP Authenticator Receiving IDs");

                // If we're listening, the last state we should
                // have gotten to was STATE_STARTED (after the channel start)
                if (state != STATE_STARTED)
                {
                    abort(ERR_OTP_STATE);
                }

                if (log.isDebugEnabled())
                {
                    log.debug("Data is" + data);
                }

                int i = data[0]; // data.indexOf(SPACE_CHAR);

                if (i == - 1)
                {
                    abort(ERR_IDENTITY_PARSE_FAILURE);
                }
                else if (i == 0)
                {
                    authorized = null;
                }
                else
                {
                    int index = 0;
                    try
                    {
                        index = data.IndexOf((System.Char) 0);
                        authorized = data.Substring(0, (index) - (0));
                    }
                    catch (System.Exception x)
                    //            catch(IndexOutOfBoundsException x)
                    {
                        authorized = null;
                    }
                }

                authenticated = data.Substring(data.IndexOf((System.Char) 0) + 1);
                if (!profile.validateIdentity(authenticated, this))
                {
                    abort(ERR_CONCURRENT);
                }

                if ((System.Object) authenticated == null)
                {
                    abort(ERR_NULL_ID);
                }

                if (log.isDebugEnabled())
                {
                    log.debug("Fetching DB for " + authenticated);
                }

                try
                {
                    database = SASLOTPProfile.UserDatabase.getUser(authenticated);
                    algorithm = SASLOTPProfile.getAlgorithm(database.AlgorithmName);
                }
                catch (SASLException x)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                    abort(x.Message);
                }

                SupportClass.PutElement(credential, SessionCredential.ALGORITHM, algorithm.Name);

                // @todo we may want to clear the DB on file or something here,
                // consider it as we consider how an abstract library and more
                // implementation specific configurations play together, a
                // SASLOTPDatabase interface or something (such as what's in the
                // database package below sasl.otp might be used.  I've got
                // update and stuff, but we may want 'purge', and then extentions
                // in the init method of SASLOTPProfile to potentially load different
                // UserDatabase managing 'things'...so someone can load something
                // other than UserDictionaryPool at init/config time and use it.
                if ((database.Sequence) == 0)
                {
                    abort(ERR_SEQUENCE_ZERO);
                }

                // Assign data
                state = STATE_ID;

                SupportClass.PutElement(credential, SessionCredential.AUTHENTICATOR, authenticated);

                if ((System.Object) authorized == null || authorized.Equals(""))
                {
                    SupportClass.PutElement(credential, SessionCredential.AUTHORIZED, authenticated);
                }
                else
                {
                    SupportClass.PutElement(credential, SessionCredential.AUTHORIZED, authorized);
                }

                SupportClass.PutElement(credential, SessionCredential.AUTHENTICATOR_TYPE, SASLOTPProfile.MECHANISM);

                System.Text.StringBuilder challenge = new System.Text.StringBuilder(128);

                challenge.Append(algorithm.Name);
                challenge.Append(SPACE);
                challenge.Append(database.Sequence);
                challenge.Append(SPACE);
                challenge.Append(database.Seed.ToLower());
                challenge.Append(SPACE);
                challenge.Append(EXT);
                if (log.isDebugEnabled())
                {
                    log.debug("Generated Challenge=>" + challenge.ToString());
                }

                try
                {
                    return new Blob(Blob.STATUS_NONE, challenge.ToString());
                }
                catch (System.Exception x)
                {
                }
                // This will throw a SASLException
                abort("Failed to issue SASL OTP challenge");
                return null;
            }
        }
Example #3
0
 /// <summary> Initiator API
 /// 
 /// ALL of the routines below are the Initiator calls.
 /// </summary>
 internal OTPAuthenticator(SASLOTPProfile otpProfile, UserDatabase db, System.String pwd, System.String authorizedId, System.String authenticateId)
 {
     InitBlock();
     init(otpProfile, db, pwd, authorizedId, authenticateId);
 }
Example #4
0
 // Weird init version
 internal OTPAuthenticator(SASLOTPProfile otpProfile, UserDatabase db, System.String pwd, System.String authorizedId, System.String authenticateId, System.String newAlgorithm, System.String newHash, System.String newSeed, System.String newSequence)
 {
     InitBlock();
     System.Text.StringBuilder sb = new System.Text.StringBuilder(128);
     sb.Append(COLON);
     sb.Append(newAlgorithm);
     sb.Append(SPACE);
     sb.Append(newSequence);
     sb.Append(SPACE);
     sb.Append(newSeed.ToLower());
     sb.Append(COLON);
     sb.Append(newHash);
     initData = sb.ToString();
     init(otpProfile, db, pwd, authorizedId, authenticateId);
 }
Example #5
0
        /// <summary> Listener API
        /// 
        /// All of the routines below, but prior to the Initiator API,
        /// are the Listener calls
        /// </summary>
        internal OTPAuthenticator(SASLOTPProfile otpProfile)
        {
            InitBlock();
            log.debug("Creating Listener OTP Authenticator");

            authenticated = null;
            authorized = null;
            credential = new System.Collections.Hashtable();
            database = null;
            password = null;
            profile = otpProfile;
            state = STATE_UNKNOWN;

            SupportClass.PutElement(credential, SessionCredential.AUTHENTICATOR_TYPE, SASLOTPProfile.MECHANISM);
        }