-
Notifications
You must be signed in to change notification settings - Fork 270
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: Implement OlmMachine::{set_,}room_settings
#3042
Conversation
/// If the settings are valid, they will be persisted to the crypto store. | ||
/// These settings are not used directly by this library, but the saved | ||
/// settings can be retrieved via [`get_room_settings`]. | ||
pub async fn set_room_settings( |
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 completely sure if this is the best place for this API: OlmMachine
already has a million methods and adding more isn't my favourite thing. But the only other likely-looking place seems to be the Store itself, and given this is application-level logic, that doesn't feel 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 agree with your reasoning. Let's keep it here for the moment. We can refactor later.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3042 +/- ##
==========================================
+ Coverage 83.67% 83.72% +0.04%
==========================================
Files 222 222
Lines 23288 23310 +22
==========================================
+ Hits 19487 19516 +29
+ Misses 3801 3794 -7 ☔ View full report in Codecov by Sentry. |
d81456a
to
78b5b2a
Compare
7ed63ae
to
532897a
Compare
We need to make sure we guard against servers downgrading the encryption settings, or breaking them with unsupported algorithms. It's not *entirely* clear what the expectation is here, but legacy crypto in matrix-js-sdk blocks any changes to the settings at all, so we'll follow suit for now.
532897a
to
2314a74
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.
The PR is really good. Commits are well written, the patch contains a lot of docs (I can't highlight enough how much I like that), the tests are good… Just a few tiny nitty gritty things , but overall it looks great. Thanks!
@@ -855,12 +856,15 @@ macro_rules! cryptostore_integration_tests { | |||
let settings_1 = RoomSettings { | |||
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2, | |||
only_allow_trusted_devices: true, | |||
session_rotation_period: Some(Duration::from_millis(10000)), |
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.
It's probably a bit more Rust idiomatic to write this as follows:
- Duration::from_millis(10000)),
+ Duration::from_millis(10_000)),
I also wonder if we could simply use : from_secs(10)
?
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.
sure
/// encryption algorithm or whether to encrypt only for trusted devices. | ||
/// | ||
/// These settings can be modified via [`OlmMachine::set_room_settings`]. | ||
pub async fn get_room_settings(&self, room_id: &RoomId) -> StoreResult<Option<RoomSettings>> { |
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 get_
prefix isn't really Rust idiomatic. I know it's present in the store API, let's not propagate this error :-]. Can you rename get_room_settings
to room_settings
please?
/// If the settings are valid, they will be persisted to the crypto store. | ||
/// These settings are not used directly by this library, but the saved | ||
/// settings can be retrieved via [`get_room_settings`]. | ||
pub async fn set_room_settings( |
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 agree with your reasoning. Let's keep it here for the moment. We can refactor later.
// `set_room_settings`. By way of an easy way to do so, we start a | ||
// StoreTransaction. There's no need to commit() it: we're just using it as a | ||
// lock guard. |
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 good to me 👍. Thanks for the comment, that's the kind of comment I like!
machine | ||
.set_room_settings(room_id!("!test:localhost"), &RoomSettings::default()) | ||
.await | ||
.unwrap(); |
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 code is not necessary for this test. I understand the idea, but it looks we can safely remove it.
|
||
/// The maximum number of messages an encryption session should be used for, | ||
/// before it is rotated. | ||
pub session_rotation_period_msgs: Option<usize>, |
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 use long names please, like session_rotation_period_for_messages
maybe?
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.
We can, but it might be worth noting that this name is based on the name in the matrix protocol (rotation_period_msgs
, https://spec.matrix.org/v1.9/client-server-api/#mroomencryption)
I'm not really sure I can think of a better name than session_rotation_period_messages
. number_of_messages_to_rotate_session_after
feels very cumbersome.
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 OK. Then session_rotation_period_messages
is fine for me. Thanks!
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.
We can, but it might be worth noting that this name is based on the name in the matrix protocol (
rotation_period_msgs
, https://spec.matrix.org/v1.9/client-server-api/#mroomencryption)
There is also a rotation_period_msgs
in EncryptionSettings
:
pub rotation_period_msgs: u64, |
... though why it uses a u64
I don't know.
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 OK. Then session_rotation_period_messages is fine for me. Thanks!
Ok!
OlmMachine::{get,set}_room_settings
OlmMachine::{set_,}room_settings
@Hywan I think I've addressed all your comments. Could you take another look? |
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!
Signed-off-by: Richard van der Hoff <[email protected]>
We need to make sure we guard against servers downgrading the encryption settings, or breaking them with unsupported algorithms. It's not entirely clear what the expectation is here, but legacy crypto in matrix-js-sdk blocks any changes to the settings at all, so we'll follow suit for now.
This PR also extends the supported
RoomSettings
. Suggest reviewing each commit separately.Signed-off-by: