Skip to content

Commit cd9f433

Browse files
authored
Merge pull request #5945 from matrix-org/kaylendog/history-sharing/encryption-info
feat: Add `forwarder: ForwarderInfo` to `EncryptionInfo`. Introduces `ForwarderInfo` which which exposes information about the forwarder of the keys with which an event was encrypted if they were shared as part of an [MSC4268](matrix-org/matrix-spec-proposals#4268) room key bundle.
1 parent 42a5910 commit cd9f433

File tree

12 files changed

+59
-7
lines changed

12 files changed

+59
-7
lines changed

crates/matrix-sdk-base/src/event_cache/store/integration_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub fn make_test_event_with_event_id(
7979
let encryption_info = Arc::new(EncryptionInfo {
8080
sender: (*ALICE).into(),
8181
sender_device: None,
82+
forwarder: None,
8283
algorithm_info: AlgorithmInfo::MegolmV1AesSha2 {
8384
curve25519_key: "1337".to_owned(),
8485
sender_claimed_keys: Default::default(),

crates/matrix-sdk-common/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ All notable changes to this project will be documented in this file.
1414

1515
### Features
1616

17+
- Add field `forwarder` of type `ForwarderInfo` to `EncryptionInfo`, which which exposes information about the forwarder of the keys with which an event was encrypted if they were shared as part of an [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268) room key bundle.
18+
([#5945](https://github.com/matrix-org/matrix-rust-sdk/pull/5945)).
1719
- [**breaking**] Cross-process lock can be dirty. The `CrossProcess::try_lock_once` now returns a new type `CrossProcessResult`, which is an enum with `Clean`, `Dirty` or `Unobtained` variants. When the lock is dirty it means it's been acquired once, then acquired another time from another holder, so the current holder may want to refresh its internal state.
1820
([#5672](https://github.com/matrix-org/matrix-rust-sdk/pull/5672)).
1921

crates/matrix-sdk-common/src/deserialized_responses.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ pub enum AlgorithmInfo {
319319
},
320320
}
321321

322+
/// Struct containing information on the forwarder of the keys used to decrypt
323+
/// an event.
324+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
325+
pub struct ForwarderInfo {
326+
/// The user ID of the forwarder.
327+
pub user_id: OwnedUserId,
328+
/// The device ID of the forwarder.
329+
pub device_id: OwnedDeviceId,
330+
}
331+
322332
/// Struct containing information on how an event was decrypted.
323333
#[derive(Clone, Debug, PartialEq, Serialize)]
324334
pub struct EncryptionInfo {
@@ -328,6 +338,11 @@ pub struct EncryptionInfo {
328338
/// The device ID of the device that sent us the event, note this is
329339
/// untrusted data unless `verification_state` is `Verified` as well.
330340
pub sender_device: Option<OwnedDeviceId>,
341+
/// If the keys for this message were shared-on-invite as part of an
342+
/// [MSC4268] key bundle, information about the forwarder.
343+
///
344+
/// [MSC4268]: https://github.com/matrix-org/matrix-spec-proposals/pull/4268
345+
pub forwarder: Option<ForwarderInfo>,
331346
/// Information about the algorithm that was used to encrypt the event.
332347
pub algorithm_info: AlgorithmInfo,
333348
/// The verification state of the device that sent us the event, note this
@@ -361,14 +376,21 @@ impl<'de> Deserialize<'de> for EncryptionInfo {
361376
struct Helper {
362377
pub sender: OwnedUserId,
363378
pub sender_device: Option<OwnedDeviceId>,
379+
pub forwarder: Option<ForwarderInfo>,
364380
pub algorithm_info: AlgorithmInfo,
365381
pub verification_state: VerificationState,
366382
#[serde(rename = "session_id")]
367383
pub old_session_id: Option<String>,
368384
}
369385

370-
let Helper { sender, sender_device, algorithm_info, verification_state, old_session_id } =
371-
Helper::deserialize(deserializer)?;
386+
let Helper {
387+
sender,
388+
sender_device,
389+
forwarder,
390+
algorithm_info,
391+
verification_state,
392+
old_session_id,
393+
} = Helper::deserialize(deserializer)?;
372394

373395
let algorithm_info = match algorithm_info {
374396
AlgorithmInfo::MegolmV1AesSha2 { curve25519_key, sender_claimed_keys, session_id } => {
@@ -382,7 +404,7 @@ impl<'de> Deserialize<'de> for EncryptionInfo {
382404
other => other,
383405
};
384406

385-
Ok(EncryptionInfo { sender, sender_device, algorithm_info, verification_state })
407+
Ok(EncryptionInfo { sender, sender_device, forwarder, algorithm_info, verification_state })
386408
}
387409
}
388410

@@ -1617,6 +1639,7 @@ mod tests {
16171639
encryption_info: Arc::new(EncryptionInfo {
16181640
sender: user_id!("@sender:example.com").to_owned(),
16191641
sender_device: None,
1642+
forwarder: None,
16201643
algorithm_info: AlgorithmInfo::MegolmV1AesSha2 {
16211644
curve25519_key: "xxx".to_owned(),
16221645
sender_claimed_keys: Default::default(),
@@ -1657,6 +1680,7 @@ mod tests {
16571680
"encryption_info": {
16581681
"sender": "@sender:example.com",
16591682
"sender_device": null,
1683+
"forwarder": null,
16601684
"algorithm_info": {
16611685
"MegolmV1AesSha2": {
16621686
"curve25519_key": "xxx",
@@ -2041,6 +2065,7 @@ mod tests {
20412065
let info = EncryptionInfo {
20422066
sender: user_id!("@alice:localhost").to_owned(),
20432067
sender_device: Some(device_id!("ABCDEFGH").to_owned()),
2068+
forwarder: None,
20442069
algorithm_info: AlgorithmInfo::MegolmV1AesSha2 {
20452070
curve25519_key: "curvecurvecurve".into(),
20462071
sender_claimed_keys: Default::default(),
@@ -2062,6 +2087,7 @@ mod tests {
20622087
encryption_info: Arc::new(EncryptionInfo {
20632088
sender: user_id!("@sender:example.com").to_owned(),
20642089
sender_device: Some(device_id!("ABCDEFGHIJ").to_owned()),
2090+
forwarder: None,
20652091
algorithm_info: AlgorithmInfo::MegolmV1AesSha2 {
20662092
curve25519_key: "xxx".to_owned(),
20672093
sender_claimed_keys: BTreeMap::from([

crates/matrix-sdk-common/src/snapshots/matrix_sdk_common__deserialized_responses__tests__encryption_info_migration.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ expression: deserialized
55
{
66
"sender": "@alice:localhost",
77
"sender_device": "ABCDEFGH",
8+
"forwarder": null,
89
"algorithm_info": {
910
"MegolmV1AesSha2": {
1011
"curve25519_key": "curvecurvecurve",

crates/matrix-sdk-common/src/snapshots/snapshot_test_encryption_info.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ expression: info
55
{
66
"sender": "@alice:localhost",
77
"sender_device": "ABCDEFGH",
8+
"forwarder": null,
89
"algorithm_info": {
910
"MegolmV1AesSha2": {
1011
"curve25519_key": "curvecurvecurve",

crates/matrix-sdk-common/src/snapshots/snapshot_test_sync_timeline_event.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ expression: "serde_json::to_value(&room_event).unwrap()"
1616
"session_id": "mysessionid112"
1717
}
1818
},
19+
"forwarder": null,
1920
"sender": "@sender:example.com",
2021
"sender_device": "ABCDEFGHIJ",
2122
"verification_state": "Verified"

crates/matrix-sdk-crypto/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88

99
### Features
1010

11+
- Added a new field `forwarder` to `InboundGroupSession` of type `ForwarderData`, which stores information about the forwarder of a session shared in a room key bundle under [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268).
12+
([#5980])(https://github.com/matrix-org/matrix-rust-sdk/pull/5980)
1113
- The `OutboundGroupSession` and `OlmMachine` now return the `EncryptionInfo`
1214
used when encrypting raw events.
1315
([#5936](https://github.com/matrix-org/matrix-rust-sdk/pull/5936))

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use matrix_sdk_common::deserialized_responses::WithheldCode;
2626
use matrix_sdk_common::{
2727
BoxFuture,
2828
deserialized_responses::{
29-
AlgorithmInfo, DecryptedRoomEvent, DeviceLinkProblem, EncryptionInfo,
29+
AlgorithmInfo, DecryptedRoomEvent, DeviceLinkProblem, EncryptionInfo, ForwarderInfo,
3030
ProcessedToDeviceEvent, ToDeviceUnableToDecryptInfo, ToDeviceUnableToDecryptReason,
3131
UnableToDecryptInfo, UnableToDecryptReason, UnsignedDecryptionResult,
3232
UnsignedEventLocation, VerificationLevel, VerificationState,
@@ -1136,6 +1136,7 @@ impl OlmMachine {
11361136
EncryptionInfo {
11371137
sender: self.inner.user_id.clone(),
11381138
sender_device: Some(self.inner.device_id.clone()),
1139+
forwarder: None,
11391140
algorithm_info,
11401141
verification_state: VerificationState::Verified,
11411142
}
@@ -2016,11 +2017,18 @@ impl OlmMachine {
20162017
let (verification_state, device_id) =
20172018
self.get_room_event_verification_state(session, sender).await?;
20182019

2019-
let sender = sender.to_owned();
2020-
20212020
Ok(Arc::new(EncryptionInfo {
2022-
sender,
2021+
sender: sender.to_owned(),
20232022
sender_device: device_id,
2023+
forwarder: session.forwarder_data.as_ref().and_then(|data| {
2024+
// Per the comment on `KnownSenderData::device_id`, we should never encounter a
2025+
// `None` value here, but must still deal with an `Optional` for backwards
2026+
// compatibility. The approach below allows us to avoid unwrapping.
2027+
data.device_id().map(|device_id| ForwarderInfo {
2028+
device_id: device_id.to_owned(),
2029+
user_id: data.user_id().to_owned(),
2030+
})
2031+
}),
20242032
algorithm_info: AlgorithmInfo::MegolmV1AesSha2 {
20252033
curve25519_key: session.sender_key().to_base64(),
20262034
sender_claimed_keys: session

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,7 @@ impl Account {
17041704
EncryptionInfo {
17051705
sender: sender_id.to_owned(),
17061706
sender_device: sender_device.as_ref().map(|d| d.device_id().to_owned()),
1707+
forwarder: None,
17071708
algorithm_info: AlgorithmInfo::OlmV1Curve25519AesSha2 {
17081709
curve25519_public_key_base64: sender_key.to_base64(),
17091710
},

crates/matrix-sdk-ui/src/timeline/controller/decryption_retry_task.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ mod tests {
296296
encryption_info: Some(Arc::new(EncryptionInfo {
297297
sender: owned_user_id!("@u:s.co"),
298298
sender_device: None,
299+
forwarder: None,
299300
algorithm_info: AlgorithmInfo::MegolmV1AesSha2 {
300301
curve25519_key: "".to_owned(),
301302
sender_claimed_keys: BTreeMap::new(),

0 commit comments

Comments
 (0)