1use std::{collections::HashMap, sync::Arc};
16
17use matrix_sdk_common::locks::RwLock as StdRwLock;
18use ruma::{
19 events::{
20 key::verification::VerificationMethod, AnyToDeviceEvent, AnyToDeviceEventContent,
21 ToDeviceEvent,
22 },
23 serde::Raw,
24 uint, DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId,
25 SecondsSinceUnixEpoch, TransactionId, UInt, UserId,
26};
27use tokio::sync::Mutex;
28use tracing::{debug, info, instrument, trace, warn, Span};
29
30use super::{
31 cache::{RequestInfo, VerificationCache},
32 event_enums::{AnyEvent, AnyVerificationContent, OutgoingContent},
33 requests::VerificationRequest,
34 sas::Sas,
35 FlowId, Verification, VerificationResult, VerificationStore,
36};
37use crate::{
38 olm::{PrivateCrossSigningIdentity, StaticAccountData},
39 store::{CryptoStoreError, CryptoStoreWrapper},
40 types::requests::{
41 OutgoingRequest, OutgoingVerificationRequest, RoomMessageRequest, ToDeviceRequest,
42 },
43 DeviceData, OtherUserIdentityData,
44};
45
46#[derive(Clone, Debug)]
47pub struct VerificationMachine {
48 pub(crate) store: VerificationStore,
49 verifications: VerificationCache,
50 requests: Arc<StdRwLock<HashMap<OwnedUserId, HashMap<String, VerificationRequest>>>>,
51}
52
53impl VerificationMachine {
54 pub(crate) fn new(
55 account: StaticAccountData,
56 identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
57 store: Arc<CryptoStoreWrapper>,
58 ) -> Self {
59 Self {
60 store: VerificationStore { account, private_identity: identity, inner: store },
61 verifications: VerificationCache::new(),
62 requests: Default::default(),
63 }
64 }
65
66 pub(crate) fn own_user_id(&self) -> &UserId {
67 &self.store.account.user_id
68 }
69
70 pub(crate) fn own_device_id(&self) -> &DeviceId {
71 &self.store.account.device_id
72 }
73
74 pub(crate) fn request_to_device_verification(
75 &self,
76 user_id: &UserId,
77 recipient_devices: Vec<OwnedDeviceId>,
78 methods: Option<Vec<VerificationMethod>>,
79 ) -> (VerificationRequest, OutgoingVerificationRequest) {
80 let flow_id = FlowId::from(TransactionId::new());
81
82 let verification = VerificationRequest::new(
83 self.verifications.clone(),
84 self.store.clone(),
85 flow_id,
86 user_id,
87 recipient_devices,
88 methods,
89 );
90
91 self.insert_request(verification.clone());
92
93 let request = verification.request_to_device();
94
95 (verification, request.into())
96 }
97
98 pub fn request_verification(
99 &self,
100 identity: &OtherUserIdentityData,
101 room_id: &RoomId,
102 request_event_id: &EventId,
103 methods: Option<Vec<VerificationMethod>>,
104 ) -> VerificationRequest {
105 let flow_id = FlowId::InRoom(room_id.to_owned(), request_event_id.to_owned());
106
107 let request = VerificationRequest::new(
108 self.verifications.clone(),
109 self.store.clone(),
110 flow_id,
111 identity.user_id(),
112 vec![],
113 methods,
114 );
115
116 self.insert_request(request.clone());
117
118 request
119 }
120
121 pub async fn start_sas(
122 &self,
123 device: DeviceData,
124 ) -> Result<(Sas, OutgoingVerificationRequest), CryptoStoreError> {
125 let identities = self.store.get_identities(device.clone()).await?;
126 let (sas, content) = Sas::start(identities, TransactionId::new(), true, None, None);
127
128 let request = match content {
129 OutgoingContent::Room(r, c) => {
130 RoomMessageRequest { room_id: r, txn_id: TransactionId::new(), content: c }.into()
131 }
132 OutgoingContent::ToDevice(c) => {
133 let request = ToDeviceRequest::with_id(
134 device.user_id(),
135 device.device_id().to_owned(),
136 &c,
137 TransactionId::new(),
138 );
139
140 self.verifications.insert_sas(sas.clone());
141
142 request.into()
143 }
144 };
145
146 Ok((sas, request))
147 }
148
149 pub fn get_request(
150 &self,
151 user_id: &UserId,
152 flow_id: impl AsRef<str>,
153 ) -> Option<VerificationRequest> {
154 self.requests.read().get(user_id)?.get(flow_id.as_ref()).cloned()
155 }
156
157 pub fn get_requests(&self, user_id: &UserId) -> Vec<VerificationRequest> {
158 self.requests.read().get(user_id).map(|v| v.values().cloned().collect()).unwrap_or_default()
159 }
160
161 fn insert_request(&self, request: VerificationRequest) {
165 if let Some(r) = self.get_request(request.other_user(), request.flow_id().as_str()) {
166 debug!(flow_id = r.flow_id().as_str(), "Ignoring known verification request",);
167 return;
168 }
169
170 let mut requests = self.requests.write();
171 let user_requests = requests.entry(request.other_user().to_owned()).or_default();
172
173 for old_verification in user_requests.values_mut() {
177 if !old_verification.is_cancelled() {
178 warn!(
179 "Received a new verification request whilst another request \
180 with the same user is ongoing. Cancelling both requests."
181 );
182
183 if let Some(r) = old_verification.cancel() {
184 self.verifications.add_request(r.into())
185 }
186
187 if let Some(r) = request.cancel() {
188 self.verifications.add_request(r.into())
189 }
190 }
191 }
192
193 user_requests.insert(request.flow_id().as_str().to_owned(), request);
197 }
198
199 pub fn get_verification(&self, user_id: &UserId, flow_id: &str) -> Option<Verification> {
200 self.verifications.get(user_id, flow_id)
201 }
202
203 pub fn get_sas(&self, user_id: &UserId, flow_id: &str) -> Option<Box<Sas>> {
204 self.verifications.get_sas(user_id, flow_id)
205 }
206
207 fn is_timestamp_valid(timestamp: MilliSecondsSinceUnixEpoch) -> bool {
208 let old_timestamp_threshold: UInt = uint!(600);
210 let timestamp_threshold: UInt = uint!(300);
213
214 let timestamp = timestamp.as_secs();
215 let now = SecondsSinceUnixEpoch::now().get();
216
217 !(now.saturating_sub(timestamp) > old_timestamp_threshold
218 || timestamp.saturating_sub(now) > timestamp_threshold)
219 }
220
221 fn queue_up_content(
222 &self,
223 recipient: &UserId,
224 recipient_device: &DeviceId,
225 content: OutgoingContent,
226 request_id: Option<RequestInfo>,
227 ) {
228 self.verifications.queue_up_content(recipient, recipient_device, content, request_id)
229 }
230
231 pub fn mark_request_as_sent(&self, request_id: &TransactionId) {
232 self.verifications.mark_request_as_sent(request_id);
233 }
234
235 pub fn outgoing_messages(&self) -> Vec<OutgoingRequest> {
236 self.verifications.outgoing_requests()
237 }
238
239 pub fn garbage_collect(&self) -> Vec<Raw<AnyToDeviceEvent>> {
240 let mut events = vec![];
241
242 let mut requests: Vec<OutgoingVerificationRequest> = {
243 let mut requests = self.requests.write();
244
245 for user_verification in requests.values_mut() {
246 user_verification.retain(|_, v| !(v.is_done() || v.is_cancelled()));
247 }
248 requests.retain(|_, v| !v.is_empty());
249
250 requests.values().flatten().filter_map(|(_, v)| v.cancel_if_timed_out()).collect()
251 };
252
253 requests.extend(self.verifications.garbage_collect());
254
255 for request in requests {
256 if let Ok(OutgoingContent::ToDevice(to_device)) = request.clone().try_into() {
257 if let AnyToDeviceEventContent::KeyVerificationCancel(content) = *to_device {
258 let event = ToDeviceEvent::new(self.own_user_id().to_owned(), content);
259
260 events.push(
261 Raw::new(&event)
262 .expect("Failed to serialize m.key_verification.cancel event")
263 .cast(),
264 );
265 }
266 }
267
268 self.verifications.add_verification_request(request)
269 }
270
271 events
272 }
273
274 async fn mark_sas_as_done(
275 &self,
276 sas: &Sas,
277 out_content: Option<OutgoingContent>,
278 ) -> Result<(), CryptoStoreError> {
279 match sas.mark_as_done().await? {
280 VerificationResult::Ok => {
281 if let Some(c) = out_content {
282 self.queue_up_content(sas.other_user_id(), sas.other_device_id(), c, None);
283 }
284 }
285 VerificationResult::Cancel(c) => {
286 if let Some(r) = sas.cancel_with_code(c) {
287 self.verifications.add_request(r.into());
288 }
289 }
290 VerificationResult::SignatureUpload(r) => {
291 self.verifications.add_request(r.into());
292
293 if let Some(c) = out_content {
294 self.queue_up_content(sas.other_user_id(), sas.other_device_id(), c, None);
295 }
296 }
297 }
298
299 Ok(())
300 }
301
302 #[instrument(skip_all, fields(flow_id))]
303 pub async fn receive_any_event(
304 &self,
305 event: impl Into<AnyEvent<'_>>,
306 ) -> Result<(), CryptoStoreError> {
307 let event = event.into();
308
309 let Ok(flow_id) = FlowId::try_from(&event) else {
310 return Ok(());
312 };
313 Span::current().record("flow_id", flow_id.as_str());
314
315 let flow_id_mismatch = || {
316 warn!(
317 flow_id = flow_id.as_str(),
318 "Received a verification event with a mismatched flow id, \
319 the verification object was created for a in-room \
320 verification but an event was received over to-device \
321 messaging or vice versa"
322 );
323 };
324
325 let event_sent_from_us = |event: &AnyEvent<'_>, from_device: &DeviceId| {
326 if event.sender() == self.store.account.user_id {
327 from_device == self.store.account.device_id || event.is_room_event()
328 } else {
329 false
330 }
331 };
332
333 let Some(content) = event.verification_content() else { return Ok(()) };
334 match &content {
335 AnyVerificationContent::Request(r) => {
336 info!(
337 sender = ?event.sender(),
338 from_device = r.from_device().as_str(),
339 "Received a new verification request",
340 );
341
342 let Some(timestamp) = event.timestamp() else {
343 warn!(
344 from_device = r.from_device().as_str(),
345 "The key verification request didn't contain a valid timestamp"
346 );
347 return Ok(());
348 };
349
350 if !Self::is_timestamp_valid(timestamp) {
351 info!(
352 from_device = r.from_device().as_str(),
353 ?timestamp,
354 "The received verification request was too old or too far into the future",
355 );
356 return Ok(());
357 }
358
359 if event_sent_from_us(&event, r.from_device()) {
360 trace!(
361 from_device = r.from_device().as_str(),
362 "The received verification request was sent by us, ignoring it",
363 );
364 return Ok(());
365 }
366
367 let Some(device_data) =
368 self.store.get_device(event.sender(), r.from_device()).await?
369 else {
370 warn!(
371 "Could not retrieve the device data for the incoming verification request, \
372 ignoring it"
373 );
374 return Ok(());
375 };
376
377 let request = VerificationRequest::from_request(
378 self.verifications.clone(),
379 self.store.clone(),
380 event.sender(),
381 flow_id,
382 r,
383 device_data,
384 );
385
386 self.insert_request(request);
387 }
388 AnyVerificationContent::Cancel(c) => {
389 if let Some(verification) = self.get_request(event.sender(), flow_id.as_str()) {
390 verification.receive_cancel(event.sender(), c);
391 }
392
393 if let Some(verification) = self.get_verification(event.sender(), flow_id.as_str())
394 {
395 match verification {
396 Verification::SasV1(sas) => {
397 let _ = sas.receive_any_event(event.sender(), &content);
399 }
400 #[cfg(feature = "qrcode")]
401 Verification::QrV1(qr) => qr.receive_cancel(event.sender(), c),
402 }
403 }
404 }
405 AnyVerificationContent::Ready(c) => {
406 let Some(request) = self.get_request(event.sender(), flow_id.as_str()) else {
407 return Ok(());
408 };
409
410 if request.flow_id() == &flow_id {
411 if let Some(device_data) =
412 self.store.get_device(event.sender(), c.from_device()).await?
413 {
414 request.receive_ready(event.sender(), c, device_data);
415 } else {
416 warn!("Could not retrieve the data for the accepting device, ignoring it");
417 }
418 } else {
419 flow_id_mismatch();
420 }
421 }
422 AnyVerificationContent::Start(c) => {
423 if let Some(request) = self.get_request(event.sender(), flow_id.as_str()) {
424 if request.flow_id() == &flow_id {
425 Box::pin(request.receive_start(event.sender(), c)).await?
426 } else {
427 flow_id_mismatch();
428 }
429 } else if let FlowId::ToDevice(_) = flow_id {
430 if let Some(device) =
433 self.store.get_device(event.sender(), c.from_device()).await?
434 {
435 let identities = self.store.get_identities(device).await?;
436
437 match Sas::from_start_event(flow_id, c, identities, None, false) {
438 Ok(sas) => {
439 self.verifications.insert_sas(sas);
440 }
441 Err(cancellation) => self.queue_up_content(
442 event.sender(),
443 c.from_device(),
444 cancellation,
445 None,
446 ),
447 }
448 }
449 }
450 }
451 AnyVerificationContent::Accept(_) | AnyVerificationContent::Key(_) => {
452 let Some(sas) = self.get_sas(event.sender(), flow_id.as_str()) else {
453 return Ok(());
454 };
455
456 if sas.flow_id() != &flow_id {
457 flow_id_mismatch();
458 return Ok(());
459 }
460
461 let Some((content, request_info)) = sas.receive_any_event(event.sender(), &content)
462 else {
463 return Ok(());
464 };
465
466 self.queue_up_content(
467 sas.other_user_id(),
468 sas.other_device_id(),
469 content,
470 request_info,
471 );
472 }
473 AnyVerificationContent::Mac(_) => {
474 let Some(s) = self.get_sas(event.sender(), flow_id.as_str()) else { return Ok(()) };
475
476 if s.flow_id() != &flow_id {
477 flow_id_mismatch();
478 return Ok(());
479 }
480
481 let content = s.receive_any_event(event.sender(), &content);
482
483 if s.is_done() {
484 Box::pin(self.mark_sas_as_done(&s, content.map(|(c, _)| c))).await?;
485 } else {
486 let Some((content, request_id)) = content else { return Ok(()) };
491
492 self.queue_up_content(
493 s.other_user_id(),
494 s.other_device_id(),
495 content,
496 request_id,
497 );
498 }
499 }
500 AnyVerificationContent::Done(c) => {
501 if let Some(verification) = self.get_request(event.sender(), flow_id.as_str()) {
502 verification.receive_done(event.sender(), c);
503 }
504
505 #[allow(clippy::single_match)]
506 match self.get_verification(event.sender(), flow_id.as_str()) {
507 Some(Verification::SasV1(sas)) => {
508 let content = sas.receive_any_event(event.sender(), &content);
509
510 if sas.is_done() {
511 Box::pin(self.mark_sas_as_done(&sas, content.map(|(c, _)| c))).await?;
512 }
513 }
514 #[cfg(feature = "qrcode")]
515 Some(Verification::QrV1(qr)) => {
516 let (cancellation, request) = Box::pin(qr.receive_done(c)).await?;
517
518 if let Some(c) = cancellation {
519 self.verifications.add_request(c.into())
520 }
521
522 if let Some(s) = request {
523 self.verifications.add_request(s.into())
524 }
525 }
526 None => {}
527 }
528 }
529 }
530
531 Ok(())
532 }
533
534 #[cfg(test)]
540 pub async fn get_own_user_identity_data(
541 &self,
542 ) -> Result<crate::OwnUserIdentityData, crate::SignatureError> {
543 self.store.private_identity.lock().await.to_public_identity().await
544 }
545}
546
547#[cfg(test)]
548mod tests {
549 use std::sync::Arc;
550
551 use matrix_sdk_test::async_test;
552 use ruma::TransactionId;
553 use tokio::sync::Mutex;
554
555 use super::{Sas, VerificationMachine};
556 use crate::{
557 olm::PrivateCrossSigningIdentity,
558 store::{CryptoStoreWrapper, MemoryStore},
559 verification::{
560 cache::VerificationCache,
561 event_enums::{AcceptContent, KeyContent, MacContent, OutgoingContent},
562 tests::{alice_device_id, alice_id, setup_stores, wrap_any_to_device_content},
563 FlowId, VerificationStore,
564 },
565 Account, VerificationRequest,
566 };
567
568 async fn verification_machine() -> (VerificationMachine, VerificationStore) {
569 let (_account, store, _bob, bob_store) = setup_stores().await;
570
571 let machine = VerificationMachine {
572 store,
573 verifications: VerificationCache::new(),
574 requests: Default::default(),
575 };
576
577 (machine, bob_store)
578 }
579
580 async fn setup_verification_machine() -> (VerificationMachine, Sas) {
581 let (machine, bob_store) = verification_machine().await;
582
583 let alice_device =
584 bob_store.get_device(alice_id(), alice_device_id()).await.unwrap().unwrap();
585
586 let identities = bob_store.get_identities(alice_device).await.unwrap();
587 let (bob_sas, start_content) =
588 Sas::start(identities, TransactionId::new(), true, None, None);
589
590 machine
591 .receive_any_event(&wrap_any_to_device_content(bob_sas.user_id(), start_content))
592 .await
593 .unwrap();
594
595 (machine, bob_sas)
596 }
597
598 #[async_test]
599 async fn test_create() {
600 let alice = Account::with_device_id(alice_id(), alice_device_id());
601 let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id())));
602 let _ = VerificationMachine::new(
603 alice.static_data,
604 identity,
605 Arc::new(CryptoStoreWrapper::new(alice_id(), alice_device_id(), MemoryStore::new())),
606 );
607 }
608
609 #[async_test]
610 async fn test_full_flow() {
611 let (alice_machine, bob) = setup_verification_machine().await;
612
613 let alice = alice_machine.get_sas(bob.user_id(), bob.flow_id().as_str()).unwrap();
614
615 let request = alice.accept().unwrap();
616
617 let content = OutgoingContent::try_from(request).unwrap();
618 let content = AcceptContent::try_from(&content).unwrap().into();
619
620 let (content, request_info) = bob.receive_any_event(alice.user_id(), &content).unwrap();
621
622 let event = wrap_any_to_device_content(bob.user_id(), content);
623
624 assert!(alice_machine.verifications.outgoing_requests().is_empty());
625 alice_machine.receive_any_event(&event).await.unwrap();
626 assert!(!alice_machine.verifications.outgoing_requests().is_empty());
627
628 let request = alice_machine.verifications.outgoing_requests().first().cloned().unwrap();
629 let txn_id = request.request_id().to_owned();
630 let content = OutgoingContent::try_from(request).unwrap();
631 let content = KeyContent::try_from(&content).unwrap().into();
632
633 alice_machine.mark_request_as_sent(&txn_id);
634
635 assert!(bob.receive_any_event(alice.user_id(), &content).is_none());
636
637 assert!(alice.emoji().is_some());
638 assert!(bob.emoji().is_none());
641 bob.mark_request_as_sent(&request_info.unwrap().request_id);
642 assert!(bob.emoji().is_some());
643 assert_eq!(alice.emoji(), bob.emoji());
644
645 let mut requests = alice.confirm().await.unwrap().0;
646 assert!(requests.len() == 1);
647 let request = requests.pop().unwrap();
648 let content = OutgoingContent::try_from(request).unwrap();
649 let content = MacContent::try_from(&content).unwrap().into();
650 bob.receive_any_event(alice.user_id(), &content);
651
652 let mut requests = bob.confirm().await.unwrap().0;
653 assert!(requests.len() == 1);
654 let request = requests.pop().unwrap();
655 let content = OutgoingContent::try_from(request).unwrap();
656 let content = MacContent::try_from(&content).unwrap().into();
657 alice.receive_any_event(bob.user_id(), &content);
658
659 assert!(alice.is_done());
660 assert!(bob.is_done());
661 }
662
663 #[cfg(not(target_os = "macos"))]
664 #[allow(unknown_lints, clippy::unchecked_duration_subtraction)]
665 #[async_test]
666 async fn test_timing_out() {
667 use std::time::Duration;
668
669 use ruma::time::Instant;
670
671 let (alice_machine, bob) = setup_verification_machine().await;
672 let alice = alice_machine.get_sas(bob.user_id(), bob.flow_id().as_str()).unwrap();
673
674 assert!(!alice.timed_out());
675 assert!(alice_machine.verifications.outgoing_requests().is_empty());
676
677 alice.set_creation_time(Instant::now() - Duration::from_secs(60 * 15));
679 assert!(alice.timed_out());
680 assert!(alice_machine.verifications.outgoing_requests().is_empty());
681 alice_machine.garbage_collect();
682 assert!(!alice_machine.verifications.outgoing_requests().is_empty());
683 alice_machine.garbage_collect();
684 assert!(alice_machine.verifications.is_empty());
685 }
686
687 #[async_test]
690 async fn test_double_verification_cancellation() {
691 let (machine, bob_store) = verification_machine().await;
692
693 let alice_device =
694 bob_store.get_device(alice_id(), alice_device_id()).await.unwrap().unwrap();
695 let identities = bob_store.get_identities(alice_device).await.unwrap();
696
697 let (bob_sas, start_content) =
699 Sas::start(identities.clone(), TransactionId::new(), true, None, None);
700
701 machine
702 .receive_any_event(&wrap_any_to_device_content(bob_sas.user_id(), start_content))
703 .await
704 .unwrap();
705
706 let alice_sas = machine.get_sas(bob_sas.user_id(), bob_sas.flow_id().as_str()).unwrap();
707
708 assert!(!alice_sas.is_cancelled());
710
711 let second_transaction_id = TransactionId::new();
712 let (bob_sas, start_content) =
713 Sas::start(identities, second_transaction_id.clone(), true, None, None);
714 machine
715 .receive_any_event(&wrap_any_to_device_content(bob_sas.user_id(), start_content))
716 .await
717 .unwrap();
718
719 let second_sas = machine.get_sas(bob_sas.user_id(), bob_sas.flow_id().as_str()).unwrap();
720
721 assert_eq!(second_sas.flow_id().as_str(), second_transaction_id);
723
724 assert!(alice_sas.is_cancelled());
726 assert!(second_sas.is_cancelled());
727 }
728
729 #[async_test]
732 async fn test_double_verification_request_cancellation() {
733 let (machine, bob_store) = verification_machine().await;
734
735 let flow_id = FlowId::ToDevice("TEST_FLOW_ID".into());
737
738 let bob_request = VerificationRequest::new(
739 VerificationCache::new(),
740 bob_store.clone(),
741 flow_id.clone(),
742 alice_id(),
743 vec![],
744 None,
745 );
746
747 let request = bob_request.request_to_device();
748 let content: OutgoingContent = request.try_into().unwrap();
749
750 machine
751 .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content))
752 .await
753 .unwrap();
754
755 let alice_request =
756 machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap();
757
758 assert!(!alice_request.is_cancelled());
760
761 let second_transaction_id = TransactionId::new();
762 let bob_request = VerificationRequest::new(
763 VerificationCache::new(),
764 bob_store,
765 second_transaction_id.clone().into(),
766 alice_id(),
767 vec![],
768 None,
769 );
770
771 let request = bob_request.request_to_device();
772 let content: OutgoingContent = request.try_into().unwrap();
773
774 machine
775 .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content))
776 .await
777 .unwrap();
778
779 let second_request =
780 machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap();
781
782 assert_eq!(second_request.flow_id().as_str(), second_transaction_id);
784
785 assert!(alice_request.is_cancelled());
787 assert!(second_request.is_cancelled());
788 }
789
790 #[async_test]
794 async fn test_ignore_identical_verification_request() {
795 let (machine, bob_store) = verification_machine().await;
796
797 let flow_id = FlowId::ToDevice("TEST_FLOW_ID".into());
799
800 let bob_request = VerificationRequest::new(
801 VerificationCache::new(),
802 bob_store.clone(),
803 flow_id.clone(),
804 alice_id(),
805 vec![],
806 None,
807 );
808
809 let request = bob_request.request_to_device();
810 let content: OutgoingContent = request.try_into().unwrap();
811
812 machine
813 .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content))
814 .await
815 .unwrap();
816
817 let first_request =
818 machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap();
819
820 assert!(!first_request.is_cancelled());
822
823 let bob_request = VerificationRequest::new(
825 VerificationCache::new(),
826 bob_store,
827 flow_id.clone(),
828 alice_id(),
829 vec![],
830 None,
831 );
832
833 let request = bob_request.request_to_device();
834 let content: OutgoingContent = request.try_into().unwrap();
835
836 machine
837 .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content))
838 .await
839 .unwrap();
840
841 let second_request =
842 machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap();
843
844 assert!(!first_request.is_cancelled());
846 assert!(!second_request.is_cancelled());
847 }
848}