Skip to content

Commit 5e910fc

Browse files
committed
deps: update OpenSSL build config to support compression
1 parent 2b74812 commit 5e910fc

8 files changed

Lines changed: 52 additions & 19 deletions

File tree

deps/openssl/config/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ CC = gcc
2121
FAKE_GCC = ../config/fake_gcc.pl
2222

2323
CONFIGURE = ./Configure
24-
# no-comp: against CRIME attack
2524
# no-shared: openssl-cli needs static link
2625
# no-afalgeng: old Linux kernel < 4.0 does not support it
2726
# enable-ssl-trace: cause the optional SSL_trace API to be built
28-
COPTS = no-comp no-shared no-afalgeng enable-ssl-trace enable-fips
27+
# zlib/brotli/zstd: enable compression libraries for TLS certificate
28+
# compression (RFC 8879). Record compression remains disabled at runtime
29+
# via SSL_OP_NO_COMPRESSION and sk_SSL_COMP_zero() in crypto_util.cc.
30+
# Include paths point to Node's bundled deps (relative to openssl/).
31+
COPTS = no-shared no-afalgeng enable-ssl-trace enable-fips \
32+
zlib --with-zlib-include=../../zlib \
33+
enable-brotli --with-brotli-include=../../brotli/c/include \
34+
enable-zstd --with-zstd-include=../../zstd/lib
2935

3036
# disable platform check in Configure
3137
NO_WARN_ENV = CONFIGURE_CHECKER_WARN=1

deps/openssl/config/generate_gypi.pl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@
285285
$target{'lib_cppflags'} =~ s/-D//g;
286286
my @lib_cppflags = split(/ /, $target{'lib_cppflags'});
287287

288+
# Strip library flags for deps provided via GYP dependencies.
289+
# zlib, brotli, and zstd are bundled in deps/ with proper GYP targets,
290+
# so we must not link against system shared libraries.
291+
$target{ex_libs} =~ s/-l(?:z|brotlienc|brotlidec|brotlicommon|zstd)\b//g;
292+
$target{ex_libs} =~ s/\s+/ /g;
293+
$target{ex_libs} =~ s/^\s+|\s+$//g;
294+
295+
# Filter out bare ZLIB/BROTLI/ZSTD defines added by Configure for compression
296+
# support. These are internal to OpenSSL and clash with identifiers in
297+
# Node.js source (e.g. ZLIB in async_wrap.h) when propagated via
298+
# direct_dependent_settings. They are kept in the main defines for OpenSSL's
299+
# own compilation but excluded from the exported defines.
300+
my @config_defines_exported = grep { $_ !~ /^(?:ZLIB|BROTLI|ZSTD)$/ } @{$config{defines}};
301+
my @target_defines_exported = grep { $_ !~ /^(?:ZLIB|BROTLI|ZSTD)$/ } @{$target{defines}};
302+
288303
my @cflags = ();
289304
push(@cflags, @{$config{'cflags'}});
290305
push(@cflags, @{$config{'CFLAGS'}});
@@ -315,6 +330,8 @@
315330
arch => \$arch,
316331
lib_cppflags => \@lib_cppflags,
317332
is_win => \$is_win,
333+
config_defines_exported => \@config_defines_exported,
334+
target_defines_exported => \@target_defines_exported,
318335
});
319336

320337
open(GYPI, "> ./archs/$arch/$asm/openssl.gypi");

deps/openssl/config/openssl.gypi.tmpl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ foreach $src (@libcrypto_srcs) {
2626
}
2727
foreach $define (@{$config{lib_defines}}) {
2828
$OUT .= " '$define',\n";
29+
} -%% ],
30+
'openssl_defines_exported_%%-$arch-%%': [
31+
%%- foreach $define (@config_defines_exported) {
32+
$OUT .= " '$define',\n";
33+
}
34+
foreach $define (@lib_cppflags) {
35+
$OUT .= " '$define',\n";
36+
}
37+
foreach $define (@target_defines_exported) {
38+
$OUT .= " '$define',\n";
39+
}
40+
foreach $define (@{lib_defines}) {
41+
$OUT .= " '$define',\n";
42+
}
43+
foreach $define (@{$config{lib_defines}}) {
44+
$OUT .= " '$define',\n";
2945
} -%% ],
3046
'openssl_cflags_%%-$arch-%%': [
3147
%%- foreach $cflag (@cflags) {
@@ -50,6 +66,6 @@ foreach $src (@libcrypto_srcs) {
5066
'sources': ['<@(openssl_sources)', '<@(openssl_sources_%%-$arch-%%)'],
5167
'direct_dependent_settings': {
5268
'include_dirs': ['./include', '.'],
53-
'defines': ['<@(openssl_defines_%%-$arch-%%)'],
69+
'defines': ['<@(openssl_defines_exported_%%-$arch-%%)'],
5470
},
5571
}

deps/openssl/openssl.gyp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
{
2020
'target_name': 'openssl',
2121
'type': '<(library)',
22+
'dependencies': [
23+
'../zlib/zlib.gyp:zlib',
24+
'../brotli/brotli.gyp:brotli',
25+
'../zstd/zstd.gyp:zstd',
26+
],
2227
'includes': ['./openssl_common.gypi'],
2328
'defines': [
2429
# Compile out hardware engines. Most are stubs that dynamically load

deps/openssl/openssl.gypi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,6 @@
12541254
# for reducing the overall entropy.
12551255
'PURIFY',
12561256

1257-
# Compression is not used and considered insecure (CRIME.)
1258-
'OPENSSL_NO_COMP',
1259-
12601257
# SSLv3 is susceptible to downgrade attacks (POODLE.)
12611258
'OPENSSL_NO_SSL3',
12621259

test/addons/openssl-client-cert-engine/binding.gyp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
'sources': [ 'testengine.cc' ],
1414
'product_extension': 'engine',
1515
'include_dirs': ['../../../deps/openssl/openssl/include'],
16-
'link_settings': {
17-
'libraries': [
18-
'../../../../out/<(PRODUCT_DIR)/<(openssl_product)'
19-
]
16+
'xcode_settings': {
17+
'OTHER_LDFLAGS': ['-undefined', 'dynamic_lookup'],
2018
},
2119
}],
2220
]

test/addons/openssl-key-engine/binding.gyp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
'sources': [ 'testkeyengine.cc' ],
1414
'product_extension': 'engine',
1515
'include_dirs': ['../../../deps/openssl/openssl/include'],
16-
'link_settings': {
17-
'libraries': [
18-
'../../../../out/<(PRODUCT_DIR)/<(openssl_product)'
19-
]
16+
'xcode_settings': {
17+
'OTHER_LDFLAGS': ['-undefined', 'dynamic_lookup'],
2018
},
2119
}],
2220
]

test/addons/openssl-test-engine/binding.gyp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
['OS=="mac"', {
1818
'xcode_settings': {
1919
'OTHER_CFLAGS': ['-Wno-deprecated-declarations'],
20-
},
21-
'link_settings': {
22-
'libraries': [
23-
'../../../../out/<(PRODUCT_DIR)/<(openssl_product)'
24-
]
20+
'OTHER_LDFLAGS': ['-undefined', 'dynamic_lookup'],
2521
},
2622
}],
2723
['OS=="linux"', {

0 commit comments

Comments
 (0)