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,
flow_id: &str,
event: &ToDeviceEvent<MacEventContent>,
) -> Result<(Vec<ReadOnlyDevice>, Vec<String>), CancelCode> {
) -> Result<(Vec<ReadOnlyDevice>, Vec<UserIdentities>), CancelCode> {
let mut verified_devices = Vec::new();
let mut verified_identities = Vec::new();
@ -217,7 +217,7 @@ pub fn receive_mac_event(
key_id,
event.sender
);
verified_identities.push(identity)
verified_identities.push(identity.clone())
} else {
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

View File

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

View File

@ -207,7 +207,7 @@ pub struct MacReceived {
we_started: bool,
their_pubkey: String,
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.
@ -217,7 +217,7 @@ pub struct MacReceived {
#[derive(Clone, Debug)]
pub struct Done {
verified_devices: Arc<Vec<ReadOnlyDevice>>,
verified_master_keys: Arc<Vec<String>>,
verified_master_keys: Arc<Vec<UserIdentities>>,
}
#[derive(Clone, Debug)]
@ -791,6 +791,11 @@ impl SasState<Done> {
pub fn verified_devices(&self) -> Arc<Vec<ReadOnlyDevice>> {
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 {