-
Notifications
You must be signed in to change notification settings - Fork 258
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
feat(sdk-crypto): Add Identity based room key sharing strategy #3607
Conversation
9c325a2
to
e3b8900
Compare
e3b8900
to
a12e281
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3607 +/- ##
==========================================
+ Coverage 83.86% 83.87% +0.01%
==========================================
Files 254 254
Lines 25892 25909 +17
==========================================
+ Hits 21714 21731 +17
Misses 4178 4178 ☔ View full report in Codecov by Sentry. |
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.
Much better PR, thanks for taking the time to make this reviewable. I left some nits.
@@ -764,6 +764,18 @@ impl ReadOnlyDevice { | |||
) | |||
} | |||
|
|||
pub(crate) fn is_cross_signed_by_owner( |
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 method exists for Device
matrix-rust-sdk/crates/matrix-sdk-crypto/src/identities/device.rs
Lines 274 to 286 in 3be84a5
/// Is this device cross signed by its owner? | |
pub fn is_cross_signed_by_owner(&self) -> bool { | |
self.device_owner_identity.as_ref().is_some_and(|device_identity| match device_identity { | |
// If it's one of our own devices, just check that | |
// we signed the device. | |
ReadOnlyUserIdentities::Own(identity) => identity.is_device_signed(&self.inner).is_ok(), | |
// If it's a device from someone else, check | |
// if the other user has signed this device. | |
ReadOnlyUserIdentities::Other(device_identity) => { | |
device_identity.is_device_signed(&self.inner).is_ok() | |
} | |
}) | |
} |
Please just move the body of that function over here instead of duplicating it.
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.
done
None => { | ||
// withheld all the users devices, we need to have an identity for this | ||
// distribution mode | ||
denied_devices_with_code |
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.
Let's return in each branch of that match a RecipientDevices
struct, makes it a bit clearer that we're not really mutating multiple times the above vectors and might get rid of a couple of allocations.
denied_devices_with_code | |
RecipientDevices { | |
denied_devices_with_code: user_devices | |
.into_values() | |
.map(|d| (d, WithheldCode::Unauthorised)), | |
..Default::default() | |
} |
(You won't be able to apply that suggestion because I can't modify multiple lines and you need further modifications in the rest of the function).
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Show resolved
Hide resolved
.find(|(d, _)| d.device_id() == KeyDistributionTestData::dan_unsigned_device_id()) | ||
.expect("This dan's device should receive a withheld code"); | ||
|
||
assert_eq!(code.as_str(), WithheldCode::Unauthorised.as_str()); |
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.
Why the as_str()
on both sides? This should be the same type, no?
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.
updated
crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs
Outdated
Show resolved
Hide resolved
device_owner_identity: &ReadOnlyUserIdentities, | ||
) -> bool { | ||
match device_owner_identity { | ||
ReadOnlyUserIdentities::Own(identity) => 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.
Could you please preserve the comments from the other body of this function?
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.
done
Draft because based on #3605Fixes #3563
This PR just introduce a new way to distribute room keys based on identities, by only sharing with devices signed by their owner.
This is a first PR to introduce this mode, but it will be really usable once we introduce some support for identity TOFU.
Signed-off-by: