mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
openssl_publickey: Ensure format OpenSSH is idempotent (#33264)
Currently the check() method for idempotence only assumes the public key is under the form of a PEM file when its not always the case. The module openssl_publickey allows one to generate OpenSSH format publickey. This leads to idempotence not being detected.
This commit is contained in:
parent
341e79b604
commit
a773bd7ad5
3 changed files with 21 additions and 2 deletions
|
@ -212,11 +212,16 @@ class PublicKey(crypto_utils.OpenSSLObject):
|
|||
return False
|
||||
|
||||
try:
|
||||
publickey_content = open(self.path, 'rb').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,
|
||||
crypto_serialization.PublicFormat.SubjectPublicKeyInfo)
|
||||
current_publickey = crypto.dump_publickey(
|
||||
crypto.FILETYPE_ASN1,
|
||||
crypto.load_publickey(crypto.FILETYPE_PEM, open(self.path, 'rb').read())
|
||||
crypto.load_publickey(crypto.FILETYPE_PEM, publickey_content)
|
||||
)
|
||||
except crypto.Error:
|
||||
except (crypto.Error, ValueError):
|
||||
return False
|
||||
|
||||
desired_publickey = crypto.dump_publickey(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue