-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
ElementR: Ensure Encryption order per room #3973
ElementR: Ensure Encryption order per room #3973
Conversation
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.
as discussed elsewhere: I don't think this does the right thing
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.
LGTM mostly. A few suggestions, nits, etc.
src/rust-crypto/RoomEncryptor.ts
Outdated
// message is finally sent. The actual event encryption request will arrive after wait for the prepareForEncryption | ||
// promise to resolve, and then do again an ensureEncryptionSession that should be no op as we already share the room key. |
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.
The actual event encryption request will arrive after wait for the prepareForEncryption promise to resolve
I don't really understand this, or what it is trying to say. "The actual event encryption request" == "a call to encryptEvent
"? So you're saying that the application will wait for prepareForEncryption
to complete before it calls encryptEvent
? I don't think that's right.
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 it's how it's supposed to work. Legacy is doing the same.
If you starts typing then call encrypt event, we let the prepare finish, then do the encrypt. The share room key part for the secong call should be no op as the room key is already shared
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.
Notice that anyhow the olmMachine.shareRoomKey() should be locked per room
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.
if you starts typing then call encrypt event, we let the prepare finish, then do the encrypt.
but that's not what the comment says?
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.
... or rather the comment says that we expect the application to wait, and I don't think we do. That's why we have to wait here.
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 updated the comment:
// If `encryptEvent` is invoked before `prepareForEncryption` has completed, the `encryptEvent` call will wait for
// `prepareForEncryption` to complete before executing.
// The part where `encryptEvent` shares the room key would be no op as it was already performed by prepareForEncryption.
Co-authored-by: Richard van der Hoff <[email protected]>
Co-authored-by: Richard van der Hoff <[email protected]>
Co-authored-by: Richard van der Hoff <[email protected]>
Co-authored-by: Richard van der Hoff <[email protected]>
Co-authored-by: Richard van der Hoff <[email protected]>
Co-authored-by: Richard van der Hoff <[email protected]>
Co-authored-by: Richard van der Hoff <[email protected]>
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.
A couple of nits, lgtm otherwise
Co-authored-by: Richard van der Hoff <[email protected]>
Co-authored-by: Richard van der Hoff <[email protected]>
Fixes element-hq/element-web#26684
Encryption order was not ensured with the existing code. So in some case editing an inflight message would encrypt the edit first and schedule it first. That will cause an error because it will send an edit of an unknown event.
It can also invert the message order.
There is a sheduler currently but it doesn't handle encryption, it only queues the event for sending.
The scheduler should probably handle the encryption, but for now I modified RoomEncryptor to ensure order.
Notice that there was already a ordering mechanism but only to ensure order of
olmMachine.shareRoomKey
but it was not enough.Added a test to reproduce the problem if the fix is not present.
Checklist
Here's what your changelog entry will look like:
🐛 Bug Fixes