Handle rare case when failing to load libssl (#1167)

This commit is contained in:
Lonami 2019-04-28 10:44:22 +02:00 committed by GitHub
parent 1666976646
commit 3ea1c9f04b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,15 +3,25 @@ Helper module around the system's libssl library if available for IGE mode.
"""
import ctypes
import ctypes.util
import logging
__log__ = logging.getLogger(__name__)
lib = ctypes.util.find_library('ssl')
if not lib:
try:
_libssl = ctypes.cdll.LoadLibrary(lib)
except OSError as e:
# See https://github.com/LonamiWebs/Telethon/issues/1167
# Sometimes `find_library` returns improper filenames.
__log__.info('Failed to load %s: %s (%s)', lib, type(e), e)
_libssl = None
if not _libssl:
decrypt_ige = None
encrypt_ige = None
else:
_libssl = ctypes.cdll.LoadLibrary(lib)
# https://github.com/openssl/openssl/blob/master/include/openssl/aes.h
AES_ENCRYPT = ctypes.c_int(1)
AES_DECRYPT = ctypes.c_int(0)