Skip to content

Commit 9cbfbfb

Browse files
committed
fix(crypto): Store session ID in EncryptionInfo, and use it to redecrypt items even if they are not UTDs.
1 parent 366bf4b commit 9cbfbfb

File tree

7 files changed

+20
-4
lines changed

7 files changed

+20
-4
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
@@ -51,6 +51,7 @@ pub fn make_test_event(room_id: &RoomId, content: &str) -> TimelineEvent {
5151
sender_claimed_keys: Default::default(),
5252
},
5353
verification_state: VerificationState::Verified,
54+
session_id: "mysessionid9".to_owned(),
5455
};
5556

5657
let event = EventFactory::new()

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ pub struct EncryptionInfo {
302302
/// Callers that persist this should mark the state as dirty when a device
303303
/// change is received down the sync.
304304
pub verification_state: VerificationState,
305+
/// The Megolm session ID that was used to encrypt this event.
306+
#[serde(default)]
307+
pub session_id: String,
305308
}
306309

307310
/// Represents a matrix room event that has been returned from `/sync`,
@@ -541,10 +544,13 @@ impl TimelineEventKind {
541544
}
542545
}
543546

544-
/// The Megolm session ID that was used to send this event, if it is a UTD.
547+
/// The Megolm session ID that was used to send this event, if it was
548+
/// encrypted.
545549
pub fn session_id(&self) -> Option<String> {
546550
match self {
547-
TimelineEventKind::Decrypted(_decrypted_room_event) => None,
551+
TimelineEventKind::Decrypted(decrypted_room_event) => {
552+
Some(decrypted_room_event.encryption_info.session_id.clone())
553+
}
548554
TimelineEventKind::UnableToDecrypt { utd_info, .. } => utd_info.session_id.clone(),
549555
TimelineEventKind::PlainText { .. } => None,
550556
}
@@ -1051,6 +1057,7 @@ mod tests {
10511057
sender_claimed_keys: Default::default(),
10521058
},
10531059
verification_state: VerificationState::Verified,
1060+
session_id: "xyz".to_owned(),
10541061
},
10551062
unsigned_encryption_info: Some(BTreeMap::from([(
10561063
UnsignedEventLocation::RelationsReplace,
@@ -1089,6 +1096,7 @@ mod tests {
10891096
}
10901097
},
10911098
"verification_state": "Verified",
1099+
"session_id": "xyz",
10921100
},
10931101
"unsigned_encryption_info": {
10941102
"RelationsReplace": {"UnableToDecrypt": {
@@ -1137,6 +1145,7 @@ mod tests {
11371145
event.encryption_info().unwrap().algorithm_info,
11381146
AlgorithmInfo::MegolmV1AesSha2 { .. }
11391147
);
1148+
assert_eq!(event.encryption_info().unwrap().session_id, "");
11401149

11411150
// Test that the previous format, with an undecryptable unsigned event, can also
11421151
// be deserialized.
@@ -1363,6 +1372,7 @@ mod tests {
13631372
sender_claimed_keys: Default::default(),
13641373
},
13651374
verification_state: VerificationState::Verified,
1375+
session_id: "mysessionid76".to_owned(),
13661376
};
13671377

13681378
with_settings!({sort_maps =>true}, {
@@ -1392,6 +1402,7 @@ mod tests {
13921402
]),
13931403
},
13941404
verification_state: VerificationState::Verified,
1405+
session_id: "mysessionid112".to_owned(),
13951406
},
13961407
unsigned_encryption_info: Some(BTreeMap::from([(
13971408
UnsignedEventLocation::RelationsThreadLatestEvent,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ expression: info
1111
"sender_claimed_keys": {}
1212
}
1313
},
14-
"verification_state": "Verified"
14+
"verification_state": "Verified",
15+
"session_id": "mysessionid76"
1516
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ expression: "serde_json::to_value(&room_event).unwrap()"
1717
},
1818
"sender": "@sender:example.com",
1919
"sender_device": "ABCDEFGHIJ",
20+
"session_id": "mysessionid112",
2021
"verification_state": "Verified"
2122
},
2223
"event": {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,7 @@ impl OlmMachine {
16781678
.collect(),
16791679
},
16801680
verification_state,
1681+
session_id: session.session_id().to_owned(),
16811682
})
16821683
}
16831684

crates/matrix-sdk-ui/src/timeline/event_item/remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(in crate::timeline) struct RemoteEventTimelineItem {
6666
/// Where we got this event from: A sync response or pagination.
6767
pub origin: RemoteEventOrigin,
6868

69-
/// The megolm session ID used to send this event, if it is UTD.
69+
/// The megolm session ID used to send this event, if it was encrypted.
7070
pub session_id: Option<String>,
7171
}
7272

crates/matrix-sdk-ui/src/timeline/tests/edit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ async fn test_edit_updates_encryption_info() {
176176
sender_claimed_keys: BTreeMap::new(),
177177
},
178178
verification_state: VerificationState::Verified,
179+
session_id: "mysessionid6333".to_owned(),
179180
};
180181

181182
let original_event: TimelineEvent = DecryptedRoomEvent {

0 commit comments

Comments
 (0)