diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-02-08 21:49:42 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-02-08 21:49:42 +0100 |
commit | d515b99796841f2209cc42336d9980ca03ee2e7e (patch) | |
tree | 5e620f33ee9675442343b356a2b1e172d6e31fb4 /src/main/java | |
parent | 1c3de25ca64a0eb81b3f9024c7718d45db1d6d66 (diff) |
support aesgcm:// style urls
Diffstat (limited to 'src/main/java')
4 files changed, 45 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index bf53b3cd7..0936c86c8 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -9,6 +9,7 @@ import java.net.URL; import de.pixart.messenger.Config; import de.pixart.messenger.crypto.axolotl.FingerprintStatus; +import de.pixart.messenger.http.AesGcmURLStreamHandler; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.MimeUtils; @@ -659,6 +660,12 @@ public class Message extends AbstractEntity { } try { URL url = new URL(body); + String ref = url.getRef(); + final String protocol = url.getProtocol(); + final boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}"); + if (AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted) { + return Decision.MUST; + } if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) { return Decision.NEVER; } else if (oob) { @@ -668,8 +675,6 @@ public class Message extends AbstractEntity { if (extension == null) { return Decision.NEVER; } - String ref = url.getRef(); - boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}"); if (encrypted) { return Decision.MUST; diff --git a/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java b/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java new file mode 100644 index 000000000..64188c5db --- /dev/null +++ b/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java @@ -0,0 +1,17 @@ +package de.pixart.messenger.http; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + + +public class AesGcmURLStreamHandler extends URLStreamHandler { + + public static final String PROTOCOL_NAME = "aesgcm"; + + @Override + protected URLConnection openConnection(URL url) throws IOException { + return new URL("https"+url.toString().substring(url.getProtocol().length())).openConnection(); + } +} diff --git a/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandlerFactory.java b/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandlerFactory.java new file mode 100644 index 000000000..b5edd2f5a --- /dev/null +++ b/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandlerFactory.java @@ -0,0 +1,15 @@ +package de.pixart.messenger.http; + +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; + +public class AesGcmURLStreamHandlerFactory implements URLStreamHandlerFactory { + @Override + public URLStreamHandler createURLStreamHandler(String protocol) { + if (AesGcmURLStreamHandler.PROTOCOL_NAME.equals(protocol)) { + return new AesGcmURLStreamHandler(); + } else { + return null; + } + } +} diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 5fe77667b..729079f2a 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -99,6 +99,7 @@ import de.pixart.messenger.generator.IqGenerator; import de.pixart.messenger.generator.MessageGenerator; import de.pixart.messenger.generator.PresenceGenerator; import de.pixart.messenger.http.HttpConnectionManager; +import de.pixart.messenger.http.AesGcmURLStreamHandlerFactory; import de.pixart.messenger.parser.AbstractParser; import de.pixart.messenger.parser.IqParser; import de.pixart.messenger.parser.MessageParser; @@ -143,9 +144,14 @@ import de.pixart.messenger.xmpp.stanzas.IqPacket; import de.pixart.messenger.xmpp.stanzas.MessagePacket; import de.pixart.messenger.xmpp.stanzas.PresencePacket; import me.leolin.shortcutbadger.ShortcutBadger; +import java.net.URL; public class XmppConnectionService extends Service { + static { + URL.setURLStreamHandlerFactory(new AesGcmURLStreamHandlerFactory()); + } + public static final String ACTION_REPLY_TO_CONVERSATION = "reply_to_conversations"; public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification"; public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground"; |