-
Notifications
You must be signed in to change notification settings - Fork 320
feat(crypto): Support EncryptionInfo for olm encrypted messages when using add_event_handler
#5099
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5099 +/- ##
==========================================
- Coverage 85.14% 85.13% -0.01%
==========================================
Files 329 329
Lines 36912 36939 +27
==========================================
+ Hits 31429 31449 +20
- Misses 5483 5490 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
crates/matrix-sdk-base/src/client.rs
Outdated
false // Exclude events with no type or encrypted | ||
} | ||
}) | ||
.map(matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent::PlainText) |
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.
When there is no encryption, to-device are not processed by the olm machine. There is no UnProcessed
variant of ProcessedToDeviceEvent
(not sure it would make sense :/).
So anyhow, we can just ignore the encrypted to-device as they are useless. So we can just map to PlainText variant?
I wonder if we should at some point remove the optional e2e-encryption
feature flag
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.
Huh, but how are events we fail to decrypt treated? Why not treat them just like that?
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.
Looks sensible to me. A couple of optional minor comments.
let captured_info: Arc<Mutex<Option<EncryptionInfo>>> = Arc::new(Mutex::new(None)); | ||
|
||
client.add_event_handler({ | ||
let captured = captured_event.clone(); |
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'd prefer this to be called captured_event
too.
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.
Thx @andybalam I updated the test 041e50d
let captured_info = captured_info.clone(); | ||
move |ev: AnyToDeviceEvent, encryption_info: Option<EncryptionInfo>| { | ||
let mut captured_lock = captured.lock(); | ||
*captured_lock = Some(ev); |
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.
Can we lock and update in the same line of code? Might be nicer?
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.
Alright, I think most of this looks good and makes sense.
I don't think we should completely filter out UTDs in case E2EE is disabled at compile time, the rest are small nits.
crates/matrix-sdk-base/src/client.rs
Outdated
false // Exclude events with no type or encrypted | ||
} | ||
}) | ||
.map(matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent::PlainText) |
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.
Huh, but how are events we fail to decrypt treated? Why not treat them just like that?
crates/matrix-sdk-base/src/sync.rs
Outdated
.field( | ||
"to_device", | ||
&DebugListOfRawEventsNoId( | ||
self.to_device.iter().map(|p| p.to_raw()).collect::<Vec<_>>().as_slice(), |
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 a bit expensive to clone the whole thing for a debug output, can't we have an as_raw()
that will borrow the thing instead?
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 did a similar thing to DebugListOfRawEventsNoId for list of processed to device 3eaaa30
@@ -120,6 +120,15 @@ impl MatrixMockServer { | |||
alice_olm.update_tracked_users([bob_user_id.as_ref()]).await.unwrap(); | |||
} | |||
|
|||
// let bob be aware of Alice keys in order to be able to decrypt custom | |||
// to-device (the device keys check are not delayed for non-crypto to-device |
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 they are in fact only delayed or rather deferred for m.room.key
events since dropping those would lead to a lot of UTDs.
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 clarified (I am not sure what is exactly done for key bundles, but no need to go in details 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 think this is now good to go, we just need to fix the changelog entry.
To double check, this isn't a breaking change, right? Existing event handlers will continue on working, they'll just ignore the new EncryptionInfo
field.
crates/matrix-sdk/CHANGELOG.md
Outdated
- `Client::add_event_handler`: Set `Option<EncryptionInfo>` in `EventHandlerData` for to-device messages. | ||
If the to-device message was encrypted, the `EncryptionInfo` will be set. If it is `None` the message was sent in clear. | ||
([#5099](https://github.com/matrix-org/matrix-rust-sdk/pull/5099)) |
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 has been put in the wrong place, it's not part of the 0.12.0 release.
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.
oh right, got hit by the merge. d92eceb
To double check, this isn't a breaking change, right? Existing event handlers will continue on working
Yes no change for existing event handlers.
Existing event handlers for to_device that requested the EncryptionInfo
were always getting None, now they will get something if the event was encrypted.
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.
Thanks, looks good now.
Should I just squash merge?
... which includes matrix-org/matrix-rust-sdk#5099, which moves `ProcessedToDeviceEvent` to matrix-sdk-common.
Main change
In
event_handler/mod.rs
there is a new methodhandle_sync_to_device_events(..)
that will dispatch the to-device messages with the olm variant ofEncryptionInfo
.The sync response struct
SyncResponse
now havepub to_device: Vec<ProcessedToDeviceEvent>
instead of the oldpub to_device: Vec<Raw<AnyToDeviceEvent>>
Context
It is now possible to get an Olm
EncryptionInfo
when register an event handler for to-device messages (previously the encryption_info was alwaysNone
for to-device`.Make it possible to make a difference between a plaintext and a successfully decrypted to-device message.
There is now a new variant of
EncryptionInfo
that will be passed to the to-device event handlers.There might be a change that would be better to review alone 125aec6
=> I needed to move
ProcessedToDeviceEvent
from thecrypto
crate to the commoncrate
. If not it was making it complex to compile with thee2e
feature not enabled. This is the same reason why SyncTimelineEvent/UnableToDecryptReason/Encryption info are already in the common crate.Based on #5074
Signed-off-by: