Commit 908f3a79 authored by Dave Cridland's avatar Dave Cridland

Handle and generate "=" as appropriate

Although the RFC doesn't explicitly appear to say this, the SASL profile for
XMPP has historically used "=" as a null indicator in all cases. This patch
builds on Christian's to ensure this is properly checked and handled in
challenge and client-sent cases.
parent cd0b4e69
......@@ -305,7 +305,7 @@ public class SASLAuthentication {
// Decode any data that is provided in the client response.
final String encoded = doc.getTextTrim();
final byte[] decoded;
if ( encoded == null || encoded.isEmpty() )
if ( encoded == null || encoded.isEmpty() || encoded.equals("=") ) // java SaslServer cannot handle a null.
{
decoded = new byte[ 0 ];
}
......@@ -404,19 +404,31 @@ public class SASLAuthentication {
return false;
}
private static void sendChallenge(Session session, byte[] challenge) {
private static void sendElement(Session session, String element, byte[] data) {
StringBuilder reply = new StringBuilder(250);
if (challenge == null) {
challenge = new byte[0];
reply.append("<");
reply.append(element);
reply.append(" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"");
if (data != null) {
reply.append(">");
String data_b64 = StringUtils.encodeBase64(data).trim();
if ("".equals(data_b64)) {
data_b64 = "=";
}
reply.append(data_b64);
reply.append("</");
reply.append(element);
reply.append(">");
} else {
reply.append("/>");
}
String challenge_b64 = StringUtils.encodeBase64(challenge).trim();
reply.append(
"<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
reply.append(challenge_b64);
reply.append("</challenge>");
session.deliverRawText(reply.toString());
}
private static void sendChallenge(Session session, byte[] challenge) {
sendElement(session, "challenge", challenge);
}
private static void authenticationSuccessful(LocalSession session, String username,
byte[] successData) {
if (username != null && LockOutManager.getInstance().isAccountDisabled(username)) {
......@@ -425,19 +437,7 @@ public class SASLAuthentication {
authenticationFailed(session, Failure.ACCOUNT_DISABLED);
return;
}
StringBuilder reply = new StringBuilder(80);
reply.append("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"");
if (successData != null) {
String successData_b64 = StringUtils.encodeBase64(successData).trim();
if ("".equals(successData_b64)) {
successData_b64 = "="; // Must be padded if null
}
reply.append('>').append(successData_b64).append("</success>");
}
else {
reply.append("/>");
}
session.deliverRawText( reply.toString() );
sendElement(session, "success", successData);
// We only support SASL for c2s
if (session instanceof ClientSession) {
((LocalClientSession) session).setAuthToken(new AuthToken(username));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment