ec2_win_password.py - handle missing or unparseable key file more intuitively (#2729)
This commit is contained in:
parent
f108f8ef72
commit
587636b525
1 changed files with 9 additions and 3 deletions
|
@ -146,9 +146,15 @@ def main():
|
|||
|
||||
try:
|
||||
f = open(key_file, 'r')
|
||||
key = RSA.importKey(f.read(), key_passphrase)
|
||||
finally:
|
||||
f.close()
|
||||
except IOError as e:
|
||||
module.fail_json(msg = "I/O error (%d) opening key file: %s" % (e.errno, e.strerror))
|
||||
else:
|
||||
try:
|
||||
with f:
|
||||
key = RSA.importKey(f.read(), key_passphrase)
|
||||
except (ValueError, IndexError, TypeError) as e:
|
||||
module.fail_json(msg = "unable to parse key file")
|
||||
|
||||
cipher = PKCS1_v1_5.new(key)
|
||||
sentinel = 'password decryption failed!!!'
|
||||
|
||||
|
|
Loading…
Reference in a new issue