mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Refactored Verification Classes
This commit is contained in:
parent
bb5179140c
commit
d0addc4c4f
33 changed files with 350 additions and 339 deletions
|
@ -55,10 +55,10 @@ class SASTest : InstrumentedTest {
|
|||
val bobSasMgr = bobSession!!.getSasVerificationService()
|
||||
|
||||
val bobTxCreatedLatch = CountDownLatch(1)
|
||||
val bobListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val bobListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
bobTxCreatedLatch.countDown()
|
||||
}
|
||||
|
||||
|
@ -78,26 +78,26 @@ class SASTest : InstrumentedTest {
|
|||
val bobKeyTx = bobSasMgr.getExistingTransaction(aliceSession.myUserId, txID)
|
||||
|
||||
assertNotNull("Bob should have started verif transaction", bobKeyTx)
|
||||
assertTrue(bobKeyTx is SASVerificationTransaction)
|
||||
assertTrue(bobKeyTx is SASDefaultVerificationTransaction)
|
||||
assertNotNull("Bob should have starting a SAS transaction", bobKeyTx)
|
||||
assertTrue(aliceKeyTx is SASVerificationTransaction)
|
||||
assertTrue(aliceKeyTx is SASDefaultVerificationTransaction)
|
||||
assertEquals("Alice and Bob have same transaction id", aliceKeyTx!!.transactionId, bobKeyTx!!.transactionId)
|
||||
|
||||
val aliceSasTx = aliceKeyTx as SASVerificationTransaction?
|
||||
val bobSasTx = bobKeyTx as SASVerificationTransaction?
|
||||
val aliceSasTx = aliceKeyTx as SASDefaultVerificationTransaction?
|
||||
val bobSasTx = bobKeyTx as SASDefaultVerificationTransaction?
|
||||
|
||||
assertEquals("Alice state should be started", SasVerificationTxState.Started, aliceSasTx!!.state)
|
||||
assertEquals("Bob state should be started by alice", SasVerificationTxState.OnStarted, bobSasTx!!.state)
|
||||
assertEquals("Alice state should be started", VerificationTxState.Started, aliceSasTx!!.state)
|
||||
assertEquals("Bob state should be started by alice", VerificationTxState.OnStarted, bobSasTx!!.state)
|
||||
|
||||
// Let's cancel from alice side
|
||||
val cancelLatch = CountDownLatch(1)
|
||||
|
||||
val bobListener2 = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val bobListener2 = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if (tx.transactionId == txID) {
|
||||
if ((tx as SASVerificationTransaction).state === SasVerificationTxState.OnCancelled) {
|
||||
if ((tx as SASDefaultVerificationTransaction).state === VerificationTxState.OnCancelled) {
|
||||
cancelLatch.countDown()
|
||||
}
|
||||
}
|
||||
|
@ -111,9 +111,9 @@ class SASTest : InstrumentedTest {
|
|||
mTestHelper.await(cancelLatch)
|
||||
|
||||
assertEquals("Should be cancelled on alice side",
|
||||
SasVerificationTxState.Cancelled, aliceSasTx.state)
|
||||
VerificationTxState.Cancelled, aliceSasTx.state)
|
||||
assertEquals("Should be cancelled on bob side",
|
||||
SasVerificationTxState.OnCancelled, bobSasTx.state)
|
||||
VerificationTxState.OnCancelled, bobSasTx.state)
|
||||
|
||||
assertEquals("Should be User cancelled on alice side",
|
||||
CancelCode.User, aliceSasTx.cancelledReason)
|
||||
|
@ -139,10 +139,10 @@ class SASTest : InstrumentedTest {
|
|||
var cancelReason: String? = null
|
||||
val cancelLatch = CountDownLatch(1)
|
||||
|
||||
val bobListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val bobListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if (tx.transactionId == tid && tx.cancelledReason != null) {
|
||||
cancelReason = tx.cancelledReason?.humanReadable
|
||||
cancelLatch.countDown()
|
||||
|
@ -168,10 +168,10 @@ class SASTest : InstrumentedTest {
|
|||
val aliceUserID = aliceSession.myUserId
|
||||
val aliceDevice = aliceSession.getMyDevice().deviceId
|
||||
|
||||
val aliceListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val aliceListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if ((tx as IncomingSasVerificationTransaction).uxState === IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT) {
|
||||
(tx as IncomingSasVerificationTransaction).performAccept()
|
||||
}
|
||||
|
@ -268,10 +268,10 @@ class SASTest : InstrumentedTest {
|
|||
aliceUserID: String?,
|
||||
aliceDevice: String?,
|
||||
tid: String,
|
||||
protocols: List<String> = SASVerificationTransaction.KNOWN_AGREEMENT_PROTOCOLS,
|
||||
hashes: List<String> = SASVerificationTransaction.KNOWN_HASHES,
|
||||
mac: List<String> = SASVerificationTransaction.KNOWN_MACS,
|
||||
codes: List<String> = SASVerificationTransaction.KNOWN_SHORT_CODES) {
|
||||
protocols: List<String> = SASDefaultVerificationTransaction.KNOWN_AGREEMENT_PROTOCOLS,
|
||||
hashes: List<String> = SASDefaultVerificationTransaction.KNOWN_HASHES,
|
||||
mac: List<String> = SASDefaultVerificationTransaction.KNOWN_MACS,
|
||||
codes: List<String> = SASDefaultVerificationTransaction.KNOWN_SHORT_CODES) {
|
||||
val startMessage = KeyVerificationStart(
|
||||
fromDevice = bobSession.getMyDevice().deviceId,
|
||||
method = VerificationMethod.SAS.toValue(),
|
||||
|
@ -307,15 +307,15 @@ class SASTest : InstrumentedTest {
|
|||
|
||||
val aliceCreatedLatch = CountDownLatch(2)
|
||||
val aliceCancelledLatch = CountDownLatch(2)
|
||||
val createdTx = ArrayList<SASVerificationTransaction>()
|
||||
val aliceListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {
|
||||
createdTx.add(tx as SASVerificationTransaction)
|
||||
val createdTx = ArrayList<SASDefaultVerificationTransaction>()
|
||||
val aliceListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {
|
||||
createdTx.add(tx as SASDefaultVerificationTransaction)
|
||||
aliceCreatedLatch.countDown()
|
||||
}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
if ((tx as SASVerificationTransaction).state === SasVerificationTxState.OnCancelled) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if ((tx as SASDefaultVerificationTransaction).state === VerificationTxState.OnCancelled) {
|
||||
aliceCancelledLatch.countDown()
|
||||
}
|
||||
}
|
||||
|
@ -352,14 +352,14 @@ class SASTest : InstrumentedTest {
|
|||
var startReq: KeyVerificationStart? = null
|
||||
|
||||
val aliceAcceptedLatch = CountDownLatch(1)
|
||||
val aliceListener = object : SasVerificationService.SasVerificationListener {
|
||||
val aliceListener = object : VerificationService.VerificationListener {
|
||||
override fun markedAsManuallyVerified(userId: String, deviceId: String) {}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
if ((tx as SASVerificationTransaction).state === SasVerificationTxState.OnAccepted) {
|
||||
val at = tx as SASVerificationTransaction
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if ((tx as SASDefaultVerificationTransaction).state === VerificationTxState.OnAccepted) {
|
||||
val at = tx as SASDefaultVerificationTransaction
|
||||
accepted = at.accepted as? KeyVerificationAccept
|
||||
startReq = at.startReq as? KeyVerificationStart
|
||||
aliceAcceptedLatch.countDown()
|
||||
|
@ -368,10 +368,10 @@ class SASTest : InstrumentedTest {
|
|||
}
|
||||
aliceSasMgr.addListener(aliceListener)
|
||||
|
||||
val bobListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val bobListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if ((tx as IncomingSasVerificationTransaction).uxState === IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT) {
|
||||
val at = tx as IncomingSasVerificationTransaction
|
||||
at.performAccept()
|
||||
|
@ -413,10 +413,10 @@ class SASTest : InstrumentedTest {
|
|||
val bobSasMgr = bobSession!!.getSasVerificationService()
|
||||
|
||||
val aliceSASLatch = CountDownLatch(1)
|
||||
val aliceListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val aliceListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
val uxState = (tx as OutgoingSasVerificationRequest).uxState
|
||||
when (uxState) {
|
||||
OutgoingSasVerificationRequest.UxState.SHOW_SAS -> {
|
||||
|
@ -431,10 +431,10 @@ class SASTest : InstrumentedTest {
|
|||
aliceSasMgr.addListener(aliceListener)
|
||||
|
||||
val bobSASLatch = CountDownLatch(1)
|
||||
val bobListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val bobListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
val uxState = (tx as IncomingSasVerificationTransaction).uxState
|
||||
when (uxState) {
|
||||
IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT -> {
|
||||
|
@ -457,8 +457,8 @@ class SASTest : InstrumentedTest {
|
|||
mTestHelper.await(aliceSASLatch)
|
||||
mTestHelper.await(bobSASLatch)
|
||||
|
||||
val aliceTx = aliceSasMgr.getExistingTransaction(bobUserId, verificationSAS!!) as SASVerificationTransaction
|
||||
val bobTx = bobSasMgr.getExistingTransaction(aliceSession.myUserId, verificationSAS) as SASVerificationTransaction
|
||||
val aliceTx = aliceSasMgr.getExistingTransaction(bobUserId, verificationSAS!!) as SASDefaultVerificationTransaction
|
||||
val bobTx = bobSasMgr.getExistingTransaction(aliceSession.myUserId, verificationSAS) as SASDefaultVerificationTransaction
|
||||
|
||||
assertEquals("Should have same SAS", aliceTx.getShortCodeRepresentation(SasMode.DECIMAL),
|
||||
bobTx.getShortCodeRepresentation(SasMode.DECIMAL))
|
||||
|
@ -477,10 +477,10 @@ class SASTest : InstrumentedTest {
|
|||
val bobSasMgr = bobSession!!.getSasVerificationService()
|
||||
|
||||
val aliceSASLatch = CountDownLatch(1)
|
||||
val aliceListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val aliceListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
val uxState = (tx as OutgoingSasVerificationRequest).uxState
|
||||
when (uxState) {
|
||||
OutgoingSasVerificationRequest.UxState.SHOW_SAS -> {
|
||||
|
@ -498,10 +498,10 @@ class SASTest : InstrumentedTest {
|
|||
aliceSasMgr.addListener(aliceListener)
|
||||
|
||||
val bobSASLatch = CountDownLatch(1)
|
||||
val bobListener = object : SasVerificationService.SasVerificationListener {
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
val bobListener = object : VerificationService.VerificationListener {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
val uxState = (tx as IncomingSasVerificationTransaction).uxState
|
||||
when (uxState) {
|
||||
IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT -> {
|
||||
|
|
|
@ -23,7 +23,7 @@ import im.vector.matrix.android.api.listeners.ProgressListener
|
|||
import im.vector.matrix.android.api.session.crypto.crosssigning.CrossSigningService
|
||||
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService
|
||||
import im.vector.matrix.android.api.session.crypto.keyshare.RoomKeysRequestListener
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.events.model.Content
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult
|
||||
|
@ -50,7 +50,7 @@ interface CryptoService {
|
|||
|
||||
fun isCryptoEnabled(): Boolean
|
||||
|
||||
fun getSasVerificationService(): SasVerificationService
|
||||
fun getSasVerificationService(): VerificationService
|
||||
|
||||
fun getCrossSigningService(): CrossSigningService
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.api.session.crypto.sas
|
||||
|
||||
interface IncomingSasVerificationTransaction {
|
||||
interface IncomingSasVerificationTransaction : SasVerificationTransaction {
|
||||
val uxState: UxState
|
||||
|
||||
fun performAccept()
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.api.session.crypto.sas
|
||||
|
||||
interface OutgoingSasVerificationRequest {
|
||||
interface OutgoingSasVerificationRequest : SasVerificationTransaction {
|
||||
val uxState: UxState
|
||||
|
||||
enum class UxState {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package im.vector.matrix.android.api.session.crypto.sas
|
||||
|
||||
interface QRVerificationTransaction : VerificationTransaction {
|
||||
|
||||
fun userHasScannedRemoteQrCode(scannedData: String)
|
||||
|
||||
}
|
|
@ -16,18 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.api.session.crypto.sas
|
||||
|
||||
interface SasVerificationTransaction {
|
||||
var state: SasVerificationTxState
|
||||
|
||||
val cancelledReason: CancelCode?
|
||||
|
||||
val transactionId: String
|
||||
|
||||
val otherUserId: String
|
||||
|
||||
var otherDeviceId: String?
|
||||
|
||||
val isIncoming: Boolean
|
||||
interface SasVerificationTransaction : VerificationTransaction {
|
||||
|
||||
fun supportsEmoji(): Boolean
|
||||
|
||||
|
@ -37,11 +26,6 @@ interface SasVerificationTransaction {
|
|||
|
||||
fun getDecimalCodeRepresentation(): String
|
||||
|
||||
/**
|
||||
* User wants to cancel the transaction
|
||||
*/
|
||||
fun cancel()
|
||||
|
||||
/**
|
||||
* To be called by the client when the user has verified that
|
||||
* both short codes do match
|
||||
|
@ -50,8 +34,4 @@ interface SasVerificationTransaction {
|
|||
|
||||
fun shortCodeDoesNotMatch()
|
||||
|
||||
fun isToDeviceTransport(): Boolean
|
||||
|
||||
// TODO Not sure this is the right place to add this, because it is not Sas
|
||||
fun userHasScannedRemoteQrCode(scannedData: String)
|
||||
}
|
||||
|
|
|
@ -27,19 +27,18 @@ import im.vector.matrix.android.internal.crypto.verification.PendingVerification
|
|||
* SAS verification is intended to be a highly interactive process for users,
|
||||
* and as such exposes verification methods which are easier for users to use.
|
||||
*/
|
||||
// TODO Rename to VerificationService and reorganize packages?
|
||||
interface SasVerificationService {
|
||||
interface VerificationService {
|
||||
|
||||
fun addListener(listener: SasVerificationListener)
|
||||
fun addListener(listener: VerificationListener)
|
||||
|
||||
fun removeListener(listener: SasVerificationListener)
|
||||
fun removeListener(listener: VerificationListener)
|
||||
|
||||
/**
|
||||
* Mark this device as verified manually
|
||||
*/
|
||||
fun markedLocallyAsManuallyVerified(userId: String, deviceID: String)
|
||||
|
||||
fun getExistingTransaction(otherUser: String, tid: String): SasVerificationTransaction?
|
||||
fun getExistingTransaction(otherUser: String, tid: String): VerificationTransaction?
|
||||
|
||||
fun getExistingVerificationRequest(otherUser: String): List<PendingVerificationRequest>?
|
||||
|
||||
|
@ -70,10 +69,9 @@ interface SasVerificationService {
|
|||
|
||||
// fun transactionUpdated(tx: SasVerificationTransaction)
|
||||
|
||||
// TODO Rename to VerificationListener
|
||||
interface SasVerificationListener {
|
||||
fun transactionCreated(tx: SasVerificationTransaction)
|
||||
fun transactionUpdated(tx: SasVerificationTransaction)
|
||||
interface VerificationListener {
|
||||
fun transactionCreated(tx: VerificationTransaction)
|
||||
fun transactionUpdated(tx: VerificationTransaction)
|
||||
fun markedAsManuallyVerified(userId: String, deviceId: String) {}
|
||||
|
||||
fun verificationRequestCreated(pr: PendingVerificationRequest) {}
|
|
@ -0,0 +1,20 @@
|
|||
package im.vector.matrix.android.api.session.crypto.sas
|
||||
|
||||
interface VerificationTransaction {
|
||||
|
||||
|
||||
var state: VerificationTxState
|
||||
|
||||
val cancelledReason: CancelCode?
|
||||
val transactionId: String
|
||||
val otherUserId: String
|
||||
var otherDeviceId: String?
|
||||
val isIncoming: Boolean
|
||||
/**
|
||||
* User wants to cancel the transaction
|
||||
*/
|
||||
fun cancel()
|
||||
fun cancel(code: CancelCode)
|
||||
|
||||
fun isToDeviceTransport(): Boolean
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package im.vector.matrix.android.api.session.crypto.sas
|
||||
|
||||
enum class SasVerificationTxState {
|
||||
enum class VerificationTxState {
|
||||
None,
|
||||
// I have started a verification request
|
||||
SendingStart,
|
|
@ -21,7 +21,7 @@ import im.vector.matrix.android.api.session.crypto.sas.SasMode
|
|||
import im.vector.matrix.android.api.session.events.model.toContent
|
||||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.supportedVerificationMethods
|
||||
import im.vector.matrix.android.internal.crypto.verification.SASVerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.SASDefaultVerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoStart
|
||||
import im.vector.matrix.android.internal.util.JsonCanonicalizer
|
||||
import timber.log.Timber
|
||||
|
@ -51,8 +51,8 @@ internal data class MessageVerificationStartContent(
|
|||
|| keyAgreementProtocols.isNullOrEmpty()
|
||||
|| hashes.isNullOrEmpty()
|
||||
|| !hashes.contains("sha256") || messageAuthenticationCodes.isNullOrEmpty()
|
||||
|| (!messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256)
|
||||
&& !messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256_LONGKDF))
|
||||
|| (!messageAuthenticationCodes.contains(SASDefaultVerificationTransaction.SAS_MAC_SHA256)
|
||||
&& !messageAuthenticationCodes.contains(SASDefaultVerificationTransaction.SAS_MAC_SHA256_LONGKDF))
|
||||
|| shortAuthenticationStrings.isNullOrEmpty()
|
||||
|| !shortAuthenticationStrings.contains(SasMode.DECIMAL)) {
|
||||
Timber.e("## received invalid verification request")
|
||||
|
|
|
@ -67,7 +67,7 @@ import im.vector.matrix.android.internal.crypto.tasks.GetDeviceInfoTask
|
|||
import im.vector.matrix.android.internal.crypto.tasks.GetDevicesTask
|
||||
import im.vector.matrix.android.internal.crypto.tasks.SetDeviceNameTask
|
||||
import im.vector.matrix.android.internal.crypto.tasks.UploadKeysTask
|
||||
import im.vector.matrix.android.internal.crypto.verification.DefaultSasVerificationService
|
||||
import im.vector.matrix.android.internal.crypto.verification.DefaultVerificationService
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
||||
|
@ -127,7 +127,7 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
//
|
||||
private val roomDecryptorProvider: RoomDecryptorProvider,
|
||||
// The SAS verification service.
|
||||
private val sasVerificationService: DefaultSasVerificationService,
|
||||
private val sasVerificationService: DefaultVerificationService,
|
||||
|
||||
private val crossSigningService: DefaultCrossSigningService,
|
||||
//
|
||||
|
@ -341,7 +341,7 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
override fun getKeysBackupService() = keysBackup
|
||||
|
||||
/**
|
||||
* @return the SasVerificationService
|
||||
* @return the VerificationService
|
||||
*/
|
||||
override fun getSasVerificationService() = sasVerificationService
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package im.vector.matrix.android.internal.crypto.model.rest
|
|||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasMode
|
||||
import im.vector.matrix.android.internal.crypto.verification.SASVerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.SASDefaultVerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoStart
|
||||
import im.vector.matrix.android.internal.util.JsonCanonicalizer
|
||||
import timber.log.Timber
|
||||
|
@ -49,8 +49,8 @@ internal data class KeyVerificationStart(
|
|||
|| hashes.isNullOrEmpty()
|
||||
|| !hashes.contains("sha256")
|
||||
|| messageAuthenticationCodes.isNullOrEmpty()
|
||||
|| (!messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256)
|
||||
&& !messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256_LONGKDF))
|
||||
|| (!messageAuthenticationCodes.contains(SASDefaultVerificationTransaction.SAS_MAC_SHA256)
|
||||
&& !messageAuthenticationCodes.contains(SASDefaultVerificationTransaction.SAS_MAC_SHA256_LONGKDF))
|
||||
|| shortAuthenticationStrings.isNullOrEmpty()
|
||||
|| !shortAuthenticationStrings.contains(SasMode.DECIMAL)) {
|
||||
Timber.e("## received invalid verification request")
|
||||
|
|
|
@ -18,13 +18,13 @@ package im.vector.matrix.android.internal.crypto.tasks
|
|||
|
||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||
import im.vector.matrix.android.api.session.crypto.MXCryptoError
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.message.*
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
|
||||
import im.vector.matrix.android.internal.crypto.verification.DefaultSasVerificationService
|
||||
import im.vector.matrix.android.internal.crypto.verification.DefaultVerificationService
|
||||
import im.vector.matrix.android.internal.di.DeviceId
|
||||
import im.vector.matrix.android.internal.di.UserId
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
|
@ -35,7 +35,7 @@ import javax.inject.Inject
|
|||
internal interface RoomVerificationUpdateTask : Task<RoomVerificationUpdateTask.Params, Unit> {
|
||||
data class Params(
|
||||
val events: List<Event>,
|
||||
val sasVerificationService: DefaultSasVerificationService,
|
||||
val sasVerificationService: DefaultVerificationService,
|
||||
val cryptoService: CryptoService
|
||||
)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor(
|
|||
// If the request is in the future by more than 5 minutes or more than 10 minutes in the past,
|
||||
// the message should be ignored by the receiver.
|
||||
|
||||
if (!SasVerificationService.isValidRequest(event.ageLocalTs
|
||||
if (!VerificationService.isValidRequest(event.ageLocalTs
|
||||
?: event.originServerTs)) return@forEach Unit.also {
|
||||
Timber.d("## SAS Verification live observer: msgId: ${event.eventId} is outdated")
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ import im.vector.matrix.android.api.session.crypto.crosssigning.CrossSigningServ
|
|||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.IncomingSasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasMode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.internal.crypto.actions.SetDeviceVerificationAction
|
||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import timber.log.Timber
|
||||
|
||||
internal class DefaultIncomingSASVerificationTransaction(
|
||||
internal class DefaultIncomingSASDefaultVerificationTransaction(
|
||||
setDeviceVerificationAction: SetDeviceVerificationAction,
|
||||
override val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
|
@ -37,7 +37,7 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
transactionId: String,
|
||||
otherUserID: String,
|
||||
val autoAccept: Boolean = false
|
||||
) : SASVerificationTransaction(
|
||||
) : SASDefaultVerificationTransaction(
|
||||
setDeviceVerificationAction,
|
||||
credentials,
|
||||
cryptoStore,
|
||||
|
@ -52,33 +52,33 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
override val uxState: IncomingSasVerificationTransaction.UxState
|
||||
get() {
|
||||
return when (state) {
|
||||
SasVerificationTxState.OnStarted -> IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT
|
||||
SasVerificationTxState.SendingAccept,
|
||||
SasVerificationTxState.Accepted,
|
||||
SasVerificationTxState.OnKeyReceived,
|
||||
SasVerificationTxState.SendingKey,
|
||||
SasVerificationTxState.KeySent -> IncomingSasVerificationTransaction.UxState.WAIT_FOR_KEY_AGREEMENT
|
||||
SasVerificationTxState.ShortCodeReady -> IncomingSasVerificationTransaction.UxState.SHOW_SAS
|
||||
SasVerificationTxState.ShortCodeAccepted,
|
||||
SasVerificationTxState.SendingMac,
|
||||
SasVerificationTxState.MacSent,
|
||||
SasVerificationTxState.Verifying -> IncomingSasVerificationTransaction.UxState.WAIT_FOR_VERIFICATION
|
||||
SasVerificationTxState.Verified -> IncomingSasVerificationTransaction.UxState.VERIFIED
|
||||
SasVerificationTxState.Cancelled -> IncomingSasVerificationTransaction.UxState.CANCELLED_BY_ME
|
||||
SasVerificationTxState.OnCancelled -> IncomingSasVerificationTransaction.UxState.CANCELLED_BY_OTHER
|
||||
else -> IncomingSasVerificationTransaction.UxState.UNKNOWN
|
||||
VerificationTxState.OnStarted -> IncomingSasVerificationTransaction.UxState.SHOW_ACCEPT
|
||||
VerificationTxState.SendingAccept,
|
||||
VerificationTxState.Accepted,
|
||||
VerificationTxState.OnKeyReceived,
|
||||
VerificationTxState.SendingKey,
|
||||
VerificationTxState.KeySent -> IncomingSasVerificationTransaction.UxState.WAIT_FOR_KEY_AGREEMENT
|
||||
VerificationTxState.ShortCodeReady -> IncomingSasVerificationTransaction.UxState.SHOW_SAS
|
||||
VerificationTxState.ShortCodeAccepted,
|
||||
VerificationTxState.SendingMac,
|
||||
VerificationTxState.MacSent,
|
||||
VerificationTxState.Verifying -> IncomingSasVerificationTransaction.UxState.WAIT_FOR_VERIFICATION
|
||||
VerificationTxState.Verified -> IncomingSasVerificationTransaction.UxState.VERIFIED
|
||||
VerificationTxState.Cancelled -> IncomingSasVerificationTransaction.UxState.CANCELLED_BY_ME
|
||||
VerificationTxState.OnCancelled -> IncomingSasVerificationTransaction.UxState.CANCELLED_BY_OTHER
|
||||
else -> IncomingSasVerificationTransaction.UxState.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
override fun onVerificationStart(startReq: VerificationInfoStart) {
|
||||
Timber.v("## SAS I: received verification request from state $state")
|
||||
if (state != SasVerificationTxState.None) {
|
||||
if (state != VerificationTxState.None) {
|
||||
Timber.e("## SAS I: received verification request from invalid state")
|
||||
// should I cancel??
|
||||
throw IllegalStateException("Interactive Key verification already started")
|
||||
}
|
||||
this.startReq = startReq
|
||||
state = SasVerificationTxState.OnStarted
|
||||
state = VerificationTxState.OnStarted
|
||||
this.otherDeviceId = startReq.fromDevice
|
||||
|
||||
if (autoAccept) {
|
||||
|
@ -87,7 +87,7 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
}
|
||||
|
||||
override fun performAccept() {
|
||||
if (state != SasVerificationTxState.OnStarted) {
|
||||
if (state != VerificationTxState.OnStarted) {
|
||||
Timber.e("## SAS Cannot perform accept from state $state")
|
||||
return
|
||||
}
|
||||
|
@ -143,11 +143,11 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
val concat = getSAS().publicKey + startReq!!.toCanonicalJson()
|
||||
accept.commitment = hashUsingAgreedHashMethod(concat) ?: ""
|
||||
// we need to send this to other device now
|
||||
state = SasVerificationTxState.SendingAccept
|
||||
sendToOther(EventType.KEY_VERIFICATION_ACCEPT, accept, SasVerificationTxState.Accepted, CancelCode.User) {
|
||||
if (state == SasVerificationTxState.SendingAccept) {
|
||||
state = VerificationTxState.SendingAccept
|
||||
sendToOther(EventType.KEY_VERIFICATION_ACCEPT, accept, VerificationTxState.Accepted, CancelCode.User) {
|
||||
if (state == VerificationTxState.SendingAccept) {
|
||||
// It is possible that we receive the next event before this one :/, in this case we should keep state
|
||||
state = SasVerificationTxState.Accepted
|
||||
state = VerificationTxState.Accepted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
|
||||
override fun onKeyVerificationKey(userId: String, vKey: VerificationInfoKey) {
|
||||
Timber.v("## SAS received key for request id:$transactionId")
|
||||
if (state != SasVerificationTxState.SendingAccept && state != SasVerificationTxState.Accepted) {
|
||||
if (state != VerificationTxState.SendingAccept && state != VerificationTxState.Accepted) {
|
||||
Timber.e("## SAS received key from invalid state $state")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
return
|
||||
|
@ -173,11 +173,11 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
|
||||
val keyToDevice = transport.createKey(transactionId, pubKey)
|
||||
// we need to send this to other device now
|
||||
state = SasVerificationTxState.SendingKey
|
||||
this.sendToOther(EventType.KEY_VERIFICATION_KEY, keyToDevice, SasVerificationTxState.KeySent, CancelCode.User) {
|
||||
if (state == SasVerificationTxState.SendingKey) {
|
||||
state = VerificationTxState.SendingKey
|
||||
this.sendToOther(EventType.KEY_VERIFICATION_KEY, keyToDevice, VerificationTxState.KeySent, CancelCode.User) {
|
||||
if (state == VerificationTxState.SendingKey) {
|
||||
// It is possible that we receive the next event before this one :/, in this case we should keep state
|
||||
state = SasVerificationTxState.KeySent
|
||||
state = VerificationTxState.KeySent
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,18 +207,18 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
Timber.v("************ BOB EMOJI CODE ${getShortCodeRepresentation(SasMode.EMOJI)}")
|
||||
}
|
||||
|
||||
state = SasVerificationTxState.ShortCodeReady
|
||||
state = VerificationTxState.ShortCodeReady
|
||||
}
|
||||
|
||||
override fun onKeyVerificationMac(vKey: VerificationInfoMac) {
|
||||
Timber.v("## SAS I: received mac for request id:$transactionId")
|
||||
// Check for state?
|
||||
if (state != SasVerificationTxState.SendingKey
|
||||
&& state != SasVerificationTxState.KeySent
|
||||
&& state != SasVerificationTxState.ShortCodeReady
|
||||
&& state != SasVerificationTxState.ShortCodeAccepted
|
||||
&& state != SasVerificationTxState.SendingMac
|
||||
&& state != SasVerificationTxState.MacSent) {
|
||||
if (state != VerificationTxState.SendingKey
|
||||
&& state != VerificationTxState.KeySent
|
||||
&& state != VerificationTxState.ShortCodeReady
|
||||
&& state != VerificationTxState.ShortCodeAccepted
|
||||
&& state != VerificationTxState.SendingMac
|
||||
&& state != VerificationTxState.MacSent) {
|
||||
Timber.e("## SAS I: received key from invalid state $state")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
return
|
|
@ -19,7 +19,7 @@ import im.vector.matrix.android.api.auth.data.Credentials
|
|||
import im.vector.matrix.android.api.session.crypto.crosssigning.CrossSigningService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.OutgoingSasVerificationRequest
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationMethod
|
||||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.internal.crypto.actions.SetDeviceVerificationAction
|
||||
|
@ -27,7 +27,7 @@ import im.vector.matrix.android.internal.crypto.model.rest.toValue
|
|||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import timber.log.Timber
|
||||
|
||||
internal class DefaultOutgoingSASVerificationRequest(
|
||||
internal class DefaultOutgoingSASDefaultVerificationRequest(
|
||||
setDeviceVerificationAction: SetDeviceVerificationAction,
|
||||
credentials: Credentials,
|
||||
cryptoStore: IMXCryptoStore,
|
||||
|
@ -36,7 +36,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
transactionId: String,
|
||||
otherUserId: String,
|
||||
otherDeviceId: String
|
||||
) : SASVerificationTransaction(
|
||||
) : SASDefaultVerificationTransaction(
|
||||
setDeviceVerificationAction,
|
||||
credentials,
|
||||
cryptoStore,
|
||||
|
@ -51,22 +51,22 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
override val uxState: OutgoingSasVerificationRequest.UxState
|
||||
get() {
|
||||
return when (state) {
|
||||
SasVerificationTxState.None -> OutgoingSasVerificationRequest.UxState.WAIT_FOR_START
|
||||
SasVerificationTxState.SendingStart,
|
||||
SasVerificationTxState.Started,
|
||||
SasVerificationTxState.OnAccepted,
|
||||
SasVerificationTxState.SendingKey,
|
||||
SasVerificationTxState.KeySent,
|
||||
SasVerificationTxState.OnKeyReceived -> OutgoingSasVerificationRequest.UxState.WAIT_FOR_KEY_AGREEMENT
|
||||
SasVerificationTxState.ShortCodeReady -> OutgoingSasVerificationRequest.UxState.SHOW_SAS
|
||||
SasVerificationTxState.ShortCodeAccepted,
|
||||
SasVerificationTxState.SendingMac,
|
||||
SasVerificationTxState.MacSent,
|
||||
SasVerificationTxState.Verifying -> OutgoingSasVerificationRequest.UxState.WAIT_FOR_VERIFICATION
|
||||
SasVerificationTxState.Verified -> OutgoingSasVerificationRequest.UxState.VERIFIED
|
||||
SasVerificationTxState.OnCancelled -> OutgoingSasVerificationRequest.UxState.CANCELLED_BY_ME
|
||||
SasVerificationTxState.Cancelled -> OutgoingSasVerificationRequest.UxState.CANCELLED_BY_OTHER
|
||||
else -> OutgoingSasVerificationRequest.UxState.UNKNOWN
|
||||
VerificationTxState.None -> OutgoingSasVerificationRequest.UxState.WAIT_FOR_START
|
||||
VerificationTxState.SendingStart,
|
||||
VerificationTxState.Started,
|
||||
VerificationTxState.OnAccepted,
|
||||
VerificationTxState.SendingKey,
|
||||
VerificationTxState.KeySent,
|
||||
VerificationTxState.OnKeyReceived -> OutgoingSasVerificationRequest.UxState.WAIT_FOR_KEY_AGREEMENT
|
||||
VerificationTxState.ShortCodeReady -> OutgoingSasVerificationRequest.UxState.SHOW_SAS
|
||||
VerificationTxState.ShortCodeAccepted,
|
||||
VerificationTxState.SendingMac,
|
||||
VerificationTxState.MacSent,
|
||||
VerificationTxState.Verifying -> OutgoingSasVerificationRequest.UxState.WAIT_FOR_VERIFICATION
|
||||
VerificationTxState.Verified -> OutgoingSasVerificationRequest.UxState.VERIFIED
|
||||
VerificationTxState.OnCancelled -> OutgoingSasVerificationRequest.UxState.CANCELLED_BY_ME
|
||||
VerificationTxState.Cancelled -> OutgoingSasVerificationRequest.UxState.CANCELLED_BY_OTHER
|
||||
else -> OutgoingSasVerificationRequest.UxState.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
}
|
||||
|
||||
fun start(method: VerificationMethod) {
|
||||
if (state != SasVerificationTxState.None) {
|
||||
if (state != VerificationTxState.None) {
|
||||
Timber.e("## SAS O: start verification from invalid state")
|
||||
// should I cancel??
|
||||
throw IllegalStateException("Interactive Key verification already started")
|
||||
|
@ -93,19 +93,19 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
)
|
||||
|
||||
startReq = startMessage
|
||||
state = SasVerificationTxState.SendingStart
|
||||
state = VerificationTxState.SendingStart
|
||||
|
||||
sendToOther(
|
||||
EventType.KEY_VERIFICATION_START,
|
||||
startMessage,
|
||||
SasVerificationTxState.Started,
|
||||
VerificationTxState.Started,
|
||||
CancelCode.User,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
// fun request() {
|
||||
// if (state != SasVerificationTxState.None) {
|
||||
// if (state != VerificationTxState.None) {
|
||||
// Timber.e("## start verification from invalid state")
|
||||
// // should I cancel??
|
||||
// throw IllegalStateException("Interactive Key verification already started")
|
||||
|
@ -121,7 +121,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
// sendToOther(
|
||||
// EventType.KEY_VERIFICATION_REQUEST,
|
||||
// requestMessage,
|
||||
// SasVerificationTxState.None,
|
||||
// VerificationTxState.None,
|
||||
// CancelCode.User,
|
||||
// null
|
||||
// )
|
||||
|
@ -129,7 +129,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
|
||||
override fun onVerificationAccept(accept: VerificationInfoAccept) {
|
||||
Timber.v("## SAS O: onVerificationAccept id:$transactionId")
|
||||
if (state != SasVerificationTxState.Started) {
|
||||
if (state != VerificationTxState.Started) {
|
||||
Timber.e("## SAS O: received accept request from invalid state $state")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
return
|
||||
|
@ -147,7 +147,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
// Upon receipt of the m.key.verification.accept message from Bob’s device,
|
||||
// Alice’s device stores the commitment value for later use.
|
||||
accepted = accept
|
||||
state = SasVerificationTxState.OnAccepted
|
||||
state = VerificationTxState.OnAccepted
|
||||
|
||||
// Alice’s device creates an ephemeral Curve25519 key pair (dA,QA),
|
||||
// and replies with a to_device message with type set to “m.key.verification.key”, sending Alice’s public key QA
|
||||
|
@ -155,18 +155,18 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
|
||||
val keyToDevice = transport.createKey(transactionId, pubKey)
|
||||
// we need to send this to other device now
|
||||
state = SasVerificationTxState.SendingKey
|
||||
sendToOther(EventType.KEY_VERIFICATION_KEY, keyToDevice, SasVerificationTxState.KeySent, CancelCode.User) {
|
||||
state = VerificationTxState.SendingKey
|
||||
sendToOther(EventType.KEY_VERIFICATION_KEY, keyToDevice, VerificationTxState.KeySent, CancelCode.User) {
|
||||
// It is possible that we receive the next event before this one :/, in this case we should keep state
|
||||
if (state == SasVerificationTxState.SendingKey) {
|
||||
state = SasVerificationTxState.KeySent
|
||||
if (state == VerificationTxState.SendingKey) {
|
||||
state = VerificationTxState.KeySent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyVerificationKey(userId: String, vKey: VerificationInfoKey) {
|
||||
Timber.v("## SAS O: onKeyVerificationKey id:$transactionId")
|
||||
if (state != SasVerificationTxState.SendingKey && state != SasVerificationTxState.KeySent) {
|
||||
if (state != VerificationTxState.SendingKey && state != VerificationTxState.KeySent) {
|
||||
Timber.e("## received key from invalid state $state")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
return
|
||||
|
@ -199,7 +199,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
// decimal: generate five bytes by using HKDF.
|
||||
// emoji: generate six bytes by using HKDF.
|
||||
shortCodeBytes = getSAS().generateShortCode(sasInfo, 6)
|
||||
state = SasVerificationTxState.ShortCodeReady
|
||||
state = VerificationTxState.ShortCodeReady
|
||||
} else {
|
||||
// bad commitement
|
||||
cancel(CancelCode.MismatchedCommitment)
|
||||
|
@ -208,11 +208,11 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
|
||||
override fun onKeyVerificationMac(vKey: VerificationInfoMac) {
|
||||
Timber.v("## SAS O: onKeyVerificationMac id:$transactionId")
|
||||
if (state != SasVerificationTxState.OnKeyReceived
|
||||
&& state != SasVerificationTxState.ShortCodeReady
|
||||
&& state != SasVerificationTxState.ShortCodeAccepted
|
||||
&& state != SasVerificationTxState.SendingMac
|
||||
&& state != SasVerificationTxState.MacSent) {
|
||||
if (state != VerificationTxState.OnKeyReceived
|
||||
&& state != VerificationTxState.ShortCodeReady
|
||||
&& state != VerificationTxState.ShortCodeAccepted
|
||||
&& state != VerificationTxState.SendingMac
|
||||
&& state != VerificationTxState.MacSent) {
|
||||
Timber.e("## SAS O: received key from invalid state $state")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
return
|
|
@ -50,7 +50,7 @@ import kotlin.collections.HashMap
|
|||
import kotlin.collections.set
|
||||
|
||||
@SessionScope
|
||||
internal class DefaultSasVerificationService @Inject constructor(
|
||||
internal class DefaultVerificationService @Inject constructor(
|
||||
private val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val myDeviceInfoHolder: Lazy<MyDeviceInfoHolder>,
|
||||
|
@ -60,7 +60,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
private val sasTransportRoomMessageFactory: SasTransportRoomMessageFactory,
|
||||
private val sasTransportToDeviceFactory: SasTransportToDeviceFactory,
|
||||
private val crossSigningService: CrossSigningService
|
||||
) : VerificationTransaction.Listener, SasVerificationService {
|
||||
) : DefaultVerificationTransaction.Listener, VerificationService {
|
||||
|
||||
private val uiHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
|
@ -68,7 +68,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
lateinit var cryptoService: CryptoService
|
||||
|
||||
// map [sender : [transaction]]
|
||||
private val txMap = HashMap<String, HashMap<String, VerificationTransaction>>()
|
||||
private val txMap = HashMap<String, HashMap<String, DefaultVerificationTransaction>>()
|
||||
|
||||
/**
|
||||
* Map [sender: [PendingVerificationRequest]]
|
||||
|
@ -139,9 +139,9 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private var listeners = ArrayList<SasVerificationService.SasVerificationListener>()
|
||||
private var listeners = ArrayList<VerificationService.VerificationListener>()
|
||||
|
||||
override fun addListener(listener: SasVerificationService.SasVerificationListener) {
|
||||
override fun addListener(listener: VerificationService.VerificationListener) {
|
||||
uiHandler.post {
|
||||
if (!listeners.contains(listener)) {
|
||||
listeners.add(listener)
|
||||
|
@ -149,7 +149,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun removeListener(listener: SasVerificationService.SasVerificationListener) {
|
||||
override fun removeListener(listener: VerificationService.VerificationListener) {
|
||||
uiHandler.post {
|
||||
listeners.remove(listener)
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun handleStart(otherUserId: String?, startReq: VerificationInfoStart, txConfigure: (SASVerificationTransaction) -> Unit): CancelCode? {
|
||||
private suspend fun handleStart(otherUserId: String?, startReq: VerificationInfoStart, txConfigure: (DefaultVerificationTransaction) -> Unit): CancelCode? {
|
||||
Timber.d("## SAS onStartRequestReceived ${startReq.transactionID!!}")
|
||||
if (checkKeysAreDownloaded(otherUserId!!, startReq.fromDevice ?: "") != null) {
|
||||
Timber.v("## SAS onStartRequestReceived $startReq")
|
||||
|
@ -373,7 +373,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
// as we are the one requesting in first place (or we accepted the request)
|
||||
val autoAccept = getExistingVerificationRequest(otherUserId)?.any { it.transactionId == startReq.transactionID }
|
||||
?: false
|
||||
val tx = DefaultIncomingSASVerificationTransaction(
|
||||
val tx = DefaultIncomingSASDefaultVerificationTransaction(
|
||||
// this,
|
||||
setDeviceVerificationAction,
|
||||
credentials,
|
||||
|
@ -461,9 +461,9 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
))
|
||||
}
|
||||
|
||||
if (existingTransaction is SASVerificationTransaction) {
|
||||
if (existingTransaction is SASDefaultVerificationTransaction) {
|
||||
existingTransaction.cancelledReason = safeValueOf(cancelReq.code)
|
||||
existingTransaction.state = SasVerificationTxState.OnCancelled
|
||||
existingTransaction.state = VerificationTxState.OnCancelled
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,7 +497,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
return
|
||||
}
|
||||
|
||||
if (existing is SASVerificationTransaction) {
|
||||
if (existing is SASDefaultVerificationTransaction) {
|
||||
existing.acceptVerificationEvent(otherUserId, acceptReq)
|
||||
} else {
|
||||
// not other types now
|
||||
|
@ -538,7 +538,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
Timber.e("## SAS Received invalid key request")
|
||||
return
|
||||
}
|
||||
if (existing is SASVerificationTransaction) {
|
||||
if (existing is SASDefaultVerificationTransaction) {
|
||||
existing.acceptVerificationEvent(otherUserId, keyReq)
|
||||
} else {
|
||||
// not other types now
|
||||
|
@ -616,7 +616,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
Timber.e("## SAS Received invalid Mac request")
|
||||
return
|
||||
}
|
||||
if (existing is SASVerificationTransaction) {
|
||||
if (existing is SASDefaultVerificationTransaction) {
|
||||
existing.acceptVerificationEvent(senderId, macReq)
|
||||
} else {
|
||||
// not other types known for now
|
||||
|
@ -681,7 +681,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun addTransaction(tx: VerificationTransaction) {
|
||||
private fun addTransaction(tx: DefaultVerificationTransaction) {
|
||||
tx.otherUserId.let { otherUserId ->
|
||||
synchronized(txMap) {
|
||||
val txInnerMap = txMap.getOrPut(otherUserId) { HashMap() }
|
||||
|
@ -696,7 +696,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
val txID = createUniqueIDForTransaction(userId, deviceID)
|
||||
// should check if already one (and cancel it)
|
||||
if (method == VerificationMethod.SAS) {
|
||||
val tx = DefaultOutgoingSASVerificationRequest(
|
||||
val tx = DefaultOutgoingSASDefaultVerificationRequest(
|
||||
setDeviceVerificationAction,
|
||||
credentials,
|
||||
cryptoStore,
|
||||
|
@ -795,7 +795,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
otherDeviceId: String,
|
||||
callback: MatrixCallback<String>?): String? {
|
||||
if (method == VerificationMethod.SAS) {
|
||||
val tx = DefaultOutgoingSASVerificationRequest(
|
||||
val tx = DefaultOutgoingSASDefaultVerificationRequest(
|
||||
setDeviceVerificationAction,
|
||||
credentials,
|
||||
cryptoStore,
|
||||
|
@ -831,7 +831,7 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
// TODO this is not yet related to a transaction, maybe we should use another method like for cancel?
|
||||
val readyMsg = transport.createReady(transactionId, credentials.deviceId ?: "", methods)
|
||||
transport.sendToOther(EventType.KEY_VERIFICATION_READY, readyMsg,
|
||||
SasVerificationTxState.None,
|
||||
VerificationTxState.None,
|
||||
CancelCode.User,
|
||||
null // TODO handle error?
|
||||
)
|
||||
|
@ -859,10 +859,10 @@ internal class DefaultSasVerificationService @Inject constructor(
|
|||
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
dispatchTxUpdated(tx)
|
||||
if (tx is SASVerificationTransaction
|
||||
&& (tx.state == SasVerificationTxState.Cancelled
|
||||
|| tx.state == SasVerificationTxState.OnCancelled
|
||||
|| tx.state == SasVerificationTxState.Verified)
|
||||
if (tx is SASDefaultVerificationTransaction
|
||||
&& (tx.state == VerificationTxState.Cancelled
|
||||
|| tx.state == VerificationTxState.OnCancelled
|
||||
|| tx.state == VerificationTxState.Verified)
|
||||
) {
|
||||
// remove
|
||||
this.removeTransaction(tx.otherUserId, tx.transactionId)
|
|
@ -16,16 +16,18 @@
|
|||
package im.vector.matrix.android.internal.crypto.verification
|
||||
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
|
||||
/**
|
||||
* Generic interactive key verification transaction
|
||||
*/
|
||||
internal abstract class VerificationTransaction(
|
||||
internal abstract class DefaultVerificationTransaction(
|
||||
override val transactionId: String,
|
||||
override val otherUserId: String,
|
||||
override var otherDeviceId: String? = null,
|
||||
override val isIncoming: Boolean) : SasVerificationTransaction {
|
||||
override val isIncoming: Boolean) : VerificationTransaction {
|
||||
|
||||
lateinit var transport: SasTransport
|
||||
|
||||
interface Listener {
|
||||
fun transactionUpdated(tx: VerificationTransaction)
|
||||
|
@ -42,6 +44,4 @@ internal abstract class VerificationTransaction(
|
|||
}
|
||||
|
||||
abstract fun acceptVerificationEvent(senderId: String, info: VerificationInfo)
|
||||
|
||||
abstract fun cancel(code: CancelCode)
|
||||
}
|
|
@ -22,7 +22,8 @@ import im.vector.matrix.android.api.session.crypto.crosssigning.CrossSigningServ
|
|||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.EmojiRepresentation
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasMode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.internal.crypto.actions.SetDeviceVerificationAction
|
||||
import im.vector.matrix.android.internal.crypto.crosssigning.DeviceTrustLevel
|
||||
|
@ -38,7 +39,7 @@ import kotlin.properties.Delegates
|
|||
/**
|
||||
* Represents an ongoing short code interactive key verification between two devices.
|
||||
*/
|
||||
internal abstract class SASVerificationTransaction(
|
||||
internal abstract class SASDefaultVerificationTransaction(
|
||||
private val setDeviceVerificationAction: SetDeviceVerificationAction,
|
||||
open val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
|
@ -48,9 +49,7 @@ internal abstract class SASVerificationTransaction(
|
|||
otherUserId: String,
|
||||
otherDevice: String?,
|
||||
isIncoming: Boolean) :
|
||||
VerificationTransaction(transactionId, otherUserId, otherDevice, isIncoming) {
|
||||
|
||||
lateinit var transport: SasTransport
|
||||
DefaultVerificationTransaction(transactionId, otherUserId, otherDevice, isIncoming), SasVerificationTransaction {
|
||||
|
||||
companion object {
|
||||
const val SAS_MAC_SHA256_LONGKDF = "hmac-sha256"
|
||||
|
@ -72,7 +71,7 @@ internal abstract class SASVerificationTransaction(
|
|||
}
|
||||
}
|
||||
|
||||
override var state by Delegates.observable(SasVerificationTxState.None) { _, _, new ->
|
||||
override var state by Delegates.observable(VerificationTxState.None) { _, _, new ->
|
||||
// println("$property has changed from $old to $new")
|
||||
listeners.forEach {
|
||||
try {
|
||||
|
@ -81,9 +80,9 @@ internal abstract class SASVerificationTransaction(
|
|||
Timber.e(e, "## Error while notifying listeners")
|
||||
}
|
||||
}
|
||||
if (new == SasVerificationTxState.Cancelled
|
||||
|| new == SasVerificationTxState.OnCancelled
|
||||
|| new == SasVerificationTxState.Verified) {
|
||||
if (new == VerificationTxState.Cancelled
|
||||
|| new == VerificationTxState.OnCancelled
|
||||
|| new == VerificationTxState.Verified) {
|
||||
releaseSAS()
|
||||
}
|
||||
}
|
||||
|
@ -122,14 +121,14 @@ internal abstract class SASVerificationTransaction(
|
|||
*/
|
||||
override fun userHasVerifiedShortCode() {
|
||||
Timber.v("## SAS short code verified by user for id:$transactionId")
|
||||
if (state != SasVerificationTxState.ShortCodeReady) {
|
||||
if (state != VerificationTxState.ShortCodeReady) {
|
||||
// ignore and cancel?
|
||||
Timber.e("## Accepted short code from invalid state $state")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
return
|
||||
}
|
||||
|
||||
state = SasVerificationTxState.ShortCodeAccepted
|
||||
state = VerificationTxState.ShortCodeAccepted
|
||||
// Alice and Bob’ devices calculate the HMAC of their own device keys and a comma-separated,
|
||||
// sorted list of the key IDs that they wish the other user to verify,
|
||||
// the shared secret as the input keying material, no salt, and with the input parameter set to the concatenation of:
|
||||
|
@ -185,11 +184,11 @@ internal abstract class SASVerificationTransaction(
|
|||
|
||||
val macMsg = transport.createMac(transactionId, keyMap, keyStrings)
|
||||
myMac = macMsg
|
||||
state = SasVerificationTxState.SendingMac
|
||||
sendToOther(EventType.KEY_VERIFICATION_MAC, macMsg, SasVerificationTxState.MacSent, CancelCode.User) {
|
||||
if (state == SasVerificationTxState.SendingMac) {
|
||||
state = VerificationTxState.SendingMac
|
||||
sendToOther(EventType.KEY_VERIFICATION_MAC, macMsg, VerificationTxState.MacSent, CancelCode.User) {
|
||||
if (state == VerificationTxState.SendingMac) {
|
||||
// It is possible that we receive the next event before this one :/, in this case we should keep state
|
||||
state = SasVerificationTxState.MacSent
|
||||
state = VerificationTxState.MacSent
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,13 +227,9 @@ internal abstract class SASVerificationTransaction(
|
|||
|
||||
abstract fun onKeyVerificationMac(vKey: VerificationInfoMac)
|
||||
|
||||
override fun userHasScannedRemoteQrCode(scannedData: String) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
protected fun verifyMacs() {
|
||||
Timber.v("## SAS verifying macs for id:$transactionId")
|
||||
state = SasVerificationTxState.Verifying
|
||||
state = VerificationTxState.Verifying
|
||||
|
||||
// Keys have been downloaded earlier in process
|
||||
val otherUserKnownDevices = cryptoStore.getUserDevices(otherUserId)
|
||||
|
@ -335,7 +330,7 @@ internal abstract class SASVerificationTransaction(
|
|||
setDeviceVerified(otherUserId, it)
|
||||
}
|
||||
transport.done(transactionId)
|
||||
state = SasVerificationTxState.Verified
|
||||
state = VerificationTxState.Verified
|
||||
}
|
||||
|
||||
private fun setDeviceVerified(userId: String, deviceId: String) {
|
||||
|
@ -351,13 +346,13 @@ internal abstract class SASVerificationTransaction(
|
|||
|
||||
override fun cancel(code: CancelCode) {
|
||||
cancelledReason = code
|
||||
state = SasVerificationTxState.Cancelled
|
||||
state = VerificationTxState.Cancelled
|
||||
transport.cancelTransaction(transactionId, otherUserId, otherDeviceId ?: "", code)
|
||||
}
|
||||
|
||||
protected fun sendToOther(type: String,
|
||||
keyToDevice: VerificationInfo,
|
||||
nextState: SasVerificationTxState,
|
||||
nextState: VerificationTxState,
|
||||
onErrorReason: CancelCode,
|
||||
onDone: (() -> Unit)?) {
|
||||
transport.sendToOther(type, keyToDevice, nextState, onErrorReason, onDone)
|
|
@ -16,7 +16,7 @@
|
|||
package im.vector.matrix.android.internal.crypto.verification
|
||||
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.room.model.message.MessageVerificationRequestContent
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ internal interface SasTransport {
|
|||
*/
|
||||
fun sendToOther(type: String,
|
||||
verificationInfo: VerificationInfo,
|
||||
nextState: SasVerificationTxState,
|
||||
nextState: VerificationTxState,
|
||||
onErrorReason: CancelCode,
|
||||
onDone: (() -> Unit)?)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import androidx.work.*
|
|||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.R
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.events.model.*
|
||||
import im.vector.matrix.android.api.session.room.model.message.*
|
||||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
|
@ -48,12 +48,12 @@ internal class SasTransportRoomMessage(
|
|||
private val roomId: String,
|
||||
private val monarchy: Monarchy,
|
||||
private val localEchoEventFactory: LocalEchoEventFactory,
|
||||
private val tx: SASVerificationTransaction?
|
||||
private val tx: DefaultVerificationTransaction?
|
||||
) : SasTransport {
|
||||
|
||||
override fun sendToOther(type: String,
|
||||
verificationInfo: VerificationInfo,
|
||||
nextState: SasVerificationTxState,
|
||||
nextState: VerificationTxState,
|
||||
onErrorReason: CancelCode,
|
||||
onDone: (() -> Unit)?) {
|
||||
Timber.d("## SAS sending msg type $type")
|
||||
|
@ -304,7 +304,7 @@ internal class SasTransportRoomMessageFactory @Inject constructor(
|
|||
private val deviceId: String?,
|
||||
private val localEchoEventFactory: LocalEchoEventFactory) {
|
||||
|
||||
fun createTransport(roomId: String, tx: SASVerificationTransaction?): SasTransportRoomMessage {
|
||||
fun createTransport(roomId: String, tx: DefaultVerificationTransaction?): SasTransportRoomMessage {
|
||||
return SasTransportRoomMessage(workManagerProvider, stringProvider, sessionId, userId, deviceId, roomId, monarchy, localEchoEventFactory, tx)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ package im.vector.matrix.android.internal.crypto.verification
|
|||
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.events.model.EventType
|
||||
import im.vector.matrix.android.api.session.room.model.message.MessageVerificationRequestContent
|
||||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||
|
@ -29,7 +29,7 @@ import timber.log.Timber
|
|||
import javax.inject.Inject
|
||||
|
||||
internal class SasTransportToDevice(
|
||||
private var tx: SASVerificationTransaction?,
|
||||
private var tx: DefaultVerificationTransaction?,
|
||||
private var sendToDeviceTask: SendToDeviceTask,
|
||||
private var taskExecutor: TaskExecutor
|
||||
) : SasTransport {
|
||||
|
@ -44,7 +44,7 @@ internal class SasTransportToDevice(
|
|||
|
||||
override fun sendToOther(type: String,
|
||||
verificationInfo: VerificationInfo,
|
||||
nextState: SasVerificationTxState,
|
||||
nextState: VerificationTxState,
|
||||
onErrorReason: CancelCode,
|
||||
onDone: (() -> Unit)?) {
|
||||
Timber.d("## SAS sending msg type $type")
|
||||
|
@ -149,7 +149,7 @@ internal class SasTransportToDeviceFactory @Inject constructor(
|
|||
private val sendToDeviceTask: SendToDeviceTask,
|
||||
private val taskExecutor: TaskExecutor) {
|
||||
|
||||
fun createTransport(tx: SASVerificationTransaction?): SasTransportToDevice {
|
||||
fun createTransport(tx: DefaultVerificationTransaction?): SasTransportToDevice {
|
||||
return SasTransportToDevice(tx, sendToDeviceTask, taskExecutor)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ internal class VerificationMessageLiveObserver @Inject constructor(
|
|||
@SessionDatabase realmConfiguration: RealmConfiguration,
|
||||
private val roomVerificationUpdateTask: DefaultRoomVerificationUpdateTask,
|
||||
private val cryptoService: CryptoService,
|
||||
private val sasVerificationService: DefaultSasVerificationService,
|
||||
private val sasVerificationService: DefaultVerificationService,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : RealmLiveEntityObserver<EventEntity>(realmConfiguration) {
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
|||
import im.vector.matrix.android.internal.crypto.DefaultCryptoService
|
||||
import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult
|
||||
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
|
||||
import im.vector.matrix.android.internal.crypto.verification.DefaultSasVerificationService
|
||||
import im.vector.matrix.android.internal.crypto.verification.DefaultVerificationService
|
||||
import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService
|
||||
import im.vector.matrix.android.internal.session.sync.model.SyncResponse
|
||||
import im.vector.matrix.android.internal.session.sync.model.ToDeviceSyncResponse
|
||||
|
@ -32,7 +32,7 @@ import timber.log.Timber
|
|||
import javax.inject.Inject
|
||||
|
||||
internal class CryptoSyncHandler @Inject constructor(private val cryptoService: DefaultCryptoService,
|
||||
private val sasVerificationService: DefaultSasVerificationService) {
|
||||
private val sasVerificationService: DefaultVerificationService) {
|
||||
|
||||
fun handleToDevice(toDevice: ToDeviceSyncResponse, initialSyncProgressService: DefaultInitialSyncProgressService? = null) {
|
||||
val total = toDevice.events?.size ?: 0
|
||||
|
|
|
@ -23,9 +23,10 @@ import android.content.Context
|
|||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.keyshare.RoomKeysRequestListener
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequest
|
||||
import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequestCancellation
|
||||
import im.vector.matrix.android.internal.crypto.crosssigning.DeviceTrustLevel
|
||||
|
@ -55,7 +56,7 @@ import kotlin.collections.HashMap
|
|||
@Singleton
|
||||
class KeyRequestHandler @Inject constructor(private val context: Context)
|
||||
: RoomKeysRequestListener,
|
||||
SasVerificationService.SasVerificationListener {
|
||||
VerificationService.VerificationListener {
|
||||
|
||||
private val alertsToRequests = HashMap<String, ArrayList<IncomingRoomKeyRequest>>()
|
||||
|
||||
|
@ -261,16 +262,20 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
|
|||
}
|
||||
}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {
|
||||
}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
val state = tx.state
|
||||
if (state == SasVerificationTxState.Verified) {
|
||||
// ok it's verified, see if we have key request for that
|
||||
shareAllSessions("${tx.otherDeviceId}${tx.otherUserId}")
|
||||
PopupAlertManager.cancelAlert("ikr_${tx.otherDeviceId}${tx.otherUserId}")
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if (tx is SasVerificationTransaction) {
|
||||
val state = tx.state
|
||||
if (state == VerificationTxState.Verified) {
|
||||
// ok it's verified, see if we have key request for that
|
||||
shareAllSessions("${tx.otherDeviceId}${tx.otherUserId}")
|
||||
PopupAlertManager.cancelAlert("ikr_${tx.otherDeviceId}${tx.otherUserId}")
|
||||
}
|
||||
}
|
||||
// should do it with QR tx also
|
||||
// TODO -> Probably better to listen to device trust changes?
|
||||
}
|
||||
|
||||
override fun markedAsManuallyVerified(userId: String, deviceId: String) {
|
||||
|
|
|
@ -17,9 +17,9 @@ package im.vector.riotx.features.crypto.verification
|
|||
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.PendingVerificationRequest
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.platform.VectorBaseActivity
|
||||
|
@ -34,7 +34,7 @@ import javax.inject.Singleton
|
|||
* Listens to the VerificationManager and add a new notification when an incoming request is detected.
|
||||
*/
|
||||
@Singleton
|
||||
class IncomingVerificationRequestHandler @Inject constructor(private val context: Context) : SasVerificationService.SasVerificationListener {
|
||||
class IncomingVerificationRequestHandler @Inject constructor(private val context: Context) : VerificationService.VerificationListener {
|
||||
|
||||
private var session: Session? = null
|
||||
|
||||
|
@ -48,13 +48,13 @@ class IncomingVerificationRequestHandler @Inject constructor(private val context
|
|||
this.session = null
|
||||
}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if (!tx.isToDeviceTransport()) return
|
||||
// TODO maybe check also if
|
||||
when (tx.state) {
|
||||
SasVerificationTxState.OnStarted -> {
|
||||
VerificationTxState.OnStarted -> {
|
||||
// Add a notification for every incoming request
|
||||
val name = session?.getUser(tx.otherUserId)?.displayName
|
||||
?: tx.otherUserId
|
||||
|
@ -92,13 +92,13 @@ class IncomingVerificationRequestHandler @Inject constructor(private val context
|
|||
}
|
||||
PopupAlertManager.postVectorAlert(alert)
|
||||
}
|
||||
SasVerificationTxState.Cancelled,
|
||||
SasVerificationTxState.OnCancelled,
|
||||
SasVerificationTxState.Verified -> {
|
||||
VerificationTxState.Cancelled,
|
||||
VerificationTxState.OnCancelled,
|
||||
VerificationTxState.Verified -> {
|
||||
// cancel related notification
|
||||
PopupAlertManager.cancelAlert("kvr_${tx.transactionId}")
|
||||
}
|
||||
else -> Unit
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import im.vector.riotx.core.platform.VectorViewModelAction
|
|||
sealed class VerificationAction : VectorViewModelAction {
|
||||
data class RequestVerificationByDM(val userID: String, val roomId: String?) : VerificationAction()
|
||||
data class StartSASVerification(val userID: String, val pendingRequestTransactionId: String) : VerificationAction()
|
||||
data class RemoteQrCodeScanned(val userID: String, val sasTransactionId: String, val scannedData: String) : VerificationAction()
|
||||
data class RemoteQrCodeScanned(val userID: String, val transactionId: String, val scannedData: String) : VerificationAction()
|
||||
data class SASMatchAction(val userID: String, val sasTransactionId: String) : VerificationAction()
|
||||
data class SASDoNotMatchAction(val userID: String, val sasTransactionId: String) : VerificationAction()
|
||||
object GotItConclusion : VerificationAction()
|
||||
|
|
|
@ -31,7 +31,7 @@ import com.airbnb.mvrx.MvRx
|
|||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.ScreenComponent
|
||||
import im.vector.riotx.core.extensions.commitTransactionNow
|
||||
|
@ -101,7 +101,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||
it.otherUserMxItem?.let { matrixItem ->
|
||||
avatarRenderer.render(matrixItem, otherUserAvatarImageView)
|
||||
|
||||
if (it.sasTransactionState == SasVerificationTxState.Verified) {
|
||||
if (it.transactionState == VerificationTxState.Verified) {
|
||||
otherUserNameText.text = getString(R.string.verification_verified_user, matrixItem.getBestName())
|
||||
otherUserShield.isVisible = true
|
||||
} else {
|
||||
|
@ -111,23 +111,23 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||
}
|
||||
|
||||
// Did the request result in a SAS transaction?
|
||||
if (it.sasTransactionState != null) {
|
||||
when (it.sasTransactionState) {
|
||||
SasVerificationTxState.None,
|
||||
SasVerificationTxState.SendingStart,
|
||||
SasVerificationTxState.Started,
|
||||
SasVerificationTxState.OnStarted,
|
||||
SasVerificationTxState.SendingAccept,
|
||||
SasVerificationTxState.Accepted,
|
||||
SasVerificationTxState.OnAccepted,
|
||||
SasVerificationTxState.SendingKey,
|
||||
SasVerificationTxState.KeySent,
|
||||
SasVerificationTxState.OnKeyReceived,
|
||||
SasVerificationTxState.ShortCodeReady,
|
||||
SasVerificationTxState.ShortCodeAccepted,
|
||||
SasVerificationTxState.SendingMac,
|
||||
SasVerificationTxState.MacSent,
|
||||
SasVerificationTxState.Verifying -> {
|
||||
if (it.transactionState != null) {
|
||||
when (it.transactionState) {
|
||||
VerificationTxState.None,
|
||||
VerificationTxState.SendingStart,
|
||||
VerificationTxState.Started,
|
||||
VerificationTxState.OnStarted,
|
||||
VerificationTxState.SendingAccept,
|
||||
VerificationTxState.Accepted,
|
||||
VerificationTxState.OnAccepted,
|
||||
VerificationTxState.SendingKey,
|
||||
VerificationTxState.KeySent,
|
||||
VerificationTxState.OnKeyReceived,
|
||||
VerificationTxState.ShortCodeReady,
|
||||
VerificationTxState.ShortCodeAccepted,
|
||||
VerificationTxState.SendingMac,
|
||||
VerificationTxState.MacSent,
|
||||
VerificationTxState.Verifying -> {
|
||||
showFragment(VerificationEmojiCodeFragment::class, Bundle().apply {
|
||||
putParcelable(MvRx.KEY_ARG, VerificationArgs(
|
||||
it.otherUserMxItem?.id ?: "",
|
||||
|
@ -136,12 +136,12 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||
it.pendingRequest?.transactionId ?: it.transactionId))
|
||||
})
|
||||
}
|
||||
SasVerificationTxState.Verified,
|
||||
SasVerificationTxState.Cancelled,
|
||||
SasVerificationTxState.OnCancelled -> {
|
||||
VerificationTxState.Verified,
|
||||
VerificationTxState.Cancelled,
|
||||
VerificationTxState.OnCancelled -> {
|
||||
showFragment(VerificationConclusionFragment::class, Bundle().apply {
|
||||
putParcelable(MvRx.KEY_ARG, VerificationConclusionFragment.Args(
|
||||
it.sasTransactionState == SasVerificationTxState.Verified,
|
||||
it.transactionState == VerificationTxState.Verified,
|
||||
it.cancelCode?.value))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -27,10 +27,12 @@ import com.squareup.inject.assisted.Assisted
|
|||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.QRVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationMethod
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.util.MatrixItem
|
||||
import im.vector.matrix.android.api.util.toMatrixItem
|
||||
import im.vector.matrix.android.internal.crypto.verification.PendingVerificationRequest
|
||||
|
@ -42,7 +44,7 @@ data class VerificationBottomSheetViewState(
|
|||
val otherUserMxItem: MatrixItem? = null,
|
||||
val roomId: String? = null,
|
||||
val pendingRequest: PendingVerificationRequest? = null,
|
||||
val sasTransactionState: SasVerificationTxState? = null,
|
||||
val transactionState: VerificationTxState? = null,
|
||||
val transactionId: String? = null,
|
||||
val cancelCode: CancelCode? = null
|
||||
) : MvRxState
|
||||
|
@ -50,7 +52,7 @@ data class VerificationBottomSheetViewState(
|
|||
class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted initialState: VerificationBottomSheetViewState,
|
||||
private val session: Session)
|
||||
: VectorViewModel<VerificationBottomSheetViewState, VerificationAction>(initialState),
|
||||
SasVerificationService.SasVerificationListener {
|
||||
VerificationService.VerificationListener {
|
||||
|
||||
// Can be used for several actions, for a one shot result
|
||||
private val _requestLiveData = MutableLiveData<LiveEvent<Async<VerificationAction>>>()
|
||||
|
@ -89,7 +91,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
|
|||
|
||||
return fragment.verificationViewModelFactory.create(VerificationBottomSheetViewState(
|
||||
otherUserMxItem = userItem?.toMatrixItem(),
|
||||
sasTransactionState = sasTx?.state,
|
||||
transactionState = sasTx?.state,
|
||||
transactionId = args.verificationId,
|
||||
pendingRequest = pr,
|
||||
roomId = args.roomId)
|
||||
|
@ -101,6 +103,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
|
|||
val otherUserId = state.otherUserMxItem?.id ?: return@withState
|
||||
val roomId = state.roomId
|
||||
?: session.getExistingDirectRoomWithUser(otherUserId)?.roomId
|
||||
|
||||
when (action) {
|
||||
is VerificationAction.RequestVerificationByDM -> {
|
||||
if (roomId == null) return@withState
|
||||
|
@ -124,18 +127,20 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
|
|||
}
|
||||
is VerificationAction.RemoteQrCodeScanned -> {
|
||||
// TODO Use session.getCrossSigningService()?
|
||||
session.getSasVerificationService()
|
||||
.getExistingTransaction(action.userID, action.sasTransactionId)
|
||||
val existingTransaction = session.getSasVerificationService()
|
||||
.getExistingTransaction(action.userID, action.transactionId) as? QRVerificationTransaction
|
||||
existingTransaction
|
||||
?.userHasScannedRemoteQrCode(action.scannedData)
|
||||
}
|
||||
is VerificationAction.SASMatchAction -> {
|
||||
session.getSasVerificationService()
|
||||
(session.getSasVerificationService()
|
||||
.getExistingTransaction(action.userID, action.sasTransactionId)
|
||||
?.userHasVerifiedShortCode()
|
||||
as? SasVerificationTransaction)?.userHasVerifiedShortCode()
|
||||
}
|
||||
is VerificationAction.SASDoNotMatchAction -> {
|
||||
session.getSasVerificationService()
|
||||
(session.getSasVerificationService()
|
||||
.getExistingTransaction(action.userID, action.sasTransactionId)
|
||||
as? SasVerificationTransaction)
|
||||
?.shortCodeDoesNotMatch()
|
||||
}
|
||||
is VerificationAction.GotItConclusion -> {
|
||||
|
@ -144,16 +149,16 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(@Assisted ini
|
|||
}
|
||||
}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {
|
||||
transactionUpdated(tx)
|
||||
}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) = withState { state ->
|
||||
override fun transactionUpdated(tx: VerificationTransaction) = withState { state ->
|
||||
if (tx.transactionId == (state.pendingRequest?.transactionId ?: state.transactionId)) {
|
||||
// A SAS tx has been started following this request
|
||||
setState {
|
||||
copy(
|
||||
sasTransactionState = tx.state,
|
||||
transactionState = tx.state,
|
||||
cancelCode = tx.cancelledReason
|
||||
)
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ import com.airbnb.mvrx.ViewModelContext
|
|||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationMethod
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.PendingVerificationRequest
|
||||
import im.vector.riotx.core.di.HasScreenInjector
|
||||
import im.vector.riotx.core.platform.EmptyAction
|
||||
|
@ -43,11 +43,11 @@ data class VerificationChooseMethodViewState(
|
|||
class VerificationChooseMethodViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: VerificationChooseMethodViewState,
|
||||
private val session: Session
|
||||
) : VectorViewModel<VerificationChooseMethodViewState, EmptyAction>(initialState), SasVerificationService.SasVerificationListener {
|
||||
) : VectorViewModel<VerificationChooseMethodViewState, EmptyAction>(initialState), VerificationService.VerificationListener {
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {}
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun verificationRequestUpdated(pr: PendingVerificationRequest) = withState { state ->
|
||||
val pvr = session.getSasVerificationService().getExistingVerificationRequest(state.otherUserId, state.transactionId)
|
||||
|
|
|
@ -20,9 +20,10 @@ import com.squareup.inject.assisted.Assisted
|
|||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.sas.EmojiRepresentation
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
import im.vector.matrix.android.api.util.MatrixItem
|
||||
import im.vector.matrix.android.api.util.toMatrixItem
|
||||
import im.vector.riotx.core.di.HasScreenInjector
|
||||
|
@ -42,13 +43,13 @@ data class VerificationEmojiCodeViewState(
|
|||
class VerificationEmojiCodeViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: VerificationEmojiCodeViewState,
|
||||
private val session: Session
|
||||
) : VectorViewModel<VerificationEmojiCodeViewState, EmptyAction>(initialState), SasVerificationService.SasVerificationListener {
|
||||
) : VectorViewModel<VerificationEmojiCodeViewState, EmptyAction>(initialState), VerificationService.VerificationListener {
|
||||
|
||||
init {
|
||||
withState { state ->
|
||||
refreshStateFromTx(session.getSasVerificationService()
|
||||
.getExistingTransaction(state.otherUser?.id ?: "", state.transactionId
|
||||
?: ""))
|
||||
?: "") as? SasVerificationTransaction)
|
||||
}
|
||||
|
||||
session.getSasVerificationService().addListener(this)
|
||||
|
@ -61,16 +62,16 @@ class VerificationEmojiCodeViewModel @AssistedInject constructor(
|
|||
|
||||
private fun refreshStateFromTx(sasTx: SasVerificationTransaction?) {
|
||||
when (sasTx?.state) {
|
||||
SasVerificationTxState.None,
|
||||
SasVerificationTxState.SendingStart,
|
||||
SasVerificationTxState.Started,
|
||||
SasVerificationTxState.OnStarted,
|
||||
SasVerificationTxState.SendingAccept,
|
||||
SasVerificationTxState.Accepted,
|
||||
SasVerificationTxState.OnAccepted,
|
||||
SasVerificationTxState.SendingKey,
|
||||
SasVerificationTxState.KeySent,
|
||||
SasVerificationTxState.OnKeyReceived -> {
|
||||
VerificationTxState.None,
|
||||
VerificationTxState.SendingStart,
|
||||
VerificationTxState.Started,
|
||||
VerificationTxState.OnStarted,
|
||||
VerificationTxState.SendingAccept,
|
||||
VerificationTxState.Accepted,
|
||||
VerificationTxState.OnAccepted,
|
||||
VerificationTxState.SendingKey,
|
||||
VerificationTxState.KeySent,
|
||||
VerificationTxState.OnKeyReceived -> {
|
||||
setState {
|
||||
copy(
|
||||
isWaitingFromOther = false,
|
||||
|
@ -84,7 +85,7 @@ class VerificationEmojiCodeViewModel @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
}
|
||||
SasVerificationTxState.ShortCodeReady -> {
|
||||
VerificationTxState.ShortCodeReady -> {
|
||||
setState {
|
||||
copy(
|
||||
isWaitingFromOther = false,
|
||||
|
@ -96,17 +97,17 @@ class VerificationEmojiCodeViewModel @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
}
|
||||
SasVerificationTxState.ShortCodeAccepted,
|
||||
SasVerificationTxState.SendingMac,
|
||||
SasVerificationTxState.MacSent,
|
||||
SasVerificationTxState.Verifying,
|
||||
SasVerificationTxState.Verified -> {
|
||||
VerificationTxState.ShortCodeAccepted,
|
||||
VerificationTxState.SendingMac,
|
||||
VerificationTxState.MacSent,
|
||||
VerificationTxState.Verifying,
|
||||
VerificationTxState.Verified -> {
|
||||
setState {
|
||||
copy(isWaitingFromOther = true)
|
||||
}
|
||||
}
|
||||
SasVerificationTxState.Cancelled,
|
||||
SasVerificationTxState.OnCancelled -> {
|
||||
VerificationTxState.Cancelled,
|
||||
VerificationTxState.OnCancelled -> {
|
||||
// The fragment should not be rendered in this state,
|
||||
// it should have been replaced by a conclusion fragment
|
||||
setState {
|
||||
|
@ -130,12 +131,12 @@ class VerificationEmojiCodeViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {
|
||||
transactionUpdated(tx)
|
||||
}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) = withState { state ->
|
||||
if (tx.transactionId == state.transactionId) {
|
||||
override fun transactionUpdated(tx: VerificationTransaction) = withState { state ->
|
||||
if (tx.transactionId == state.transactionId && tx is SasVerificationTransaction) {
|
||||
refreshStateFromTx(tx)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ import com.airbnb.mvrx.*
|
|||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
import im.vector.matrix.android.api.util.MatrixItem
|
||||
import im.vector.matrix.android.api.util.toMatrixItem
|
||||
import im.vector.matrix.android.internal.crypto.verification.PendingVerificationRequest
|
||||
|
@ -38,7 +38,7 @@ data class VerificationRequestViewState(
|
|||
class VerificationRequestViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: VerificationRequestViewState,
|
||||
private val session: Session
|
||||
) : VectorViewModel<VerificationRequestViewState, EmptyAction>(initialState), SasVerificationService.SasVerificationListener {
|
||||
) : VectorViewModel<VerificationRequestViewState, EmptyAction>(initialState), VerificationService.VerificationListener {
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory {
|
||||
|
@ -79,9 +79,9 @@ class VerificationRequestViewModel @AssistedInject constructor(
|
|||
|
||||
override fun handle(action: EmptyAction) {}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {}
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {}
|
||||
|
||||
override fun verificationRequestCreated(pr: PendingVerificationRequest) {
|
||||
verificationRequestUpdated(pr)
|
||||
|
|
|
@ -28,7 +28,7 @@ import androidx.core.view.isVisible
|
|||
import androidx.core.view.updateLayoutParams
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.internal.session.room.VerificationState
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
|
@ -110,7 +110,7 @@ abstract class VerificationRequestItem : AbsBaseMessageItem<VerificationRequestI
|
|||
}
|
||||
|
||||
// Always hide buttons if request is too old
|
||||
if (!SasVerificationService.isValidRequest(attributes.informationData.ageLocalTS)) {
|
||||
if (!VerificationService.isValidRequest(attributes.informationData.ageLocalTS)) {
|
||||
holder.buttonBar.isVisible = false
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ import com.squareup.inject.assisted.AssistedInject
|
|||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTxState
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationMethod
|
||||
import im.vector.matrix.android.api.session.crypto.sas.VerificationTransaction
|
||||
import im.vector.matrix.android.internal.auth.data.LoginFlowTypes
|
||||
import im.vector.matrix.android.internal.crypto.model.CryptoDeviceInfo
|
||||
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
|
||||
|
@ -64,7 +64,7 @@ sealed class DevicesAction : VectorViewModelAction {
|
|||
|
||||
class DevicesViewModel @AssistedInject constructor(@Assisted initialState: DevicesViewState,
|
||||
private val session: Session)
|
||||
: VectorViewModel<DevicesViewState, DevicesAction>(initialState), SasVerificationService.SasVerificationListener {
|
||||
: VectorViewModel<DevicesViewState, DevicesAction>(initialState), VerificationService.VerificationListener {
|
||||
|
||||
@AssistedInject.Factory
|
||||
interface Factory {
|
||||
|
@ -103,9 +103,9 @@ class DevicesViewModel @AssistedInject constructor(@Assisted initialState: Devic
|
|||
super.onCleared()
|
||||
}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
override fun transactionUpdated(tx: SasVerificationTransaction) {
|
||||
if(tx.state == SasVerificationTxState.Verified) {
|
||||
override fun transactionCreated(tx: VerificationTransaction) {}
|
||||
override fun transactionUpdated(tx: VerificationTransaction) {
|
||||
if(tx.state == VerificationTxState.Verified) {
|
||||
refreshDevicesList()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue