Skip to content
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: withhold outgoing messages to unsigned dehydrated devices #4551

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Jan 17, 2025

Per #4313, we should not send outgoing messages to dehydrated devices that are not signed by the user's identity

Fixes #4313

@richvdh richvdh requested review from a team as code owners January 17, 2025 16:40
@richvdh richvdh requested review from poljar and removed request for a team January 17, 2025 16:40
@richvdh richvdh force-pushed the rav/withheld_to_unverified_dehydrated branch from 001dcf6 to cac1067 Compare January 17, 2025 16:54
Comment on lines -164 to +163
// We only need the user identity if `only_allow_trusted_devices` or
// `error_on_verified_user_problem` is set.
let device_owner_identity =
if only_allow_trusted_devices || error_on_verified_user_problem {
store.get_user_identity(user_id).await?
} else {
None
};
let device_owner_identity = store.get_user_identity(user_id).await?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now also need the identity if the user has a dehydrated device. Trying to optimise away this call in the cases where we weren't going to need the identity was getting too complicated, so let's just do it every time.

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.39%. Comparing base (f7db52e) to head (919f073).
Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-crypto/src/identities/device.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4551      +/-   ##
==========================================
- Coverage   85.40%   85.39%   -0.02%     
==========================================
  Files         285      285              
  Lines       32213    32217       +4     
==========================================
  Hits        27513    27513              
- Misses       4700     4704       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@richvdh
Copy link
Member Author

richvdh commented Jan 20, 2025

I need to update this in view of #4313 (comment)

@richvdh richvdh marked this pull request as draft January 20, 2025 21:22
@richvdh richvdh removed the request for review from poljar January 20, 2025 21:22
 * Split the existing `set_up_test_machine` into two parts, so we can set up
   the test OlmMachine without importing data for other users
 * Add some helpers for creating common `EncryptionSettings`
@richvdh richvdh force-pushed the rav/withheld_to_unverified_dehydrated branch from cac1067 to aa82b96 Compare January 21, 2025 13:21
Per #4313, we should not
send outgoing messages to dehydrated devices that are not signed by the current
pinned/verified identity.
@richvdh richvdh force-pushed the rav/withheld_to_unverified_dehydrated branch from aa82b96 to 919f073 Compare January 21, 2025 13:32
@richvdh richvdh marked this pull request as ready for review January 21, 2025 13:32
@richvdh
Copy link
Member Author

richvdh commented Jan 22, 2025

I need to update this in view of #4313 (comment)

(Now done)

@richvdh richvdh requested a review from poljar January 22, 2025 09:29
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor the meat of the logic a bit, I find the function to be quite a challenging read.

@@ -406,23 +398,50 @@ fn split_devices_for_user(
for d in user_devices.into_values() {
if d.is_blacklisted() {
recipient_devices.denied_devices_with_code.push((d, WithheldCode::Blacklisted));
} else if d.local_trust_state() == LocalTrust::Ignored {
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in the loop has, due to the additions of various new settings, grown a bit into a maze, it's quite hard to enumerate that all the different settings and combinations thereof don't have some logic flaw in them.

I think this needs to be put into a separate method which would then allow us to easier test the logic as well.

Something like:

enum Decision {
    Ok,
    Withhold(WithheldCode),
    Err,
}

fn decide_what_to_do_with_device(device: &Device) -> Decision {
    ...
}

Then write a match statement per setting, i.e.

if only_allow_trusted {
    match (d.is_verified(), d.is_dehydrated)
       ...
    }
}

Or something along those lines which would allow us to easily see if our logic is exhaustive and we didn't forget a case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeySharing, DevicebasedStrategy | Exclude insecure dehydrated devices when sending messages
2 participants