From 303f14200f0128ea959399900cab89a4fc07592f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 1 Mar 2023 09:19:48 +0100 Subject: [PATCH] take btbv setting into account when deciding default trust --- .../android/xmpp/MessageTransformationTest.java | 3 ++- .../java/im/conversations/android/AppSettings.java | 2 +- .../conversations/android/axolotl/AxolotlService.java | 8 ++++++-- .../android/database/AxolotlDatabaseStore.java | 11 +++++++++-- .../android/transformer/Transformer.java | 11 +++++++++-- .../android/xmpp/manager/AxolotlManager.java | 4 +++- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java b/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java index a4321f035..fb1da0a6b 100644 --- a/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java +++ b/app/src/androidTest/java/im/conversations/android/xmpp/MessageTransformationTest.java @@ -55,7 +55,8 @@ public class MessageTransformationTest { final long id = database.accountDao().insert(account); this.transformer = - new Transformer(database.accountDao().getEnabledAccount(id).get(), database); + new Transformer( + database.accountDao().getEnabledAccount(id).get(), context, database); } @Test diff --git a/app/src/main/java/im/conversations/android/AppSettings.java b/app/src/main/java/im/conversations/android/AppSettings.java index e4afd409a..0e4e47d8a 100644 --- a/app/src/main/java/im/conversations/android/AppSettings.java +++ b/app/src/main/java/im/conversations/android/AppSettings.java @@ -36,7 +36,7 @@ public class AppSettings { .apply(); } - public boolean isBtbv() { + public boolean isBTBVEnabled() { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return sharedPreferences.getBoolean( diff --git a/app/src/main/java/im/conversations/android/axolotl/AxolotlService.java b/app/src/main/java/im/conversations/android/axolotl/AxolotlService.java index 24612eef4..2fae09d7f 100644 --- a/app/src/main/java/im/conversations/android/axolotl/AxolotlService.java +++ b/app/src/main/java/im/conversations/android/axolotl/AxolotlService.java @@ -1,5 +1,6 @@ package im.conversations.android.axolotl; +import android.content.Context; import android.os.Build; import com.google.common.base.Optional; import com.google.common.collect.ArrayListMultimap; @@ -62,9 +63,12 @@ public class AxolotlService extends AbstractAccountService { private final Multimap devicesNotInPep = ArrayListMultimap.create(); public AxolotlService( - final Account account, final ConversationsDatabase conversationsDatabase) { + final Account account, + final Context context, + final ConversationsDatabase conversationsDatabase) { super(account, conversationsDatabase); - this.signalProtocolStore = new AxolotlDatabaseStore(account, conversationsDatabase); + this.signalProtocolStore = + new AxolotlDatabaseStore(account, context, conversationsDatabase); } public void setPostDecryptionHook(final PostDecryptionHook postDecryptionHook) { diff --git a/app/src/main/java/im/conversations/android/database/AxolotlDatabaseStore.java b/app/src/main/java/im/conversations/android/database/AxolotlDatabaseStore.java index d5eb80a25..844bf22ef 100644 --- a/app/src/main/java/im/conversations/android/database/AxolotlDatabaseStore.java +++ b/app/src/main/java/im/conversations/android/database/AxolotlDatabaseStore.java @@ -1,6 +1,8 @@ package im.conversations.android.database; +import android.content.Context; import im.conversations.android.AbstractAccountService; +import im.conversations.android.AppSettings; import im.conversations.android.axolotl.AxolotlAddress; import im.conversations.android.database.dao.AxolotlDao; import im.conversations.android.database.model.Account; @@ -17,9 +19,14 @@ import org.whispersystems.libsignal.state.SignedPreKeyRecord; public class AxolotlDatabaseStore extends AbstractAccountService implements SignalProtocolStore { + private AppSettings appSettings; + public AxolotlDatabaseStore( - final Account account, final ConversationsDatabase conversationsDatabase) { + final Account account, + final Context context, + final ConversationsDatabase conversationsDatabase) { super(account, conversationsDatabase); + this.appSettings = new AppSettings(context); } private AxolotlDao axolotlDao() { @@ -40,7 +47,7 @@ public class AxolotlDatabaseStore extends AbstractAccountService implements Sign public boolean saveIdentity( final SignalProtocolAddress signalProtocolAddress, final IdentityKey identityKey) { final var address = AxolotlAddress.cast(signalProtocolAddress); - final boolean isBTBVEnabled = true; + final boolean isBTBVEnabled = appSettings.isBTBVEnabled(); return database.runInTransaction( () -> { final Trust trust; diff --git a/app/src/main/java/im/conversations/android/transformer/Transformer.java b/app/src/main/java/im/conversations/android/transformer/Transformer.java index 13f97ff8e..fbfbbfa43 100644 --- a/app/src/main/java/im/conversations/android/transformer/Transformer.java +++ b/app/src/main/java/im/conversations/android/transformer/Transformer.java @@ -1,5 +1,6 @@ package im.conversations.android.transformer; +import android.content.Context; import com.google.common.base.Preconditions; import im.conversations.android.axolotl.AxolotlDecryptionException; import im.conversations.android.axolotl.AxolotlService; @@ -32,8 +33,14 @@ public class Transformer { private final AxolotlService axolotlService; - public Transformer(final Account account, final ConversationsDatabase conversationsDatabase) { - this(account, conversationsDatabase, new AxolotlService(account, conversationsDatabase)); + public Transformer( + final Account account, + final Context context, + final ConversationsDatabase conversationsDatabase) { + this( + account, + conversationsDatabase, + new AxolotlService(account, context, conversationsDatabase)); } public Transformer( diff --git a/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java b/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java index 0c58d0905..11089c4cf 100644 --- a/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java +++ b/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java @@ -67,7 +67,9 @@ public class AxolotlManager extends AbstractManager implements AxolotlService.Po super(context, connection); this.axolotlService = new AxolotlService( - connection.getAccount(), ConversationsDatabase.getInstance(context)); + connection.getAccount(), + context, + ConversationsDatabase.getInstance(context)); this.axolotlService.setPostDecryptionHook(this); }