shiro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stuart Broad (JIRA)" <j...@apache.org>
Subject [jira] [Created] (SHIRO-458) Possible leaked timing information from DefaultPasswordService
Date Mon, 16 Sep 2013 09:17:51 GMT
Stuart Broad created SHIRO-458:
----------------------------------

             Summary: Possible leaked timing information from DefaultPasswordService
                 Key: SHIRO-458
                 URL: https://issues.apache.org/jira/browse/SHIRO-458
             Project: Shiro
          Issue Type: Bug
          Components: Cryptography & Hashing
    Affects Versions: 1.2.2
         Environment: Mac OS X 10.8.3, Java 1.6.0_51
            Reporter: Stuart Broad
            Priority: Trivial


Use of the String equals comparison for the password hash comparison could leak timing information
since it returns false as soon a character does not match.

DefaultPasswordService>>passwordsMatch(Object submittedPlaintext, String saved)

Last line is:

return saved.equals(formatted); //saved and formatted are strings

A possible constant time equals could be:

    private boolean constantEquals(String s1, String s2)
    {
        /*
         * Alternative option (simpler but I'm not sure about the intern 'cost'):
         * s1.intern();
         * s2.intern();
         * s1 == s2
         */
        int result = 0;
        byte[] a = s1.getBytes();
        byte[] b = s2.getBytes();

        // Also leaks timing information but probably ok...
        if (a.length != b.length) {
            return false;
        }

        /*
         * XOR each byte.  If each byte is the
         * same the XOR will result in 0.
         */
        for (int i = 0; i < a.length; i++) {
            result |= a[i] ^ b[i];
        }
        return result == 0;
    }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message