From 4e516fb84283e23358dfb860f009c49204bd75e6 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 26 Apr 2022 20:28:16 +0200 Subject: [PATCH] Prevent crash if PyOpenSSL cannot be imported because of an AttributeError. --- plugins/module_utils/crypto/basic.py | 2 +- plugins/module_utils/crypto/module_backends/certificate.py | 2 +- .../crypto/module_backends/certificate_assertonly.py | 2 +- plugins/module_utils/crypto/module_backends/certificate_info.py | 2 +- .../module_utils/crypto/module_backends/certificate_ownca.py | 2 +- .../crypto/module_backends/certificate_selfsigned.py | 2 +- plugins/module_utils/crypto/module_backends/csr.py | 2 +- plugins/module_utils/crypto/module_backends/csr_info.py | 2 +- plugins/module_utils/crypto/module_backends/privatekey.py | 2 +- plugins/module_utils/crypto/module_backends/privatekey_info.py | 2 +- plugins/module_utils/crypto/module_backends/publickey_info.py | 2 +- plugins/module_utils/crypto/support.py | 2 +- plugins/modules/get_certificate.py | 2 +- plugins/modules/openssl_pkcs12.py | 2 +- plugins/modules/openssl_publickey.py | 2 +- plugins/modules/openssl_signature.py | 2 +- plugins/modules/openssl_signature_info.py | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/module_utils/crypto/basic.py b/plugins/module_utils/crypto/basic.py index 6bda7aa53..9d9bb2b46 100644 --- a/plugins/module_utils/crypto/basic.py +++ b/plugins/module_utils/crypto/basic.py @@ -26,7 +26,7 @@ import OpenSSL # noqa from OpenSSL import crypto # noqa HAS_PYOPENSSL = True -except ImportError: +except (ImportError, AttributeError): # Error handled in the calling module. HAS_PYOPENSSL = False diff --git a/plugins/module_utils/crypto/module_backends/certificate.py b/plugins/module_utils/crypto/module_backends/certificate.py index 557daede8..6322691a5 100644 --- a/plugins/module_utils/crypto/module_backends/certificate.py +++ b/plugins/module_utils/crypto/module_backends/certificate.py @@ -45,7 +45,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/module_utils/crypto/module_backends/certificate_assertonly.py b/plugins/module_utils/crypto/module_backends/certificate_assertonly.py index 016dbbde0..dcb45bc03 100644 --- a/plugins/module_utils/crypto/module_backends/certificate_assertonly.py +++ b/plugins/module_utils/crypto/module_backends/certificate_assertonly.py @@ -37,7 +37,7 @@ try: import OpenSSL from OpenSSL import crypto -except ImportError: +except (ImportError, AttributeError): pass try: diff --git a/plugins/module_utils/crypto/module_backends/certificate_info.py b/plugins/module_utils/crypto/module_backends/certificate_info.py index 8da72d4a3..9a7b2b1b9 100644 --- a/plugins/module_utils/crypto/module_backends/certificate_info.py +++ b/plugins/module_utils/crypto/module_backends/certificate_info.py @@ -59,7 +59,7 @@ # OpenSSL 1.0.x or older OPENSSL_MUST_STAPLE_NAME = b"1.3.6.1.5.5.7.1.24" OPENSSL_MUST_STAPLE_VALUE = b"DER:30:03:02:01:05" -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/module_utils/crypto/module_backends/certificate_ownca.py b/plugins/module_utils/crypto/module_backends/certificate_ownca.py index f348e00f5..e2391c586 100644 --- a/plugins/module_utils/crypto/module_backends/certificate_ownca.py +++ b/plugins/module_utils/crypto/module_backends/certificate_ownca.py @@ -43,7 +43,7 @@ try: from OpenSSL import crypto -except ImportError: +except (ImportError, AttributeError): pass try: diff --git a/plugins/module_utils/crypto/module_backends/certificate_selfsigned.py b/plugins/module_utils/crypto/module_backends/certificate_selfsigned.py index 141a6f74b..f2249fd1e 100644 --- a/plugins/module_utils/crypto/module_backends/certificate_selfsigned.py +++ b/plugins/module_utils/crypto/module_backends/certificate_selfsigned.py @@ -33,7 +33,7 @@ try: from OpenSSL import crypto -except ImportError: +except (ImportError, AttributeError): pass try: diff --git a/plugins/module_utils/crypto/module_backends/csr.py b/plugins/module_utils/crypto/module_backends/csr.py index 129debe9f..4da3b97ec 100644 --- a/plugins/module_utils/crypto/module_backends/csr.py +++ b/plugins/module_utils/crypto/module_backends/csr.py @@ -63,7 +63,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/module_utils/crypto/module_backends/csr_info.py b/plugins/module_utils/crypto/module_backends/csr_info.py index 2b3f550c3..096cd1d29 100644 --- a/plugins/module_utils/crypto/module_backends/csr_info.py +++ b/plugins/module_utils/crypto/module_backends/csr_info.py @@ -57,7 +57,7 @@ # OpenSSL 1.0.x or older OPENSSL_MUST_STAPLE_NAME = b"1.3.6.1.5.5.7.1.24" OPENSSL_MUST_STAPLE_VALUE = b"DER:30:03:02:01:05" -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/module_utils/crypto/module_backends/privatekey.py b/plugins/module_utils/crypto/module_backends/privatekey.py index 474738bc8..7d5803b27 100644 --- a/plugins/module_utils/crypto/module_backends/privatekey.py +++ b/plugins/module_utils/crypto/module_backends/privatekey.py @@ -54,7 +54,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/module_utils/crypto/module_backends/privatekey_info.py b/plugins/module_utils/crypto/module_backends/privatekey_info.py index 52bd2c1ff..9039dbb8e 100644 --- a/plugins/module_utils/crypto/module_backends/privatekey_info.py +++ b/plugins/module_utils/crypto/module_backends/privatekey_info.py @@ -49,7 +49,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/module_utils/crypto/module_backends/publickey_info.py b/plugins/module_utils/crypto/module_backends/publickey_info.py index a51363f0a..2e0713549 100644 --- a/plugins/module_utils/crypto/module_backends/publickey_info.py +++ b/plugins/module_utils/crypto/module_backends/publickey_info.py @@ -38,7 +38,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/module_utils/crypto/support.py b/plugins/module_utils/crypto/support.py index 67b7226ce..1353ac24a 100644 --- a/plugins/module_utils/crypto/support.py +++ b/plugins/module_utils/crypto/support.py @@ -32,7 +32,7 @@ try: from OpenSSL import crypto HAS_PYOPENSSL = True -except ImportError: +except (ImportError, AttributeError): # Error handled in the calling module. HAS_PYOPENSSL = False diff --git a/plugins/modules/get_certificate.py b/plugins/modules/get_certificate.py index d793a1b4f..876ad859f 100644 --- a/plugins/modules/get_certificate.py +++ b/plugins/modules/get_certificate.py @@ -198,7 +198,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/modules/openssl_pkcs12.py b/plugins/modules/openssl_pkcs12.py index d891c9cdf..e659d6cde 100644 --- a/plugins/modules/openssl_pkcs12.py +++ b/plugins/modules/openssl_pkcs12.py @@ -276,7 +276,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/modules/openssl_publickey.py b/plugins/modules/openssl_publickey.py index 57cb50d78..60f71c772 100644 --- a/plugins/modules/openssl_publickey.py +++ b/plugins/modules/openssl_publickey.py @@ -217,7 +217,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/modules/openssl_signature.py b/plugins/modules/openssl_signature.py index 26db52cd7..4406c484c 100644 --- a/plugins/modules/openssl_signature.py +++ b/plugins/modules/openssl_signature.py @@ -108,7 +108,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: diff --git a/plugins/modules/openssl_signature_info.py b/plugins/modules/openssl_signature_info.py index 28e94259b..e16bae5f9 100644 --- a/plugins/modules/openssl_signature_info.py +++ b/plugins/modules/openssl_signature_info.py @@ -108,7 +108,7 @@ import OpenSSL from OpenSSL import crypto PYOPENSSL_VERSION = LooseVersion(OpenSSL.__version__) -except ImportError: +except (ImportError, AttributeError): PYOPENSSL_IMP_ERR = traceback.format_exc() PYOPENSSL_FOUND = False else: