directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r583457 - in /directory/studio/trunk/studio-ldapbrowser-core/src: main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java test/java/org/apache/directory/studio/ldapbrowser/core/model/PasswordTest.java
Date Wed, 10 Oct 2007 12:44:17 GMT
Author: pamarcelot
Date: Wed Oct 10 05:44:17 2007
New Revision: 583457

URL: http://svn.apache.org/viewvc?rev=583457&view=rev
Log:
Fix for DIRSTUDIO-220 (lowercase {crypt} in userPassword is an "Unsupported Hash Method").

Modified:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java
    directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/PasswordTest.java

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java?rev=583457&r1=583456&r2=583457&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/Password.java
Wed Oct 10 05:44:17 2007
@@ -111,26 +111,26 @@
             hashMethod = password.substring( password.indexOf( '{' ) + 1, password.indexOf(
'}' ) );
             String rest = password.substring( hashMethod.length() + 2 );
 
-            if ( HASH_METHOD_SHA.equals( hashMethod ) || HASH_METHOD_MD5.equals( hashMethod
) )
+            if ( HASH_METHOD_SHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_MD5.equalsIgnoreCase(
hashMethod ) )
             {
                 hashedPassword = LdifUtils.base64decodeToByteArray( rest );
                 salt = null;
             }
-            else if ( HASH_METHOD_SSHA.equals( hashMethod ) )
+            else if ( HASH_METHOD_SSHA.equalsIgnoreCase( hashMethod ) )
             {
                 byte[] hashedPasswordWithSalt = LdifUtils.base64decodeToByteArray( rest );
                 hashedPassword = new byte[20];
                 salt = new byte[hashedPasswordWithSalt.length - hashedPassword.length];
                 split( hashedPasswordWithSalt, hashedPassword, salt );
             }
-            else if ( HASH_METHOD_SMD5.equals( hashMethod ) )
+            else if ( HASH_METHOD_SMD5.equalsIgnoreCase( hashMethod ) )
             {
                 byte[] hashedPasswordWithSalt = LdifUtils.base64decodeToByteArray( rest );
                 hashedPassword = new byte[16];
                 salt = new byte[hashedPasswordWithSalt.length - hashedPassword.length];
                 split( hashedPasswordWithSalt, hashedPassword, salt );
             }
-            else if ( HASH_METHOD_CRYPT.equals( hashMethod ) )
+            else if ( HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) )
             {
                 byte[] saltWithPassword = LdifUtils.utf8encode( rest );
                 salt = new byte[2];
@@ -168,9 +168,9 @@
      */
     public Password( String hashMethod, String passwordAsPlaintext )
     {
-        if ( !( hashMethod == null || HASH_METHOD_NO.equals( hashMethod ) || HASH_METHOD_SHA.equals(
hashMethod )
-            || HASH_METHOD_SSHA.equals( hashMethod ) || HASH_METHOD_MD5.equals( hashMethod
)
-            || HASH_METHOD_SMD5.equals( hashMethod ) || HASH_METHOD_CRYPT.equals( hashMethod
) ) )
+        if ( !( hashMethod == null || HASH_METHOD_NO.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SHA.equalsIgnoreCase(
hashMethod )
+            || HASH_METHOD_SSHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_MD5.equalsIgnoreCase(
hashMethod )
+            || HASH_METHOD_SMD5.equalsIgnoreCase( hashMethod ) || HASH_METHOD_CRYPT.equalsIgnoreCase(
hashMethod ) ) )
         {
             throw new IllegalArgumentException( BrowserCoreMessages.model__unsupported_hash
);
         }
@@ -180,19 +180,19 @@
         }
 
         // set hash method
-        if ( HASH_METHOD_NO.equals( hashMethod ) )
+        if ( HASH_METHOD_NO.equalsIgnoreCase( hashMethod ) )
         {
             hashMethod = null;
         }
         this.hashMethod = hashMethod;
 
         // set salt
-        if ( HASH_METHOD_SSHA.equals( hashMethod ) || HASH_METHOD_SMD5.equals( hashMethod
) )
+        if ( HASH_METHOD_SSHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SMD5.equalsIgnoreCase(
hashMethod ) )
         {
             this.salt = new byte[8];
             new SecureRandom().nextBytes( this.salt );
         }
-        else if ( HASH_METHOD_CRYPT.equals( hashMethod ) )
+        else if ( HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) )
         {
             this.salt = new byte[2];
             SecureRandom sr = new SecureRandom();
@@ -207,15 +207,15 @@
         }
 
         // digest
-        if ( HASH_METHOD_SHA.equals( hashMethod ) || HASH_METHOD_SSHA.equals( hashMethod
) )
+        if ( HASH_METHOD_SHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SSHA.equalsIgnoreCase(
hashMethod ) )
         {
             this.hashedPassword = digest( HASH_METHOD_SHA, passwordAsPlaintext, this.salt
);
         }
-        else if ( HASH_METHOD_MD5.equals( hashMethod ) || HASH_METHOD_SMD5.equals( hashMethod
) )
+        else if ( HASH_METHOD_MD5.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SMD5.equalsIgnoreCase(
hashMethod ) )
         {
             this.hashedPassword = digest( HASH_METHOD_MD5, passwordAsPlaintext, this.salt
);
         }
-        else if ( HASH_METHOD_CRYPT.equals( hashMethod ) )
+        else if ( HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) )
         {
             this.hashedPassword = crypt( passwordAsPlaintext, this.salt );
         }
@@ -245,17 +245,17 @@
         {
             verified = testPasswordAsPlaintext.equals( LdifUtils.utf8decode( hashedPassword
) );
         }
-        else if ( HASH_METHOD_SHA.equals( hashMethod ) || HASH_METHOD_SSHA.equals( hashMethod
) )
+        else if ( HASH_METHOD_SHA.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SSHA.equalsIgnoreCase(
hashMethod ) )
         {
             byte[] hash = digest( HASH_METHOD_SHA, testPasswordAsPlaintext, salt );
             verified = equals( hash, hashedPassword );
         }
-        else if ( HASH_METHOD_MD5.equals( hashMethod ) || HASH_METHOD_SMD5.equals( hashMethod
) )
+        else if ( HASH_METHOD_MD5.equalsIgnoreCase( hashMethod ) || HASH_METHOD_SMD5.equalsIgnoreCase(
hashMethod ) )
         {
             byte[] hash = digest( HASH_METHOD_MD5, testPasswordAsPlaintext, salt );
             verified = equals( hash, hashedPassword );
         }
-        else if ( HASH_METHOD_CRYPT.equals( hashMethod ) )
+        else if ( HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) )
         {
             byte[] crypted = crypt( testPasswordAsPlaintext, salt );
             verified = equals( crypted, hashedPassword );
@@ -338,11 +338,11 @@
     {
         StringBuffer sb = new StringBuffer();
 
-        if ( HASH_METHOD_UNSUPPORTED.equals( hashMethod ) )
+        if ( HASH_METHOD_UNSUPPORTED.equalsIgnoreCase( hashMethod ) )
         {
             sb.append( trash );
         }
-        else if ( HASH_METHOD_CRYPT.equals( hashMethod ) )
+        else if ( HASH_METHOD_CRYPT.equalsIgnoreCase( hashMethod ) )
         {
             sb.append( '{' ).append( hashMethod ).append( '}' );
             sb.append( LdifUtils.utf8decode( salt ) );

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/PasswordTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/PasswordTest.java?rev=583457&r1=583456&r2=583457&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/PasswordTest.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/test/java/org/apache/directory/studio/ldapbrowser/core/model/PasswordTest.java
Wed Oct 10 05:44:17 2007
@@ -20,8 +20,10 @@
 
 package org.apache.directory.studio.ldapbrowser.core.model;
 
+
 import junit.framework.TestCase;
 
+
 /**
  * Test all the encryption algorithmes
  *
@@ -37,7 +39,7 @@
     {
         try
         {
-            new Password( (String)null );
+            new Password( ( String ) null );
             fail();
         }
         catch ( IllegalArgumentException iae )
@@ -45,57 +47,117 @@
             assertTrue( true );
         }
     }
-    
-    
+
+
     /**
      * 
      */
     public void testPasswordSHAEncrypted()
     {
         Password password = new Password( "{SHA}5en6G6MezRroT3XKqkdPOmY/BfQ=" );
-            
+
         assertTrue( password.verify( "secret" ) );
     }
 
+
+    /**
+     * 
+     */
+    public void testPasswordSHAEncryptedLowercase()
+    {
+        Password password = new Password( "{sha}5en6G6MezRroT3XKqkdPOmY/BfQ=" );
+
+        assertTrue( password.verify( "secret" ) );
+    }
+
+
     /**
      * 
      */
     public void testPasswordSSHAEncrypted()
     {
         Password password = new Password( "{SSHA}mjVVxasFkk59wMW4L1Ldt+YCblfhULHs03WW7g=="
);
-            
+
         assertTrue( password.verify( "secret" ) );
     }
 
+
+    /**
+     * 
+     */
+    public void testPasswordSSHAEncryptedLowercase()
+    {
+        Password password = new Password( "{ssha}mjVVxasFkk59wMW4L1Ldt+YCblfhULHs03WW7g=="
);
+
+        assertTrue( password.verify( "secret" ) );
+    }
+
+
     /**
      * 
      */
     public void testPasswordMD5Encrypted()
     {
         Password password = new Password( "{MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ==" );
-            
+
         assertTrue( password.verify( "secret" ) );
     }
 
+
+    /**
+     * 
+     */
+    public void testPasswordMD5EncryptedLowercase()
+    {
+        Password password = new Password( "{md5}Xr4ilOzQ4PCOq3aQ0qbuaQ==" );
+
+        assertTrue( password.verify( "secret" ) );
+    }
+
+
     /**
      * 
      */
     public void testPasswordSMD5Encrypted()
     {
         Password password = new Password( "{SMD5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
-            
+
         assertTrue( password.verify( "secret" ) );
     }
 
+
+    /**
+     * 
+     */
+    public void testPasswordSMD5EncryptedLowercase()
+    {
+        Password password = new Password( "{smd5}tQ9wo/VBuKsqBtylMMCcORbnYOJFMyDJ" );
+
+        assertTrue( password.verify( "secret" ) );
+    }
+
+
     /**
      * 
      */
     public void testPasswordCRYPTEncrypted()
     {
         Password password = new Password( "{CRYPT}qFkH8Z1woBlXw" );
-            
+
+        assertTrue( password.verify( "secret" ) );
+    }
+
+
+    /**
+     * 
+     */
+    public void testPasswordCRYPTEncryptedLowercase()
+    {
+        Password password = new Password( "{crypt}qFkH8Z1woBlXw" );
+
         assertTrue( password.verify( "secret" ) );
     }
+
 
     /**
      * 



Mime
View raw message