From 073b91fa6224a9e13df1a8a768a134d2d8f2b946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Jun 2021 17:08:31 +0200 Subject: [PATCH] crypto: Ignore verification requests that are sent by us --- .../src/verification/event_enums.rs | 4 ++ matrix_sdk_crypto/src/verification/machine.rs | 37 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/matrix_sdk_crypto/src/verification/event_enums.rs b/matrix_sdk_crypto/src/verification/event_enums.rs index 895e34b3..a8805d70 100644 --- a/matrix_sdk_crypto/src/verification/event_enums.rs +++ b/matrix_sdk_crypto/src/verification/event_enums.rs @@ -64,6 +64,10 @@ impl AnyEvent<'_> { } } + pub fn is_room_event(&self) -> bool { + matches!(self, AnyEvent::Room(_)) + } + pub fn verification_content(&self) -> Option { match self { AnyEvent::Room(e) => match e { diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index e9f7faf6..8278fc52 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -204,6 +204,14 @@ impl VerificationMachine { ); }; + let event_sent_from_us = |event: &AnyEvent<'_>, from_device: &DeviceId| { + if event.sender() == self.account.user_id() { + from_device == self.account.device_id() || event.is_room_event() + } else { + false + } + }; + if let Some(content) = event.verification_content() { match &content { AnyVerificationContent::Request(r) => { @@ -215,17 +223,26 @@ impl VerificationMachine { if let Some(timestamp) = event.timestamp() { if Self::is_timestamp_valid(timestamp) { - let request = VerificationRequest::from_request( - self.verifications.clone(), - self.account.clone(), - self.private_identity.lock().await.clone(), - self.store.clone(), - event.sender(), - flow_id, - r, - ); + if !event_sent_from_us(&event, r.from_device()) { + let request = VerificationRequest::from_request( + self.verifications.clone(), + self.account.clone(), + self.private_identity.lock().await.clone(), + self.store.clone(), + event.sender(), + flow_id, + r, + ); - self.requests.insert(request.flow_id().as_str().to_owned(), request); + self.requests + .insert(request.flow_id().as_str().to_owned(), request); + } else { + trace!( + sender = event.sender().as_str(), + from_device = r.from_device().as_str(), + "The received verification request was sent by us, ignoring it", + ); + } } else { trace!( sender = event.sender().as_str(),