From ffc707401bc3f11aafd0b3d9b21a038ebbb2e44c Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 11 May 2022 15:11:34 +0200 Subject: [PATCH] post rebase fix --- .../internal/crypto/DefaultCryptoService.kt | 1 - .../crypto/IncomingKeyRequestManager.kt | 2 +- .../algorithms/megolm/MXMegolmDecryption.kt | 94 ++++++++++--------- .../store/db/RealmCryptoStoreMigration.kt | 3 - 4 files changed, 49 insertions(+), 51 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index c79a888c704..464d97bd31d 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -93,7 +93,6 @@ import org.matrix.android.sdk.internal.crypto.tasks.SetDeviceNameTask import org.matrix.android.sdk.internal.crypto.tasks.UploadKeysTask import org.matrix.android.sdk.internal.crypto.verification.DefaultVerificationService import org.matrix.android.sdk.internal.crypto.verification.VerificationMessageProcessor -import org.matrix.android.sdk.internal.database.helper.SessionInfoPair import org.matrix.android.sdk.internal.di.DeviceId import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.di.UserId diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt index 13f2fb861ab..78789802212 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingKeyRequestManager.kt @@ -403,7 +403,7 @@ internal class IncomingKeyRequestManager @Inject constructor( } val export = sessionHolder.mutex.withLock { - sessionHolder.wrapper.exportKeys(chainIndex) + sessionHolder.wrapper.exportKeys(/**TODO*/ false ,chainIndex) } ?: return false.also { Timber.tag(loggerTag.value) .e("shareKeysWithDevice: failed to export group session ${validRequest.sessionId}") diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt index db6d8d761a4..b3f155ca38b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt @@ -29,8 +29,7 @@ import org.matrix.android.sdk.api.session.events.model.content.RoomKeyContent import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.internal.crypto.MXOlmDevice import org.matrix.android.sdk.internal.crypto.MegolmSessionData -import org.matrix.android.sdk.internal.crypto.actions.EnsureOlmSessionsForDevicesAction -import org.matrix.android.sdk.internal.crypto.actions.MessageEncrypter +import org.matrix.android.sdk.internal.crypto.OutgoingKeyRequestManager import org.matrix.android.sdk.internal.crypto.algorithms.IMXDecrypting import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore @@ -150,7 +149,8 @@ internal class MXMegolmDecryption( throw MXCryptoError.Base( MXCryptoError.ErrorType.KEYS_WITHHELD, withHeldInfo.code?.value ?: "", - withHeldInfo.reason) + withHeldInfo.reason + ) } if (requestKeysOnFail) { @@ -249,9 +249,9 @@ internal class MXMegolmDecryption( ) when (addSessionResult) { - is MXOlmDevice.AddSessionResult.Imported -> addSessionResult.ratchetIndex + is MXOlmDevice.AddSessionResult.Imported -> addSessionResult.ratchetIndex is MXOlmDevice.AddSessionResult.NotImportedHigherIndex -> addSessionResult.newIndex - else -> null + else -> null }?.let { index -> if (event.getClearType() == EventType.FORWARDED_ROOM_KEY) { val fromDevice = (event.content?.get("sender_key") as? String)?.let { senderDeviceIdentityKey -> @@ -268,7 +268,8 @@ internal class MXMegolmDecryption( senderKey = senderKey, fromIndex = index, fromDevice = fromDevice, - event = event) + event = event + ) cryptoStore.saveIncomingForwardKeyAuditTrail( roomId = roomKeyContent.roomId, @@ -277,7 +278,8 @@ internal class MXMegolmDecryption( algorithm = roomKeyContent.algorithm ?: "", userId = event.senderId ?: "", deviceId = fromDevice ?: "", - chainIndex = index.toLong()) + chainIndex = index.toLong() + ) // The index is used to decide if we cancel sent request or if we wait for a better key outgoingKeyRequestManager.postCancelRequestForSessionIfNeeded(roomKeyContent.sessionId, roomKeyContent.roomId, senderKey, index) @@ -304,44 +306,44 @@ internal class MXMegolmDecryption( Timber.tag(loggerTag.value).v("ON NEW SESSION $sessionId - $senderKey") newSessionListener?.onNewSession(roomId, senderKey, sessionId) } - override fun shareKeysWithDevice(exportedKeys: MegolmSessionData?, deviceId: String, userId: String) { - exportedKeys ?: return - cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { - runCatching { deviceListManager.downloadKeys(listOf(userId), false) } - .mapCatching { - val deviceInfo = cryptoStore.getUserDevice(userId, deviceId) - if (deviceInfo == null) { - throw RuntimeException() - } else { - val devicesByUser = mapOf(userId to listOf(deviceInfo)) - val usersDeviceMap = ensureOlmSessionsForDevicesAction.handle(devicesByUser) - val olmSessionResult = usersDeviceMap.getObject(userId, deviceId) - if (olmSessionResult?.sessionId == null) { - // no session with this device, probably because there - // were no one-time keys. - Timber.tag(loggerTag.value).e("no session with this device $deviceId, probably because there were no one-time keys.") - return@mapCatching - } - Timber.tag(loggerTag.value).i("shareKeysWithDevice() : sharing session ${exportedKeys.sessionId} with device $userId:$deviceId") - - val payloadJson = mapOf( - "type" to EventType.FORWARDED_ROOM_KEY, - "content" to exportedKeys - ) - - val encodedPayload = messageEncrypter.encryptMessage(payloadJson, listOf(deviceInfo)) - val sendToDeviceMap = MXUsersDevicesMap() - sendToDeviceMap.setObject(userId, deviceId, encodedPayload) - Timber.tag(loggerTag.value).i("shareKeysWithDevice() : sending ${exportedKeys.sessionId} to $userId:$deviceId") - val sendToDeviceParams = SendToDeviceTask.Params(EventType.ENCRYPTED, sendToDeviceMap) - try { - sendToDeviceTask.execute(sendToDeviceParams) - } catch (failure: Throwable) { - Timber.tag(loggerTag.value).e(failure, "shareKeysWithDevice() : Failed to send ${exportedKeys.sessionId} to $userId:$deviceId") - } - } - } - } - } + override fun shareForwardKeysWithDevice(exportedKeys: MegolmSessionData?, deviceId: String, userId: String) { +// exportedKeys ?: return +// cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { +// runCatching { deviceListManager.downloadKeys(listOf(userId), false) } +// .mapCatching { +// val deviceInfo = cryptoStore.getUserDevice(userId, deviceId) +// if (deviceInfo == null) { +// throw RuntimeException() +// } else { +// val devicesByUser = mapOf(userId to listOf(deviceInfo)) +// val usersDeviceMap = ensureOlmSessionsForDevicesAction.handle(devicesByUser) +// val olmSessionResult = usersDeviceMap.getObject(userId, deviceId) +// if (olmSessionResult?.sessionId == null) { +// // no session with this device, probably because there +// // were no one-time keys. +// Timber.tag(loggerTag.value).e("no session with this device $deviceId, probably because there were no one-time keys.") +// return@mapCatching +// } +// Timber.tag(loggerTag.value).i("shareKeysWithDevice() : sharing session ${exportedKeys.sessionId} with device $userId:$deviceId") +// +// val payloadJson = mapOf( +// "type" to EventType.FORWARDED_ROOM_KEY, +// "content" to exportedKeys +// ) +// +// val encodedPayload = messageEncrypter.encryptMessage(payloadJson, listOf(deviceInfo)) +// val sendToDeviceMap = MXUsersDevicesMap() +// sendToDeviceMap.setObject(userId, deviceId, encodedPayload) +// Timber.tag(loggerTag.value).i("shareKeysWithDevice() : sending ${exportedKeys.sessionId} to $userId:$deviceId") +// val sendToDeviceParams = SendToDeviceTask.Params(EventType.ENCRYPTED, sendToDeviceMap) +// try { +// sendToDeviceTask.execute(sendToDeviceParams) +// } catch (failure: Throwable) { +// Timber.tag(loggerTag.value).e(failure, "shareKeysWithDevice() : Failed to send ${exportedKeys.sessionId} to $userId:$deviceId") +// } +// } +// } +// } + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt index 61b2afba8b5..e0fed3fdf5c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt @@ -73,9 +73,6 @@ internal class RealmCryptoStoreMigration @Inject constructor( if (oldVersion < 14) MigrateCryptoTo014(realm).perform() if (oldVersion < 15) MigrateCryptoTo015(realm).perform() if (oldVersion < 16) MigrateCryptoTo016(realm).perform() -<<<<<<< develop if (oldVersion < 17) MigrateCryptoTo017(realm).perform() -======= ->>>>>>> Implement history key sharing functionality with respect to room visibility settings } }