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.
This commit is contained in:
Damir Jelić 2021-06-14 17:16:40 +02:00
parent 073b91fa62
commit df1fe0ebc4
2 changed files with 5 additions and 9 deletions

View file

@ -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();
}

View file

@ -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());