Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 0290e0a

Browse files
panvaaduh95
authored andcommitted
crypto: split OpenSSL 3, BoringSSL, and legacy backends
This separates the native crypto backend paths for OpenSSL >= 3, BoringSSL, and legacy OpenSSL. The OpenSSL >= 3 path now builds with `OPENSSL_API_COMPAT=30000` and `OPENSSL_NO_DEPRECATED`, moving normal crypto/TLS code away from APIs that OpenSSL 3.0.0 marks deprecated. BoringSSL remains on its own branch, and OpenSSL < 3 remains the legacy fallback. The exception is ENGINE support. ENGINE APIs are isolated into a dedicated compatibility target so they can remain available while the JS-facing engine APIs are runtime-deprecated in 27.x. That gives us a clear removal point for 28.x, without letting ENGINE usage leak back into the strict OpenSSL 3 path. The split also makes the eventual OpenSSL 1.1.1 removal easier to reason about. Once support for OpenSSL < 3 is dropped, the legacy branch can be removed in a focused follow-up, possibly targeting 27.x, instead of untangling mixed version guards throughout the crypto implementation. No public crypto or TLS API behavior is intentionally changed. Assisted-by: Codex:gpt-5 Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64211 Backport-PR-URL: #65087 Refs: #56733 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c7a0440 commit 0290e0a

23 files changed

Lines changed: 2477 additions & 211 deletions

β€Žcommon.gypiβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'node_module_version%': '',
2525
'node_with_ltcg%': '',
2626
'node_shared_openssl%': 'false',
27+
'openssl_is_boringssl%': 'false',
2728

2829
'node_tag%': '',
2930
'uv_library%': 'static_library',

β€Žconfigure.pyβ€Ž

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,50 +1328,72 @@ def get_gas_version(cc):
13281328
warn(f'Could not recognize `gas`: {gas_ret}')
13291329
return'0.0'
13301330

1331-
defget_openssl_version():
1331+
defget_openssl_macros(o):
1332+
"""Extract OpenSSL preprocessor macros from the configured headers."""
1333+
1334+
# Use the C compiler to extract preprocessor macros from OpenSSL headers.
1335+
# crypto.h is included because BoringSSL declares OPENSSL_IS_BORINGSSL there.
1336+
args= ['-E', '-dM',
1337+
'-include', 'openssl/opensslv.h',
1338+
'-include', 'openssl/crypto.h',
1339+
'-']
1340+
ifnotoptions.shared_openssl:
1341+
args= ['-I', 'deps/openssl/openssl/include'] +args
1342+
elifoptions.shared_openssl_includes:
1343+
args= ['-I', options.shared_openssl_includes] +args
1344+
else:
1345+
fordirino['include_dirs']:
1346+
args= ['-I', dir] +args
1347+
1348+
proc=subprocess.Popen(
1349+
shlex.split(CC) +args,
1350+
stdin=subprocess.PIPE,
1351+
stdout=subprocess.PIPE,
1352+
stderr=subprocess.PIPE
1353+
)
1354+
withproc:
1355+
proc.stdin.write(b'\n')
1356+
out=to_utf8(proc.communicate()[0])
1357+
1358+
ifproc.returncode!=0:
1359+
warn('Failed to extract OpenSSL macros from headers')
1360+
return {}
1361+
1362+
macros= {}
1363+
forlineinout.split('\n'):
1364+
ifline.startswith('#define OPENSSL_'):
1365+
parts=line.split()
1366+
iflen(parts) >=2:
1367+
macro_name=parts[1]
1368+
macro_value=parts[2] iflen(parts) >=3else'1'
1369+
macros[macro_name] =macro_value
1370+
1371+
returnmacros
1372+
1373+
defget_openssl_version(o):
13321374
"""Parse OpenSSL version from opensslv.h header file.
13331375
13341376
Returns the version as a number matching OPENSSL_VERSION_NUMBER format:
1335-
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre), L=0
1377+
0xMNN00PPSL where M=major, NN=minor, PP=patch, S=status(0xf=release,0x0=pre),
1378+
L denotes as a long type literal
13361379
"""
13371380

13381381
try:
1339-
# Use the C compiler to extract preprocessor macros from opensslv.h
1340-
args= ['-E', '-dM', '-include', 'openssl/opensslv.h', '-']
1341-
ifnotoptions.shared_openssl:
1342-
args= ['-I', 'deps/openssl/openssl/include'] +args
1343-
elifoptions.shared_openssl_includes:
1344-
args= ['-I', options.shared_openssl_includes] +args
1345-
1346-
proc=subprocess.Popen(
1347-
shlex.split(CC) +args,
1348-
stdin=subprocess.PIPE,
1349-
stdout=subprocess.PIPE,
1350-
stderr=subprocess.PIPE
1351-
)
1352-
withproc:
1353-
proc.stdin.write(b'\n')
1354-
out=to_utf8(proc.communicate()[0])
1355-
1356-
ifproc.returncode!=0:
1357-
warn('Failed to extract OpenSSL version from opensslv.h header')
1358-
return0
1359-
1360-
# Parse the macro definitions
1361-
macros= {}
1362-
forlineinout.split('\n'):
1363-
ifline.startswith('#define OPENSSL_VERSION_'):
1364-
parts=line.split()
1365-
iflen(parts) >=3:
1366-
macro_name=parts[1]
1367-
macro_value=parts[2]
1368-
macros[macro_name] =macro_value
1382+
macros=get_openssl_macros(o)
13691383

13701384
# Extract version components
13711385
major=int(macros.get('OPENSSL_VERSION_MAJOR', '0'))
13721386
minor=int(macros.get('OPENSSL_VERSION_MINOR', '0'))
13731387
patch=int(macros.get('OPENSSL_VERSION_PATCH', '0'))
13741388

1389+
# If major, minor and patch are all 0, this is probably OpenSSL < 3.
1390+
if (major, minor, patch) == (0, 0, 0):
1391+
version_number=macros.get('OPENSSL_VERSION_NUMBER')
1392+
# Prior to OpenSSL 3 the value should be in the format 0xMNN00PPSL.
1393+
# If it is, we need to strip the `L` suffix prior to parsing.
1394+
ifversion_number[:2] =="0x"andversion_number[-1] =="L":
1395+
returnint(version_number[:-1], 16)
1396+
13751397
# Check if it's a pre-release (has non-empty PRE_RELEASE string)
13761398
pre_release=macros.get('OPENSSL_VERSION_PRE_RELEASE', '""').strip('"')
13771399
status=0x0ifpre_releaseelse0xf
@@ -1387,6 +1409,13 @@ def get_openssl_version():
13871409
warn(f'Failed to determine OpenSSL version from header: {e}')
13881410
return0
13891411

1412+
defget_openssl_is_boringssl(o):
1413+
try:
1414+
returnb('OPENSSL_IS_BORINGSSL'inget_openssl_macros(o))
1415+
except (OSError, ValueError, subprocess.SubprocessError) ase:
1416+
warn(f'Failed to determine whether OpenSSL headers are BoringSSL: {e}')
1417+
return'false'
1418+
13901419
# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
13911420
# the version check more by accident than anything else but a more rigorous
13921421
# check involves checking the build number against an allowlist. I'm not
@@ -2065,7 +2094,8 @@ def without_ssl_error(option):
20652094

20662095
configure_library('openssl', o)
20672096

2068-
o['variables']['openssl_version'] =get_openssl_version()
2097+
o['variables']['openssl_version'] =get_openssl_version(o)
2098+
o['variables']['openssl_is_boringssl'] =get_openssl_is_boringssl(o)
20692099

20702100
defconfigure_sqlite(o):
20712101
o['variables']['node_use_sqlite'] =b(notoptions.without_sqlite)

β€Ždeps/ncrypto/engine.ccβ€Ž

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include"ncrypto.h"
22

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+
39
namespacencrypto {
410

511
// ============================================================================
612
// Engine
713

814
#ifndef OPENSSL_NO_ENGINE
9-
EnginePointer::EnginePointer(ENGINE* engine_, bool finish_on_exit_)
15+
EnginePointer::EnginePointer(void* engine_, bool finish_on_exit_)
1016
: engine(engine_), finish_on_exit(finish_on_exit_) {}
1117

1218
EnginePointer::EnginePointer(EnginePointer&& other) noexcept
@@ -24,21 +30,22 @@ EnginePointer& EnginePointer::operator=(EnginePointer&& other) noexcept {
2430
return *new (this) EnginePointer(std::move(other));
2531
}
2632

27-
voidEnginePointer::reset(ENGINE* engine_, bool finish_on_exit_) {
33+
voidEnginePointer::reset(void* engine_, bool finish_on_exit_) {
2834
if (engine != nullptr) {
35+
ENGINE* current = static_cast<ENGINE*>(engine);
2936
if (finish_on_exit) {
3037
// This also does the equivalent of ENGINE_free.
31-
ENGINE_finish(engine);
38+
ENGINE_finish(current);
3239
} else {
33-
ENGINE_free(engine);
40+
ENGINE_free(current);
3441
}
3542
}
3643
engine = engine_;
3744
finish_on_exit = finish_on_exit_;
3845
}
3946

40-
ENGINE* EnginePointer::release() {
41-
ENGINE* ret = engine;
47+
void* EnginePointer::release() {
48+
void* ret = engine;
4249
engine = nullptr;
4350
finish_on_exit = false;
4451
return ret;
@@ -52,8 +59,9 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
5259
// Engine not found, try loading dynamically.
5360
engine = EnginePointer(ENGINE_by_id("dynamic"));
5461
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)) {
5765
engine.reset();
5866
}
5967
}
@@ -64,19 +72,24 @@ EnginePointer EnginePointer::getEngineByName(const char* name,
6472
boolEnginePointer::setAsDefault(uint32_t flags, CryptoErrorList* errors) {
6573
if (engine == nullptr) returnfalse;
6674
ClearErrorOnReturn clear_error_on_return(errors);
67-
returnENGINE_set_default(engine, flags) != 0;
75+
returnENGINE_set_default(static_cast<ENGINE*>(engine), flags) != 0;
6876
}
6977

7078
boolEnginePointer::init(bool finish_on_exit) {
7179
if (engine == nullptr) returnfalse;
7280
if (finish_on_exit) setFinishOnExit();
73-
returnENGINE_init(engine) == 1;
81+
returnENGINE_init(static_cast<ENGINE*>(engine)) == 1;
7482
}
7583

7684
EVPKeyPointer EnginePointer::loadPrivateKey(constchar* key_name) {
7785
if (engine == nullptr) returnEVPKeyPointer();
78-
returnEVPKeyPointer(
79-
ENGINE_load_private_key(engine, key_name, nullptr, nullptr));
86+
returnEVPKeyPointer(ENGINE_load_private_key(
87+
static_cast<ENGINE*>(engine), key_name, nullptr, nullptr));
88+
}
89+
90+
boolEnginePointer::setClientCertEngine(SSL_CTX* ctx) {
91+
if (engine == nullptr || ctx == nullptr) returnfalse;
92+
returnSSL_CTX_set_client_cert_engine(ctx, static_cast<ENGINE*>(engine)) == 1;
8093
}
8194

8295
voidEnginePointer::initEnginesOnce() {

0 commit comments

Comments
Β (0)