support omemo:// style urls

This commit is contained in:
Daniel Gultsch 2017-02-07 19:32:12 +01:00
parent c37117b940
commit 71ad18beb9
4 changed files with 35 additions and 10 deletions

View File

@ -657,6 +657,12 @@ public class Message extends AbstractEntity {
} }
try { try {
URL url = new URL(body); 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 ("omemo".equalsIgnoreCase(protocol) && encrypted) {
return Decision.MUST;
}
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) { if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
return Decision.NEVER; return Decision.NEVER;
} else if (oob) { } else if (oob) {
@ -666,8 +672,6 @@ public class Message extends AbstractEntity {
if (extension == null) { if (extension == null) {
return Decision.NEVER; return Decision.NEVER;
} }
String ref = url.getRef();
boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}");
if (encrypted) { if (encrypted) {
return Decision.MUST; return Decision.MUST;

View File

@ -1,7 +1,14 @@
package eu.siacs.conversations.http; package eu.siacs.conversations.http;
/** import java.io.IOException;
* Created by daniel on 2/7/17. import java.net.URL;
*/ import java.net.URLConnection;
public class OmemoURLStreamHandler { import java.net.URLStreamHandler;
public class OmemoURLStreamHandler extends URLStreamHandler {
@Override
protected URLConnection openConnection(URL url) throws IOException {
return new URL("https"+url.toString().substring(5)).openConnection();
}
} }

View File

@ -1,7 +1,15 @@
package eu.siacs.conversations.http; package eu.siacs.conversations.http;
/** import java.net.URLStreamHandler;
* Created by daniel on 2/7/17. import java.net.URLStreamHandlerFactory;
*/
public class OmemoURLStreamHandlerFactory { public class OmemoURLStreamHandlerFactory implements URLStreamHandlerFactory {
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
if ("omemo".equals(protocol)) {
return new OmemoURLStreamHandler();
} else {
return null;
}
}
} }

View File

@ -48,6 +48,7 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URL;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
@ -95,6 +96,7 @@ import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.generator.MessageGenerator; import eu.siacs.conversations.generator.MessageGenerator;
import eu.siacs.conversations.generator.PresenceGenerator; import eu.siacs.conversations.generator.PresenceGenerator;
import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.http.HttpConnectionManager;
import eu.siacs.conversations.http.OmemoURLStreamHandlerFactory;
import eu.siacs.conversations.parser.AbstractParser; import eu.siacs.conversations.parser.AbstractParser;
import eu.siacs.conversations.parser.IqParser; import eu.siacs.conversations.parser.IqParser;
import eu.siacs.conversations.parser.MessageParser; import eu.siacs.conversations.parser.MessageParser;
@ -142,6 +144,10 @@ import me.leolin.shortcutbadger.ShortcutBadger;
public class XmppConnectionService extends Service { public class XmppConnectionService extends Service {
static {
URL.setURLStreamHandlerFactory(new OmemoURLStreamHandlerFactory());
}
public static final String ACTION_REPLY_TO_CONVERSATION = "reply_to_conversations"; 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_CLEAR_NOTIFICATION = "clear_notification";
public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground"; public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground";