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: Log details about olm session after encryption/decryption #3242

Merged
merged 6 commits into from
Mar 22, 2024

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Mar 19, 2024

Together with matrix-org/vodozemac#133, this produces output like:

 DEBUG matrix_sdk_crypto::olm::session: Successfully encrypted an event
    olm_session=Session { session_id: "p7/wyUC7jF3QoQykzVS0a4nhwc+GUNxg4IcO/UbND4M", sending_ratchet: DoubleRatchet(ActiveDoubleRatchet { parent_ratchet_key: Some("curve25519:Tm4Tg+61UDj3hdQy9RA8KBqWlrpLRCLsx/LIbg8HIUw"), ratchet_key: RatchetPublicKey("curve25519:0KLirzBvhFYoVEUNtaAMA5xIeRw8DieSFy+8sgWqDwg"), chain_index: 1, .. }), receiving_chains: [ReceiverChain { ratchet_key: "curve25519:HpzTu3kDkFLaL043GvmDa78QkYx5UJw7Eh31ccWlMHQ", chain_index: 1, skipped_message_keys: [], .. }, ReceiverChain { ratchet_key: "curve25519:fvesXrxw35teK2guQ183emcwGbuPE5VUy4EhcfnrkDE", chain_index: 1, skipped_message_keys: [], .. }, ReceiverChain { ratchet_key: "curve25519:iPXoz18BWAEGYHLrXr/JP2xGxCW4QJgRgfHrNK85Y1U", chain_index: 1, skipped_message_keys: [], .. }, ReceiverChain { ratchet_key: "curve25519:Tm4Tg+61UDj3hdQy9RA8KBqWlrpLRCLsx/LIbg8HIUw", chain_index: 2, skipped_message_keys: [], .. }], config: SessionConfig { version: V1 }, .. }
    at /home/rav/work/matrix-rust-sdk/crates/matrix-sdk-crypto/src/olm/session.rs:131
    in matrix_sdk_crypto::identities::device::encrypt with recipient="@t:xps9320.sw1v.org" recipient_device="PWEGIRZHZL" recipient_key=Some("curve25519:IU7l9RQQEBr4Fsuxf8m45o+4FgQ902ZnItiV+hDdbBY") message_id="cb3d3c0ef06a4fc88b9256b0d3793b08"

and:

 DEBUG matrix_sdk_crypto::olm::session: Decrypted an Olm message
    session=Session { session_id: "8QZ5J7zTOTm/CiewTdl0Ogf4NZI3hw0+EfAccBmiY5I", sending_ratchet: DoubleRatchet(InactiveDoubleRatchet { ratchet_key: "curve25519:IzlCl+Rt1JcNCSTVFq9ZWPUsZb3BF5Z7IOaRnAMrZTE", .. }), receiving_chains: [ReceiverChain { ratchet_key: "curve25519:+kCvSHbmusowgJJAnxSEBGvtnPFcdf48xCpOnoyuQWE", chain_index: 1, skipped_message_keys: [], .. }, ReceiverChain { ratchet_key: "curve25519:Ppe7WGeSTHXJXLwp4HZ/HHIEYFh67B/6AwdAf7LwGiY", chain_index: 1, skipped_message_keys: [], .. }, ReceiverChain { ratchet_key: "curve25519:IzlCl+Rt1JcNCSTVFq9ZWPUsZb3BF5Z7IOaRnAMrZTE", chain_index: 3, skipped_message_keys: [], .. }], config: SessionConfig { version: V1 }, .. }
    at /home/rav/work/matrix-rust-sdk/crates/matrix-sdk-crypto/src/olm/session.rs:87
    in matrix_sdk_crypto::olm::account::decrypt_and_parse_olm_message with sender="@a:xps9320.sw1v.org" sender_key="curve25519:Ftj2NSlSQ4XQJWp0JrPlHDaP0/0kW4X+qVhV+pPpPCg" Normal(Message { version: 3, ratchet_key: "curve25519:IzlCl+Rt1JcNCSTVFq9ZWPUsZb3BF5Z7IOaRnAMrZTE", chain_index: 2, .. }) session_id="8QZ5J7zTOTm/CiewTdl0Ogf4NZI3hw0+EfAccBmiY5I"
    in matrix_sdk_crypto::olm::account::decrypt_olm_v1 with sender_key="curve25519:Ftj2NSlSQ4XQJWp0JrPlHDaP0/0kW4X+qVhV+pPpPCg"
    in matrix_sdk_crypto::olm::account::decrypt_to_device_event with algorithm="m.olm.v1.curve25519-aes-sha2"
    in matrix_sdk_crypto::machine::receive_to_device_event with sender="@a:xps9320.sw1v.org" event_type="m.room.encrypted" message_id="a7a6cab1d381427f8c86822b9658de89"
    in matrix_sdk_crypto::machine::receive_sync_changes

@richvdh richvdh requested a review from a team as a code owner March 19, 2024 11:52
@richvdh richvdh requested review from poljar and removed request for a team March 19, 2024 11:52
self.last_use_time = SecondsSinceUnixEpoch::now();
debug!(?session, "Successfully encrypted an event");
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm deliberately moving this field from the span, to the individual event. Firstly, it's quite a lot of data and, if there were more than one event in this span, we wouldn't want to log it on every event. More importantly, it's important that we capture the state of the session after the encryption happens (we want to know if it's stepped the DH ratchet, etc.) Given that the state of the session changes over the lifetime of the span, it feels inappropriate to attach it to the span.

@richvdh richvdh marked this pull request as draft March 19, 2024 11:58
@richvdh richvdh force-pushed the rav/log_encryption_session branch from 0ab64b8 to abf5eac Compare March 19, 2024 12:16
@richvdh richvdh marked this pull request as ready for review March 19, 2024 13:24
Copy link

codecov bot commented Mar 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.74%. Comparing base (82bcf48) to head (a952e2e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3242   +/-   ##
=======================================
  Coverage   83.73%   83.74%           
=======================================
  Files         238      238           
  Lines       24567    24565    -2     
=======================================
- Hits        20572    20571    -1     
+ Misses       3995     3994    -1     

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

@richvdh richvdh marked this pull request as draft March 19, 2024 13:56
@richvdh richvdh changed the title Log details about olm session after encryption Log details about olm session after encryption/decryption Mar 19, 2024
@richvdh richvdh marked this pull request as ready for review March 19, 2024 14:25
@poljar
Copy link
Contributor

poljar commented Mar 19, 2024

Don't you want to bump the vodozemac dep as well?

@richvdh
Copy link
Member Author

richvdh commented Mar 19, 2024

Well I do, but this can land independently, so I thought I'd put it up for review while we're still dealing with vodozemac PRs.

@bnjbvr bnjbvr changed the title Log details about olm session after encryption/decryption crypto: Log details about olm session after encryption/decryption Mar 21, 2024
@richvdh richvdh enabled auto-merge (squash) March 21, 2024 13:55
@richvdh richvdh disabled auto-merge March 21, 2024 16:46
@richvdh richvdh merged commit 97959bb into main Mar 22, 2024
35 checks passed
@richvdh richvdh deleted the rav/log_encryption_session branch March 22, 2024 09:43
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