crypto: Store the history visibility with inbound group sessions

This can be useful to share the room history with new room members.
master
Damir Jelić 2021-02-03 16:59:34 +01:00
parent 9e83eaf2f5
commit 1799721a5f
7 changed files with 20 additions and 1 deletions

View File

@ -597,6 +597,7 @@ impl OlmMachine {
signing_key, signing_key,
&event.content.room_id, &event.content.room_id,
session_key, session_key,
None,
)?; )?;
let event = AnyToDeviceEvent::RoomKey(event.clone()); let event = AnyToDeviceEvent::RoomKey(event.clone());
Ok((Some(event), Some(session))) Ok((Some(event), Some(session)))

View File

@ -991,6 +991,8 @@ impl ReadOnlyAccount {
return Err(()); return Err(());
} }
let visiblity = settings.history_visibility.clone();
let outbound = OutboundGroupSession::new( let outbound = OutboundGroupSession::new(
self.device_id.clone(), self.device_id.clone(),
self.identity_keys.clone(), self.identity_keys.clone(),
@ -1007,6 +1009,7 @@ impl ReadOnlyAccount {
signing_key, signing_key,
&room_id, &room_id,
outbound.session_key().await, outbound.session_key().await,
Some(visiblity),
) )
.expect("Can't create inbound group session from a newly created outbound group session"); .expect("Can't create inbound group session from a newly created outbound group session");

View File

@ -35,7 +35,8 @@ pub use olm_rs::{
use matrix_sdk_common::{ use matrix_sdk_common::{
events::{ events::{
forwarded_room_key::ForwardedRoomKeyToDeviceEventContent, forwarded_room_key::ForwardedRoomKeyToDeviceEventContent,
room::encrypted::EncryptedEventContent, AnySyncRoomEvent, SyncMessageEvent, room::{encrypted::EncryptedEventContent, history_visibility::HistoryVisibility},
AnySyncRoomEvent, SyncMessageEvent,
}, },
identifiers::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId}, identifiers::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId},
locks::Mutex, locks::Mutex,
@ -56,6 +57,7 @@ use crate::error::{EventError, MegolmResult};
#[derive(Clone)] #[derive(Clone)]
pub struct InboundGroupSession { pub struct InboundGroupSession {
inner: Arc<Mutex<OlmInboundGroupSession>>, inner: Arc<Mutex<OlmInboundGroupSession>>,
history_visibility: Arc<Option<HistoryVisibility>>,
session_id: Arc<str>, session_id: Arc<str>,
first_known_index: u32, first_known_index: u32,
pub(crate) sender_key: Arc<str>, pub(crate) sender_key: Arc<str>,
@ -87,6 +89,7 @@ impl InboundGroupSession {
signing_key: &str, signing_key: &str,
room_id: &RoomId, room_id: &RoomId,
session_key: GroupSessionKey, session_key: GroupSessionKey,
history_visibility: Option<HistoryVisibility>,
) -> Result<Self, OlmGroupSessionError> { ) -> Result<Self, OlmGroupSessionError> {
let session = OlmInboundGroupSession::new(&session_key.0)?; let session = OlmInboundGroupSession::new(&session_key.0)?;
let session_id = session.session_id(); let session_id = session.session_id();
@ -98,6 +101,7 @@ impl InboundGroupSession {
Ok(InboundGroupSession { Ok(InboundGroupSession {
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: session_id.into(), session_id: session_id.into(),
history_visibility: history_visibility.into(),
sender_key: sender_key.to_owned().into(), sender_key: sender_key.to_owned().into(),
first_known_index, first_known_index,
signing_key: Arc::new(keys), signing_key: Arc::new(keys),
@ -152,6 +156,7 @@ impl InboundGroupSession {
session_id: content.session_id.as_str().into(), session_id: content.session_id.as_str().into(),
sender_key: content.sender_key.as_str().into(), sender_key: content.sender_key.as_str().into(),
first_known_index, first_known_index,
history_visibility: None.into(),
signing_key: Arc::new(sender_claimed_key), signing_key: Arc::new(sender_claimed_key),
room_id: Arc::new(content.room_id.clone()), room_id: Arc::new(content.room_id.clone()),
forwarding_chains: Arc::new(Mutex::new(Some(forwarding_chains))), forwarding_chains: Arc::new(Mutex::new(Some(forwarding_chains))),
@ -175,6 +180,7 @@ impl InboundGroupSession {
room_id: (&*self.room_id).clone(), room_id: (&*self.room_id).clone(),
forwarding_chains: self.forwarding_chains.lock().await.clone(), forwarding_chains: self.forwarding_chains.lock().await.clone(),
imported: *self.imported, imported: *self.imported,
history_visibility: self.history_visibility.as_ref().clone(),
} }
} }
@ -243,6 +249,7 @@ impl InboundGroupSession {
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: session_id.into(), session_id: session_id.into(),
sender_key: pickle.sender_key.into(), sender_key: pickle.sender_key.into(),
history_visibility: pickle.history_visibility.into(),
first_known_index, first_known_index,
signing_key: Arc::new(pickle.signing_key), signing_key: Arc::new(pickle.signing_key),
room_id: Arc::new(pickle.room_id), room_id: Arc::new(pickle.room_id),
@ -376,6 +383,8 @@ pub struct PickledInboundGroupSession {
/// Flag remembering if the session was dirrectly sent to us by the sender /// Flag remembering if the session was dirrectly sent to us by the sender
/// or if it was imported. /// or if it was imported.
pub imported: bool, pub imported: bool,
/// History visiblity of the room when the session was created.
pub history_visibility: Option<HistoryVisibility>,
} }
/// The typed representation of a base64 encoded string of the GroupSession pickle. /// The typed representation of a base64 encoded string of the GroupSession pickle.
@ -412,6 +421,7 @@ impl TryFrom<ExportedRoomKey> for InboundGroupSession {
inner: Arc::new(Mutex::new(session)), inner: Arc::new(Mutex::new(session)),
session_id: key.session_id.into(), session_id: key.session_id.into(),
sender_key: key.sender_key.into(), sender_key: key.sender_key.into(),
history_visibility: None.into(),
first_known_index, first_known_index,
signing_key: Arc::new(key.sender_claimed_keys), signing_key: Arc::new(key.sender_claimed_keys),
room_id: Arc::new(key.room_id), room_id: Arc::new(key.room_id),

View File

@ -233,6 +233,7 @@ pub(crate) mod test {
"test_key", "test_key",
&room_id, &room_id,
outbound.session_key().await, outbound.session_key().await,
None,
) )
.unwrap(); .unwrap();

View File

@ -254,6 +254,7 @@ mod test {
"test_key", "test_key",
&room_id, &room_id,
outbound.session_key().await, outbound.session_key().await,
None,
) )
.unwrap(); .unwrap();

View File

@ -286,6 +286,7 @@ mod test {
"test_key", "test_key",
&room_id, &room_id,
outbound.session_key().await, outbound.session_key().await,
None,
) )
.unwrap(); .unwrap();

View File

@ -857,6 +857,7 @@ mod test {
identity_keys.ed25519(), identity_keys.ed25519(),
&room_id!("!test:localhost"), &room_id!("!test:localhost"),
GroupSessionKey(outbound_session.session_key()), GroupSessionKey(outbound_session.session_key()),
None,
) )
.expect("Can't create session"); .expect("Can't create session");
@ -882,6 +883,7 @@ mod test {
identity_keys.ed25519(), identity_keys.ed25519(),
&room_id!("!test:localhost"), &room_id!("!test:localhost"),
GroupSessionKey(outbound_session.session_key()), GroupSessionKey(outbound_session.session_key()),
None,
) )
.expect("Can't create session"); .expect("Can't create session");