From c120bc1cbcc67dff1601dad0f9773a5936c3e30f Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 21 May 2015 22:20:30 +0200 Subject: [PATCH] Handle empty array in SASLMechanism.authenticate() like null array. Thanks to Anthony Sorvari for reporting. Fixes SMACK-670. --- .../java/org/jivesoftware/smack/sasl/SASLMechanism.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java index eba0d7045..3ac5a685b 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java @@ -195,7 +195,10 @@ public abstract class SASLMechanism implements Comparable { private final void authenticate() throws SmackException, NotConnectedException { byte[] authenticationBytes = getAuthenticationText(); String authenticationText; - if (authenticationBytes != null) { + // Some SASL mechanisms do return an empty array (e.g. EXTERNAL from javax), so check that + // the array is not-empty. Mechanisms are allowed to return either 'null' or an empty array + // if there is no authentication text. + if (authenticationBytes != null && authenticationBytes.length > 0) { authenticationText = Base64.encodeToString(authenticationBytes); } else { // RFC6120 6.4.2 "If the initiating entity needs to send a zero-length initial response, @@ -209,7 +212,8 @@ public abstract class SASLMechanism implements Comparable { /** * Should return the initial response of the SASL mechanism. The returned byte array will be - * send base64 encoded to the server. SASL mechanism are free to return null here. + * send base64 encoded to the server. SASL mechanism are free to return null or an + * empty array here. * * @return the initial response or null * @throws SmackException