|
31 | 31 | import subprocess |
32 | 32 | import shlex |
33 | 33 | import os |
| 34 | +import sys |
34 | 35 | from ctypes import cdll |
35 | 36 | from collections import namedtuple |
36 | 37 |
|
@@ -249,11 +250,38 @@ def generate_libwolfssl(): |
249 | 250 | get_platform(), version)) |
250 | 251 | make(make_flags(prefix, False)) |
251 | 252 |
|
252 | | - |
| 253 | +# detect features if user has built against local wolfSSL library |
| 254 | +# if they are not, we are controlling build options above |
253 | 255 | local_wolfssl = os.environ.get("USE_LOCAL_WOLFSSL") |
254 | | -if local_wolfssl and get_libwolfssl() == 0: |
255 | | - generate_libwolfssl() |
256 | | - get_libwolfssl() |
| 256 | +if local_wolfssl: |
| 257 | + # Try to do native wolfSSL/wolfCrypt feature detection. |
| 258 | + # Open <wolfssl/options.h> header to parse for #define's |
| 259 | + # This will throw a FileNotFoundError if not able to find options.h |
| 260 | + optionsHeaderPath = wolfssl_inc_path() + "/wolfssl/options.h" |
| 261 | + optionsHeader = open(optionsHeaderPath, 'r') |
| 262 | + optionsHeaderStr = optionsHeader.read() |
| 263 | + optionsHeader.close() |
| 264 | + # require HAVE_SNI (--enable-sni) in native lib |
| 265 | + if '#define HAVE_SNI' not in optionsHeaderStr: |
| 266 | + raise RuntimeError("wolfSSL needs to be compiled with --enable-sni") |
| 267 | + |
| 268 | + # require OPENSSL_EXTRA (--enable-opensslextra) in native lib |
| 269 | + if '#define OPENSSL_EXTRA' not in optionsHeaderStr: |
| 270 | + raise RuntimeError("wolfSSL needs to be compiled with " |
| 271 | + "--enable-opensslextra") |
| 272 | + featureDetection = 1 |
| 273 | + sys.stderr.write("\nDEBUG: Found <wolfssl/options.h>, attempting native " |
| 274 | + "feature detection\n") |
| 275 | + |
| 276 | +else: |
| 277 | + optionsHeaderStr = "" |
| 278 | + featureDetection = 0 |
| 279 | + sys.stderr.write("\nDEBUG: Skipping native feature detection, build not " |
| 280 | + "using USE_LOCAL_WOLFSSL\n") |
| 281 | + if get_libwolfssl() == 0: |
| 282 | + generate_libwolfssl() |
| 283 | + get_libwolfssl() |
| 284 | + |
257 | 285 |
|
258 | 286 | WolfFunction = namedtuple("WolfFunction", ["name", "native_sig", "ossl_sig"]) |
259 | 287 | # Depending on how wolfSSL was configured, the functions below may or may not be |
|
0 commit comments