-
Notifications
You must be signed in to change notification settings - Fork 260
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
Configurable sender trust checking on decrypting #3701
Conversation
8fbd9a4
to
e309219
Compare
…_sharing_with_pin' into invisible_crypto/decrypt
I'm not sure how to handle the higher levels. It seems like we should be storing the setting in some struct so that, e.g. messages that come down /sync get decrypted with the right setting, but I'm not sure where it should go. I don't see a relevant struct that has settings, so there isn't a clear place to put the setting. |
Sorry, I don't have much experience with the SDK and much less with the crypto part of it. Maybe someone else from the team can answer your questions? @poljar , @andybalaam? |
@@ -74,6 +74,9 @@ pub enum SenderData { | |||
/// If false, we had simply accepted the key as this user's latest | |||
/// key. | |||
master_key_verified: bool, | |||
|
|||
#[serde(default)] | |||
identity_needs_user_approval: 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.
I added this so that session_data_finder can find this information, so that the trust level can be calculated. But I think that it would be better to combine this with the master_key_verified
field, and make them into a new master_key_status
field that is an enum with Unverified
, NeedsApproval
, and Verified
options. Maybe we should even add another option for the case where the user's previous identity was verified, but they rotated their identity. Maybe something like PreviousIdentityVerified
.
What do you think?
(If you think it's better to keep it as-is, then I'll write documentation for this field, but I didn't want to write it if I was going to remove it right away.)
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.
You've asked me for my opinion on this question, but this change doesn't seem to appear anywhere in the PR, so I don't think I have enough context on the change to form a sensible opinion.
I believe the tests fail because |
Discussion: should we throw an error when an identity has been rotated?
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3701 +/- ##
==========================================
- Coverage 84.11% 84.09% -0.02%
==========================================
Files 262 262
Lines 27599 27628 +29
==========================================
+ Hits 23214 23235 +21
- Misses 4385 4393 +8 ☔ View full report in Codecov by Sentry. |
@richvdh I think this is ready for review. I do have one question that I'd like an opinion on. The commit history is a big mess, partially due to being based on a branch that got force-pushed at some point, so this PR should probably get squash-merged. |
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.
Some initial thoughts.
I'm really struggling to follow this as one big diff. +600 lines isn't huge, but there is actually quite a lot changing here, and following the logic though everywhere is hard.
I think it might be better to start again on the commit history, and break it into smaller changes. For example - let's separate the changes to SenderData
from the changes to decryption. Then add the DecryptionSettings
parameter without actually implementing it, so that we can see the real changes without all the noise from that.
@@ -32,6 +32,9 @@ Changes: | |||
|
|||
Breaking changes: | |||
|
|||
- `OlmMachine::decrypt_room_event` now takes an `EncryptionSettings` argument. |
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.
- `OlmMachine::decrypt_room_event` now takes an `EncryptionSettings` argument. | |
- `OlmMachine::decrypt_room_event` now takes a `DecryptionSettings` argument. |
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 should probably also document some of the changes to publicly-visible types (MegolmError
, VerificationLevel
, etc)
@@ -115,6 +116,10 @@ pub enum MegolmError { | |||
/// The storage layer returned an error. | |||
#[error(transparent)] | |||
Store(#[from] CryptoStoreError), | |||
|
|||
/// The sender's cross-signing identity isn't trusted | |||
#[error("message quarantined because sender's cross-signing identity is not trusted: {0}")] |
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.
what does "quarantined" mean here? Is it stored somewhere within the store?
|
||
/// The sender's cross-signing identity isn't trusted | ||
#[error("message quarantined because sender's cross-signing identity is not trusted: {0}")] | ||
SenderIdentity(#[from] VerificationLevel), |
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.
SenderIdentity
feels like it doesn't quite describe the problem here.
SenderIdentity(#[from] VerificationLevel), | |
SenderIdentityNotTrusted(#[from] VerificationLevel), |
@@ -115,6 +116,10 @@ pub enum MegolmError { | |||
/// The storage layer returned an error. | |||
#[error(transparent)] | |||
Store(#[from] CryptoStoreError), | |||
|
|||
/// The sender's cross-signing identity isn't trusted |
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 sender's cross-signing identity isn't trusted | |
/// An encrypted message wasn't decrypted, because the sender's cross-signing identity isn't trusted. |
(This should maybe also link to DecryptionSettings
and say that it only happens under some conditions)
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.
Actually, isn't it more "because the message could not be linked to a verified device" than specific to the sender's identity?
pub enum TrustRequirement { | ||
/// Decrypt events from everyone regardless of trust. | ||
Untrusted, | ||
/// Only decrypt events from cross-signed or legacy sessions (Megolm |
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.
/// Only decrypt events from cross-signed or legacy sessions (Megolm | |
/// Only decrypt events from cross-signed devices or legacy sessions (Megolm |
/// TODO: should this be merged with the master_key_verified field and | ||
/// turned into an enum? |
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.
Short answer: yes, this really feels like it ought to be a tri-state.
(#3846 added an OwnUserIdentityVerifiedState
enum for a similar reason; not sure we should reuse that, but I think it's a pattern we should follow)
A downside is that it breaks backwards-compatibility for the crypto store :/
/// | ||
/// This is used by `check_sender_trust_requirement`, and ensures that the | ||
/// sending device is cross-signed. | ||
fn check_sender_trusted(&self, encryption_info: &EncryptionInfo) -> MegolmResult<()> { |
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.
per a discussion today in #matrix-rust-sdk-dev
, helper functions should probably come after the functions they help.
// Helper function that encrypts a message and shares the Megolm session | ||
// with a recipient |
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.
helpers after the functions they help, please
/// Whether the user's master key was previously verified, but the | ||
/// current master key is not. |
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 this is the actual behaviour (and I'm not sure that it is), it needs a name that reflects it.
@@ -74,6 +74,9 @@ pub enum SenderData { | |||
/// If false, we had simply accepted the key as this user's latest | |||
/// key. | |||
master_key_verified: bool, | |||
|
|||
#[serde(default)] | |||
identity_needs_user_approval: 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.
You've asked me for my opinion on this question, but this change doesn't seem to appear anywhere in the PR, so I don't think I have enough context on the change to form a sensible opinion.
replaced by #3899 |
Signed-off-by: