diff options
author | Micah Lee <micah@micahflee.com> | 2019-12-08 10:13:56 -0800 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2019-12-08 10:13:56 -0800 |
commit | 76d109747e7caa861ee1a05e70334679d1942b04 (patch) | |
tree | d7b8740ae8bb5d27bc8089d07a1236da7e8a45b7 /onionshare | |
parent | 19e378dff444a09a64a5ac41904a247f25e6b8b8 (diff) | |
download | onionshare-76d109747e7caa861ee1a05e70334679d1942b04.tar.gz onionshare-76d109747e7caa861ee1a05e70334679d1942b04.zip |
Move private_key, hidservauth_string, and password from "persistent" mode settings to "onion" mode settings; and make it so the onion settings are always saved in each tab, even if the tab is not persistent, so if you stop and start a service in the same tab it has the same onion address and password
Diffstat (limited to 'onionshare')
-rw-r--r-- | onionshare/__init__.py | 6 | ||||
-rw-r--r-- | onionshare/mode_settings.py | 5 | ||||
-rw-r--r-- | onionshare/onion.py | 53 | ||||
-rw-r--r-- | onionshare/web/web.py | 12 |
4 files changed, 41 insertions, 35 deletions
diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 704f0a51..8d2077c2 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -284,7 +284,7 @@ def main(cwd=None): try: common.settings.load() if not mode_settings.get("general", "public"): - web.generate_password(mode_settings.get("persistent", "password")) + web.generate_password(mode_settings.get("onion", "password")) else: web.password = None app = OnionShare(common, onion, local_only, autostop_timer) @@ -385,8 +385,8 @@ def main(cwd=None): # Save the web password if we are using a persistent private key if mode_settings.get("persistent", "enabled"): - if not mode_settings.get("persistent", "password"): - mode_settings.set("persistent", "password", web.password) + if not mode_settings.get("onion", "password"): + mode_settings.set("onion", "password", web.password) # mode_settings.save() # Build the URL diff --git a/onionshare/mode_settings.py b/onionshare/mode_settings.py index 6e875f0d..9201721e 100644 --- a/onionshare/mode_settings.py +++ b/onionshare/mode_settings.py @@ -32,13 +32,12 @@ class ModeSettings: self.common = common self.default_settings = { - "persistent": { - "enabled": False, - "mode": None, + "onion": { "private_key": None, "hidservauth_string": None, "password": None, }, + "persistent": {"mode": None, "enabled": False}, "general": { "public": False, "autostart_timer": False, diff --git a/onionshare/onion.py b/onionshare/onion.py index e368819c..9520f381 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -229,7 +229,9 @@ class Onion(object): else: self.tor_data_directory_name = self.common.build_tor_dir() self.common.log( - "Onion", "connect", f"tor_data_directory_name={self.tor_data_directory_name}" + "Onion", + "connect", + f"tor_data_directory_name={self.tor_data_directory_name}", ) # Create the torrc @@ -595,12 +597,10 @@ class Onion(object): 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( - "persistent", "hidservauth_string" - ): - auth_cookie = mode_settings.get("persistent", "hidservauth_string").split()[ - 2 - ] + if mode_settings.get("onion", "hidservauth_string"): + auth_cookie = mode_settings.get( + "onion", "hidservauth_string" + ).split()[2] if auth_cookie: basic_auth = {"onionshare": auth_cookie} # If we had neither a scheduled auth cookie or a persistent hidservauth string, @@ -611,8 +611,8 @@ class Onion(object): # Not using client auth at all basic_auth = None - if mode_settings.get("persistent", "private_key"): - key_content = mode_settings.get("persistent", "private_key") + if mode_settings.get("onion", "private_key"): + key_content = mode_settings.get("onion", "private_key") if self.is_v2_key(key_content): key_type = "RSA1024" else: @@ -668,16 +668,15 @@ class Onion(object): # Save the service_id mode_settings.set("general", "service_id", res.service_id) - # Save the private key and hidservauth string if persistence is enabled - if mode_settings.get("persistent", "enabled"): - if not mode_settings.get("persistent", "private_key"): - mode_settings.set("persistent", "private_key", res.private_key) - if mode_settings.get("general", "client_auth") and not mode_settings.get( - "persistent", "hidservauth_string" - ): - auth_cookie = list(res.client_auth.values())[0] - auth_string = f"HidServAuth {onion_host} {auth_cookie}" - mode_settings.set("persistent", "hidservauth_string", auth_string) + # Save the private key and hidservauth string + if not mode_settings.get("onion", "private_key"): + mode_settings.set("onion", "private_key", res.private_key) + if mode_settings.get("general", "client_auth") and not mode_settings.get( + "onion", "hidservauth_string" + ): + auth_cookie = list(res.client_auth.values())[0] + auth_string = f"HidServAuth {onion_host} {auth_cookie}" + 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: @@ -750,14 +749,24 @@ class Onion(object): self.tor_proc.terminate() time.sleep(0.2) if self.tor_proc.poll() == None: - self.common.log("Onion", "cleanup", "Tried to terminate tor process but it's still running") + self.common.log( + "Onion", + "cleanup", + "Tried to terminate tor process but it's still running", + ) try: self.tor_proc.kill() time.sleep(0.2) if self.tor_proc.poll() == None: - self.common.log("Onion", "cleanup", "Tried to kill tor process but it's still running") + self.common.log( + "Onion", + "cleanup", + "Tried to kill tor process but it's still running", + ) except: - self.common.log("Onion", "cleanup", "Exception while killing tor process") + self.common.log( + "Onion", "cleanup", "Exception while killing tor process" + ) self.tor_proc = None # Reset other Onion settings diff --git a/onionshare/web/web.py b/onionshare/web/web.py index 8c4373fb..8582e694 100644 --- a/onionshare/web/web.py +++ b/onionshare/web/web.py @@ -304,16 +304,14 @@ class Web: """ self.q.put({"type": request_type, "path": path, "data": data}) - def generate_password(self, persistent_password=None): - self.common.log( - "Web", "generate_password", f"persistent_password={persistent_password}" - ) - if persistent_password != None and persistent_password != "": - self.password = persistent_password + def generate_password(self, saved_password=None): + self.common.log("Web", "generate_password", f"saved_password={saved_password}") + if saved_password != None and saved_password != "": + self.password = saved_password self.common.log( "Web", "generate_password", - f'persistent_password sent, so password is: "{self.password}"', + f'saved_password sent, so password is: "{self.password}"', ) else: self.password = self.common.build_password() |