powered by Jive Software

Patch: Fix for broken SASL DIGEST-MD5 implementation

Hi folk, this is not my work but I'm passing it along.  Eric Sessoms send me the following patch which is working great!  Most importantly to me, it fixes the ability to use Smack to make DIGEST-MD5 based connections to ejabberd.  An explanation of how the conversation is supposed to occur can be found here: [http://web.archive.org/web/20050224191820/http://cataclysm.cx/wip/digest-md5-cra sh.html](http://web.archive.org/web/20050224191820/http://cataclysm.cx/wip/digest-md5-crash.html)

The patch itself is simple, and as follows:

--- source/org/jivesoftware/smack/sasl/SASLDigestMD5Mechanism.java
(revision 11014)
+++ source/org/jivesoftware/smack/sasl/SASLDigestMD5Mechanism.java
(working copy)
@@ -20,7 +20,10 @@ package org.jivesoftware.smack.sasl; import org.jivesoftware.smack.SASLAuthentication;
+import org.jivesoftware.smack.util.Base64; +import java.io.IOException;
+ /** * Implementation of the SASL DIGEST-MD5 mechanism *
@@ -35,4 +38,42 @@
    protected String getName() {
        return "DIGEST-MD5";
    }
+
+    /**
+     * The server is challenging the SASL mechanism for the stanza he
just sent. Send a
+     * response to the server's challenge.
+     *
+     * @param challenge a base64 encoded string representing the challenge.
+     * @throws IOException if an exception sending the response occurs.
+     */
+    public void challengeReceived(String challenge) throws IOException {
+        // Build the challenge response stanza encoding the response text
+        StringBuilder stanza = new StringBuilder();
+
+        byte response[];
+        if(challenge != null) {
+            response = sc.evaluateChallenge(Base64.decode(challenge));
+        } else {
+            response = sc.evaluateChallenge(null);
+        }
+
+        String authenticationText = null;
+        if (response != null) {
+           authenticationText =
Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
+            if(authenticationText.equals("")) {
+                authenticationText = "=";
+            }
+       }
+
+       if (authenticationText != null) {
+            stanza.append("<response
xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
+            stanza.append(authenticationText);
+            stanza.append("</response>");
+       } else {
+            stanza.append("<response
xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" />");
+       }
+
+        // Send the authentication to the server
+        getSASLAuthentication().send(stanza.toString());
+    } }

Hi Daniel,

Filed SMACK-275 for it.

daryl

Thanks Daryl!