@@ -29,8 +29,7 @@ import org.matrix.android.sdk.api.session.events.model.content.RoomKeyContent
2929import org.matrix.android.sdk.api.session.events.model.toModel
3030import org.matrix.android.sdk.internal.crypto.MXOlmDevice
3131import org.matrix.android.sdk.internal.crypto.MegolmSessionData
32- import org.matrix.android.sdk.internal.crypto.actions.EnsureOlmSessionsForDevicesAction
33- import org.matrix.android.sdk.internal.crypto.actions.MessageEncrypter
32+ import org.matrix.android.sdk.internal.crypto.OutgoingKeyRequestManager
3433import org.matrix.android.sdk.internal.crypto.algorithms.IMXDecrypting
3534import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
3635import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
@@ -150,7 +149,8 @@ internal class MXMegolmDecryption(
150149 throw MXCryptoError .Base (
151150 MXCryptoError .ErrorType .KEYS_WITHHELD ,
152151 withHeldInfo.code?.value ? : " " ,
153- withHeldInfo.reason)
152+ withHeldInfo.reason
153+ )
154154 }
155155
156156 if (requestKeysOnFail) {
@@ -249,9 +249,9 @@ internal class MXMegolmDecryption(
249249 )
250250
251251 when (addSessionResult) {
252- is MXOlmDevice .AddSessionResult .Imported -> addSessionResult.ratchetIndex
252+ is MXOlmDevice .AddSessionResult .Imported -> addSessionResult.ratchetIndex
253253 is MXOlmDevice .AddSessionResult .NotImportedHigherIndex -> addSessionResult.newIndex
254- else -> null
254+ else -> null
255255 }?.let { index ->
256256 if (event.getClearType() == EventType .FORWARDED_ROOM_KEY ) {
257257 val fromDevice = (event.content?.get(" sender_key" ) as ? String )?.let { senderDeviceIdentityKey ->
@@ -268,7 +268,8 @@ internal class MXMegolmDecryption(
268268 senderKey = senderKey,
269269 fromIndex = index,
270270 fromDevice = fromDevice,
271- event = event)
271+ event = event
272+ )
272273
273274 cryptoStore.saveIncomingForwardKeyAuditTrail(
274275 roomId = roomKeyContent.roomId,
@@ -277,7 +278,8 @@ internal class MXMegolmDecryption(
277278 algorithm = roomKeyContent.algorithm ? : " " ,
278279 userId = event.senderId ? : " " ,
279280 deviceId = fromDevice ? : " " ,
280- chainIndex = index.toLong())
281+ chainIndex = index.toLong()
282+ )
281283
282284 // The index is used to decide if we cancel sent request or if we wait for a better key
283285 outgoingKeyRequestManager.postCancelRequestForSessionIfNeeded(roomKeyContent.sessionId, roomKeyContent.roomId, senderKey, index)
@@ -304,44 +306,44 @@ internal class MXMegolmDecryption(
304306 Timber .tag(loggerTag.value).v(" ON NEW SESSION $sessionId - $senderKey " )
305307 newSessionListener?.onNewSession(roomId, senderKey, sessionId)
306308 }
307- override fun shareKeysWithDevice (exportedKeys : MegolmSessionData ? , deviceId : String , userId : String ) {
308- exportedKeys ? : return
309- cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
310- runCatching { deviceListManager.downloadKeys(listOf (userId), false ) }
311- .mapCatching {
312- val deviceInfo = cryptoStore.getUserDevice(userId, deviceId)
313- if (deviceInfo == null ) {
314- throw RuntimeException ()
315- } else {
316- val devicesByUser = mapOf (userId to listOf (deviceInfo))
317- val usersDeviceMap = ensureOlmSessionsForDevicesAction.handle(devicesByUser)
318- val olmSessionResult = usersDeviceMap.getObject(userId, deviceId)
319- if (olmSessionResult?.sessionId == null ) {
320- // no session with this device, probably because there
321- // were no one-time keys.
322- Timber .tag(loggerTag.value).e(" no session with this device $deviceId , probably because there were no one-time keys." )
323- return @mapCatching
324- }
325- Timber .tag(loggerTag.value).i(" shareKeysWithDevice() : sharing session ${exportedKeys.sessionId} with device $userId :$deviceId " )
326-
327- val payloadJson = mapOf (
328- " type" to EventType .FORWARDED_ROOM_KEY ,
329- " content" to exportedKeys
330- )
331-
332- val encodedPayload = messageEncrypter.encryptMessage(payloadJson, listOf (deviceInfo))
333- val sendToDeviceMap = MXUsersDevicesMap <Any >()
334- sendToDeviceMap.setObject(userId, deviceId, encodedPayload)
335- Timber .tag(loggerTag.value).i(" shareKeysWithDevice() : sending ${exportedKeys.sessionId} to $userId :$deviceId " )
336- val sendToDeviceParams = SendToDeviceTask .Params (EventType .ENCRYPTED , sendToDeviceMap)
337- try {
338- sendToDeviceTask.execute(sendToDeviceParams)
339- } catch (failure: Throwable ) {
340- Timber .tag(loggerTag.value).e(failure, " shareKeysWithDevice() : Failed to send ${exportedKeys.sessionId} to $userId :$deviceId " )
341- }
342- }
343- }
344- }
345- }
346309
310+ override fun shareForwardKeysWithDevice (exportedKeys : MegolmSessionData ? , deviceId : String , userId : String ) {
311+ // exportedKeys ?: return
312+ // cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
313+ // runCatching { deviceListManager.downloadKeys(listOf(userId), false) }
314+ // .mapCatching {
315+ // val deviceInfo = cryptoStore.getUserDevice(userId, deviceId)
316+ // if (deviceInfo == null) {
317+ // throw RuntimeException()
318+ // } else {
319+ // val devicesByUser = mapOf(userId to listOf(deviceInfo))
320+ // val usersDeviceMap = ensureOlmSessionsForDevicesAction.handle(devicesByUser)
321+ // val olmSessionResult = usersDeviceMap.getObject(userId, deviceId)
322+ // if (olmSessionResult?.sessionId == null) {
323+ // // no session with this device, probably because there
324+ // // were no one-time keys.
325+ // Timber.tag(loggerTag.value).e("no session with this device $deviceId, probably because there were no one-time keys.")
326+ // return@mapCatching
327+ // }
328+ // Timber.tag(loggerTag.value).i("shareKeysWithDevice() : sharing session ${exportedKeys.sessionId} with device $userId:$deviceId")
329+ //
330+ // val payloadJson = mapOf(
331+ // "type" to EventType.FORWARDED_ROOM_KEY,
332+ // "content" to exportedKeys
333+ // )
334+ //
335+ // val encodedPayload = messageEncrypter.encryptMessage(payloadJson, listOf(deviceInfo))
336+ // val sendToDeviceMap = MXUsersDevicesMap<Any>()
337+ // sendToDeviceMap.setObject(userId, deviceId, encodedPayload)
338+ // Timber.tag(loggerTag.value).i("shareKeysWithDevice() : sending ${exportedKeys.sessionId} to $userId:$deviceId")
339+ // val sendToDeviceParams = SendToDeviceTask.Params(EventType.ENCRYPTED, sendToDeviceMap)
340+ // try {
341+ // sendToDeviceTask.execute(sendToDeviceParams)
342+ // } catch (failure: Throwable) {
343+ // Timber.tag(loggerTag.value).e(failure, "shareKeysWithDevice() : Failed to send ${exportedKeys.sessionId} to $userId:$deviceId")
344+ // }
345+ // }
346+ // }
347+ // }
348+ }
347349}
0 commit comments