summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2026-11-03 21:10:22 +0200
committerGitHub <noreply@github.com>2026-11-03 21:10:22 +0200
commite71bc6905befedf78008d2cdadda03b7a359759f (patch)
tree27097de4896f5f983a07e954924a3da439ce09e8 /src
parent329b63a60bb841e5f3fe8bc21073601a55d9bf1d (diff)
parentd73122f17a14511f522261fa7fee6eae54811ca5 (diff)
downloadvyos-1x-e71bc6905befedf78008d2cdadda03b7a359759f.tar.gz
vyos-1x-e71bc6905befedf78008d2cdadda03b7a359759f.zip
Merge pull request #5567 from aiv/T9469-openvpn-client-config-tls-key
openvpn: T9469: add TLS key to generated client config
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/generate_ovpn_client_file.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/op_mode/generate_ovpn_client_file.py b/src/op_mode/generate_ovpn_client_file.py
index 463815601..04943a059 100755
--- a/src/op_mode/generate_ovpn_client_file.py
+++ b/src/op_mode/generate_ovpn_client_file.py
@@ -21,6 +21,7 @@ from textwrap import fill
from vyos.config import Config
from vyos.ifconfig import Section
+from vyos.utils.dict import dict_search_args
client_config = """
@@ -88,7 +89,22 @@ auth {{ hash }}
-----END PRIVATE KEY-----
</key>
-
+{% if tls is defined and tls.crypt_key is defined %}
+
+<tls-crypt>
+-----BEGIN OpenVPN Static key V1-----
+{{ tls_key }}
+-----END OpenVPN Static key V1-----
+</tls-crypt>
+{% elif tls is defined and tls.auth_key is defined %}
+
+key-direction 1
+<tls-auth>
+-----BEGIN OpenVPN Static key V1-----
+{{ tls_key }}
+-----END OpenVPN Static key V1-----
+</tls-auth>
+{% endif %}
"""
config = Config()
@@ -158,5 +174,15 @@ if __name__ == '__main__':
config['key'] = key
config['port'] = '1194' if 'local_port' not in config else config['local_port']
+ tls = config.get('tls', {})
+ tls_key = tls.get('crypt_key') or tls.get('auth_key')
+ if tls_key:
+ tls_key_data = dict_search_args(
+ config, 'pki', 'openvpn', 'shared_secret', tls_key, 'key'
+ )
+ if not tls_key_data:
+ exit(f'OpenVPN shared secret key "{tls_key}" does not exist!')
+ config['tls_key'] = fill(tls_key_data, width=32)
+
client = Template(client_config, trim_blocks=True).render(config)
print(client)