Correctly handle the situation when with the secret key or public key values are empty.

This commit is contained in:
Gareth J. Greenaway 2019-02-28 13:18:53 -08:00
parent 3fdb564346
commit c314f5166b
No known key found for this signature in database
GPG Key ID: 10B62F8A7CAD7A41

View File

@ -69,12 +69,15 @@ def _get_sk(**kwargs):
Return sk
'''
config = _get_config(**kwargs)
key = None
if config['sk']:
key = salt.utils.stringutils.to_str(config['sk'])
sk_file = config['sk_file']
if not key and sk_file:
try:
with salt.utils.files.fopen(sk_file, 'rb') as keyf:
key = salt.utils.stringutils.to_unicode(keyf.read()).rstrip('\n')
if key is None:
except (IOError, OSError):
raise Exception('no key or sk_file found')
return base64.b64decode(key)
@ -84,12 +87,15 @@ def _get_pk(**kwargs):
Return pk
'''
config = _get_config(**kwargs)
pubkey = None
if config['pk']:
pubkey = salt.utils.stringutils.to_str(config['pk'])
pk_file = config['pk_file']
if not pubkey and pk_file:
try:
with salt.utils.files.fopen(pk_file, 'rb') as keyf:
pubkey = salt.utils.stringutils.to_unicode(keyf.read()).rstrip('\n')
if pubkey is None:
except (IOError, OSError):
raise Exception('no pubkey or pk_file found')
pubkey = six.text_type(pubkey)
return base64.b64decode(pubkey)