crypto: Replace the decrypted to-device events in the sync response.

master
Damir Jelić 2020-03-31 13:38:44 +02:00
parent ceeb685e1a
commit 0d183daa3d
1 changed files with 7 additions and 5 deletions

View File

@ -590,12 +590,12 @@ impl OlmMachine {
let count: u64 = one_time_key_count.map_or(0, |c| (*c).into()); let count: u64 = one_time_key_count.map_or(0, |c| (*c).into());
self.uploaded_signed_key_count = Some(count); self.uploaded_signed_key_count = Some(count);
for event in response.to_device.events.iter() { for event_result in &mut response.to_device.events {
let event = if let EventResult::Ok(e) = event { let event = if let EventResult::Ok(e) = &event_result {
e e
} else { } else {
// Skip invalid events. // Skip invalid events.
warn!("Received an invalid to-device event {:?}", event); warn!("Received an invalid to-device event {:?}", event_result);
continue; continue;
}; };
@ -603,8 +603,6 @@ impl OlmMachine {
match event { match event {
ToDeviceEvent::RoomEncrypted(e) => { ToDeviceEvent::RoomEncrypted(e) => {
// TODO put the decrypted event into a vec so we can replace
// them in the sync response.
let decrypted_event = match self.decrypt_to_device_event(e).await { let decrypted_event = match self.decrypt_to_device_event(e).await {
Ok(e) => e, Ok(e) => e,
Err(err) => { Err(err) => {
@ -617,6 +615,10 @@ impl OlmMachine {
continue; continue;
} }
}; };
// TODO make sure private keys are cleared from the event
// before we replace the result.
*event_result = decrypted_event;
} }
ToDeviceEvent::RoomKeyRequest(e) => self.handle_room_key_request(e), ToDeviceEvent::RoomKeyRequest(e) => self.handle_room_key_request(e),
ToDeviceEvent::KeyVerificationAccept(..) ToDeviceEvent::KeyVerificationAccept(..)