Commit d064c3ee authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed base64 encoding problem. JM-644

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3784 b35dd754-fafc-0310-a699-88a17e54d16e
parent 73c80095
...@@ -203,7 +203,6 @@ public class StringUtils { ...@@ -203,7 +203,6 @@ public class StringUtils {
for (; i < len; i++) { for (; i < len; i++) {
ch = input[i]; ch = input[i];
if (ch > '>') { if (ch > '>') {
continue;
} }
else if (ch == '<') { else if (ch == '<') {
if (i + 3 < len && input[i + 1] == 'b' && input[i + 2] == 'r' && input[i + 3] == '>') { if (i + 3 < len && input[i + 1] == 'b' && input[i + 2] == 'r' && input[i + 3] == '>') {
...@@ -250,7 +249,6 @@ public class StringUtils { ...@@ -250,7 +249,6 @@ public class StringUtils {
for (; i < len; i++) { for (; i < len; i++) {
ch = input[i]; ch = input[i];
if (ch > '>') { if (ch > '>') {
continue;
} }
else if (ch == '<') { else if (ch == '<') {
if (i > last) { if (i > last) {
...@@ -425,7 +423,7 @@ public class StringUtils { ...@@ -425,7 +423,7 @@ public class StringUtils {
public static String encodeBase64(String data) { public static String encodeBase64(String data) {
byte[] bytes = null; byte[] bytes = null;
try { try {
bytes = data.getBytes("ISO-8859-1"); bytes = data.getBytes("UTF-8");
} }
catch (UnsupportedEncodingException uee) { catch (UnsupportedEncodingException uee) {
Log.error(uee); Log.error(uee);
...@@ -453,14 +451,8 @@ public class StringUtils { ...@@ -453,14 +451,8 @@ public class StringUtils {
* @param data a base64 encoded String to decode. * @param data a base64 encoded String to decode.
* @return the decoded String. * @return the decoded String.
*/ */
public static String decodeBase64(String data) { public static byte[] decodeBase64(String data) {
byte [] bytes = Base64.decode(data); return Base64.decode(data);
try {
return new String(bytes, "UTF-8");
}
catch (UnsupportedEncodingException uee) {
return new String(bytes);
}
} }
/** /**
...@@ -754,7 +746,6 @@ public class StringUtils { ...@@ -754,7 +746,6 @@ public class StringUtils {
for (; i < len; i++) { for (; i < len; i++) {
ch = input[i]; ch = input[i];
if (ch > '>') { if (ch > '>') {
continue;
} }
else if (ch == '<') { else if (ch == '<') {
if (i > last) { if (i > last) {
......
...@@ -165,8 +165,7 @@ public class SASLAuthentication { ...@@ -165,8 +165,7 @@ public class SASLAuthentication {
byte[] token = new byte[0]; byte[] token = new byte[0];
if (doc.isTextOnly()) { if (doc.isTextOnly()) {
// If auth request includes a value then validate it // If auth request includes a value then validate it
token = StringUtils.decodeBase64(doc.getText()) token = StringUtils.decodeBase64(doc.getText());
.getBytes(CHARSET);
if (token == null) { if (token == null) {
token = new byte[0]; token = new byte[0];
} }
...@@ -190,7 +189,7 @@ public class SASLAuthentication { ...@@ -190,7 +189,7 @@ public class SASLAuthentication {
boolean ssComplete = ss.isComplete(); boolean ssComplete = ss.isComplete();
String response = doc.getTextTrim(); String response = doc.getTextTrim();
try { try {
byte[] data = StringUtils.decodeBase64(response).getBytes(CHARSET); byte[] data = StringUtils.decodeBase64(response);
if (data == null) { if (data == null) {
data = new byte[0]; data = new byte[0];
} }
...@@ -272,7 +271,7 @@ public class SASLAuthentication { ...@@ -272,7 +271,7 @@ public class SASLAuthentication {
if (response != null && response.length() > 0) { if (response != null && response.length() > 0) {
// Parse data and obtain username & password // Parse data and obtain username & password
String data = StringUtils.decodeBase64(response); String data = new String(StringUtils.decodeBase64(response), CHARSET);
StringTokenizer tokens = new StringTokenizer(data, "\0"); StringTokenizer tokens = new StringTokenizer(data, "\0");
if (tokens.countTokens() > 2) { if (tokens.countTokens() > 2) {
// Skip the "authorization identity" // Skip the "authorization identity"
...@@ -311,7 +310,7 @@ public class SASLAuthentication { ...@@ -311,7 +310,7 @@ public class SASLAuthentication {
} }
if (hostname != null && hostname.length() > 0) { if (hostname != null && hostname.length() > 0) {
hostname = StringUtils.decodeBase64(hostname); hostname = new String(StringUtils.decodeBase64(hostname), CHARSET);
// Check if cerificate validation is disabled for s2s // Check if cerificate validation is disabled for s2s
if (session instanceof IncomingServerSession) { if (session instanceof IncomingServerSession) {
// Flag that indicates if certificates of the remote server should be validated. // Flag that indicates if certificates of the remote server should be validated.
...@@ -373,7 +372,7 @@ public class SASLAuthentication { ...@@ -373,7 +372,7 @@ public class SASLAuthentication {
// Give a number of retries before closing the connection // Give a number of retries before closing the connection
Integer retries = (Integer) session.getSessionData("authRetries"); Integer retries = (Integer) session.getSessionData("authRetries");
if (retries == null) { if (retries == null) {
retries = new Integer(1); retries = 1;
} }
else { else {
retries = retries + 1; retries = retries + 1;
......
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