diff options
author | Gurmeen Bindra <gurmeen.bindra@isode.com> | 2015-08-21 13:33:46 (GMT) |
---|---|---|
committer | Gurmeen Bindra <gurmeen.bindra@isode.com> | 2015-08-21 13:44:58 (GMT) |
commit | 277e11b13ea468697804aeb76a1431446c7d3944 (patch) | |
tree | a89844b828cdb7ca699d7f6cba0631e9a805f8f3 | |
parent | 73cb8ef5b98cf9b5026c4620a325ee799e6fcb8a (diff) | |
download | stroke-277e11b13ea468697804aeb76a1431446c7d3944.zip stroke-277e11b13ea468697804aeb76a1431446c7d3944.tar.bz2 |
Fix code to not throw StringPrepParseException that was part of ICU jar
The IDNConverter interface now throws java strandard IllegalArg exception
instead of the ICU specific StringPrepParseException. Users of stroke that
are not using ICU will now be able to use it without the icu jar.
Test-information:
Sanity tested by connecting to an XMPP server using an XMPP client
Change-Id: I6999ae0c690b70bc748f131908a758a01dac20b9
-rw-r--r-- | src/com/isode/stroke/idn/ICUConverter.java | 21 | ||||
-rw-r--r-- | src/com/isode/stroke/idn/IDNConverter.java | 7 | ||||
-rw-r--r-- | src/com/isode/stroke/jid/JID.java | 2 | ||||
-rw-r--r-- | src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java | 16 | ||||
-rw-r--r-- | test/com/isode/stroke/idn/IDNConverterTest.java | 4 |
5 files changed, 27 insertions, 23 deletions
diff --git a/src/com/isode/stroke/idn/ICUConverter.java b/src/com/isode/stroke/idn/ICUConverter.java index bd347df..6f77983 100644 --- a/src/com/isode/stroke/idn/ICUConverter.java +++ b/src/com/isode/stroke/idn/ICUConverter.java @@ -19,18 +19,25 @@ import com.ibm.icu.text.StringPrepParseException; public class ICUConverter implements IDNConverter { - public String getStringPrepared(String s, StringPrepProfile profile) throws StringPrepParseException { + public String getStringPrepared(String s, StringPrepProfile profile) throws IllegalArgumentException { StringPrep str = StringPrep.getInstance(getICUProfileType(profile)); - - String preparedData = str.prepare(s, StringPrep.DEFAULT); - return preparedData; + try { + String preparedData = str.prepare(s, StringPrep.DEFAULT); + return preparedData; + }catch(StringPrepParseException e){ + throw new IllegalArgumentException(e); + } } - public SafeByteArray getStringPrepared(SafeByteArray s, StringPrepProfile profile) throws StringPrepParseException { + public SafeByteArray getStringPrepared(SafeByteArray s, StringPrepProfile profile) throws IllegalArgumentException { StringPrep str = StringPrep.getInstance(getICUProfileType(profile)); - String preparedData = str.prepare(s.toString(), StringPrep.DEFAULT); - return new SafeByteArray(preparedData); + try { + String preparedData = str.prepare(s.toString(), StringPrep.DEFAULT); + return new SafeByteArray(preparedData); + }catch(StringPrepParseException e){ + throw new IllegalArgumentException(e); + } } public String getIDNAEncoded(String s) { diff --git a/src/com/isode/stroke/idn/IDNConverter.java b/src/com/isode/stroke/idn/IDNConverter.java index 3566020..bc929f0 100644 --- a/src/com/isode/stroke/idn/IDNConverter.java +++ b/src/com/isode/stroke/idn/IDNConverter.java @@ -12,7 +12,6 @@ package com.isode.stroke.idn; import com.isode.stroke.base.SafeByteArray; -import com.ibm.icu.text.StringPrepParseException; public interface IDNConverter { @@ -21,10 +20,10 @@ public interface IDNConverter { XMPPNodePrep, XMPPResourcePrep, SASLPrep - }; + } - public String getStringPrepared(String s, StringPrepProfile profile) throws StringPrepParseException; - public SafeByteArray getStringPrepared(SafeByteArray s, StringPrepProfile profile) throws StringPrepParseException; + public String getStringPrepared(String s, StringPrepProfile profile) throws IllegalArgumentException; + public SafeByteArray getStringPrepared(SafeByteArray s, StringPrepProfile profile) throws IllegalArgumentException; // Thread-safe public String getIDNAEncoded(String s); diff --git a/src/com/isode/stroke/jid/JID.java b/src/com/isode/stroke/jid/JID.java index 6067afc..59eef52 100644 --- a/src/com/isode/stroke/jid/JID.java +++ b/src/com/isode/stroke/jid/JID.java @@ -160,7 +160,7 @@ public class JID implements Comparable<JID> { node_ = idnConverter.getStringPrepared(node, IDNConverter.StringPrepProfile.XMPPNodePrep); domain_ = idnConverter.getStringPrepared(domain, IDNConverter.StringPrepProfile.NamePrep); resource_ = resource != null ? idnConverter.getStringPrepared(resource, IDNConverter.StringPrepProfile.XMPPResourcePrep) : null; - } catch (StringPrepParseException e) { + } catch (IllegalArgumentException e) { valid_ = false; return; } diff --git a/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java b/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java index 1d2b4d9..2b302d0 100644 --- a/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java +++ b/src/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticator.java @@ -8,17 +8,15 @@ */ package com.isode.stroke.sasl; +import java.util.HashMap; +import java.util.Map; + import com.isode.stroke.base.ByteArray; import com.isode.stroke.base.SafeByteArray; -import com.ibm.icu.text.StringPrepParseException; +import com.isode.stroke.crypto.CryptoProvider; +import com.isode.stroke.idn.IDNConverter; import com.isode.stroke.stringcodecs.Base64; import com.isode.stroke.stringcodecs.PBKDF2; -import com.isode.stroke.idn.IDNConverter; -import com.isode.stroke.crypto.CryptoProvider; -import java.text.Normalizer; -import java.text.Normalizer.Form; -import java.util.HashMap; -import java.util.Map; public class SCRAMSHA1ClientAuthenticator extends ClientAuthenticator { @@ -113,7 +111,7 @@ public class SCRAMSHA1ClientAuthenticator extends ClientAuthenticator { // Compute all the values needed for the server signature try { saltedPassword = PBKDF2.encode(idnConverter.getStringPrepared(getPassword(), IDNConverter.StringPrepProfile.SASLPrep), salt, iterations, crypto); - } catch (StringPrepParseException e) { + } catch (IllegalArgumentException e) { } authMessage = getInitialBareClientMessage().append(",").append(initialServerMessage).append(",").append(getFinalMessageWithoutProof()); @@ -161,7 +159,7 @@ public class SCRAMSHA1ClientAuthenticator extends ClientAuthenticator { String authenticationID = ""; try { authenticationID = idnConverter.getStringPrepared(getAuthenticationID(), IDNConverter.StringPrepProfile.SASLPrep); - } catch (StringPrepParseException e) { + } catch (IllegalArgumentException e) { } return new ByteArray("n=" + escape(authenticationID) + ",r=" + clientnonce); diff --git a/test/com/isode/stroke/idn/IDNConverterTest.java b/test/com/isode/stroke/idn/IDNConverterTest.java index a17affc..eb82a61 100644 --- a/test/com/isode/stroke/idn/IDNConverterTest.java +++ b/test/com/isode/stroke/idn/IDNConverterTest.java @@ -38,7 +38,7 @@ public class IDNConverterTest { try { String result = testling.getStringPrepared("tronçon", IDNConverter.StringPrepProfile.NamePrep); assertEquals("tronçon", result); - } catch (StringPrepParseException e) { + } catch (IllegalArgumentException e) { assertTrue("getStringPrep threw " + e, (e == null)); } } @@ -49,7 +49,7 @@ public class IDNConverterTest { assertEquals("", testling.getStringPrepared("", IDNConverter.StringPrepProfile.NamePrep)); assertEquals("", testling.getStringPrepared("", IDNConverter.StringPrepProfile.XMPPNodePrep)); assertEquals("", testling.getStringPrepared("", IDNConverter.StringPrepProfile.XMPPResourcePrep)); - } catch (StringPrepParseException e) { + } catch (IllegalArgumentException e) { assertTrue("getStringPrep threw " + e, (e == null)); } } |