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(feat): Key distribution errors for pin violations #3662

Closed

Conversation

BillCarsonFr
Copy link
Member

Part of invisible crypto, follow up of #3639

Fixes #3565

Following support for key pinning, we have now to manage pinning violation when encrypting olm messages (room key distribution).

The new encryption errors:

/// Depending on the sharing strategy for room keys, the distribution of the
/// room key could fail.
#[derive(Error, Debug)]
pub enum RoomKeyDistributionError {
    /// When encrypting using the IdentityBased strategy.
    /// Will be thrown when sharing room keys when there is a new identity for a
    /// user that has not been confirmed by the user.
    /// Application should display identity changes to the user as soon as
    /// possible to avoid hitting this case. If it happens the app might
    /// just retry automatically after the identity change has been
    /// notified, or offer option to cancel.
    #[error("Encryption failed because there are key pinning violation, please re-pin or verify the problematic users")]
    KeyPinningViolation(Vec<OwnedUserId>),

    /// Cross-signing is required for encryption with invisible crypto
    #[error("Encryption failed: Setup cross-signing on your account")]
    CrossSigningNotSetup,
    /// The current device needs to be verified when encrypting using the
    /// IdentityBased strategy. Apps should prevent sending in the UI to
    /// avoid hitting this case.
    #[error("Encryption failed: Verify your device to send encrypted messages")]
    SendingFromUnverifiedDevice,
}
  • Public API changes documented in changelogs (optional)

Signed-off-by:

@BillCarsonFr BillCarsonFr force-pushed the valere/invisible_crypto/identity_local_tofu_2 branch from daf7331 to 1d4cefb Compare July 22, 2024 15:29
@BillCarsonFr BillCarsonFr force-pushed the valere/invisible_crypto/identity_sharing_with_pin branch from 8fbd9a4 to e309219 Compare July 23, 2024 08:46
Base automatically changed from valere/invisible_crypto/identity_local_tofu_2 to main August 2, 2024 07:13
@uhoreg uhoreg marked this pull request as ready for review August 6, 2024 20:00
@uhoreg uhoreg requested a review from a team as a code owner August 6, 2024 20:00
@uhoreg uhoreg requested review from jmartinesp and removed request for a team August 6, 2024 20:00
Copy link

codecov bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 91.93548% with 5 lines in your changes missing coverage. Please review.

Project coverage is 84.18%. Comparing base (70f46d4) to head (afda06a).
Report is 2 commits behind head on main.

Files Patch % Lines
...c/session_manager/group_sessions/share_strategy.rs 91.93% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3662      +/-   ##
==========================================
+ Coverage   84.12%   84.18%   +0.05%     
==========================================
  Files         263      263              
  Lines       27584    27621      +37     
==========================================
+ Hits        23205    23252      +47     
+ Misses       4379     4369      -10     

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

Copy link
Contributor

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

I can't say much about the crypto logic, but the code LGTM and the docs and comments made it a bit easier to understand, thanks. I have a couple of comments, but feel free to ignore them.

Comment on lines 270 to 271
let shared: BTreeSet<OwnedDeviceId> = shared.keys().cloned().collect();
let shared: BTreeSet<&DeviceId> = shared.iter().map(|d| d.as_ref()).collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to collect it twice?

Copy link
Member

Choose a reason for hiding this comment

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

+1. I fixed another copy of this code recently in 1e58c03

@richvdh
Copy link
Member

richvdh commented Aug 8, 2024

Per #3565 (comment): this needs an update so that an error is not thrown if a TOFU-trusted user has rotated their identity.

@uhoreg uhoreg requested a review from a team as a code owner August 9, 2024 21:32
@uhoreg uhoreg requested review from richvdh and removed request for a team August 9, 2024 21:32
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

A few comments. Also, needs a changelog entry.

#[error(transparent)]
/// The room key that was to be shared was not shared because the sharing
/// strategy could not be fulfilled.
RoomKeySharingStrategyError(RoomKeySharingStrategyError),
Copy link
Member

Choose a reason for hiding this comment

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

#3810 added a "SessionRecipientCollectionError" which I think we should be using here, rather than adding a new error type.

let strategy = CollectStrategy::new_identity_based();

let encryption_settings =
EncryptionSettings { sharing_strategy: strategy.clone(), ..Default::default() };
Copy link
Member

Choose a reason for hiding this comment

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

no need to .clone() here. Could just inline strategy

}

pub fn initial_key_query() -> KeyQueryResponse {
let data = response_from_file(&json!({
Copy link
Member

Choose a reason for hiding this comment

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

#3823 removed response_from_file

device_id!("NZFSPBRLDO")
}

pub fn initial_key_query() -> KeyQueryResponse {
Copy link
Member

Choose a reason for hiding this comment

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

could you give all these methods a doc-comment explaining what they mean?

Comment on lines +619 to +620
#[async_test]
async fn test_share_identity_strategy_no_cross_signing() {
Copy link
Member

Choose a reason for hiding this comment

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

it would be good to add a doc-comment for each of these tests explaining what they are testing.

)
.await;

assert!(request_result.is_ok());
Copy link
Member

Choose a reason for hiding this comment

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

this is normally spelt .unwrap()

let request_result = machine
.share_room_key(
fake_room_id,
// vec![KeyDistributionTestData::dan_id()].into_iter(),
Copy link
Member

Choose a reason for hiding this comment

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

dead code?

}

#[async_test]
async fn test_share_identity_strategy_report_pinning_violation() {
Copy link
Member

Choose a reason for hiding this comment

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

as well as a all the cleanups suggested for the other test, this test could do with some comments to explain what's going on.

Comment on lines +128 to +129
let mut devices: BTreeMap<OwnedUserId, Vec<DeviceData>> = Default::default();
let mut withheld_devices: Vec<(DeviceData, WithheldCode)> = Default::default();
Copy link
Member

Choose a reason for hiding this comment

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

not sure that moving this declaration is helpful?


for user_id in users {
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a big refactor, combined with behavioural changes. Please could we have the refactor and the behavioral change as separate commits?

Comment on lines +733 to +734
.other()
.unwrap()
Copy link
Member

Choose a reason for hiding this comment

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

I think some of these .other().unwrap() calls become unnecessary with #3847

@uhoreg
Copy link
Member

uhoreg commented Aug 23, 2024

I "merged" main into here (by which, I mean that I rewrote the changes on top of current main, plus #3884), and tried to use the new has_identity_verification_violation function that was introduced to make it error when we had a previously-verified user under the device-based strategy. But I noticed that that function doesn't take identity pinning into account, which I guess is fine for the device-based strategy. But with the fact that we are no longer erroring on TOFU user rotations, I'm wondering if we even need pinning any more.

richvdh pushed a commit that referenced this pull request Aug 27, 2024
…anges (#3884)

This is part of #3662,
pulled out to into a separate PR. Recent changes in `main` made it
pretty much impossible to merge this section of code from `main` into
that PR, and Rich wanted to see the refactoring bits separate from the
behavioural changes. So I've re-written the refactoring.

Pulls the `match` on `sharing_strategy` outside of the `for` loop, and
moves any code that is specific to one strategy into the appropriate
branch.
@richvdh
Copy link
Member

richvdh commented Sep 2, 2024

@uhoreg what is the state of this PR? Can it be closed, in favour of #3896?

@bnjbvr bnjbvr changed the title feat(crypto): Key distribution errors for pin violations crypto(feat): Key distribution errors for pin violations Sep 3, 2024
@uhoreg
Copy link
Member

uhoreg commented Sep 3, 2024

Obsoleted by #3896

@uhoreg uhoreg closed this Sep 3, 2024
@poljar poljar deleted the valere/invisible_crypto/identity_sharing_with_pin branch November 5, 2024 11:45
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.

Invisible Crypto | Share Room Keys: Update the Identity Based sharing strategy to use the tofu_trusted flag
4 participants