forked from nabla-c0d3/nassl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
102 lines (85 loc) · 3.97 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import sys
from pathlib import Path
from build_tasks import ModernOpenSslBuildConfig, ZlibBuildConfig, LegacyOpenSslBuildConfig, SupportedPlatformEnum, \
CURRENT_PLATFORM
from nassl import __author__, __version__
from setuptools import setup, Extension
SHOULD_BUILD_FOR_DEBUG = False
NASSL_SETUP = {
'name': "nassl",
'version': __version__,
'package_dir': {'nassl': 'nassl'},
'py_modules': ['nassl.__init__', 'nassl.ssl_client', 'nassl.legacy_ssl_client',
'nassl.ocsp_response'],
'description': 'Experimental OpenSSL wrapper for Python 3.6+ and SSLyze.',
'author': __author__,
'author_email': 'nabla.c0d3@gmail.com',
'url': 'https://github.com/nabla-c0d3/nassl',
'python_requires': '>=3.6',
}
# There are two native extensions: the "legacy" OpenSSL one and the "modern" OpenSSL one
BASE_NASSL_EXT_SETUP = {
'extra_compile_args': [],
'extra_link_args': [],
'sources': ["nassl/_nassl/nassl.c", "nassl/_nassl/nassl_SSL_CTX.c", "nassl/_nassl/nassl_SSL.c",
"nassl/_nassl/nassl_X509.c", "nassl/_nassl/nassl_errors.c", "nassl/_nassl/nassl_BIO.c",
"nassl/_nassl/nassl_X509_EXTENSION.c", "nassl/_nassl/nassl_X509_NAME_ENTRY.c",
"nassl/_nassl/nassl_SSL_SESSION.c", "nassl/_nassl/openssl_utils.c",
"nassl/_nassl/nassl_OCSP_RESPONSE.c", "nassl/_nassl/python_utils.c"],
}
if CURRENT_PLATFORM in [SupportedPlatformEnum.WINDOWS_32, SupportedPlatformEnum.WINDOWS_64]:
# Build using the Python that was used to run this script; will not work for cross-compiling
PYTHON_LIBS_PATH = Path(sys.executable).parent / 'libs'
BASE_NASSL_EXT_SETUP.update({
'library_dirs': [str(PYTHON_LIBS_PATH)],
'libraries': ['user32', 'kernel32', 'Gdi32', 'Advapi32', 'Ws2_32', 'crypt32',]
})
else:
BASE_NASSL_EXT_SETUP['extra_compile_args'].append('-Wall')
if CURRENT_PLATFORM == SupportedPlatformEnum.LINUX_64:
# Explicitly disable executable stack on Linux 64 to address issues with Ubuntu on Windows
# https://github.com/nabla-c0d3/nassl/issues/28
BASE_NASSL_EXT_SETUP['extra_link_args'].append('-Wl,-z,noexecstack')
legacy_openssl_config = LegacyOpenSslBuildConfig(CURRENT_PLATFORM)
modern_openssl_config = ModernOpenSslBuildConfig(CURRENT_PLATFORM)
zlib_config = ZlibBuildConfig(CURRENT_PLATFORM)
LEGACY_NASSL_EXT_SETUP = BASE_NASSL_EXT_SETUP.copy()
LEGACY_NASSL_EXT_SETUP['name'] = 'nassl._nassl_legacy'
LEGACY_NASSL_EXT_SETUP['define_macros'] = [('LEGACY_OPENSSL', '1')]
LEGACY_NASSL_EXT_SETUP.update({
'include_dirs': [str(legacy_openssl_config.include_path)],
'extra_objects': [
# The order matters on some flavors of Linux
str(legacy_openssl_config.libssl_path),
str(legacy_openssl_config.libcrypto_path),
str(zlib_config.libz_path),
],
})
MODERN_NASSL_EXT_SETUP = BASE_NASSL_EXT_SETUP.copy()
MODERN_NASSL_EXT_SETUP['name'] = 'nassl._nassl'
MODERN_NASSL_EXT_SETUP.update({
'include_dirs': [str(modern_openssl_config.include_path)],
'extra_objects': [
# The order matters on some flavors of Linux
str(modern_openssl_config.libssl_path),
str(modern_openssl_config.libcrypto_path),
str(zlib_config.libz_path),
],
})
if CURRENT_PLATFORM in [SupportedPlatformEnum.WINDOWS_32, SupportedPlatformEnum.WINDOWS_64]:
if SHOULD_BUILD_FOR_DEBUG:
LEGACY_NASSL_EXT_SETUP.update({
'extra_compile_args': ['/Zi'],
'extra_link_args': ['/DEBUG'],
})
MODERN_NASSL_EXT_SETUP.update({
'extra_compile_args': ['/Zi'],
'extra_link_args': ['/DEBUG'],
})
else:
# Add arguments specific to Unix builds
LEGACY_NASSL_EXT_SETUP['include_dirs'].append(str(Path('nassl') / '_nassl'))
MODERN_NASSL_EXT_SETUP['include_dirs'].append(str(Path('nassl') / '_nassl'))
NASSL_SETUP.update({'ext_modules': [Extension(**LEGACY_NASSL_EXT_SETUP), Extension(**MODERN_NASSL_EXT_SETUP)]})
if __name__ == "__main__":
setup(**NASSL_SETUP)