Skip to content

Commit 2f6f5d9

Browse files
richvdhkaylendog
authored andcommitted
feat: Add forwarder_data to InboundGroupSession and pickle.
Issue: #5109 Signed-off-by: Skye Elliot <[email protected]>
1 parent b19377a commit 2f6f5d9

File tree

17 files changed

+86
-25
lines changed

17 files changed

+86
-25
lines changed

bindings/matrix-sdk-crypto-ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ fn collect_sessions(
506506
})
507507
.collect::<anyhow::Result<_>>()?,
508508
sender_data: SenderData::legacy(),
509+
forwarder_data: None,
509510
room_id: RoomId::parse(session.room_id)?,
510511
imported: session.imported,
511512
backed_up: session.backed_up,

bindings/matrix-sdk-crypto-ffi/src/machine.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use matrix_sdk_crypto::{
1515
SignatureVerification as RustSignatureCheckResult,
1616
},
1717
decrypt_room_key_export, encrypt_room_key_export,
18-
olm::ExportedRoomKey,
18+
olm::{ExportedRoomKey, SenderData},
1919
store::types::{BackupDecryptionKey, Changes},
2020
types::requests::ToDeviceRequest,
2121
CollectStrategy, DecryptionSettings, LocalTrust, OlmMachine as InnerMachine,
@@ -1023,7 +1023,7 @@ impl OlmMachine {
10231023
) -> Result<KeysImportResult, KeyImportError> {
10241024
let keys = Cursor::new(keys);
10251025
let keys = decrypt_room_key_export(keys, &passphrase)?;
1026-
self.import_room_keys_helper(keys, None, progress_listener)
1026+
self.import_room_keys_helper(keys, None, None, progress_listener)
10271027
}
10281028

10291029
/// Import room keys from the given serialized unencrypted key export.
@@ -1051,7 +1051,7 @@ impl OlmMachine {
10511051
let backup_version = self.runtime.block_on(self.inner.backup_machine().backup_version());
10521052
let keys: Vec<Value> = serde_json::from_str(&keys)?;
10531053
let keys = keys.into_iter().map(serde_json::from_value).filter_map(|k| k.ok()).collect();
1054-
self.import_room_keys_helper(keys, backup_version.as_deref(), progress_listener)
1054+
self.import_room_keys_helper(keys, backup_version.as_deref(), None, progress_listener)
10551055
}
10561056

10571057
/// Import room keys from the given serialized unencrypted key export.
@@ -1078,7 +1078,7 @@ impl OlmMachine {
10781078
) -> Result<KeysImportResult, KeyImportError> {
10791079
let keys: Vec<Value> = serde_json::from_str(&keys)?;
10801080
let keys = keys.into_iter().map(serde_json::from_value).filter_map(|k| k.ok()).collect();
1081-
self.import_room_keys_helper(keys, Some(&backup_version), progress_listener)
1081+
self.import_room_keys_helper(keys, Some(&backup_version), None, progress_listener)
10821082
}
10831083

10841084
/// Discard the currently active room key for the given room if there is
@@ -1572,6 +1572,7 @@ impl OlmMachine {
15721572
&self,
15731573
keys: Vec<ExportedRoomKey>,
15741574
from_backup_version: Option<&str>,
1575+
sender_data: Option<&SenderData>,
15751576
progress_listener: Box<dyn ProgressListener>,
15761577
) -> Result<KeysImportResult, KeyImportError> {
15771578
let listener = |progress: usize, total: usize| {
@@ -1581,6 +1582,7 @@ impl OlmMachine {
15811582
let result = self.runtime.block_on(self.inner.store().import_room_keys(
15821583
keys,
15831584
from_backup_version,
1585+
sender_data,
15841586
listener,
15851587
))?;
15861588

crates/matrix-sdk-crypto/src/backups/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,12 @@ impl BackupMachine {
630630
let backup_version = self.backup_version().await;
631631

632632
self.store
633-
.import_room_keys(decrypted_room_keys, backup_version.as_deref(), progress_listener)
633+
.import_room_keys(
634+
decrypted_room_keys,
635+
backup_version.as_deref(),
636+
None,
637+
progress_listener,
638+
)
634639
.await
635640
}
636641
}

crates/matrix-sdk-crypto/src/machine/tests/decryption_verification_state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ async fn test_verification_states_multiple_device() {
448448
fake_room_id,
449449
&olm,
450450
SenderData::unknown(),
451+
None,
451452
EventEncryptionAlgorithm::MegolmV1AesSha2,
452453
None,
453454
false,
@@ -466,6 +467,7 @@ async fn test_verification_states_multiple_device() {
466467
fake_room_id,
467468
&olm,
468469
SenderData::unknown(),
470+
None,
469471
EventEncryptionAlgorithm::MegolmV1AesSha2,
470472
None,
471473
false,

crates/matrix-sdk-crypto/src/olm/account.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ impl StaticAccountData {
235235
room_id,
236236
&outbound.session_key().await,
237237
own_sender_data,
238+
None,
238239
algorithm,
239240
Some(visibility),
240241
shared_history,

crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ pub struct InboundGroupSession {
187187
/// key.
188188
pub sender_data: SenderData,
189189

190+
/// If this session was shared-on-invite as part of an MSC4268 key bundle,
191+
/// information about the user who forwarded us the session information.
192+
/// This is distinct from [`InboundGroupSession::sender_data`].
193+
pub forwarder_data: Option<SenderData>,
194+
190195
/// The Room this GroupSession belongs to
191196
pub room_id: OwnedRoomId,
192197

@@ -263,6 +268,7 @@ impl InboundGroupSession {
263268
room_id: &RoomId,
264269
session_key: &SessionKey,
265270
sender_data: SenderData,
271+
forwarder_data: Option<SenderData>,
266272
encryption_algorithm: EventEncryptionAlgorithm,
267273
history_visibility: Option<HistoryVisibility>,
268274
shared_history: bool,
@@ -286,6 +292,7 @@ impl InboundGroupSession {
286292
signing_keys: keys.into(),
287293
},
288294
sender_data,
295+
forwarder_data,
289296
room_id: room_id.into(),
290297
imported: false,
291298
algorithm: encryption_algorithm.into(),
@@ -325,6 +332,7 @@ impl InboundGroupSession {
325332
room_id,
326333
session_key,
327334
SenderData::unknown(),
335+
None,
328336
EventEncryptionAlgorithm::MegolmV1AesSha2,
329337
None,
330338
*shared_history,
@@ -380,6 +388,7 @@ impl InboundGroupSession {
380388
sender_key: self.creator_info.curve25519_key,
381389
signing_key: (*self.creator_info.signing_keys).clone(),
382390
sender_data: self.sender_data.clone(),
391+
forwarder_data: self.forwarder_data.clone(),
383392
room_id: self.room_id().to_owned(),
384393
imported: self.imported,
385394
backed_up: self.backed_up(),
@@ -459,6 +468,7 @@ impl InboundGroupSession {
459468
sender_key,
460469
signing_key,
461470
sender_data,
471+
forwarder_data,
462472
room_id,
463473
imported,
464474
backed_up,
@@ -479,6 +489,7 @@ impl InboundGroupSession {
479489
signing_keys: signing_key.into(),
480490
},
481491
sender_data,
492+
forwarder_data,
482493
history_visibility: history_visibility.into(),
483494
first_known_index,
484495
room_id,
@@ -693,6 +704,9 @@ pub struct PickledInboundGroupSession {
693704
/// Information on the device/sender who sent us this session
694705
#[serde(default)]
695706
pub sender_data: SenderData,
707+
/// Information on the device/sender who forwarded us this session
708+
#[serde(default)]
709+
pub forwarder_data: Option<SenderData>,
696710
/// The id of the room that the session is used in.
697711
pub room_id: OwnedRoomId,
698712
/// Flag remembering if the session was directly sent to us by the sender
@@ -746,6 +760,7 @@ impl TryFrom<&HistoricRoomKey> for InboundGroupSession {
746760
// TODO: How do we remember that this is a historic room key and events decrypted using
747761
// this room key should always show some form of warning.
748762
sender_data: SenderData::default(),
763+
forwarder_data: None,
749764
history_visibility: None.into(),
750765
first_known_index,
751766
room_id: room_id.to_owned(),
@@ -786,6 +801,7 @@ impl TryFrom<&ExportedRoomKey> for InboundGroupSession {
786801
// TODO: In future, exported keys should contain sender data that we can use here.
787802
// See https://github.com/matrix-org/matrix-rust-sdk/issues/3548
788803
sender_data: SenderData::default(),
804+
forwarder_data: None,
789805
history_visibility: None.into(),
790806
first_known_index,
791807
room_id: room_id.to_owned(),
@@ -817,6 +833,7 @@ impl From<&ForwardedMegolmV1AesSha2Content> for InboundGroupSession {
817833
// In future, exported keys should contain sender data that we can use here.
818834
// See https://github.com/matrix-org/matrix-rust-sdk/issues/3548
819835
sender_data: SenderData::default(),
836+
forwarder_data: None,
820837
history_visibility: None.into(),
821838
first_known_index,
822839
room_id: value.room_id.to_owned(),
@@ -844,6 +861,7 @@ impl From<&ForwardedMegolmV2AesSha2Content> for InboundGroupSession {
844861
// In future, exported keys should contain sender data that we can use here.
845862
// See https://github.com/matrix-org/matrix-rust-sdk/issues/3548
846863
sender_data: SenderData::default(),
864+
forwarder_data: None,
847865
history_visibility: None.into(),
848866
first_known_index,
849867
room_id: value.room_id.to_owned(),
@@ -984,6 +1002,7 @@ mod tests {
9841002
room_id!("!test:localhost"),
9851003
&create_session_key(),
9861004
SenderData::unknown(),
1005+
None,
9871006
EventEncryptionAlgorithm::MegolmV1AesSha2,
9881007
Some(HistoryVisibility::Shared),
9891008
false,

crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data_finder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ mod tests {
826826
room_id,
827827
&session_key,
828828
SenderData::unknown(),
829+
None,
829830
EventEncryptionAlgorithm::MegolmV1AesSha2,
830831
None,
831832
false,

crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use super::{
1414
};
1515
use crate::{
1616
olm::InboundGroupSession,
17-
store,
18-
store::{Changes, DynCryptoStore, IntoCryptoStore, RoomKeyInfo, RoomKeyWithheldInfo},
17+
store::{self, Changes, DynCryptoStore, IntoCryptoStore, RoomKeyInfo, RoomKeyWithheldInfo},
1918
CryptoStoreError, GossippedSecret, OwnUserIdentityData, Session, UserIdentityData,
2019
};
2120

@@ -291,6 +290,8 @@ impl CryptoStoreWrapper {
291290
/// # Arguments
292291
///
293292
/// * `sessions` - The sessions to be saved.
293+
/// * `sender_data` - If the sessions were received as part of an MSC4268
294+
/// key bundle, the information about the user who sent us the bundle.
294295
/// * `backed_up_to_version` - If the keys should be marked as having been
295296
/// backed up, the version of the backup.
296297
///

crates/matrix-sdk-crypto/src/store/integration_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ macro_rules! cryptostore_integration_tests {
14301430
room_id!("!r:s.co"),
14311431
&session_key,
14321432
sender_data,
1433+
None,
14331434
EventEncryptionAlgorithm::MegolmV1AesSha2,
14341435
None,
14351436
false,

crates/matrix-sdk-crypto/src/store/memorystore.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ mod tests {
846846
room_id,
847847
&outbound.session_key().await,
848848
SenderData::unknown(),
849+
None,
849850
outbound.settings().algorithm.to_owned(),
850851
None,
851852
false,
@@ -1244,6 +1245,7 @@ mod tests {
12441245
room_id,
12451246
&outbound.session_key().await,
12461247
SenderData::unknown(),
1248+
None,
12471249
outbound.settings().algorithm.to_owned(),
12481250
None,
12491251
false,

0 commit comments

Comments
 (0)