Ensure ec2_win_password doesn't leak file handle
Currently the module doesn't explicitly close the file handle. This wraps the reading of the private key in a try/finally block to ensure the file is properly closed.
This commit is contained in:
parent
f6a7b6dd1f
commit
41a2542f00
1 changed files with 5 additions and 2 deletions
|
@ -140,8 +140,11 @@ def main():
|
||||||
if wait and datetime.datetime.now() >= end:
|
if wait and datetime.datetime.now() >= end:
|
||||||
module.fail_json(msg = "wait for password timeout after %d seconds" % wait_timeout)
|
module.fail_json(msg = "wait for password timeout after %d seconds" % wait_timeout)
|
||||||
|
|
||||||
|
try:
|
||||||
f = open(key_file, 'r')
|
f = open(key_file, 'r')
|
||||||
key = RSA.importKey(f.read(), key_passphrase)
|
key = RSA.importKey(f.read(), key_passphrase)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
cipher = PKCS1_v1_5.new(key)
|
cipher = PKCS1_v1_5.new(key)
|
||||||
sentinel = 'password decryption failed!!!'
|
sentinel = 'password decryption failed!!!'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue