summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2021-11-22 23:05:41 +0100
committerMatěj Cepl <mcepl@cepl.eu>2021-11-22 23:15:18 +0100
commit1a746c6d01eff4863c116e279756a1035fd5feb0 (patch)
tree8b94f61c29f6e78b0f8f3558493144d949b2bcf2
parentb8addc7ad9990d1ba3786830ebd74aa8c939849d (diff)
downloadm2crypto-1a746c6d01eff4863c116e279756a1035fd5feb0.tar.gz
Use OpenSSL_version_num() instead of unrealiable parsing of .h file.
Fixes #302
-rw-r--r--setup.py39
1 files changed, 24 insertions, 15 deletions
diff --git a/setup.py b/setup.py
index a1d58f2..04ac8c7 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