User: starksm 
  Date: 01/12/28 20:32:21

  Modified:    src/main/org/jboss/security Tag: Branch_2_4 Util.java
  Added:       src/main/org/jboss/security Tag: Branch_2_4
                        Base64Encoder.java
  Log:
  Integrate the password hash from main into UsernamePasswordLoginModule
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.4.2   +57 -6     jbosssx/src/main/org/jboss/security/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/security/Util.java,v
  retrieving revision 1.1.4.1
  retrieving revision 1.1.4.2
  diff -u -r1.1.4.1 -r1.1.4.2
  --- Util.java 2001/11/09 10:21:46     1.1.4.1
  +++ Util.java 2001/12/29 04:32:21     1.1.4.2
  @@ -20,13 +20,14 @@
    Jhong for the SRP Distribution (http://srp.stanford.edu/srp/).
    
    @author [EMAIL PROTECTED]
  - @version $Revision: 1.1.4.1 $
  + @version $Revision: 1.1.4.2 $
    */
   public class Util
   {
      private static final int HASH_LEN = 20;
      private static final char[] base64Table =
      "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./".toCharArray();
  +
      private static SecureRandom psuedoRng;
      private static MessageDigest sha1Digest;
      private static boolean initialized;
  @@ -221,11 +222,56 @@
            result[i] = (byte) (b1[i] ^ b2[i]);
         return result;
      }
  -   
  +
  +   /**
  +    * Hex encoding of hashes, as used by Catalina. Each byte is converted to
  +    * the corresponding two hex characters.
  +    */
  +   public static String encodeBase16(byte[] bytes)
  +   {
  +      StringBuffer sb = new StringBuffer(bytes.length * 2);
  +      for (int i = 0; i < bytes.length; i++)
  +      {
  +         byte b = bytes[i];
  +         // top 4 bits
  +         char c = (char)((b >> 4) & 0xf);
  +         if(c > 9)
  +            c = (char)((c - 10) + 'a');
  +         else
  +            c = (char)(c + '0');
  +         sb.append(c);
  +         // bottom 4 bits
  +         c = (char)(b & 0xf);
  +         if (c > 9)
  +            c = (char)((c - 10) + 'a');
  +         else
  +            c = (char)(c + '0');
  +         sb.append(c);
  +      }
  +      return sb.toString();
  +   }
  +
  +   /**
  +    * BASE64 encoder implementation.
  +    * Provides encoding methods, using the BASE64 encoding rules, as defined
  +    * in the MIME specification, <a 
href="http://ietf.org/rfc/rfc1521.txt";>rfc1521</a>.
  +    */
  +   public static String encodeBase64(byte[] bytes)
  +   {
  +      String base64 = null;
  +      try
  +      {
  +         base64 = Base64Encoder.encode(bytes);
  +      }
  +      catch(Exception e)
  +      {
  +      }
  +      return base64;
  +   }
  +
      // These functions assume that the byte array has MSB at 0, LSB at end.
      // Reverse the byte array (not the String) if this is not the case.
      // All base64 strings are in natural order, least significant digit last.
  -   
      public static String tob64(byte[] buffer)
      {
         boolean notleading = false;
  @@ -272,13 +318,18 @@
            if(pos >= len)
               break;
            else
  +         {
               try
               {
                  b0 = buffer[pos++];
                  b1 = buffer[pos++];
                  b2 = buffer[pos++];
  -            } catch(ArrayIndexOutOfBoundsException e)
  -            { break; }
  +            }
  +            catch(ArrayIndexOutOfBoundsException e)
  +            {
  +               break;
  +            }
  +         }
         } while(true);
         
         if(notleading)
  @@ -286,7 +337,7 @@
         else
            return "0";
      }
  -   
  +
      public static byte[] fromb64(String str) throws NumberFormatException
      {
         int len = str.length();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +3 -4      jbosssx/src/main/org/jboss/security/Base64Encoder.java
  
  Index: Base64Encoder.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/security/Base64Encoder.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- Base64Encoder.java        2001/12/20 00:58:34     1.2
  +++ Base64Encoder.java        2001/12/29 04:32:21     1.2.2.1
  @@ -1,6 +1,5 @@
  +package org.jboss.security;
   
  -package org.jboss.security; // for the time being ...
  -
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
  @@ -237,7 +236,8 @@
            }
         }
         // Manage the last bytes, from 0 to off:
  -      switch (off) {
  +      switch (off)
  +      {
           case 1:
               out.write(encoding[get1(buffer, 0)]);
               out.write(encoding[get2(buffer, 0)]);
  @@ -253,4 +253,3 @@
         return;
      }
   }
  -
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to