Skip to content

Commit

Permalink
Emit warning when consistency cannot be checked. (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Jan 27, 2024
1 parent 87af1f2 commit 9ec8680
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "openssl_privatekey_info - ``check_consistency=true`` now reports a warning if it cannot determine consistency (https://github.com/ansible-collections/community.crypto/pull/705)."
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _check_dsa_consistency(key_public_data, key_private_data):
return True


def _is_cryptography_key_consistent(key, key_public_data, key_private_data):
def _is_cryptography_key_consistent(key, key_public_data, key_private_data, warn_func=None):
if isinstance(key, cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey):
# key._backend was removed in cryptography 42.0.0
backend = getattr(key, '_backend', None)
Expand Down Expand Up @@ -160,6 +160,8 @@ def _is_cryptography_key_consistent(key, key_public_data, key_private_data):
except cryptography.exceptions.InvalidSignature:
return False
# For X25519 and X448, there's no test yet.
if warn_func is not None:
warn_func('Cannot determine consistency for key of type %s' % type(key))
return None


Expand Down Expand Up @@ -256,7 +258,7 @@ def _get_key_info(self, need_private_key_data=False):
return _get_cryptography_private_key_info(self.key, need_private_key_data=need_private_key_data)

def _is_key_consistent(self, key_public_data, key_private_data):
return _is_cryptography_key_consistent(self.key, key_public_data, key_private_data)
return _is_cryptography_key_consistent(self.key, key_public_data, key_private_data, warn_func=self.module.warn)


def get_privatekey_info(module, backend, content, passphrase=None, return_private_key_data=False, prefer_one_fingerprint=False):
Expand Down

0 comments on commit 9ec8680

Please sign in to comment.