Skip to content

Conversation

kaylendog
Copy link
Contributor

@kaylendog kaylendog commented Aug 12, 2025

Depends on #5511, #5512 and #5523.

  • Add OutboundGroupSession::encrypt_state.
  • Add GroupSessionManager::encrypt_state and a private helper function ::encrypt_inner.
  • Add OlmMachine::encrypt_state_event and ::encrypt_state_event_raw.
  • Add naive state key unpacking and verification to OlmMachine::decrypt_room_event_inner.

@kaylendog kaylendog self-assigned this Aug 12, 2025
@kaylendog kaylendog force-pushed the kaylendog/msc3414/crypto branch 2 times, most recently from 4a93d4a to ac72e92 Compare August 12, 2025 13:24
Copy link

codspeed-hq bot commented Aug 12, 2025

CodSpeed Performance Report

Merging #5519 will not alter performance

Comparing kaylendog:kaylendog/msc3414/crypto (17818dd) with main (ae7f0fe)

Summary

✅ 31 untouched benchmarks

@kaylendog kaylendog force-pushed the kaylendog/msc3414/crypto branch from ac72e92 to 0e56b6d Compare August 12, 2025 13:29
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.59%. Comparing base (ae7f0fe) to head (17818dd).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...trix-sdk-crypto/src/olm/group_sessions/outbound.rs 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5519      +/-   ##
==========================================
+ Coverage   88.57%   88.59%   +0.02%     
==========================================
  Files         340      340              
  Lines       93690    93701      +11     
  Branches    93690    93701      +11     
==========================================
+ Hits        82982    83012      +30     
+ Misses       6575     6556      -19     
  Partials     4133     4133              

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

@kaylendog kaylendog force-pushed the kaylendog/msc3414/crypto branch 4 times, most recently from dc09c52 to 0504cf0 Compare August 14, 2025 14:53
Comment on lines +137 to +141
/// The outer state key could not be verified against the inner encrypted
/// state key and type.
#[cfg(feature = "experimental-encrypted-state-events")]
#[error("decryption failed because the state key failed to validate")]
StateKeyVerificationFailed,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be split into a larger variety of cases:

  • MalformedStateKey - when the outer encrypted event state key is not formatted as str:str.
  • MismatchBodyType - when the decrypted ciphertext is not a state event but the outer event is.
  • EventTypeMismatch - when the outer event type does not match the inner.
  • StateKeyMismatch - when the outer state key does not match the inner.

These may not be worth implementing?

Comment on lines +1001 to +1005

/// The outer state key could not be verified against the inner encrypted
/// state key and type.
#[cfg(feature = "experimental-encrypted-state-events")]
StateKeyVerificationFailed,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kaylendog kaylendog force-pushed the kaylendog/msc3414/crypto branch 2 times, most recently from 4edd1a2 to dc93006 Compare August 15, 2025 10:38
@kaylendog kaylendog marked this pull request as ready for review August 15, 2025 13:34
@kaylendog kaylendog requested review from a team as code owners August 15, 2025 13:34
@kaylendog kaylendog requested review from stefanceriu and richvdh and removed request for a team and stefanceriu August 15, 2025 13:34
This commit also refactors out what would be common code between
::encrypt and ::encrypt_state to a helper ::encrypt_inner.

Signed-off-by: Skye Elliot <[email protected]>
Modifies `OlmMachine::decrypt_room_event_inner` to call a new method
`OlmMachine::verify_packed_state_key` which, if the event is a state
event, verifies that the original event's state key, when unpacked,
matches the state key and event type in the decrypted event content.

Introduces MegolmError::StateKeyVerificationFailed and
UnableToDecryptReason::StateKeyVerificationFailed which are thrown when
the verification fails.

Signed-off-by: Skye Elliot <[email protected]>
@kaylendog kaylendog force-pushed the kaylendog/msc3414/crypto branch from dc93006 to 17818dd Compare August 15, 2025 13:41
@kaylendog
Copy link
Contributor Author

Closing in favour of a branch local to this repository for branch-matching.

@kaylendog kaylendog closed this Aug 15, 2025
@kaylendog kaylendog removed the request for review from richvdh August 15, 2025 13: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.

1 participant