Merge pull request #1026 from vector-im/feature/crypto_service_renaming

Feature/crypto service renaming
This commit is contained in:
Benoit Marty 2020-02-17 19:21:02 +01:00 committed by GitHub
commit adc545a93d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 309 additions and 346 deletions

View File

@ -15,7 +15,7 @@ Translations 🗣:
-
SDK API changes ⚠️:
-
- Get crypto methods through Session.cryptoService()
Build 🧱:
-

View File

@ -111,15 +111,15 @@ class RxSession(private val session: Session) {
}
fun liveUserCryptoDevices(userId: String): Observable<List<CryptoDeviceInfo>> {
return session.getLiveCryptoDeviceInfo(userId).asObservable().startWithCallable {
session.getCryptoDeviceInfo(userId)
return session.cryptoService().getLiveCryptoDeviceInfo(userId).asObservable().startWithCallable {
session.cryptoService().getCryptoDeviceInfo(userId)
}
}
fun liveCrossSigningInfo(userId: String): Observable<Optional<MXCrossSigningInfo>> {
return session.getCrossSigningService().getLiveCrossSigningKeys(userId).asObservable()
return session.cryptoService().crossSigningService().getLiveCrossSigningKeys(userId).asObservable()
.startWithCallable {
session.getCrossSigningService().getUserCrossSigningKeys(userId).toOptional()
session.cryptoService().crossSigningService().getUserCrossSigningKeys(userId).toOptional()
}
}

View File

@ -230,9 +230,9 @@ class CryptoTestHelper(val mTestHelper: CommonTestHelper) {
val aliceRoomId = cryptoTestData.roomId
val bobSession = cryptoTestData.secondSession!!
bobSession.setWarnOnUnknownDevices(false)
bobSession.cryptoService().setWarnOnUnknownDevices(false)
aliceSession.setWarnOnUnknownDevices(false)
aliceSession.cryptoService().setWarnOnUnknownDevices(false)
val roomFromBobPOV = bobSession.getRoom(aliceRoomId)!!
val roomFromAlicePOV = aliceSession.getRoom(aliceRoomId)!!

View File

@ -35,7 +35,7 @@ class XSigningTest : InstrumentedTest {
val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true))
val aliceLatch = CountDownLatch(1)
aliceSession.getCrossSigningService()
aliceSession.cryptoService().crossSigningService()
.initializeCrossSigning(UserPasswordAuth(
user = aliceSession.myUserId,
password = TestConstants.PASSWORD
@ -43,7 +43,7 @@ class XSigningTest : InstrumentedTest {
mTestHelper.await(aliceLatch)
val myCrossSigningKeys = aliceSession.getCrossSigningService().getMyCrossSigningKeys()
val myCrossSigningKeys = aliceSession.cryptoService().crossSigningService().getMyCrossSigningKeys()
val masterPubKey = myCrossSigningKeys?.masterKey()
assertNotNull("Master key should be stored", masterPubKey?.unpaddedBase64PublicKey)
val selfSigningKey = myCrossSigningKeys?.selfSigningKey()
@ -53,7 +53,7 @@ class XSigningTest : InstrumentedTest {
assertTrue("Signing Keys should be trusted", myCrossSigningKeys?.isTrusted() == true)
assertTrue("Signing Keys should be trusted", aliceSession.getCrossSigningService().checkUserTrust(aliceSession.myUserId).isVerified())
assertTrue("Signing Keys should be trusted", aliceSession.cryptoService().crossSigningService().checkUserTrust(aliceSession.myUserId).isVerified())
mTestHelper.signout(aliceSession)
}
@ -76,23 +76,23 @@ class XSigningTest : InstrumentedTest {
val latch = CountDownLatch(2)
aliceSession.getCrossSigningService().initializeCrossSigning(aliceAuthParams, TestMatrixCallback(latch))
bobSession.getCrossSigningService().initializeCrossSigning(bobAuthParams, TestMatrixCallback(latch))
aliceSession.cryptoService().crossSigningService().initializeCrossSigning(aliceAuthParams, TestMatrixCallback(latch))
bobSession.cryptoService().crossSigningService().initializeCrossSigning(bobAuthParams, TestMatrixCallback(latch))
mTestHelper.await(latch)
// Check that alice can see bob keys
val downloadLatch = CountDownLatch(1)
aliceSession.downloadKeys(listOf(bobSession.myUserId), true, TestMatrixCallback(downloadLatch))
aliceSession.cryptoService().downloadKeys(listOf(bobSession.myUserId), true, TestMatrixCallback(downloadLatch))
mTestHelper.await(downloadLatch)
val bobKeysFromAlicePOV = aliceSession.getCrossSigningService().getUserCrossSigningKeys(bobSession.myUserId)
val bobKeysFromAlicePOV = aliceSession.cryptoService().crossSigningService().getUserCrossSigningKeys(bobSession.myUserId)
assertNotNull("Alice can see bob Master key", bobKeysFromAlicePOV!!.masterKey())
assertNull("Alice should not see bob User key", bobKeysFromAlicePOV.userKey())
assertNotNull("Alice can see bob SelfSigned key", bobKeysFromAlicePOV.selfSigningKey())
assertEquals("Bob keys from alice pov should match", bobKeysFromAlicePOV.masterKey()?.unpaddedBase64PublicKey, bobSession.getCrossSigningService().getMyCrossSigningKeys()?.masterKey()?.unpaddedBase64PublicKey)
assertEquals("Bob keys from alice pov should match", bobKeysFromAlicePOV.selfSigningKey()?.unpaddedBase64PublicKey, bobSession.getCrossSigningService().getMyCrossSigningKeys()?.selfSigningKey()?.unpaddedBase64PublicKey)
assertEquals("Bob keys from alice pov should match", bobKeysFromAlicePOV.masterKey()?.unpaddedBase64PublicKey, bobSession.cryptoService().crossSigningService().getMyCrossSigningKeys()?.masterKey()?.unpaddedBase64PublicKey)
assertEquals("Bob keys from alice pov should match", bobKeysFromAlicePOV.selfSigningKey()?.unpaddedBase64PublicKey, bobSession.cryptoService().crossSigningService().getMyCrossSigningKeys()?.selfSigningKey()?.unpaddedBase64PublicKey)
assertFalse("Bob keys from alice pov should not be trusted", bobKeysFromAlicePOV.isTrusted())
@ -118,22 +118,22 @@ class XSigningTest : InstrumentedTest {
val latch = CountDownLatch(2)
aliceSession.getCrossSigningService().initializeCrossSigning(aliceAuthParams, TestMatrixCallback(latch))
bobSession.getCrossSigningService().initializeCrossSigning(bobAuthParams, TestMatrixCallback(latch))
aliceSession.cryptoService().crossSigningService().initializeCrossSigning(aliceAuthParams, TestMatrixCallback(latch))
bobSession.cryptoService().crossSigningService().initializeCrossSigning(bobAuthParams, TestMatrixCallback(latch))
mTestHelper.await(latch)
// Check that alice can see bob keys
val downloadLatch = CountDownLatch(1)
val bobUserId = bobSession.myUserId
aliceSession.downloadKeys(listOf(bobUserId), true, TestMatrixCallback(downloadLatch))
aliceSession.cryptoService().downloadKeys(listOf(bobUserId), true, TestMatrixCallback(downloadLatch))
mTestHelper.await(downloadLatch)
val bobKeysFromAlicePOV = aliceSession.getCrossSigningService().getUserCrossSigningKeys(bobUserId)
val bobKeysFromAlicePOV = aliceSession.cryptoService().crossSigningService().getUserCrossSigningKeys(bobUserId)
assertTrue("Bob keys from alice pov should not be trusted", bobKeysFromAlicePOV?.isTrusted() == false)
val trustLatch = CountDownLatch(1)
aliceSession.getCrossSigningService().trustUser(bobUserId, object : MatrixCallback<Unit> {
aliceSession.cryptoService().crossSigningService().trustUser(bobUserId, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
trustLatch.countDown()
}
@ -152,7 +152,7 @@ class XSigningTest : InstrumentedTest {
// Check that bob first session sees the new login
val bobKeysLatch = CountDownLatch(1)
bobSession.downloadKeys(listOf(bobUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
bobSession.cryptoService().downloadKeys(listOf(bobUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
override fun onFailure(failure: Throwable) {
fail("Failed to get device")
}
@ -166,12 +166,12 @@ class XSigningTest : InstrumentedTest {
})
mTestHelper.await(bobKeysLatch)
val bobSecondDevicePOVFirstDevice = bobSession.getDeviceInfo(bobUserId, bobSecondDeviceId)
val bobSecondDevicePOVFirstDevice = bobSession.cryptoService().getDeviceInfo(bobUserId, bobSecondDeviceId)
assertNotNull("Bob Second device should be known and persisted from first", bobSecondDevicePOVFirstDevice)
// Manually mark it as trusted from first session
val bobSignLatch = CountDownLatch(1)
bobSession.getCrossSigningService().signDevice(bobSecondDeviceId!!, object : MatrixCallback<Unit> {
bobSession.cryptoService().crossSigningService().signDevice(bobSecondDeviceId!!, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
bobSignLatch.countDown()
}
@ -184,7 +184,7 @@ class XSigningTest : InstrumentedTest {
// Now alice should cross trust bob's second device
val aliceKeysLatch = CountDownLatch(1)
aliceSession.downloadKeys(listOf(bobUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
aliceSession.cryptoService().downloadKeys(listOf(bobUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
override fun onFailure(failure: Throwable) {
fail("Failed to get device")
}
@ -199,7 +199,7 @@ class XSigningTest : InstrumentedTest {
})
mTestHelper.await(aliceKeysLatch)
val result = aliceSession.getCrossSigningService().checkDeviceTrust(bobUserId, bobSecondDeviceId, null)
val result = aliceSession.cryptoService().crossSigningService().checkDeviceTrust(bobUserId, bobSecondDeviceId, null)
assertTrue("Bob second device should be trusted from alice POV", result.isCrossSignedVerified())
mTestHelper.signout(aliceSession)

View File

@ -77,21 +77,21 @@ class KeysBackupTest : InstrumentedTest {
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
// From doE2ETestWithAliceAndBobInARoomWithEncryptedMessages, we should have no backed up keys
val cryptoStore = (cryptoTestData.firstSession.getKeysBackupService() as KeysBackup).store
val cryptoStore = (cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService).store
val sessions = cryptoStore.inboundGroupSessionsToBackup(100)
val sessionsCount = sessions.size
assertFalse(sessions.isEmpty())
assertEquals(sessionsCount, cryptoTestData.firstSession.inboundGroupSessionsCount(false))
assertEquals(0, cryptoTestData.firstSession.inboundGroupSessionsCount(true))
assertEquals(sessionsCount, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false))
assertEquals(0, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true))
// - Check backup keys after having marked one as backed up
val session = sessions[0]
cryptoStore.markBackupDoneForInboundGroupSessions(Collections.singletonList(session))
assertEquals(sessionsCount, cryptoTestData.firstSession.inboundGroupSessionsCount(false))
assertEquals(1, cryptoTestData.firstSession.inboundGroupSessionsCount(true))
assertEquals(sessionsCount, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false))
assertEquals(1, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true))
val sessions2 = cryptoStore.inboundGroupSessionsToBackup(100)
assertEquals(sessionsCount - 1, sessions2.size)
@ -101,8 +101,8 @@ class KeysBackupTest : InstrumentedTest {
val sessions3 = cryptoStore.inboundGroupSessionsToBackup(100)
assertEquals(sessionsCount, sessions3.size)
assertEquals(sessionsCount, cryptoTestData.firstSession.inboundGroupSessionsCount(false))
assertEquals(0, cryptoTestData.firstSession.inboundGroupSessionsCount(true))
assertEquals(sessionsCount, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false))
assertEquals(0, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true))
}
/**
@ -112,9 +112,9 @@ class KeysBackupTest : InstrumentedTest {
fun prepareKeysBackupVersionTest() {
val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, defaultSessionParams)
assertNotNull(bobSession.getKeysBackupService())
assertNotNull(bobSession.cryptoService().keysBackupService())
val keysBackup = bobSession.getKeysBackupService()
val keysBackup = bobSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -154,7 +154,7 @@ class KeysBackupTest : InstrumentedTest {
fun createKeysBackupVersionTest() {
val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, defaultSessionParams)
val keysBackup = bobSession.getKeysBackupService()
val keysBackup = bobSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -209,12 +209,12 @@ class KeysBackupTest : InstrumentedTest {
fun backupAfterCreateKeysBackupVersionTest() {
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val latch = CountDownLatch(1)
assertEquals(2, cryptoTestData.firstSession.inboundGroupSessionsCount(false))
assertEquals(0, cryptoTestData.firstSession.inboundGroupSessionsCount(true))
assertEquals(2, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false))
assertEquals(0, cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true))
val stateObserver = StateObserver(keysBackup, latch, 5)
@ -222,8 +222,8 @@ class KeysBackupTest : InstrumentedTest {
mTestHelper.await(latch)
val nbOfKeys = cryptoTestData.firstSession.inboundGroupSessionsCount(false)
val backedUpKeys = cryptoTestData.firstSession.inboundGroupSessionsCount(true)
val nbOfKeys = cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false)
val backedUpKeys = cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true)
assertEquals(2, nbOfKeys)
assertEquals("All keys must have been marked as backed up", nbOfKeys, backedUpKeys)
@ -248,14 +248,14 @@ class KeysBackupTest : InstrumentedTest {
fun backupAllGroupSessionsTest() {
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
prepareAndCreateKeysBackupData(keysBackup)
// Check that backupAllGroupSessions returns valid data
val nbOfKeys = cryptoTestData.firstSession.inboundGroupSessionsCount(false)
val nbOfKeys = cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(false)
assertEquals(2, nbOfKeys)
@ -273,7 +273,7 @@ class KeysBackupTest : InstrumentedTest {
mTestHelper.await(latch)
assertEquals(nbOfKeys, lastBackedUpKeysProgress)
val backedUpKeys = cryptoTestData.firstSession.inboundGroupSessionsCount(true)
val backedUpKeys = cryptoTestData.firstSession.cryptoService().inboundGroupSessionsCount(true)
assertEquals("All keys must have been marked as backed up", nbOfKeys, backedUpKeys)
@ -293,7 +293,7 @@ class KeysBackupTest : InstrumentedTest {
fun testEncryptAndDecryptKeysBackupData() {
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService() as KeysBackup
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService
val stateObserver = StateObserver(keysBackup)
@ -337,7 +337,7 @@ class KeysBackupTest : InstrumentedTest {
// - Restore the e2e backup from the homeserver
val latch2 = CountDownLatch(1)
var importRoomKeysResult: ImportRoomKeysResult? = null
testData.aliceSession2.getKeysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
testData.prepareKeysBackupDataResult.megolmBackupCreationInfo.recoveryKey,
null,
null,
@ -373,7 +373,7 @@ class KeysBackupTest : InstrumentedTest {
val testData = createKeysBackupScenarioWithPassword(null)
// - Check the SDK sent key share requests
val cryptoStore2 = (testData.aliceSession2.getKeysBackupService() as KeysBackup).store
val cryptoStore2 = (testData.aliceSession2.cryptoService().keysBackupService() as DefaultKeysBackupService).store
val unsentRequest = cryptoStore2
.getOutgoingRoomKeyRequestByState(setOf(OutgoingRoomKeyRequest.RequestState.UNSENT))
val sentRequest = cryptoStore2
@ -385,7 +385,7 @@ class KeysBackupTest : InstrumentedTest {
// - Restore the e2e backup from the homeserver
val latch2 = CountDownLatch(1)
var importRoomKeysResult: ImportRoomKeysResult? = null
testData.aliceSession2.getKeysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
testData.prepareKeysBackupDataResult.megolmBackupCreationInfo.recoveryKey,
null,
null,
@ -429,17 +429,17 @@ class KeysBackupTest : InstrumentedTest {
// - And log Alice on a new device
val testData = createKeysBackupScenarioWithPassword(null)
val stateObserver = StateObserver(testData.aliceSession2.getKeysBackupService())
val stateObserver = StateObserver(testData.aliceSession2.cryptoService().keysBackupService())
// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.getKeysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.getKeysBackupService().state)
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
// - Trust the backup from the new device
val latch = CountDownLatch(1)
testData.aliceSession2.getKeysBackupService().trustKeysBackupVersion(
testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().trustKeysBackupVersion(
testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
true,
TestMatrixCallback(latch)
)
@ -449,13 +449,13 @@ class KeysBackupTest : InstrumentedTest {
waitForKeysBackupToBeInState(testData.aliceSession2, KeysBackupState.ReadyToBackUp)
// - Backup must be enabled on the new device, on the same version
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.getKeysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
// - Retrieve the last version from the server
val latch2 = CountDownLatch(1)
var keysVersionResult: KeysVersionResult? = null
testData.aliceSession2.getKeysBackupService().getCurrentVersion(
testData.aliceSession2.cryptoService().keysBackupService().getCurrentVersion(
object : TestMatrixCallback<KeysVersionResult?>(latch2) {
override fun onSuccess(data: KeysVersionResult?) {
keysVersionResult = data
@ -470,7 +470,7 @@ class KeysBackupTest : InstrumentedTest {
val latch3 = CountDownLatch(1)
var keysBackupVersionTrust: KeysBackupVersionTrust? = null
testData.aliceSession2.getKeysBackupService().getKeysBackupTrust(keysVersionResult!!,
testData.aliceSession2.cryptoService().keysBackupService().getKeysBackupTrust(keysVersionResult!!,
object : TestMatrixCallback<KeysBackupVersionTrust>(latch3) {
override fun onSuccess(data: KeysBackupVersionTrust) {
keysBackupVersionTrust = data
@ -503,17 +503,17 @@ class KeysBackupTest : InstrumentedTest {
// - And log Alice on a new device
val testData = createKeysBackupScenarioWithPassword(null)
val stateObserver = StateObserver(testData.aliceSession2.getKeysBackupService())
val stateObserver = StateObserver(testData.aliceSession2.cryptoService().keysBackupService())
// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.getKeysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.getKeysBackupService().state)
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
// - Trust the backup from the new device with the recovery key
val latch = CountDownLatch(1)
testData.aliceSession2.getKeysBackupService().trustKeysBackupVersionWithRecoveryKey(
testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().trustKeysBackupVersionWithRecoveryKey(
testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
testData.prepareKeysBackupDataResult.megolmBackupCreationInfo.recoveryKey,
TestMatrixCallback(latch)
)
@ -523,13 +523,13 @@ class KeysBackupTest : InstrumentedTest {
waitForKeysBackupToBeInState(testData.aliceSession2, KeysBackupState.ReadyToBackUp)
// - Backup must be enabled on the new device, on the same version
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.getKeysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
// - Retrieve the last version from the server
val latch2 = CountDownLatch(1)
var keysVersionResult: KeysVersionResult? = null
testData.aliceSession2.getKeysBackupService().getCurrentVersion(
testData.aliceSession2.cryptoService().keysBackupService().getCurrentVersion(
object : TestMatrixCallback<KeysVersionResult?>(latch2) {
override fun onSuccess(data: KeysVersionResult?) {
keysVersionResult = data
@ -544,7 +544,7 @@ class KeysBackupTest : InstrumentedTest {
val latch3 = CountDownLatch(1)
var keysBackupVersionTrust: KeysBackupVersionTrust? = null
testData.aliceSession2.getKeysBackupService().getKeysBackupTrust(keysVersionResult!!,
testData.aliceSession2.cryptoService().keysBackupService().getKeysBackupTrust(keysVersionResult!!,
object : TestMatrixCallback<KeysBackupVersionTrust>(latch3) {
override fun onSuccess(data: KeysBackupVersionTrust) {
keysBackupVersionTrust = data
@ -575,26 +575,26 @@ class KeysBackupTest : InstrumentedTest {
// - And log Alice on a new device
val testData = createKeysBackupScenarioWithPassword(null)
val stateObserver = StateObserver(testData.aliceSession2.getKeysBackupService())
val stateObserver = StateObserver(testData.aliceSession2.cryptoService().keysBackupService())
// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.getKeysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.getKeysBackupService().state)
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
// - Try to trust the backup from the new device with a wrong recovery key
val latch = CountDownLatch(1)
testData.aliceSession2.getKeysBackupService().trustKeysBackupVersionWithRecoveryKey(
testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().trustKeysBackupVersionWithRecoveryKey(
testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
"Bad recovery key",
TestMatrixCallback(latch, false)
)
mTestHelper.await(latch)
// - The new device must still see the previous backup as not trusted
assertNotNull(testData.aliceSession2.getKeysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.getKeysBackupService().state)
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
stateObserver.stopAndCheckStates(null)
testData.cryptoTestData.close()
@ -618,17 +618,17 @@ class KeysBackupTest : InstrumentedTest {
// - And log Alice on a new device
val testData = createKeysBackupScenarioWithPassword(password)
val stateObserver = StateObserver(testData.aliceSession2.getKeysBackupService())
val stateObserver = StateObserver(testData.aliceSession2.cryptoService().keysBackupService())
// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.getKeysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.getKeysBackupService().state)
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
// - Trust the backup from the new device with the password
val latch = CountDownLatch(1)
testData.aliceSession2.getKeysBackupService().trustKeysBackupVersionWithPassphrase(
testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().trustKeysBackupVersionWithPassphrase(
testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
password,
TestMatrixCallback(latch)
)
@ -638,13 +638,13 @@ class KeysBackupTest : InstrumentedTest {
waitForKeysBackupToBeInState(testData.aliceSession2, KeysBackupState.ReadyToBackUp)
// - Backup must be enabled on the new device, on the same version
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.getKeysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
// - Retrieve the last version from the server
val latch2 = CountDownLatch(1)
var keysVersionResult: KeysVersionResult? = null
testData.aliceSession2.getKeysBackupService().getCurrentVersion(
testData.aliceSession2.cryptoService().keysBackupService().getCurrentVersion(
object : TestMatrixCallback<KeysVersionResult?>(latch2) {
override fun onSuccess(data: KeysVersionResult?) {
keysVersionResult = data
@ -659,7 +659,7 @@ class KeysBackupTest : InstrumentedTest {
val latch3 = CountDownLatch(1)
var keysBackupVersionTrust: KeysBackupVersionTrust? = null
testData.aliceSession2.getKeysBackupService().getKeysBackupTrust(keysVersionResult!!,
testData.aliceSession2.cryptoService().keysBackupService().getKeysBackupTrust(keysVersionResult!!,
object : TestMatrixCallback<KeysBackupVersionTrust>(latch3) {
override fun onSuccess(data: KeysBackupVersionTrust) {
keysBackupVersionTrust = data
@ -693,26 +693,26 @@ class KeysBackupTest : InstrumentedTest {
// - And log Alice on a new device
val testData = createKeysBackupScenarioWithPassword(password)
val stateObserver = StateObserver(testData.aliceSession2.getKeysBackupService())
val stateObserver = StateObserver(testData.aliceSession2.cryptoService().keysBackupService())
// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.getKeysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.getKeysBackupService().state)
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
// - Try to trust the backup from the new device with a wrong password
val latch = CountDownLatch(1)
testData.aliceSession2.getKeysBackupService().trustKeysBackupVersionWithPassphrase(
testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().trustKeysBackupVersionWithPassphrase(
testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
badPassword,
TestMatrixCallback(latch, false)
)
mTestHelper.await(latch)
// - The new device must still see the previous backup as not trusted
assertNotNull(testData.aliceSession2.getKeysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.getKeysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.getKeysBackupService().state)
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
stateObserver.stopAndCheckStates(null)
testData.cryptoTestData.close()
@ -731,7 +731,7 @@ class KeysBackupTest : InstrumentedTest {
// - Try to restore the e2e backup with a wrong recovery key
val latch2 = CountDownLatch(1)
var importRoomKeysResult: ImportRoomKeysResult? = null
testData.aliceSession2.getKeysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
"EsTc LW2K PGiF wKEA 3As5 g5c4 BXwk qeeJ ZJV8 Q9fu gUMN UE4d",
null,
null,
@ -768,7 +768,7 @@ class KeysBackupTest : InstrumentedTest {
var importRoomKeysResult: ImportRoomKeysResult? = null
val steps = ArrayList<StepProgressListener.Step>()
testData.aliceSession2.getKeysBackupService().restoreKeyBackupWithPassword(testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().restoreKeyBackupWithPassword(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
password,
null,
null,
@ -828,7 +828,7 @@ class KeysBackupTest : InstrumentedTest {
// - Try to restore the e2e backup with a wrong password
val latch2 = CountDownLatch(1)
var importRoomKeysResult: ImportRoomKeysResult? = null
testData.aliceSession2.getKeysBackupService().restoreKeyBackupWithPassword(testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().restoreKeyBackupWithPassword(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
wrongPassword,
null,
null,
@ -863,7 +863,7 @@ class KeysBackupTest : InstrumentedTest {
// - Restore the e2e backup with the recovery key.
val latch2 = CountDownLatch(1)
var importRoomKeysResult: ImportRoomKeysResult? = null
testData.aliceSession2.getKeysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().restoreKeysWithRecoveryKey(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
testData.prepareKeysBackupDataResult.megolmBackupCreationInfo.recoveryKey,
null,
null,
@ -895,7 +895,7 @@ class KeysBackupTest : InstrumentedTest {
// - Try to restore the e2e backup with a password
val latch2 = CountDownLatch(1)
var importRoomKeysResult: ImportRoomKeysResult? = null
testData.aliceSession2.getKeysBackupService().restoreKeyBackupWithPassword(testData.aliceSession2.getKeysBackupService().keysBackupVersion!!,
testData.aliceSession2.cryptoService().keysBackupService().restoreKeyBackupWithPassword(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion!!,
"password",
null,
null,
@ -924,7 +924,7 @@ class KeysBackupTest : InstrumentedTest {
// - Create a backup version
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -967,7 +967,7 @@ class KeysBackupTest : InstrumentedTest {
val signature = keysBackupVersionTrust!!.signatures[0]
assertTrue(signature.valid)
assertNotNull(signature.device)
assertEquals(cryptoTestData.firstSession.getMyDevice().deviceId, signature.deviceId)
assertEquals(cryptoTestData.firstSession.cryptoService().getMyDevice().deviceId, signature.deviceId)
assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.credentials.deviceId)
stateObserver.stopAndCheckStates(null)
@ -986,7 +986,7 @@ class KeysBackupTest : InstrumentedTest {
// - Create a backup version
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -1002,7 +1002,7 @@ class KeysBackupTest : InstrumentedTest {
cryptoTestData.close()
val keysBackup2 = aliceSession2.getKeysBackupService()
val keysBackup2 = aliceSession2.cryptoService().keysBackupService()
val stateObserver2 = StateObserver(keysBackup2)
@ -1046,7 +1046,7 @@ class KeysBackupTest : InstrumentedTest {
// - Create a backup version
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -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.getKeysBackupService() as KeysBackup).store.resetBackupMarkers()
(cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService).store.resetBackupMarkers()
// - Make alice back up all her keys again
val latch2 = CountDownLatch(1)
@ -1121,7 +1121,7 @@ class KeysBackupTest : InstrumentedTest {
// - Create a backup version
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -1147,14 +1147,14 @@ class KeysBackupTest : InstrumentedTest {
val aliceSession2 = mTestHelper.logIntoAccount(aliceUserId, defaultSessionParamsWithInitialSync)
// - Post a message to have a new megolm session
aliceSession2.setWarnOnUnknownDevices(false)
aliceSession2.cryptoService().setWarnOnUnknownDevices(false)
val room2 = aliceSession2.getRoom(cryptoTestData.roomId)!!
mTestHelper.sendTextMessage(room2, "New key", 1)
// - Try to backup all in aliceSession2, it must fail
val keysBackup2 = aliceSession2.getKeysBackupService()
val keysBackup2 = aliceSession2.cryptoService().keysBackupService()
val stateObserver2 = StateObserver(keysBackup2)
@ -1178,7 +1178,7 @@ class KeysBackupTest : InstrumentedTest {
assertFalse(keysBackup2.isEnabled)
// - Validate the old device from the new one
aliceSession2.setDeviceVerification(DeviceTrustLevel(false, true), aliceSession2.myUserId, oldDeviceId)
aliceSession2.cryptoService().setDeviceVerification(DeviceTrustLevel(false, true), aliceSession2.myUserId, oldDeviceId)
// -> Backup should automatically enable on the new device
val latch4 = CountDownLatch(1)
@ -1196,14 +1196,14 @@ class KeysBackupTest : InstrumentedTest {
mTestHelper.await(latch4)
// -> It must use the same backup version
assertEquals(oldKeyBackupVersion, aliceSession2.getKeysBackupService().currentBackupVersion)
assertEquals(oldKeyBackupVersion, aliceSession2.cryptoService().keysBackupService().currentBackupVersion)
val latch5 = CountDownLatch(1)
aliceSession2.getKeysBackupService().backupAllGroupSessions(null, TestMatrixCallback(latch5))
aliceSession2.cryptoService().keysBackupService().backupAllGroupSessions(null, TestMatrixCallback(latch5))
mTestHelper.await(latch5)
// -> It must success
assertTrue(aliceSession2.getKeysBackupService().isEnabled)
assertTrue(aliceSession2.cryptoService().keysBackupService().isEnabled)
stateObserver.stopAndCheckStates(null)
stateObserver2.stopAndCheckStates(null)
@ -1220,7 +1220,7 @@ class KeysBackupTest : InstrumentedTest {
// - Create a backup version
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -1254,17 +1254,17 @@ class KeysBackupTest : InstrumentedTest {
*/
private fun waitForKeysBackupToBeInState(session: Session, state: KeysBackupState) {
// If already in the wanted state, return
if (session.getKeysBackupService().state == state) {
if (session.cryptoService().keysBackupService().state == state) {
return
}
// Else observe state changes
val latch = CountDownLatch(1)
session.getKeysBackupService().addListener(object : KeysBackupStateListener {
session.cryptoService().keysBackupService().addListener(object : KeysBackupStateListener {
override fun onStateChange(newState: KeysBackupState) {
if (newState == state) {
session.getKeysBackupService().removeListener(this)
session.cryptoService().keysBackupService().removeListener(this)
latch.countDown()
}
}
@ -1359,8 +1359,8 @@ class KeysBackupTest : InstrumentedTest {
private fun createKeysBackupScenarioWithPassword(password: String?): KeysBackupScenarioData {
val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages()
val cryptoStore = (cryptoTestData.firstSession.getKeysBackupService() as KeysBackup).store
val keysBackup = cryptoTestData.firstSession.getKeysBackupService()
val cryptoStore = (cryptoTestData.firstSession.cryptoService().keysBackupService() as DefaultKeysBackupService).store
val keysBackup = cryptoTestData.firstSession.cryptoService().keysBackupService()
val stateObserver = StateObserver(keysBackup)
@ -1394,7 +1394,7 @@ class KeysBackupTest : InstrumentedTest {
val aliceSession2 = mTestHelper.logIntoAccount(aliceUserId, defaultSessionParamsWithInitialSync)
// Test check: aliceSession2 has no keys at login
assertEquals(0, aliceSession2.inboundGroupSessionsCount(false))
assertEquals(0, aliceSession2.cryptoService().inboundGroupSessionsCount(false))
// Wait for backup state to be NotTrusted
waitForKeysBackupToBeInState(aliceSession2, KeysBackupState.NotTrusted)
@ -1421,11 +1421,11 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(total, imported)
// - The new device must have the same count of megolm keys
assertEquals(testData.aliceKeys.size, testData.aliceSession2.inboundGroupSessionsCount(false))
assertEquals(testData.aliceKeys.size, testData.aliceSession2.cryptoService().inboundGroupSessionsCount(false))
// - Alice must have the same keys on both devices
for (aliceKey1 in testData.aliceKeys) {
val aliceKey2 = (testData.aliceSession2.getKeysBackupService() 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())

View File

@ -62,8 +62,8 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val bobSession = cryptoTestData.secondSession
val aliceVerificationService = aliceSession.getVerificationService()
val bobVerificationService = bobSession!!.getVerificationService()
val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession!!.cryptoService().verificationService()
val bobTxCreatedLatch = CountDownLatch(1)
val bobListener = object : VerificationService.Listener {
@ -75,7 +75,7 @@ class SASTest : InstrumentedTest {
val txID = aliceVerificationService.beginKeyVerification(VerificationMethod.SAS,
bobSession.myUserId,
bobSession.getMyDevice().deviceId,
bobSession.cryptoService().getMyDevice().deviceId,
null)
assertNotNull("Alice should have a started transaction", txID)
@ -157,7 +157,7 @@ class SASTest : InstrumentedTest {
}
}
}
bobSession.getVerificationService().addListener(bobListener)
bobSession.cryptoService().verificationService().addListener(bobListener)
// TODO bobSession!!.dataHandler.addListener(object : MXEventListener() {
// TODO override fun onToDeviceEvent(event: Event?) {
@ -172,7 +172,7 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val aliceUserID = aliceSession.myUserId
val aliceDevice = aliceSession.getMyDevice().deviceId
val aliceDevice = aliceSession.cryptoService().getMyDevice().deviceId
val aliceListener = object : VerificationService.Listener {
override fun transactionUpdated(tx: VerificationTransaction) {
@ -181,7 +181,7 @@ class SASTest : InstrumentedTest {
}
}
}
aliceSession.getVerificationService().addListener(aliceListener)
aliceSession.cryptoService().verificationService().addListener(aliceListener)
fakeBobStart(bobSession, aliceUserID, aliceDevice, tid, protocols = protocols)
@ -218,7 +218,7 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val aliceUserID = aliceSession.myUserId
val aliceDevice = aliceSession.getMyDevice().deviceId
val aliceDevice = aliceSession.cryptoService().getMyDevice().deviceId
fakeBobStart(bobSession, aliceUserID, aliceDevice, tid, mac = mac)
@ -256,7 +256,7 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val aliceUserID = aliceSession.myUserId
val aliceDevice = aliceSession.getMyDevice().deviceId
val aliceDevice = aliceSession.cryptoService().getMyDevice().deviceId
fakeBobStart(bobSession, aliceUserID, aliceDevice, tid, codes = codes)
@ -277,7 +277,7 @@ class SASTest : InstrumentedTest {
mac: List<String> = SASDefaultVerificationTransaction.KNOWN_MACS,
codes: List<String> = SASDefaultVerificationTransaction.KNOWN_SHORT_CODES) {
val startMessage = KeyVerificationStart(
fromDevice = bobSession.getMyDevice().deviceId,
fromDevice = bobSession.cryptoService().getMyDevice().deviceId,
method = VerificationMethod.SAS.toValue(),
transactionID = tid,
keyAgreementProtocols = protocols,
@ -307,7 +307,7 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val bobSession = cryptoTestData.secondSession
val aliceVerificationService = aliceSession.getVerificationService()
val aliceVerificationService = aliceSession.cryptoService().verificationService()
val aliceCreatedLatch = CountDownLatch(2)
val aliceCancelledLatch = CountDownLatch(2)
@ -327,7 +327,7 @@ class SASTest : InstrumentedTest {
aliceVerificationService.addListener(aliceListener)
val bobUserId = bobSession!!.myUserId
val bobDeviceId = bobSession.getMyDevice().deviceId
val bobDeviceId = bobSession.cryptoService().getMyDevice().deviceId
aliceVerificationService.beginKeyVerification(VerificationMethod.SAS, bobUserId, bobDeviceId, null)
aliceVerificationService.beginKeyVerification(VerificationMethod.SAS, bobUserId, bobDeviceId, null)
@ -347,8 +347,8 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val bobSession = cryptoTestData.secondSession
val aliceVerificationService = aliceSession.getVerificationService()
val bobVerificationService = bobSession!!.getVerificationService()
val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession!!.cryptoService().verificationService()
var accepted: KeyVerificationAccept? = null
var startReq: KeyVerificationStart? = null
@ -377,7 +377,7 @@ class SASTest : InstrumentedTest {
bobVerificationService.addListener(bobListener)
val bobUserId = bobSession.myUserId
val bobDeviceId = bobSession.getMyDevice().deviceId
val bobDeviceId = bobSession.cryptoService().getMyDevice().deviceId
aliceVerificationService.beginKeyVerification(VerificationMethod.SAS, bobUserId, bobDeviceId, null)
mTestHelper.await(aliceAcceptedLatch)
@ -403,8 +403,8 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val bobSession = cryptoTestData.secondSession
val aliceVerificationService = aliceSession.getVerificationService()
val bobVerificationService = bobSession!!.getVerificationService()
val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession!!.cryptoService().verificationService()
val aliceSASLatch = CountDownLatch(1)
val aliceListener = object : VerificationService.Listener {
@ -438,7 +438,7 @@ class SASTest : InstrumentedTest {
bobVerificationService.addListener(bobListener)
val bobUserId = bobSession.myUserId
val bobDeviceId = bobSession.getMyDevice().deviceId
val bobDeviceId = bobSession.cryptoService().getMyDevice().deviceId
val verificationSAS = aliceVerificationService.beginKeyVerification(VerificationMethod.SAS, bobUserId, bobDeviceId, null)
mTestHelper.await(aliceSASLatch)
mTestHelper.await(bobSASLatch)
@ -459,8 +459,8 @@ class SASTest : InstrumentedTest {
val aliceSession = cryptoTestData.firstSession
val bobSession = cryptoTestData.secondSession
val aliceVerificationService = aliceSession.getVerificationService()
val bobVerificationService = bobSession!!.getVerificationService()
val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession!!.cryptoService().verificationService()
val aliceSASLatch = CountDownLatch(1)
val aliceListener = object : VerificationService.Listener {
@ -500,14 +500,14 @@ class SASTest : InstrumentedTest {
bobVerificationService.addListener(bobListener)
val bobUserId = bobSession.myUserId
val bobDeviceId = bobSession.getMyDevice().deviceId
val bobDeviceId = bobSession.cryptoService().getMyDevice().deviceId
aliceVerificationService.beginKeyVerification(VerificationMethod.SAS, bobUserId, bobDeviceId, null)
mTestHelper.await(aliceSASLatch)
mTestHelper.await(bobSASLatch)
// Assert that devices are verified
val bobDeviceInfoFromAlicePOV: CryptoDeviceInfo? = aliceSession.getDeviceInfo(bobUserId, bobDeviceId)
val aliceDeviceInfoFromBobPOV: CryptoDeviceInfo? = bobSession.getDeviceInfo(aliceSession.myUserId, aliceSession.getMyDevice().deviceId)
val bobDeviceInfoFromAlicePOV: CryptoDeviceInfo? = aliceSession.cryptoService().getDeviceInfo(bobUserId, bobDeviceId)
val aliceDeviceInfoFromBobPOV: CryptoDeviceInfo? = bobSession.cryptoService().getDeviceInfo(aliceSession.myUserId, aliceSession.cryptoService().getMyDevice().deviceId)
// latch wait a bit again
Thread.sleep(1000)

View File

@ -156,7 +156,7 @@ class VerificationTest : InstrumentedTest {
val bobSession = cryptoTestData.secondSession!!
mTestHelper.doSync<Unit> { callback ->
aliceSession.getCrossSigningService()
aliceSession.cryptoService().crossSigningService()
.initializeCrossSigning(UserPasswordAuth(
user = aliceSession.myUserId,
password = TestConstants.PASSWORD
@ -164,15 +164,15 @@ class VerificationTest : InstrumentedTest {
}
mTestHelper.doSync<Unit> { callback ->
bobSession.getCrossSigningService()
bobSession.cryptoService().crossSigningService()
.initializeCrossSigning(UserPasswordAuth(
user = bobSession.myUserId,
password = TestConstants.PASSWORD
), callback)
}
val aliceVerificationService = aliceSession.getVerificationService()
val bobVerificationService = bobSession.getVerificationService()
val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession.cryptoService().verificationService()
var aliceReadyPendingVerificationRequest: PendingVerificationRequest? = null
var bobReadyPendingVerificationRequest: PendingVerificationRequest? = null

View File

@ -49,7 +49,6 @@ interface Session :
RoomDirectoryService,
GroupService,
UserService,
CryptoService,
CacheService,
SignOutService,
FilterService,
@ -139,6 +138,11 @@ interface Session :
*/
fun contentUploadProgressTracker(): ContentUploadStateTracker
/**
* Returns the cryptoService associated with the session
*/
fun cryptoService(): CryptoService
/**
* Add a listener to the session.
* @param listener the listener to add.

View File

@ -40,6 +40,12 @@ import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
interface CryptoService {
fun verificationService(): VerificationService
fun crossSigningService(): CrossSigningService
fun keysBackupService(): KeysBackupService
fun setDeviceName(deviceId: String, deviceName: String, callback: MatrixCallback<Unit>)
fun deleteDevice(deviceId: String, callback: MatrixCallback<Unit>)
@ -50,12 +56,6 @@ interface CryptoService {
fun isCryptoEnabled(): Boolean
fun getVerificationService(): VerificationService
fun getCrossSigningService(): CrossSigningService
fun getKeysBackupService(): KeysBackupService
fun isRoomBlacklistUnverifiedDevices(roomId: String?): Boolean
fun setWarnOnUnknownDevices(warn: Boolean)

View File

@ -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,14 +340,14 @@ internal class DefaultCryptoService @Inject constructor(
/**
* @return the Keys backup Service
*/
override fun getKeysBackupService() = keysBackup
override fun keysBackupService() = keysBackupService
/**
* @return the VerificationService
*/
override fun getVerificationService() = verificationService
override fun verificationService() = verificationService
override fun getCrossSigningService() = crossSigningService
override fun crossSigningService() = crossSigningService
/**
* A sync response has been received
@ -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)
}
/**

View File

@ -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()
}
}

View File

@ -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

View File

@ -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<RoomKeyContent>() ?: return
@ -262,7 +262,7 @@ internal class MXMegolmDecryption(private val userId: String,
exportFormat)
if (added) {
keysBackup.maybeBackupKeys()
defaultKeysBackupService.maybeBackupKeys()
val content = RoomKeyRequestBody()

View File

@ -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)
}

View File

@ -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,

View File

@ -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,

View File

@ -49,7 +49,6 @@ import im.vector.matrix.android.internal.crypto.crosssigning.ShieldTrustUpdater
import im.vector.matrix.android.internal.database.LiveEntityObserver
import im.vector.matrix.android.internal.di.SessionId
import im.vector.matrix.android.internal.di.WorkManagerProvider
import im.vector.matrix.android.internal.session.sync.SyncTaskSequencer
import im.vector.matrix.android.internal.session.sync.SyncTokenStore
import im.vector.matrix.android.internal.session.sync.job.SyncThread
import im.vector.matrix.android.internal.session.sync.job.SyncWorker
@ -88,7 +87,6 @@ internal class DefaultSession @Inject constructor(
private val syncThreadProvider: Provider<SyncThread>,
private val contentUrlResolver: ContentUrlResolver,
private val syncTokenStore: SyncTokenStore,
private val syncTaskSequencer: SyncTaskSequencer,
private val sessionParamsStore: SessionParamsStore,
private val contentUploadProgressTracker: ContentUploadStateTracker,
private val initialSyncProgressService: Lazy<InitialSyncProgressService>,
@ -101,7 +99,6 @@ internal class DefaultSession @Inject constructor(
RoomDirectoryService by roomDirectoryService.get(),
GroupService by groupService.get(),
UserService by userService.get(),
CryptoService by cryptoService.get(),
SignOutService by signOutService.get(),
FilterService by filterService.get(),
PushRuleService by pushRuleService.get(),
@ -170,7 +167,6 @@ internal class DefaultSession @Inject constructor(
cryptoService.get().close()
isOpen = false
eventBus.unregister(this)
syncTaskSequencer.close()
shieldTrustUpdater.stop()
}
@ -212,6 +208,8 @@ internal class DefaultSession @Inject constructor(
override fun contentUploadProgressTracker() = contentUploadProgressTracker
override fun cryptoService(): CryptoService = cryptoService.get()
override fun addListener(listener: Session.Listener) {
sessionListeners.addListener(listener)
}

View File

@ -17,8 +17,8 @@
package im.vector.matrix.android.internal.session.sync
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.ChannelCoroutineSequencer
import im.vector.matrix.android.internal.task.SemaphoreCoroutineSequencer
import javax.inject.Inject
@SessionScope
internal class SyncTaskSequencer @Inject constructor() : ChannelCoroutineSequencer<Unit>()
internal class SyncTaskSequencer @Inject constructor() : SemaphoreCoroutineSequencer()

View File

@ -16,72 +16,28 @@
package im.vector.matrix.android.internal.task
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import java.util.concurrent.Executors
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
/**
* This class intends to be used for ensure suspendable methods are played sequentially all the way long.
* This class intends to be used to ensure suspendable methods are played sequentially all the way long.
*/
internal interface CoroutineSequencer<T> {
internal interface CoroutineSequencer {
/**
* @param block the suspendable block to execute
* @return the result of the block
*/
suspend fun post(block: suspend () -> T): T
/**
* Cancel all and close, so you won't be able to post anything else after
*/
fun close()
suspend fun <T> post(block: suspend () -> T): T
}
internal open class ChannelCoroutineSequencer<T> : CoroutineSequencer<T> {
internal open class SemaphoreCoroutineSequencer : CoroutineSequencer {
private data class Message<T>(
val block: suspend () -> T,
val deferred: CompletableDeferred<T>
)
// Permits 1 suspend function at a time.
private val semaphore = Semaphore(1)
private var messageChannel: Channel<Message<T>> = Channel()
private val coroutineScope = CoroutineScope(SupervisorJob())
// This will ensure
private val singleDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
init {
launchCoroutine()
}
private fun launchCoroutine() {
coroutineScope.launch(singleDispatcher) {
for (message in messageChannel) {
try {
val result = message.block()
message.deferred.complete(result)
} catch (exception: Throwable) {
message.deferred.completeExceptionally(exception)
}
}
}
}
override fun close() {
coroutineScope.coroutineContext.cancelChildren()
messageChannel.close()
}
override suspend fun post(block: suspend () -> T): T {
val deferred = CompletableDeferred<T>()
val message = Message(block, deferred)
messageChannel.send(message)
return try {
deferred.await()
} catch (cancellation: CancellationException) {
// In case of cancellation, we stop the current coroutine context
// and relaunch one to consume next messages
coroutineScope.coroutineContext.cancelChildren()
launchCoroutine()
throw cancellation
override suspend fun <T> post(block: suspend () -> T): T {
return semaphore.withPermit {
block()
}
}
}

View File

@ -32,7 +32,7 @@ class CoroutineSequencersTest {
@Test
fun sequencer_should_run_sequential() {
val sequencer = ChannelCoroutineSequencer<String>()
val sequencer = SemaphoreCoroutineSequencer()
val results = ArrayList<String>()
val jobs = listOf(
@ -63,9 +63,9 @@ class CoroutineSequencersTest {
@Test
fun sequencer_should_run_parallel() {
val sequencer1 = ChannelCoroutineSequencer<String>()
val sequencer2 = ChannelCoroutineSequencer<String>()
val sequencer3 = ChannelCoroutineSequencer<String>()
val sequencer1 = SemaphoreCoroutineSequencer()
val sequencer2 = SemaphoreCoroutineSequencer()
val sequencer3 = SemaphoreCoroutineSequencer()
val results = ArrayList<String>()
val jobs = listOf(
GlobalScope.launch(dispatcher) {
@ -92,7 +92,7 @@ class CoroutineSequencersTest {
@Test
fun sequencer_should_jump_to_next_when_current_job_canceled() {
val sequencer = ChannelCoroutineSequencer<String>()
val sequencer = SemaphoreCoroutineSequencer()
val results = ArrayList<String>()
val jobs = listOf(
GlobalScope.launch(dispatcher) {

View File

@ -66,6 +66,6 @@ fun Session.startSyncing(context: Context) {
* Tell is the session has unsaved e2e keys in the backup
*/
fun Session.hasUnsavedKeys(): Boolean {
return inboundGroupSessionsCount(false) > 0
&& getKeysBackupService().state != KeysBackupState.ReadyToBackUp
return cryptoService().inboundGroupSessionsCount(false) > 0
&& cryptoService().keysBackupService().state != KeysBackupState.ReadyToBackUp
}

View File

@ -38,7 +38,7 @@ class KeysExporter(private val session: Session) {
fun export(context: Context, password: String, callback: MatrixCallback<String>) {
GlobalScope.launch(Dispatchers.Main) {
runCatching {
val data = awaitCallback<ByteArray> { session.exportRoomKeys(password, it) }
val data = awaitCallback<ByteArray> { session.cryptoService().exportRoomKeys(password, it) }
withContext(Dispatchers.IO) {
val parentDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
val file = File(parentDir, "riotx-keys-" + System.currentTimeMillis() + ".txt")

View File

@ -59,7 +59,7 @@ class KeysImporter(private val session: Session) {
}
awaitCallback<ImportRoomKeysResult> {
session.importRoomKeys(data, password, null, it)
session.cryptoService().importRoomKeys(data, password, null, it)
}
}
}.foldToCallback(callback)

View File

@ -47,7 +47,7 @@ class KeysBackupRestoreFromKeyViewModel @Inject constructor() : ViewModel() {
fun recoverKeys(context: Context, sharedViewModel: KeysBackupRestoreSharedViewModel) {
val session = sharedViewModel.session
val keysBackup = session.getKeysBackupService()
val keysBackup = session.cryptoService().keysBackupService()
recoveryCodeErrorText.value = null
val recoveryKey = recoveryCode.value!!

View File

@ -49,7 +49,7 @@ class KeysBackupRestoreFromPassphraseViewModel @Inject constructor() : ViewModel
}
fun recoverKeys(context: Context, sharedViewModel: KeysBackupRestoreSharedViewModel) {
val keysBackup = sharedViewModel.session.getKeysBackupService()
val keysBackup = sharedViewModel.session.cryptoService().keysBackupService()
passphraseErrorText.value = null

View File

@ -63,7 +63,7 @@ class KeysBackupRestoreSharedViewModel @Inject constructor() : ViewModel() {
}
fun getLatestVersion(context: Context) {
val keysBackup = session.getKeysBackupService()
val keysBackup = session.cryptoService().keysBackupService()
loadingEvent.value = WaitingViewData(context.getString(R.string.keys_backup_restore_is_getting_backup_version))

View File

@ -119,8 +119,8 @@ class KeysBackupSettingsRecyclerViewController @Inject constructor(private val s
style(GenericItem.STYLE.BIG_TEXT)
hasIndeterminateProcess(true)
val totalKeys = session.inboundGroupSessionsCount(false)
val backedUpKeys = session.inboundGroupSessionsCount(true)
val totalKeys = session.cryptoService().inboundGroupSessionsCount(false)
val backedUpKeys = session.cryptoService().inboundGroupSessionsCount(true)
val remainingKeysToBackup = totalKeys - backedUpKeys

View File

@ -47,13 +47,13 @@ class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialS
}
}
private var keysBackupService: KeysBackupService = session.getKeysBackupService()
private val keysBackupService: KeysBackupService = session.cryptoService().keysBackupService()
init {
setState {
this.copy(
keysBackupState = session.getKeysBackupService().state,
keysBackupVersion = session.getKeysBackupService().keysBackupVersion
keysBackupState = keysBackupService.state,
keysBackupVersion = keysBackupService.keysBackupVersion
)
}
keysBackupService.addListener(this)

View File

@ -102,7 +102,7 @@ class KeysBackupSetupSharedViewModel @Inject constructor() : ViewModel() {
session.let { mxSession ->
val requestedId = currentRequestId.value!!
mxSession.getKeysBackupService().prepareKeysBackupVersion(withPassphrase,
mxSession.cryptoService().keysBackupService().prepareKeysBackupVersion(withPassphrase,
object : ProgressListener {
override fun onProgress(progress: Int, total: Int) {
if (requestedId != currentRequestId.value) {
@ -125,7 +125,7 @@ class KeysBackupSetupSharedViewModel @Inject constructor() : ViewModel() {
megolmBackupCreationInfo = data
copyHasBeenMade = false
val keyBackup = session.getKeysBackupService()
val keyBackup = session.cryptoService().keysBackupService()
createKeysBackup(context, keyBackup)
}
@ -145,14 +145,14 @@ class KeysBackupSetupSharedViewModel @Inject constructor() : ViewModel() {
}
fun forceCreateKeyBackup(context: Context) {
val keyBackup = session.getKeysBackupService()
val keyBackup = session.cryptoService().keysBackupService()
createKeysBackup(context, keyBackup, true)
}
fun stopAndKeepAfterDetectingExistingOnServer() {
loadingStatus.value = null
navigateEvent.value = LiveEvent(NAVIGATE_FINISH)
session.getKeysBackupService().checkAndStartKeysBackup()
session.cryptoService().keysBackupService().checkAndStartKeysBackup()
}
private fun createKeysBackup(context: Context, keysBackup: KeysBackupService, forceOverride: Boolean = false) {

View File

@ -64,13 +64,13 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
fun start(session: Session) {
this.session = session
session.getVerificationService().addListener(this)
session.addRoomKeysRequestListener(this)
session.cryptoService().verificationService().addListener(this)
session.cryptoService().addRoomKeysRequestListener(this)
}
fun stop() {
session?.getVerificationService()?.removeListener(this)
session?.removeRoomKeysRequestListener(this)
session?.cryptoService()?.verificationService()?.removeListener(this)
session?.cryptoService()?.removeRoomKeysRequestListener(this)
session = null
}
@ -100,7 +100,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
alertsToRequests[mappingKey] = ArrayList<IncomingRoomKeyRequest>().apply { this.add(request) }
// Add a notification for every incoming request
session?.downloadKeys(listOf(userId), false, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
session?.cryptoService()?.downloadKeys(listOf(userId), false, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
override fun onSuccess(data: MXUsersDevicesMap<CryptoDeviceInfo>) {
val deviceInfo = data.getObject(userId, deviceId)
@ -111,12 +111,12 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
}
if (deviceInfo.isUnknown) {
session?.setDeviceVerification(DeviceTrustLevel(false, false), userId, deviceId)
session?.cryptoService()?.setDeviceVerification(DeviceTrustLevel(false, false), userId, deviceId)
deviceInfo.trustLevel = DeviceTrustLevel(false, false)
// can we get more info on this device?
session?.getDevicesList(object : MatrixCallback<DevicesListResponse> {
session?.cryptoService()?.getDevicesList(object : MatrixCallback<DevicesListResponse> {
override fun onSuccess(data: DevicesListResponse) {
data.devices?.find { it.deviceId == deviceId }?.let {
postAlert(context, userId, deviceId, true, deviceInfo, it)

View File

@ -40,11 +40,11 @@ class IncomingVerificationRequestHandler @Inject constructor(private val context
fun start(session: Session) {
this.session = session
session.getVerificationService().addListener(this)
session.cryptoService().verificationService().addListener(this)
}
fun stop() {
session?.getVerificationService()?.removeListener(this)
session?.cryptoService()?.verificationService()?.removeListener(this)
this.session = null
}
@ -139,7 +139,7 @@ class IncomingVerificationRequestHandler @Inject constructor(private val context
}
}
dismissedAction = Runnable {
session?.getVerificationService()?.declineVerificationRequestInDMs(pr.otherUserId,
session?.cryptoService()?.verificationService()?.declineVerificationRequestInDMs(pr.otherUserId,
pr.transactionId ?: "",
pr.roomId ?: ""
)

View File

@ -63,7 +63,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
VerificationService.Listener {
init {
session.getVerificationService().addListener(this)
session.cryptoService().verificationService().addListener(this)
val userItem = session.getUser(args.otherUserId)
@ -73,7 +73,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
val pr = if (isWaitingForOtherMode) {
// See if active tx for this user and take it
session.getVerificationService().getExistingVerificationRequest(args.otherUserId)
session.cryptoService().verificationService().getExistingVerificationRequest(args.otherUserId)
?.lastOrNull { !it.isFinished }
?.also { verificationRequest ->
if (verificationRequest.isIncoming && !verificationRequest.isReady) {
@ -82,15 +82,15 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
}
}
} else {
session.getVerificationService().getExistingVerificationRequest(args.otherUserId, args.verificationId)
session.cryptoService().verificationService().getExistingVerificationRequest(args.otherUserId, args.verificationId)
}
val sasTx = (pr?.transactionId ?: args.verificationId)?.let {
session.getVerificationService().getExistingTransaction(args.otherUserId, it) as? SasVerificationTransaction
session.cryptoService().verificationService().getExistingTransaction(args.otherUserId, it) as? SasVerificationTransaction
}
val qrTx = (pr?.transactionId ?: args.verificationId)?.let {
session.getVerificationService().getExistingTransaction(args.otherUserId, it) as? QrCodeVerificationTransaction
session.cryptoService().verificationService().getExistingTransaction(args.otherUserId, it) as? QrCodeVerificationTransaction
}
setState {
@ -108,7 +108,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
if (autoReady) {
// TODO, can I be here in DM mode? in this case should test if roomID is null?
session.getVerificationService()
session.cryptoService().verificationService()
.readyPendingVerification(supportedVerificationMethods,
pr!!.otherUserId,
pr.transactionId ?: "")
@ -116,7 +116,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
}
override fun onCleared() {
session.getVerificationService().removeListener(this)
session.cryptoService().verificationService().removeListener(this)
super.onCleared()
}
@ -164,7 +164,8 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
roomId = data,
pendingRequest = Success(
session
.getVerificationService()
.cryptoService()
.verificationService()
.requestKeyVerificationInDMs(supportedVerificationMethods, otherUserId, data, pendingLocalId)
)
)
@ -181,7 +182,8 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
setState {
copy(
pendingRequest = Success(session
.getVerificationService()
.cryptoService()
.verificationService()
.requestKeyVerificationInDMs(supportedVerificationMethods, otherUserId, roomId)
)
)
@ -190,18 +192,18 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
Unit
}
is VerificationAction.StartSASVerification -> {
val request = session.getVerificationService().getExistingVerificationRequest(otherUserId, action.pendingRequestTransactionId)
val request = session.cryptoService().verificationService().getExistingVerificationRequest(otherUserId, action.pendingRequestTransactionId)
?: return@withState
val otherDevice = if (request.isIncoming) request.requestInfo?.fromDevice else request.readyInfo?.fromDevice
if (roomId == null) {
session.getVerificationService().beginKeyVerification(
session.cryptoService().verificationService().beginKeyVerification(
VerificationMethod.SAS,
otherUserId = request.otherUserId,
otherDeviceId = otherDevice ?: "",
transactionId = action.pendingRequestTransactionId
)
} else {
session.getVerificationService().beginKeyVerificationInDMs(
session.cryptoService().verificationService().beginKeyVerificationInDMs(
VerificationMethod.SAS,
transactionId = action.pendingRequestTransactionId,
roomId = roomId,
@ -213,7 +215,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
Unit
}
is VerificationAction.RemoteQrCodeScanned -> {
val existingTransaction = session.getVerificationService()
val existingTransaction = session.cryptoService().verificationService()
.getExistingTransaction(action.otherUserId, action.transactionId) as? QrCodeVerificationTransaction
existingTransaction
?.userHasScannedOtherQrCode(action.scannedData)
@ -221,7 +223,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
is VerificationAction.OtherUserScannedSuccessfully -> {
val transactionId = state.transactionId ?: return@withState
val existingTransaction = session.getVerificationService()
val existingTransaction = session.cryptoService().verificationService()
.getExistingTransaction(otherUserId, transactionId) as? QrCodeVerificationTransaction
existingTransaction
?.otherUserScannedMyQrCode()
@ -229,18 +231,18 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
is VerificationAction.OtherUserDidNotScanned -> {
val transactionId = state.transactionId ?: return@withState
val existingTransaction = session.getVerificationService()
val existingTransaction = session.cryptoService().verificationService()
.getExistingTransaction(otherUserId, transactionId) as? QrCodeVerificationTransaction
existingTransaction
?.otherUserDidNotScannedMyQrCode()
}
is VerificationAction.SASMatchAction -> {
(session.getVerificationService()
(session.cryptoService().verificationService()
.getExistingTransaction(action.otherUserId, action.sasTransactionId)
as? SasVerificationTransaction)?.userHasVerifiedShortCode()
}
is VerificationAction.SASDoNotMatchAction -> {
(session.getVerificationService()
(session.cryptoService().verificationService()
.getExistingTransaction(action.otherUserId, action.sasTransactionId)
as? SasVerificationTransaction)
?.shortCodeDoesNotMatch()
@ -312,7 +314,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
if (!pr.isReady) {
// auto ready in this case, as we are waiting
// TODO, can I be here in DM mode? in this case should test if roomID is null?
session.getVerificationService()
session.cryptoService().verificationService()
.readyPendingVerification(supportedVerificationMethods,
pr.otherUserId,
pr.transactionId ?: "")

View File

@ -62,7 +62,7 @@ class VerificationChooseMethodViewModel @AssistedInject constructor(
}
override fun verificationRequestUpdated(pr: PendingVerificationRequest) = withState { state ->
val pvr = session.getVerificationService().getExistingVerificationRequest(state.otherUserId, state.transactionId)
val pvr = session.cryptoService().verificationService().getExistingVerificationRequest(state.otherUserId, state.transactionId)
setState {
copy(
@ -79,12 +79,12 @@ class VerificationChooseMethodViewModel @AssistedInject constructor(
}
init {
session.getVerificationService().addListener(this)
session.cryptoService().verificationService().addListener(this)
}
override fun onCleared() {
super.onCleared()
session.getVerificationService().removeListener(this)
session.cryptoService().verificationService().removeListener(this)
}
companion object : MvRxViewModelFactory<VerificationChooseMethodViewModel, VerificationChooseMethodViewState> {
@ -96,10 +96,11 @@ class VerificationChooseMethodViewModel @AssistedInject constructor(
override fun initialState(viewModelContext: ViewModelContext): VerificationChooseMethodViewState? {
val args: VerificationBottomSheet.VerificationArgs = viewModelContext.args()
val session = (viewModelContext.activity as HasScreenInjector).injector().activeSessionHolder().getActiveSession()
val pvr = session.getVerificationService().getExistingVerificationRequest(args.otherUserId, args.verificationId)
val verificationService = session.cryptoService().verificationService()
val pvr = verificationService.getExistingVerificationRequest(args.otherUserId, args.verificationId)
// Get the QR code now, because transaction is already created, so transactionCreated() will not be called
val qrCodeVerificationTransaction = session.getVerificationService().getExistingTransaction(args.otherUserId, args.verificationId ?: "")
val qrCodeVerificationTransaction = verificationService.getExistingTransaction(args.otherUserId, args.verificationId ?: "")
return VerificationChooseMethodViewState(otherUserId = args.otherUserId,
transactionId = args.verificationId ?: "",

View File

@ -56,16 +56,16 @@ class VerificationEmojiCodeViewModel @AssistedInject constructor(
init {
withState { state ->
refreshStateFromTx(session.getVerificationService()
refreshStateFromTx(session.cryptoService().verificationService()
.getExistingTransaction(state.otherUser?.id ?: "", state.transactionId
?: "") as? SasVerificationTransaction)
}
session.getVerificationService().addListener(this)
session.cryptoService().verificationService().addListener(this)
}
override fun onCleared() {
session.getVerificationService().removeListener(this)
session.cryptoService().verificationService().removeListener(this)
super.onCleared()
}

View File

@ -130,7 +130,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
if (sharedActionViewModel.hasDisplayedCompleteSecurityPrompt) return
// ensure keys are downloaded
session.downloadKeys(listOf(session.myUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
session.cryptoService().downloadKeys(listOf(session.myUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
override fun onSuccess(data: MXUsersDevicesMap<CryptoDeviceInfo>) {
runOnUiThread {
alertCompleteSecurity(session)
@ -140,7 +140,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
}
private fun alertCompleteSecurity(session: Session) {
val myCrossSigningKeys = session.getCrossSigningService()
val myCrossSigningKeys = session.cryptoService().crossSigningService()
.getMyCrossSigningKeys()
val crossSigningEnabledOnAccount = myCrossSigningKeys != null

View File

@ -420,7 +420,10 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
popDraft()
}
is ParsedCommand.VerifyUser -> {
session.getVerificationService().requestKeyVerificationInDMs(supportedVerificationMethods, slashCommandResult.userId, room.roomId)
session
.cryptoService()
.verificationService()
.requestKeyVerificationInDMs(supportedVerificationMethods, slashCommandResult.userId, room.roomId)
_viewEvents.post(RoomDetailViewEvents.SlashCommandHandled())
popDraft()
}
@ -826,7 +829,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
private fun handleAcceptVerification(action: RoomDetailAction.AcceptVerificationRequest) {
Timber.v("## SAS handleAcceptVerification ${action.otherUserId}, roomId:${room.roomId}, txId:${action.transactionId}")
if (session.getVerificationService().readyPendingVerificationInDMs(
if (session.cryptoService().verificationService().readyPendingVerificationInDMs(
supportedVerificationMethods,
action.otherUserId,
room.roomId,
@ -838,7 +841,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
}
private fun handleDeclineVerification(action: RoomDetailAction.DeclineVerificationRequest) {
session.getVerificationService().declineVerificationRequestInDMs(
session.cryptoService().verificationService().declineVerificationRequestInDMs(
action.otherUserId,
action.transactionId,
room.roomId)
@ -851,7 +854,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
private fun handleResumeRequestVerification(action: RoomDetailAction.ResumeVerification) {
// Check if this request is still active and handled by me
session.getVerificationService().getExistingVerificationRequestInRoom(room.roomId, action.transactionId)?.let {
session.cryptoService().verificationService().getExistingVerificationRequestInRoom(room.roomId, action.transactionId)?.let {
if (it.handledByOtherSession) return
if (!it.isFinished) {
_viewEvents.post(RoomDetailViewEvents.ActionSuccess(action.copy(

View File

@ -100,7 +100,7 @@ class ViewEditHistoryViewModel @AssistedInject constructor(@Assisted
if (it.isEncrypted() && it.mxDecryptionResult == null) {
// for now decrypt sync
try {
val result = session.decryptEvent(it, timelineID)
val result = session.cryptoService().decryptEvent(it, timelineID)
it.mxDecryptionResult = OlmDecryptionResult(
payload = result.clearEvent,
senderKey = result.senderCurve25519Key,

View File

@ -66,7 +66,7 @@ class DefaultNavigator @Inject constructor(
override fun performDeviceVerification(context: Context, otherUserId: String, sasTransationId: String) {
val session = sessionHolder.getSafeActiveSession() ?: return
val tx = session.getVerificationService().getExistingTransaction(otherUserId, sasTransationId) ?: return
val tx = session.cryptoService().verificationService().getExistingTransaction(otherUserId, sasTransationId) ?: return
(tx as? IncomingSasVerificationTransaction)?.performAccept()
if (context is VectorBaseActivity) {
VerificationBottomSheet.withArgs(
@ -79,10 +79,10 @@ class DefaultNavigator @Inject constructor(
override fun requestSessionVerification(context: Context) {
val session = sessionHolder.getSafeActiveSession() ?: return
val pr = session.getVerificationService().requestKeyVerification(
val pr = session.cryptoService().verificationService().requestKeyVerification(
listOf(VerificationMethod.SAS, VerificationMethod.QR_CODE_SCAN, VerificationMethod.QR_CODE_SHOW),
session.myUserId,
session.getUserDevices(session.myUserId).map { it.deviceId })
session.cryptoService().getUserDevices(session.myUserId).map { it.deviceId })
if (context is VectorBaseActivity) {
VerificationBottomSheet.withArgs(
roomId = null,

View File

@ -114,7 +114,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
// TODO use a global event decryptor? attache to session and that listen to new sessionId?
// for now decrypt sync
try {
val result = session.decryptEvent(event.root, event.root.roomId + UUID.randomUUID().toString())
val result = session.cryptoService().decryptEvent(event.root, event.root.roomId + UUID.randomUUID().toString())
event.root.mxDecryptionResult = OlmDecryptionResult(
payload = result.clearEvent,
senderKey = result.senderCurve25519Key,

View File

@ -211,7 +211,7 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes
activeSessionHolder.getSafeActiveSession()?.let { session ->
userId = session.myUserId
deviceId = session.sessionParams.credentials.deviceId ?: "undefined"
olmVersion = session.getCryptoVersion(context, true)
olmVersion = session.cryptoService().getCryptoVersion(context, true)
}
if (!mIsCancelled) {

View File

@ -148,7 +148,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
// ok, let's find or create the DM room
_viewEvents.post(RoomMemberProfileViewEvents.StartVerification(
userId = state.userId,
canCrossSign = session.getCrossSigningService().canCrossSign()
canCrossSign = session.cryptoService().crossSigningService().canCrossSign()
))
}
}

View File

@ -100,7 +100,7 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(@Assisted priva
}
private fun manuallyVerify(action: DeviceListAction.ManuallyVerify) {
session.getVerificationService().beginKeyVerification(VerificationMethod.SAS, userId, action.deviceId, null)?.let { txID ->
session.cryptoService().verificationService().beginKeyVerification(VerificationMethod.SAS, userId, action.deviceId, null)?.let { txID ->
_viewEvents.post(DeviceListBottomSheetViewEvents.Verify(userId, txID))
}
}

View File

@ -95,7 +95,7 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
room.rx().liveRoomMembers(roomMemberQueryParams)
.observeOn(AndroidSchedulers.mainThread())
.switchMap { membersSummary ->
session.getLiveCryptoDeviceInfo(membersSummary.map { it.userId })
session.cryptoService().getLiveCryptoDeviceInfo(membersSummary.map { it.userId })
.asObservable()
.doOnError { Timber.e(it) }
.map { deviceList ->
@ -104,7 +104,7 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
val allDeviceTrusted = it.value.fold(it.value.isNotEmpty()) { prev, next ->
prev && next.trustLevel?.isCrossSigningVerified().orFalse()
}
if (session.getCrossSigningService().getUserCrossSigningKeys(it.key)?.isTrusted().orFalse()) {
if (session.cryptoService().crossSigningService().getUserCrossSigningKeys(it.key)?.isTrusted().orFalse()) {
if (allDeviceTrusted) RoomEncryptionTrustLevel.Trusted else RoomEncryptionTrustLevel.Warning
} else {
RoomEncryptionTrustLevel.Default

View File

@ -77,7 +77,7 @@ class VectorSettingsHelpAboutFragment @Inject constructor(
// olm version
findPreference<VectorPreference>(VectorPreferences.SETTINGS_OLM_VERSION_PREFERENCE_KEY)!!
.summary = session.getCryptoVersion(requireContext(), false)
.summary = session.cryptoService().getCryptoVersion(requireContext(), false)
// copyright
findPreference<VectorPreference>(VectorPreferences.SETTINGS_COPYRIGHT_PREFERENCE_KEY)!!

View File

@ -37,7 +37,7 @@ class VectorSettingsLabsFragment @Inject constructor(
// val useCryptoPref = findPreference(VectorPreferences.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY) as SwitchPreference
// val cryptoIsEnabledPref = findPreference(VectorPreferences.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY)
if (session.isCryptoEnabled()) {
if (session.cryptoService().isCryptoEnabled()) {
// mLabsCategory.removePreference(useCryptoPref)
//
// cryptoIsEnabledPref.isEnabled = false

View File

@ -134,10 +134,10 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
private fun refreshXSigningStatus() {
if (vectorPreferences.developerMode()) {
val crossSigningKeys = session.getCrossSigningService().getMyCrossSigningKeys()
val crossSigningKeys = session.cryptoService().crossSigningService().getMyCrossSigningKeys()
val xSigningIsEnableInAccount = crossSigningKeys != null
val xSigningKeysAreTrusted = session.getCrossSigningService().checkUserTrust(session.myUserId).isVerified()
val xSigningKeyCanSign = session.getCrossSigningService().canCrossSign()
val xSigningKeysAreTrusted = session.cryptoService().crossSigningService().checkUserTrust(session.myUserId).isVerified()
val xSigningKeyCanSign = session.cryptoService().crossSigningService().canCrossSign()
if (xSigningKeyCanSign) {
mCrossSigningStatePreference.setIcon(R.drawable.ic_shield_trusted)
@ -412,10 +412,10 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
sendToUnverifiedDevicesPref.isChecked = false
sendToUnverifiedDevicesPref.isChecked = session.getGlobalBlacklistUnverifiedDevices()
sendToUnverifiedDevicesPref.isChecked = session.cryptoService().getGlobalBlacklistUnverifiedDevices()
sendToUnverifiedDevicesPref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
session.setGlobalBlacklistUnverifiedDevices(sendToUnverifiedDevicesPref.isChecked)
session.cryptoService().setGlobalBlacklistUnverifiedDevices(sendToUnverifiedDevicesPref.isChecked)
true
}
@ -426,7 +426,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
// ==============================================================================================================
private fun refreshMyDevice() {
session.getUserDevices(session.myUserId).map {
session.cryptoService().getUserDevices(session.myUserId).map {
DeviceInfo(
user_id = session.myUserId,
deviceId = it.deviceId,
@ -436,7 +436,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
refreshCryptographyPreference(it)
}
// TODO Move to a ViewModel...
session.getDevicesList(object : MatrixCallback<DevicesListResponse> {
session.cryptoService().getDevicesList(object : MatrixCallback<DevicesListResponse> {
override fun onSuccess(data: DevicesListResponse) {
if (isAdded) {
refreshCryptographyPreference(data.devices ?: emptyList())

View File

@ -57,8 +57,8 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(@Assisted privat
.execute {
val crossSigningKeys = it.invoke()?.getOrNull()
val xSigningIsEnableInAccount = crossSigningKeys != null
val xSigningKeysAreTrusted = session.getCrossSigningService().checkUserTrust(session.myUserId).isVerified()
val xSigningKeyCanSign = session.getCrossSigningService().canCrossSign()
val xSigningKeysAreTrusted = session.cryptoService().crossSigningService().checkUserTrust(session.myUserId).isVerified()
val xSigningKeyCanSign = session.cryptoService().crossSigningService().canCrossSign()
copy(
crossSigningInfo = crossSigningKeys,
xSigningIsEnableInAccount = xSigningIsEnableInAccount,
@ -97,7 +97,7 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(@Assisted privat
setState {
copy(isUploadingKeys = true)
}
session.getCrossSigningService().initializeCrossSigning(auth, object : MatrixCallback<Unit> {
session.cryptoService().crossSigningService().initializeCrossSigning(auth, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
_pendingSession = null

View File

@ -63,7 +63,7 @@ class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@As
setState {
copy(deviceInfo = Loading())
}
session.getDeviceInfo(deviceId, object : MatrixCallback<DeviceInfo> {
session.cryptoService().getDeviceInfo(deviceId, object : MatrixCallback<DeviceInfo> {
override fun onSuccess(data: DeviceInfo) {
setState {
copy(deviceInfo = Success(data))

View File

@ -74,7 +74,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
init {
refreshDevicesList()
session.getVerificationService().addListener(this)
session.cryptoService().verificationService().addListener(this)
session.rx().liveUserCryptoDevices(session.myUserId)
.execute {
@ -85,7 +85,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
}
override fun onCleared() {
session.getVerificationService().removeListener(this)
session.cryptoService().verificationService().removeListener(this)
super.onCleared()
}
@ -103,7 +103,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
private fun refreshDevicesList() {
if (!session.sessionParams.credentials.deviceId.isNullOrEmpty()) {
// display something asap
val localKnown = session.getUserDevices(session.myUserId).map {
val localKnown = session.cryptoService().getUserDevices(session.myUserId).map {
DeviceInfo(
user_id = session.myUserId,
deviceId = it.deviceId,
@ -118,7 +118,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
)
}
session.getDevicesList(object : MatrixCallback<DevicesListResponse> {
session.cryptoService().getDevicesList(object : MatrixCallback<DevicesListResponse> {
override fun onSuccess(data: DevicesListResponse) {
setState {
copy(
@ -141,16 +141,16 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
setState {
copy(
myDeviceId = session.sessionParams.credentials.deviceId ?: "",
cryptoDevices = Success(session.getUserDevices(session.myUserId))
cryptoDevices = Success(session.cryptoService().getUserDevices(session.myUserId))
)
}
// then force download
session.downloadKeys(listOf(session.myUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
session.cryptoService().downloadKeys(listOf(session.myUserId), true, object : MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>> {
override fun onSuccess(data: MXUsersDevicesMap<CryptoDeviceInfo>) {
setState {
copy(
cryptoDevices = Success(session.getUserDevices(session.myUserId))
cryptoDevices = Success(session.cryptoService().getUserDevices(session.myUserId))
)
}
}
@ -172,7 +172,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
}
private fun handleVerify(action: DevicesAction.VerifyMyDevice) {
val txID = session.getVerificationService().requestKeyVerification(supportedVerificationMethods, session.myUserId, listOf(action.deviceId))
val txID = session.cryptoService().verificationService().requestKeyVerification(supportedVerificationMethods, session.myUserId, listOf(action.deviceId))
_viewEvents.post(DevicesViewEvents.ShowVerifyDevice(
session.myUserId,
txID.transactionId
@ -187,7 +187,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
}
private fun handleRename(action: DevicesAction.Rename) {
session.setDeviceName(action.deviceId, action.newName, object : MatrixCallback<Unit> {
session.cryptoService().setDeviceName(action.deviceId, action.newName, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
setState {
copy(
@ -222,7 +222,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
)
}
session.deleteDevice(deviceId, object : MatrixCallback<Unit> {
session.cryptoService().deleteDevice(deviceId, object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) {
var isPasswordRequestFound = false
@ -284,7 +284,7 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
)
}
session.deleteDeviceWithUserPassword(currentDeviceId, _currentSession, action.password, object : MatrixCallback<Unit> {
session.cryptoService().deleteDeviceWithUserPassword(currentDeviceId, _currentSession, action.password, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
_currentDeviceId = null
_currentSession = null

View File

@ -30,36 +30,36 @@ class SignOutViewModel @Inject constructor(private val session: Session) : ViewM
var keysBackupState = MutableLiveData<KeysBackupState>()
init {
session.getKeysBackupService().addListener(this)
session.cryptoService().keysBackupService().addListener(this)
keysBackupState.value = session.getKeysBackupService().state
keysBackupState.value = session.cryptoService().keysBackupService().state
}
/**
* Safe way to get the current KeysBackup version
*/
fun getCurrentBackupVersion(): String {
return session.getKeysBackupService().currentBackupVersion ?: ""
return session.cryptoService().keysBackupService().currentBackupVersion ?: ""
}
/**
* Safe way to get the number of keys to backup
*/
fun getNumberOfKeysToBackup(): Int {
return session.inboundGroupSessionsCount(false)
return session.cryptoService().inboundGroupSessionsCount(false)
}
/**
* Safe way to tell if there are more keys on the server
*/
fun canRestoreKeys(): Boolean {
return session.getKeysBackupService().canRestoreKeys()
return session.cryptoService().keysBackupService().canRestoreKeys()
}
override fun onCleared() {
super.onCleared()
session.getKeysBackupService().removeListener(this)
session.cryptoService().keysBackupService().removeListener(this)
}
override fun onStateChange(newState: KeysBackupState) {
@ -68,7 +68,7 @@ class SignOutViewModel @Inject constructor(private val session: Session) : ViewM
fun refreshRemoteStateIfNeeded() {
if (keysBackupState.value == KeysBackupState.Disabled) {
session.getKeysBackupService().checkAndStartKeysBackup()
session.cryptoService().keysBackupService().checkAndStartKeysBackup()
}
}
}