From d9153758cdfb44b7ff37068d39c33161aea0e227 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 4 Nov 2020 15:22:27 -0800 Subject: [PATCH] Find the proper tor binary in onionshare-cli for macOS --- cli/onionshare_cli/common.py | 31 ++++++++++++++++++++----------- cli/onionshare_cli/onion.py | 4 ++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/cli/onionshare_cli/common.py b/cli/onionshare_cli/common.py index 0c034a87..1174d8e8 100644 --- a/cli/onionshare_cli/common.py +++ b/cli/onionshare_cli/common.py @@ -93,17 +93,26 @@ class Common: tor_geo_ip_file_path = os.path.join(base_path, "Data", "Tor", "geoip") tor_geo_ipv6_file_path = os.path.join(base_path, "Data", "Tor", "geoip6") elif self.platform == "Darwin": - base_path = os.path.dirname( - os.path.dirname(os.path.dirname(self.get_resource_path(""))) - ) - tor_path = os.path.join(base_path, "Resources", "Tor", "tor") - tor_geo_ip_file_path = os.path.join(base_path, "Resources", "Tor", "geoip") - tor_geo_ipv6_file_path = os.path.join( - base_path, "Resources", "Tor", "geoip6" - ) - obfs4proxy_file_path = os.path.join( - base_path, "Resources", "Tor", "obfs4proxy" - ) + if os.path.basename(sys.argv[0]) == "onionshare-cli": + tor_path = shutil.which("tor") + obfs4proxy_file_path = shutil.which("obfs4proxy") + prefix = os.path.dirname(os.path.dirname(tor_path)) + tor_geo_ip_file_path = os.path.join(prefix, "share/tor/geoip") + tor_geo_ipv6_file_path = os.path.join(prefix, "share/tor/geoip6") + else: + base_path = os.path.dirname( + os.path.dirname(os.path.dirname(self.get_resource_path(""))) + ) + tor_path = os.path.join(base_path, "Resources", "Tor", "tor") + tor_geo_ip_file_path = os.path.join( + base_path, "Resources", "Tor", "geoip" + ) + tor_geo_ipv6_file_path = os.path.join( + base_path, "Resources", "Tor", "geoip6" + ) + obfs4proxy_file_path = os.path.join( + base_path, "Resources", "Tor", "obfs4proxy" + ) elif self.platform == "BSD": tor_path = "/usr/local/bin/tor" tor_geo_ip_file_path = "/usr/local/share/tor/geoip" diff --git a/cli/onionshare_cli/onion.py b/cli/onionshare_cli/onion.py index 02fd3263..6a42638a 100644 --- a/cli/onionshare_cli/onion.py +++ b/cli/onionshare_cli/onion.py @@ -328,6 +328,10 @@ class Onion(object): f.write(self.settings.get("tor_bridges_use_custom_bridges")) f.write("\nUseBridges 1") + # Make sure the tor path is accurate + if not os.path.exists(self.tor_path): + raise BundledTorNotSupported(f"Cannot find tor binary: {self.tor_path}") + # Execute a tor subprocess start_ts = time.time() if self.common.platform == "Windows":