mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-14 00:39:33 -05:00
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
This commit is contained in:
parent
19e378dff4
commit
76d109747e
@ -284,7 +284,7 @@ def main(cwd=None):
|
|||||||
try:
|
try:
|
||||||
common.settings.load()
|
common.settings.load()
|
||||||
if not mode_settings.get("general", "public"):
|
if not mode_settings.get("general", "public"):
|
||||||
web.generate_password(mode_settings.get("persistent", "password"))
|
web.generate_password(mode_settings.get("onion", "password"))
|
||||||
else:
|
else:
|
||||||
web.password = None
|
web.password = None
|
||||||
app = OnionShare(common, onion, local_only, autostop_timer)
|
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
|
# Save the web password if we are using a persistent private key
|
||||||
if mode_settings.get("persistent", "enabled"):
|
if mode_settings.get("persistent", "enabled"):
|
||||||
if not mode_settings.get("persistent", "password"):
|
if not mode_settings.get("onion", "password"):
|
||||||
mode_settings.set("persistent", "password", web.password)
|
mode_settings.set("onion", "password", web.password)
|
||||||
# mode_settings.save()
|
# mode_settings.save()
|
||||||
|
|
||||||
# Build the URL
|
# Build the URL
|
||||||
|
@ -32,13 +32,12 @@ class ModeSettings:
|
|||||||
self.common = common
|
self.common = common
|
||||||
|
|
||||||
self.default_settings = {
|
self.default_settings = {
|
||||||
"persistent": {
|
"onion": {
|
||||||
"enabled": False,
|
|
||||||
"mode": None,
|
|
||||||
"private_key": None,
|
"private_key": None,
|
||||||
"hidservauth_string": None,
|
"hidservauth_string": None,
|
||||||
"password": None,
|
"password": None,
|
||||||
},
|
},
|
||||||
|
"persistent": {"mode": None, "enabled": False},
|
||||||
"general": {
|
"general": {
|
||||||
"public": False,
|
"public": False,
|
||||||
"autostart_timer": False,
|
"autostart_timer": False,
|
||||||
|
@ -229,7 +229,9 @@ class Onion(object):
|
|||||||
else:
|
else:
|
||||||
self.tor_data_directory_name = self.common.build_tor_dir()
|
self.tor_data_directory_name = self.common.build_tor_dir()
|
||||||
self.common.log(
|
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
|
# Create the torrc
|
||||||
@ -595,12 +597,10 @@ class Onion(object):
|
|||||||
else:
|
else:
|
||||||
# If we don't have a scheduled share, but are using persistence, then
|
# 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
|
# we should be able to find a hidservauth_string in saved settings
|
||||||
if mode_settings.get(
|
if mode_settings.get("onion", "hidservauth_string"):
|
||||||
"persistent", "hidservauth_string"
|
auth_cookie = mode_settings.get(
|
||||||
):
|
"onion", "hidservauth_string"
|
||||||
auth_cookie = mode_settings.get("persistent", "hidservauth_string").split()[
|
).split()[2]
|
||||||
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,
|
# 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
|
# Not using client auth at all
|
||||||
basic_auth = None
|
basic_auth = None
|
||||||
|
|
||||||
if mode_settings.get("persistent", "private_key"):
|
if mode_settings.get("onion", "private_key"):
|
||||||
key_content = mode_settings.get("persistent", "private_key")
|
key_content = mode_settings.get("onion", "private_key")
|
||||||
if self.is_v2_key(key_content):
|
if self.is_v2_key(key_content):
|
||||||
key_type = "RSA1024"
|
key_type = "RSA1024"
|
||||||
else:
|
else:
|
||||||
@ -668,16 +668,15 @@ class Onion(object):
|
|||||||
# Save the service_id
|
# Save the service_id
|
||||||
mode_settings.set("general", "service_id", res.service_id)
|
mode_settings.set("general", "service_id", res.service_id)
|
||||||
|
|
||||||
# Save the private key and hidservauth string if persistence is enabled
|
# Save the private key and hidservauth string
|
||||||
if mode_settings.get("persistent", "enabled"):
|
if not mode_settings.get("onion", "private_key"):
|
||||||
if not mode_settings.get("persistent", "private_key"):
|
mode_settings.set("onion", "private_key", res.private_key)
|
||||||
mode_settings.set("persistent", "private_key", res.private_key)
|
if mode_settings.get("general", "client_auth") and not mode_settings.get(
|
||||||
if mode_settings.get("general", "client_auth") and not mode_settings.get(
|
"onion", "hidservauth_string"
|
||||||
"persistent", "hidservauth_string"
|
):
|
||||||
):
|
auth_cookie = list(res.client_auth.values())[0]
|
||||||
auth_cookie = list(res.client_auth.values())[0]
|
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("persistent", "hidservauth_string", auth_string)
|
|
||||||
|
|
||||||
# If we were scheduling a future share, register the private key for later re-use
|
# If we were scheduling a future share, register the private key for later re-use
|
||||||
if save_scheduled_key:
|
if save_scheduled_key:
|
||||||
@ -750,14 +749,24 @@ class Onion(object):
|
|||||||
self.tor_proc.terminate()
|
self.tor_proc.terminate()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
if self.tor_proc.poll() == None:
|
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:
|
try:
|
||||||
self.tor_proc.kill()
|
self.tor_proc.kill()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
if self.tor_proc.poll() == None:
|
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:
|
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
|
self.tor_proc = None
|
||||||
|
|
||||||
# Reset other Onion settings
|
# Reset other Onion settings
|
||||||
|
@ -304,16 +304,14 @@ class Web:
|
|||||||
"""
|
"""
|
||||||
self.q.put({"type": request_type, "path": path, "data": data})
|
self.q.put({"type": request_type, "path": path, "data": data})
|
||||||
|
|
||||||
def generate_password(self, persistent_password=None):
|
def generate_password(self, saved_password=None):
|
||||||
self.common.log(
|
self.common.log("Web", "generate_password", f"saved_password={saved_password}")
|
||||||
"Web", "generate_password", f"persistent_password={persistent_password}"
|
if saved_password != None and saved_password != "":
|
||||||
)
|
self.password = saved_password
|
||||||
if persistent_password != None and persistent_password != "":
|
|
||||||
self.password = persistent_password
|
|
||||||
self.common.log(
|
self.common.log(
|
||||||
"Web",
|
"Web",
|
||||||
"generate_password",
|
"generate_password",
|
||||||
f'persistent_password sent, so password is: "{self.password}"',
|
f'saved_password sent, so password is: "{self.password}"',
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.password = self.common.build_password()
|
self.password = self.common.build_password()
|
||||||
|
@ -207,10 +207,9 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
self.common.settings.load()
|
self.common.settings.load()
|
||||||
self.show_url()
|
self.show_url()
|
||||||
|
|
||||||
if self.settings.get("persistent", "enabled"):
|
if not self.settings.get("onion", "password"):
|
||||||
if not self.settings.get("persistent", "password"):
|
self.settings.set("onion", "password", self.web.password)
|
||||||
self.settings.set("persistent", "password", self.web.password)
|
self.settings.save()
|
||||||
self.settings.save()
|
|
||||||
|
|
||||||
if self.settings.get("general", "autostop_timer"):
|
if self.settings.get("general", "autostop_timer"):
|
||||||
self.server_button.setToolTip(
|
self.server_button.setToolTip(
|
||||||
|
@ -64,7 +64,7 @@ class OnionThread(QtCore.QThread):
|
|||||||
if not self.mode.settings.get("general", "public"):
|
if not self.mode.settings.get("general", "public"):
|
||||||
if not self.mode.web.password:
|
if not self.mode.web.password:
|
||||||
self.mode.web.generate_password(
|
self.mode.web.generate_password(
|
||||||
self.mode.settings.get("persistent", "password")
|
self.mode.settings.get("onion", "password")
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user