Skip to content

Commit

Permalink
fix(crypto): Only accept forwarded room keys from our own trusted dev…
Browse files Browse the repository at this point in the history
…ices
  • Loading branch information
poljar committed Sep 28, 2022
1 parent 513afa5 commit 093fb5d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions crates/matrix-sdk-crypto/src/gossiping/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,21 @@ impl GossipMachine {
}
}

async fn should_accept_forward(
&self,
info: &GossipRequest,
sender_key: Curve25519PublicKey,
) -> Result<bool, CryptoStoreError> {
let device =
self.store.get_device_from_curve_key(&info.request_recipient, sender_key).await?;

if let Some(device) = device {
Ok(device.user_id() == self.user_id() && device.is_verified())
} else {
Ok(false)
}
}

/// Receive a forwarded room key event that was sent using any of our
/// supported content types.
async fn receive_supported_keys(
Expand All @@ -956,8 +971,22 @@ impl GossipMachine {
let algorithm = event.content.algorithm();

if let Some(info) = self.get_key_info(event).await? {
self.accept_forwarded_room_key(&info, &event.sender, sender_key, algorithm, content)
.await
if self.should_accept_forward(&info, sender_key).await? {
self.accept_forwarded_room_key(&info, &event.sender, sender_key, algorithm, content)
.await
} else {
warn!(
sender = %event.sender,
%sender_key,
room_id = %content.room_id,
session_id = content.session_id.as_str(),
claimed_sender_key = %content.claimed_sender_key,
"Received a forwarded room key from an unknown device, or \
from a device that the key request recipient doesn't own",
);

Ok(None)
}
} else {
warn!(
sender = %event.sender,
Expand Down

0 comments on commit 093fb5d

Please sign in to comment.