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

modify megolm's prepareToEncrypt to be cancellable #1255

Closed
uhoreg opened this issue Mar 10, 2020 · 1 comment
Closed

modify megolm's prepareToEncrypt to be cancellable #1255

uhoreg opened this issue Mar 10, 2020 · 1 comment

Comments

@uhoreg
Copy link
Member

uhoreg commented Mar 10, 2020

prepareToEncrypt is introduced in #1252 so that applications can pre-send keys to recipients before the message itself is ready to send, reducing the amount of work that needs to be done when the message is sent.

However, the current function cannot be cancelled if the key cannot be used after all (e.g. a user/device has left, so the key needs to be rotated).

@clarkf
Copy link
Contributor

clarkf commented Jan 8, 2023

I believe this is the root cause of element-hq/element-web#21612. Or, well, sorta. Mind if I take a stab at it?

MegolmEncryption#prepareToEncrypt does a bunch of expensive, blocking crypto on the main thread per untrusted device (see CrossSigningInfo#checkDeviceTrust). I don't think a simple cancellation callback will work, since it mostly blocks the caller.

The most straightforward option would be to break the work up into chunks, wrapped in setImmediate (or similar). Allow preemption between each checkDeviceTrust call. Then, cancellation could be added, and element-hq/element-web#21612 resolved (probably).

The "correct" solution would probably be to move the expensive crypto off the main thread, using a WebWorker or something. I don't think that's super reasonable, though, and would require some really sweeping changes.

clarkf added a commit to clarkf/matrix-js-sdk that referenced this issue Jan 8, 2023
NOTE: This commit introduces a backwards-compatible API change.

Adds the ability to cancel `MegolmEncryption#prepareToEncrypt` by returning
a cancellation function. The bulk of the processing happens in
`getDevicesInRoom`, which now accepts a 'getter' that allows the caller to
indicate cancellation.

See matrix-org#1255
Closes matrix-org#1255

Signed-off-by: Clark Fischer <clark.fischer@gmail.com>
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

No branches or pull requests

2 participants