diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt index 66ce44ad4f..2edc0c3976 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt @@ -77,7 +77,7 @@ class KeysBackupTest : InstrumentedTest { val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages() // From doE2ETestWithAliceAndBobInARoomWithEncryptedMessages, we should have no backed up keys - val cryptoStore = (cryptoTestData.firstSession.cryptoService().keysBackupService() as KeysBackup).store + val cryptoStore = (cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService).store val sessions = cryptoStore.inboundGroupSessionsToBackup(100) val sessionsCount = sessions.size @@ -293,7 +293,7 @@ class KeysBackupTest : InstrumentedTest { fun testEncryptAndDecryptKeysBackupData() { val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages() - val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService() as KeysBackup + val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService val stateObserver = StateObserver(keysBackup) @@ -373,7 +373,7 @@ class KeysBackupTest : InstrumentedTest { val testData = createKeysBackupScenarioWithPassword(null) // - Check the SDK sent key share requests - val cryptoStore2 = (testData.aliceSession2.cryptoService().keysBackupService() as KeysBackup).store + val cryptoStore2 = (testData.aliceSession2.cryptoService().keysBackupService() as DefaultKeysBackupService).store val unsentRequest = cryptoStore2 .getOutgoingRoomKeyRequestByState(setOf(OutgoingRoomKeyRequest.RequestState.UNSENT)) val sentRequest = cryptoStore2 @@ -1082,11 +1082,11 @@ class KeysBackupTest : InstrumentedTest { val latch = CountDownLatch(1) val megolmBackupCreationInfo = mCryptoTestHelper.createFakeMegolmBackupCreationInfo() - (keysBackup as KeysBackup).createFakeKeysBackupVersion(megolmBackupCreationInfo, TestMatrixCallback(latch)) + (keysBackup as DefaultKeysBackupService).createFakeKeysBackupVersion(megolmBackupCreationInfo, TestMatrixCallback(latch)) mTestHelper.await(latch) // Reset the store backup status for keys - (cryptoTestData.firstSession.cryptoService().keysBackupService() as KeysBackup).store.resetBackupMarkers() + (cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService).store.resetBackupMarkers() // - Make alice back up all her keys again val latch2 = CountDownLatch(1) @@ -1359,7 +1359,7 @@ class KeysBackupTest : InstrumentedTest { private fun createKeysBackupScenarioWithPassword(password: String?): KeysBackupScenarioData { val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages() - val cryptoStore = (cryptoTestData.firstSession.cryptoService().keysBackupService() as KeysBackup).store + val cryptoStore = (cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService).store val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService() val stateObserver = StateObserver(keysBackup) @@ -1425,7 +1425,7 @@ class KeysBackupTest : InstrumentedTest { // - Alice must have the same keys on both devices for (aliceKey1 in testData.aliceKeys) { - val aliceKey2 = (testData.aliceSession2.cryptoService().keysBackupService() as KeysBackup).store + val aliceKey2 = (testData.aliceSession2.cryptoService().keysBackupService() as DefaultKeysBackupService).store .getInboundGroupSession(aliceKey1.olmInboundGroupSession!!.sessionIdentifier(), aliceKey1.senderKey!!) assertNotNull(aliceKey2) assertKeysEquals(aliceKey1.exportKeys(), aliceKey2!!.exportKeys()) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt index 593cbb493c..b0acb031fc 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt @@ -49,7 +49,7 @@ import im.vector.matrix.android.internal.crypto.algorithms.megolm.MXMegolmEncryp import im.vector.matrix.android.internal.crypto.algorithms.olm.MXOlmEncryptionFactory import im.vector.matrix.android.internal.crypto.crosssigning.DefaultCrossSigningService import im.vector.matrix.android.internal.crypto.crosssigning.DeviceTrustLevel -import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup +import im.vector.matrix.android.internal.crypto.keysbackup.DefaultKeysBackupService import im.vector.matrix.android.internal.crypto.model.CryptoDeviceInfo import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo @@ -122,7 +122,7 @@ internal class DefaultCryptoService @Inject constructor( // Device list manager private val deviceListManager: DeviceListManager, // The key backup service. - private val keysBackup: KeysBackup, + private val keysBackupService: DefaultKeysBackupService, // private val objectSigner: ObjectSigner, // @@ -301,7 +301,7 @@ internal class DefaultCryptoService @Inject constructor( uploadDeviceKeys() oneTimeKeysUploader.maybeUploadOneTimeKeys() outgoingRoomKeyRequestManager.start() - keysBackup.checkAndStartKeysBackup() + keysBackupService.checkAndStartKeysBackup() if (isInitialSync) { // refresh the devices list for each known room members deviceListManager.invalidateAllDeviceLists() @@ -340,7 +340,7 @@ internal class DefaultCryptoService @Inject constructor( /** * @return the Keys backup Service */ - override fun keysBackupService() = keysBackup + override fun keysBackupService() = keysBackupService /** * @return the VerificationService @@ -721,7 +721,7 @@ internal class DefaultCryptoService @Inject constructor( Timber.e("## onRoomKeyEvent() : Unable to handle keys for ${roomKeyContent.algorithm}") return } - alg.onRoomKeyEvent(event, keysBackup) + alg.onRoomKeyEvent(event, keysBackupService) } /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt index 8dad832617..d6538f041d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/SetDeviceVerificationAction.kt @@ -17,7 +17,7 @@ package im.vector.matrix.android.internal.crypto.actions import im.vector.matrix.android.internal.crypto.crosssigning.DeviceTrustLevel -import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup +import im.vector.matrix.android.internal.crypto.keysbackup.DefaultKeysBackupService import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.di.UserId import timber.log.Timber @@ -26,7 +26,7 @@ import javax.inject.Inject internal class SetDeviceVerificationAction @Inject constructor( private val cryptoStore: IMXCryptoStore, @UserId private val userId: String, - private val keysBackup: KeysBackup) { + private val defaultKeysBackupService: DefaultKeysBackupService) { fun handle(trustLevel: DeviceTrustLevel, userId: String, deviceId: String) { val device = cryptoStore.getUserDevice(userId, deviceId) @@ -42,7 +42,7 @@ internal class SetDeviceVerificationAction @Inject constructor( // If one of the user's own devices is being marked as verified / unverified, // check the key backup status, since whether or not we use this depends on // whether it has a signature from a verified device - keysBackup.checkAndStartKeysBackup() + defaultKeysBackupService.checkAndStartKeysBackup() } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/IMXDecrypting.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/IMXDecrypting.kt index f63eaa93b3..e8fb6be6ff 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/IMXDecrypting.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/IMXDecrypting.kt @@ -20,7 +20,7 @@ package im.vector.matrix.android.internal.crypto.algorithms import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequest import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult -import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup +import im.vector.matrix.android.internal.crypto.keysbackup.DefaultKeysBackupService /** * An interface for decrypting data @@ -41,7 +41,7 @@ internal interface IMXDecrypting { * * @param event the key event. */ - fun onRoomKeyEvent(event: Event, keysBackup: KeysBackup) {} + fun onRoomKeyEvent(event: Event, defaultKeysBackupService: DefaultKeysBackupService) {} /** * Check if the some messages can be decrypted with a new session diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt index 9121ce3fcb..054b38ad06 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt @@ -30,7 +30,7 @@ import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequestManager import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevicesAction import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter import im.vector.matrix.android.internal.crypto.algorithms.IMXDecrypting -import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup +import im.vector.matrix.android.internal.crypto.keysbackup.DefaultKeysBackupService import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent import im.vector.matrix.android.internal.crypto.model.event.RoomKeyContent @@ -198,7 +198,7 @@ internal class MXMegolmDecryption(private val userId: String, * * @param event the key event. */ - override fun onRoomKeyEvent(event: Event, keysBackup: KeysBackup) { + override fun onRoomKeyEvent(event: Event, defaultKeysBackupService: DefaultKeysBackupService) { var exportFormat = false val roomKeyContent = event.getClearContent().toModel() ?: return @@ -262,7 +262,7 @@ internal class MXMegolmDecryption(private val userId: String, exportFormat) if (added) { - keysBackup.maybeBackupKeys() + defaultKeysBackupService.maybeBackupKeys() val content = RoomKeyRequestBody() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt index ee35810763..a2d21c4f89 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt @@ -28,7 +28,7 @@ import im.vector.matrix.android.internal.crypto.MXOlmDevice import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevicesAction import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter import im.vector.matrix.android.internal.crypto.algorithms.IMXEncrypting -import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup +import im.vector.matrix.android.internal.crypto.keysbackup.DefaultKeysBackupService import im.vector.matrix.android.internal.crypto.model.CryptoDeviceInfo import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.repository.WarnOnUnknownDeviceRepository @@ -42,7 +42,7 @@ internal class MXMegolmEncryption( // The id of the room we will be sending to. private var roomId: String, private val olmDevice: MXOlmDevice, - private val keysBackup: KeysBackup, + private val defaultKeysBackupService: DefaultKeysBackupService, private val cryptoStore: IMXCryptoStore, private val deviceListManager: DeviceListManager, private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction, @@ -85,7 +85,7 @@ internal class MXMegolmEncryption( olmDevice.addInboundGroupSession(sessionId!!, olmDevice.getSessionKey(sessionId)!!, roomId, olmDevice.deviceCurve25519Key!!, emptyList(), keysClaimedMap, false) - keysBackup.maybeBackupKeys() + defaultKeysBackupService.maybeBackupKeys() return MXOutboundSessionInfo(sessionId) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt index dadd810a4b..e9fe902f1f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt @@ -21,7 +21,7 @@ import im.vector.matrix.android.internal.crypto.DeviceListManager import im.vector.matrix.android.internal.crypto.MXOlmDevice import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevicesAction import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter -import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup +import im.vector.matrix.android.internal.crypto.keysbackup.DefaultKeysBackupService import im.vector.matrix.android.internal.crypto.repository.WarnOnUnknownDeviceRepository import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask @@ -29,7 +29,7 @@ import javax.inject.Inject internal class MXMegolmEncryptionFactory @Inject constructor( private val olmDevice: MXOlmDevice, - private val keysBackup: KeysBackup, + private val defaultKeysBackupService: DefaultKeysBackupService, private val cryptoStore: IMXCryptoStore, private val deviceListManager: DeviceListManager, private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction, @@ -42,7 +42,7 @@ internal class MXMegolmEncryptionFactory @Inject constructor( return MXMegolmEncryption( roomId, olmDevice, - keysBackup, + defaultKeysBackupService, cryptoStore, deviceListManager, ensureOlmSessionsForDevicesAction, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/DefaultKeysBackupService.kt similarity index 99% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/DefaultKeysBackupService.kt index 595b55a7a6..a630467d4c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/DefaultKeysBackupService.kt @@ -92,12 +92,11 @@ import javax.inject.Inject import kotlin.random.Random /** - * A KeysBackup class instance manage incremental backup of e2e keys (megolm keys) + * A DefaultKeysBackupService class instance manage incremental backup of e2e keys (megolm keys) * to the user's homeserver. */ - @SessionScope -internal class KeysBackup @Inject constructor( +internal class DefaultKeysBackupService @Inject constructor( @UserId private val userId: String, private val credentials: Credentials, private val cryptoStore: IMXCryptoStore,