crypto: Store the verified identities in the SAS states.

master
Damir Jelić 2020-08-19 14:28:16 +02:00
parent 90ea0229f2
commit 3990e50ca6
3 changed files with 24 additions and 5 deletions

View File

@ -159,7 +159,7 @@ pub fn receive_mac_event(
ids: &SasIds, ids: &SasIds,
flow_id: &str, flow_id: &str,
event: &ToDeviceEvent<MacEventContent>, event: &ToDeviceEvent<MacEventContent>,
) -> Result<(Vec<ReadOnlyDevice>, Vec<String>), CancelCode> { ) -> Result<(Vec<ReadOnlyDevice>, Vec<UserIdentities>), CancelCode> {
let mut verified_devices = Vec::new(); let mut verified_devices = Vec::new();
let mut verified_identities = Vec::new(); let mut verified_identities = Vec::new();
@ -217,7 +217,7 @@ pub fn receive_mac_event(
key_id, key_id,
event.sender event.sender
); );
verified_identities.push(identity) verified_identities.push(identity.clone())
} else { } else {
return Err(CancelCode::KeyMismatch); return Err(CancelCode::KeyMismatch);
} }
@ -233,7 +233,7 @@ pub fn receive_mac_event(
} }
} }
Ok((verified_devices, vec![])) Ok((verified_devices, verified_identities))
} }
/// Get the extra info that will be used when we generate a MAC and need to send /// Get the extra info that will be used when we generate a MAC and need to send

View File

@ -150,6 +150,7 @@ impl Sas {
other_identity.clone(), other_identity.clone(),
)?; )?;
let flow_id = inner.verification_flow_id(); let flow_id = inner.verification_flow_id();
Ok(Sas { Ok(Sas {
inner: Arc::new(Mutex::new(inner)), inner: Arc::new(Mutex::new(inner)),
account, account,
@ -334,6 +335,11 @@ impl Sas {
self.inner.lock().unwrap().verified_devices() self.inner.lock().unwrap().verified_devices()
} }
#[allow(dead_code)]
pub(crate) fn verified_identities(&self) -> Option<Arc<Vec<UserIdentities>>> {
self.inner.lock().unwrap().verified_identities()
}
pub(crate) fn content_to_request( pub(crate) fn content_to_request(
&self, &self,
content: AnyToDeviceEventContent, content: AnyToDeviceEventContent,
@ -564,6 +570,14 @@ impl InnerSas {
None None
} }
} }
fn verified_identities(&self) -> Option<Arc<Vec<UserIdentities>>> {
if let InnerSas::Done(s) = self {
Some(s.verified_identities())
} else {
None
}
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -207,7 +207,7 @@ pub struct MacReceived {
we_started: bool, we_started: bool,
their_pubkey: String, their_pubkey: String,
verified_devices: Arc<Vec<ReadOnlyDevice>>, verified_devices: Arc<Vec<ReadOnlyDevice>>,
verified_master_keys: Arc<Vec<String>>, verified_master_keys: Arc<Vec<UserIdentities>>,
} }
/// The SAS state indicating that the verification finished successfully. /// The SAS state indicating that the verification finished successfully.
@ -217,7 +217,7 @@ pub struct MacReceived {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Done { pub struct Done {
verified_devices: Arc<Vec<ReadOnlyDevice>>, verified_devices: Arc<Vec<ReadOnlyDevice>>,
verified_master_keys: Arc<Vec<String>>, verified_master_keys: Arc<Vec<UserIdentities>>,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -791,6 +791,11 @@ impl SasState<Done> {
pub fn verified_devices(&self) -> Arc<Vec<ReadOnlyDevice>> { pub fn verified_devices(&self) -> Arc<Vec<ReadOnlyDevice>> {
self.state.verified_devices.clone() self.state.verified_devices.clone()
} }
/// Get the list of verified identities.
pub fn verified_identities(&self) -> Arc<Vec<UserIdentities>> {
self.state.verified_master_keys.clone()
}
} }
impl Canceled { impl Canceled {