1
0
mirror of https://github.com/vector-im/riotX-android synced 2025-10-06 00:02:48 +02:00

Add a cryptoConfig to limit room key requests

This commit is contained in:
yostyle
2021-10-25 17:40:58 +02:00
parent f2c22c1985
commit f343f84490
2 changed files with 12 additions and 3 deletions

View File

@@ -31,5 +31,11 @@ data class MXCryptoConfig constructor(
* If set to false, the request will be forwarded to the application layer; in this
* case the application can decide to prompt the user.
*/
val discardRoomKeyRequestsFromUntrustedDevices: Boolean = true
val discardRoomKeyRequestsFromUntrustedDevices: Boolean = true,
/**
* If set to true, the SDK will send room key request to my devices only.
* If set to false, the SDK will send room key request to my devices and the sender device.
*/
val onlyRequestRoomKeysToMyDevices: Boolean = false
)

View File

@@ -19,6 +19,8 @@ package org.matrix.android.sdk.internal.crypto.algorithms.megolm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.crypto.MXCryptoConfig
import org.matrix.android.sdk.api.extensions.orTrue
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
@@ -53,6 +55,7 @@ internal class MXMegolmDecryption(private val userId: String,
private val cryptoStore: IMXCryptoStore,
private val sendToDeviceTask: SendToDeviceTask,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val cryptoConfig: MXCryptoConfig,
private val cryptoCoroutineScope: CoroutineScope
) : IMXDecrypting, IMXWithHeldExtension {
@@ -68,7 +71,7 @@ internal class MXMegolmDecryption(private val userId: String,
override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
// If cross signing is enabled, we don't send request until the keys are trusted
// There could be a race effect here when xsigning is enabled, we should ensure that keys was downloaded once
val requestOnFail = cryptoStore.getMyCrossSigningInfo()?.isTrusted() == true
val requestOnFail = cryptoStore.getMyCrossSigningInfo()?.isTrusted().orTrue()
return decryptEvent(event, timeline, requestOnFail)
}
@@ -180,7 +183,7 @@ internal class MXMegolmDecryption(private val userId: String,
val encryptedEventContent = event.content.toModel<EncryptedEventContent>()
val senderDevice = encryptedEventContent?.deviceId ?: return
val recipients = if (event.senderId == userId || withHeld) {
val recipients = if (event.senderId == userId || withHeld|| cryptoConfig.onlyRequestRoomKeysToMyDevices) {
mapOf(
userId to listOf("*")
)