From 06f8d8c5d6a4339530c8e14cfb02e621129b43f6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 26 Mar 2018 13:29:01 +0200 Subject: [PATCH] add ruleset to disable omemo-by-default for certain providers --- src/main/java/eu/siacs/conversations/Config.java | 13 +++++++++++++ .../siacs/conversations/entities/Conversation.java | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 8c598225f..1a5ccef7c 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -2,6 +2,10 @@ package eu.siacs.conversations; import android.graphics.Bitmap; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + import eu.siacs.conversations.xmpp.chatstate.ChatState; import rocks.xmpp.addr.Jid; @@ -145,6 +149,15 @@ public final class Config { "_MD5", }; + public static class OMEMO_EXCEPTIONS { + //if the own account matches one of the following domains OMEMO won’t be turned on automatically + public static final List ACCOUNT_DOMAINS = Collections.singletonList("s.ms"); + + //if the contacts domain matches one of the following domains OMEMO won’t be turned on automatically + //can be used for well known, widely used gateways + public static final List CONTACT_DOMAINS = Collections.singletonList("cheogram.com"); + } + private Config() { } } diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 6e91fc332..33f6ebab7 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -596,10 +596,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl if (!Config.supportOmemo() && !Config.supportOpenPgp()) { return Message.ENCRYPTION_NONE; } - AxolotlService axolotlService = account.getAxolotlService(); if (contactJid.asBareJid().equals(Config.BUG_REPORTS)) { defaultEncryption = Message.ENCRYPTION_NONE; - } else if (axolotlService != null && axolotlService.isConversationAxolotlCapable(this)) { + } else if (suitableForOmemoByDefault(this)) { defaultEncryption = Message.ENCRYPTION_AXOLOTL; } else { defaultEncryption = Message.ENCRYPTION_NONE; @@ -612,6 +611,16 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } + private static boolean suitableForOmemoByDefault(final Conversation conversation) { + final String contact = conversation.getJid().getDomain(); + final String account = conversation.getAccount().getServer(); + if (Config.OMEMO_EXCEPTIONS.CONTACT_DOMAINS.contains(contact) || Config.OMEMO_EXCEPTIONS.ACCOUNT_DOMAINS.contains(account)) { + return false; + } + final AxolotlService axolotlService = conversation.getAccount().getAxolotlService(); + return axolotlService != null && axolotlService.isConversationAxolotlCapable(conversation); + } + public void setNextEncryption(int encryption) { this.setAttribute(ATTRIBUTE_NEXT_ENCRYPTION, String.valueOf(encryption)); }