-
Notifications
You must be signed in to change notification settings - Fork 252
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
Crypto: Return an error when sharing a room key to a verified user, who has an unverified device (optional encryption setting) #3810
Conversation
e715223
to
1b05380
Compare
b643839
to
6e6f71d
Compare
6e6f71d
to
9874e40
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3810 +/- ##
==========================================
+ Coverage 84.07% 84.09% +0.01%
==========================================
Files 262 262
Lines 27544 27581 +37
==========================================
+ Hits 23158 23193 +35
- Misses 4386 4388 +2 ☔ View full report in Codecov by Sentry. |
9874e40
to
de4cc83
Compare
/// Whitelisted devices will receive group sessions regardless of their | ||
/// verification status. | ||
pub fn is_whitelisted(&self) -> bool { | ||
self.local_trust_state() == LocalTrust::Ignored |
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 LocalTrust::Ignored actually is really Whitelist, as it says that the trust state should be ignored. Should it be renamed to Whitelisted? to be consistent with LocalTrust::BlackListed?
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.
yeahh, this feels pretty confusing to me, and could do with clean up.
That said: "whitelisted"/"blacklisted" are somewhat problematic terms, and we might take the opportunity to rename both.
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
@@ -228,16 +313,61 @@ fn split_recipients_withhelds_for_user( | |||
user_devices.into_values().partition_map(|d| { | |||
if d.is_blacklisted() { |
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 if/else sequence is getting harder and harder to read with all the possible settings/outcome.
We might want to get rid of the partition/Either system.
Also the set of settings can create invalid configuration, like only_allow_trusted_devices
+ error_on_unsigned_device_of_verified_users
doesn't really make sense.
Will get worse with more options
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 broadly good to me. Some initial thoughts, but nothing major -- except my question about checking own_identity.is_verified()
.
I'll take a closer look tomorrow.
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
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 few more, more nitpicky comments. I still need to take a closer look at the tests.
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
/// Once the problematic devices are blacklisted or whitelisted the | ||
/// caller can retry to share a second time. This has to be done | ||
/// once per problematic device. | ||
#[serde(default)] |
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.
is this persisted somewhere, that makes the default
necessary?
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.
EncryptionSettings
is persisted in the OutboundSession at least, and maybe some clients could persist the encryption settings? All the things we put as serializable could be persisted... (are we serializing things for other reasons? like for bindings to pass things back and forth?)
We really need to improve that part of the sdk, it's too easy to make a change that would break applications.
I thought about having tests with json exports of all the serializable things that are persisted, that just tries to load them back and see if it breaks. This would be minimum. Or we need to think about a specific trait for things that are expected to be serialized persisted, with a version of some form
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.
EncryptionSettings
is persisted in the OutboundSession at least
Hrm... does that means that, once we enable the new behaviour, it won't work until megolm sessions are replaced?
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 don't think so. But there is something odd with the settings how they are now.
The settings persisted is used mainly (i think) in the code to detect if the session should be rotated.
I think that only part of the EncryptionSetting
should be persisted (rotation_period, rotation_period_msgs, and history_visibility?).
The old only_allow_trusted_devices
that was in the EncryptionSetting (replaced now by CollectStrategy) shouldn't be persisted. Because anyhow if a change on this setting change the set of devices that should receive it, then is_session_overshared_for_user
will detect it and rotate the session.
history_visibility
is different because you want to rotate if you decide that this session could be shared now as part of history sharing for example, event if it doesn't change right now who get the 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.
I'm not really following all of this. It sounds like we shouldn't be persisting EncryptionSettings
at all to me.
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 change the rotation_period
you would want the session to be rotated immediatly instead of having to wait for the old one to be rotated based on the old rotation period. Same for history_visibility
, you want to make history sharable from the point you change to that setting and not make early history available?
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.
Both of those things sound like we should be taking notice of the current EncryptionSettings
, not whatever was persisted to the store.
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
/// Whitelisted devices will receive group sessions regardless of their | ||
/// verification status. | ||
pub fn is_whitelisted(&self) -> bool { | ||
self.local_trust_state() == LocalTrust::Ignored |
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.
yeahh, this feels pretty confusing to me, and could do with clean up.
That said: "whitelisted"/"blacklisted" are somewhat problematic terms, and we might take the opportunity to rename both.
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
fbc66d6
to
e1ad36f
Compare
/// Should fail to send when a verified user has unverified devices. | ||
pub error_on_verified_user_problem: bool, |
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.
e1ad36f
to
37329ea
Compare
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.
On request, I've just skimmed the PR and looked at Rust idioms. I've got some small suggestions to improve readability of the code, which I think should be addressed; confusing a bool for another could be particularly bad in the context of crypto, IMO. LGTM otherwise!
} | ||
match device_identity { | ||
UserIdentityData::Own(_) => { | ||
own_identity.is_verified() && own_identity.is_device_signed(self).is_ok() |
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.
preexisting, and can be done in another PR: having is_device_signed
return a Result when all the callers check for is_ok()
makes me think it should just return a boolean instead of a Result
👀
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.
Agreed. Let's fix that in another PR.
/// * `identity` - The identity of another user which we want to check has | ||
/// been verified. | ||
pub fn is_identity_verified(&self, identity: &OtherUserIdentityData) -> bool { | ||
self.is_verified() && self.is_identity_signed(identity).is_ok() |
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.
same here for is_identity_signed
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
ea1d8a2
to
5dbc599
Compare
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.
Super nice, thanks!
Use a for loop rather than `partition_map`. We're about to add a third list, so partition_map won't work. (partition_map ends up using Vec::push under the hood, so this is pretty much equivalent.)
... and use it to remove a bit of duplicated code.
The list of boolean arguments is confusing. We may as well just construct the `DeviceBasedStrategy` directly.
Again, the list of boolean arguments is confusing.
Add (as yet unimplemented) `error_on_verified_user_problem` option
This thing was confusing. What is "legacy" about it?
38a4477
to
5f24f8e
Compare
Fixes #3792
Suggest review commit-by-commit.