Uploaded image for project: 'Shiro'
  1. Shiro
  2. SHIRO-458

Possible leaked timing information from DefaultPasswordService

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Trivial
    • Resolution: Resolved
    • 1.2.2
    • 1.5.0
    • Cryptography & Hashing
    • None
    • Mac OS X 10.8.3, Java 1.6.0_51

    Description

      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;
        }

      Attachments

        Activity

          People

            coheigea Colm O hEigeartaigh
            trisport88 Stuart Broad
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 20m
                1h 20m