mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-10 03:37:28 -03:00
Properly handle exceptions in CLI, and pass the actual exception message in TorErrorProtocolError exceptions
This commit is contained in:
parent
5448c4f345
commit
cc265491fd
4 changed files with 23 additions and 16 deletions
|
@ -111,6 +111,10 @@ def main(cwd=None):
|
|||
except KeyboardInterrupt:
|
||||
print("")
|
||||
sys.exit()
|
||||
except (TorTooOld, TorErrorProtocolError) as e:
|
||||
print("")
|
||||
print(e.args[0])
|
||||
sys.exit()
|
||||
|
||||
# Prepare files to share
|
||||
print(strings._("preparing_files"))
|
||||
|
|
|
@ -443,18 +443,18 @@ class Onion(object):
|
|||
# is the key a v2 key?
|
||||
if onionkey.is_v2_key(key_content):
|
||||
key_type = "RSA1024"
|
||||
# The below section is commented out because re-publishing
|
||||
# a pre-prepared v3 private key is currently unstable in Tor.
|
||||
# This is fixed upstream but won't reach stable until 0.3.5
|
||||
# (expected in December 2018)
|
||||
# See https://trac.torproject.org/projects/tor/ticket/25552
|
||||
# Until then, we will deliberately not work with 'persistent'
|
||||
# v3 onions, which should not be possible via the GUI settings
|
||||
# anyway.
|
||||
# Our ticket: https://github.com/micahflee/onionshare/issues/677
|
||||
#
|
||||
# Assume it was a v3 key
|
||||
# key_type = "ED25519-V3"
|
||||
# The below section is commented out because re-publishing
|
||||
# a pre-prepared v3 private key is currently unstable in Tor.
|
||||
# This is fixed upstream but won't reach stable until 0.3.5
|
||||
# (expected in December 2018)
|
||||
# See https://trac.torproject.org/projects/tor/ticket/25552
|
||||
# Until then, we will deliberately not work with 'persistent'
|
||||
# v3 onions, which should not be possible via the GUI settings
|
||||
# anyway.
|
||||
# Our ticket: https://github.com/micahflee/onionshare/issues/677
|
||||
#
|
||||
# Assume it was a v3 key
|
||||
# key_type = "ED25519-V3"
|
||||
else:
|
||||
raise TorErrorProtocolError(strings._('error_invalid_private_key'))
|
||||
else:
|
||||
|
@ -473,6 +473,7 @@ class Onion(object):
|
|||
basic_auth = None
|
||||
self.stealth = False
|
||||
|
||||
self.common.log('Onion', 'start_onion_service', 'key_type={}'.format(key_type))
|
||||
try:
|
||||
if basic_auth != None:
|
||||
res = self.c.create_ephemeral_hidden_service({ 80: port }, await_publication=True, basic_auth=basic_auth, key_type=key_type, key_content=key_content)
|
||||
|
@ -480,8 +481,8 @@ class Onion(object):
|
|||
# if the stem interface is older than 1.5.0, basic_auth isn't a valid keyword arg
|
||||
res = self.c.create_ephemeral_hidden_service({ 80: port }, await_publication=True, key_type=key_type, key_content=key_content)
|
||||
|
||||
except ProtocolError:
|
||||
raise TorErrorProtocolError(strings._('error_tor_protocol_error'))
|
||||
except ProtocolError as e:
|
||||
raise TorErrorProtocolError(strings._('error_tor_protocol_error').format(e.args[0]))
|
||||
|
||||
self.service_id = res.service_id
|
||||
onion_host = self.service_id + '.onion'
|
||||
|
@ -512,7 +513,7 @@ class Onion(object):
|
|||
self.settings.save()
|
||||
return onion_host
|
||||
else:
|
||||
raise TorErrorProtocolError(strings._('error_tor_protocol_error'))
|
||||
raise TorErrorProtocolError(strings._('error_tor_protocol_error_unknown'))
|
||||
|
||||
def cleanup(self, stop_tor=True):
|
||||
"""
|
||||
|
|
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import os, shutil
|
||||
|
||||
from . import common, strings
|
||||
from .onion import TorTooOld, TorErrorProtocolError
|
||||
from .common import ShutdownTimer
|
||||
|
||||
class OnionShare(object):
|
||||
|
|
|
@ -122,7 +122,8 @@
|
|||
"settings_error_bundled_tor_timeout": "Connecting to Tor is taking too long. Maybe your computer is offline, or your system clock isn't accurate.",
|
||||
"settings_error_bundled_tor_broken": "OnionShare could not connect 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": "Could not communicate with the Tor controller.\nIf you're using Whonix, check out https://www.whonix.org/wiki/onionshare to make OnionShare work.",
|
||||
"error_tor_protocol_error": "There was an error with Tor: {}",
|
||||
"error_tor_protocol_error_unknown": "There was an unknown error with Tor",
|
||||
"error_invalid_private_key": "This private key type is unsupported",
|
||||
"connecting_to_tor": "Connecting to the Tor network",
|
||||
"update_available": "A new version of OnionShare is available. <a href='{}'>Click here</a> to download it.<br><br>Installed version: {}<br>Latest version: {}",
|
||||
|
|
Loading…
Reference in a new issue