Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cryptoConfig to limit room key requests #4333

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand All @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is not strictly equivalent to the previous version. Is it intended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit strange yes, and unwanted I think (or should be guarded by a flag)

return decryptEvent(event, timeline, requestOnFail)
}

Expand Down Expand Up @@ -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("*")
)
Expand Down