Skip to content

Commit

Permalink
fix: remove noise negotiation for debugging on bad wire mode (#3657)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi authored Jan 3, 2022
1 parent f5274aa commit eee73f7
Showing 1 changed file with 2 additions and 34 deletions.
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

0 comments on commit eee73f7

Please sign in to comment.