crypto: Take the session key out of the RoomKey event.

master
Damir Jelić 2020-04-10 17:02:30 +02:00
parent 01656690bc
commit 8210c2377d
1 changed files with 6 additions and 5 deletions

View File

@ -14,6 +14,7 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::convert::TryInto; use std::convert::TryInto;
use std::mem;
#[cfg(feature = "sqlite-cryptostore")] #[cfg(feature = "sqlite-cryptostore")]
use std::path::Path; use std::path::Path;
use std::result::Result as StdResult; use std::result::Result as StdResult;
@ -751,11 +752,11 @@ impl OlmMachine {
OlmMessage::from_type_and_ciphertext(message_type.into(), ciphertext.body.clone()) OlmMessage::from_type_and_ciphertext(message_type.into(), ciphertext.body.clone())
.map_err(|_| OlmError::UnsupportedOlmType)?; .map_err(|_| OlmError::UnsupportedOlmType)?;
let decrypted_event = self let mut decrypted_event = self
.decrypt_olm_message(&event.sender.to_string(), &content.sender_key, message) .decrypt_olm_message(&event.sender.to_string(), &content.sender_key, message)
.await?; .await?;
debug!("Decrypted a to-device event {:?}", decrypted_event); debug!("Decrypted a to-device event {:?}", decrypted_event);
self.handle_decrypted_to_device_event(&content.sender_key, &decrypted_event) self.handle_decrypted_to_device_event(&content.sender_key, &mut decrypted_event)
.await?; .await?;
Ok(decrypted_event) Ok(decrypted_event)
@ -765,7 +766,7 @@ impl OlmMachine {
} }
} }
async fn add_room_key(&mut self, sender_key: &str, event: &ToDeviceRoomKey) -> Result<()> { async fn add_room_key(&mut self, sender_key: &str, event: &mut ToDeviceRoomKey) -> Result<()> {
match event.content.algorithm { match event.content.algorithm {
Algorithm::MegolmV1AesSha2 => { Algorithm::MegolmV1AesSha2 => {
// TODO check for all the valid fields. // TODO check for all the valid fields.
@ -774,7 +775,7 @@ impl OlmMachine {
.get("ed25519") .get("ed25519")
.ok_or(OlmError::MissingSigningKey)?; .ok_or(OlmError::MissingSigningKey)?;
let session_key = GroupSessionKey(event.content.session_key.to_owned()); let session_key = GroupSessionKey(mem::take(&mut event.content.session_key));
let session = InboundGroupSession::new( let session = InboundGroupSession::new(
sender_key, sender_key,
@ -1038,7 +1039,7 @@ impl OlmMachine {
async fn handle_decrypted_to_device_event( async fn handle_decrypted_to_device_event(
&mut self, &mut self,
sender_key: &str, sender_key: &str,
event: &EventResult<ToDeviceEvent>, event: &mut EventResult<ToDeviceEvent>,
) -> Result<()> { ) -> Result<()> {
let event = if let EventResult::Ok(e) = event { let event = if let EventResult::Ok(e) = event {
e e