From da225ed7d1871ae9f4173bf2ccd9d1b7bdf88a83 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 8 Apr 2017 18:10:17 -0700 Subject: [PATCH] Started to implement Bundled Tor connection settings --- onionshare/__init__.py | 7 ++++--- onionshare/onion.py | 15 +++++++++++++++ onionshare_gui/settings_dialog.py | 4 ++-- share/locale/en.json | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 58f6a1c7..e0608b6d 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -20,7 +20,8 @@ along with this program. If not, see . import os, sys, time, argparse, shutil, socket, threading -from . import strings, helpers, web, onion +from . import strings, helpers, web +from .onion import * class OnionShare(object): """ @@ -84,7 +85,7 @@ class OnionShare(object): return if not self.onion: - self.onion = onion.Onion(self.stealth) + self.onion = Onion(self.stealth) self.onion_host = self.onion.start(self.port) @@ -155,7 +156,7 @@ def main(cwd=None): app = OnionShare(debug, local_only, stay_open, transparent_torification, stealth) app.choose_port() app.start_onion_service() - except (onion.TorTooOld, onion.TorErrorInvalidSetting, onion.TorErrorAutomatic, onion.TorErrorSocketPort, onion.TorErrorSocketFile, onion.TorErrorMissingPassword, onion.TorErrorUnreadableCookieFile, onion.TorErrorAuthError, onion.TorErrorProtocolError) as e: + except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported) as e: sys.exit(e.args[0]) except KeyboardInterrupt: print("") diff --git a/onionshare/onion.py b/onionshare/onion.py index bb2bca72..ccfdd4b0 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -87,6 +87,12 @@ class TorTooOld(Exception): """ pass +class BundledTorNotSupported(Exception): + """ + This exception is raised if onionshare is set to use the bundled Tor binary, + but it's not supported on that platform, or in dev mode. + """ + class Onion(object): """ Onion is an abstraction layer for connecting to the Tor control port and @@ -107,6 +113,15 @@ class Onion(object): # Try to connect to Tor self.c = None + if self.settings.get('connection_type') == 'bundled': + dev_mode = getattr(sys, 'onionshare_dev_mode', False) + p = platform.system() + + if (p != 'Windows' and p != 'Darwin') or dev_mode: + raise BundledTorNotSupported(strings._('settings_error_bundled_tor_not_supported')) + + # TODO: actually implement bundled Tor + if self.settings.get('connection_type') == 'automatic': # Automatically try to guess the right way to connect to Tor Browser p = platform.system() diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py index 3a41dfdb..ee340884 100644 --- a/onionshare_gui/settings_dialog.py +++ b/onionshare_gui/settings_dialog.py @@ -22,7 +22,7 @@ import sys, platform from onionshare import strings from onionshare.settings import Settings -from onionshare.onion import Onion, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError +from onionshare.onion import * from .alert import Alert @@ -290,7 +290,7 @@ class SettingsDialog(QtWidgets.QDialog): # If an exception hasn't been raised yet, the Tor settings work Alert(strings._('settings_test_success', True).format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth)) - except (TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError) as e: + except (TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorNotSupported) as e: Alert(e.args[0], QtWidgets.QMessageBox.Warning) def save_clicked(self): diff --git a/share/locale/en.json b/share/locale/en.json index 9f192a49..29b2bad3 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -85,6 +85,7 @@ "settings_error_auth": "Connected to {}:{}, but can't authenticate. Maybe this isn't a Tor controller?", "settings_error_missing_password": "Connected to Tor controller, but it requires a password to authenticate.", "settings_error_unreadable_cookie_file": "Connected to Tor controller, but can't authenticate because your password may be wrong, and your user doesn't have permission to read the cookie file.", + "settings_error_bundled_tor_not_supported": "Bundled Tor is only supported in Windows and macOS. It's not supported when not using developer mode or the command line interface.", "settings_test_success": "Congratulations, OnionShare can connect to the Tor controller.\n\nTor version: {}\nSupports ephemeral onion services: {}\nSupports stealth onion services: {}", "error_tor_protocol_error": "Error talking to the Tor controller.\nIf you're using Whonix, check out https://www.whonix.org/wiki/onionshare to make OnionShare work." }