Skip to content

Commit 1b7ef4a

Browse files
authored
Expose forwarder and forwarderDevice on DecryptedRoomEvent. (#284)
Expose information about the forwarder for events that were decrypted using a key from an [MSC4268](matrix-org/matrix-spec-proposals#4268) key bundle. Signed-off-by: Skye Elliot <actuallyori@gmail.com>
1 parent c740781 commit 1b7ef4a

6 files changed

Lines changed: 68 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# UNRELEASED
22

3+
- Expose information about the forwarder for events that were decrypted using a
4+
key from an [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268)
5+
key bundle.
6+
([#270](https://github.com/matrix-org/matrix-sdk-crypto-wasm/pull/284/changes))
7+
- Update matrix-rust-sdk to `cd9f433`, which includes:
8+
9+
- Add field `forwarder` of type `ForwarderInfo` to `EncryptionInfo`, which
10+
exposes information about the forwarder of the keys with which an event was
11+
encrypted if they were shared as part of an [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268)
12+
room key bundle.
13+
([#5945](https://github.com/matrix-org/matrix-rust-sdk/pull/5945)).
14+
- Added a new field `forwarder` to `InboundGroupSession` of type `ForwarderData`,
15+
which stores information about the forwarder of a session shared in a room key
16+
bundle under [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268).
17+
([#5980](https://github.com/matrix-org/matrix-rust-sdk/pull/5980)
18+
- The `OutboundGroupSession` and `OlmMachine` now return the `EncryptionInfo` used
19+
when encrypting raw events.
20+
([#5936](https://github.com/matrix-org/matrix-rust-sdk/pull/5936))
21+
**Note:** The WASM bindings are not affected by this change.
22+
323
# matrix-sdk-crypto-wasm v16.0.0
424

525
- Add new property `MegolmDecryptionError.withheldCode`, which returns a withheld

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ futures-util = "0.3.27"
6464
getrandom = { version = "0.3.0", features = ["wasm_js"] }
6565
http = "1.1.0"
6666
js-sys = "0.3.49"
67-
matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "183116a4b1888039ad4d1714ac0d97f1375cc45a" }
68-
matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "183116a4b1888039ad4d1714ac0d97f1375cc45a" }
69-
matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "183116a4b1888039ad4d1714ac0d97f1375cc45a" }
67+
matrix-sdk-common = { features = ["js", "experimental-encrypted-state-events"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "cd9f433358586e8717417fc043650f46362aa14c" }
68+
matrix-sdk-indexeddb = { default-features = false, features = ["e2e-encryption"], git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "cd9f433358586e8717417fc043650f46362aa14c" }
69+
matrix-sdk-qrcode = { optional = true, git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "cd9f433358586e8717417fc043650f46362aa14c" }
7070
serde = "1.0.91"
7171
serde_json = "1.0.91"
7272
serde-wasm-bindgen = "0.6.5"
@@ -86,7 +86,7 @@ vergen-gitcl = { version = "1.0.0", features = ["build"] }
8686
default-features = false
8787
features = ["js", "automatic-room-key-forwarding", "experimental-encrypted-state-events"]
8888
git = "https://github.com/matrix-org/matrix-rust-sdk"
89-
rev = "183116a4b1888039ad4d1714ac0d97f1375cc45a"
89+
rev = "cd9f433358586e8717417fc043650f46362aa14c"
9090

9191
[lints.rust]
9292
# Workaround for https://github.com/rustwasm/wasm-bindgen/issues/4283, while we work up the courage to upgrade

src/libolm_migration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ fn libolm_pickled_megolm_session_to_rust_pickled_session(
464464
sender_key,
465465
signing_key: sender_signing_keys,
466466
sender_data: Default::default(),
467+
forwarder_data: None,
467468
room_id: libolm_session
468469
.room_id
469470
.clone()

src/responses.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,25 @@ impl DecryptedRoomEvent {
213213
pub fn shield_state(&self, strict: bool) -> encryption::ShieldState {
214214
self.encryption_info.shield_state(strict)
215215
}
216+
217+
/// If the keys for this message were shared-on-invite as part of an
218+
/// [MSC4268] key bundle, the ID of the user who sent us the bundle.
219+
///
220+
/// [MSC4268]: https://github.com/matrix-org/matrix-spec-proposals/pull/4268
221+
#[wasm_bindgen(getter, js_name = "forwarder")]
222+
pub fn forwarder(&self) -> Option<identifiers::UserId> {
223+
self.encryption_info.forwarder.clone()
224+
}
225+
226+
/// If the keys for this message were shared-on-invite as part of an
227+
/// [MSC4268] key bundle, the ID of the device from which this bundle
228+
/// was sent.
229+
///
230+
/// [MSC4268]: https://github.com/matrix-org/matrix-spec-proposals/pull/4268
231+
#[wasm_bindgen(getter, js_name = "forwarderDevice")]
232+
pub fn forwarder_device(&self) -> Option<identifiers::DeviceId> {
233+
self.encryption_info.forwarder_device.clone()
234+
}
216235
}
217236

218237
impl TryFrom<matrix_sdk_common::deserialized_responses::DecryptedRoomEvent> for DecryptedRoomEvent {
@@ -244,6 +263,18 @@ pub struct EncryptionInfo {
244263
#[wasm_bindgen(getter_with_clone, js_name = "senderDevice")]
245264
pub sender_device: Option<identifiers::DeviceId>,
246265

266+
/// The ID of the user who sent us the keys with which we decrypted this
267+
/// event as part of an MSC4268 key bundle, if present. Only applicable for
268+
/// room events.
269+
#[wasm_bindgen(getter_with_clone)]
270+
pub forwarder: Option<identifiers::UserId>,
271+
272+
/// The device ID of the user who sent us the keys with which we decrypted
273+
/// this event as part of an MSC4268 key bundle, if present. Only applicable
274+
/// for room events.
275+
#[wasm_bindgen(getter_with_clone, js_name = "forwarderDevice")]
276+
pub forwarder_device: Option<identifiers::DeviceId>,
277+
247278
/// The base64-encoded public Curve25519 key of the device that created the
248279
/// megolm decryption key originally.
249280
#[wasm_bindgen(getter_with_clone, js_name = "senderCurve25519Key")]
@@ -299,6 +330,8 @@ impl TryFrom<Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>> for
299330
.get(&ruma::DeviceKeyAlgorithm::Ed25519)
300331
.cloned()
301332
.into(),
333+
forwarder: value.forwarder.as_ref().map(|info| info.user_id.clone().into()),
334+
forwarder_device: value.forwarder.as_ref().map(|info| info.device_id.clone().into()),
302335
verification_state: value.verification_state.clone(),
303336
})
304337
}

tests/shared_room_history.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ describe("encrypted history sharing/decrypting", () => {
137137
const decryptedData = await receiverMachine.decryptRoomEvent(encryptedEvent, room, decryptionSettings);
138138
const decryptedEvent = JSON.parse(decryptedData.event);
139139
expect(decryptedEvent.content.body).toEqual("Hi!");
140+
141+
// ... and be able to look up who forwarded them the decryption key.
142+
expect(decryptedData.forwarder?.toString()).toEqual("@alice:example.org");
143+
expect(decryptedData.forwarderDevice?.toString()).toEqual("A");
140144
});
141145
});
142146
});

0 commit comments

Comments
 (0)