diff --git a/src/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt b/src/org/thoughtcrime/securesms/loki/api/ClosedGroupPoller.kt index f3a72a474b..7109640bba 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().map { "05$it" } + val publicKeys = database.getAllClosedGroupPublicKeys() 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/LokiAPIDatabase.kt b/src/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt index e89507a3cc..732ce550f0 100644 --- a/src/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt @@ -36,7 +36,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( private val lastMessageHashValueTable2 = "last_message_hash_value_table" private val lastMessageHashValue = "last_message_hash_value" @JvmStatic val createLastMessageHashValueTable2Command - = "CREATE TABLE $lastMessageHashValueTable2 ($snode STRING, $publicKey STRING, $lastMessageHashValue STRING, PRIMARY KEY ($snode, $publicKey));" + = "CREATE TABLE $lastMessageHashValueTable2 ($snode STRING, $publicKey STRING, $lastMessageHashValue TEXT, PRIMARY KEY ($snode, $publicKey));" // Received message hash values private val receivedMessageHashValuesTable2 = "received_message_hash_values_table" private val receivedMessageHashValues = "received_message_hash_values" diff --git a/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt b/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt index de9e86e275..1b668f532e 100644 --- a/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt @@ -101,6 +101,8 @@ class SharedSenderKeysDatabase(context: Context, helper: SQLCipherOpenHelper) : val database = databaseHelper.readableDatabase return database.getAll(closedGroupPrivateKeyTable, null, null) { cursor -> cursor.getString(Companion.closedGroupPublicKey) + }.filter { + PublicKeyValidation.isValid(it) }.toSet() } // endregion diff --git a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt index 735770a231..77eb4d937d 100644 --- a/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt +++ b/src/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt @@ -206,6 +206,10 @@ object ClosedGroupsProtocol { } val members = closedGroupUpdate.membersList.map { it.toByteArray().toHexString() } val admins = closedGroupUpdate.adminsList.map { it.toByteArray().toHexString() } + if (groupPublicKey.isEmpty() || name.isEmpty() || groupPrivateKey.isEmpty() || senderKeys.isEmpty() || members.isEmpty() || admins.isEmpty()) { + Log.d("Loki", "Ignoring invalid new closed group.") + return + } // Persist the ratchets senderKeys.forEach { senderKey -> if (!members.contains(senderKey.publicKey.toHexString())) { return@forEach } @@ -218,7 +222,7 @@ object ClosedGroupsProtocol { null, null, LinkedList
(admins.map { Address.fromSerialized(it) })) DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.from(context, Address.fromSerialized(groupID), false), true) // Add the group to the user's set of public keys to poll for - sskDatabase.setClosedGroupPrivateKey(groupPrivateKey.toHexString(), groupPublicKey) + sskDatabase.setClosedGroupPrivateKey(groupPublicKey, groupPrivateKey.toHexString()) // Notify the user // TODO: Implement // Establish sessions if needed