-
Notifications
You must be signed in to change notification settings - Fork 268
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
base: main
Are you sure you want to change the base?
Conversation
9a19fcf
to
9cbfbfb
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4644 +/- ##
==========================================
+ Coverage 85.82% 85.83% +0.01%
==========================================
Files 292 292
Lines 33761 33830 +69
==========================================
+ Hits 28974 29037 +63
- Misses 4787 4793 +6 ☔ View full report in Codecov by Sentry. |
741aa40
to
d83e187
Compare
…imelineItem ... meaning we attempt to redecrypt them even if they are not UTDs. The redecryption doesn't actually work - that will be fixed in the next commit.
…etry decryption In later commits, we will make this cleverer, so it can calculate which non-UTD events need updating too.
Future commits will add code to try non-UTDs too, in another function.
d83e187
to
414f03d
Compare
I swapped the Rust team reviewer to @bnjbvr since I know he has questions about including session ID in the timeline item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems generally good to me. A few comments.
@@ -121,6 +123,12 @@ pub(super) trait RoomDataProvider: | |||
) -> impl Future<Output = Result<(), super::Error>> + SendOutsideWasm + 'a; | |||
|
|||
fn room_info(&self) -> Subscriber<RoomInfo>; | |||
|
|||
fn get_encryption_info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be "obvious" but this could use a doc-comment?
@@ -441,6 +443,14 @@ impl<'a> TimelineStateTransaction<'a> { | |||
} | |||
} | |||
|
|||
pub(super) fn replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc-comment?
@@ -368,6 +368,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { | |||
mut self, | |||
date_divider_adjuster: &mut DateDividerAdjuster, | |||
event_kind: TimelineEventKind, | |||
session_id: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally: I think we need a better name, or better documentation, or both, for things called session_id
. It's very unclear to a casual reader what it is supposed to be.
// In the timeline, this is used to find events that need re-decrypting but in | ||
// the message preview it is not used. | ||
let session_id = None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be baking in a bit of an assumption: is there no way we can get the session id here, to guard against future changes?
If not, we should document RemoteEventTimelineItem.session_id
to note that it is not always populated.
|
||
/// The megolm session ID used to send this event, if it is UTD. | ||
pub session_id: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't feel right here -- in particular the fact that it overlaps with encryption_info
.
Maybe we want to replace encryption_info
with an enum field. But it sounds like Benji might have bigger plans anyway.
/// `state` is the [`TimelineState`] state of the timeline. | ||
/// `retry_indices` contains the indices of events to try within the | ||
/// `state.items` `should_retry` checks that a session is included in | ||
/// the list of updated sessions. `decryptor` does the actual work of | ||
/// decrypting events. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a sort of informal convention of setting out parameter documentation as a markdown list.
let mut retry_decryption_indices = Vec::new(); | ||
let mut retry_info_indices = Vec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion here, but in the past I've been asked to use partition_map
for this sort of thing.
We could write this as a filter
followed by a partition_map
?
// Retry decrypting | ||
self.retry_event_decryption_by_index(state, retry_indices, should_retry, decryptor).await; | ||
// Retry decrypting UTDs | ||
let state = self.state.clone().write_owned().await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels like this state.clone()
should happen inside retry_event_decryption_by_index
@@ -225,6 +228,45 @@ impl TimelineState { | |||
txn.commit(); | |||
} | |||
|
|||
/// Try to fetch [`EncryptionInfo`] for the events with the supplied | |||
/// indices, and update them where we succeed. | |||
pub(super) async fn retry_event_encryption_info<P: RoomDataProvider>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to say that having this here but retry_event_decryption_by_index
in the other place feels rather asymmetric. Is there a reason they need to be different?
Fixes element-hq/element-meta#2697
I'm sorry it's a big change. I've tried to break it into decent commits, and I did a couple of preparatory PRs to make it less painful, but it's still a bit to get your head around.
The basic idea is that when a session is updated and we call
retry_event_decryption
, we don't only look at UTDs any more - now we also look at decrypted events, and re-request theirEncryptionInfo
, in case it has improved.