From 9a7fc3d9b8a001e80097cb7762a738c71281a2e1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 23 Mar 2021 11:52:34 +0100 Subject: [PATCH] disable omemo by default for *.covid.monal.im domains --- src/main/java/eu/siacs/conversations/Config.java | 13 +++++++++++-- .../conversations/crypto/XmppDomainVerifier.java | 7 ++----- .../siacs/conversations/entities/Conversation.java | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 667b9e76e..4ee4c1fb8 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -3,9 +3,11 @@ package eu.siacs.conversations; import android.graphics.Bitmap; import android.net.Uri; +import java.util.Arrays; import java.util.Collections; import java.util.List; +import eu.siacs.conversations.crypto.XmppDomainVerifier; import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.chatstate.ChatState; @@ -98,7 +100,7 @@ public final class Config { //remove *other* omemo devices from *your* device list announcement after not seeing any activity from them for 42 days. They will automatically add themselves after coming back online. public static final long OMEMO_AUTO_EXPIRY = 42 * MILLISECONDS_IN_DAY; - + public static final boolean REMOVE_BROKEN_DEVICES = false; public static final boolean OMEMO_PADDING = false; public static final boolean PUT_AUTH_TAG_INTO_KEY = true; @@ -176,7 +178,14 @@ public final class Config { //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 static final List CONTACT_DOMAINS = Arrays.asList( + "cheogram.com", + "*.covid.monal.im" + ); + + public static boolean matchesContactDomain(final String domain) { + return XmppDomainVerifier.matchDomain(domain, CONTACT_DOMAINS); + } } private Config() { diff --git a/src/main/java/eu/siacs/conversations/crypto/XmppDomainVerifier.java b/src/main/java/eu/siacs/conversations/crypto/XmppDomainVerifier.java index 689b465c9..7b741b864 100644 --- a/src/main/java/eu/siacs/conversations/crypto/XmppDomainVerifier.java +++ b/src/main/java/eu/siacs/conversations/crypto/XmppDomainVerifier.java @@ -71,8 +71,8 @@ public class XmppDomainVerifier implements DomainHostnameVerifier { } } - private static boolean matchDomain(String needle, List haystack) { - for (String entry : haystack) { + public static boolean matchDomain(final String needle, final List haystack) { + for (final String entry : haystack) { if (entry.startsWith("*.")) { int offset = 0; while (offset < needle.length()) { @@ -80,16 +80,13 @@ public class XmppDomainVerifier implements DomainHostnameVerifier { if (i < 0) { break; } - Log.d(LOGTAG, "comparing " + needle.substring(i) + " and " + entry.substring(1)); if (needle.substring(i).equalsIgnoreCase(entry.substring(1))) { - Log.d(LOGTAG, "domain " + needle + " matched " + entry); return true; } offset = i + 1; } } else { if (entry.equalsIgnoreCase(needle)) { - Log.d(LOGTAG, "domain " + needle + " matched " + entry); return true; } } diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 11314952c..20db15da2 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -143,7 +143,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } final String contact = conversation.getJid().getDomain().toEscapedString(); final String account = conversation.getAccount().getServer(); - if (Config.OMEMO_EXCEPTIONS.CONTACT_DOMAINS.contains(contact) || Config.OMEMO_EXCEPTIONS.ACCOUNT_DOMAINS.contains(account)) { + if (Config.OMEMO_EXCEPTIONS.matchesContactDomain(contact) || Config.OMEMO_EXCEPTIONS.ACCOUNT_DOMAINS.contains(account)) { return false; } return conversation.isSingleOrPrivateAndNonAnonymous() || conversation.getBooleanAttribute(ATTRIBUTE_FORMERLY_PRIVATE_NON_ANONYMOUS, false);