This commit is contained in:
nielsandriesse 2020-08-11 13:31:21 +10:00
parent 6c5034f4b3
commit 96f235423d
4 changed files with 9 additions and 3 deletions

View File

@ -59,7 +59,7 @@ class ClosedGroupPoller private constructor(private val context: Context, privat
// region Private API // region Private API
private fun poll() { private fun poll() {
if (!isPolling) { return } if (!isPolling) { return }
val publicKeys = database.getAllClosedGroupPublicKeys().map { "05$it" } val publicKeys = database.getAllClosedGroupPublicKeys()
publicKeys.forEach { publicKey -> publicKeys.forEach { publicKey ->
SwarmAPI.shared.getSwarm(publicKey).bind { swarm -> SwarmAPI.shared.getSwarm(publicKey).bind { swarm ->
val snode = swarm.getRandomElementOrNull() ?: throw InsufficientSnodesException() // Should be cryptographically secure val snode = swarm.getRandomElementOrNull() ?: throw InsufficientSnodesException() // Should be cryptographically secure

View File

@ -36,7 +36,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
private val lastMessageHashValueTable2 = "last_message_hash_value_table" private val lastMessageHashValueTable2 = "last_message_hash_value_table"
private val lastMessageHashValue = "last_message_hash_value" private val lastMessageHashValue = "last_message_hash_value"
@JvmStatic val createLastMessageHashValueTable2Command @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 // Received message hash values
private val receivedMessageHashValuesTable2 = "received_message_hash_values_table" private val receivedMessageHashValuesTable2 = "received_message_hash_values_table"
private val receivedMessageHashValues = "received_message_hash_values" private val receivedMessageHashValues = "received_message_hash_values"

View File

@ -101,6 +101,8 @@ class SharedSenderKeysDatabase(context: Context, helper: SQLCipherOpenHelper) :
val database = databaseHelper.readableDatabase val database = databaseHelper.readableDatabase
return database.getAll(closedGroupPrivateKeyTable, null, null) { cursor -> return database.getAll(closedGroupPrivateKeyTable, null, null) { cursor ->
cursor.getString(Companion.closedGroupPublicKey) cursor.getString(Companion.closedGroupPublicKey)
}.filter {
PublicKeyValidation.isValid(it)
}.toSet() }.toSet()
} }
// endregion // endregion

View File

@ -206,6 +206,10 @@ object ClosedGroupsProtocol {
} }
val members = closedGroupUpdate.membersList.map { it.toByteArray().toHexString() } val members = closedGroupUpdate.membersList.map { it.toByteArray().toHexString() }
val admins = closedGroupUpdate.adminsList.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 // Persist the ratchets
senderKeys.forEach { senderKey -> senderKeys.forEach { senderKey ->
if (!members.contains(senderKey.publicKey.toHexString())) { return@forEach } if (!members.contains(senderKey.publicKey.toHexString())) { return@forEach }
@ -218,7 +222,7 @@ object ClosedGroupsProtocol {
null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) })) null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) }))
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.from(context, Address.fromSerialized(groupID), false), true) 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 // 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 // Notify the user
// TODO: Implement // TODO: Implement
// Establish sessions if needed // Establish sessions if needed