From f9be4fa2bda5cb715c0e756bfd831412c86945a6 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 21 Feb 2020 14:04:55 +0100 Subject: [PATCH] Fixes #1047 --- .../tasks/RoomVerificationUpdateTask.kt | 23 +++++++++++-------- .../DefaultVerificationService.kt | 8 +++++-- .../verification/VerificationBottomSheet.kt | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt index d6118867ea..fa5bfe56d1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/RoomVerificationUpdateTask.kt @@ -83,11 +83,15 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor( } Timber.v("## SAS Verification live observer: received msgId: ${event.eventId} type: ${event.getClearType()}") + // Relates to is not encrypted + val relatesTo = event.content.toModel()?.relatesTo?.eventId + if (event.senderId == userId) { // If it's send from me, we need to keep track of Requests or Start // done from another device of mine - if (EventType.MESSAGE == event.type) { + + if (EventType.MESSAGE == event.getClearType()) { val msgType = event.getClearContent().toModel()?.msgType if (MessageType.MSGTYPE_VERIFICATION_REQUEST == msgType) { event.getClearContent().toModel()?.let { @@ -98,26 +102,26 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor( } } } - } else if (EventType.KEY_VERIFICATION_START == event.type) { + } else if (EventType.KEY_VERIFICATION_START == event.getClearType()) { event.getClearContent().toModel()?.let { if (it.fromDevice != deviceId) { // The verification is started from another device - Timber.v("## SAS Verification live observer: Transaction started by other device tid:${it.transactionID} ") - it.transactionID?.let { txId -> transactionsHandledByOtherDevice.add(txId) } + Timber.v("## SAS Verification live observer: Transaction started by other device tid:${relatesTo} ") + relatesTo?.let { txId -> transactionsHandledByOtherDevice.add(txId) } params.verificationService.onRoomRequestHandledByOtherDevice(event) } } - } else if (EventType.KEY_VERIFICATION_READY == event.type) { + } else if (EventType.KEY_VERIFICATION_READY == event.getClearType()) { event.getClearContent().toModel()?.let { if (it.fromDevice != deviceId) { // The verification is started from another device - Timber.v("## SAS Verification live observer: Transaction started by other device tid:${it.transactionID} ") - it.transactionID?.let { txId -> transactionsHandledByOtherDevice.add(txId) } + Timber.v("## SAS Verification live observer: Transaction started by other device tid:${relatesTo} ") + relatesTo?.let { txId -> transactionsHandledByOtherDevice.add(txId) } params.verificationService.onRoomRequestHandledByOtherDevice(event) } } - } else if (EventType.KEY_VERIFICATION_CANCEL == event.type || EventType.KEY_VERIFICATION_DONE == event.type) { - event.getClearContent().toModel()?.relatesTo?.eventId?.let { + } else if (EventType.KEY_VERIFICATION_CANCEL == event.getClearType() || EventType.KEY_VERIFICATION_DONE == event.getClearType()) { + relatesTo?.let { transactionsHandledByOtherDevice.remove(it) params.verificationService.onRoomRequestHandledByOtherDevice(event) } @@ -127,7 +131,6 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor( return@forEach } - val relatesTo = event.getClearContent().toModel()?.relatesTo?.eventId if (relatesTo != null && transactionsHandledByOtherDevice.contains(relatesTo)) { // Ignore this event, it is directed to another of my devices Timber.v("## SAS Verification live observer: Ignore Transaction handled by other device tid:$relatesTo ") diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt index fa1bfb3b98..5ea4b32e85 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultVerificationService.kt @@ -255,7 +255,7 @@ internal class DefaultVerificationService @Inject constructor( } fun onRoomRequestHandledByOtherDevice(event: Event) { - val requestInfo = event.getClearContent().toModel() + val requestInfo = event.content.toModel() ?: return val requestId = requestInfo.relatesTo?.eventId ?: return getExistingVerificationRequestInRoom(event.roomId ?: "", requestId)?.let { @@ -465,7 +465,11 @@ internal class DefaultVerificationService @Inject constructor( Timber.v("## SAS onStartRequestReceived - request accepted ${startReq.transactionID!!}") // If there is a corresponding request, we can auto accept // as we are the one requesting in first place (or we accepted the request) - val autoAccept = getExistingVerificationRequest(otherUserId)?.any { it.transactionId == startReq.transactionID } + // I need to check if the pending request was related to this device also + val autoAccept = getExistingVerificationRequest(otherUserId)?.any { + it.transactionId == startReq.transactionID + && (it.requestInfo?.fromDevice == this.deviceId || it.readyInfo?.fromDevice == this.deviceId) + } ?: false val tx = DefaultIncomingSASDefaultVerificationTransaction( // this, diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheet.kt b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheet.kt index 48c7827e87..61599c0f14 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/verification/VerificationBottomSheet.kt @@ -149,7 +149,7 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() { } } } - + if (state.selfVerificationMode && state.verifiedFromPrivateKeys) { showFragment(VerificationConclusionFragment::class, Bundle().apply { putParcelable(MvRx.KEY_ARG, VerificationConclusionFragment.Args(true, null, state.isMe))