From 4fb59aadb15ddd04ca3f553b9152c2c141895f86 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 31 Jan 2020 09:39:31 +0100 Subject: [PATCH] Fix / ensure RoomKeyRequest are made after device is verified --- .../crypto/IncomingRoomKeyRequestManager.kt | 8 ++++++++ .../crypto/algorithms/megolm/MXMegolmDecryption.kt | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt index e7c500edbf..290de52e85 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt @@ -122,6 +122,14 @@ internal class IncomingRoomKeyRequestManager @Inject constructor( continue } } + + // If cross signing is available on account we automatically discard untrust devices request + if (cryptoStore.getMyCrossSigningInfo() != null) { + // At this point the device is unknown, we don't want to bother user with that + cryptoStore.deleteIncomingRoomKeyRequest(request) + continue + } + cryptoStore.storeIncomingRoomKeyRequest(request) onRoomKeyRequest(request) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt index 49871434f9..99d23a888a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt @@ -21,7 +21,12 @@ import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel -import im.vector.matrix.android.internal.crypto.* +import im.vector.matrix.android.internal.crypto.DeviceListManager +import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequest +import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult +import im.vector.matrix.android.internal.crypto.MXOlmDevice +import im.vector.matrix.android.internal.crypto.NewSessionListener +import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequestManager import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevicesAction import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter import im.vector.matrix.android.internal.crypto.algorithms.IMXDecrypting @@ -59,7 +64,12 @@ internal class MXMegolmDecryption(private val userId: String, private var pendingEvents: MutableMap>> = HashMap() override suspend fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult { - return decryptEvent(event, timeline, true) + // If cross signing is enabled, we don't send request until the keys are trusted + val requestOnFail = + if (cryptoStore.getMyCrossSigningInfo() != null) + cryptoStore.getMyCrossSigningInfo()?.isTrusted() == true + else true // Legacy + return decryptEvent(event, timeline, requestOnFail) } private fun decryptEvent(event: Event, timeline: String, requestKeysOnFail: Boolean): MXEventDecryptionResult {