Fix test compilation

This commit is contained in:
valere 2022-12-13 11:50:06 +01:00
parent 3db82e629b
commit d0807b9239
15 changed files with 108 additions and 214 deletions

View file

@ -83,7 +83,7 @@ class XSigningTest : InstrumentedTest {
} }
@Test @Test
fun test_CrossSigningCheckBobSeesTheKeys() = runCryptoTest(context()) { cryptoTestHelper, testHelper -> fun test_CrossSigningCheckBobSeesTheKeys() = runCryptoTest(context()) { cryptoTestHelper, _ ->
val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceAndBobInARoom() val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceAndBobInARoom()
val aliceSession = cryptoTestData.firstSession val aliceSession = cryptoTestData.firstSession

View file

@ -169,13 +169,13 @@ class KeyShareTests : InstrumentedTest {
aliceSession.cryptoService().setDeviceVerification( aliceSession.cryptoService().setDeviceVerification(
DeviceTrustLevel(crossSigningVerified = false, locallyVerified = true), aliceSession.myUserId, DeviceTrustLevel(crossSigningVerified = false, locallyVerified = true), aliceSession.myUserId,
aliceSession2.sessionParams.deviceId ?: "" aliceSession2.sessionParams.deviceId
) )
// We only accept forwards from trusted session, so we need to trust on other side to // We only accept forwards from trusted session, so we need to trust on other side to
aliceSession2.cryptoService().setDeviceVerification( aliceSession2.cryptoService().setDeviceVerification(
DeviceTrustLevel(crossSigningVerified = false, locallyVerified = true), aliceSession.myUserId, DeviceTrustLevel(crossSigningVerified = false, locallyVerified = true), aliceSession.myUserId,
aliceSession.sessionParams.deviceId ?: "" aliceSession.sessionParams.deviceId
) )
aliceSession.cryptoService().deviceWithIdentityKey( aliceSession.cryptoService().deviceWithIdentityKey(
@ -335,10 +335,10 @@ class KeyShareTests : InstrumentedTest {
// Mark the new session as verified // Mark the new session as verified
aliceSession.cryptoService() aliceSession.cryptoService()
.verificationService() .verificationService()
.markedLocallyAsManuallyVerified(aliceNewSession.myUserId, aliceNewSession.sessionParams.deviceId!!) .markedLocallyAsManuallyVerified(aliceNewSession.myUserId, aliceNewSession.sessionParams.deviceId)
aliceNewSession.cryptoService() aliceNewSession.cryptoService()
.verificationService() .verificationService()
.markedLocallyAsManuallyVerified(aliceSession.myUserId, aliceSession.sessionParams.deviceId!!) .markedLocallyAsManuallyVerified(aliceSession.myUserId, aliceSession.sessionParams.deviceId)
// Let's now try to request // Let's now try to request
aliceNewSession.cryptoService().reRequestRoomKeyForEvent(sentEvents.first().root) aliceNewSession.cryptoService().reRequestRoomKeyForEvent(sentEvents.first().root)
@ -420,10 +420,10 @@ class KeyShareTests : InstrumentedTest {
// Mark the new session as verified // Mark the new session as verified
aliceSession.cryptoService() aliceSession.cryptoService()
.verificationService() .verificationService()
.markedLocallyAsManuallyVerified(aliceNewSession.myUserId, aliceNewSession.sessionParams.deviceId!!) .markedLocallyAsManuallyVerified(aliceNewSession.myUserId, aliceNewSession.sessionParams.deviceId)
aliceNewSession.cryptoService() aliceNewSession.cryptoService()
.verificationService() .verificationService()
.markedLocallyAsManuallyVerified(aliceSession.myUserId, aliceSession.sessionParams.deviceId!!) .markedLocallyAsManuallyVerified(aliceSession.myUserId, aliceSession.sessionParams.deviceId)
// /!\ Stop initial alice session syncing so that it can't reply // /!\ Stop initial alice session syncing so that it can't reply
aliceSession.cryptoService().enableKeyGossiping(false) aliceSession.cryptoService().enableKeyGossiping(false)

View file

@ -16,19 +16,13 @@
package org.matrix.android.sdk.internal.crypto.verification package org.matrix.android.sdk.internal.crypto.verification
import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.common.CommonTestHelper import org.matrix.android.sdk.common.CommonTestHelper
import org.matrix.android.sdk.common.CryptoTestData import org.matrix.android.sdk.common.CryptoTestData
import org.matrix.android.sdk.common.CryptoTestHelper
import timber.log.Timber
import java.util.concurrent.CountDownLatch
class SasVerificationTestHelper(private val testHelper: CommonTestHelper, private val cryptoTestHelper: CryptoTestHelper) { class SasVerificationTestHelper(private val testHelper: CommonTestHelper) {
suspend fun requestVerificationAndWaitForReadyState(cryptoTestData: CryptoTestData, supportedMethods: List<VerificationMethod>): String { suspend fun requestVerificationAndWaitForReadyState(cryptoTestData: CryptoTestData, supportedMethods: List<VerificationMethod>): String {
val aliceSession = cryptoTestData.firstSession val aliceSession = cryptoTestData.firstSession
val bobSession = cryptoTestData.secondSession!! val bobSession = cryptoTestData.secondSession!!
@ -36,93 +30,63 @@ class SasVerificationTestHelper(private val testHelper: CommonTestHelper, privat
val aliceVerificationService = aliceSession.cryptoService().verificationService() val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession.cryptoService().verificationService() val bobVerificationService = bobSession.cryptoService().verificationService()
var bobReadyPendingVerificationRequest: PendingVerificationRequest? = null val bobUserId = bobSession.myUserId
// Step 1: Alice starts a verification request
val transactionId = aliceVerificationService.requestKeyVerificationInDMs(
supportedMethods, bobUserId, cryptoTestData.roomId
)
.transactionId
val latch = CountDownLatch(2) testHelper.retryPeriodically {
val aliceListener = object : VerificationService.Listener { val incomingRequest = bobVerificationService.getExistingVerificationRequest(aliceSession.myUserId, transactionId)
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { if (incomingRequest != null) {
// Step 4: Alice receive the ready request
Timber.v("Alice request updated: $pr")
if (pr.state == EVerificationState.Ready) {
latch.countDown()
}
}
}
// aliceVerificationService.addListener(aliceListener)
val bobListener = object : VerificationService.Listener {
override fun verificationRequestCreated(pr: PendingVerificationRequest) {
// Step 2: Bob accepts the verification request
Timber.v("Bob accepts the verification request")
runBlocking {
bobVerificationService.readyPendingVerification( bobVerificationService.readyPendingVerification(
supportedMethods, supportedMethods,
aliceSession.myUserId, aliceSession.myUserId,
pr.transactionId incomingRequest.transactionId
) )
true
} else {
false
} }
} }
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { // wait for alice to see the ready
// Step 3: Bob is ready testHelper.retryPeriodically {
Timber.v("Bob request updated $pr") val pendingRequest = aliceVerificationService.getExistingVerificationRequest(bobUserId, transactionId)
if (pr.state == EVerificationState.Ready) { pendingRequest?.state == EVerificationState.Ready
bobReadyPendingVerificationRequest = pr
latch.countDown()
} }
}
}
// bobVerificationService.addListener(bobListener)
val bobUserId = bobSession.myUserId return transactionId
// Step 1: Alice starts a verification request
aliceVerificationService.requestKeyVerificationInDMs(supportedMethods, bobUserId, cryptoTestData.roomId)
testHelper.await(latch)
// bobVerificationService.removeListener(bobListener)
// aliceVerificationService.removeListener(aliceListener)
return bobReadyPendingVerificationRequest?.transactionId!!
} }
suspend fun requestSelfKeyAndWaitForReadyState(session1: Session, session2: Session, supportedMethods: List<VerificationMethod>): String { suspend fun requestSelfKeyAndWaitForReadyState(session1: Session, session2: Session, supportedMethods: List<VerificationMethod>): String {
val session1VerificationService = session1.cryptoService().verificationService() val session1VerificationService = session1.cryptoService().verificationService()
val session2VerificationService = session2.cryptoService().verificationService() val session2VerificationService = session2.cryptoService().verificationService()
var bobReadyPendingVerificationRequest: PendingVerificationRequest? = null
val latch = CountDownLatch(2) val requestID = session1VerificationService.requestSelfKeyVerification(supportedMethods).transactionId
val aliceListener = object : VerificationService.Listener {
override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
if (pr.state == EVerificationState.Ready) {
latch.countDown()
}
}
}
// session1VerificationService.addListener(aliceListener)
val bobListener = object : VerificationService.Listener { val myUserId = session1.myUserId
override fun verificationRequestCreated(pr: PendingVerificationRequest) { testHelper.retryPeriodically {
runBlocking { val incomingRequest = session2VerificationService.getExistingVerificationRequest(myUserId, requestID)
if (incomingRequest != null) {
session2VerificationService.readyPendingVerification( session2VerificationService.readyPendingVerification(
supportedMethods, supportedMethods,
session1.myUserId, myUserId,
pr.transactionId incomingRequest.transactionId
) )
true
} else {
false
} }
} }
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { // wait for alice to see the ready
Timber.v("Bob request updated $pr") testHelper.retryPeriodically {
if (pr.state == EVerificationState.Ready) { val pendingRequest = session1VerificationService.getExistingVerificationRequest(myUserId, requestID)
bobReadyPendingVerificationRequest = pr pendingRequest?.state == EVerificationState.Ready
latch.countDown()
} }
}
}
// session2VerificationService.addListener(bobListener)
session1VerificationService.requestSelfKeyVerification(supportedMethods)
testHelper.await(latch) return requestID
// session2VerificationService.removeListener(bobListener)
// session1VerificationService.removeListener(aliceListener)
return bobReadyPendingVerificationRequest?.transactionId!!
} }
} }

View file

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.crypto.verification package org.matrix.android.sdk.internal.crypto.verification
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.runBlocking
import org.amshove.kluent.shouldBe import org.amshove.kluent.shouldBe
import org.junit.FixMethodOrder import org.junit.FixMethodOrder
import org.junit.Test import org.junit.Test
@ -25,12 +24,8 @@ import org.junit.runner.RunWith
import org.junit.runners.MethodSorters import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.common.CommonTestHelper.Companion.runCryptoTest import org.matrix.android.sdk.common.CommonTestHelper.Companion.runCryptoTest
import timber.log.Timber
import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@FixMethodOrder(MethodSorters.JVM) @FixMethodOrder(MethodSorters.JVM)
@ -159,58 +154,41 @@ class VerificationTest : InstrumentedTest {
val aliceVerificationService = aliceSession.cryptoService().verificationService() val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession.cryptoService().verificationService() val bobVerificationService = bobSession.cryptoService().verificationService()
var aliceReadyPendingVerificationRequest: PendingVerificationRequest? = null val transactionId = aliceVerificationService.requestKeyVerificationInDMs(
var bobReadyPendingVerificationRequest: PendingVerificationRequest? = null aliceSupportedMethods, bobSession.myUserId, cryptoTestData.roomId
)
.transactionId
val latch = CountDownLatch(2) testHelper.retryPeriodically {
val aliceListener = object : VerificationService.Listener { val incomingRequest = bobVerificationService.getExistingVerificationRequest(aliceSession.myUserId, transactionId)
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { if (incomingRequest != null) {
// Step 4: Alice receive the ready request
Timber.v("Alice is ready: ${pr.state}")
if (pr.state == EVerificationState.Ready) {
aliceReadyPendingVerificationRequest = pr
latch.countDown()
}
}
}
// aliceVerificationService.addListener(aliceListener)
val bobListener = object : VerificationService.Listener {
override fun verificationRequestCreated(pr: PendingVerificationRequest) {
// Step 2: Bob accepts the verification request
Timber.v("Bob accepts the verification request")
runBlocking {
bobVerificationService.readyPendingVerification( bobVerificationService.readyPendingVerification(
bobSupportedMethods, bobSupportedMethods,
aliceSession.myUserId, aliceSession.myUserId,
pr.transactionId incomingRequest.transactionId
) )
true
} else {
false
} }
} }
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { // wait for alice to see the ready
// Step 3: Bob is ready testHelper.retryPeriodically {
Timber.v("Bob is ready: ${pr.state}") val pendingRequest = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId, transactionId)
if (pr.state == EVerificationState.Ready) { pendingRequest?.state == EVerificationState.Ready
bobReadyPendingVerificationRequest = pr
latch.countDown()
} }
}
}
// bobVerificationService.addListener(bobListener)
val bobUserId = bobSession.myUserId val aliceReadyPendingVerificationRequest = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId, transactionId)!!
// Step 1: Alice starts a verification request val bobReadyPendingVerificationRequest = bobVerificationService.getExistingVerificationRequest(aliceSession.myUserId, transactionId)!!
aliceVerificationService.requestKeyVerificationInDMs(aliceSupportedMethods, bobUserId, cryptoTestData.roomId)
testHelper.await(latch)
aliceReadyPendingVerificationRequest!!.let { pr -> aliceReadyPendingVerificationRequest.let { pr ->
pr.isSasSupported shouldBe expectedResultForAlice.sasIsSupported pr.isSasSupported shouldBe expectedResultForAlice.sasIsSupported
pr.weShouldShowScanOption shouldBe expectedResultForAlice.otherCanShowQrCode pr.weShouldShowScanOption shouldBe expectedResultForAlice.otherCanShowQrCode
pr.weShouldDisplayQRCode shouldBe expectedResultForAlice.otherCanScanQrCode pr.weShouldDisplayQRCode shouldBe expectedResultForAlice.otherCanScanQrCode
} }
bobReadyPendingVerificationRequest!!.let { pr -> bobReadyPendingVerificationRequest.let { pr ->
pr.isSasSupported shouldBe expectedResultForBob.sasIsSupported pr.isSasSupported shouldBe expectedResultForBob.sasIsSupported
pr.weShouldShowScanOption shouldBe expectedResultForBob.otherCanShowQrCode pr.weShouldShowScanOption shouldBe expectedResultForBob.otherCanShowQrCode
pr.weShouldDisplayQRCode shouldBe expectedResultForBob.otherCanScanQrCode pr.weShouldDisplayQRCode shouldBe expectedResultForBob.otherCanScanQrCode

View file

@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto.verification.qrcode
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import org.amshove.kluent.shouldBe import org.amshove.kluent.shouldBe
import org.junit.FixMethodOrder import org.junit.FixMethodOrder
import org.junit.Ignore import org.junit.Ignore
@ -33,15 +32,12 @@ import org.matrix.android.sdk.api.auth.UserPasswordAuth
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
import org.matrix.android.sdk.api.session.crypto.verification.CancelCode import org.matrix.android.sdk.api.session.crypto.verification.CancelCode
import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
import org.matrix.android.sdk.api.session.crypto.verification.VerificationEvent import org.matrix.android.sdk.api.session.crypto.verification.VerificationEvent
import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.common.CommonTestHelper.Companion.runCryptoTest import org.matrix.android.sdk.common.CommonTestHelper.Companion.runCryptoTest
import org.matrix.android.sdk.common.CommonTestHelper.Companion.runSessionTest import org.matrix.android.sdk.common.CommonTestHelper.Companion.runSessionTest
import org.matrix.android.sdk.common.SessionTestParams import org.matrix.android.sdk.common.SessionTestParams
import org.matrix.android.sdk.common.TestConstants import org.matrix.android.sdk.common.TestConstants
import java.util.concurrent.CountDownLatch
import kotlin.coroutines.Continuation import kotlin.coroutines.Continuation
import kotlin.coroutines.resume import kotlin.coroutines.resume
@ -202,55 +198,41 @@ class VerificationTest : InstrumentedTest {
val aliceVerificationService = aliceSession.cryptoService().verificationService() val aliceVerificationService = aliceSession.cryptoService().verificationService()
val bobVerificationService = bobSession.cryptoService().verificationService() val bobVerificationService = bobSession.cryptoService().verificationService()
var aliceReadyPendingVerificationRequest: PendingVerificationRequest? = null val transactionId = aliceVerificationService.requestKeyVerificationInDMs(
var bobReadyPendingVerificationRequest: PendingVerificationRequest? = null aliceSupportedMethods, bobSession.myUserId, cryptoTestData.roomId
)
.transactionId
val latch = CountDownLatch(2) testHelper.retryPeriodically {
val aliceListener = object : VerificationService.Listener { val incomingRequest = bobVerificationService.getExistingVerificationRequest(aliceSession.myUserId, transactionId)
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { if (incomingRequest != null) {
// Step 4: Alice receive the ready request
if (pr.state == EVerificationState.Ready) {
aliceReadyPendingVerificationRequest = pr
latch.countDown()
}
}
}
// aliceVerificationService.addListener(aliceListener)
val bobListener = object : VerificationService.Listener {
override fun verificationRequestCreated(pr: PendingVerificationRequest) {
// Step 2: Bob accepts the verification request
runBlocking {
bobVerificationService.readyPendingVerification( bobVerificationService.readyPendingVerification(
bobSupportedMethods, bobSupportedMethods,
aliceSession.myUserId, aliceSession.myUserId,
pr.transactionId incomingRequest.transactionId
) )
true
} else {
false
} }
} }
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { // wait for alice to see the ready
// Step 3: Bob is ready testHelper.retryPeriodically {
if (pr.state == EVerificationState.Ready) { val pendingRequest = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId, transactionId)
bobReadyPendingVerificationRequest = pr pendingRequest?.state == EVerificationState.Ready
latch.countDown()
} }
}
}
// bobVerificationService.addListener(bobListener)
val bobUserId = bobSession.myUserId val aliceReadyPendingVerificationRequest = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId, transactionId)!!
// Step 1: Alice starts a verification request val bobReadyPendingVerificationRequest = bobVerificationService.getExistingVerificationRequest(aliceSession.myUserId, transactionId)!!
aliceVerificationService.requestKeyVerificationInDMs(aliceSupportedMethods, bobUserId, cryptoTestData.roomId)
testHelper.await(latch)
aliceReadyPendingVerificationRequest!!.let { pr -> aliceReadyPendingVerificationRequest.let { pr ->
pr.isSasSupported shouldBe expectedResultForAlice.sasIsSupported pr.isSasSupported shouldBe expectedResultForAlice.sasIsSupported
pr.weShouldShowScanOption shouldBe expectedResultForAlice.otherCanShowQrCode pr.weShouldShowScanOption shouldBe expectedResultForAlice.otherCanShowQrCode
pr.weShouldDisplayQRCode shouldBe expectedResultForAlice.otherCanScanQrCode pr.weShouldDisplayQRCode shouldBe expectedResultForAlice.otherCanScanQrCode
} }
bobReadyPendingVerificationRequest!!.let { pr -> bobReadyPendingVerificationRequest.let { pr ->
pr.isSasSupported shouldBe expectedResultForBob.sasIsSupported pr.isSasSupported shouldBe expectedResultForBob.sasIsSupported
pr.weShouldShowScanOption shouldBe expectedResultForBob.otherCanShowQrCode pr.weShouldShowScanOption shouldBe expectedResultForBob.otherCanShowQrCode
pr.weShouldDisplayQRCode shouldBe expectedResultForBob.otherCanScanQrCode pr.weShouldDisplayQRCode shouldBe expectedResultForBob.otherCanScanQrCode
@ -284,7 +266,7 @@ class VerificationTest : InstrumentedTest {
serviceOfVerifier.readyPendingVerification( serviceOfVerifier.readyPendingVerification(
verificationMethods, verificationMethods,
pr.otherUserId, pr.otherUserId,
pr.transactionId!!, pr.transactionId,
) )
job?.cancel() job?.cancel()
} }

View file

@ -63,7 +63,7 @@ class PreShareKeysTest : InstrumentedTest {
val aliceOutboundSessionInRoom = aliceCryptoStore.getCurrentOutboundGroupSessionForRoom(e2eRoomID)!!.outboundGroupSession.sessionIdentifier() val aliceOutboundSessionInRoom = aliceCryptoStore.getCurrentOutboundGroupSessionForRoom(e2eRoomID)!!.outboundGroupSession.sessionIdentifier()
val bobCryptoStore = (bobSession.cryptoService() as DefaultCryptoService).cryptoStoreForTesting val bobCryptoStore = (bobSession.cryptoService() as DefaultCryptoService).cryptoStoreForTesting
val aliceDeviceBobPov = bobCryptoStore.getUserDevice(aliceSession.myUserId, aliceSession.sessionParams.deviceId!!)!! val aliceDeviceBobPov = bobCryptoStore.getUserDevice(aliceSession.myUserId, aliceSession.sessionParams.deviceId)!!
val bobInboundForAlice = bobCryptoStore.getInboundGroupSession(aliceOutboundSessionInRoom, aliceDeviceBobPov.identityKey()!!) val bobInboundForAlice = bobCryptoStore.getInboundGroupSession(aliceOutboundSessionInRoom, aliceDeviceBobPov.identityKey()!!)
assertNotNull("Bob should have received and decrypted a room key event from alice", bobInboundForAlice) assertNotNull("Bob should have received and decrypted a room key event from alice", bobInboundForAlice)
assertEquals("Wrong room", e2eRoomID, bobInboundForAlice!!.roomId) assertEquals("Wrong room", e2eRoomID, bobInboundForAlice!!.roomId)

View file

@ -16,38 +16,12 @@
package org.matrix.android.sdk.internal.crypto.verification package org.matrix.android.sdk.internal.crypto.verification
import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.FixMethodOrder import org.junit.FixMethodOrder
import org.junit.Ignore import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.junit.runners.MethodSorters import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.api.session.crypto.verification.CancelCode
import org.matrix.android.sdk.api.session.crypto.verification.EVerificationState
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
import org.matrix.android.sdk.api.session.crypto.verification.SasTransactionState
import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction
import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.common.CommonTestHelper.Companion.runCryptoTest
import org.matrix.android.sdk.internal.crypto.model.rest.KeyVerificationCancel
import org.matrix.android.sdk.internal.crypto.model.rest.KeyVerificationStart
import org.matrix.android.sdk.internal.crypto.model.rest.toValue
import timber.log.Timber
import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)

View file

@ -21,7 +21,6 @@ import kotlinx.coroutines.channels.Channel
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.verification.CancelCode import org.matrix.android.sdk.api.session.crypto.verification.CancelCode
import org.matrix.android.sdk.api.session.crypto.verification.EmojiRepresentation import org.matrix.android.sdk.api.session.crypto.verification.EmojiRepresentation
import org.matrix.android.sdk.api.session.crypto.verification.SasMode
import org.matrix.android.sdk.api.session.crypto.verification.SasTransactionState import org.matrix.android.sdk.api.session.crypto.verification.SasTransactionState
import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction
import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction.Companion.KEY_AGREEMENT_V1 import org.matrix.android.sdk.api.session.crypto.verification.SasVerificationTransaction.Companion.KEY_AGREEMENT_V1

View file

@ -17,11 +17,13 @@
package org.matrix.android.sdk.internal.session package org.matrix.android.sdk.internal.session
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import timber.log.Timber
import java.io.File import java.io.File
class MigrateEAtoEROperation { class MigrateEAtoEROperation {
fun execute(cryptoRealm: RealmConfiguration, sessionFilesDir: File): File { fun execute(cryptoRealm: RealmConfiguration, sessionFilesDir: File): File {
Timber.v("Not used in kotlin crypto $cryptoRealm")
// no op in kotlinCrypto // no op in kotlinCrypto
return sessionFilesDir return sessionFilesDir
} }

View file

@ -35,10 +35,7 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.KEYBACKUP_SECRET_S
import org.matrix.android.sdk.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME import org.matrix.android.sdk.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME
import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME import org.matrix.android.sdk.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME
import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME import org.matrix.android.sdk.api.session.crypto.crosssigning.USER_SIGNING_KEY_SSSS_NAME
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.api.util.MatrixJsonParser import org.matrix.android.sdk.api.util.MatrixJsonParser
import org.matrix.android.sdk.api.util.awaitCallback
import timber.log.Timber import timber.log.Timber
/** /**

View file

@ -157,8 +157,7 @@ internal class RealmCryptoStore @Inject constructor(
// Check credentials // Check credentials
// The device id may not have been provided in credentials. // The device id may not have been provided in credentials.
// Check it only if provided, else trust the stored one. // Check it only if provided, else trust the stored one.
if (currentMetadata.userId != userId || if (currentMetadata.userId != userId || deviceId != currentMetadata.deviceId) {
(deviceId != null && deviceId != currentMetadata.deviceId)) {
Timber.w("## open() : Credentials do not match, close this store and delete data") Timber.w("## open() : Credentials do not match, close this store and delete data")
deleteAll = true deleteAll = true
currentMetadata = null currentMetadata = null

View file

@ -17,12 +17,11 @@
package im.vector.app.features.home.room.list.home package im.vector.app.features.home.room.list.home
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject import javax.inject.Inject
class RoomSummaryRoomListDiffCallback @Inject constructor( class RoomSummaryRoomListDiffCallback @Inject constructor(
vectorPreferences: VectorPreferences // vectorPreferences: VectorPreferences
) : DiffUtil.ItemCallback<RoomSummary>() { ) : DiffUtil.ItemCallback<RoomSummary>() {
override fun areItemsTheSame(oldItem: RoomSummary, newItem: RoomSummary): Boolean { override fun areItemsTheSame(oldItem: RoomSummary, newItem: RoomSummary): Boolean {

View file

@ -29,7 +29,7 @@ class DeleteNotificationSettingsAccountDataUseCase @Inject constructor(
) { ) {
suspend fun execute(session: Session) { suspend fun execute(session: Session) {
val deviceId = session.sessionParams.deviceId ?: return val deviceId = session.sessionParams.deviceId
if (getNotificationSettingsAccountDataUseCase.execute(session, deviceId)?.isSilenced != null) { if (getNotificationSettingsAccountDataUseCase.execute(session, deviceId)?.isSilenced != null) {
val emptyNotificationSettingsContent = LocalNotificationSettingsContent( val emptyNotificationSettingsContent = LocalNotificationSettingsContent(
isSilenced = null isSilenced = null

View file

@ -43,7 +43,7 @@ class UpdateNotificationSettingsAccountDataUseCase @Inject constructor(
} }
private suspend fun setCurrentNotificationStatus(session: Session) { private suspend fun setCurrentNotificationStatus(session: Session) {
val deviceId = session.sessionParams.deviceId ?: return val deviceId = session.sessionParams.deviceId
val areNotificationsSilenced = !vectorPreferences.areNotificationEnabledForDevice() val areNotificationsSilenced = !vectorPreferences.areNotificationEnabledForDevice()
val isSilencedAccountData = getNotificationSettingsAccountDataUseCase.execute(session, deviceId)?.isSilenced val isSilencedAccountData = getNotificationSettingsAccountDataUseCase.execute(session, deviceId)?.isSilenced
if (areNotificationsSilenced != isSilencedAccountData) { if (areNotificationsSilenced != isSilencedAccountData) {

View file

@ -35,7 +35,7 @@ class ToggleNotificationsForCurrentSessionUseCase @Inject constructor(
suspend fun execute(enabled: Boolean) { suspend fun execute(enabled: Boolean) {
val session = activeSessionHolder.getSafeActiveSession() ?: return val session = activeSessionHolder.getSafeActiveSession() ?: return
val deviceId = session.sessionParams.deviceId ?: return val deviceId = session.sessionParams.deviceId
if (unifiedPushHelper.isBackgroundSync()) { if (unifiedPushHelper.isBackgroundSync()) {
Timber.d("background sync is enabled, setting account data event") Timber.d("background sync is enabled, setting account data event")