diff --git a/matrix_sdk/src/device.rs b/matrix_sdk/src/device.rs index 44812ba1..1ffb51c5 100644 --- a/matrix_sdk/src/device.rs +++ b/matrix_sdk/src/device.rs @@ -61,7 +61,7 @@ impl Device { /// # }); /// ``` pub async fn start_verification(&self) -> Result { - let (sas, request) = self.inner.start_verification(); + let (sas, request) = self.inner.start_verification().await?; let request = ToDeviceRequest { event_type: request.event_type, txn_id: &request.txn_id, diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/device.rs index f8eb6e49..b6fbcbd9 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/device.rs @@ -72,8 +72,10 @@ impl Device { /// Start a interactive verification with this `Device` /// /// Returns a `Sas` object and to-device request that needs to be sent out. - pub fn start_verification(&self) -> (Sas, OwnedToDeviceRequest) { - self.verification_machine.start_sas(self.inner.clone()) + pub async fn start_verification(&self) -> StoreResult<(Sas, OwnedToDeviceRequest)> { + self.verification_machine + .start_sas(self.inner.clone()) + .await } /// Set the trust state of the device to the given state. diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 2543b518..3fb2e912 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -2063,7 +2063,7 @@ pub(crate) mod test { assert!(!bob_device.is_trusted()); - let (alice_sas, request) = bob_device.start_verification(); + let (alice_sas, request) = bob_device.start_verification().await.unwrap(); let mut event = request_to_event(alice.user_id(), &request); bob.handle_verification_event(&mut event).await; diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index d6382b7a..d496fcad 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -45,8 +45,19 @@ impl VerificationMachine { } } - pub fn start_sas(&self, device: ReadOnlyDevice) -> (Sas, OwnedToDeviceRequest) { - let (sas, content) = Sas::start(self.account.clone(), device.clone(), self.store.clone()); + pub async fn start_sas( + &self, + device: ReadOnlyDevice, + ) -> Result<(Sas, OwnedToDeviceRequest), CryptoStoreError> { + let identity = self.store.get_user_identity(device.user_id()).await?; + + let (sas, content) = Sas::start( + self.account.clone(), + device.clone(), + self.store.clone(), + identity, + ); + let request = content_to_request( device.user_id(), device.device_id(), @@ -56,7 +67,7 @@ impl VerificationMachine { self.verifications .insert(sas.flow_id().to_owned(), sas.clone()); - (sas, request) + Ok((sas, request)) } pub fn get_sas(&self, transaction_id: &str) -> Option { @@ -128,7 +139,13 @@ impl VerificationMachine { .get_device(&e.sender, &e.content.from_device) .await? { - match Sas::from_start_event(self.account.clone(), d, self.store.clone(), e) { + match Sas::from_start_event( + self.account.clone(), + d, + self.store.clone(), + e, + None, + ) { Ok(s) => { self.verifications .insert(e.content.transaction_id.clone(), s); @@ -231,7 +248,7 @@ mod test { .unwrap(); let machine = VerificationMachine::new(alice, Arc::new(Box::new(store))); - let (bob_sas, start_content) = Sas::start(bob, alice_device, bob_store); + let (bob_sas, start_content) = Sas::start(bob, alice_device, bob_store, None); machine .receive_event(&mut wrap_any_to_device_content( bob_sas.user_id(), diff --git a/matrix_sdk_crypto/src/verification/sas/mod.rs b/matrix_sdk_crypto/src/verification/sas/mod.rs index 6e79a4e5..eebcac46 100644 --- a/matrix_sdk_crypto/src/verification/sas/mod.rs +++ b/matrix_sdk_crypto/src/verification/sas/mod.rs @@ -33,7 +33,10 @@ use matrix_sdk_common::{ identifiers::{DeviceId, UserId}, }; -use crate::{Account, CryptoStore, CryptoStoreError, ReadOnlyDevice, TrustState}; +use crate::{ + user_identity::UserIdentities, Account, CryptoStore, CryptoStoreError, ReadOnlyDevice, + TrustState, +}; pub use helpers::content_to_request; use sas_state::{ @@ -47,6 +50,7 @@ pub struct Sas { store: Arc>, account: Account, other_device: ReadOnlyDevice, + other_identity: Option, flow_id: Arc, } @@ -101,6 +105,7 @@ impl Sas { account: Account, other_device: ReadOnlyDevice, store: Arc>, + other_identity: Option, ) -> (Sas, StartEventContent) { let (inner, content) = InnerSas::start(account.clone(), other_device.clone()); let flow_id = inner.verification_flow_id(); @@ -111,6 +116,7 @@ impl Sas { store, other_device, flow_id, + other_identity, }; (sas, content) @@ -131,6 +137,7 @@ impl Sas { other_device: ReadOnlyDevice, store: Arc>, event: &ToDeviceEvent, + other_identity: Option, ) -> Result { let inner = InnerSas::from_start_event(account.clone(), other_device.clone(), event)?; let flow_id = inner.verification_flow_id(); @@ -138,6 +145,7 @@ impl Sas { inner: Arc::new(Mutex::new(inner)), account, other_device, + other_identity, store, flow_id, }) @@ -683,10 +691,10 @@ mod test { .await .unwrap(); - let (alice, content) = Sas::start(alice, bob_device, alice_store); + let (alice, content) = Sas::start(alice, bob_device, alice_store, None); let event = wrap_to_device_event(alice.user_id(), content); - let bob = Sas::from_start_event(bob, alice_device, bob_store, &event).unwrap(); + let bob = Sas::from_start_event(bob, alice_device, bob_store, &event, None).unwrap(); let mut event = wrap_any_to_device_content( bob.user_id(), get_content_from_request(&bob.accept().unwrap()),