matrix-rust-sdk icon indicating copy to clipboard operation
matrix-rust-sdk copied to clipboard

crypto: Move device_keys to DecryptedOlmV1Event as per MSC4147

Open andybalaam opened this issue 1 year ago • 3 comments

Part of https://github.com/matrix-org/matrix-rust-sdk/issues/3542

Fixes a mistake I made in https://github.com/matrix-org/matrix-rust-sdk/pull/3556 - I included device_keys in the content and it should be outside as per MSC4147

andybalaam avatar Jul 01 '24 14:07 andybalaam

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 01 '24 15:07 codecov[bot]

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

andybalaam avatar Jul 02 '24 14:07 andybalaam

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: https://github.com/matrix-org/matrix-rust-sdk/blob/2507a450df4bfe12d163a8141a2e47932c1ee21c/crates/matrix-sdk-crypto/src/olm/session.rs#L351-L353

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

poljar avatar Jul 03 '24 07:07 poljar

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

Thank you, done in 46b4d00b6e

andybalaam avatar Jul 03 '24 11:07 andybalaam

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

andybalaam avatar Jul 03 '24 11:07 andybalaam

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.

poljar avatar Jul 03 '24 11:07 poljar