This commit is contained in:
mig5 2025-08-19 01:30:38 +08:00 committed by GitHub
commit 415f495626
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 1128 additions and 41 deletions

View file

@ -43,7 +43,7 @@ class ModeSettings:
"persistent": {
"mode": None,
"enabled": False,
"autostart_on_launch": False
"autostart_on_launch": False,
},
"general": {
"title": None,
@ -67,8 +67,9 @@ class ModeSettings:
"disable_csp": False,
"custom_csp": None,
"log_filenames": False,
"filenames": []
"filenames": [],
},
"download": {"data_dir": self.build_default_receive_data_dir(), "poll": 0},
"chat": {},
}
self._settings = {}

View file

@ -190,6 +190,23 @@ class Onion(object):
s = key_b32.decode("utf-8")
return s
def private_key_to_b64(self, encoded_key):
"""
Converts a base32 encoded string back to a base64 encoded string.
This is used for adding a Private Key to an onion when operating in
client mode (such as when downloading from another OnionShare)
"""
# Decode the base32 string into bytes
encoded_key_b32 = encoded_key.encode("utf-8")
decoded_bytes = base64.b32decode(encoded_key_b32 + b"====")
# Convert the decoded bytes to base64
base64_key = base64.b64encode(decoded_bytes)
# Convert to string and return
return base64_key.decode("utf-8")
def connect(
self,
custom_settings=None,
@ -417,7 +434,11 @@ class Onion(object):
return_code = self.tor_proc.poll()
if return_code != None:
self.common.log("Onion", "connect", f"tor process has terminated early: {return_code}")
self.common.log(
"Onion",
"connect",
f"tor process has terminated early: {return_code}",
)
# Connect to the controller
self.common.log("Onion", "connect", "authenticating to tor controller")
@ -679,6 +700,31 @@ class Onion(object):
else:
return False
def add_onion_client_auth(self, service_id, private_key, key_type="x25519"):
"""
Implemented from scratch here because it never made it into Stem maint branch
"""
if self.supports_v3_onions and self.supports_ephemeral:
private_key64 = self.private_key_to_b64(private_key)
request = f"ONION_CLIENT_AUTH_ADD {service_id} {key_type}:{private_key64}"
response = self.c.msg(request)
self.common.log("Onion", "add_onion_client_auth", response)
return response
else:
raise TorTooOldEphemeral()
def remove_onion_client_auth(self, service_id):
"""
Implemented from scratch here because it never made it into Stem maint branch
"""
if self.supports_v3_onions and self.supports_ephemeral:
request = f"ONION_CLIENT_AUTH_REMOVE {service_id}"
response = self.c.msg(request)
self.common.log("Onion", "remove_onion_client_auth", response)
return response
else:
raise TorTooOldEphemeral()
def start_onion_service(self, mode, mode_settings, port, await_publication):
"""
Start a onion service on port 80, pointing to the given port, and