From cb3529d227b7cdd709fb9abe88358ecfe4689634 Mon Sep 17 00:00:00 2001 From: BarsTiger Date: Mon, 26 Jun 2023 14:02:29 +0300 Subject: [PATCH] v3 auth file --- .gitignore | 1 + dragonion_server/modules/server/integration.py | 11 ++++++++++- dragonion_server/utils/generated_auth/__init__.py | 1 + dragonion_server/utils/generated_auth/db.py | 10 ++++++++++ dragonion_server/utils/onion/onion.py | 3 ++- 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 dragonion_server/utils/generated_auth/__init__.py create mode 100644 dragonion_server/utils/generated_auth/db.py diff --git a/.gitignore b/.gitignore index 5ab8aa6..dd65b47 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /dist/ /data/ data.storage +*.auth __pycache__ poetry.lock diff --git a/dragonion_server/modules/server/integration.py b/dragonion_server/modules/server/integration.py index 912c4d4..6e907f7 100644 --- a/dragonion_server/modules/server/integration.py +++ b/dragonion_server/modules/server/integration.py @@ -1,9 +1,18 @@ from dragonion_server.utils.onion import Onion +from dragonion_server.utils.generated_auth.db import AuthFile +from dragonion_server.utils.config.db import services def integrate_onion(port: int, name: str) -> Onion: onion = Onion() onion.connect() onion.write_onion_service(name, port) - print(f'Available on {onion.start_onion_service(name)}') + print(f'Available on {(onion_host := onion.start_onion_service(name))}') + auth = AuthFile(name) + auth['host'] = onion_host + auth['auth'] = onion.auth_string + print(f'To connect to server share .onion host and auth string (next line), ' + f'also you can just share {auth.filename} file') + print(onion.auth_string) + print(f'Raw url auth string: {services[name].client_auth_priv_key}') return onion diff --git a/dragonion_server/utils/generated_auth/__init__.py b/dragonion_server/utils/generated_auth/__init__.py new file mode 100644 index 0000000..2ae2839 --- /dev/null +++ b/dragonion_server/utils/generated_auth/__init__.py @@ -0,0 +1 @@ +pass diff --git a/dragonion_server/utils/generated_auth/db.py b/dragonion_server/utils/generated_auth/db.py new file mode 100644 index 0000000..b61e190 --- /dev/null +++ b/dragonion_server/utils/generated_auth/db.py @@ -0,0 +1,10 @@ +import sqlitedict + + +class AuthFile(sqlitedict.SqliteDict): + def __init__(self, service): + super().__init__( + filename=f'{service}.auth', + tablename='auth', + autocommit=True + ) diff --git a/dragonion_server/utils/onion/onion.py b/dragonion_server/utils/onion/onion.py index 0b5b0c7..8b86a65 100644 --- a/dragonion_server/utils/onion/onion.py +++ b/dragonion_server/utils/onion/onion.py @@ -237,7 +237,8 @@ class Onion(object): service.key_type = "ED25519-V3" service.key_content = res.private_key - self.auth_string = service.client_auth_priv_key + self.auth_string = \ + base64.b64encode(f'{res.service_id}:descriptor:x25519:{service.client_auth_priv_key}'.encode()).decode() services[name] = service