mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Close all open filehandle (#50544)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
committed by
Brian Coca
parent
94a1d86d70
commit
db8702cdb8
@@ -255,8 +255,9 @@ class Pkcs(crypto_utils.OpenSSLObject):
|
||||
|
||||
try:
|
||||
self.remove()
|
||||
|
||||
p12 = crypto.load_pkcs12(open(self.src, 'rb').read(),
|
||||
with open(self.src, 'rb') as pkcs12_fh:
|
||||
pkcs12_content = pkcs12_fh.read()
|
||||
p12 = crypto.load_pkcs12(pkcs12_content,
|
||||
self.passphrase)
|
||||
pkey = crypto.dump_privatekey(crypto.FILETYPE_PEM,
|
||||
p12.get_privatekey())
|
||||
|
||||
@@ -170,7 +170,8 @@ class PublicKey(crypto_utils.OpenSSLObject):
|
||||
if not self.check(module, perms_required=False) or self.force:
|
||||
try:
|
||||
if self.format == 'OpenSSH':
|
||||
privatekey_content = open(self.privatekey_path, 'rb').read()
|
||||
with open(self.privatekey_path, 'rb') as private_key_fh:
|
||||
privatekey_content = private_key_fh.read()
|
||||
key = crypto_serialization.load_pem_private_key(privatekey_content,
|
||||
password=self.privatekey_passphrase,
|
||||
backend=default_backend())
|
||||
@@ -212,7 +213,8 @@ class PublicKey(crypto_utils.OpenSSLObject):
|
||||
return False
|
||||
|
||||
try:
|
||||
publickey_content = open(self.path, 'rb').read()
|
||||
with open(self.path, 'rb') as public_key_fh:
|
||||
publickey_content = public_key_fh.read()
|
||||
if self.format == 'OpenSSH':
|
||||
current_publickey = crypto_serialization.load_ssh_public_key(publickey_content, backend=default_backend())
|
||||
publickey_content = current_publickey.public_bytes(crypto_serialization.Encoding.PEM,
|
||||
|
||||
Reference in New Issue
Block a user