crypto: Pass the user identity to the SAS object when doing verifications.
parent
f96437a242
commit
6d0b73cb3d
|
@ -61,7 +61,7 @@ impl Device {
|
||||||
/// # });
|
/// # });
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn start_verification(&self) -> Result<Sas> {
|
pub async fn start_verification(&self) -> Result<Sas> {
|
||||||
let (sas, request) = self.inner.start_verification();
|
let (sas, request) = self.inner.start_verification().await?;
|
||||||
let request = ToDeviceRequest {
|
let request = ToDeviceRequest {
|
||||||
event_type: request.event_type,
|
event_type: request.event_type,
|
||||||
txn_id: &request.txn_id,
|
txn_id: &request.txn_id,
|
||||||
|
|
|
@ -72,8 +72,10 @@ impl Device {
|
||||||
/// Start a interactive verification with this `Device`
|
/// Start a interactive verification with this `Device`
|
||||||
///
|
///
|
||||||
/// Returns a `Sas` object and to-device request that needs to be sent out.
|
/// Returns a `Sas` object and to-device request that needs to be sent out.
|
||||||
pub fn start_verification(&self) -> (Sas, OwnedToDeviceRequest) {
|
pub async fn start_verification(&self) -> StoreResult<(Sas, OwnedToDeviceRequest)> {
|
||||||
self.verification_machine.start_sas(self.inner.clone())
|
self.verification_machine
|
||||||
|
.start_sas(self.inner.clone())
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the trust state of the device to the given state.
|
/// Set the trust state of the device to the given state.
|
||||||
|
|
|
@ -2063,7 +2063,7 @@ pub(crate) mod test {
|
||||||
|
|
||||||
assert!(!bob_device.is_trusted());
|
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);
|
let mut event = request_to_event(alice.user_id(), &request);
|
||||||
bob.handle_verification_event(&mut event).await;
|
bob.handle_verification_event(&mut event).await;
|
||||||
|
|
|
@ -45,8 +45,19 @@ impl VerificationMachine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_sas(&self, device: ReadOnlyDevice) -> (Sas, OwnedToDeviceRequest) {
|
pub async fn start_sas(
|
||||||
let (sas, content) = Sas::start(self.account.clone(), device.clone(), self.store.clone());
|
&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(
|
let request = content_to_request(
|
||||||
device.user_id(),
|
device.user_id(),
|
||||||
device.device_id(),
|
device.device_id(),
|
||||||
|
@ -56,7 +67,7 @@ impl VerificationMachine {
|
||||||
self.verifications
|
self.verifications
|
||||||
.insert(sas.flow_id().to_owned(), sas.clone());
|
.insert(sas.flow_id().to_owned(), sas.clone());
|
||||||
|
|
||||||
(sas, request)
|
Ok((sas, request))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_sas(&self, transaction_id: &str) -> Option<Sas> {
|
pub fn get_sas(&self, transaction_id: &str) -> Option<Sas> {
|
||||||
|
@ -128,7 +139,13 @@ impl VerificationMachine {
|
||||||
.get_device(&e.sender, &e.content.from_device)
|
.get_device(&e.sender, &e.content.from_device)
|
||||||
.await?
|
.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) => {
|
Ok(s) => {
|
||||||
self.verifications
|
self.verifications
|
||||||
.insert(e.content.transaction_id.clone(), s);
|
.insert(e.content.transaction_id.clone(), s);
|
||||||
|
@ -231,7 +248,7 @@ mod test {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let machine = VerificationMachine::new(alice, Arc::new(Box::new(store)));
|
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
|
machine
|
||||||
.receive_event(&mut wrap_any_to_device_content(
|
.receive_event(&mut wrap_any_to_device_content(
|
||||||
bob_sas.user_id(),
|
bob_sas.user_id(),
|
||||||
|
|
|
@ -33,7 +33,10 @@ use matrix_sdk_common::{
|
||||||
identifiers::{DeviceId, UserId},
|
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;
|
pub use helpers::content_to_request;
|
||||||
use sas_state::{
|
use sas_state::{
|
||||||
|
@ -47,6 +50,7 @@ pub struct Sas {
|
||||||
store: Arc<Box<dyn CryptoStore>>,
|
store: Arc<Box<dyn CryptoStore>>,
|
||||||
account: Account,
|
account: Account,
|
||||||
other_device: ReadOnlyDevice,
|
other_device: ReadOnlyDevice,
|
||||||
|
other_identity: Option<UserIdentities>,
|
||||||
flow_id: Arc<String>,
|
flow_id: Arc<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +105,7 @@ impl Sas {
|
||||||
account: Account,
|
account: Account,
|
||||||
other_device: ReadOnlyDevice,
|
other_device: ReadOnlyDevice,
|
||||||
store: Arc<Box<dyn CryptoStore>>,
|
store: Arc<Box<dyn CryptoStore>>,
|
||||||
|
other_identity: Option<UserIdentities>,
|
||||||
) -> (Sas, StartEventContent) {
|
) -> (Sas, StartEventContent) {
|
||||||
let (inner, content) = InnerSas::start(account.clone(), other_device.clone());
|
let (inner, content) = InnerSas::start(account.clone(), other_device.clone());
|
||||||
let flow_id = inner.verification_flow_id();
|
let flow_id = inner.verification_flow_id();
|
||||||
|
@ -111,6 +116,7 @@ impl Sas {
|
||||||
store,
|
store,
|
||||||
other_device,
|
other_device,
|
||||||
flow_id,
|
flow_id,
|
||||||
|
other_identity,
|
||||||
};
|
};
|
||||||
|
|
||||||
(sas, content)
|
(sas, content)
|
||||||
|
@ -131,6 +137,7 @@ impl Sas {
|
||||||
other_device: ReadOnlyDevice,
|
other_device: ReadOnlyDevice,
|
||||||
store: Arc<Box<dyn CryptoStore>>,
|
store: Arc<Box<dyn CryptoStore>>,
|
||||||
event: &ToDeviceEvent<StartEventContent>,
|
event: &ToDeviceEvent<StartEventContent>,
|
||||||
|
other_identity: Option<UserIdentities>,
|
||||||
) -> Result<Sas, AnyToDeviceEventContent> {
|
) -> Result<Sas, AnyToDeviceEventContent> {
|
||||||
let inner = InnerSas::from_start_event(account.clone(), other_device.clone(), event)?;
|
let inner = InnerSas::from_start_event(account.clone(), other_device.clone(), event)?;
|
||||||
let flow_id = inner.verification_flow_id();
|
let flow_id = inner.verification_flow_id();
|
||||||
|
@ -138,6 +145,7 @@ impl Sas {
|
||||||
inner: Arc::new(Mutex::new(inner)),
|
inner: Arc::new(Mutex::new(inner)),
|
||||||
account,
|
account,
|
||||||
other_device,
|
other_device,
|
||||||
|
other_identity,
|
||||||
store,
|
store,
|
||||||
flow_id,
|
flow_id,
|
||||||
})
|
})
|
||||||
|
@ -683,10 +691,10 @@ mod test {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.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 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(
|
let mut event = wrap_any_to_device_content(
|
||||||
bob.user_id(),
|
bob.user_id(),
|
||||||
get_content_from_request(&bob.accept().unwrap()),
|
get_content_from_request(&bob.accept().unwrap()),
|
||||||
|
|
Loading…
Reference in New Issue