Skip to content

Commit 8bb8bba

Browse files
authored
Merge pull request matrix-org#5737 from matrix-org/kaylendog/shared-history/store
When we receive a key bundle, add any `withheld` data to the crypto store.
2 parents 3733ee8 + b045462 commit 8bb8bba

File tree

13 files changed

+372
-77
lines changed

13 files changed

+372
-77
lines changed

crates/matrix-sdk-crypto/CHANGELOG.md

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

77
## [Unreleased] - ReleaseDate
88

9+
### Features
10+
11+
- Improve feedback support for shared history when downloading room key bundles.
12+
([#5737](https://github.com/matrix-org/matrix-rust-sdk/pull/5737))
13+
- Add `RoomKeyWithheldEntry` enum, wrapping either a received to-device `m.room_key.withheld` event or
14+
its content, if derived from a downloaded room key bundle.
15+
- `OlmMachine::receive_room_key_bundle` now appends withheld key information to the store.
16+
- [**breaking**] `Changes::withheld_session_info` now stores a `RoomKeyWithheldEntry` in each `room-id`-`session-id` entry.
17+
- [**breaking**] `CryptoStore::get_withheld_info` now returns `Result<Option<RoomKeyWithheldEntry>>`. This change also affects `MemoryStore`.
18+
919
### Bug Fixes
1020

1121
- Fix a bug which caused encrypted to-device messages from unknown devices to be ignored.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,14 +1003,16 @@ impl OlmMachine {
10031003

10041004
if let RoomKeyWithheldContent::MegolmV1AesSha2(
10051005
MegolmV1AesSha2WithheldContent::BlackListed(c)
1006-
| MegolmV1AesSha2WithheldContent::Unverified(c),
1006+
| MegolmV1AesSha2WithheldContent::Unverified(c)
1007+
| MegolmV1AesSha2WithheldContent::Unauthorised(c)
1008+
| MegolmV1AesSha2WithheldContent::Unavailable(c),
10071009
) = &event.content
10081010
{
10091011
changes
10101012
.withheld_session_info
10111013
.entry(c.room_id.to_owned())
10121014
.or_default()
1013-
.insert(c.session_id.to_owned(), event.to_owned());
1015+
.insert(c.session_id.to_owned(), event.to_owned().into());
10141016
}
10151017
}
10161018

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ macro_rules! cryptostore_integration_tests {
5353
store::{
5454
types::{
5555
BackupDecryptionKey, Changes, DehydratedDeviceKey, DeviceChanges,
56-
IdentityChanges, PendingChanges, StoredRoomKeyBundleData, RoomSettings,
56+
IdentityChanges, PendingChanges, StoredRoomKeyBundleData, RoomKeyWithheldEntry,
57+
RoomSettings
5758
},
5859
CryptoStore, GossipRequest,
5960
},
@@ -1138,7 +1139,7 @@ macro_rules! cryptostore_integration_tests {
11381139
async fn test_withheld_info_storage() {
11391140
let (account, store) = get_loaded_store("withheld_info_storage").await;
11401141

1141-
let mut info_list: BTreeMap<_, BTreeMap<_, _>> = BTreeMap::new();
1142+
let mut info_list: BTreeMap<_, BTreeMap<_, RoomKeyWithheldEntry>> = BTreeMap::new();
11421143

11431144
let user_id = account.user_id().to_owned();
11441145
let room_id = room_id!("!DwLygpkclUAfQNnfva:example.com");
@@ -1163,7 +1164,7 @@ macro_rules! cryptostore_integration_tests {
11631164
info_list
11641165
.entry(room_id.to_owned())
11651166
.or_default()
1166-
.insert(session_id_1.to_owned(), event);
1167+
.insert(session_id_1.to_owned(), event.into());
11671168

11681169
let content = RoomKeyWithheldContent::MegolmV1AesSha2(
11691170
MegolmV1AesSha2WithheldContent::BlackListed(
@@ -1183,7 +1184,7 @@ macro_rules! cryptostore_integration_tests {
11831184
info_list
11841185
.entry(room_id.to_owned())
11851186
.or_default()
1186-
.insert(session_id_2.to_owned(), event);
1187+
.insert(session_id_2.to_owned(), event.into());
11871188

11881189
let changes = Changes { withheld_session_info: info_list, ..Default::default() };
11891190
store.save_changes(changes).await.unwrap();

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::{
4545
OutboundGroupSession, PickledAccount, PickledInboundGroupSession, PickledSession,
4646
PrivateCrossSigningIdentity, SenderDataType, StaticAccountData,
4747
},
48-
types::events::room_key_withheld::RoomKeyWithheldEvent,
48+
store::types::RoomKeyWithheldEntry,
4949
};
5050

5151
fn encode_key_info(info: &SecretInfo) -> String {
@@ -97,7 +97,7 @@ pub struct MemoryStore {
9797
identities: StdRwLock<HashMap<OwnedUserId, String>>,
9898
outgoing_key_requests: StdRwLock<HashMap<OwnedTransactionId, GossipRequest>>,
9999
key_requests_by_info: StdRwLock<HashMap<String, OwnedTransactionId>>,
100-
direct_withheld_info: StdRwLock<HashMap<OwnedRoomId, HashMap<String, RoomKeyWithheldEvent>>>,
100+
direct_withheld_info: StdRwLock<HashMap<OwnedRoomId, HashMap<String, RoomKeyWithheldEntry>>>,
101101
custom_values: StdRwLock<HashMap<String, Vec<u8>>>,
102102
leases: StdRwLock<HashMap<String, (String, Instant)>>,
103103
secret_inbox: StdRwLock<HashMap<String, Vec<GossippedSecret>>>,
@@ -420,7 +420,7 @@ impl CryptoStore for MemoryStore {
420420
&self,
421421
room_id: &RoomId,
422422
session_id: &str,
423-
) -> Result<Option<RoomKeyWithheldEvent>> {
423+
) -> Result<Option<RoomKeyWithheldEntry>> {
424424
Ok(self
425425
.direct_withheld_info
426426
.read()
@@ -1272,11 +1272,10 @@ mod integration_tests {
12721272
store::{
12731273
types::{
12741274
BackupKeys, Changes, DehydratedDeviceKey, PendingChanges, RoomKeyCounts,
1275-
RoomSettings, StoredRoomKeyBundleData, TrackedUser,
1275+
RoomKeyWithheldEntry, RoomSettings, StoredRoomKeyBundleData, TrackedUser,
12761276
},
12771277
CryptoStore,
12781278
},
1279-
types::events::room_key_withheld::RoomKeyWithheldEvent,
12801279
Account, DeviceData, GossipRequest, GossippedSecret, SecretInfo, Session, UserIdentityData,
12811280
};
12821281

@@ -1372,7 +1371,7 @@ mod integration_tests {
13721371
&self,
13731372
room_id: &RoomId,
13741373
session_id: &str,
1375-
) -> Result<Option<RoomKeyWithheldEvent>, Self::Error> {
1374+
) -> Result<Option<RoomKeyWithheldEntry>, Self::Error> {
13761375
self.0.get_withheld_info(room_id, session_id).await
13771376
}
13781377

0 commit comments

Comments
 (0)