Skip to content

Commit

Permalink
Check whether _backend exists before calling internal function.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Jan 26, 2024
1 parent 8a8faa8 commit 384cafc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/700-private_key_info-cryptography.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "openssl_privatekey_info - was using an internal function for determining whether a private key is consistent, that got removed in cryptography 42.0.0.
The code now checks whether that function exists before calling it (https://github.com/ansible-collections/community.crypto/pull/700)."
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def _check_dsa_consistency(key_public_data, key_private_data):

def _is_cryptography_key_consistent(key, key_public_data, key_private_data):
if isinstance(key, cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey):
return bool(key._backend._lib.RSA_check_key(key._rsa_cdata))
# key._backend was removed in cryptography 42.0.0
backend = getattr(key, '_backend', None)
if backend is None:
return None
return bool(backend._lib.RSA_check_key(key._rsa_cdata))
if isinstance(key, cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey):
result = _check_dsa_consistency(key_public_data, key_private_data)
if result is not None:
Expand Down

0 comments on commit 384cafc

Please sign in to comment.