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

Conversation

andybalaam
Copy link
Member

@andybalaam andybalaam commented Feb 7, 2025

Fixes element-hq/element-meta#2697
Fixes https://github.com/element-hq/crypto-internal/issues/398

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 their EncryptionInfo, in case it has improved.

@andybalaam andybalaam changed the title refactor(crypto): Store the session ID of a UTD in RemoteEventTimelineItem fix(crypto): Redecrypt non-UTD messages to remove no-longer-relevant warning shields Feb 7, 2025
@andybalaam andybalaam force-pushed the andybalaam/redecrypt-non-utds branch from 9a19fcf to 9cbfbfb Compare February 7, 2025 14:17
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 80.59701% with 13 lines in your changes missing coverage. Please review.

Project coverage is 86.36%. Comparing base (3fbf159) to head (3b1e18e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...es/matrix-sdk-common/src/deserialized_responses.rs 0.00% 6 Missing ⚠️
...i/src/timeline/controller/decryption_retry_task.rs 89.13% 5 Missing ⚠️
...trix-sdk-ui/src/timeline/event_item/content/mod.rs 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4644      +/-   ##
==========================================
+ Coverage   86.34%   86.36%   +0.01%     
==========================================
  Files         291      291              
  Lines       34233    34283      +50     
==========================================
+ Hits        29559    29607      +48     
- Misses       4674     4676       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andybalaam andybalaam force-pushed the andybalaam/redecrypt-non-utds branch 4 times, most recently from d83e187 to 414f03d Compare February 14, 2025 11:59
@andybalaam andybalaam marked this pull request as ready for review February 14, 2025 12:11
@andybalaam andybalaam requested review from a team as code owners February 14, 2025 12:11
@andybalaam andybalaam requested review from stefanceriu, richvdh and bnjbvr and removed request for a team and stefanceriu February 14, 2025 12:11
@andybalaam
Copy link
Member Author

I swapped the Rust team reviewer to @bnjbvr since I know he has questions about including session ID in the timeline item.

Copy link
Member

@richvdh richvdh left a 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.

@andybalaam andybalaam marked this pull request as draft February 17, 2025 12:26
@bnjbvr bnjbvr removed their request for review February 17, 2025 13:05
@andybalaam andybalaam requested review from bnjbvr and richvdh February 17, 2025 15:16
@andybalaam andybalaam marked this pull request as ready for review February 17, 2025 15:16
@andybalaam
Copy link
Member Author

This is ready for re-review. I think I would recommend looking at the full diff now, since the review changes reverted some of what I did in earlier commits. I will rebase into nice commits after review.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few stylistic change requests below. On the one hand, thanks for not storing any extra data in the TimelineItemContent itself, on the other… you know my opinion about adding more code to the timeline re-decryption. This all should be moved somewhere else, and tested in isolation there (could be in the crypto crate, the main SDK crate, inside or outside the event cache,… any place other than the timeline would make more sense).

@andybalaam andybalaam requested a review from bnjbvr March 7, 2025 12:53
It's unusual to have the method on the parent type when the field type
could also hold the method. In fact, this was the only bool getter
inspecting the timeline's content, so let's move the method next to as
its siblings, for consistency, and let's spell it out fully for clarity.
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving, i'll address my own comments as a separate commit and will squash-merge it altogether.

/// Create a replacement TimelineItem for the supplied one, with new
/// [`EncryptionInfo`] from the supplied `room_data_provider`. Returns None if
/// the supplied item is not a remote event, or if it doesn't have a session ID.
async fn replacement_for<P: RoomDataProvider>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, let's name it make_replacement_for.

@bnjbvr bnjbvr enabled auto-merge (squash) March 11, 2025 06:47
@bnjbvr bnjbvr merged commit c8536e9 into main Mar 11, 2025
42 checks passed
@bnjbvr bnjbvr deleted the andybalaam/redecrypt-non-utds branch March 11, 2025 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EX: Messages sent after an identity reset can sometimes be flagged as sent from insecure device
4 participants