From a2434e40e0938f120b8c26fee084143c7896dc10 Mon Sep 17 00:00:00 2001 From: Adrian Vladu Date: Fri, 10 May 2019 12:27:37 +0300 Subject: [PATCH] ssl: fix ERR_load_crypto_strings attribute error ERR_load_crypto_strings does not exist anymore in OpenSSL > 1.1.0, thus leading to an AttributeError in Python: openssl/include/openssl/err.h#L253 Change-Id: I1b135dcdd296f05703fee1c41441d4bac6fac37a --- cloudbaseinit/utils/crypt.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cloudbaseinit/utils/crypt.py b/cloudbaseinit/utils/crypt.py index 0ec06054..20364383 100644 --- a/cloudbaseinit/utils/crypt.py +++ b/cloudbaseinit/utils/crypt.py @@ -92,8 +92,13 @@ openssl.ERR_error_string_n.argtypes = [ctypes.c_long, ctypes.c_char_p, ctypes.c_int] -openssl.ERR_load_crypto_strings.restype = ctypes.c_int -openssl.ERR_load_crypto_strings.argtypes = [] +try: + openssl.ERR_load_crypto_strings.restype = ctypes.c_int + openssl.ERR_load_crypto_strings.argtypes = [] +except AttributeError: + # NOTE(avladu): This function is deprecated and no longer needed + # since OpenSSL 1.1 + pass clib.fopen.restype = ctypes.c_void_p clib.fopen.argtypes = [ctypes.c_char_p, ctypes.c_char_p] @@ -113,7 +118,11 @@ class OpenSSLException(CryptException): super(OpenSSLException, self).__init__(message) def _get_openssl_error_msg(self): - openssl.ERR_load_crypto_strings() + try: + openssl.ERR_load_crypto_strings() + except AttributeError: + pass + errno = openssl.ERR_get_error() errbuf = ctypes.create_string_buffer(1024) openssl.ERR_error_string_n(errno, errbuf, 1024)