From ca42657abb9f794a4912cea8953edaba31f23a0f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 9 Aug 2024 12:51:36 +0100 Subject: [PATCH] crypto: Log the received device keys on an encrypted olm message Attempt to summarise the received keys. --- crates/matrix-sdk-crypto/src/machine/mod.rs | 6 +++++- crates/matrix-sdk-crypto/src/types/events/olm_v1.rs | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk-crypto/src/machine/mod.rs b/crates/matrix-sdk-crypto/src/machine/mod.rs index b2c782dbef0..7e951615669 100644 --- a/crates/matrix-sdk-crypto/src/machine/mod.rs +++ b/crates/matrix-sdk-crypto/src/machine/mod.rs @@ -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())).unwrap_or((None, None)), + "Received a decrypted to-device event", + ); match &*decrypted.result.event { AnyDecryptedOlmEvent::RoomKey(e) => { diff --git a/crates/matrix-sdk-crypto/src/types/events/olm_v1.rs b/crates/matrix-sdk-crypto/src/types/events/olm_v1.rs index 0ecf19c2268..dc33fffdae7 100644 --- a/crates/matrix-sdk-crypto/src/types/events/olm_v1.rs +++ b/crates/matrix-sdk-crypto/src/types/events/olm_v1.rs @@ -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.