Skip to content

Commit

Permalink
crypto: Log the received device keys on an encrypted olm message
Browse files Browse the repository at this point in the history
Attempt to summarise the received keys.
  • Loading branch information
richvdh committed Aug 16, 2024
1 parent 352a836 commit 84f2735
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/matrix-sdk-crypto/src/machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,11 @@ impl OlmMachine {
decrypted: &mut OlmDecryptionInfo,
changes: &mut Changes,
) -> OlmResult<()> {
debug!("Received a decrypted to-device event");
debug!(
sender_device_keys =
?decrypted.result.event.sender_device_keys().map(|k| (k.curve25519_key(), k.ed25519_key())),
"Received a decrypted to-device event",
);

match &*decrypted.result.event {
AnyDecryptedOlmEvent::RoomKey(e) => {
Expand Down
5 changes: 4 additions & 1 deletion crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,10 @@ impl InboundGroupSession {
#[cfg(not(tarpaulin_include))]
impl fmt::Debug for InboundGroupSession {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("InboundGroupSession").field("session_id", &self.session_id()).finish()
f.debug_struct("InboundGroupSession")
.field("session_id", &self.session_id())
.field("sender_data", &self.sender_data)
.finish()
}
}

Expand Down
11 changes: 11 additions & 0 deletions crates/matrix-sdk-crypto/src/types/events/olm_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ impl AnyDecryptedOlmEvent {
AnyDecryptedOlmEvent::Dummy(e) => e.content.event_type(),
}
}

/// The sender's device keys, if supplied in the message as per MSC4147
pub fn sender_device_keys(&self) -> Option<&DeviceKeys> {
match self {
AnyDecryptedOlmEvent::Custom(_) => None,
AnyDecryptedOlmEvent::RoomKey(e) => e.device_keys.as_ref(),
AnyDecryptedOlmEvent::ForwardedRoomKey(e) => e.device_keys.as_ref(),
AnyDecryptedOlmEvent::SecretSend(e) => e.device_keys.as_ref(),
AnyDecryptedOlmEvent::Dummy(e) => e.device_keys.as_ref(),
}
}
}

/// An `m.olm.v1.curve25519-aes-sha2` decrypted to-device event.
Expand Down

0 comments on commit 84f2735

Please sign in to comment.