crypto: Allow the key request machine to access the outbound group sessions.

master
Damir Jelić 2020-09-29 10:09:47 +02:00
parent 721c459577
commit 798656dac5
2 changed files with 29 additions and 6 deletions

View File

@ -107,6 +107,7 @@ pub(crate) struct KeyRequestMachine {
user_id: Arc<UserId>, user_id: Arc<UserId>,
device_id: Arc<DeviceIdBox>, device_id: Arc<DeviceIdBox>,
store: Store, store: Store,
outbound_group_sessions: Arc<DashMap<RoomId, OutboundGroupSession>>,
outgoing_to_device_requests: Arc<DashMap<Uuid, OutgoingRequest>>, outgoing_to_device_requests: Arc<DashMap<Uuid, OutgoingRequest>>,
incoming_key_requests: incoming_key_requests:
Arc<DashMap<(UserId, DeviceIdBox, String), ToDeviceEvent<RoomKeyRequestEventContent>>>, Arc<DashMap<(UserId, DeviceIdBox, String), ToDeviceEvent<RoomKeyRequestEventContent>>>,
@ -167,11 +168,17 @@ fn wrap_key_request_content(
} }
impl KeyRequestMachine { impl KeyRequestMachine {
pub fn new(user_id: Arc<UserId>, device_id: Arc<DeviceIdBox>, store: Store) -> Self { pub fn new(
user_id: Arc<UserId>,
device_id: Arc<DeviceIdBox>,
store: Store,
outbound_group_sessions: Arc<DashMap<RoomId, OutboundGroupSession>>,
) -> Self {
Self { Self {
user_id, user_id,
device_id, device_id,
store, store,
outbound_group_sessions,
outgoing_to_device_requests: Arc::new(DashMap::new()), outgoing_to_device_requests: Arc::new(DashMap::new()),
incoming_key_requests: Arc::new(DashMap::new()), incoming_key_requests: Arc::new(DashMap::new()),
} }
@ -267,7 +274,12 @@ impl KeyRequestMachine {
if let Some(device) = device { if let Some(device) = device {
// TODO get the matching outbound session. // TODO get the matching outbound session.
if let Err(e) = self.should_share_session(&device, None) { if let Err(e) = self.should_share_session(
&device,
self.outbound_group_sessions
.get(&key_info.room_id)
.as_deref(),
) {
info!( info!(
"Received a key request from {} {} that we won't serve: {}", "Received a key request from {} {} that we won't serve: {}",
device.user_id(), device.user_id(),
@ -572,6 +584,7 @@ impl KeyRequestMachine {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use dashmap::DashMap;
use matrix_sdk_common::{ use matrix_sdk_common::{
events::{forwarded_room_key::ForwardedRoomKeyEventContent, ToDeviceEvent}, events::{forwarded_room_key::ForwardedRoomKeyEventContent, ToDeviceEvent},
identifiers::{room_id, user_id, DeviceIdBox, RoomId, UserId}, identifiers::{room_id, user_id, DeviceIdBox, RoomId, UserId},
@ -619,7 +632,12 @@ mod test {
let user_id = Arc::new(alice_id()); let user_id = Arc::new(alice_id());
let store = Store::new(user_id.clone(), Box::new(MemoryStore::new())); let store = Store::new(user_id.clone(), Box::new(MemoryStore::new()));
KeyRequestMachine::new(user_id, Arc::new(alice_device_id()), store) KeyRequestMachine::new(
user_id,
Arc::new(alice_device_id()),
store,
Arc::new(DashMap::new()),
)
} }
#[test] #[test]

View File

@ -129,8 +129,13 @@ impl OlmMachine {
let store = Store::new(user_id.clone(), store); let store = Store::new(user_id.clone(), store);
let verification_machine = VerificationMachine::new(account.clone(), store.clone()); let verification_machine = VerificationMachine::new(account.clone(), store.clone());
let device_id: Arc<DeviceIdBox> = Arc::new(device_id); let device_id: Arc<DeviceIdBox> = Arc::new(device_id);
let key_request_machine = let outbound_group_sessions = Arc::new(DashMap::new());
KeyRequestMachine::new(user_id.clone(), device_id.clone(), store.clone()); let key_request_machine = KeyRequestMachine::new(
user_id.clone(),
device_id.clone(),
store.clone(),
outbound_group_sessions.clone(),
);
let identity_manager = let identity_manager =
IdentityManager::new(user_id.clone(), device_id.clone(), store.clone()); IdentityManager::new(user_id.clone(), device_id.clone(), store.clone());
@ -139,7 +144,7 @@ impl OlmMachine {
device_id, device_id,
account, account,
store, store,
outbound_group_sessions: Arc::new(DashMap::new()), outbound_group_sessions,
verification_machine, verification_machine,
key_request_machine, key_request_machine,
identity_manager, identity_manager,