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

Try to load keys from key backup when a message fails to decrypt #2373

Merged
merged 13 commits into from
Jun 1, 2022

Conversation

duxovni
Copy link
Contributor

@duxovni duxovni commented May 16, 2022

Fixes element-hq/element-web#21026.

Also typescriptified TestClient while I was in the area, I can split that into a separate PR if that'd be preferable.


Here's what your changelog entry will look like:

✨ Features

@duxovni duxovni requested a review from a team as a code owner May 16, 2022 18:42
Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

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

Overall seems fine, thank you! Just some random suggestions and an edge case to consider.

spec/integ/megolm-backup.spec.ts Outdated Show resolved Hide resolved
src/crypto/algorithms/megolm.ts Outdated Show resolved Hide resolved
src/crypto/backup.ts Show resolved Hide resolved
src/crypto/backup.ts Outdated Show resolved Hide resolved
src/crypto/backup.ts Show resolved Hide resolved
duxovni and others added 6 commits May 18, 2022 00:12
Co-authored-by: Travis Ralston <travisr@matrix.org>
Co-authored-by: Travis Ralston <travisr@matrix.org>
Co-authored-by: Travis Ralston <travisr@matrix.org>
Co-authored-by: Travis Ralston <travisr@matrix.org>
@@ -1298,7 +1298,9 @@ class MegolmDecryption extends DecryptionAlgorithm {

if (res === null) {
// We've got a message for a session we don't have.
//
// try and get the missing key from the backup first
this.crypto.backupManager.queryKeyBackupRateLimited(event.getRoomId(), content.session_id).catch(() => {});
Copy link
Member

Choose a reason for hiding this comment

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

In order to reduce unneeded to_device traffic, on EA if we have a positive reply from the backup we don't call requestKeysForEvent. Is it possible to do the same here?

Copy link
Contributor Author

@duxovni duxovni May 19, 2022

Choose a reason for hiding this comment

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

Not trivially. If we naively await this operation, we get stuck in a deadlock because the key backup query operation includes importing the keys, which includes re-attempting decryption of the messages, which means waiting for the current decryption attempt to finish. So we can't use, or even know, the results of the backup query during the current decryption attempt, without a bunch of messy re-architecting. In order to still avoid sending key requests, we'd need to add more complicated state tracking to check whether we've already tried the key backups on a previous decryption attempt, as well as logic to immediately queue another decryption attempt if the backup query fails.

@duxovni duxovni requested a review from turt2live May 30, 2022 13:13
Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

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

would recommend waiting for the RC to be cut first, but lgtm

@duxovni duxovni merged commit 8412ccf into develop Jun 1, 2022
@duxovni duxovni deleted the fayed/load-key-backup branch June 1, 2022 04:43
su-ex added a commit to SchildiChat/matrix-js-sdk that referenced this pull request Jul 7, 2022
* Remove unused sessionStore ([\matrix-org#2455](matrix-org#2455)).
* Implement MSC3827: Filtering of `/publicRooms` by room type ([\matrix-org#2469](matrix-org#2469)).
* expose latestLocationEvent on beacon model ([\matrix-org#2467](matrix-org#2467)). Contributed by @kerryarchibald.
* Live location share - add start time leniency ([\matrix-org#2465](matrix-org#2465)). Contributed by @kerryarchibald.
* Log real errors and not just their messages, traces are useful ([\matrix-org#2464](matrix-org#2464)).
* Various changes to `src/crypto` files for correctness ([\matrix-org#2137](matrix-org#2137)). Contributed by @ShadowJonathan.
* Update MSC3786 implementation: Check the `state_key` ([\matrix-org#2429](matrix-org#2429)).
* Timeline needs to refresh when we see a MSC2716 marker event  ([\matrix-org#2299](matrix-org#2299)). Contributed by @MadLittleMods.
* Try to load keys from key backup when a message fails to decrypt ([\matrix-org#2373](matrix-org#2373)). Fixes element-hq/element-web#21026. Contributed by @duxovni.
* Send call version `1` as a string ([\matrix-org#2471](matrix-org#2471)). Fixes element-hq/element-web#22629.
* Fix issue with `getEventTimeline` returning undefined for thread roots in main timeline ([\matrix-org#2454](matrix-org#2454)). Fixes element-hq/element-web#22539.
* Add missing `type` property on `IAuthData` ([\matrix-org#2463](matrix-org#2463)).
* Clearly indicate that `lastReply` on a Thread can return falsy ([\matrix-org#2462](matrix-org#2462)).
* Fix issues with getEventTimeline and thread roots ([\matrix-org#2444](matrix-org#2444)). Fixes element-hq/element-web#21613.
* Live location sharing - monitor liveness of beacons yet to start ([\matrix-org#2437](matrix-org#2437)). Contributed by @kerryarchibald.
* Refactor Relations to not be per-EventTimelineSet ([\matrix-org#2412](matrix-org#2412)). Fixes matrix-org#2399 and element-hq/element-web#22298.
* Add tests for sendEvent threadId handling ([\matrix-org#2435](matrix-org#2435)). Fixes element-hq/element-web#22433.
* Make sure `encryptAndSendKeysToDevices` assumes devices are unique per-user. ([\matrix-org#2136](matrix-org#2136)). Fixes matrix-org#2135. Contributed by @ShadowJonathan.
* Don't bug the user while re-checking key backups after decryption failures ([\matrix-org#2430](matrix-org#2430)). Fixes element-hq/element-web#22416. Contributed by @duxovni.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants