From e2ce43c3cdbcecd9021245c0289efbc8c280bc6d Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Tue, 11 Aug 2020 11:51:51 +1000 Subject: [PATCH] Debug --- src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java | 4 ++++ src/org/thoughtcrime/securesms/jobs/PushReceivedJob.java | 3 ++- src/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt | 2 +- .../securesms/loki/database/SharedSenderKeysDatabase.kt | 2 ++ .../securesms/loki/protocol/ClosedGroupsProtocol.kt | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 425ffaf441..47344b0f2f 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -279,6 +279,10 @@ public class PushDecryptJob extends BaseJob implements InjectableType { MultiDeviceProtocol.handleUnlinkingRequestIfNeeded(context, content); } else { + if (message.getClosedGroupUpdate().isPresent()) { + ClosedGroupsProtocol.handleSharedSenderKeysUpdate(context, message.getClosedGroupUpdate().get(), content.getSender()); + } + if (message.isEndSession()) { handleEndSessionMessage(content, smsMessageId); } else if (message.isGroupUpdate()) { diff --git a/src/org/thoughtcrime/securesms/jobs/PushReceivedJob.java b/src/org/thoughtcrime/securesms/jobs/PushReceivedJob.java index 63fc0f65d5..34570b169d 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushReceivedJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushReceivedJob.java @@ -36,7 +36,8 @@ public abstract class PushReceivedJob extends BaseJob { if (envelope.isReceipt()) { handleReceipt(envelope); - } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage() || envelope.isUnidentifiedSender() || envelope.isFallbackMessage()) { + } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage() + || envelope.isUnidentifiedSender() || envelope.isFallbackMessage() || envelope.isClosedGroupCiphertext()) { handleMessage(envelope, isPushNotification); } else { Log.w(TAG, "Received envelope of unknown type: " + envelope.getType()); diff --git a/src/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt b/src/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt index 7109640bba..f3a72a474b 100644 --- a/src/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt +++ b/src/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt @@ -59,7 +59,7 @@ class ClosedGroupPoller private constructor(private val context: Context, privat // region Private API private fun poll() { if (!isPolling) { return } - val publicKeys = database.getAllClosedGroupPublicKeys() + val publicKeys = database.getAllClosedGroupPublicKeys().map { "05$it" } publicKeys.forEach { publicKey -> SwarmAPI.shared.getSwarm(publicKey).bind { swarm -> val snode = swarm.getRandomElementOrNull() ?: throw InsufficientSnodesException() // Should be cryptographically secure diff --git a/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt b/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt index d251208f66..de9e86e275 100644 --- a/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt @@ -9,6 +9,7 @@ import org.thoughtcrime.securesms.util.Hex import org.whispersystems.signalservice.loki.protocol.closedgroups.ClosedGroupRatchet import org.whispersystems.signalservice.loki.protocol.closedgroups.ClosedGroupSenderKey import org.whispersystems.signalservice.loki.protocol.closedgroups.SharedSenderKeysDatabaseProtocol +import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation class SharedSenderKeysDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), SharedSenderKeysDatabaseProtocol { @@ -105,6 +106,7 @@ class SharedSenderKeysDatabase(context: Context, helper: SQLCipherOpenHelper) : // endregion override fun isSSKBasedClosedGroup(groupPublicKey: String): Boolean { + if (!PublicKeyValidation.isValid(groupPublicKey)) { return false } return getAllClosedGroupPublicKeys().contains(groupPublicKey) } // endregion diff --git a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt index bebdce37af..50aeffeb8d 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt @@ -180,6 +180,7 @@ object ClosedGroupsProtocol { ApplicationContext.getInstance(context).jobManager.add(job) } + @JvmStatic public fun handleSharedSenderKeysUpdate(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) { when (closedGroupUpdate.type) { SignalServiceProtos.ClosedGroupUpdate.Type.NEW -> handleNewClosedGroup(context, closedGroupUpdate)