diff --git a/matrix_sdk_crypto/src/key_request.rs b/matrix_sdk_crypto/src/key_request.rs index c77b8af9..5fa560a5 100644 --- a/matrix_sdk_crypto/src/key_request.rs +++ b/matrix_sdk_crypto/src/key_request.rs @@ -216,6 +216,11 @@ impl KeyRequestMachine { &self.user_id } + /// Our own device id. + pub fn device_id(&self) -> &DeviceId { + &self.device_id + } + pub fn outgoing_to_device_requests(&self) -> Vec { #[allow(clippy::map_clone)] self.outgoing_to_device_requests @@ -301,6 +306,17 @@ impl KeyRequestMachine { &self, event: &ToDeviceEvent, ) -> OlmResult> { + // Some servers might send to-device events to ourselves if we send one + // out using a wildcard instead of a specific device as a recipient. + // + // Check if we're the sender of this key request event and ignore it if + // so. + if &event.sender == self.user_id() + && &*event.content.requesting_device_id == self.device_id() + { + return Ok(None); + } + let key_info = match &event.content.action { Action::Request => { if let Some(info) = &event.content.body {