mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-08 14:52:59 -04:00
Refactor Onion to store all state for auto-start timer directly in the mode settings, and not in the Onion object itself
This commit is contained in:
parent
5b6d986951
commit
e7bd89c41d
3 changed files with 10 additions and 56 deletions
|
@ -155,8 +155,6 @@ class Onion(object):
|
||||||
self.common.log("Onion", "__init__")
|
self.common.log("Onion", "__init__")
|
||||||
|
|
||||||
self.use_tmp_dir = use_tmp_dir
|
self.use_tmp_dir = use_tmp_dir
|
||||||
self.scheduled_key = None
|
|
||||||
self.scheduled_auth_cookie = None
|
|
||||||
|
|
||||||
# Is bundled tor supported?
|
# Is bundled tor supported?
|
||||||
if (
|
if (
|
||||||
|
@ -574,9 +572,7 @@ class Onion(object):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def start_onion_service(
|
def start_onion_service(self, mode_settings, port, await_publication):
|
||||||
self, mode_settings, port, await_publication, save_scheduled_key=False
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Start a onion service on port 80, pointing to the given port, and
|
Start a onion service on port 80, pointing to the given port, and
|
||||||
return the onion hostname.
|
return the onion hostname.
|
||||||
|
@ -590,22 +586,15 @@ class Onion(object):
|
||||||
|
|
||||||
auth_cookie = None
|
auth_cookie = None
|
||||||
if mode_settings.get("general", "client_auth"):
|
if mode_settings.get("general", "client_auth"):
|
||||||
# If we have an auth cookie that's temporarily saved as part of a
|
if mode_settings.get("onion", "hidservauth_string"):
|
||||||
# scheduled share, use that for the basic auth.
|
auth_cookie = mode_settings.get("onion", "hidservauth_string").split()[
|
||||||
if self.scheduled_auth_cookie:
|
2
|
||||||
auth_cookie = self.scheduled_auth_cookie
|
]
|
||||||
else:
|
|
||||||
# If we don't have a scheduled share, but are using persistence, then
|
|
||||||
# we should be able to find a hidservauth_string in saved settings
|
|
||||||
if mode_settings.get("onion", "hidservauth_string"):
|
|
||||||
auth_cookie = mode_settings.get(
|
|
||||||
"onion", "hidservauth_string"
|
|
||||||
).split()[2]
|
|
||||||
if auth_cookie:
|
if auth_cookie:
|
||||||
basic_auth = {"onionshare": auth_cookie}
|
basic_auth = {"onionshare": auth_cookie}
|
||||||
# If we had neither a scheduled auth cookie or a persistent hidservauth string,
|
|
||||||
# set the cookie to 'None', which means Tor will create one for us
|
|
||||||
else:
|
else:
|
||||||
|
# If we had neither a scheduled auth cookie or a persistent hidservauth string,
|
||||||
|
# set the cookie to 'None', which means Tor will create one for us
|
||||||
basic_auth = {"onionshare": None}
|
basic_auth = {"onionshare": None}
|
||||||
else:
|
else:
|
||||||
# Not using client auth at all
|
# Not using client auth at all
|
||||||
|
@ -618,15 +607,6 @@ class Onion(object):
|
||||||
else:
|
else:
|
||||||
# Assume it was a v3 key. Stem will throw an error if it's something illegible
|
# Assume it was a v3 key. Stem will throw an error if it's something illegible
|
||||||
key_type = "ED25519-V3"
|
key_type = "ED25519-V3"
|
||||||
elif self.scheduled_key:
|
|
||||||
# We have a private key prepared already as part of a scheduled share
|
|
||||||
# that is about to start. Use that private key instead of a new one.
|
|
||||||
key_content = self.scheduled_key
|
|
||||||
if self.is_v2_key(key_content):
|
|
||||||
key_type = "RSA1024"
|
|
||||||
else:
|
|
||||||
# Assume it was a v3 key. Stem will throw an error if it's something illegible
|
|
||||||
key_type = "ED25519-V3"
|
|
||||||
else:
|
else:
|
||||||
key_type = "NEW"
|
key_type = "NEW"
|
||||||
# Work out if we can support v3 onion services, which are preferred
|
# Work out if we can support v3 onion services, which are preferred
|
||||||
|
@ -678,30 +658,6 @@ class Onion(object):
|
||||||
auth_string = f"HidServAuth {onion_host} {auth_cookie}"
|
auth_string = f"HidServAuth {onion_host} {auth_cookie}"
|
||||||
mode_settings.set("onion", "hidservauth_string", auth_string)
|
mode_settings.set("onion", "hidservauth_string", auth_string)
|
||||||
|
|
||||||
# If we were scheduling a future share, register the private key for later re-use
|
|
||||||
if save_scheduled_key:
|
|
||||||
self.scheduled_key = res.private_key
|
|
||||||
else:
|
|
||||||
self.scheduled_key = None
|
|
||||||
|
|
||||||
# Likewise, save the hidservauth string if we were scheduling a share
|
|
||||||
if mode_settings.get("general", "client_auth"):
|
|
||||||
if not self.scheduled_auth_cookie:
|
|
||||||
auth_cookie = list(res.client_auth.values())[0]
|
|
||||||
self.auth_string = f"HidServAuth {onion_host} {auth_cookie}"
|
|
||||||
if save_scheduled_key:
|
|
||||||
# Register the HidServAuth for the scheduled share
|
|
||||||
self.scheduled_auth_cookie = auth_cookie
|
|
||||||
else:
|
|
||||||
self.scheduled_auth_cookie = None
|
|
||||||
else:
|
|
||||||
self.auth_string = (
|
|
||||||
f"HidServAuth {onion_host} {self.scheduled_auth_cookie}"
|
|
||||||
)
|
|
||||||
if not save_scheduled_key:
|
|
||||||
# We've used the scheduled share's HidServAuth. Reset it to None for future shares
|
|
||||||
self.scheduled_auth_cookie = None
|
|
||||||
|
|
||||||
return onion_host
|
return onion_host
|
||||||
|
|
||||||
def stop_onion_service(self, mode_settings):
|
def stop_onion_service(self, mode_settings):
|
||||||
|
|
|
@ -63,9 +63,7 @@ class OnionShare(object):
|
||||||
except:
|
except:
|
||||||
raise OSError(strings._("no_available_port"))
|
raise OSError(strings._("no_available_port"))
|
||||||
|
|
||||||
def start_onion_service(
|
def start_onion_service(self, mode_settings, await_publication=True):
|
||||||
self, mode_settings, await_publication=True, save_scheduled_key=False
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Start the onionshare onion service.
|
Start the onionshare onion service.
|
||||||
"""
|
"""
|
||||||
|
@ -82,7 +80,7 @@ class OnionShare(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.onion_host = self.onion.start_onion_service(
|
self.onion_host = self.onion.start_onion_service(
|
||||||
mode_settings, self.port, await_publication, save_scheduled_key
|
mode_settings, self.port, await_publication
|
||||||
)
|
)
|
||||||
|
|
||||||
if mode_settings.get("general", "client_auth"):
|
if mode_settings.get("general", "client_auth"):
|
||||||
|
|
|
@ -70,7 +70,7 @@ class OnionThread(QtCore.QThread):
|
||||||
try:
|
try:
|
||||||
if self.mode.obtain_onion_early:
|
if self.mode.obtain_onion_early:
|
||||||
self.mode.app.start_onion_service(
|
self.mode.app.start_onion_service(
|
||||||
self.mode.settings, await_publication=False, save_scheduled_key=True
|
self.mode.settings, await_publication=False
|
||||||
)
|
)
|
||||||
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash
|
# wait for modules in thread to load, preventing a thread-related cx_Freeze crash
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue