| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d2c8acd commit 195f103
23 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ | |||
| 24 | 24 | 'node_module_version%': '', | |
| 25 | 25 | 'node_with_ltcg%': '', | |
| 26 | 26 | 'node_shared_openssl%': 'false', | |
| 27 | + 'openssl_is_boringssl%': 'false', | ||
| 27 | 28 | ||
| 28 | 29 | 'node_tag%': '', | |
| 29 | 30 | 'uv_library%': 'static_library', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1434,6 +1434,48 @@ def get_gas_version(cc): | |||
| 1434 | 1434 | warn(f'Could not recognize `gas`: {gas_ret}') | |
| 1435 | 1435 | return '0.0' | |
| 1436 | 1436 | ||
| 1437 | + def get_openssl_macros(o): | ||
| 1438 | + """Extract OpenSSL preprocessor macros from the configured headers.""" | ||
| 1439 | + | ||
| 1440 | + # Use the C compiler to extract preprocessor macros from OpenSSL headers. | ||
| 1441 | + # crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there. | ||
| 1442 | + args = ['-E', '-dM', | ||
| 1443 | + '-include', 'openssl/opensslv.h', | ||
| 1444 | + '-include', 'openssl/crypto.h', | ||
| 1445 | + '-'] | ||
| 1446 | + if not options.shared_openssl: | ||
| 1447 | + args = ['-I', 'deps/openssl/openssl/include'] + args | ||
| 1448 | + elif options.shared_openssl_includes: | ||
| 1449 | + args = ['-I', options.shared_openssl_includes] + args | ||
| 1450 | + else: | ||
| 1451 | + for dir in o['include_dirs']: | ||
| 1452 | + args = ['-I', dir] + args | ||
| 1453 | + | ||
| 1454 | + proc = subprocess.Popen( | ||
| 1455 | + shlex.split(CC) + args, | ||
| 1456 | + stdin=subprocess.PIPE, | ||
| 1457 | + stdout=subprocess.PIPE, | ||
| 1458 | + stderr=subprocess.PIPE | ||
| 1459 | + ) | ||
| 1460 | + with proc: | ||
| 1461 | + proc.stdin.write(b'\n') | ||
| 1462 | + out = to_utf8(proc.communicate()[0]) | ||
| 1463 | + | ||
| 1464 | + if proc.returncode != 0: | ||
| 1465 | + warn('Failed to extract OpenSSL macros from headers') | ||
| 1466 | + return {} | ||
| 1467 | + | ||
| 1468 | + macros = {} | ||
| 1469 | + for line in out.split('\n'): | ||
| 1470 | + if line.startswith('#define OPENSSL_'): | ||
| 1471 | + parts = line.split() | ||
| 1472 | + if len(parts) >= 2: | ||
| 1473 | + macro_name = parts[1] | ||
| 1474 | + macro_value = parts[2] if len(parts) >= 3 else '1' | ||
| 1475 | + macros[macro_name] = macro_value | ||
| 1476 | + | ||
| 1477 | + return macros | ||
| 1478 | + | ||
| 1437 | 1479 | def get_openssl_version(o): | |
| 1438 | 1480 | """Parse OpenSSL version from opensslv.h header file. | |
| 1439 | 1481 | ||
@@ -1443,39 +1485,7 @@ def get_openssl_version(o): | |||
| 1443 | 1485 | """ | |
| 1444 | 1486 | ||
| 1445 | 1487 | try: | |
| 1446 | - # Use the C compiler to extract preprocessor macros from opensslv.h | ||
| 1447 | - args = ['-E', '-dM', '-include', 'openssl/opensslv.h', '-'] | ||
| 1448 | - if not options.shared_openssl: | ||
| 1449 | - args = ['-I', 'deps/openssl/openssl/include'] + args | ||
| 1450 | - elif options.shared_openssl_includes: | ||
| 1451 | - args = ['-I', options.shared_openssl_includes] + args | ||
| 1452 | - else: | ||
| 1453 | - for dir in o['include_dirs']: | ||
| 1454 | - args = ['-I', dir] + args | ||
| 1455 | - | ||
| 1456 | - proc = subprocess.Popen( | ||
| 1457 | - shlex.split(CC) + args, | ||
| 1458 | - stdin=subprocess.PIPE, | ||
| 1459 | - stdout=subprocess.PIPE, | ||
| 1460 | - stderr=subprocess.PIPE | ||
| 1461 | - ) | ||
| 1462 | - with proc: | ||
| 1463 | - proc.stdin.write(b'\n') | ||
| 1464 | - out = to_utf8(proc.communicate()[0]) | ||
| 1465 | - | ||
| 1466 | - if proc.returncode != 0: | ||
| 1467 | - warn('Failed to extract OpenSSL version from opensslv.h header') | ||
| 1468 | - return 0 | ||
| 1469 | - | ||
| 1470 | - # Parse the macro definitions | ||
| 1471 | - macros = {} | ||
| 1472 | - for line in out.split('\n'): | ||
| 1473 | - if line.startswith('#define OPENSSL_VERSION_'): | ||
| 1474 | - parts = line.split() | ||
| 1475 | - if len(parts) >= 3: | ||
| 1476 | - macro_name = parts[1] | ||
| 1477 | - macro_value = parts[2] | ||
| 1478 | - macros[macro_name] = macro_value | ||
| 1488 | + macros = get_openssl_macros(o) | ||
| 1479 | 1489 | ||
| 1480 | 1490 | # Extract version components | |
| 1481 | 1491 | major = int(macros.get('OPENSSL_VERSION_MAJOR', '0')) | |
@@ -1505,6 +1515,13 @@ def get_openssl_version(o): | |||
| 1505 | 1515 | warn(f'Failed to determine OpenSSL version from header: {e}') | |
| 1506 | 1516 | return 0 | |
| 1507 | 1517 | ||
| 1518 | + def get_openssl_is_boringssl(o): | ||
| 1519 | + try: | ||
| 1520 | + return b('OPENSSL_IS_BORINGSSL' in get_openssl_macros(o)) | ||
| 1521 | + except (OSError, ValueError, subprocess.SubprocessError) as e: | ||
| 1522 | + warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}') | ||
| 1523 | + return 'false' | ||
| 1524 | + | ||
| 1508 | 1525 | def get_cargo_version(cargo): | |
| 1509 | 1526 | try: | |
| 1510 | 1527 | proc = subprocess.Popen(shlex.split(cargo) + ['--version'], | |
@@ -2309,6 +2326,7 @@ def without_ssl_error(option): | |||
| 2309 | 2326 | configure_library('openssl', o) | |
| 2310 | 2327 | ||
| 2311 | 2328 | o['variables']['openssl_version'] = get_openssl_version(o) | |
| 2329 | + o['variables']['openssl_is_boringssl'] = get_openssl_is_boringssl(o) | ||
| 2312 | 2330 | ||
| 2313 | 2331 | def configure_lief(o): | |
| 2314 | 2332 | if options.without_lief: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,18 @@ | |||
| 1 | 1 | #include "ncrypto.h" | |
| 2 | 2 | ||
| 3 | + #if !defined(OPENSSL_NO_ENGINE) && \ | ||
| 4 | + ((defined(NCRYPTO_ENGINE_COMPAT) && NCRYPTO_ENGINE_COMPAT) || \ | ||
| 5 | + NCRYPTO_USE_LEGACY_OPENSSL) | ||
| 6 | + #include <openssl/engine.h> | ||
| 7 | + #endif | ||
| 8 | + | ||
| 3 | 9 | namespace ncrypto { | |
| 4 | 10 | ||
| 5 | 11 | // ============================================================================ | |
| 6 | 12 | // Engine | |
| 7 | 13 | ||
| 8 | 14 | #ifndef OPENSSL_NO_ENGINE | |
| 9 | - EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_) | ||
| 15 | + EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_) | ||
| 10 | 16 | : engine(engine_), finish_on_exit(finish_on_exit_) {} | |
| 11 | 17 | ||
| 12 | 18 | EnginePointer::EnginePointer(EnginePointer&& other) noexcept | |
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept { | |||
| 24 | 30 | return *new (this) EnginePointer(std::move(other)); | |
| 25 | 31 | } | |
| 26 | 32 | ||
| 27 | - void EnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) { | ||
| 33 | + void EnginePointer::reset(void* engine_, bool finish_on_exit_) { | ||
| 28 | 34 | if (engine != nullptr) { | |
| 35 | + ENGINE* current = static_cast<ENGINE*>(engine); | ||
| 29 | 36 | if (finish_on_exit) { | |
| 30 | 37 | // This also does the equivalent of ENGINE_free. | |
| 31 | - ENGINE_finish(engine); | ||
| 38 | + ENGINE_finish(current); | ||
| 32 | 39 | } else { | |
| 33 | - ENGINE_free(engine); | ||
| 40 | + ENGINE_free(current); | ||
| 34 | 41 | } | |
| 35 | 42 | } | |
| 36 | 43 | engine = engine_; | |
| 37 | 44 | finish_on_exit = finish_on_exit_; | |
| 38 | 45 | } | |
| 39 | 46 | ||
| 40 | - ENGINE* EnginePointer::release() { | ||
| 41 | - ENGINE* ret = engine; | ||
| 47 | + void* EnginePointer::release() { | ||
| 48 | + void* ret = engine; | ||
| 42 | 49 | engine = nullptr; | |
| 43 | 50 | finish_on_exit = false; | |
| 44 | 51 | return ret; | |
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name, | |||
| 52 | 59 | // Engine not found, try loading dynamically. | |
| 53 | 60 | engine = EnginePointer(ENGINE_by_id("dynamic")); | |
| 54 | 61 | if (engine) { | |
| 55 | - if (!ENGINE_ctrl_cmd_string(engine.get(), "SO_PATH", name, 0) || | ||
| 56 | - !ENGINE_ctrl_cmd_string(engine.get(), "LOAD", nullptr, 0)) { | ||
| 62 | + ENGINE* current = static_cast<ENGINE*>(engine.engine); | ||
| 63 | + if (!ENGINE_ctrl_cmd_string(current, "SO_PATH", name, 0) || | ||
| 64 | + !ENGINE_ctrl_cmd_string(current, "LOAD", nullptr, 0)) { | ||
| 57 | 65 | engine.reset(); | |
| 58 | 66 | } | |
| 59 | 67 | } | |
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name, | |||
| 64 | 72 | bool EnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) { | |
| 65 | 73 | if (engine == nullptr) return false; | |
| 66 | 74 | ClearErrorOnReturn clear_error_on_return(errors); | |
| 67 | - return ENGINE_set_default(engine, flags) != 0; | ||
| 75 | + return ENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0; | ||
| 68 | 76 | } | |
| 69 | 77 | ||
| 70 | 78 | bool EnginePointer::init(bool finish_on_exit) { | |
| 71 | 79 | if (engine == nullptr) return false; | |
| 72 | 80 | if (finish_on_exit) setFinishOnExit(); | |
| 73 | - return ENGINE_init(engine) == 1; | ||
| 81 | + return ENGINE_init(static_cast<ENGINE*>(engine)) == 1; | ||
| 74 | 82 | } | |
| 75 | 83 | ||
| 76 | 84 | EVPKeyPointer EnginePointer::loadPrivateKey(const char* key_name) { | |
| 77 | 85 | if (engine == nullptr) return EVPKeyPointer(); | |
| 78 | - return EVPKeyPointer( | ||
| 79 | - ENGINE_load_private_key(engine, key_name, nullptr, nullptr)); | ||
| 86 | + return EVPKeyPointer(ENGINE_load_private_key( | ||
| 87 | + static_cast<ENGINE*>(engine), key_name, nullptr, nullptr)); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + bool EnginePointer::setClientCertEngine(SSL_CTX* ctx) { | ||
| 91 | + if (engine == nullptr || ctx == nullptr) return false; | ||
| 92 | + return SSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1; | ||
| 80 | 93 | } | |
| 81 | 94 | ||
| 82 | 95 | void EnginePointer::initEnginesOnce() { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments