mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-24 23:19:34 -05:00
Peer check for incoming encrypted signatures
Alice validates that incoming encsig messages are coming from the peer-id that is associated with the swap. Encsig message from a peer-id different to the one associated with the swap are ignored.
This commit is contained in:
parent
c0501627c9
commit
3c2dfa830a
@ -195,11 +195,32 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SwarmEvent::Behaviour(OutEvent::EncryptedSignatureReceived{ msg, channel, peer }) => {
|
SwarmEvent::Behaviour(OutEvent::EncryptedSignatureReceived{ msg, channel, peer }) => {
|
||||||
let sender = match self.recv_encrypted_signature.remove(&msg.swap_id) {
|
let swap_id = msg.swap_id;
|
||||||
|
let swap_peer = self.db.get_peer_id(swap_id);
|
||||||
|
|
||||||
|
// Ensure that an incoming encrypted signature is sent by the peer-id associated with the swap
|
||||||
|
let swap_peer = match swap_peer {
|
||||||
|
Ok(swap_peer) => swap_peer,
|
||||||
|
Err(_) => {
|
||||||
|
tracing::warn!("Ignoring encrypted signature for unknown swap {} from {}", swap_id, peer);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if swap_peer != peer {
|
||||||
|
tracing::warn!(
|
||||||
|
%swap_id,
|
||||||
|
"Ignoring malicious encrypted signature from {}, expected to receive it from {}",
|
||||||
|
peer,
|
||||||
|
swap_peer);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let sender = match self.recv_encrypted_signature.remove(&swap_id) {
|
||||||
Some(sender) => sender,
|
Some(sender) => sender,
|
||||||
None => {
|
None => {
|
||||||
// TODO: Don't just drop encsig if we currently don't have a running swap for it, save in db
|
// TODO: Don't just drop encsig if we currently don't have a running swap for it, save in db
|
||||||
tracing::warn!(%peer, "No sender for encrypted signature, maybe already handled?");
|
tracing::warn!(%swap_id, "No sender for encrypted signature, maybe already handled?");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -207,7 +228,7 @@ where
|
|||||||
let mut responder = match sender.send(msg.tx_redeem_encsig).await {
|
let mut responder = match sender.send(msg.tx_redeem_encsig).await {
|
||||||
Ok(responder) => responder,
|
Ok(responder) => responder,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
tracing::warn!(%peer, "Failed to relay encrypted signature to swap");
|
tracing::warn!(%swap_id, "Failed to relay encrypted signature to swap");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user