From ceaee33d28e9533fbba46655aedf6c695224a560 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 21 May 2020 14:29:51 +1000 Subject: [PATCH] Fix self syncing --- .../MultiDeviceStickerPackOperationJob.java | 8 ++---- .../jobs/MultiDeviceStickerPackSyncJob.java | 13 +++------- .../jobs/MultiDeviceVerifiedUpdateJob.java | 15 ++++------- .../securesms/jobs/PushDecryptJob.java | 25 ++++++++++++------- .../securesms/jobs/PushMediaSendJob.java | 4 ++- .../securesms/jobs/PushSendJob.java | 14 +++++------ .../securesms/jobs/PushTextSendJob.java | 6 +++-- .../loki/protocol/SyncMessagesProtocol.kt | 2 +- 8 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackOperationJob.java b/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackOperationJob.java index 3e27b5f89d..f30a353f5e 100644 --- a/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackOperationJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackOperationJob.java @@ -2,20 +2,14 @@ package org.thoughtcrime.securesms.jobs; import android.support.annotation.NonNull; -import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.Hex; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.signalservice.api.SignalServiceMessageSender; -import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; -import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage; import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; -import java.util.Collections; import java.util.concurrent.TimeUnit; import javax.inject.Inject; @@ -76,6 +70,7 @@ public class MultiDeviceStickerPackOperationJob extends BaseJob implements Injec @Override protected void onRun() throws Exception { + /* if (!TextSecurePreferences.isMultiDevice(context)) { Log.i(TAG, "Not multi device, aborting..."); return; @@ -96,6 +91,7 @@ public class MultiDeviceStickerPackOperationJob extends BaseJob implements Injec messageSender.sendMessage(SignalServiceSyncMessage.forStickerPackOperations(Collections.singletonList(stickerPackOperation)), UnidentifiedAccessUtil.getAccessForSync(context)); + */ } @Override diff --git a/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackSyncJob.java b/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackSyncJob.java index 4fcc526b58..f918659446 100644 --- a/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackSyncJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MultiDeviceStickerPackSyncJob.java @@ -2,24 +2,14 @@ package org.thoughtcrime.securesms.jobs; import android.support.annotation.NonNull; -import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; -import org.thoughtcrime.securesms.database.DatabaseFactory; -import org.thoughtcrime.securesms.database.StickerDatabase.StickerPackRecordReader; -import org.thoughtcrime.securesms.database.model.StickerPackRecord; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.Hex; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.signalservice.api.SignalServiceMessageSender; -import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; -import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage; import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; -import java.util.LinkedList; -import java.util.List; import java.util.concurrent.TimeUnit; import javax.inject.Inject; @@ -59,6 +49,8 @@ public class MultiDeviceStickerPackSyncJob extends BaseJob implements Injectable @Override protected void onRun() throws Exception { + return; + /* if (!TextSecurePreferences.isMultiDevice(context)) { Log.i(TAG, "Not multi device, aborting..."); return; @@ -78,6 +70,7 @@ public class MultiDeviceStickerPackSyncJob extends BaseJob implements Injectable messageSender.sendMessage(SignalServiceSyncMessage.forStickerPackOperations(operations), UnidentifiedAccessUtil.getAccessForSync(context)); + */ } @Override diff --git a/src/org/thoughtcrime/securesms/jobs/MultiDeviceVerifiedUpdateJob.java b/src/org/thoughtcrime/securesms/jobs/MultiDeviceVerifiedUpdateJob.java index 8a498d02cd..81e6299e2c 100644 --- a/src/org/thoughtcrime/securesms/jobs/MultiDeviceVerifiedUpdateJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MultiDeviceVerifiedUpdateJob.java @@ -3,23 +3,16 @@ package org.thoughtcrime.securesms.jobs; import android.support.annotation.NonNull; -import org.thoughtcrime.securesms.jobmanager.Data; -import org.thoughtcrime.securesms.jobmanager.Job; -import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; -import org.thoughtcrime.securesms.logging.Log; - -import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus; import org.thoughtcrime.securesms.dependencies.InjectableType; +import org.thoughtcrime.securesms.jobmanager.Data; +import org.thoughtcrime.securesms.jobmanager.Job; +import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.util.Base64; -import org.thoughtcrime.securesms.recipients.Recipient; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.InvalidKeyException; import org.whispersystems.signalservice.api.SignalServiceMessageSender; import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException; -import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage; import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; @@ -89,6 +82,7 @@ public class MultiDeviceVerifiedUpdateJob extends BaseJob implements InjectableT @Override public void onRun() throws IOException, UntrustedIdentityException { + /* try { if (!TextSecurePreferences.isMultiDevice(context)) { Log.i(TAG, "Not multi device..."); @@ -109,6 +103,7 @@ public class MultiDeviceVerifiedUpdateJob extends BaseJob implements InjectableT } catch (InvalidKeyException e) { throw new IOException(e); } + */ } private VerifiedMessage.VerifiedState getVerifiedState(VerifiedStatus status) { diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 97a06606f9..aeb0178ad9 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -135,6 +135,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Set; import javax.inject.Inject; @@ -1393,16 +1394,22 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (recipient.isGroupRecipient()) { return recipient; } else { - try { - // TODO: Burn this with fire when we can - PromiseUtilities.timeout(LokiFileServerAPI.shared.getDeviceLinks(publicKey, false), 4000).get(); - String masterPublicKey = org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol.shared.getMasterDevice(publicKey); - if (masterPublicKey == null) { - masterPublicKey = publicKey; + String userPublicKey = TextSecurePreferences.getLocalNumber(context); + Set allUserDevices = org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol.shared.getAllLinkedDevices(userPublicKey); + if (allUserDevices.contains(publicKey)) { + return Recipient.from(context, Address.fromSerialized(userPublicKey), false); + } else { + try { + // TODO: Burn this with fire when we can + PromiseUtilities.timeout(LokiFileServerAPI.shared.getDeviceLinks(publicKey, false), 4000).get(); + String masterPublicKey = org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol.shared.getMasterDevice(publicKey); + if (masterPublicKey == null) { + masterPublicKey = publicKey; + } + return Recipient.from(context, Address.fromSerialized(masterPublicKey), false); + } catch (Exception e) { + return recipient; } - return Recipient.from(context, Address.fromSerialized(masterPublicKey), false); - } catch (Exception e) { - return recipient; } } } diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index 29802525e5..6051021665 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -45,6 +45,7 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; import org.whispersystems.signalservice.loki.api.LokiAPI; +import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol; import java.io.FileNotFoundException; import java.io.IOException; @@ -293,7 +294,8 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { .asFriendRequest(isLokiPreKeyBundleMessage) .build(); - if (address.getNumber().equals(TextSecurePreferences.getLocalNumber(context))) { + if (SessionMetaProtocol.shared.isNoteToSelf(address.getNumber())) { + // Loki - Device link messages don't go through here Optional syncAccess = UnidentifiedAccessUtil.getAccessForSync(context); SignalServiceSyncMessage syncMessage = buildSelfSendSyncMessage(context, mediaMessage, syncAccess); diff --git a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java index 5bce0332f1..3d0eb2e259 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -282,13 +282,13 @@ public abstract class PushSendJob extends SendJob { } protected SignalServiceSyncMessage buildSelfSendSyncMessage(@NonNull Context context, @NonNull SignalServiceDataMessage message, Optional syncAccess) { - String primary = TextSecurePreferences.getMasterHexEncodedPublicKey(context); - String localNumber = primary != null ? primary : TextSecurePreferences.getLocalNumber(context); - SentTranscriptMessage transcript = new SentTranscriptMessage(localNumber, - message.getTimestamp(), - message, - message.getExpiresInSeconds(), - Collections.singletonMap(localNumber, syncAccess.isPresent())); + String masterPublicKeyOrNull = TextSecurePreferences.getMasterHexEncodedPublicKey(context); + String masterPublicKey = masterPublicKeyOrNull != null ? masterPublicKeyOrNull : TextSecurePreferences.getLocalNumber(context); + SentTranscriptMessage transcript = new SentTranscriptMessage(masterPublicKey, + message.getTimestamp(), + message, + message.getExpiresInSeconds(), + Collections.singletonMap(masterPublicKey, syncAccess.isPresent())); return SignalServiceSyncMessage.forSentTranscript(transcript); } diff --git a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java index 458d885331..f6f58b6c74 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java @@ -33,6 +33,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSy import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; import org.whispersystems.signalservice.loki.api.LokiAPI; +import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol; import java.io.IOException; @@ -232,9 +233,10 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { .withPreKeyBundle(preKeyBundle) .build(); - if (address.getNumber().equals(TextSecurePreferences.getLocalNumber(context))) { + if (SessionMetaProtocol.shared.isNoteToSelf(address.getNumber())) { + // Loki - Device link messages don't go through here Optional syncAccess = UnidentifiedAccessUtil.getAccessForSync(context); - SignalServiceSyncMessage syncMessage = buildSelfSendSyncMessage(context, textSecureMessage, syncAccess); + SignalServiceSyncMessage syncMessage = buildSelfSendSyncMessage(context, textSecureMessage, syncAccess); messageSender.sendMessage(syncMessage, syncAccess); return syncAccess.isPresent(); diff --git a/src/org/thoughtcrime/securesms/loki/protocol/SyncMessagesProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/SyncMessagesProtocol.kt index d17cb723d9..db0a8a85d7 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/SyncMessagesProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/SyncMessagesProtocol.kt @@ -34,7 +34,7 @@ object SyncMessagesProtocol { @JvmStatic fun shouldIgnoreSyncMessage(context: Context, sender: Recipient): Boolean { val userPublicKey = TextSecurePreferences.getLocalNumber(context) - return MultiDeviceProtocol.shared.getAllLinkedDevices(userPublicKey).contains(sender.address.serialize()) + return !MultiDeviceProtocol.shared.getAllLinkedDevices(userPublicKey).contains(sender.address.serialize()) } @JvmStatic