mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-23 13:51:08 -05:00
Refuse to dial addresses via Tor that are almost certainly not reachable
For now, this just concerns loopback addresses.
This commit is contained in:
parent
ec59184e85
commit
92ed8d9c04
@ -35,15 +35,17 @@ impl Transport for TorDialOnlyTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
||||||
let tor_compatible_address = TorCompatibleAddress::from_multiaddr(Cow::Borrowed(&addr))?;
|
let address = TorCompatibleAddress::from_multiaddr(Cow::Borrowed(&addr))?;
|
||||||
|
|
||||||
|
if address.is_certainly_not_reachable_via_tor_daemon() {
|
||||||
|
return Err(TransportError::MultiaddrNotSupported(addr));
|
||||||
|
}
|
||||||
|
|
||||||
let dial_future = async move {
|
let dial_future = async move {
|
||||||
tracing::trace!("Connecting through Tor proxy to address: {}", addr);
|
tracing::trace!("Connecting through Tor proxy to address: {}", addr);
|
||||||
|
|
||||||
let stream = Socks5Stream::connect(
|
let stream =
|
||||||
(Ipv4Addr::LOCALHOST, self.socks_port),
|
Socks5Stream::connect((Ipv4Addr::LOCALHOST, self.socks_port), address.to_string())
|
||||||
tor_compatible_address.to_string(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| io::Error::new(io::ErrorKind::ConnectionRefused, e))?;
|
.map_err(|e| io::Error::new(io::ErrorKind::ConnectionRefused, e))?;
|
||||||
|
|
||||||
@ -99,6 +101,22 @@ impl TorCompatibleAddress {
|
|||||||
_ => Err(TransportError::MultiaddrNotSupported(multi.into_owned())),
|
_ => Err(TransportError::MultiaddrNotSupported(multi.into_owned())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if the address is reachable via the Tor daemon.
|
||||||
|
///
|
||||||
|
/// The Tor daemon can dial onion addresses, resolve DNS names and dial
|
||||||
|
/// IP4/IP6 addresses reachable via the public Internet.
|
||||||
|
/// We can't guarantee that an address is reachable via the Internet but we
|
||||||
|
/// can say that some addresses are almost certainly not reachable, for
|
||||||
|
/// example, loopback addresses.
|
||||||
|
fn is_certainly_not_reachable_via_tor_daemon(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
TorCompatibleAddress::Onion3 { .. } => false,
|
||||||
|
TorCompatibleAddress::Dns { address, .. } => address == "localhost",
|
||||||
|
TorCompatibleAddress::Ip4 { address, .. } => address.is_loopback(),
|
||||||
|
TorCompatibleAddress::Ip6 { address, .. } => address.is_loopback(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for TorCompatibleAddress {
|
impl fmt::Display for TorCompatibleAddress {
|
||||||
|
Loading…
Reference in New Issue
Block a user