crypto: WIP handle in-room start events.

master
Damir Jelić 2020-12-11 16:13:58 +01:00
parent 7570cf5ac2
commit 5105629c08
2 changed files with 31 additions and 8 deletions

View File

@ -46,7 +46,7 @@ pub struct VerificationMachine {
private_identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
pub(crate) store: Arc<Box<dyn CryptoStore>>,
verifications: Arc<DashMap<String, Sas>>,
room_verifications: Arc<DashMap<String, Sas>>,
room_verifications: Arc<DashMap<EventId, Sas>>,
requests: Arc<DashMap<EventId, VerificationRequest>>,
outgoing_to_device_messages: Arc<DashMap<Uuid, OutgoingRequest>>,
}
@ -202,6 +202,32 @@ impl VerificationMachine {
);
if let Some((_, request)) = self.requests.remove(&e.content.relation.event_id) {
if let Some(d) = self
.store
.get_device(&e.sender, &e.content.from_device)
.await?
{
match request.into_started_sas(
e,
d,
self.store.get_user_identity(&e.sender).await?,
) {
Ok(s) => {
// TODO we need to queue up the accept event
// here.
let accept_event = s.accept();
self.room_verifications
.insert(e.content.relation.event_id.clone(), s);
}
Err(c) => {
warn!(
"Can't start key verification with {} {}, canceling: {:?}",
e.sender, e.content.from_device, c
);
// self.queue_up_content(&e.sender, &e.content.from_device, c)
}
}
}
}
}
_ => (),

View File

@ -23,7 +23,7 @@ use matrix_sdk_common::{
ready::ReadyEventContent, start::StartEventContent, Relation, VerificationMethod,
},
room::message::KeyVerificationRequestEventContent,
MessageEvent,
MessageEvent, SyncMessageEvent,
},
identifiers::{DeviceId, DeviceIdBox, EventId, RoomId, UserId},
};
@ -87,7 +87,7 @@ impl VerificationRequest {
pub(crate) fn into_started_sas(
&self,
event: &MessageEvent<StartEventContent>,
event: &SyncMessageEvent<StartEventContent>,
device: ReadOnlyDevice,
user_identity: Option<UserIdentities>,
) -> Result<Sas, OutgoingContent> {
@ -128,7 +128,7 @@ impl InnerRequest {
fn into_started_sas(
&mut self,
event: &MessageEvent<StartEventContent>,
event: &SyncMessageEvent<StartEventContent>,
store: Arc<Box<dyn CryptoStore>>,
account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity,
@ -299,7 +299,7 @@ struct Ready {
impl RequestState<Ready> {
fn into_started_sas(
&self,
event: &MessageEvent<StartEventContent>,
event: &SyncMessageEvent<StartEventContent>,
store: Arc<Box<dyn CryptoStore>>,
account: ReadOnlyAccount,
private_identity: PrivateCrossSigningIdentity,
@ -344,6 +344,3 @@ struct Passive {
/// unique id identifying this verification flow.
pub flow_id: EventId,
}
#[derive(Clone, Debug)]
struct Started {}