From f9bd2542a73731e7a4223a49e213ca0e129bd5d9 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 27 Mar 2017 21:54:44 +0530 Subject: [PATCH] openvpn: Apply empty file check to private key also When downloading user's profile, if user's private key is empty, regenerate user's key. Minor styling fixes too. --- actions/openvpn | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/actions/openvpn b/actions/openvpn index 8a4106966..c5ec10a9f 100755 --- a/actions/openvpn +++ b/actions/openvpn @@ -148,8 +148,8 @@ def _create_certificates(): subprocess.check_call(['/usr/share/easy-rsa/clean-all'], **COMMON_ARGS) subprocess.check_call(['/usr/share/easy-rsa/pkitool', '--initca'], **COMMON_ARGS) - subprocess.check_call(['/usr/share/easy-rsa/pkitool', '--server', 'server'], - **COMMON_ARGS) + subprocess.check_call(['/usr/share/easy-rsa/pkitool', '--server', + 'server'], **COMMON_ARGS) subprocess.check_call(['/usr/share/easy-rsa/build-dh'], **COMMON_ARGS) @@ -164,7 +164,8 @@ def subcommand_get_profile(arguments): user_certificate = USER_CERTIFICATE_PATH.format(username=username) user_key = USER_KEY_PATH.format(username=username) - if not _is_non_empty_file(user_certificate) or not os.path.isfile(user_key): + if not _is_non_empty_file(user_certificate) or \ + not _is_non_empty_file(user_key): subprocess.check_call(['/usr/share/easy-rsa/pkitool', username], **COMMON_ARGS) @@ -186,8 +187,8 @@ def _read_file(filename): def _is_non_empty_file(filepath): + """Return wheather a file exists and is not zero size.""" return os.path.isfile(filepath) and os.path.getsize(filepath) > 0 - pass def main():