Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crypto): Redecrypt non-UTD messages to remove no-longer-relevant warning shields #4644

Merged
merged 39 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8f953b9
tool(ui): Allow getting encryption info via a Room instance
andybalaam Feb 12, 2025
362e232
refactor(crypto): Store session ID in EncryptionInfo
andybalaam Feb 11, 2025
cec1c3f
tool(timeline): Allow fetching the session ID of an EncryptedMessage
andybalaam Feb 28, 2025
d61ceca
fix(crypto): When a session updates, re-fetch encryption info for non…
andybalaam Feb 13, 2025
1071441
test(timeline): Test for updating the timeline on new session info
andybalaam Mar 3, 2025
77edb35
Fix typos
andybalaam Mar 5, 2025
5825aa8
Clippy fixes
andybalaam Mar 5, 2025
9752a02
Attempt to fix flake by waiting for the event to appear
andybalaam Mar 5, 2025
a3f39b7
Merge branch 'main' into andybalaam/redecrypt-non-utds
andybalaam Mar 5, 2025
3fc0b0f
Merge branch 'main' into andybalaam/redecrypt-non-utds
andybalaam Mar 5, 2025
94b7776
Add a doc comment for get_encryption_info
andybalaam Mar 5, 2025
55c9b56
Add a comment to explain that get_encryption_info passes through to Room
andybalaam Mar 6, 2025
7131ed4
Doc comment for EncryptedMessage::session_id
andybalaam Mar 6, 2025
0d93fcb
Add a comment explaining that we are waiting for the event
andybalaam Mar 6, 2025
7b12cd3
Remove unneeded serde(default)
andybalaam Mar 7, 2025
5eb3944
Return reference from session_id
andybalaam Mar 7, 2025
449f234
Replace .into() with more explicit ::from()
andybalaam Mar 7, 2025
cef82ad
Use subscribe_events to ignore date divider
andybalaam Mar 7, 2025
e4e6e83
Separate sanity checks into blocks
andybalaam Mar 7, 2025
2735180
Add a newline
andybalaam Mar 7, 2025
da8a993
Mock get_encryption_info by storing a hashmap
andybalaam Mar 7, 2025
7acac9b
Remove unneeded pub(crate)
andybalaam Mar 7, 2025
52846f7
Remove unneeded Just
andybalaam Mar 7, 2025
8de03ad
Replace if with filter
andybalaam Mar 7, 2025
f501afe
Merge replacement_item into replacement_for
andybalaam Mar 7, 2025
585ceba
Prefix tests with test_
andybalaam Mar 7, 2025
6212cf3
Rename retry_fetch_encryption_info
andybalaam Mar 7, 2025
c3066c9
Expand comment about why we are calling event_indices_to_retry_decryp…
andybalaam Mar 7, 2025
e52add1
Specify that we are returning indices from event_indices_to_retry_dec…
andybalaam Mar 7, 2025
8e0af15
Collapse two and_thens
andybalaam Mar 7, 2025
650fe4b
Replace items as we create them in retry_fetch_encryption_info
andybalaam Mar 7, 2025
5b3cc43
Replace summarize_* methods with direct assertions
andybalaam Mar 7, 2025
4ea1127
Provide timeline_messages function to simplify assertions
andybalaam Mar 7, 2025
6570556
Move helpers inside test_new_users_first_messages_dont_warn_about_ins…
andybalaam Mar 7, 2025
dd55342
feat(timeline): Provide is_utd on EventTimelineItem
andybalaam Mar 7, 2025
34013b3
Make use of new is_utd method on EventTimelineItem
andybalaam Mar 7, 2025
1423281
refactor(timeline): move `is_utd()` to `TimelineItemContent`
bnjbvr Mar 11, 2025
513d1e8
Merge branch 'bnjbvr/is-unable-to-decrypt' into andybalaam/redecrypt-…
bnjbvr Mar 11, 2025
3b1e18e
review
bnjbvr Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn make_test_event(room_id: &RoomId, content: &str) -> TimelineEvent {
sender_claimed_keys: Default::default(),
},
verification_state: VerificationState::Verified,
session_id: Some("mysessionid9".to_owned()),
};

let event = EventFactory::new()
Expand Down
21 changes: 21 additions & 0 deletions crates/matrix-sdk-common/src/deserialized_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ pub struct EncryptionInfo {
/// Callers that persist this should mark the state as dirty when a device
/// change is received down the sync.
pub verification_state: VerificationState,
/// The Megolm session ID that was used to encrypt this event, or None if
/// this info was stored before we collected this data.
pub session_id: Option<String>,
}

/// Represents a matrix room event that has been returned from `/sync`,
Expand Down Expand Up @@ -540,6 +543,19 @@ impl TimelineEventKind {
TimelineEventKind::PlainText { event } => event,
}
}

/// The Megolm session ID that was used to send this event, if it was
/// encrypted.
pub fn session_id(&self) -> Option<&str> {
match self {
TimelineEventKind::Decrypted(decrypted_room_event) => {
decrypted_room_event.encryption_info.session_id.as_ref()
}
TimelineEventKind::UnableToDecrypt { utd_info, .. } => utd_info.session_id.as_ref(),
TimelineEventKind::PlainText { .. } => None,
}
.map(String::as_str)
}
}

#[cfg(not(tarpaulin_include))]
Expand Down Expand Up @@ -1042,6 +1058,7 @@ mod tests {
sender_claimed_keys: Default::default(),
},
verification_state: VerificationState::Verified,
session_id: Some("xyz".to_owned()),
},
unsigned_encryption_info: Some(BTreeMap::from([(
UnsignedEventLocation::RelationsReplace,
Expand Down Expand Up @@ -1080,6 +1097,7 @@ mod tests {
}
},
"verification_state": "Verified",
"session_id": "xyz",
},
"unsigned_encryption_info": {
"RelationsReplace": {"UnableToDecrypt": {
Expand Down Expand Up @@ -1128,6 +1146,7 @@ mod tests {
event.encryption_info().unwrap().algorithm_info,
AlgorithmInfo::MegolmV1AesSha2 { .. }
);
assert_eq!(event.encryption_info().unwrap().session_id, None);

// Test that the previous format, with an undecryptable unsigned event, can also
// be deserialized.
Expand Down Expand Up @@ -1364,6 +1383,7 @@ mod tests {
sender_claimed_keys: Default::default(),
},
verification_state: VerificationState::Verified,
session_id: Some("mysessionid76".to_owned()),
};

with_settings!({ sort_maps => true, prepend_module_to_snapshot => false }, {
Expand Down Expand Up @@ -1393,6 +1413,7 @@ mod tests {
]),
},
verification_state: VerificationState::Verified,
session_id: Some("mysessionid112".to_owned()),
},
unsigned_encryption_info: Some(BTreeMap::from([(
UnsignedEventLocation::RelationsThreadLatestEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ expression: info
"sender_claimed_keys": {}
}
},
"verification_state": "Verified"
"verification_state": "Verified",
"session_id": "mysessionid76"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ expression: "serde_json::to_value(&room_event).unwrap()"
},
"sender": "@sender:example.com",
"sender_device": "ABCDEFGHIJ",
"session_id": "mysessionid112",
"verification_state": "Verified"
},
"event": {
Expand Down
1 change: 1 addition & 0 deletions crates/matrix-sdk-crypto/src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,7 @@ impl OlmMachine {
.collect(),
},
verification_state,
session_id: Some(session.session_id().to_owned()),
})
}

Expand Down
Loading
Loading