Add more logs on verif

This commit is contained in:
ganfra 2022-05-20 11:21:51 +02:00
parent 42e5dcd50a
commit 21ef138e97
4 changed files with 65 additions and 21 deletions

View file

@ -55,6 +55,7 @@ import org.matrix.android.sdk.common.CommonTestHelper
import org.matrix.android.sdk.common.CryptoTestHelper import org.matrix.android.sdk.common.CryptoTestHelper
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 org.matrix.android.sdk.internal.crypto.verification.SasVerificationTestHelper
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
@RunWith(JUnit4::class) @RunWith(JUnit4::class)
@ -610,7 +611,6 @@ class E2eeSanityTests : InstrumentedTest {
fun testSelfInteractiveVerificationAndGossip() { fun testSelfInteractiveVerificationAndGossip() {
val testHelper = CommonTestHelper(context()) val testHelper = CommonTestHelper(context())
val cryptoTestHelper = CryptoTestHelper(testHelper) val cryptoTestHelper = CryptoTestHelper(testHelper)
val aliceSession = testHelper.createAccount("alice", SessionTestParams(true)) val aliceSession = testHelper.createAccount("alice", SessionTestParams(true))
cryptoTestHelper.bootstrapSecurity(aliceSession) cryptoTestHelper.bootstrapSecurity(aliceSession)
@ -618,18 +618,18 @@ class E2eeSanityTests : InstrumentedTest {
val aliceNewSession = testHelper.logIntoAccount(aliceSession.myUserId, SessionTestParams(true)) val aliceNewSession = testHelper.logIntoAccount(aliceSession.myUserId, SessionTestParams(true))
val transactionId = SasVerificationTestHelper(testHelper, cryptoTestHelper).requestSelfKeyAndWaitForReadyState(
aliceSession,
aliceNewSession,
listOf(VerificationMethod.SAS)
)
val oldCompleteLatch = CountDownLatch(1) val oldCompleteLatch = CountDownLatch(1)
lateinit var oldCode: String lateinit var oldCode: String
aliceSession.cryptoService().verificationService().addListener(object : VerificationService.Listener { aliceSession.cryptoService().verificationService().addListener(object : VerificationService.Listener {
override fun verificationRequestUpdated(pr: PendingVerificationRequest) { override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
val readyInfo = pr.readyInfo ?: return Log.d("##TEST", "existingPov: $pr")
testHelper.runBlockingTest {
aliceSession.cryptoService().verificationService().beginDeviceVerification(
aliceSession.myUserId,
readyInfo.fromDevice
)
}
} }
override fun transactionUpdated(tx: VerificationTransaction) { override fun transactionUpdated(tx: VerificationTransaction) {
@ -656,15 +656,8 @@ class E2eeSanityTests : InstrumentedTest {
lateinit var newCode: String lateinit var newCode: String
aliceNewSession.cryptoService().verificationService().addListener(object : VerificationService.Listener { aliceNewSession.cryptoService().verificationService().addListener(object : VerificationService.Listener {
override fun verificationRequestCreated(pr: PendingVerificationRequest) { override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
// let's ready Log.d("##TEST", "newPov: $pr")
testHelper.runBlockingTest {
aliceNewSession.cryptoService().verificationService().readyPendingVerification(
listOf(VerificationMethod.SAS, VerificationMethod.QR_CODE_SCAN, VerificationMethod.QR_CODE_SHOW),
aliceSession.myUserId,
pr.transactionId!!
)
}
} }
var matchOnce = true var matchOnce = true
@ -689,11 +682,8 @@ class E2eeSanityTests : InstrumentedTest {
} }
}) })
// initiate self verification
testHelper.runBlockingTest { testHelper.runBlockingTest {
aliceSession.cryptoService().verificationService().requestSelfKeyVerification( aliceSession.cryptoService().verificationService().beginKeyVerification(VerificationMethod.SAS, aliceNewSession.myUserId, transactionId)
listOf(VerificationMethod.SAS, VerificationMethod.QR_CODE_SCAN, VerificationMethod.QR_CODE_SHOW)
)
} }
testHelper.await(oldCompleteLatch) testHelper.await(oldCompleteLatch)
testHelper.await(newCompleteLatch) testHelper.await(newCompleteLatch)

View file

@ -16,6 +16,7 @@
package org.matrix.android.sdk.internal.crypto.verification package org.matrix.android.sdk.internal.crypto.verification
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest 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.api.session.crypto.verification.VerificationService
@ -83,4 +84,49 @@ class SasVerificationTestHelper(private val testHelper: CommonTestHelper, privat
aliceVerificationService.removeListener(aliceListener) aliceVerificationService.removeListener(aliceListener)
return bobReadyPendingVerificationRequest?.transactionId!! return bobReadyPendingVerificationRequest?.transactionId!!
} }
fun requestSelfKeyAndWaitForReadyState(session1: Session, session2: Session, supportedMethods: List<VerificationMethod>): String {
val session1VerificationService = session1.cryptoService().verificationService()
val session2VerificationService = session2.cryptoService().verificationService()
var bobReadyPendingVerificationRequest: PendingVerificationRequest? = null
val latch = CountDownLatch(2)
val aliceListener = object : VerificationService.Listener {
override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
if (pr.isReady) {
latch.countDown()
}
}
}
session1VerificationService.addListener(aliceListener)
val bobListener = object : VerificationService.Listener {
override fun verificationRequestCreated(pr: PendingVerificationRequest) {
testHelper.runBlockingTest {
session2VerificationService.readyPendingVerification(
supportedMethods,
session1.myUserId,
pr.transactionId!!
)
}
}
override fun verificationRequestUpdated(pr: PendingVerificationRequest) {
Timber.v("Bob request updated $pr")
if (pr.isReady) {
bobReadyPendingVerificationRequest = pr
latch.countDown()
}
}
}
session2VerificationService.addListener(bobListener)
testHelper.runBlockingTest {
session1VerificationService.requestSelfKeyVerification(supportedMethods)
}
testHelper.await(latch)
session2VerificationService.removeListener(bobListener)
session1VerificationService.removeListener(aliceListener)
return bobReadyPendingVerificationRequest?.transactionId!!
}
} }

View file

@ -211,4 +211,8 @@ internal class QrCodeVerification(
return return
} }
override fun toString(): String {
return "QrCodeVerification(qrCodeText=$qrCodeText, state=$state, transactionId='$transactionId', otherUserId='$otherUserId', otherDeviceId=$otherDeviceId, isIncoming=$isIncoming)"
}
} }

View file

@ -233,4 +233,8 @@ internal class SasVerification(
return return
} }
override fun toString(): String {
return "SasVerification(otherUserId='$otherUserId', otherDeviceId=$otherDeviceId, isIncoming=$isIncoming, state=$state, transactionId='$transactionId')"
}
} }