Skip to content

Commit

Permalink
chore: disallow onion v2 (#4745)
Browse files Browse the repository at this point in the history
Description
---
Disallow onion v2 addresses.
#4681
  • Loading branch information
Cifko authored Sep 27, 2022
1 parent 0dad9e8 commit 467cad2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions comms/core/src/connection_manager/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -300,14 +301,14 @@ 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(),
multiaddr!(Dnsaddr("mike-magic-nodes.com"), Tcp(1u16)),
];

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])),
Expand All @@ -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(),
Expand All @@ -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")),
Expand Down
2 changes: 2 additions & 0 deletions comms/core/src/connection_manager/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<yamux::ConnectionError> for ConnectionManagerError {
Expand Down

0 comments on commit 467cad2

Please sign in to comment.