From 2d2ec33a9cb233f6af00a4b6f97cf16c80c4956d Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 18 Jul 2024 17:48:22 +0200 Subject: [PATCH] feat(worker): allow manual config of Wireguard keys Added optional manual configuration for Wireguard private and preshared keys in the configuration file. If these keys are not provided, they will be automatically generated as previously. This flexibility allows users to specify their own keys, thus integrating custom security needs and syncing with existing setups more seamlessly. --- config.dist.ini | 6 ++++++ worker.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/config.dist.ini b/config.dist.ini index 3f15976..054149c 100644 --- a/config.dist.ini +++ b/config.dist.ini @@ -4,6 +4,12 @@ address = 10.123.123.2, fdfd:fdfd:1234::2 listen_port = 1234 +# You can provide a private key and a pre-shared key for the server +# If you don't provide them, they will be generated automatically + +# private_key = your_private_key +# preshared_key = your_preshared_key + # Peer configuration peer_public_key = public key of the peer diff --git a/worker.py b/worker.py index 500c9dd..ebc01ed 100644 --- a/worker.py +++ b/worker.py @@ -370,7 +370,19 @@ def main(provider, location, server_type): for command in commands: ssh_execute_command(server_ip, command) - private_key, public_key, preshared_key = generate_wireguard_keys() + # Check if private key and preshared key are provided + if config["wireguard"]["private_key"]: + private_key = config["wireguard"]["private_key"] + else: + private_key = generate_private_key() + + if config["wireguard"]["preshared_key"]: + preshared_key = config["wireguard"]["preshared_key"] + else: + preshared_key = generate_preshared_key() + + public_key = private_to_public_key(private_key) + configure_wireguard(server_ip, private_key, public_key, preshared_key) # Generate client configuration for Chimpman