From edfb82772cb36451d3cbcf9c514c3be1a617b19d Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 11 Feb 2026 22:11:21 +0100 Subject: [PATCH] Fix EC detection. (#981) (#982) (cherry picked from commit 911ed33c2e898e6b56e640fa4f71afa599db3fcb) --- changelogs/fragments/981-ec.yml | 2 ++ plugins/module_utils/crypto/module_backends/privatekey.py | 2 +- plugins/modules/crypto_info.py | 6 ++---- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/981-ec.yml diff --git a/changelogs/fragments/981-ec.yml b/changelogs/fragments/981-ec.yml new file mode 100644 index 00000000..ec00722b --- /dev/null +++ b/changelogs/fragments/981-ec.yml @@ -0,0 +1,2 @@ +bugfixes: + - "crypto_info, openssl_privatekey, openssl_privatekey_pipe - fix detection of EC support for cryptography 46.0.5+ (https://github.com/ansible-collections/community.crypto/pull/981)." diff --git a/plugins/module_utils/crypto/module_backends/privatekey.py b/plugins/module_utils/crypto/module_backends/privatekey.py index 2e473f14..6f9b7dd5 100644 --- a/plugins/module_utils/crypto/module_backends/privatekey.py +++ b/plugins/module_utils/crypto/module_backends/privatekey.py @@ -276,7 +276,7 @@ class PrivateKeyBackend: class PrivateKeyCryptographyBackend(PrivateKeyBackend): def _get_ec_class(self, ectype): - ecclass = cryptography.hazmat.primitives.asymmetric.ec.__dict__.get(ectype) + ecclass = getattr(cryptography.hazmat.primitives.asymmetric.ec, ectype, None) if ecclass is None: self.module.fail_json( msg="Your cryptography version does not support {0}".format(ectype) diff --git a/plugins/modules/crypto_info.py b/plugins/modules/crypto_info.py index ac3c1c27..74d9014f 100644 --- a/plugins/modules/crypto_info.py +++ b/plugins/modules/crypto_info.py @@ -286,10 +286,8 @@ def add_crypto_information(module): backend = cryptography.hazmat.backends.default_backend() for curve_name, constructor_name in CURVES: - ecclass = cryptography.hazmat.primitives.asymmetric.ec.__dict__.get( - constructor_name - ) - if ecclass: + ecclass = getattr(cryptography.hazmat.primitives.asymmetric.ec, constructor_name, None) + if ecclass is not None: try: cryptography.hazmat.primitives.asymmetric.ec.generate_private_key( curve=ecclass(), backend=backend