|
|
ef5b8a2 |
From 1a746c6d01eff4863c116e279756a1035fd5feb0 Mon Sep 17 00:00:00 2001
|
|
|
ef5b8a2 |
From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= <mcepl@cepl.eu>
|
|
|
ef5b8a2 |
Date: Mon, 22 Nov 2021 23:05:41 +0100
|
|
|
ef5b8a2 |
Subject: [PATCH] Use OpenSSL_version_num() instead of unrealiable parsing of
|
|
|
ef5b8a2 |
.h file.
|
|
|
ef5b8a2 |
|
|
|
ef5b8a2 |
Fixes #302
|
|
|
ef5b8a2 |
---
|
|
|
ef5b8a2 |
setup.py | 39 ++++++++++++++++++++++++---------------
|
|
|
ef5b8a2 |
1 file changed, 24 insertions(+), 15 deletions(-)
|
|
|
ef5b8a2 |
|
|
|
ef5b8a2 |
diff --git a/setup.py b/setup.py
|
|
|
ef5b8a2 |
index a1d58f25..04ac8c77 100644
|
|
|
ef5b8a2 |
--- a/setup.py
|
|
|
ef5b8a2 |
+++ b/setup.py
|
|
|
ef5b8a2 |
@@ -75,21 +75,30 @@ def openssl_version(ossldir, req_ver, required=False):
|
|
|
ef5b8a2 |
:return: Boolean indicating whether the satisfying version of
|
|
|
ef5b8a2 |
OpenSSL has been installed.
|
|
|
ef5b8a2 |
"""
|
|
|
ef5b8a2 |
- ver = None
|
|
|
ef5b8a2 |
- file = os.path.join(ossldir, 'include', 'openssl', 'opensslv.h')
|
|
|
ef5b8a2 |
-
|
|
|
ef5b8a2 |
- with open(file) as origin_file:
|
|
|
ef5b8a2 |
- for line in origin_file:
|
|
|
ef5b8a2 |
- m = re.match(
|
|
|
ef5b8a2 |
- r'^# *define *OPENSSL_VERSION_NUMBER *(0x[0-9a-fA-F]*)',
|
|
|
ef5b8a2 |
- line)
|
|
|
ef5b8a2 |
- if m:
|
|
|
ef5b8a2 |
- log.debug('found version number: %s\n', m.group(1))
|
|
|
ef5b8a2 |
- ver = int(m.group(1), base=16)
|
|
|
ef5b8a2 |
- break
|
|
|
ef5b8a2 |
-
|
|
|
ef5b8a2 |
- if ver is None:
|
|
|
ef5b8a2 |
- raise OSError('Unknown format of file %s\n' % file)
|
|
|
ef5b8a2 |
+ try:
|
|
|
ef5b8a2 |
+ import ctypes
|
|
|
ef5b8a2 |
+ libssl = ctypes.cdll.LoadLibrary("libssl.so")
|
|
|
ef5b8a2 |
+ ver = libssl.OpenSSL_version_num()
|
|
|
ef5b8a2 |
+ log.debug("ctypes: ver = %s", hex(ver))
|
|
|
ef5b8a2 |
+ # for OpenSSL < 1.1.0
|
|
|
ef5b8a2 |
+ except AttributeError:
|
|
|
ef5b8a2 |
+ ver = None
|
|
|
ef5b8a2 |
+ file = os.path.join(ossldir, 'include', 'openssl', 'opensslv.h')
|
|
|
ef5b8a2 |
+
|
|
|
ef5b8a2 |
+ with open(file) as origin_file:
|
|
|
ef5b8a2 |
+ for line in origin_file:
|
|
|
ef5b8a2 |
+ m = re.match(
|
|
|
ef5b8a2 |
+ r'^# *define *OPENSSL_VERSION_NUMBER *(0x[0-9a-fA-F]*)',
|
|
|
ef5b8a2 |
+ line)
|
|
|
ef5b8a2 |
+ if m:
|
|
|
ef5b8a2 |
+ log.debug('found version number: %s\n', m.group(1))
|
|
|
ef5b8a2 |
+ ver = int(m.group(1), base=16)
|
|
|
ef5b8a2 |
+ break
|
|
|
ef5b8a2 |
+
|
|
|
ef5b8a2 |
+ log.debug("parsing header file: ver = %s", hex(ver))
|
|
|
ef5b8a2 |
+
|
|
|
ef5b8a2 |
+ if ver is None:
|
|
|
ef5b8a2 |
+ raise OSError('Unknown format of file %s\n' % file)
|
|
|
ef5b8a2 |
|
|
|
ef5b8a2 |
if required:
|
|
|
ef5b8a2 |
return ver >= req_ver
|
|
|
ef5b8a2 |
--
|
|
|
ef5b8a2 |
GitLab
|
|
|
ef5b8a2 |
|