From 467cad2351462aab5a55580e0d1fc1fba1ce1e78 Mon Sep 17 00:00:00 2001 From: Martin Stefcek <35243812+Cifko@users.noreply.github.com> Date: Tue, 27 Sep 2022 18:39:33 +0200 Subject: [PATCH] chore: disallow onion v2 (#4745) Description --- Disallow onion v2 addresses. https://github.com/tari-project/tari/issues/4681 --- comms/core/src/connection_manager/common.rs | 7 ++++--- comms/core/src/connection_manager/error.rs | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/comms/core/src/connection_manager/common.rs b/comms/core/src/connection_manager/common.rs index 9c9d76398d..60645bb0e3 100644 --- a/comms/core/src/connection_manager/common.rs +++ b/comms/core/src/connection_manager/common.rs @@ -268,7 +268,8 @@ fn validate_address(addr: &Multiaddr, allow_test_addrs: bool) -> Result<(), Conn Protocol::Onion3(addr) if addr.port() == 0 => Err(ConnectionManagerError::InvalidMultiaddr( "A zero onion port is not valid in the onion spec".to_string(), )), - Protocol::Onion(_, _) | Protocol::Onion3(_) => expect_end_of_address(addr_iter), + Protocol::Onion(_, _) => Err(ConnectionManagerError::OnionV2NotSupported), + Protocol::Onion3(_) => expect_end_of_address(addr_iter), p => Err(ConnectionManagerError::InvalidMultiaddr(format!( "Unsupported address type '{}'", p @@ -300,7 +301,6 @@ mod test { let valid = [ multiaddr!(Ip4([172, 0, 0, 1]), Tcp(1u16)), multiaddr!(Ip6([172, 0, 0, 1, 1, 1, 1, 1]), Tcp(1u16)), - "/onion/aaimaq4ygg2iegci:1234".parse().unwrap(), "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234" .parse() .unwrap(), @@ -308,6 +308,7 @@ mod test { ]; let invalid = &[ + "/onion/aaimaq4ygg2iegci:1234".parse().unwrap(), multiaddr!(Ip4([127, 0, 0, 1]), Tcp(1u16)), multiaddr!(Ip4([169, 254, 0, 1]), Tcp(1u16)), multiaddr!(Ip4([172, 0, 0, 1])), @@ -330,7 +331,6 @@ mod test { multiaddr!(Ip4([169, 254, 0, 1]), Tcp(1u16)), multiaddr!(Ip4([172, 0, 0, 1]), Tcp(1u16)), multiaddr!(Ip6([172, 0, 0, 1, 1, 1, 1, 1]), Tcp(1u16)), - "/onion/aaimaq4ygg2iegci:1234".parse().unwrap(), "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234" .parse() .unwrap(), @@ -339,6 +339,7 @@ mod test { ]; let invalid = &[ + "/onion/aaimaq4ygg2iegci:1234".parse().unwrap(), multiaddr!(Ip4([172, 0, 0, 1])), "/onion/aaimaq4ygg2iegci:1234/http".parse().unwrap(), multiaddr!(Dnsaddr("mike-magic-nodes.com")), diff --git a/comms/core/src/connection_manager/error.rs b/comms/core/src/connection_manager/error.rs index 1bde90ffdf..e4cc622164 100644 --- a/comms/core/src/connection_manager/error.rs +++ b/comms/core/src/connection_manager/error.rs @@ -89,6 +89,8 @@ pub enum ConnectionManagerError { PeerIdentityNoSignature, #[error("Peer did not provide any public addresses")] PeerIdentityNoAddresses, + #[error("Onion v2 is no longer supported")] + OnionV2NotSupported, } impl From for ConnectionManagerError {