crypto: Move the m.room_key content creation into the outbound group session.
This commit is contained in:
parent
fe33430e9b
commit
3d6872607e
2 changed files with 17 additions and 16 deletions
|
@ -899,30 +899,19 @@ impl OlmMachine {
|
|||
I: IntoIterator<Item = &'a UserId>,
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
let session_id = megolm_session.session_id().to_owned();
|
||||
|
||||
// TODO don't mark the session as shared automatically only, when all
|
||||
// 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
|
||||
// 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
|
||||
// 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 key_content = session.as_json().await;
|
||||
|
||||
let mut user_map = Vec::new();
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ use matrix_sdk_common::{
|
|||
encrypted::{EncryptedEventContent, MegolmV1AesSha2Content},
|
||||
message::MessageEventContent,
|
||||
},
|
||||
AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent,
|
||||
Algorithm, AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent,
|
||||
},
|
||||
identifiers::{DeviceId, RoomId},
|
||||
};
|
||||
|
@ -385,6 +385,18 @@ impl OutboundGroupSession {
|
|||
let session = self.inner.lock().await;
|
||||
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)]
|
||||
|
|
Loading…
Reference in a new issue