From 9e055d97933aecebb756a42e2b33e0b2f6cbeb85 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 19 Nov 2021 15:14:04 +0100 Subject: [PATCH] post rebase fix --- .../sdk/internal/crypto/CryptoModule.kt | 7 +-- .../internal/crypto/DefaultCryptoService.kt | 47 +++---------------- .../sdk/internal/crypto/MXOlmDevice.kt | 1 + .../crypto/RustCrossSigningService.kt | 4 +- .../actions/MegolmSessionDataImporter.kt | 1 + .../crypto/algorithms/IMXDecrypting.kt | 1 + .../crypto/algorithms/IMXEncrypting.kt | 1 + .../crypto/algorithms/IMXGroupEncryption.kt | 1 + .../crypto/algorithms/IMXWithHeldExtension.kt | 1 + .../algorithms/megolm/MXMegolmEncryption.kt | 1 + .../keysbackup/DefaultKeysBackupService.kt | 1 + .../crypto/keysbackup/RustKeyBackupService.kt | 5 +- 12 files changed, 23 insertions(+), 48 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CryptoModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CryptoModule.kt index eb898188ae..dc3b99fcb8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CryptoModule.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CryptoModule.kt @@ -24,6 +24,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob 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.verification.VerificationService 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.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.UploadSignaturesTask 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.di.CryptoDatabase 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.cache.ClearCacheTask 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 java.io.File 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 021b4ff42d..526797d3be 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 @@ -20,8 +20,6 @@ import android.content.Context import androidx.annotation.VisibleForTesting import androidx.lifecycle.LiveData import androidx.paging.PagedList -import com.squareup.moshi.Types -import dagger.Lazy import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope 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.extensions.tryOrNull 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.session.crypto.CryptoService 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.keysbackup.KeysBackupService 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.Event 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.DeviceOneTimeKeysCountSyncResponse 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.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.ImportRoomKeysResult 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.verification.RustVerificationService 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.extensions.foldToCallback import org.matrix.android.sdk.internal.session.SessionScope @@ -152,6 +129,7 @@ internal class DefaultCryptoService @Inject constructor( private val sender: RequestSender, private val crossSigningService: CrossSigningService, private val verificationService: RustVerificationService, + private val keysBackupService: RustKeyBackupService, private val olmMachineProvider: OlmMachineProvider ) : CryptoService { @@ -165,11 +143,6 @@ internal class DefaultCryptoService @Inject constructor( // 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 private val keyClaimLock: Mutex = Mutex() private val outgoingRequestsLock: Mutex = Mutex() @@ -335,7 +308,6 @@ internal class DefaultCryptoService @Inject constructor( try { setRustLogger() - keysBackupService = RustKeyBackupService(machine, sender, coroutineDispatchers, cryptoCoroutineScope) Timber.v( "## CRYPTO | Successfully started up an Olm machine for " + "${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're gonna continue backing up. tryOrNull { - keysBackupService!!.checkAndStartKeysBackup() + keysBackupService.checkAndStartKeysBackup() } // Open the store @@ -370,12 +342,7 @@ internal class DefaultCryptoService @Inject constructor( /** * @return the Keys backup Service */ - override fun keysBackupService(): KeysBackupService { - if (keysBackupService == null) { - internalStart() - } - return keysBackupService!! - } + override fun keysBackupService() = keysBackupService /** * @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 sendOutgoingRequests() - keysBackupService?.maybeBackupKeys() + keysBackupService.maybeBackupKeys() } cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { @@ -431,7 +398,7 @@ internal class DefaultCryptoService @Inject constructor( override fun getCryptoDeviceInfo(userId: String): List { 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) } } + private fun getRoomUserIds(roomId: String): List { val encryptForInvitedMembers = isEncryptionEnabledForInvitedUser() && shouldEncryptForInvitedMembers(roomId) @@ -726,7 +694,7 @@ internal class DefaultCryptoService @Inject constructor( 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 // when we try to construct the recovery key. val secretContent = event.getClearContent().toModel() ?: return@forEach @@ -808,7 +776,6 @@ internal class DefaultCryptoService @Inject constructor( cryptoSessionInfoProvider.updateShieldForRoom(roomId, shield) } } - } catch (throwable: Throwable) { Timber.e(throwable, "## CRYPTO | doKeyDownloadForUsers(): error") } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt index 441dfe4a5d..7a3ae7c1b9 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt @@ -41,6 +41,7 @@ import java.net.URLEncoder import javax.inject.Inject // The libolm wrapper. +@Deprecated("rust") @SessionScope internal class MXOlmDevice @Inject constructor( /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt index bf5d0eca9e..4c9d62f610 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt @@ -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.isVerified 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.extensions.foldToCallback import javax.inject.Inject internal class RustCrossSigningService @Inject constructor( - @SessionId private val sessionId: String, +// @SessionId private val sessionId: String, @UserId private val myUserId: String, private val olmMachineProvider: OlmMachineProvider ) : CrossSigningService { val olmMachine = olmMachineProvider.olmMachine + /** * Is our own device signed by our own cross signing identity */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/actions/MegolmSessionDataImporter.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/actions/MegolmSessionDataImporter.kt index 0d78f68e5c..e0748a0d1f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/actions/MegolmSessionDataImporter.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/actions/MegolmSessionDataImporter.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore import timber.log.Timber import javax.inject.Inject +@Deprecated("rust") internal class MegolmSessionDataImporter @Inject constructor(private val olmDevice: MXOlmDevice, private val roomDecryptorProvider: RoomDecryptorProvider, private val outgoingGossipingRequestManager: OutgoingGossipingRequestManager, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXDecrypting.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXDecrypting.kt index 79c7608cbf..b9cfd942ce 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXDecrypting.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXDecrypting.kt @@ -26,6 +26,7 @@ import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupServic /** * An interface for decrypting data */ +@Deprecated("rust") internal interface IMXDecrypting { /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXEncrypting.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXEncrypting.kt index 5294429198..b0f411cbcc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXEncrypting.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXEncrypting.kt @@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.Content /** * An interface for encrypting data */ +@Deprecated("rust") internal interface IMXEncrypting { /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXGroupEncryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXGroupEncryption.kt index 1fd5061a65..7d191861e7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXGroupEncryption.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXGroupEncryption.kt @@ -16,6 +16,7 @@ package org.matrix.android.sdk.internal.crypto.algorithms +@Deprecated("rust") internal interface IMXGroupEncryption { /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXWithHeldExtension.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXWithHeldExtension.kt index 91f10adf4c..7a03217ea5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXWithHeldExtension.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/IMXWithHeldExtension.kt @@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.crypto.algorithms import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyWithHeldContent +@Deprecated("rust") internal interface IMXWithHeldExtension { fun onRoomKeyWithHeldEvent(withHeldInfo: RoomKeyWithHeldContent) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt index 031bb4e194..5e748d3739 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt @@ -43,6 +43,7 @@ import org.matrix.android.sdk.internal.util.JsonCanonicalizer import org.matrix.android.sdk.internal.util.convertToUTF8 import timber.log.Timber +@Deprecated("in favour of rust") internal class MXMegolmEncryption( // The id of the room we will be sending to. private val roomId: String, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt index b20168eaa3..b0c7c8b610 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt @@ -99,6 +99,7 @@ import kotlin.random.Random * to the user's homeserver. */ @SessionScope +@Deprecated("use rust") internal class DefaultKeysBackupService @Inject constructor( @UserId private val userId: String, private val credentials: Credentials, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt index 3b9ce5b67e..0ec13ced19 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/RustKeyBackupService.kt @@ -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.MegolmSessionData 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.keysbackup.model.KeysBackupVersionTrust import org.matrix.android.sdk.internal.crypto.keysbackup.model.MegolmBackupAuthData @@ -71,7 +72,7 @@ import kotlin.random.Random */ @SessionScope internal class RustKeyBackupService @Inject constructor( - private val olmMachine: OlmMachine, + olmMachineProvider: OlmMachineProvider, private val sender: RequestSender, private val coroutineDispatchers: MatrixCoroutineDispatchers, private val cryptoCoroutineScope: CoroutineScope, @@ -85,6 +86,8 @@ internal class RustKeyBackupService @Inject constructor( private val keysBackupStateManager = KeysBackupStateManager(uiHandler) + private val olmMachine = olmMachineProvider.olmMachine + // The backup version override var keysBackupVersion: KeysVersionResult? = null private set