mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-27 08:19:41 -05:00
Make automatic settings work with with Tor Browser 6.0.8
This commit is contained in:
parent
fa7bec2fae
commit
a0abab3653
@ -27,6 +27,13 @@ from . import socks
|
||||
from . import helpers, strings
|
||||
from .settings import Settings
|
||||
|
||||
class TorErrorAutomatic(Exception):
|
||||
"""
|
||||
OnionShare is failing to connect and authenticate to the Tor controller,
|
||||
using automatic settings that should work with Tor Browser.
|
||||
"""
|
||||
pass
|
||||
|
||||
class TorErrorInvalidSetting(Exception):
|
||||
"""
|
||||
This exception is raised if the settings just don't make sense.
|
||||
@ -58,13 +65,6 @@ class TorErrorUnreadableCookieFile(Exception):
|
||||
"""
|
||||
pass
|
||||
|
||||
class NoTor(Exception):
|
||||
"""
|
||||
This exception is raised if onionshare can't find a Tor control port
|
||||
to connect to, or if it can't find a Tor socks5 proxy to proxy though.
|
||||
"""
|
||||
pass
|
||||
|
||||
class TorTooOld(Exception):
|
||||
"""
|
||||
This exception is raised if onionshare needs to use a feature of Tor or stem
|
||||
@ -109,30 +109,34 @@ class Onion(object):
|
||||
if self.settings.get('connection_type') == 'automatic':
|
||||
# Automatically try to guess the right way to connect to Tor Browser
|
||||
|
||||
# if the TOR_CONTROL_PORT environment variable is set, use that
|
||||
# otherwise, default to Tor Browser, Tor Messenger, and system tor ports
|
||||
# Try connecting
|
||||
try:
|
||||
# If the TOR_CONTROL_PORT environment variable is set, use that
|
||||
env_port = os.environ.get('TOR_CONTROL_PORT')
|
||||
if env_port:
|
||||
ports = [int(env_port)]
|
||||
else:
|
||||
ports = [9151, 9153, 9051]
|
||||
self.c = Controller.from_port(port=int(env_port))
|
||||
|
||||
# connect to the tor controlport
|
||||
else:
|
||||
# Otherwise, try default ports for Tor Browser, Tor Messenger, and system tor
|
||||
found_tor = False
|
||||
for port in ports:
|
||||
try:
|
||||
ports = [9151, 9153, 9051]
|
||||
for port in ports:
|
||||
self.c = Controller.from_port(port=port)
|
||||
self.c.authenticate()
|
||||
found_tor = True
|
||||
break
|
||||
except SocketError:
|
||||
except:
|
||||
pass
|
||||
except MissingPassword:
|
||||
raise NoTor(strings._("ctrlport_missing_password").format(str(ports)))
|
||||
except UnreadableCookieFile:
|
||||
raise NoTor(strings._("ctrlport_unreadable_cookie").format(str(ports)))
|
||||
if not found_tor:
|
||||
raise NoTor(strings._("cant_connect_ctrlport").format(str(ports)))
|
||||
raise TorErrorAutomatic(strings._('settings_error_automatic'))
|
||||
|
||||
except TorErrorAutomatic:
|
||||
raise TorErrorAutomatic(strings._('settings_error_automatic'))
|
||||
|
||||
# Try authenticating
|
||||
try:
|
||||
self.c.authenticate()
|
||||
except:
|
||||
raise TorErrorAutomatic(strings._('settings_error_automatic'))
|
||||
|
||||
else:
|
||||
# Use specific settings to connect to tor
|
||||
|
@ -155,7 +155,7 @@ def main(cwd=None):
|
||||
app = OnionShare(debug, local_only, stay_open, transparent_torification, stealth)
|
||||
app.choose_port()
|
||||
app.start_onion_service()
|
||||
except (onion.NoTor, onion.TorTooOld, onion.TorErrorInvalidSetting, onion.TorErrorSocketPort, onion.TorErrorSocketFile, onion.TorErrorMissingPassword, onion.TorErrorUnreadableCookieFile) as e:
|
||||
except (onion.TorTooOld, onion.TorErrorInvalidSetting, onion.TorErrorAutomatic, onion.TorErrorSocketPort, onion.TorErrorSocketFile, onion.TorErrorMissingPassword, onion.TorErrorUnreadableCookieFile) as e:
|
||||
sys.exit(e.args[0])
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
|
@ -177,7 +177,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
self.app.start_onion_service()
|
||||
self.starting_server_step2.emit()
|
||||
|
||||
except (onionshare.onion.NoTor, onionshare.onion.TorTooOld, onionshare.onion.TorErrorInvalidSetting, onionshare.onion.TorErrorSocketPort, onionshare.onion.TorErrorSocketFile, onionshare.onion.TorErrorMissingPassword, onionshare.onion.TorErrorUnreadableCookieFile) as e:
|
||||
except (onionshare.onion.TorTooOld, onionshare.onion.TorErrorInvalidSetting, onionshare.onion.TorErrorAutomatic, onionshare.onion.TorErrorSocketPort, onionshare.onion.TorErrorSocketFile, onionshare.onion.TorErrorMissingPassword, onionshare.onion.TorErrorUnreadableCookieFile) as e:
|
||||
self.starting_server_error.emit(e.args[0])
|
||||
return
|
||||
|
||||
|
@ -21,7 +21,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from onionshare import strings
|
||||
from onionshare.settings import Settings
|
||||
from onionshare.onion import Onion, TorErrorInvalidSetting, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile
|
||||
from onionshare.onion import Onion, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile
|
||||
|
||||
from .alert import Alert
|
||||
|
||||
@ -216,7 +216,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, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile) as e:
|
||||
except (TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile) as e:
|
||||
Alert(e.args[0], QtWidgets.QMessageBox.Warning)
|
||||
|
||||
def save_clicked(self):
|
||||
|
@ -1,9 +1,5 @@
|
||||
{
|
||||
"config_onion_service": "Configuring onion service on port {0:d}.",
|
||||
"cant_connect_ctrlport": "Can't connect to Tor control port on port {0:s}. OnionShare requires Tor Browser to be running in the background to work. If you don't have it you can get it from https://www.torproject.org/.",
|
||||
"cant_connect_socksport": "Can't connect to Tor SOCKS5 server on port {0:s}. OnionShare requires Tor Browser to be running in the background to work. If you don't have it you can get it from https://www.torproject.org/.",
|
||||
"ctrlport_missing_password": "Connected to Tor control port on port {0:s}, but you require a password. You must have the TOR_AUTHENTICATION_PASSWORD environment variable set. Or just open Tor Browser in the background.",
|
||||
"ctrlport_unreadable_cookie": "Connected to Tor control port on port {0:s}, but your user does not have permission to authenticate. You might want to add a HashedControlPassword to your torrc, and set the TOR_AUTHENTICATION_PASSWORD environment variable. Or just open Tor Browser in the background.",
|
||||
"preparing_files": "Preparing files to share.",
|
||||
"wait_for_hs": "Waiting for HS to be ready:",
|
||||
"wait_for_hs_trying": "Trying...",
|
||||
@ -80,6 +76,7 @@
|
||||
"gui_settings_button_cancel": "Cancel",
|
||||
"settings_saved": "Settings saved to {}",
|
||||
"settings_error_unknown": "Can't connect to Tor controller because the settings don't make sense.",
|
||||
"settings_error_automatic": "Can't connect to Tor controller. Is Tor Browser running in the background? If you don't have it you can get it from:\nhttps://www.torproject.org/.",
|
||||
"settings_error_socket_port": "Can't connect to Tor controller on address {} with port {}.",
|
||||
"settings_error_socket_file": "Can't connect to Tor controller using socket file {}.",
|
||||
"settings_error_missing_password": "Connected to Tor controller, but it requires a password to authenticate.",
|
||||
|
Loading…
Reference in New Issue
Block a user