post rebase fix

This commit is contained in:
Valere 2021-11-19 15:14:04 +01:00
parent f209ae26bc
commit 9e055d9793
12 changed files with 23 additions and 48 deletions

View file

@ -24,6 +24,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import org.matrix.android.sdk.api.session.crypto.CryptoService import org.matrix.android.sdk.api.session.crypto.CryptoService
import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.internal.crypto.api.CryptoApi import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.crosssigning.ComputeTrustTask import org.matrix.android.sdk.internal.crypto.crosssigning.ComputeTrustTask
import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultComputeTrustTask import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultComputeTrustTask
@ -88,6 +89,7 @@ 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.tasks.UploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadSignaturesTask import org.matrix.android.sdk.internal.crypto.tasks.UploadSignaturesTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadSigningKeysTask import org.matrix.android.sdk.internal.crypto.tasks.UploadSigningKeysTask
import org.matrix.android.sdk.internal.crypto.verification.RustVerificationService
import org.matrix.android.sdk.internal.database.RealmKeysUtils import org.matrix.android.sdk.internal.database.RealmKeysUtils
import org.matrix.android.sdk.internal.di.CryptoDatabase import org.matrix.android.sdk.internal.di.CryptoDatabase
import org.matrix.android.sdk.internal.di.SessionFilesDirectory import org.matrix.android.sdk.internal.di.SessionFilesDirectory
@ -95,11 +97,6 @@ import org.matrix.android.sdk.internal.di.UserMd5
import org.matrix.android.sdk.internal.session.SessionScope import org.matrix.android.sdk.internal.session.SessionScope
import org.matrix.android.sdk.internal.session.cache.ClearCacheTask import org.matrix.android.sdk.internal.session.cache.ClearCacheTask
import org.matrix.android.sdk.internal.session.cache.RealmClearCacheTask import org.matrix.android.sdk.internal.session.cache.RealmClearCacheTask
import io.realm.RealmConfiguration
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.internal.crypto.verification.RustVerificationService
import retrofit2.Retrofit import retrofit2.Retrofit
import java.io.File import java.io.File

View file

@ -20,8 +20,6 @@ import android.content.Context
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.paging.PagedList import androidx.paging.PagedList
import com.squareup.moshi.Types
import dagger.Lazy
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async import kotlinx.coroutines.async
@ -39,14 +37,12 @@ import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
import org.matrix.android.sdk.api.crypto.MXCryptoConfig import org.matrix.android.sdk.api.crypto.MXCryptoConfig
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.MatrixError
import org.matrix.android.sdk.api.listeners.ProgressListener import org.matrix.android.sdk.api.listeners.ProgressListener
import org.matrix.android.sdk.api.session.crypto.CryptoService import org.matrix.android.sdk.api.session.crypto.CryptoService
import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.session.crypto.MXCryptoError
import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupService import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupService
import org.matrix.android.sdk.api.session.crypto.keyshare.GossipingRequestListener import org.matrix.android.sdk.api.session.crypto.keyshare.GossipingRequestListener
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.api.session.events.model.Content import org.matrix.android.sdk.api.session.events.model.Content
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.EventType import org.matrix.android.sdk.api.session.events.model.EventType
@ -58,26 +54,8 @@ import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
import org.matrix.android.sdk.api.session.sync.model.DeviceListResponse import org.matrix.android.sdk.api.session.sync.model.DeviceListResponse
import org.matrix.android.sdk.api.session.sync.model.DeviceOneTimeKeysCountSyncResponse import org.matrix.android.sdk.api.session.sync.model.DeviceOneTimeKeysCountSyncResponse
import org.matrix.android.sdk.api.session.sync.model.ToDeviceSyncResponse import org.matrix.android.sdk.api.session.sync.model.ToDeviceSyncResponse
import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.internal.auth.registration.handleUIA
import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel
import org.matrix.android.sdk.internal.crypto.keysbackup.RustKeyBackupService import org.matrix.android.sdk.internal.crypto.keysbackup.RustKeyBackupService
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.BackupKeysResult
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysBackupData
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersion
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionResult
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.CreateKeysBackupVersionTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.DeleteBackupTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.GetKeysBackupLastVersionTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.GetKeysBackupVersionTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.GetRoomSessionDataTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.GetRoomSessionsDataTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.GetSessionsDataTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.StoreSessionsDataTask
import org.matrix.android.sdk.internal.crypto.keysbackup.tasks.UpdateKeysBackupVersionTask
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.internal.crypto.model.ImportRoomKeysResult import org.matrix.android.sdk.internal.crypto.model.ImportRoomKeysResult
import org.matrix.android.sdk.internal.crypto.model.MXEncryptEventContentResult import org.matrix.android.sdk.internal.crypto.model.MXEncryptEventContentResult
@ -96,7 +74,6 @@ import org.matrix.android.sdk.internal.crypto.tasks.GetDevicesTask
import org.matrix.android.sdk.internal.crypto.tasks.SetDeviceNameTask import org.matrix.android.sdk.internal.crypto.tasks.SetDeviceNameTask
import org.matrix.android.sdk.internal.crypto.verification.RustVerificationService import org.matrix.android.sdk.internal.crypto.verification.RustVerificationService
import org.matrix.android.sdk.internal.di.DeviceId import org.matrix.android.sdk.internal.di.DeviceId
import org.matrix.android.sdk.internal.di.SessionFilesDirectory
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.extensions.foldToCallback import org.matrix.android.sdk.internal.extensions.foldToCallback
import org.matrix.android.sdk.internal.session.SessionScope import org.matrix.android.sdk.internal.session.SessionScope
@ -152,6 +129,7 @@ internal class DefaultCryptoService @Inject constructor(
private val sender: RequestSender, private val sender: RequestSender,
private val crossSigningService: CrossSigningService, private val crossSigningService: CrossSigningService,
private val verificationService: RustVerificationService, private val verificationService: RustVerificationService,
private val keysBackupService: RustKeyBackupService,
private val olmMachineProvider: OlmMachineProvider private val olmMachineProvider: OlmMachineProvider
) : CryptoService { ) : CryptoService {
@ -165,11 +143,6 @@ internal class DefaultCryptoService @Inject constructor(
// private val deviceObserver: DeviceUpdateObserver = DeviceUpdateObserver() // private val deviceObserver: DeviceUpdateObserver = DeviceUpdateObserver()
// The key backup service.
private var keysBackupService: RustKeyBackupService? = null
private val deviceObserver: DeviceUpdateObserver = DeviceUpdateObserver()
// Locks for some of our operations // Locks for some of our operations
private val keyClaimLock: Mutex = Mutex() private val keyClaimLock: Mutex = Mutex()
private val outgoingRequestsLock: Mutex = Mutex() private val outgoingRequestsLock: Mutex = Mutex()
@ -335,7 +308,6 @@ internal class DefaultCryptoService @Inject constructor(
try { try {
setRustLogger() setRustLogger()
keysBackupService = RustKeyBackupService(machine, sender, coroutineDispatchers, cryptoCoroutineScope)
Timber.v( Timber.v(
"## CRYPTO | Successfully started up an Olm machine for " + "## CRYPTO | Successfully started up an Olm machine for " +
"${userId}, ${deviceId}, identity keys: ${this.olmMachine.identityKeys()}") "${userId}, ${deviceId}, identity keys: ${this.olmMachine.identityKeys()}")
@ -346,7 +318,7 @@ internal class DefaultCryptoService @Inject constructor(
// We try to enable key backups, if the backup version on the server is trusted, // We try to enable key backups, if the backup version on the server is trusted,
// we're gonna continue backing up. // we're gonna continue backing up.
tryOrNull { tryOrNull {
keysBackupService!!.checkAndStartKeysBackup() keysBackupService.checkAndStartKeysBackup()
} }
// Open the store // Open the store
@ -370,12 +342,7 @@ internal class DefaultCryptoService @Inject constructor(
/** /**
* @return the Keys backup Service * @return the Keys backup Service
*/ */
override fun keysBackupService(): KeysBackupService { override fun keysBackupService() = keysBackupService
if (keysBackupService == null) {
internalStart()
}
return keysBackupService!!
}
/** /**
* @return the VerificationService * @return the VerificationService
@ -400,7 +367,7 @@ internal class DefaultCryptoService @Inject constructor(
// This could be omitted but then devices might be waiting for the next // This could be omitted but then devices might be waiting for the next
sendOutgoingRequests() sendOutgoingRequests()
keysBackupService?.maybeBackupKeys() keysBackupService.maybeBackupKeys()
} }
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
@ -431,7 +398,7 @@ internal class DefaultCryptoService @Inject constructor(
override fun getCryptoDeviceInfo(userId: String): List<CryptoDeviceInfo> { override fun getCryptoDeviceInfo(userId: String): List<CryptoDeviceInfo> {
return runBlocking { return runBlocking {
this@DefaultCryptoService.olmMachine.getCryptoDeviceInfo(userId) ?: listOf() this@DefaultCryptoService.olmMachine.getCryptoDeviceInfo(userId)
} }
} }
@ -633,6 +600,7 @@ internal class DefaultCryptoService @Inject constructor(
olmMachine.updateTrackedUsers(userIds) olmMachine.updateTrackedUsers(userIds)
} }
} }
private fun getRoomUserIds(roomId: String): List<String> { private fun getRoomUserIds(roomId: String): List<String> {
val encryptForInvitedMembers = isEncryptionEnabledForInvitedUser() && val encryptForInvitedMembers = isEncryptionEnabledForInvitedUser() &&
shouldEncryptForInvitedMembers(roomId) shouldEncryptForInvitedMembers(roomId)
@ -726,7 +694,7 @@ internal class DefaultCryptoService @Inject constructor(
notifyRoomKeyReceived(roomId, sessionId) notifyRoomKeyReceived(roomId, sessionId)
} }
EventType.SEND_SECRET -> { EventType.SEND_SECRET -> {
// The rust-sdk will clear this event if it's invalid, this will produce an invalid base64 error // The rust-sdk will clear this event if it's invalid, this will produce an invalid base64 error
// when we try to construct the recovery key. // when we try to construct the recovery key.
val secretContent = event.getClearContent().toModel<SecretSendEventContent>() ?: return@forEach val secretContent = event.getClearContent().toModel<SecretSendEventContent>() ?: return@forEach
@ -808,7 +776,6 @@ internal class DefaultCryptoService @Inject constructor(
cryptoSessionInfoProvider.updateShieldForRoom(roomId, shield) cryptoSessionInfoProvider.updateShieldForRoom(roomId, shield)
} }
} }
} catch (throwable: Throwable) { } catch (throwable: Throwable) {
Timber.e(throwable, "## CRYPTO | doKeyDownloadForUsers(): error") Timber.e(throwable, "## CRYPTO | doKeyDownloadForUsers(): error")
} }

View file

@ -41,6 +41,7 @@ import java.net.URLEncoder
import javax.inject.Inject import javax.inject.Inject
// The libolm wrapper. // The libolm wrapper.
@Deprecated("rust")
@SessionScope @SessionScope
internal class MXOlmDevice @Inject constructor( internal class MXOlmDevice @Inject constructor(
/** /**

View file

@ -30,18 +30,18 @@ import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustResult
import org.matrix.android.sdk.internal.crypto.crosssigning.UserTrustResult import org.matrix.android.sdk.internal.crypto.crosssigning.UserTrustResult
import org.matrix.android.sdk.internal.crypto.crosssigning.isVerified import org.matrix.android.sdk.internal.crypto.crosssigning.isVerified
import org.matrix.android.sdk.internal.crypto.store.PrivateKeysInfo import org.matrix.android.sdk.internal.crypto.store.PrivateKeysInfo
import org.matrix.android.sdk.internal.di.SessionId
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.extensions.foldToCallback import org.matrix.android.sdk.internal.extensions.foldToCallback
import javax.inject.Inject import javax.inject.Inject
internal class RustCrossSigningService @Inject constructor( internal class RustCrossSigningService @Inject constructor(
@SessionId private val sessionId: String, // @SessionId private val sessionId: String,
@UserId private val myUserId: String, @UserId private val myUserId: String,
private val olmMachineProvider: OlmMachineProvider private val olmMachineProvider: OlmMachineProvider
) : CrossSigningService { ) : CrossSigningService {
val olmMachine = olmMachineProvider.olmMachine val olmMachine = olmMachineProvider.olmMachine
/** /**
* Is our own device signed by our own cross signing identity * Is our own device signed by our own cross signing identity
*/ */

View file

@ -28,6 +28,7 @@ import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@Deprecated("rust")
internal class MegolmSessionDataImporter @Inject constructor(private val olmDevice: MXOlmDevice, internal class MegolmSessionDataImporter @Inject constructor(private val olmDevice: MXOlmDevice,
private val roomDecryptorProvider: RoomDecryptorProvider, private val roomDecryptorProvider: RoomDecryptorProvider,
private val outgoingGossipingRequestManager: OutgoingGossipingRequestManager, private val outgoingGossipingRequestManager: OutgoingGossipingRequestManager,

View file

@ -26,6 +26,7 @@ import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupServic
/** /**
* An interface for decrypting data * An interface for decrypting data
*/ */
@Deprecated("rust")
internal interface IMXDecrypting { internal interface IMXDecrypting {
/** /**

View file

@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.Content
/** /**
* An interface for encrypting data * An interface for encrypting data
*/ */
@Deprecated("rust")
internal interface IMXEncrypting { internal interface IMXEncrypting {
/** /**

View file

@ -16,6 +16,7 @@
package org.matrix.android.sdk.internal.crypto.algorithms package org.matrix.android.sdk.internal.crypto.algorithms
@Deprecated("rust")
internal interface IMXGroupEncryption { internal interface IMXGroupEncryption {
/** /**

View file

@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.crypto.algorithms
import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyWithHeldContent import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyWithHeldContent
@Deprecated("rust")
internal interface IMXWithHeldExtension { internal interface IMXWithHeldExtension {
fun onRoomKeyWithHeldEvent(withHeldInfo: RoomKeyWithHeldContent) fun onRoomKeyWithHeldEvent(withHeldInfo: RoomKeyWithHeldContent)
} }

View file

@ -43,6 +43,7 @@ import org.matrix.android.sdk.internal.util.JsonCanonicalizer
import org.matrix.android.sdk.internal.util.convertToUTF8 import org.matrix.android.sdk.internal.util.convertToUTF8
import timber.log.Timber import timber.log.Timber
@Deprecated("in favour of rust")
internal class MXMegolmEncryption( internal class MXMegolmEncryption(
// The id of the room we will be sending to. // The id of the room we will be sending to.
private val roomId: String, private val roomId: String,

View file

@ -99,6 +99,7 @@ import kotlin.random.Random
* to the user's homeserver. * to the user's homeserver.
*/ */
@SessionScope @SessionScope
@Deprecated("use rust")
internal class DefaultKeysBackupService @Inject constructor( internal class DefaultKeysBackupService @Inject constructor(
@UserId private val userId: String, @UserId private val userId: String,
private val credentials: Credentials, private val credentials: Credentials,

View file

@ -38,6 +38,7 @@ import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupStateListe
import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM_BACKUP import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM_BACKUP
import org.matrix.android.sdk.internal.crypto.MegolmSessionData import org.matrix.android.sdk.internal.crypto.MegolmSessionData
import org.matrix.android.sdk.internal.crypto.OlmMachine import org.matrix.android.sdk.internal.crypto.OlmMachine
import org.matrix.android.sdk.internal.crypto.OlmMachineProvider
import org.matrix.android.sdk.internal.crypto.RequestSender import org.matrix.android.sdk.internal.crypto.RequestSender
import org.matrix.android.sdk.internal.crypto.keysbackup.model.KeysBackupVersionTrust import org.matrix.android.sdk.internal.crypto.keysbackup.model.KeysBackupVersionTrust
import org.matrix.android.sdk.internal.crypto.keysbackup.model.MegolmBackupAuthData import org.matrix.android.sdk.internal.crypto.keysbackup.model.MegolmBackupAuthData
@ -71,7 +72,7 @@ import kotlin.random.Random
*/ */
@SessionScope @SessionScope
internal class RustKeyBackupService @Inject constructor( internal class RustKeyBackupService @Inject constructor(
private val olmMachine: OlmMachine, olmMachineProvider: OlmMachineProvider,
private val sender: RequestSender, private val sender: RequestSender,
private val coroutineDispatchers: MatrixCoroutineDispatchers, private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val cryptoCoroutineScope: CoroutineScope, private val cryptoCoroutineScope: CoroutineScope,
@ -85,6 +86,8 @@ internal class RustKeyBackupService @Inject constructor(
private val keysBackupStateManager = KeysBackupStateManager(uiHandler) private val keysBackupStateManager = KeysBackupStateManager(uiHandler)
private val olmMachine = olmMachineProvider.olmMachine
// The backup version // The backup version
override var keysBackupVersion: KeysVersionResult? = null override var keysBackupVersion: KeysVersionResult? = null
private set private set