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: remove noise negotiation for debugging on bad wire mode #3657

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
36 changes: 2 additions & 34 deletions comms/src/connection_manager/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use std::{

use futures::{future, FutureExt};
use log::*;
use tari_crypto::tari_utilities::hex::Hex;
use tari_shutdown::{oneshot_trigger, oneshot_trigger::OneshotTrigger, ShutdownSignal};
use tokio::{
io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt},
Expand Down Expand Up @@ -286,18 +285,14 @@ where
}
},
Ok(WireMode::Comms(byte)) => {
// TODO: This call is expensive and only added for the benefit of improved logging and may lead to
// TODO: DoS attacks. Remove later when not needed anymore or make it optional with a config file
// TODO: setting.
let public_key = Self::remote_public_key_from_socket(socket, noise_config).await;
warn!(
target: LOG_TARGET,
"Peer at address '{}' ({}) sent invalid wire format byte. Expected {:x?} got: {:x?} ",
"Peer at address '{}' sent invalid wire format byte. Expected {:x?} got: {:x?} ",
peer_addr,
public_key,
config.network_info.network_byte,
byte,
);
let _ = socket.shutdown().await;
},
Ok(WireMode::Liveness) => {
if liveness_session_count.load(Ordering::SeqCst) > 0 &&
Expand Down Expand Up @@ -339,33 +334,6 @@ where
self.bounded_executor.spawn(inbound_fut).await;
}

async fn remote_public_key_from_socket(socket: TTransport::Output, noise_config: NoiseConfig) -> String {
let noise_socket = time::timeout(
Duration::from_secs(30),
noise_config.upgrade_socket(socket, ConnectionDirection::Inbound),
)
.await;

let public_key = match noise_socket {
Ok(Ok(mut noise_socket)) => {
let pk = noise_socket.get_remote_public_key();
if let Err(err) = noise_socket.shutdown().await {
debug!(
target: LOG_TARGET,
"IO error when closing socket after invalid wire format: {}", err
);
}
pk
},
_ => None,
};

match public_key {
None => "public key not known".to_string(),
Some(pk) => pk.to_hex(),
}
}

#[allow(clippy::too_many_arguments)]
async fn perform_socket_upgrade_procedure(
node_identity: Arc<NodeIdentity>,
Expand Down