Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dht): optimisation, no decrypt if public key dest doesn't match #4131

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions comms/dht/src/inbound/decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ where S: Service<DecryptedDhtMessage, Response = (), Error = PipelineError>
}
}

#[allow(clippy::too_many_lines)]
async fn validate_and_decrypt_message(
node_identity: Arc<NodeIdentity>,
message: DhtInboundMessage,
Expand All @@ -220,6 +221,24 @@ where S: Service<DecryptedDhtMessage, Response = (), Error = PipelineError>
return Err(DecryptionError::EncryptedMessageNoDestination);
}

if !message.dht_header.destination.is_unknown() &&
message
.dht_header
.destination
.public_key()
.map(|pk| pk != node_identity.public_key())
.unwrap_or(false)
{
debug!(
target: LOG_TARGET,
"Encrypted message (source={}, {}) not destined for this peer. Passing to next service (Trace: {})",
message.source_peer.node_id,
message.dht_header.message_tag,
message.tag
);
return Ok(DecryptedDhtMessage::failed(message));
}

let e_pk = dht_header
.ephemeral_public_key
.as_ref()
Expand Down