From 40b4d8f84cf2ccdabc24eda81f4aa5166d268b05 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 22 Dec 2021 13:08:01 -0800 Subject: [PATCH] Allow onionshare-cli binary made by cx_Freeze find tor binaries in macOS --- cli/onionshare_cli/common.py | 37 +++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/cli/onionshare_cli/common.py b/cli/onionshare_cli/common.py index d7f3fdac..272d2860 100644 --- a/cli/onionshare_cli/common.py +++ b/cli/onionshare_cli/common.py @@ -337,26 +337,41 @@ class Common: # If tor.exe isn't there, mayber we're running from the source tree if not os.path.exists(tor_path): base_path = os.path.join(os.getcwd(), "onionshare", "resources", "tor") - tor_path = os.path.join(base_path, "Tor", "tor.exe") + tor_path = os.path.join(base_path, "Tor", "tor.exe") if not os.path.exists(tor_path): - print("Error: Cannot find tor.exe") + raise CannotFindTor() obfs4proxy_file_path = os.path.join(base_path, "Tor", "obfs4proxy.exe") snowflake_file_path = os.path.join(base_path, "Tor", "snowflake-client.exe") meek_client_file_path = os.path.join(base_path, "Tor", "meek-client.exe") 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": - tor_path = shutil.which("tor") - if not tor_path: - raise CannotFindTor() - obfs4proxy_file_path = shutil.which("obfs4proxy") - snowflake_file_path = shutil.which("snowflake-client") - meek_client_file_path = shutil.which("meek-client") - 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") + # Let's see if we have tor binaries in the onionshare GUI package + base_path = self.get_resource_path("tor") + base_path = base_path.replace("onionshare_cli", "onionshare") + tor_path = os.path.join(base_path, "tor") + if os.path.exists(tor_path): + obfs4proxy_file_path = os.path.join(base_path, "obfs4proxy") + snowflake_file_path = os.path.join(base_path, "snowflake-client") + meek_client_file_path = os.path.join(base_path, "meek-client") + tor_geo_ip_file_path = os.path.join(base_path, "geoip") + tor_geo_ipv6_file_path = os.path.join(base_path, "geoip6") + else: + # Fallback to looking in the path + tor_path = shutil.which("tor") + if not os.path.exists(tor_path): + raise CannotFindTor() + + obfs4proxy_file_path = shutil.which("obfs4proxy") + snowflake_file_path = shutil.which("snowflake-client") + meek_client_file_path = shutil.which("meek-client") + 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") + elif self.platform == "BSD": tor_path = "/usr/local/bin/tor" tor_geo_ip_file_path = "/usr/local/share/tor/geoip"