From ef5b8a208b2efdc57f162b4235094d1bed1cead2 Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Mar 09 2022 13:14:17 +0000 Subject: Fix compiling with OpenSSL 3.0 and use correct test run command --- diff --git a/m2crypto-MR271-opensslversion.patch b/m2crypto-MR271-opensslversion.patch new file mode 100644 index 0000000..c26beb9 --- /dev/null +++ b/m2crypto-MR271-opensslversion.patch @@ -0,0 +1,64 @@ +From 1a746c6d01eff4863c116e279756a1035fd5feb0 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= +Date: Mon, 22 Nov 2021 23:05:41 +0100 +Subject: [PATCH] Use OpenSSL_version_num() instead of unrealiable parsing of + .h file. + +Fixes #302 +--- + setup.py | 39 ++++++++++++++++++++++++--------------- + 1 file changed, 24 insertions(+), 15 deletions(-) + +diff --git a/setup.py b/setup.py +index a1d58f25..04ac8c77 100644 +--- a/setup.py ++++ b/setup.py +@@ -75,21 +75,30 @@ def openssl_version(ossldir, req_ver, required=False): + :return: Boolean indicating whether the satisfying version of + OpenSSL has been installed. + """ +- ver = None +- file = os.path.join(ossldir, 'include', 'openssl', 'opensslv.h') +- +- with open(file) as origin_file: +- for line in origin_file: +- m = re.match( +- r'^# *define *OPENSSL_VERSION_NUMBER *(0x[0-9a-fA-F]*)', +- line) +- if m: +- log.debug('found version number: %s\n', m.group(1)) +- ver = int(m.group(1), base=16) +- break +- +- if ver is None: +- raise OSError('Unknown format of file %s\n' % file) ++ try: ++ import ctypes ++ libssl = ctypes.cdll.LoadLibrary("libssl.so") ++ ver = libssl.OpenSSL_version_num() ++ log.debug("ctypes: ver = %s", hex(ver)) ++ # for OpenSSL < 1.1.0 ++ except AttributeError: ++ ver = None ++ file = os.path.join(ossldir, 'include', 'openssl', 'opensslv.h') ++ ++ with open(file) as origin_file: ++ for line in origin_file: ++ m = re.match( ++ r'^# *define *OPENSSL_VERSION_NUMBER *(0x[0-9a-fA-F]*)', ++ line) ++ if m: ++ log.debug('found version number: %s\n', m.group(1)) ++ ver = int(m.group(1), base=16) ++ break ++ ++ log.debug("parsing header file: ver = %s", hex(ver)) ++ ++ if ver is None: ++ raise OSError('Unknown format of file %s\n' % file) + + if required: + return ver >= req_ver +-- +GitLab + diff --git a/m2crypto.spec b/m2crypto.spec index 90223ee..bcb382a 100644 --- a/m2crypto.spec +++ b/m2crypto.spec @@ -10,6 +10,10 @@ License: MIT URL: https://gitlab.com/m2crypto/m2crypto/ Source0: %{pypi_source M2Crypto} +# Fix build for OpenSSL 3.0 +# From: https://gitlab.com/m2crypto/m2crypto/-/merge_requests/271 +Patch0: m2crypto-MR271-opensslversion.patch + BuildRequires: gcc BuildRequires: openssl BuildRequires: openssl-devel @@ -54,7 +58,7 @@ fi %py3_install %check -%{__python3} setup.py test +PYTHONPATH=%{buildroot}%{python3_sitearch} %{__python3} -munittest discover -v tests/ %files -n python%{python3_pkgversion}-m2crypto %doc CHANGES README.rst