From df1fe0ebc417e57326bc23854e08cb91df9eb6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Jun 2021 17:16:40 +0200 Subject: [PATCH] crypto: Don't return a result when receiving a ready event Ready events might be invalid but we might receive a valid one later on, e.g. someone is trying to disrupt our verification, so just ignore invalid ready events. --- matrix_sdk_crypto/src/verification/machine.rs | 3 +-- matrix_sdk_crypto/src/verification/requests.rs | 11 ++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index 8278fc52..b8b21200 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -272,8 +272,7 @@ impl VerificationMachine { AnyVerificationContent::Ready(c) => { if let Some(request) = self.requests.get(flow_id.as_str()) { if request.flow_id() == &flow_id { - // TODO remove this unwrap. - request.receive_ready(event.sender(), c).unwrap(); + request.receive_ready(event.sender(), c); } else { flow_id_mismatch(); } diff --git a/matrix_sdk_crypto/src/verification/requests.rs b/matrix_sdk_crypto/src/verification/requests.rs index 363e4f29..bb5bbfa7 100644 --- a/matrix_sdk_crypto/src/verification/requests.rs +++ b/matrix_sdk_crypto/src/verification/requests.rs @@ -301,15 +301,12 @@ impl VerificationRequest { }) } - #[allow(clippy::unnecessary_wraps)] - pub(crate) fn receive_ready(&self, sender: &UserId, content: &ReadyContent) -> Result<(), ()> { + pub(crate) fn receive_ready(&self, sender: &UserId, content: &ReadyContent) { let mut inner = self.inner.lock().unwrap(); if let InnerRequest::Created(s) = &*inner { *inner = InnerRequest::Ready(s.clone().into_ready(sender, content)); } - - Ok(()) } pub(crate) async fn receive_start( @@ -932,7 +929,7 @@ mod test { let content: OutgoingContent = alice_request.accept().unwrap().into(); let content = ReadyContent::try_from(&content).unwrap(); - bob_request.receive_ready(&alice_id(), &content).unwrap(); + bob_request.receive_ready(&alice_id(), &content); assert!(bob_request.is_ready()); assert!(alice_request.is_ready()); @@ -985,7 +982,7 @@ mod test { let content: OutgoingContent = alice_request.accept().unwrap().into(); let content = ReadyContent::try_from(&content).unwrap(); - bob_request.receive_ready(&alice_id(), &content).unwrap(); + bob_request.receive_ready(&alice_id(), &content); assert!(bob_request.is_ready()); assert!(alice_request.is_ready()); @@ -1043,7 +1040,7 @@ mod test { let content: OutgoingContent = alice_request.accept().unwrap().into(); let content = ReadyContent::try_from(&content).unwrap(); - bob_request.receive_ready(&alice_id(), &content).unwrap(); + bob_request.receive_ready(&alice_id(), &content); assert!(bob_request.is_ready()); assert!(alice_request.is_ready());