1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22:06 +01:00

SMACK-404 Changed StringUtils.decodeBase64(String) behavior so that the method does not try to detect and decompress a gzip-compressed input. Refactored every use of the Base64.(de|en)code* methods to use the StringUtils (de|en)codeBase64 methods instead.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13416 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Florian Schmaus 2013-01-29 22:49:20 +00:00 committed by flow
parent e3f84cdbe6
commit 401c37bd28
4 changed files with 19 additions and 10 deletions

View file

@ -9,7 +9,8 @@ import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.net.SocketFactory; import javax.net.SocketFactory;
import org.jivesoftware.smack.util.Base64; import org.jivesoftware.smack.util.StringUtils;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -73,8 +74,7 @@ class HTTPProxySocketFactory
{ {
String password = proxy.getProxyPassword(); String password = proxy.getProxyPassword();
proxyLine = "\r\nProxy-Authorization: Basic " proxyLine = "\r\nProxy-Authorization: Basic "
+ new String (Base64.encodeBytes((username + ":" + new String(StringUtils.encodeBase64(username + ":" + password));
+ password).getBytes("UTF-8")));
} }
socket.getOutputStream().write((hostport + " HTTP/1.1\r\nHost: " socket.getOutputStream().write((hostport + " HTTP/1.1\r\nHost: "
+ hostport + proxyLine + "\r\n\r\n").getBytes("UTF-8")); + hostport + proxyLine + "\r\n\r\n").getBytes("UTF-8"));

View file

@ -23,7 +23,7 @@ package org.jivesoftware.smack.sasl;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.SASLAuthentication; import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.Base64; import org.jivesoftware.smack.util.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@ -115,7 +115,7 @@ public abstract class SASLMechanism implements CallbackHandler {
try { try {
if(sc.hasInitialResponse()) { if(sc.hasInitialResponse()) {
byte[] response = sc.evaluateChallenge(new byte[0]); byte[] response = sc.evaluateChallenge(new byte[0]);
authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES); authenticationText = StringUtils.encodeBase64(response, false);
} }
} catch (SaslException e) { } catch (SaslException e) {
throw new XMPPException("SASL authentication failed", e); throw new XMPPException("SASL authentication failed", e);
@ -136,7 +136,7 @@ public abstract class SASLMechanism implements CallbackHandler {
public void challengeReceived(String challenge) throws IOException { public void challengeReceived(String challenge) throws IOException {
byte response[]; byte response[];
if(challenge != null) { if(challenge != null) {
response = sc.evaluateChallenge(Base64.decode(challenge)); response = sc.evaluateChallenge(StringUtils.decodeBase64(challenge));
} else { } else {
response = sc.evaluateChallenge(new byte[0]); response = sc.evaluateChallenge(new byte[0]);
} }
@ -146,7 +146,7 @@ public abstract class SASLMechanism implements CallbackHandler {
responseStanza = new Response(); responseStanza = new Response();
} }
else { else {
responseStanza = new Response(Base64.encodeBytes(response,Base64.DONT_BREAK_LINES)); responseStanza = new Response(StringUtils.encodeBase64(response, false));
} }
// Send the authentication to the server // Send the authentication to the server

View file

@ -501,12 +501,21 @@ public class StringUtils {
/** /**
* Decodes a base64 String. * Decodes a base64 String.
* Unlike Base64.decode() this method does not try to detect and decompress a gzip-compressed input.
* *
* @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 byte[] decodeBase64(String data) { public static byte[] decodeBase64(String data) {
return Base64.decode(data); byte[] bytes;
try {
bytes = data.getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException uee) {
bytes = data.getBytes();
}
bytes = Base64.decode(bytes, 0, bytes.length, Base64.NO_OPTIONS);
return bytes;
} }
/** /**

View file

@ -20,7 +20,7 @@ import static org.mockito.Mockito.*;
import java.util.Properties; import java.util.Properties;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.Base64; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.junit.Test; import org.junit.Test;
@ -53,7 +53,7 @@ public class DataTest {
@Test @Test
public void shouldReturnValidIQStanzaXML() throws Exception { public void shouldReturnValidIQStanzaXML() throws Exception {
String encodedData = Base64.encodeBytes("Test".getBytes()); String encodedData = StringUtils.encodeBase64("Test");
String control = XMLBuilder.create("iq") String control = XMLBuilder.create("iq")
.a("from", "romeo@montague.lit/orchard") .a("from", "romeo@montague.lit/orchard")