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.
This commit is contained in:
Sunil Mohan Adapa 2017-03-27 21:54:44 +05:30
parent fcd2499092
commit f9bd2542a7
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -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():