openvpn: Minor refactoring in setting up easy-rsa

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2023-08-24 10:38:03 -07:00 committed by James Valleroy
parent 0e91261446
commit 95f65b5c4b
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -144,10 +144,10 @@ def _setup_firewall():
action_utils.service_restart('firewalld') action_utils.service_restart('firewalld')
def _init_pki(): def _run_easy_rsa(args):
"""Initialize easy-rsa PKI directory to create configuration file.""" """Execute easy-rsa command with some default arguments."""
subprocess.check_call(['/usr/share/easy-rsa/easyrsa', 'init-pki'], return subprocess.run(['/usr/share/easy-rsa/easyrsa'] + args,
**COMMON_ARGS) cwd=KEYS_DIRECTORY, check=True)
def _create_certificates(): def _create_certificates():
@ -157,11 +157,9 @@ def _create_certificates():
except FileExistsError: except FileExistsError:
pass pass
_init_pki() _run_easy_rsa(['init-pki'])
easy_rsa = '/usr/share/easy-rsa/easyrsa' _run_easy_rsa(['build-ca', 'nopass'])
subprocess.check_call([easy_rsa, 'build-ca', 'nopass'], **COMMON_ARGS) _run_easy_rsa(['build-server-full', 'server', 'nopass'])
subprocess.check_call([easy_rsa, 'build-server-full', 'server', 'nopass'],
**COMMON_ARGS)
@privileged @privileged
@ -176,10 +174,7 @@ def get_profile(username: str, remote_server: str) -> str:
if not _is_non_empty_file(user_certificate) or \ if not _is_non_empty_file(user_certificate) or \
not _is_non_empty_file(user_key): not _is_non_empty_file(user_key):
set_unique_subject('no') # Set unique subject in attribute file to no set_unique_subject('no') # Set unique subject in attribute file to no
subprocess.check_call([ _run_easy_rsa(['build-client-full', username, 'nopass'])
'/usr/share/easy-rsa/easyrsa', 'build-client-full', username,
'nopass'
], env=CERTIFICATE_CONFIGURATION, cwd=KEYS_DIRECTORY)
user_certificate_string = _read_file(user_certificate) user_certificate_string = _read_file(user_certificate)
user_key_string = _read_file(user_key) user_key_string = _read_file(user_key)