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.
This commit is contained in:
Kumi 2024-07-18 17:48:22 +02:00
parent b47e81791d
commit 2d2ec33a9c
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 19 additions and 1 deletions

View file

@ -4,6 +4,12 @@
address = 10.123.123.2, fdfd:fdfd:1234::2 address = 10.123.123.2, fdfd:fdfd:1234::2
listen_port = 1234 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 configuration
peer_public_key = public key of the peer peer_public_key = public key of the peer

View file

@ -370,7 +370,19 @@ def main(provider, location, server_type):
for command in commands: for command in commands:
ssh_execute_command(server_ip, command) 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) configure_wireguard(server_ip, private_key, public_key, preshared_key)
# Generate client configuration for Chimpman # Generate client configuration for Chimpman