Fix runtime issue after upgrading Moshi library

This commit is contained in:
Benoit Marty 2020-10-06 17:47:00 +02:00
parent dd1c9976e3
commit 182158c3af
6 changed files with 74 additions and 29 deletions

View File

@ -17,6 +17,8 @@
package org.matrix.android.sdk.internal.crypto 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.auth.data.Credentials
import org.matrix.android.sdk.api.crypto.MXCryptoConfig import org.matrix.android.sdk.api.crypto.MXCryptoConfig
import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME 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.session.SessionScope
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory import org.matrix.android.sdk.internal.worker.WorkerParamsFactory
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -327,7 +327,9 @@ internal class IncomingGossipingRequestManager @Inject constructor(
val params = SendGossipWorker.Params( val params = SendGossipWorker.Params(
sessionId = sessionId, sessionId = sessionId,
secretValue = secretValue, secretValue = secretValue,
request = request requestUserId = request.userId,
requestDeviceId = request.deviceId,
requestId = request.requestId
) )
cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTING) cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTING)
@ -351,7 +353,9 @@ internal class IncomingGossipingRequestManager @Inject constructor(
val params = SendGossipWorker.Params( val params = SendGossipWorker.Params(
sessionId = userId, sessionId = userId,
secretValue = secretValue, secretValue = secretValue,
request = request requestUserId = request.userId,
requestDeviceId = request.deviceId,
requestId = request.requestId
) )
cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTING) cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTING)

View File

@ -17,15 +17,13 @@
package org.matrix.android.sdk.internal.crypto 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.Event
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.internal.crypto.model.rest.SecretShareRequest 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( data class IncomingSecretShareRequest(
/** /**
* The user id * The user id

View File

@ -47,7 +47,9 @@ internal class SendGossipWorker(context: Context,
internal data class Params( internal data class Params(
override val sessionId: String, override val sessionId: String,
val secretValue: String, val secretValue: String,
val request: IncomingSecretShareRequest, val requestUserId: String?,
val requestDeviceId: String?,
val requestId: String?,
override val lastFailureMessage: String? = null override val lastFailureMessage: String? = null
) : SessionWorkerParams ) : SessionWorkerParams
@ -67,16 +69,21 @@ internal class SendGossipWorker(context: Context,
val eventType: String = EventType.SEND_SECRET val eventType: String = EventType.SEND_SECRET
val toDeviceContent = SecretSendEventContent( val toDeviceContent = SecretSendEventContent(
requestId = params.request.requestId ?: "", requestId = params.requestId ?: "",
secretValue = params.secretValue secretValue = params.secretValue
) )
val requestingUserId = params.request.userId ?: "" val requestingUserId = params.requestUserId ?: ""
val requestingDeviceId = params.request.deviceId ?: "" val requestingDeviceId = params.requestDeviceId ?: ""
val deviceInfo = cryptoStore.getUserDevice(requestingUserId, requestingDeviceId) val deviceInfo = cryptoStore.getUserDevice(requestingUserId, requestingDeviceId)
?: return buildErrorResult(params, "Unknown deviceInfo, cannot send message").also { ?: return buildErrorResult(params, "Unknown deviceInfo, cannot send message").also {
cryptoStore.updateGossipingRequestState(params.request, GossipingRequestState.FAILED_TO_ACCEPTED) cryptoStore.updateGossipingRequestState(
Timber.e("Unknown deviceInfo, cannot send message, sessionId: ${params.request.deviceId}") 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<Any>() val sendToDeviceMap = MXUsersDevicesMap<Any>()
@ -88,7 +95,12 @@ internal class SendGossipWorker(context: Context,
// no session with this device, probably because there // no session with this device, probably because there
// were no one-time keys. // were no one-time keys.
return buildErrorResult(params, "no session with this device").also { 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.") 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 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() return Result.success()
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
return if (throwable.shouldBeRetried()) { return if (throwable.shouldBeRetried()) {
Result.retry() Result.retry()
} else { } 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") buildErrorResult(params, throwable.localizedMessage ?: "error")
} }
} }

View File

@ -17,7 +17,12 @@
package org.matrix.android.sdk.internal.crypto.keysbackup.model.rest 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( data class KeysVersion(
// the keys backup version // the keys backup version
var version: String? = null @Json(name = "version")
val version: String? = null
) )

View File

@ -1,4 +1,3 @@
/* /*
* Copyright 2016 OpenMarket Ltd * Copyright 2016 OpenMarket Ltd
* Copyright 2018 New Vector Ltd * Copyright 2018 New Vector Ltd
@ -220,6 +219,7 @@ internal interface IMXCryptoStore {
fun getLiveMyDevicesInfo(): LiveData<List<DeviceInfo>> fun getLiveMyDevicesInfo(): LiveData<List<DeviceInfo>>
fun saveMyDevicesInfo(info: List<DeviceInfo>) fun saveMyDevicesInfo(info: List<DeviceInfo>)
/** /**
* Store the crypto algorithm for a room. * Store the crypto algorithm for a room.
* *
@ -367,7 +367,19 @@ internal interface IMXCryptoStore {
fun saveGossipingEvent(event: Event) 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 * Search an IncomingRoomKeyRequest
@ -426,6 +438,7 @@ internal interface IMXCryptoStore {
fun markedSessionAsShared(roomId: String?, sessionId: String, userId: String, deviceId: String, chainIndex: Int) 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?) data class SharedSessionResult(val found: Boolean, val chainIndex: Int?)
fun getSharedWithInfo(roomId: String?, sessionId: String): MXUsersDevicesMap<Int> fun getSharedWithInfo(roomId: String?, sessionId: String): MXUsersDevicesMap<Int>
// Dev tools // Dev tools

View File

@ -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 -> doRealmTransaction(realmConfiguration) { realm ->
realm.where<IncomingGossipingRequestEntity>() realm.where<IncomingGossipingRequestEntity>()
.equalTo(IncomingGossipingRequestEntityFields.OTHER_USER_ID, request.userId) .equalTo(IncomingGossipingRequestEntityFields.OTHER_USER_ID, requestUserId)
.equalTo(IncomingGossipingRequestEntityFields.OTHER_DEVICE_ID, request.deviceId) .equalTo(IncomingGossipingRequestEntityFields.OTHER_DEVICE_ID, requestDeviceId)
.equalTo(IncomingGossipingRequestEntityFields.REQUEST_ID, request.requestId) .equalTo(IncomingGossipingRequestEntityFields.REQUEST_ID, requestId)
.findAll().forEach { .findAll().forEach {
it.requestState = state it.requestState = state
} }