From 284213aa2d9fb4756a90891b43cdd8c974496e23 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 15 Jan 2018 12:49:29 +1100 Subject: [PATCH] support obfs4 via obfs4proxy on macOS --- install/get-tor-osx.py | 3 +++ onionshare/common.py | 6 +++++- onionshare/onion.py | 4 ++-- onionshare_gui/settings_dialog.py | 5 +++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/install/get-tor-osx.py b/install/get-tor-osx.py index b8c17fba..344f5b61 100644 --- a/install/get-tor-osx.py +++ b/install/get-tor-osx.py @@ -84,6 +84,9 @@ def main(): shutil.copyfile(os.path.join(dmg_tor_path, 'MacOS', 'Tor', 'tor.real'), os.path.join(dist_path, 'MacOS', 'Tor', 'tor.real')) shutil.copyfile(os.path.join(dmg_tor_path, 'MacOS', 'Tor', 'libevent-2.0.5.dylib'), os.path.join(dist_path, 'MacOS', 'Tor', 'libevent-2.0.5.dylib')) os.chmod(os.path.join(dist_path, 'MacOS', 'Tor', 'tor.real'), 0o755) + # obfs4proxy binary + shutil.copyfile(os.path.join(dmg_tor_path, 'MacOS', 'Tor', 'PluggableTransports', 'obfs4proxy'), os.path.join(dist_path, 'Resources', 'Tor', 'obfs4proxy')) + os.chmod(os.path.join(dist_path, 'Resources', 'Tor', 'obfs4proxy'), 0o755) # Unmount dmg subprocess.call(['diskutil', 'unmount', '/Volumes/Tor Browser']) diff --git a/onionshare/common.py b/onionshare/common.py index 562c71f2..298dd42b 100644 --- a/onionshare/common.py +++ b/onionshare/common.py @@ -94,22 +94,26 @@ def get_tor_paths(): tor_path = '/usr/bin/tor' tor_geo_ip_file_path = '/usr/share/tor/geoip' tor_geo_ipv6_file_path = '/usr/share/tor/geoip6' + obfs4proxy_file_path = '/usr/bin/obfs4proxy' elif p == 'Windows': base_path = os.path.join(os.path.dirname(os.path.dirname(get_resource_path(''))), 'tor') tor_path = os.path.join(os.path.join(base_path, 'Tor'), "tor.exe") tor_geo_ip_file_path = os.path.join(os.path.join(os.path.join(base_path, 'Data'), 'Tor'), 'geoip') tor_geo_ipv6_file_path = os.path.join(os.path.join(os.path.join(base_path, 'Data'), 'Tor'), 'geoip6') + obfs4proxy_file_path = os.path.join(os.path.join(os.path.join(base_path, 'Data'), 'Tor'), 'obfs4proxy') elif p == 'Darwin': base_path = os.path.dirname(os.path.dirname(os.path.dirname(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 p == 'OpenBSD' or p == 'FreeBSD': tor_path = '/usr/local/bin/tor' tor_geo_ip_file_path = '/usr/local/share/tor/geoip' tor_geo_ipv6_file_path = '/usr/local/share/tor/geoip6' + obfs4proxy_file_path = '/usr/local/bin/obfs4proxy' - return (tor_path, tor_geo_ip_file_path, tor_geo_ipv6_file_path) + return (tor_path, tor_geo_ip_file_path, tor_geo_ipv6_file_path, obfs4proxy_file_path) def get_version(): diff --git a/onionshare/onion.py b/onionshare/onion.py index 61ab128c..0385d019 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -140,7 +140,7 @@ class Onion(object): self.bundle_tor_supported = True # Set the path of the tor binary, for bundled tor - (self.tor_path, self.tor_geo_ip_file_path, self.tor_geo_ipv6_file_path) = common.get_tor_paths() + (self.tor_path, self.tor_geo_ip_file_path, self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path) = common.get_tor_paths() # The tor process self.tor_proc = None @@ -207,7 +207,7 @@ class Onion(object): # Bridge support if self.settings.get('tor_bridges_use_obfs4'): - f.write('\n') + f.write('ClientTransportPlugin obfs4 exec {}\n'.format(self.obfs4proxy_file_path)) with open(common.get_resource_path('torrc_template-obfs4')) as o: for line in o: f.write(line) diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 7b24bf0c..7b1358a6 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -130,6 +130,11 @@ class SettingsDialog(QtWidgets.QDialog): # OBFS4 option radio self.tor_bridges_use_obfs4_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_obfs4_radio_option', True)) self.tor_bridges_use_obfs4_radio.toggled.connect(self.tor_bridges_use_obfs4_radio_toggled) + # if the obfs4proxy binary is missing, we can't use obfs4 transports + if system != 'Windows' and system != 'Darwin': + (self.tor_path, self.tor_geo_ip_file_path, self.tor_geo_ipv6_file_path, self.obfs4proxy_file_path) = common.get_tor_paths() + if not os.path.isfile(self.obfs4proxy_file_path): + self.tor_bridges_use_obfs4_radio.setEnabled(False) # Custom bridges radio and textbox self.tor_bridges_use_custom_radio = QtWidgets.QRadioButton(strings._('gui_settings_tor_bridges_custom_radio_option', True))