crypto: Move the m.room_key content creation into the outbound group session.

master
Damir Jelić 2020-07-21 11:12:20 +02:00
parent fe33430e9b
commit 3d6872607e
2 changed files with 17 additions and 16 deletions

View File

@ -899,30 +899,19 @@ impl OlmMachine {
I: IntoIterator<Item = &'a UserId>, I: IntoIterator<Item = &'a UserId>,
{ {
self.create_outbound_group_session(room_id).await?; self.create_outbound_group_session(room_id).await?;
let megolm_session = self.outbound_group_sessions.get(room_id).unwrap(); let session = self.outbound_group_sessions.get(room_id).unwrap();
if megolm_session.shared() { if session.shared() {
panic!("Session is already shared"); panic!("Session is already shared");
} }
let session_id = megolm_session.session_id().to_owned();
// TODO don't mark the session as shared automatically only, when all // TODO don't mark the session as shared automatically only, when all
// the requests are done, failure to send these requests will likely end // the requests are done, failure to send these requests will likely end
// up in wedged sessions. We'll need to store the requests and let the // up in wedged sessions. We'll need to store the requests and let the
// caller mark them as sent using an UUID. // caller mark them as sent using an UUID.
megolm_session.mark_as_shared(); session.mark_as_shared();
// TODO the key content creation can go into the OutboundGroupSession let key_content = session.as_json().await;
// struct.
let key_content = json!({
"algorithm": Algorithm::MegolmV1AesSha2,
"room_id": room_id,
"session_id": session_id.clone(),
"session_key": megolm_session.session_key().await,
"chain_index": megolm_session.message_index().await,
});
let mut user_map = Vec::new(); let mut user_map = Vec::new();

View File

@ -41,7 +41,7 @@ use matrix_sdk_common::{
encrypted::{EncryptedEventContent, MegolmV1AesSha2Content}, encrypted::{EncryptedEventContent, MegolmV1AesSha2Content},
message::MessageEventContent, message::MessageEventContent,
}, },
AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent, Algorithm, AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent,
}, },
identifiers::{DeviceId, RoomId}, identifiers::{DeviceId, RoomId},
}; };
@ -385,6 +385,18 @@ impl OutboundGroupSession {
let session = self.inner.lock().await; let session = self.inner.lock().await;
session.session_message_index() session.session_message_index()
} }
/// Get the outbound group session key as a json value that can be sent as a
/// m.room_key.
pub async fn as_json(&self) -> Value {
json!({
"algorithm": Algorithm::MegolmV1AesSha2,
"room_id": &*self.room_id,
"session_id": &*self.session_id,
"session_key": self.session_key().await,
"chain_index": self.message_index().await,
})
}
} }
// #[cfg_attr(tarpaulin, skip)] // #[cfg_attr(tarpaulin, skip)]