Find the proper tor binary in onionshare-cli for macOS

This commit is contained in:
Micah Lee 2020-11-04 15:22:27 -08:00
parent 68347039c9
commit d9153758cd
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 24 additions and 11 deletions

View File

@ -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"

View File

@ -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":