Commit 8b06d6d1 authored by Dave Cridland's avatar Dave Cridland

Merge pull request #336 from sco0ter/charset

Make code more readable by using StandardCharsets.UTF_8.
parents 9d3b8cfa fcf665a9
...@@ -25,8 +25,6 @@ import org.jivesoftware.openfire.net.SASLAuthentication; ...@@ -25,8 +25,6 @@ import org.jivesoftware.openfire.net.SASLAuthentication;
import org.jivesoftware.openfire.session.LocalClientSession; import org.jivesoftware.openfire.session.LocalClientSession;
import org.xmpp.packet.*; import org.xmpp.packet.*;
import java.io.UnsupportedEncodingException;
/** /**
* Handles the routing of packets to a particular session. It will invoke all of the appropriate * Handles the routing of packets to a particular session. It will invoke all of the appropriate
* interceptors, before and after having the server process the message. * interceptors, before and after having the server process the message.
...@@ -60,7 +58,7 @@ public class SessionPacketRouter implements PacketRouter { ...@@ -60,7 +58,7 @@ public class SessionPacketRouter implements PacketRouter {
} }
public void route(Element wrappedElement) public void route(Element wrappedElement)
throws UnsupportedEncodingException, UnknownStanzaException { throws UnknownStanzaException {
String tag = wrappedElement.getName(); String tag = wrappedElement.getName();
if ("auth".equals(tag) || "response".equals(tag)) { if ("auth".equals(tag) || "response".equals(tag)) {
SASLAuthentication.handle(session, wrappedElement); SASLAuthentication.handle(session, wrappedElement);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
package org.jivesoftware.openfire.auth; package org.jivesoftware.openfire.auth;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
...@@ -239,7 +238,7 @@ public class DefaultAuthProvider implements AuthProvider { ...@@ -239,7 +238,7 @@ public class DefaultAuthProvider implements AuthProvider {
saltedPassword = ScramUtils.createSaltedPassword(saltShaker, testPassword, iterations); saltedPassword = ScramUtils.createSaltedPassword(saltShaker, testPassword, iterations);
clientKey = ScramUtils.computeHmac(saltedPassword, "Client Key"); clientKey = ScramUtils.computeHmac(saltedPassword, "Client Key");
testStoredKey = MessageDigest.getInstance("SHA-1").digest(clientKey); testStoredKey = MessageDigest.getInstance("SHA-1").digest(clientKey);
} catch(SaslException | NoSuchAlgorithmException | UnsupportedEncodingException e) { } catch(SaslException | NoSuchAlgorithmException e) {
Log.warn("Unable to check SCRAM values for PLAIN authentication."); Log.warn("Unable to check SCRAM values for PLAIN authentication.");
return false; return false;
} }
...@@ -285,7 +284,7 @@ public class DefaultAuthProvider implements AuthProvider { ...@@ -285,7 +284,7 @@ public class DefaultAuthProvider implements AuthProvider {
clientKey = ScramUtils.computeHmac(saltedPassword, "Client Key"); clientKey = ScramUtils.computeHmac(saltedPassword, "Client Key");
storedKey = MessageDigest.getInstance("SHA-1").digest(clientKey); storedKey = MessageDigest.getInstance("SHA-1").digest(clientKey);
serverKey = ScramUtils.computeHmac(saltedPassword, "Server Key"); serverKey = ScramUtils.computeHmac(saltedPassword, "Server Key");
} catch (SaslException | NoSuchAlgorithmException | UnsupportedEncodingException e) { } catch (SaslException | NoSuchAlgorithmException e) {
Log.warn("Unable to persist values for SCRAM authentication."); Log.warn("Unable to persist values for SCRAM authentication.");
} }
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
package org.jivesoftware.openfire.auth; package org.jivesoftware.openfire.auth;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
...@@ -29,8 +28,6 @@ import javax.crypto.Mac; ...@@ -29,8 +28,6 @@ import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import javax.security.sasl.SaslException; import javax.security.sasl.SaslException;
import org.jivesoftware.util.JiveGlobals;
/** /**
* A utility class that provides methods that are useful for dealing with * A utility class that provides methods that are useful for dealing with
* Salted Challenge Response Authentication Mechanism (SCRAM). * Salted Challenge Response Authentication Mechanism (SCRAM).
...@@ -62,7 +59,7 @@ public class ScramUtils { ...@@ -62,7 +59,7 @@ public class ScramUtils {
} }
public static byte[] computeHmac(final byte[] key, final String string) public static byte[] computeHmac(final byte[] key, final String string)
throws SaslException, UnsupportedEncodingException { throws SaslException {
Mac mac = createSha1Hmac(key); Mac mac = createSha1Hmac(key);
mac.update(string.getBytes(StandardCharsets.US_ASCII)); mac.update(string.getBytes(StandardCharsets.US_ASCII));
return mac.doFinal(); return mac.doFinal();
......
package org.jivesoftware.openfire.group; package org.jivesoftware.openfire.group;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
...@@ -127,13 +127,7 @@ public class GroupJID extends JID { ...@@ -127,13 +127,7 @@ public class GroupJID extends JID {
* @return The group name * @return The group name
*/ */
private static String decodeNode(String node) { private static String decodeNode(String node) {
try { return new String(StringUtils.decodeBase32(node), StandardCharsets.UTF_8);
return new String(StringUtils.decodeBase32(node), "UTF-8");
} catch (UnsupportedEncodingException uee) {
// this shouldn't happen, but ...
Log.error("Unexpected encoding exception", uee);
return null;
}
} }
/** /**
......
...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire.http; ...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire.http;
import java.io.*; import java.io.*;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Date; import java.util.Date;
...@@ -295,7 +296,7 @@ public class HttpBindServlet extends HttpServlet { ...@@ -295,7 +296,7 @@ public class HttpBindServlet extends HttpServlet {
System.out.println(new Date() + ": HTTP SENT(" + session.getStreamID().getID() + "): " + content); System.out.println(new Date() + ": HTTP SENT(" + session.getStreamID().getID() + "): " + content);
} }
final byte[] byteContent = content.getBytes("UTF-8"); final byte[] byteContent = content.getBytes(StandardCharsets.UTF_8);
if (async) { if (async) {
response.getOutputStream().setWriteListener(new WriteListenerImpl(context, byteContent)); response.getOutputStream().setWriteListener(new WriteListenerImpl(context, byteContent));
} else { } else {
......
...@@ -21,7 +21,6 @@ package org.jivesoftware.openfire.http; ...@@ -21,7 +21,6 @@ package org.jivesoftware.openfire.http;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.cert.Certificate; import java.security.cert.Certificate;
...@@ -654,11 +653,6 @@ public class HttpSession extends LocalClientSession { ...@@ -654,11 +653,6 @@ public class HttpSession extends LocalClientSession {
try { try {
router.route(packet); router.route(packet);
} }
catch (UnsupportedEncodingException e) {
Log.error(
"Client provided unsupported encoding type in auth request",
e);
}
catch (UnknownStanzaException e) { catch (UnknownStanzaException e) {
Log.error("Client provided unknown packet type", e); Log.error("Client provided unknown packet type", e);
} }
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
package org.jivesoftware.openfire.ldap; package org.jivesoftware.openfire.ldap;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -33,7 +33,6 @@ import java.util.Set; ...@@ -33,7 +33,6 @@ import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.NamingEnumeration; import javax.naming.NamingEnumeration;
import javax.naming.NamingException; import javax.naming.NamingException;
...@@ -2239,15 +2238,10 @@ public class LdapManager { ...@@ -2239,15 +2238,10 @@ public class LdapManager {
} }
else if (c >= 0x080) { else if (c >= 0x080) {
// higher-order 2, 3 and 4-byte UTF-8 chars // higher-order 2, 3 and 4-byte UTF-8 chars
try { byte[] utf8bytes = String.valueOf(c).getBytes(StandardCharsets.UTF_8);
byte[] utf8bytes = String.valueOf(c).getBytes("UTF8"); for (byte b : utf8bytes) {
for (byte b: utf8bytes)
{
result.append(String.format("\\%02x", b)); result.append(String.format("\\%02x", b));
} }
} catch (UnsupportedEncodingException e) {
// ignore
}
} }
} }
} }
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
package org.jivesoftware.openfire.net; package org.jivesoftware.openfire.net;
import java.io.UnsupportedEncodingException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.Security; import java.security.Security;
import java.security.cert.Certificate; import java.security.cert.Certificate;
...@@ -87,11 +87,6 @@ public class SASLAuthentication { ...@@ -87,11 +87,6 @@ public class SASLAuthentication {
// plus an extra regex alternative to catch a single equals sign ('=', see RFC 6120 6.4.2) // plus an extra regex alternative to catch a single equals sign ('=', see RFC 6120 6.4.2)
private static final Pattern BASE64_ENCODED = Pattern.compile("^(=|([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==))$"); private static final Pattern BASE64_ENCODED = Pattern.compile("^(=|([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==))$");
/**
* The utf-8 charset for decoding and encoding Jabber packet streams.
*/
protected static String CHARSET = "UTF-8";
private static final String SASL_NAMESPACE = "xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\""; private static final String SASL_NAMESPACE = "xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"";
private static Map<String, ElementType> typeMap = new TreeMap<String, ElementType>(); private static Map<String, ElementType> typeMap = new TreeMap<String, ElementType>();
...@@ -232,9 +227,8 @@ public class SASLAuthentication { ...@@ -232,9 +227,8 @@ public class SASLAuthentication {
* @param doc the stanza sent by the authenticating entity. * @param doc the stanza sent by the authenticating entity.
* @return value that indicates whether the authentication has finished either successfully * @return value that indicates whether the authentication has finished either successfully
* or not or if the entity is expected to send a response to a challenge. * or not or if the entity is expected to send a response to a challenge.
* @throws UnsupportedEncodingException If UTF-8 charset is not supported.
*/ */
public static Status handle(LocalSession session, Element doc) throws UnsupportedEncodingException { public static Status handle(LocalSession session, Element doc) {
Status status; Status status;
String mechanism; String mechanism;
if (doc.getNamespace().asXML().equals(SASL_NAMESPACE)) { if (doc.getNamespace().asXML().equals(SASL_NAMESPACE)) {
...@@ -511,8 +505,7 @@ public class SASLAuthentication { ...@@ -511,8 +505,7 @@ public class SASLAuthentication {
} }
} }
private static Status doExternalAuthentication(LocalSession session, Element doc) private static Status doExternalAuthentication(LocalSession session, Element doc) {
throws UnsupportedEncodingException {
// At this point the connection has already been secured using TLS // At this point the connection has already been secured using TLS
if (session instanceof IncomingServerSession) { if (session instanceof IncomingServerSession) {
...@@ -524,7 +517,7 @@ public class SASLAuthentication { ...@@ -524,7 +517,7 @@ public class SASLAuthentication {
return Status.needResponse; return Status.needResponse;
} }
hostname = new String(StringUtils.decodeBase64(hostname), CHARSET); hostname = new String(StringUtils.decodeBase64(hostname), StandardCharsets.UTF_8);
if (hostname.length() == 0) { if (hostname.length() == 0) {
hostname = null; hostname = null;
} }
...@@ -569,7 +562,7 @@ public class SASLAuthentication { ...@@ -569,7 +562,7 @@ public class SASLAuthentication {
Log.debug("SASLAuthentication: EXTERNAL authentication via SSL certs for c2s connection"); Log.debug("SASLAuthentication: EXTERNAL authentication via SSL certs for c2s connection");
// This may be null, we will deal with that later // This may be null, we will deal with that later
String username = new String(StringUtils.decodeBase64(doc.getTextTrim()), CHARSET); String username = new String(StringUtils.decodeBase64(doc.getTextTrim()), StandardCharsets.UTF_8);
String principal = ""; String principal = "";
ArrayList<String> principals = new ArrayList<String>(); ArrayList<String> principals = new ArrayList<String>();
Connection connection = session.getConnection(); Connection connection = session.getConnection();
...@@ -669,9 +662,7 @@ public class SASLAuthentication { ...@@ -669,9 +662,7 @@ public class SASLAuthentication {
return false; return false;
} }
private static Status doSharedSecretAuthentication(LocalSession session, Element doc) private static Status doSharedSecretAuthentication(LocalSession session, Element doc) {
throws UnsupportedEncodingException
{
String secretDigest; String secretDigest;
String response = doc.getTextTrim(); String response = doc.getTextTrim();
if (response == null || response.length() == 0) { if (response == null || response.length() == 0) {
...@@ -681,7 +672,7 @@ public class SASLAuthentication { ...@@ -681,7 +672,7 @@ public class SASLAuthentication {
} }
// Parse data and obtain username & password // Parse data and obtain username & password
String data = new String(StringUtils.decodeBase64(response), CHARSET); String data = new String(StringUtils.decodeBase64(response), StandardCharsets.UTF_8);
StringTokenizer tokens = new StringTokenizer(data, "\0"); StringTokenizer tokens = new StringTokenizer(data, "\0");
tokens.nextToken(); tokens.nextToken();
secretDigest = tokens.nextToken(); secretDigest = tokens.nextToken();
......
...@@ -28,9 +28,9 @@ import java.net.InetAddress; ...@@ -28,9 +28,9 @@ import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder; import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction; import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
...@@ -77,11 +77,6 @@ public class NIOConnection implements Connection { ...@@ -77,11 +77,6 @@ public class NIOConnection implements Connection {
public enum State { RUNNING, CLOSING, CLOSED } public enum State { RUNNING, CLOSING, CLOSED }
/**
* The utf-8 charset for decoding and encoding XMPP packet streams.
*/
public static final String CHARSET = "UTF-8";
private LocalSession session; private LocalSession session;
private IoSession ioSession; private IoSession ioSession;
...@@ -361,7 +356,7 @@ public class NIOConnection implements Connection { ...@@ -361,7 +356,7 @@ public class NIOConnection implements Connection {
try { try {
//Charset charset = Charset.forName(CHARSET); //Charset charset = Charset.forName(CHARSET);
//buffer.putString(text, charset.newEncoder()); //buffer.putString(text, charset.newEncoder());
buffer.put(text.getBytes(CHARSET)); buffer.put(text.getBytes(StandardCharsets.UTF_8));
if (flashClient) { if (flashClient) {
buffer.put((byte) '\0'); buffer.put((byte) '\0');
} }
...@@ -523,7 +518,7 @@ public class NIOConnection implements Connection { ...@@ -523,7 +518,7 @@ public class NIOConnection implements Connection {
@Override @Override
protected CharsetEncoder initialValue() { protected CharsetEncoder initialValue() {
return Charset.forName(CHARSET).newEncoder() return StandardCharsets.UTF_8.newEncoder()
.onMalformedInput(CodingErrorAction.REPORT) .onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT); .onUnmappableCharacter(CodingErrorAction.REPORT);
} }
......
...@@ -21,10 +21,10 @@ ...@@ -21,10 +21,10 @@
package org.jivesoftware.openfire.sasl; package org.jivesoftware.openfire.sasl;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.security.sasl.Sasl; import javax.security.sasl.Sasl;
import javax.security.sasl.SaslServer; import javax.security.sasl.SaslServer;
import javax.security.sasl.SaslException; import javax.security.sasl.SaslException;
...@@ -105,7 +105,7 @@ public class SaslServerPlainImpl implements SaslServer { ...@@ -105,7 +105,7 @@ public class SaslServerPlainImpl implements SaslServer {
} }
try { try {
if(response.length != 0) { if(response.length != 0) {
String data = new String(response, "UTF8"); String data = new String(response, StandardCharsets.UTF_8);
StringTokenizer tokens = new StringTokenizer(data, "\0"); StringTokenizer tokens = new StringTokenizer(data, "\0");
if (tokens.countTokens() > 2) { if (tokens.countTokens() > 2) {
username = tokens.nextToken(); username = tokens.nextToken();
...@@ -141,9 +141,6 @@ public class SaslServerPlainImpl implements SaslServer { ...@@ -141,9 +141,6 @@ public class SaslServerPlainImpl implements SaslServer {
} }
return null; return null;
} }
} catch (UnsupportedEncodingException e) {
aborted = true;
throw new SaslException("UTF8 not available on platform", e);
} catch (UnsupportedCallbackException e) { } catch (UnsupportedCallbackException e) {
aborted = true; aborted = true;
throw new SaslException("PLAIN authentication failed for: "+username, e); throw new SaslException("PLAIN authentication failed for: "+username, e);
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
package org.jivesoftware.openfire.sasl; package org.jivesoftware.openfire.sasl;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
...@@ -211,7 +209,7 @@ public class ScramSha1SaslServer implements SaslServer { ...@@ -211,7 +209,7 @@ public class ScramSha1SaslServer implements SaslServer {
} }
return ("v=" + DatatypeConverter.printBase64Binary(serverSignature)) return ("v=" + DatatypeConverter.printBase64Binary(serverSignature))
.getBytes(StandardCharsets.US_ASCII); .getBytes(StandardCharsets.US_ASCII);
} catch (UnsupportedEncodingException | UserNotFoundException | NoSuchAlgorithmException e) { } catch (UserNotFoundException | NoSuchAlgorithmException e) {
throw new SaslException(e.getMessage(), e); throw new SaslException(e.getMessage(), e);
} }
} }
......
package org.jivesoftware.util; package org.jivesoftware.util;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.security.Key; import java.security.Key;
import java.security.Security; import java.security.Security;
...@@ -60,9 +60,7 @@ public class AesEncryptor implements Encryptor { ...@@ -60,9 +60,7 @@ public class AesEncryptor implements Encryptor {
public String encrypt(String value) public String encrypt(String value)
{ {
if (value == null) { return null; } if (value == null) { return null; }
byte [] bytes = null; byte [] bytes = value.getBytes(StandardCharsets.UTF_8);
try { bytes = value.getBytes("UTF-8"); }
catch (UnsupportedEncodingException uee) { bytes = value.getBytes(); }
return Base64.encodeBytes( cipher(bytes, getKey(), Cipher.ENCRYPT_MODE) ); return Base64.encodeBytes( cipher(bytes, getKey(), Cipher.ENCRYPT_MODE) );
} }
...@@ -75,10 +73,7 @@ public class AesEncryptor implements Encryptor { ...@@ -75,10 +73,7 @@ public class AesEncryptor implements Encryptor {
if (value == null) { return null; } if (value == null) { return null; }
byte [] bytes = cipher(Base64.decode(value), getKey(), Cipher.DECRYPT_MODE); byte [] bytes = cipher(Base64.decode(value), getKey(), Cipher.DECRYPT_MODE);
if (bytes == null) { return null; } if (bytes == null) { return null; }
String result = null; return new String(bytes, StandardCharsets.UTF_8);
try { result = new String(bytes,"UTF-8"); }
catch (UnsupportedEncodingException uee) { result = new String(bytes); }
return result;
} }
/** /**
...@@ -144,9 +139,7 @@ public class AesEncryptor implements Encryptor { ...@@ -144,9 +139,7 @@ public class AesEncryptor implements Encryptor {
cipherKey = null; cipherKey = null;
return; return;
} }
byte [] bytes = null; byte [] bytes = key.getBytes(StandardCharsets.UTF_8);
try { bytes = key.getBytes("UTF-8"); }
catch (UnsupportedEncodingException uee) { bytes = key.getBytes(); }
setKey(editKey(bytes)); setKey(editKey(bytes));
} }
......
...@@ -19,8 +19,14 @@ ...@@ -19,8 +19,14 @@
package org.jivesoftware.util; package org.jivesoftware.util;
import java.io.UnsupportedEncodingException; import org.apache.commons.codec.binary.Base32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import java.net.IDN; import java.net.IDN;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.BreakIterator; import java.text.BreakIterator;
...@@ -36,13 +42,6 @@ import java.util.Random; ...@@ -36,13 +42,6 @@ import java.util.Random;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import org.apache.commons.codec.binary.Base32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Utility class to perform common String manipulation algorithms. * Utility class to perform common String manipulation algorithms.
*/ */
...@@ -387,13 +386,7 @@ public class StringUtils { ...@@ -387,13 +386,7 @@ public class StringUtils {
* @return a hashed version of the passed-in String * @return a hashed version of the passed-in String
*/ */
public static String hash(String data, String algorithm) { public static String hash(String data, String algorithm) {
try { return hash(data.getBytes(StandardCharsets.UTF_8), algorithm);
return hash(data.getBytes("UTF-8"), algorithm);
}
catch (UnsupportedEncodingException e) {
Log.error(e.getMessage(), e);
}
return data;
} }
/** /**
...@@ -539,13 +532,7 @@ public class StringUtils { ...@@ -539,13 +532,7 @@ public class StringUtils {
* @return a base64 encoded String. * @return a base64 encoded String.
*/ */
public static String encodeBase64(String data) { public static String encodeBase64(String data) {
byte[] bytes = null; byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
try {
bytes = data.getBytes("UTF-8");
}
catch (UnsupportedEncodingException uee) {
Log.error(uee.getMessage(), uee);
}
return encodeBase64(bytes); return encodeBase64(bytes);
} }
...@@ -580,13 +567,7 @@ public class StringUtils { ...@@ -580,13 +567,7 @@ public class StringUtils {
* @return a base32 encoded String. * @return a base32 encoded String.
*/ */
public static String encodeBase32(String data) { public static String encodeBase32(String data) {
byte[] bytes = null; byte[] bytes = data == null ? null : data.getBytes(StandardCharsets.UTF_8);
try {
bytes = data == null ? null : data.getBytes("UTF-8");
}
catch (UnsupportedEncodingException uee) {
Log.error(uee.getMessage(), uee);
}
return encodeBase32(bytes); return encodeBase32(bytes);
} }
...@@ -1239,35 +1220,22 @@ public class StringUtils { ...@@ -1239,35 +1220,22 @@ public class StringUtils {
} }
/** /**
* Returns the UTF-8 bytes for the given String, suppressing * Returns the UTF-8 bytes for the given String.
* UnsupportedEncodingException (in lieu of log message)
* *
* @param input The source string * @param input The source string
* @return The UTF-8 encoding for the given string * @return The UTF-8 encoding for the given string
*/ */
public static byte[] getBytes(String input) { public static byte[] getBytes(String input) {
try { return input.getBytes(StandardCharsets.UTF_8);
return input.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
Log.warn("Unable to encode string using UTF-8: " + input);
return input.getBytes(); // default encoding
}
} }
/** /**
* Returns the UTF-8 String for the given byte array, suppressing * Returns the UTF-8 String for the given byte array.
* UnsupportedEncodingException (in lieu of log message)
* *
* @param input The source byte array * @param input The source byte array
* @return The UTF-8 encoded String for the given byte array * @return The UTF-8 encoded String for the given byte array
*/ */
public static String getString(byte[] input) { public static String getString(byte[] input) {
try { return new String(input, StandardCharsets.UTF_8);
return new String(input, "UTF-8");
} catch (UnsupportedEncodingException uee) {
String result = new String(input); // default encoding
Log.warn("Unable to decode byte array using UTF-8: " + result);
return result;
}
} }
} }
\ No newline at end of file
package org.jivesoftware.util.cert; package org.jivesoftware.util.cert;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.cert.CertificateParsingException; import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -97,9 +96,6 @@ public class SANCertificateIdentityMapping implements CertificateIdentityMapping ...@@ -97,9 +96,6 @@ public class SANCertificateIdentityMapping implements CertificateIdentityMapping
Log.debug("Cannot parse altName, likely because of unknown record format.", ex); Log.debug("Cannot parse altName, likely because of unknown record format.", ex);
} }
} }
catch (UnsupportedEncodingException e) {
// Ignore
}
catch (IOException e) { catch (IOException e) {
// Ignore // Ignore
} }
......
...@@ -55,7 +55,7 @@ public class StreamManagementPacketRouter extends SessionPacketRouter { ...@@ -55,7 +55,7 @@ public class StreamManagementPacketRouter extends SessionPacketRouter {
} }
@Override @Override
public void route(Element wrappedElement) throws UnsupportedEncodingException, UnknownStanzaException { public void route(Element wrappedElement) throws UnknownStanzaException {
String tag = wrappedElement.getName(); String tag = wrappedElement.getName();
if (StreamManager.NAMESPACE_V3.equals(wrappedElement.getNamespace().getStringValue())) { if (StreamManager.NAMESPACE_V3.equals(wrappedElement.getNamespace().getStringValue())) {
......
...@@ -4,8 +4,6 @@ import static org.junit.Assert.assertEquals; ...@@ -4,8 +4,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import org.junit.Test; import org.junit.Test;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -13,7 +11,7 @@ import org.xmpp.packet.JID; ...@@ -13,7 +11,7 @@ import org.xmpp.packet.JID;
public class GroupJIDTest { public class GroupJIDTest {
@Test @Test
public void testBase32Encoding() throws UnsupportedEncodingException { public void testBase32Encoding() {
String testGroupName = "Test Group (1)"; String testGroupName = "Test Group (1)";
String testDomainName = "localhost"; String testDomainName = "localhost";
......
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