ec2_win_password.py - handle missing or unparseable key file more intuitively (#2729)

reviewable/pr18780/r1
steve-dave 8 years ago committed by René Moser
parent 5e174c6e50
commit 0dbb0b131f

@ -142,9 +142,15 @@ def main():
try: try:
f = open(key_file, 'r') f = open(key_file, 'r')
key = RSA.importKey(f.read(), key_passphrase) except IOError as e:
finally: module.fail_json(msg = "I/O error (%d) opening key file: %s" % (e.errno, e.strerror))
f.close() 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) cipher = PKCS1_v1_5.new(key)
sentinel = 'password decryption failed!!!' sentinel = 'password decryption failed!!!'

Loading…
Cancel
Save