Catch errors that occur when connection_type is bundled_tor, but the tor process closes before it can connect

This commit is contained in:
Micah Lee 2017-05-17 12:00:42 -07:00
parent 22c13fc7bf
commit d3a7eef95c
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 16 additions and 6 deletions

View File

@ -105,6 +105,12 @@ class BundledTorCanceled(Exception):
and the user cancels connecting to Tor
"""
class BundledTorBroken(Exception):
"""
This exception is raised if onionshare is set to use the bundled Tor binary,
but the process seems to fail to run.
"""
class Onion(object):
"""
Onion is an abstraction layer for connecting to the Tor control port and
@ -202,12 +208,15 @@ class Onion(object):
time.sleep(0.2)
# Connect to the controller
if self.system == 'Windows':
self.c = Controller.from_port(port=self.tor_control_port)
self.c.authenticate()
else:
self.c = Controller.from_socket_file(path=self.tor_control_socket)
self.c.authenticate()
try:
if self.system == 'Windows':
self.c = Controller.from_port(port=self.tor_control_port)
self.c.authenticate()
else:
self.c = Controller.from_socket_file(path=self.tor_control_socket)
self.c.authenticate()
except Exception as e:
raise BundledTorBroken(strings._('settings_error_bundled_tor_broken', True).format(e.args[0]))
while True:
try:

View File

@ -91,6 +91,7 @@
"settings_error_bundled_tor_not_supported": "Bundled Tor is not supported when not using developer mode in Windows or macOS.",
"settings_error_bundled_tor_timeout": "Connecting to Tor is taking too long. Maybe your computer is offline, or your clock isn't accurate.",
"settings_error_bundled_tor_canceled": "The Tor process closed before it could finish connecting.",
"settings_error_bundled_tor_broken": "Something is wrong with OnionShare connecting to Tor in the background:\n{}",
"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.",
"connecting_to_tor": "Connecting to the Tor network",