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: Move device_keys to DecryptedOlmV1Event as per MSC4147 #3633

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

andybalaam
Copy link
Contributor

@andybalaam andybalaam commented Jul 1, 2024

Part of #3542

Fixes a mistake I made in #3556 - I included device_keys in the content and it should be outside as per MSC4147

@andybalaam andybalaam requested a review from a team as a code owner July 1, 2024 14:52
@andybalaam andybalaam requested review from bnjbvr and removed request for a team July 1, 2024 14:52
@poljar poljar requested review from poljar and removed request for bnjbvr July 1, 2024 14:58
Copy link

codecov bot commented Jul 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.26%. Comparing base (9aa2774) to head (25ed92f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3633      +/-   ##
==========================================
- Coverage   84.26%   84.26%   -0.01%     
==========================================
  Files         259      259              
  Lines       26596    26595       -1     
==========================================
- Hits        22411    22410       -1     
  Misses       4185     4185              

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

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.

Looks good, but now that #3517 has been merged we can add a test confirming that we put things in the right place.

@andybalaam
Copy link
Contributor Author

Looks good, but now that #3517 has been merged we can add a test confirming that we put things in the right place.

Can I have a hint on how to write a test? I've spent the day trying to call matrix_sdk_crypto::olm::session::Session::encrypt or matrix_sdk_crypto::identities::device::ReadOnlyDevice::maybe_encrypt_room_key or similar and then feed the result into matrix_sdk_crypto::olm::account::Account::decrypt_to_device_eventto check that the device keys come through, but I haven't managed to find the right incantation and I can't find any tests that directly call these things.

Is there an example I can follow? Thanks

@poljar
Copy link
Contributor

poljar commented Jul 3, 2024

Looks good, but now that #3517 has been merged we can add a test confirming that we put things in the right place.

Can I have a hint on how to write a test? I've spent the day trying to call matrix_sdk_crypto::olm::session::Session::encrypt or matrix_sdk_crypto::identities::device::ReadOnlyDevice::maybe_encrypt_room_key or similar and then feed the result into matrix_sdk_crypto::olm::account::Account::decrypt_to_device_eventto check that the device keys come through, but I haven't managed to find the right incantation and I can't find any tests that directly call these things.

Is there an example I can follow? Thanks

#3517 added a test which uses the weaker serde_json::Value type to check this:

// Also ensure that the encrypted payload has the device keys.
let plaintext: Value = serde_json::from_str(&bob_session_result.plaintext).unwrap();
assert_eq!(plaintext["device_keys"]["user_id"].as_str(), Some("@alice:localhost"));

You could modify this test to also check using our stronger type you modified.

@andybalaam
Copy link
Contributor Author

You could modify this test to also check using our stronger type you modified.

Thank you, done in 46b4d00

@andybalaam andybalaam requested a review from poljar July 3, 2024 11:14
@andybalaam
Copy link
Contributor Author

Out of interest, do you know why Session::encrypt uses json! instead of constructing and serializing a DecryptedOlmV1Event?

@poljar
Copy link
Contributor

poljar commented Jul 3, 2024

Out of interest, do you know why Session::encrypt uses json! instead of constructing and serializing a DecryptedOlmV1Event?

Nowadays probably just for historic reasons, we didn't use to have the DecryptedOlmV1Event type. But I'm not completely sure that we can just exchange the types, the C in DecryptedOlmV1Event has more trait bounds, if it's possible it certainly isn't easy.

crates/matrix-sdk-crypto/src/olm/session.rs Outdated Show resolved Hide resolved
@andybalaam andybalaam force-pushed the andybalaam/move-device_keys-out-of-content branch from 1c5f302 to 25ed92f Compare July 4, 2024 10:07
@andybalaam andybalaam enabled auto-merge (rebase) July 4, 2024 10:07
@andybalaam andybalaam merged commit 03d4a30 into main Jul 4, 2024
39 checks passed
@andybalaam andybalaam deleted the andybalaam/move-device_keys-out-of-content branch July 4, 2024 10:22
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.

2 participants