mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-07 14:23:01 -04:00
Add new AuthenticationFailure exception, and make the Onion/stem code catch more exceptions when connecting to a Tor controller
This commit is contained in:
parent
b8c7807b92
commit
c991a407e2
5 changed files with 18 additions and 7 deletions
|
@ -155,7 +155,7 @@ def main(cwd=None):
|
||||||
app = OnionShare(debug, local_only, stay_open, transparent_torification, stealth)
|
app = OnionShare(debug, local_only, stay_open, transparent_torification, stealth)
|
||||||
app.choose_port()
|
app.choose_port()
|
||||||
app.start_onion_service()
|
app.start_onion_service()
|
||||||
except (onion.TorTooOld, onion.TorErrorInvalidSetting, onion.TorErrorAutomatic, 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, onion.TorErrorAuthError) as e:
|
||||||
sys.exit(e.args[0])
|
sys.exit(e.args[0])
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
|
|
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from stem.control import Controller
|
from stem.control import Controller
|
||||||
from stem import SocketError
|
from stem import SocketError
|
||||||
from stem.connection import MissingPassword, UnreadableCookieFile
|
from stem.connection import MissingPassword, UnreadableCookieFile, AuthenticationFailure
|
||||||
import os, sys, tempfile, shutil, urllib, platform
|
import os, sys, tempfile, shutil, urllib, platform
|
||||||
|
|
||||||
from . import socks
|
from . import socks
|
||||||
|
@ -65,6 +65,13 @@ class TorErrorUnreadableCookieFile(Exception):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class TorErrorAuthError(Exception):
|
||||||
|
"""
|
||||||
|
OnionShare connected to the address and port, but can't authenticate. It's possible
|
||||||
|
that a Tor controller isn't listening on this port.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
class TorTooOld(Exception):
|
class TorTooOld(Exception):
|
||||||
"""
|
"""
|
||||||
This exception is raised if onionshare needs to use a feature of Tor or stem
|
This exception is raised if onionshare needs to use a feature of Tor or stem
|
||||||
|
@ -180,12 +187,13 @@ class Onion(object):
|
||||||
else:
|
else:
|
||||||
raise TorErrorInvalidSetting(strings._("settings_error_unknown"))
|
raise TorErrorInvalidSetting(strings._("settings_error_unknown"))
|
||||||
|
|
||||||
except SocketError:
|
except:
|
||||||
if self.settings.get('connection_type') == 'control_port':
|
if self.settings.get('connection_type') == 'control_port':
|
||||||
raise TorErrorSocketPort(strings._("settings_error_socket_port").format(self.settings.get('control_port_address'), self.settings.get('control_port_port')))
|
raise TorErrorSocketPort(strings._("settings_error_socket_port").format(self.settings.get('control_port_address'), self.settings.get('control_port_port')))
|
||||||
else:
|
else:
|
||||||
raise TorErrorSocketFile(strings._("settings_error_socket_file").format(self.settings.get('socket_file_path')))
|
raise TorErrorSocketFile(strings._("settings_error_socket_file").format(self.settings.get('socket_file_path')))
|
||||||
|
|
||||||
|
|
||||||
# Try authenticating
|
# Try authenticating
|
||||||
try:
|
try:
|
||||||
if self.settings.get('auth_type') == 'no_auth':
|
if self.settings.get('auth_type') == 'no_auth':
|
||||||
|
@ -199,6 +207,8 @@ class Onion(object):
|
||||||
raise TorErrorMissingPassword(strings._('settings_error_missing_password'))
|
raise TorErrorMissingPassword(strings._('settings_error_missing_password'))
|
||||||
except UnreadableCookieFile:
|
except UnreadableCookieFile:
|
||||||
raise TorErrorUnreadableCookieFile(strings._('settings_error_unreadable_cookie_file'))
|
raise TorErrorUnreadableCookieFile(strings._('settings_error_unreadable_cookie_file'))
|
||||||
|
except AuthenticationFailure:
|
||||||
|
raise TorErrorAuthError(strings._('settings_error_auth').format(self.settings.get('control_port_address'), self.settings.get('control_port_port')))
|
||||||
|
|
||||||
# get the tor version
|
# get the tor version
|
||||||
self.tor_version = self.c.get_version().version_str
|
self.tor_version = self.c.get_version().version_str
|
||||||
|
|
|
@ -177,7 +177,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
self.app.start_onion_service()
|
self.app.start_onion_service()
|
||||||
self.starting_server_step2.emit()
|
self.starting_server_step2.emit()
|
||||||
|
|
||||||
except (onionshare.onion.TorTooOld, onionshare.onion.TorErrorInvalidSetting, onionshare.onion.TorErrorAutomatic, 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, onionshare.onion.TorErrorAuthError) as e:
|
||||||
self.starting_server_error.emit(e.args[0])
|
self.starting_server_error.emit(e.args[0])
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
from onionshare import strings
|
from onionshare import strings
|
||||||
from onionshare.settings import Settings
|
from onionshare.settings import Settings
|
||||||
from onionshare.onion import Onion, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile
|
from onionshare.onion import Onion, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError
|
||||||
|
|
||||||
from .alert import Alert
|
from .alert import Alert
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||||
# If an exception hasn't been raised yet, the Tor settings work
|
# 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))
|
Alert(strings._('settings_test_success', True).format(onion.tor_version, onion.supports_ephemeral, onion.supports_stealth))
|
||||||
|
|
||||||
except (TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile) as e:
|
except (TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError) as e:
|
||||||
Alert(e.args[0], QtWidgets.QMessageBox.Warning)
|
Alert(e.args[0], QtWidgets.QMessageBox.Warning)
|
||||||
|
|
||||||
def save_clicked(self):
|
def save_clicked(self):
|
||||||
|
|
|
@ -77,8 +77,9 @@
|
||||||
"settings_saved": "Settings saved to {}",
|
"settings_saved": "Settings saved to {}",
|
||||||
"settings_error_unknown": "Can't connect to Tor controller because the settings don't make sense.",
|
"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_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_port": "Can't connect to Tor controller on {}:{}.",
|
||||||
"settings_error_socket_file": "Can't connect to Tor controller using socket file {}.",
|
"settings_error_socket_file": "Can't connect to Tor controller using socket file {}.",
|
||||||
|
"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_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_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_test_success": "Congratulations, OnionShare can connect to the Tor controller.\n\nTor version: {}\nSupports ephemeral onion services: {}\nSupports stealth onion services: {}"
|
"settings_test_success": "Congratulations, OnionShare can connect to the Tor controller.\n\nTor version: {}\nSupports ephemeral onion services: {}\nSupports stealth onion services: {}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue