yoavs 2004/10/27 09:26:19
Modified: catalina/src/share/org/apache/catalina/realm Tag: TOMCAT_5_0
RealmBase.java
webapps/docs Tag: TOMCAT_5_0 changelog.xml
webapps/docs/config Tag: TOMCAT_5_0 realm.xml
Log:
Bugzilla 31592: allow digestEncoding to be specified.
Revision Changes Path
No revision
No revision
1.33.2.2 +66 -5
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.33.2.1
retrieving revision 1.33.2.2
diff -u -r1.33.2.1 -r1.33.2.2
--- RealmBase.java 30 Aug 2004 20:27:35 -0000 1.33.2.1
+++ RealmBase.java 27 Oct 2004 16:26:18 -0000 1.33.2.2
@@ -21,6 +21,7 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
@@ -91,6 +92,12 @@
*/
protected String digest = null;
+ /**
+ * The digest encoding charset. Null (the default)
+ * means use the platform default encoding.
+ */
+ protected String digestEncoding = null;
+
/**
* Descriptive information about this Realm implementation.
@@ -217,6 +224,24 @@
}
+ /**
+ * Returns the digest encoding charset.
+ *
+ * @return The digest (null means platform default)
+ */
+ public String getDigestEncoding() {
+ return digestEncoding;
+ }
+
+ /**
+ * Sets the digest encoding charset.
+ *
+ * @param charset The charset (null means platform default)
+ */
+ public void setDigestEncoding(String charset) {
+ digestEncoding = charset;
+ }
+
/**
* Return descriptive information about this Realm implementation and
@@ -342,9 +367,21 @@
return null;
String serverDigestValue = md5a1 + ":" + nOnce + ":" + nc + ":"
+ cnonce + ":" + qop + ":" + md5a2;
+
+ byte[] valueBytes = null;
+ if(getDigestEncoding() == null) {
+ valueBytes = serverDigestValue.getBytes();
+ } else {
+ try {
+ valueBytes = serverDigestValue.getBytes(getDigestEncoding());
+ } catch (UnsupportedEncodingException uee) {
+ uee.printStackTrace();
+ throw new IllegalArgumentException("Illegal encoding: " +
getDigestEncoding());
+ }
+ }
+
String serverDigest =
- md5Encoder.encode(md5Helper.digest(serverDigestValue.getBytes()));
- //System.out.println("Server digest : " + serverDigest);
+ md5Encoder.encode(md5Helper.digest(valueBytes));
if (serverDigest.equals(clientDigest))
return getPrincipal(username);
@@ -1019,7 +1056,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);
@@ -1047,8 +1092,21 @@
}
String digestValue = username + ":" + realmName + ":"
+ getPassword(username);
+
+ byte[] valueBytes = null;
+ if(getDigestEncoding() == null) {
+ valueBytes = digestValue.getBytes();
+ } else {
+ try {
+ valueBytes = digestValue.getBytes(getDigestEncoding());
+ } catch (UnsupportedEncodingException uee) {
+ uee.printStackTrace();
+ throw new IllegalArgumentException("Illegal encoding: " +
getDigestEncoding());
+ }
+ }
+
byte[] digest =
- md5Helper.digest(digestValue.getBytes());
+ md5Helper.digest(valueBytes);
return md5Encoder.encode(digest);
}
@@ -1137,8 +1195,11 @@
// Obtain a new message digest with "digest" encryption
MessageDigest md =
(MessageDigest) MessageDigest.getInstance(algorithm).clone();
+
// encode the credentials
+ // Should use digestEncoding but this is a static method
md.update(credentials.getBytes());
+
// Digest the credentials and return as hexadecimal
return (HexUtils.convert(md.digest()));
} catch(Exception ex) {
No revision
No revision
1.70.2.58 +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.70.2.57
retrieving revision 1.70.2.58
diff -u -r1.70.2.57 -r1.70.2.58
--- changelog.xml 25 Oct 2004 19:20:11 -0000 1.70.2.57
+++ changelog.xml 27 Oct 2004 16:26:18 -0000 1.70.2.58
@@ -31,6 +31,9 @@
<fix>
<bug>31623</bug>: Better OS400 support in setclasspath.sh. (yoavs)
</fix>
+ <fix>
+ <bug>31592</bug>: Allow specification of digest encoding for realms. (yoavs)
+ </fix>
</changelog>
</subsection>
No revision
No revision
1.5.2.2 +5 -0 jakarta-tomcat-catalina/webapps/docs/config/realm.xml
Index: realm.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/config/realm.xml,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- realm.xml 10 Oct 2004 20:42:32 -0000 1.5.2.1
+++ realm.xml 27 Oct 2004 16:26:19 -0000 1.5.2.2
@@ -111,6 +111,11 @@
to encode user passwords stored in the database. If not specified,
user passwords are assumed to be stored in clear-text.</p>
</attribute>
+
+ <attribute name="digestEncoding" required="false">
+ <p>The charset to use when encoding digests. If not specified,
+ the platform default encoding is used.</p>
+ </attribute>
<attribute name="driverName" required="true">
<p>Fully qualified Java class name of the JDBC driver to be
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]