yoavs       2004/10/27 08:56:58

  Modified:    catalina/src/share/org/apache/catalina/realm RealmBase.java
               webapps/docs changelog.xml
  Log:
  Bugzilla 31592: allow specified encoding for digest.
  
  Revision  Changes    Path
  1.42      +36 -7     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java
  
  Index: RealmBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- RealmBase.java    25 Oct 2004 18:31:57 -0000      1.41
  +++ RealmBase.java    27 Oct 2004 15:56:57 -0000      1.42
  @@ -84,6 +84,11 @@
        */
       protected String digest = null;
   
  +    /**
  +     * The encoding charset for the digest.
  +     */
  +    protected String digestEncoding = null;
  +
   
       /**
        * Descriptive information about this Realm implementation.
  @@ -188,6 +193,23 @@
   
       }
   
  +    /**
  +     * Returns the digest encoding charset.
  +     *
  +     * @return The charset (may be null) for platform default
  +     */
  +    public String getDigestEncoding() {
  +        return digestEncoding;
  +    }
  +
  +    /**
  +     * Sets the digest encoding charset.
  +     *
  +     * @param charset The charset (null for platform default)
  +     */
  +    public void setDigestEncoding(String charset) {
  +        digestEncoding = charset;
  +    }
   
       /**
        * Return descriptive information about this Realm implementation and
  @@ -982,10 +1004,6 @@
        * convert the result to a corresponding hexadecimal string.
        * If exception, the plain credentials string is returned.
        *
  -     * <strong>IMPLEMENTATION NOTE</strong> - This implementation is
  -     * synchronized because it reuses the MessageDigest instance.
  -     * This should be faster than cloning the instance on every request.
  -     *
        * @param credentials Password or other credentials to use in
        *  authenticating this username
        */
  @@ -999,7 +1017,15 @@
           synchronized (this) {
               try {
                   md.reset();
  -                md.update(credentials.getBytes());
  +    
  +                byte[] bytes = null;
  +                if(getDigestEncoding() == null) {
  +                    bytes = credentials.getBytes();
  +                } else {
  +                    bytes = credentials.getBytes(getDigestEncoding());
  +                }
  +                md.update(bytes);
  +
                   return (HexUtils.convert(md.digest()));
               } catch (Exception e) {
                   log.error(sm.getString("realmBase.digest"), e);
  @@ -1068,7 +1094,7 @@
        *
        * @param credentials Password or other credentials to use in
        *  authenticating this username
  -     * @param algorithm Algorithm used to do th digest
  +     * @param algorithm Algorithm used to do the digest
        */
       public final static String Digest(String credentials, String algorithm) {
   
  @@ -1076,8 +1102,11 @@
               // Obtain a new message digest with "digest" encryption
               MessageDigest md =
                   (MessageDigest) MessageDigest.getInstance(algorithm).clone();
  +
               // encode the credentials
  +            // Should use the digestEncoding, but that's not a static field
               md.update(credentials.getBytes());
  +
               // Digest the credentials and return as hexadecimal
               return (HexUtils.convert(md.digest()));
           } catch(Exception ex) {
  
  
  
  1.156     +3 -0      jakarta-tomcat-catalina/webapps/docs/changelog.xml
  
  Index: changelog.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/changelog.xml,v
  retrieving revision 1.155
  retrieving revision 1.156
  diff -u -r1.155 -r1.156
  --- changelog.xml     27 Oct 2004 14:42:14 -0000      1.155
  +++ changelog.xml     27 Oct 2004 15:56:57 -0000      1.156
  @@ -96,6 +96,9 @@
           Prevent silent NPEs during StandardContext.start dealing with JMX 
registration of realm, submitted
           by Keith Wannamaker. (remm)
         </fix>
  +      <fix>
  +        <bug>31592</bug>: Support other encodings for digests. (yoavs)
  +      </fix>
       </changelog>
     </subsection>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to