From 182158c3af11ba55a9b5f8cd6f2afccd93c7c663 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 6 Oct 2020 17:47:00 +0200 Subject: [PATCH] Fix runtime issue after upgrading Moshi library --- .../crypto/IncomingGossipingRequestManager.kt | 12 ++++-- .../crypto/IncomingSecretShareRequest.kt | 4 +- .../sdk/internal/crypto/SendGossipWorker.kt | 40 ++++++++++++++----- .../keysbackup/model/rest/KeysVersion.kt | 7 +++- .../internal/crypto/store/IMXCryptoStore.kt | 29 ++++++++++---- .../crypto/store/db/RealmCryptoStore.kt | 11 +++-- 6 files changed, 74 insertions(+), 29 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt index da72186136..18356ffbb0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt @@ -17,6 +17,8 @@ package org.matrix.android.sdk.internal.crypto +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch import org.matrix.android.sdk.api.auth.data.Credentials import org.matrix.android.sdk.api.crypto.MXCryptoConfig import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME @@ -36,8 +38,6 @@ import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.session.SessionScope import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import org.matrix.android.sdk.internal.worker.WorkerParamsFactory -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch import timber.log.Timber import javax.inject.Inject @@ -327,7 +327,9 @@ internal class IncomingGossipingRequestManager @Inject constructor( val params = SendGossipWorker.Params( sessionId = sessionId, secretValue = secretValue, - request = request + requestUserId = request.userId, + requestDeviceId = request.deviceId, + requestId = request.requestId ) cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTING) @@ -351,7 +353,9 @@ internal class IncomingGossipingRequestManager @Inject constructor( val params = SendGossipWorker.Params( sessionId = userId, secretValue = secretValue, - request = request + requestUserId = request.userId, + requestDeviceId = request.deviceId, + requestId = request.requestId ) cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTING) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingSecretShareRequest.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingSecretShareRequest.kt index de71fd2391..c376a66f09 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingSecretShareRequest.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingSecretShareRequest.kt @@ -17,15 +17,13 @@ package org.matrix.android.sdk.internal.crypto -import com.squareup.moshi.JsonClass import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.internal.crypto.model.rest.SecretShareRequest /** - * IncomingRoomKeyRequest class defines the incoming room keys request. + * IncomingSecretShareRequest class defines the incoming secret keys request. */ -@JsonClass(generateAdapter = true) data class IncomingSecretShareRequest( /** * The user id diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt index c8bfdcd542..1c28dc6fbb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt @@ -47,7 +47,9 @@ internal class SendGossipWorker(context: Context, internal data class Params( override val sessionId: String, val secretValue: String, - val request: IncomingSecretShareRequest, + val requestUserId: String?, + val requestDeviceId: String?, + val requestId: String?, override val lastFailureMessage: String? = null ) : SessionWorkerParams @@ -67,16 +69,21 @@ internal class SendGossipWorker(context: Context, val eventType: String = EventType.SEND_SECRET val toDeviceContent = SecretSendEventContent( - requestId = params.request.requestId ?: "", + requestId = params.requestId ?: "", secretValue = params.secretValue ) - val requestingUserId = params.request.userId ?: "" - val requestingDeviceId = params.request.deviceId ?: "" + val requestingUserId = params.requestUserId ?: "" + val requestingDeviceId = params.requestDeviceId ?: "" val deviceInfo = cryptoStore.getUserDevice(requestingUserId, requestingDeviceId) ?: return buildErrorResult(params, "Unknown deviceInfo, cannot send message").also { - cryptoStore.updateGossipingRequestState(params.request, GossipingRequestState.FAILED_TO_ACCEPTED) - Timber.e("Unknown deviceInfo, cannot send message, sessionId: ${params.request.deviceId}") + cryptoStore.updateGossipingRequestState( + requestUserId = params.requestUserId, + requestDeviceId = params.requestDeviceId, + requestId = params.requestId, + state = GossipingRequestState.FAILED_TO_ACCEPTED + ) + Timber.e("Unknown deviceInfo, cannot send message, sessionId: ${params.requestDeviceId}") } val sendToDeviceMap = MXUsersDevicesMap() @@ -88,7 +95,12 @@ internal class SendGossipWorker(context: Context, // no session with this device, probably because there // were no one-time keys. return buildErrorResult(params, "no session with this device").also { - cryptoStore.updateGossipingRequestState(params.request, GossipingRequestState.FAILED_TO_ACCEPTED) + cryptoStore.updateGossipingRequestState( + requestUserId = params.requestUserId, + requestDeviceId = params.requestDeviceId, + requestId = params.requestId, + state = GossipingRequestState.FAILED_TO_ACCEPTED + ) Timber.e("no session with this device, probably because there were no one-time keys.") } } @@ -121,13 +133,23 @@ internal class SendGossipWorker(context: Context, transactionId = localId ) ) - cryptoStore.updateGossipingRequestState(params.request, GossipingRequestState.ACCEPTED) + cryptoStore.updateGossipingRequestState( + requestUserId = params.requestUserId, + requestDeviceId = params.requestDeviceId, + requestId = params.requestId, + state = GossipingRequestState.ACCEPTED + ) return Result.success() } catch (throwable: Throwable) { return if (throwable.shouldBeRetried()) { Result.retry() } else { - cryptoStore.updateGossipingRequestState(params.request, GossipingRequestState.FAILED_TO_ACCEPTED) + cryptoStore.updateGossipingRequestState( + requestUserId = params.requestUserId, + requestDeviceId = params.requestDeviceId, + requestId = params.requestId, + state = GossipingRequestState.FAILED_TO_ACCEPTED + ) buildErrorResult(params, throwable.localizedMessage ?: "error") } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/model/rest/KeysVersion.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/model/rest/KeysVersion.kt index 3ca8df3131..115e7814d6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/model/rest/KeysVersion.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/model/rest/KeysVersion.kt @@ -17,7 +17,12 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.model.rest +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) data class KeysVersion( // the keys backup version - var version: String? = null + @Json(name = "version") + val version: String? = null ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt index f248e464c2..491a69a1de 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt @@ -1,4 +1,3 @@ - /* * Copyright 2016 OpenMarket Ltd * Copyright 2018 New Vector Ltd @@ -215,11 +214,12 @@ internal interface IMXCryptoStore { // TODO temp fun getLiveDeviceList(): LiveData> - fun getMyDevicesInfo() : List + fun getMyDevicesInfo(): List - fun getLiveMyDevicesInfo() : LiveData> + fun getLiveMyDevicesInfo(): LiveData> fun saveMyDevicesInfo(info: List) + /** * Store the crypto algorithm for a room. * @@ -367,7 +367,19 @@ internal interface IMXCryptoStore { fun saveGossipingEvent(event: Event) - fun updateGossipingRequestState(request: IncomingShareRequestCommon, state: GossipingRequestState) + fun updateGossipingRequestState(request: IncomingShareRequestCommon, state: GossipingRequestState) { + updateGossipingRequestState( + requestUserId = request.userId, + requestDeviceId = request.deviceId, + requestId = request.requestId, + state = state + ) + } + + fun updateGossipingRequestState(requestUserId: String?, + requestDeviceId: String?, + requestId: String?, + state: GossipingRequestState) /** * Search an IncomingRoomKeyRequest @@ -411,7 +423,7 @@ internal interface IMXCryptoStore { fun getLiveCrossSigningPrivateKeys(): LiveData> fun saveBackupRecoveryKey(recoveryKey: String?, version: String?) - fun getKeyBackupRecoveryKeyInfo() : SavedKeyBackupKeyInfo? + fun getKeyBackupRecoveryKeyInfo(): SavedKeyBackupKeyInfo? fun setUserKeysAsTrusted(userId: String, trusted: Boolean = true) fun setDeviceTrust(userId: String, deviceId: String, crossSignedVerified: Boolean, locallyVerified: Boolean?) @@ -421,12 +433,13 @@ internal interface IMXCryptoStore { fun updateUsersTrust(check: (String) -> Boolean) fun addWithHeldMegolmSession(withHeldContent: RoomKeyWithHeldContent) - fun getWithHeldMegolmSession(roomId: String, sessionId: String) : RoomKeyWithHeldContent? + fun getWithHeldMegolmSession(roomId: String, sessionId: String): RoomKeyWithHeldContent? fun markedSessionAsShared(roomId: String?, sessionId: String, userId: String, deviceId: String, chainIndex: Int) - fun wasSessionSharedWithUser(roomId: String?, sessionId: String, userId: String, deviceId: String) : SharedSessionResult + fun wasSessionSharedWithUser(roomId: String?, sessionId: String, userId: String, deviceId: String): SharedSessionResult data class SharedSessionResult(val found: Boolean, val chainIndex: Int?) - fun getSharedWithInfo(roomId: String?, sessionId: String) : MXUsersDevicesMap + + fun getSharedWithInfo(roomId: String?, sessionId: String): MXUsersDevicesMap // Dev tools fun getOutgoingRoomKeyRequests(): List diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt index df71ef9eba..4f63ddc238 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt @@ -1134,12 +1134,15 @@ internal class RealmCryptoStore @Inject constructor( // } // } - override fun updateGossipingRequestState(request: IncomingShareRequestCommon, state: GossipingRequestState) { + override fun updateGossipingRequestState(requestUserId: String?, + requestDeviceId: String?, + requestId: String?, + state: GossipingRequestState) { doRealmTransaction(realmConfiguration) { realm -> realm.where() - .equalTo(IncomingGossipingRequestEntityFields.OTHER_USER_ID, request.userId) - .equalTo(IncomingGossipingRequestEntityFields.OTHER_DEVICE_ID, request.deviceId) - .equalTo(IncomingGossipingRequestEntityFields.REQUEST_ID, request.requestId) + .equalTo(IncomingGossipingRequestEntityFields.OTHER_USER_ID, requestUserId) + .equalTo(IncomingGossipingRequestEntityFields.OTHER_DEVICE_ID, requestDeviceId) + .equalTo(IncomingGossipingRequestEntityFields.REQUEST_ID, requestId) .findAll().forEach { it.requestState = state }