-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
193 lines (158 loc) · 8.19 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import sys
from os.path import join
from platform import architecture
from sys import platform
from nassl import __author__, __version__
from setuptools import setup, Extension
SHOULD_BUILD_FOR_DEBUG = False
if platform == 'win32':
# If we want to build debug builds on Windows (with symbols etc); does not do anything on other platforms
SHOULD_BUILD_FOR_DEBUG = False
_ROOT_BUILD_PATH = os.path.join(os.path.dirname(__file__), 'bin')
# TODO(AD): Switch to an enum after dropping support for Python 2
class SupportedPlatformEnum(object):
"""Platforms supported by nassl.
"""
OSX_64 = 1
LINUX_64 = 2
LINUX_32 = 3
WINDOWS_32 = 4
WINDOWS_64 = 5
OPENBSD_64 = 6
FREEBSD_64 = 7
CURRENT_PLATFORM = None
if architecture()[0] == '64bit':
if platform == 'darwin':
CURRENT_PLATFORM = SupportedPlatformEnum.OSX_64
elif platform in ['linux', 'linux2']:
CURRENT_PLATFORM = SupportedPlatformEnum.LINUX_64
elif platform == 'win32':
CURRENT_PLATFORM = SupportedPlatformEnum.WINDOWS_64
elif platform == 'openbsd5':
CURRENT_PLATFORM = SupportedPlatformEnum.OPENBSD_64
elif platform in ['freebsd10', 'freebsd11']:
CURRENT_PLATFORM = SupportedPlatformEnum.FREEBSD_64
elif architecture()[0] == '32bit':
if platform in ['linux', 'linux2']:
CURRENT_PLATFORM = SupportedPlatformEnum.LINUX_32
elif platform == 'win32':
CURRENT_PLATFORM = SupportedPlatformEnum.WINDOWS_32
LEGACY_OPENSSL_INSTALL_PATH_DICT = {
# Need full paths (hence the getcwd()) as they get passed to OpenSSL in build_from_scratch.py
SupportedPlatformEnum.OSX_64: join(_ROOT_BUILD_PATH, 'openssl-legacy', 'darwin64'),
SupportedPlatformEnum.LINUX_64: join(_ROOT_BUILD_PATH, 'openssl-legacy', 'linux64'),
SupportedPlatformEnum.LINUX_32: join(_ROOT_BUILD_PATH, 'openssl-legacy', 'linux32'),
SupportedPlatformEnum.WINDOWS_32: join(_ROOT_BUILD_PATH, 'openssl-legacy', 'win32'),
SupportedPlatformEnum.WINDOWS_64: join(_ROOT_BUILD_PATH, 'openssl-legacy', 'win64'),
SupportedPlatformEnum.OPENBSD_64: join(_ROOT_BUILD_PATH, 'openssl-legacy', 'openbsd64'),
SupportedPlatformEnum.FREEBSD_64: join(_ROOT_BUILD_PATH, 'openssl-legacy', 'freebsd64'),
}
MODERN_OPENSSL_INSTALL_PATH_DICT = {
SupportedPlatformEnum.OSX_64: join(_ROOT_BUILD_PATH, 'openssl-modern', 'darwin64'),
SupportedPlatformEnum.LINUX_64: join(_ROOT_BUILD_PATH, 'openssl-modern', 'linux64'),
SupportedPlatformEnum.LINUX_32: join(_ROOT_BUILD_PATH, 'openssl-modern', 'linux32'),
SupportedPlatformEnum.WINDOWS_32: join(_ROOT_BUILD_PATH, 'openssl-modern', 'win32'),
SupportedPlatformEnum.WINDOWS_64: join(_ROOT_BUILD_PATH, 'openssl-modern', 'win64'),
SupportedPlatformEnum.OPENBSD_64: join(_ROOT_BUILD_PATH, 'openssl-modern', 'openbsd64'),
SupportedPlatformEnum.FREEBSD_64: join(_ROOT_BUILD_PATH, 'openssl-modern', 'freebsd64'),
}
ZLIB_INSTALL_PATH_DICT = {
SupportedPlatformEnum.OSX_64: join(_ROOT_BUILD_PATH, 'zlib', 'darwin64', 'libz.a'),
SupportedPlatformEnum.LINUX_64: join(_ROOT_BUILD_PATH, 'zlib', 'linux64', 'libz.a'),
SupportedPlatformEnum.LINUX_32: join(_ROOT_BUILD_PATH, 'zlib', 'linux32', 'libz.a'),
SupportedPlatformEnum.WINDOWS_32: join(_ROOT_BUILD_PATH, 'zlib', 'win32', 'zlibstat.lib'),
SupportedPlatformEnum.WINDOWS_64: join(_ROOT_BUILD_PATH, 'zlib', 'win64', 'zlibstat.lib'),
SupportedPlatformEnum.OPENBSD_64: join(_ROOT_BUILD_PATH, 'zlib', 'openbsd64', 'libz.a'),
SupportedPlatformEnum.FREEBSD_64: join(_ROOT_BUILD_PATH, 'zlib', 'freebsd64', 'libz.a'),
}
LEGACY_OPENSSL_LIB_INSTALL_PATH = LEGACY_OPENSSL_INSTALL_PATH_DICT[CURRENT_PLATFORM]
LEGACY_OPENSSL_HEADERS_INSTALL_PATH = join(_ROOT_BUILD_PATH, 'openssl-legacy', 'include')
MODERN_OPENSSL_LIB_INSTALL_PATH = MODERN_OPENSSL_INSTALL_PATH_DICT[CURRENT_PLATFORM]
MODERN_OPENSSL_HEADERS_INSTALL_PATH = join(_ROOT_BUILD_PATH, 'openssl-modern', 'include')
ZLIB_LIB_INSTALL_PATH = ZLIB_INSTALL_PATH_DICT[CURRENT_PLATFORM]
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 2.7 / 3.4+ and SSLyze.',
'extras_require': {':python_version < "3.4"': ['enum34'],
':python_version < "3.5"': ['typing']},
'author': __author__,
'author_email': '[email protected]',
'url': 'https://github.com/nabla-c0d3/nassl',
'test_suite': 'nose.collector',
'tests_require': ['nose'],
}
# 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 = join(os.path.dirname(sys.executable), 'libs')
BASE_NASSL_EXT_SETUP.update({
'library_dirs': [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_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')]
MODERN_NASSL_EXT_SETUP = BASE_NASSL_EXT_SETUP.copy()
MODERN_NASSL_EXT_SETUP['name'] = 'nassl._nassl'
if CURRENT_PLATFORM in [SupportedPlatformEnum.WINDOWS_32, SupportedPlatformEnum.WINDOWS_64]:
LEGACY_NASSL_EXT_SETUP.update({
'include_dirs': [LEGACY_OPENSSL_HEADERS_INSTALL_PATH],
'extra_objects': [ZLIB_LIB_INSTALL_PATH,
join(LEGACY_OPENSSL_LIB_INSTALL_PATH, 'libeay32.lib'),
join(LEGACY_OPENSSL_LIB_INSTALL_PATH, 'ssleay32.lib')],
})
MODERN_NASSL_EXT_SETUP.update({
'include_dirs': [MODERN_OPENSSL_HEADERS_INSTALL_PATH],
'extra_objects': [ZLIB_LIB_INSTALL_PATH,
join(MODERN_OPENSSL_LIB_INSTALL_PATH, 'libcrypto.lib'),
join(MODERN_OPENSSL_LIB_INSTALL_PATH, 'libssl.lib')],
})
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.update({
'include_dirs': [LEGACY_OPENSSL_HEADERS_INSTALL_PATH, join('nassl', '_nassl')],
'extra_objects': [join(LEGACY_OPENSSL_LIB_INSTALL_PATH, 'libssl.a'),
join(LEGACY_OPENSSL_LIB_INSTALL_PATH, 'libcrypto.a'),
ZLIB_LIB_INSTALL_PATH]
})
MODERN_NASSL_EXT_SETUP.update({
'include_dirs': [MODERN_OPENSSL_HEADERS_INSTALL_PATH, join('nassl', '_nassl')],
'extra_objects': [join(MODERN_OPENSSL_LIB_INSTALL_PATH, 'libssl.a'),
join(MODERN_OPENSSL_LIB_INSTALL_PATH, 'libcrypto.a'),
ZLIB_LIB_INSTALL_PATH]
})
NASSL_SETUP.update({'ext_modules': [Extension(**LEGACY_NASSL_EXT_SETUP), Extension(**MODERN_NASSL_EXT_SETUP)]})
if __name__ == "__main__":
setup(**NASSL_SETUP)