Skip to content

Commit f5374d3

Browse files
committed
deps,build: add OpenSSL building of legacy module
This commit adds a configuration time flag to enable OpenSSL legacy module to be built. For example, the following will build the legacy module: $ ./configure --openssl-legacy-module To enable the default provider one has currently has to update the OpenSSL configuration file, openssl.cnf: [openssl_init] providers = provider_sect [provider_sect] default = default_sect legacy = legacy_sect [default_sect] activate = 1 [legacy_sect] activate = 1 This module can then be used by specifying the environment variable OPENSSL_MODULES like this: $ env OPENSSL_MODULES= \ $PWD/out/Release/obj.target/deps/openssl/lib/openssl-modules \ OPENSSL_CONF=out/Release/obj.target/deps/openssl/openssl.cnf \ ./node -p 'crypto.createHash("md4")' Hash { _options: undefined, [Symbol(kHandle)]: Hash {}, [Symbol(kState)]: { [Symbol(kFinalized)]: false } Refs: nodejs#40455
1 parent ad4e70c commit f5374d3

9 files changed

+411
-15
lines changed

configure.py

+10
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@
201201
default=None,
202202
help='specifies that the OpenSSL library is FIPS compatible')
203203

204+
parser.add_argument('--openssl-legacy-module',
205+
action='store_true',
206+
dest='openssl_legacy_module',
207+
default=None,
208+
help='specifies that the OpenSSL legacy module is to be built')
209+
204210
parser.add_argument('--openssl-use-def-ca-store',
205211
action='store_true',
206212
dest='use_openssl_ca_store',
@@ -1410,6 +1416,7 @@ def configure_openssl(o):
14101416
variables['node_shared_nghttp3'] = b(options.shared_nghttp3)
14111417
variables['openssl_is_fips'] = b(options.openssl_is_fips)
14121418
variables['node_fipsinstall'] = b(False)
1419+
variables['node_openssl_legacy_module'] = b(False)
14131420

14141421
if options.openssl_no_asm:
14151422
variables['openssl_no_asm'] = 1
@@ -1466,6 +1473,9 @@ def without_ssl_error(option):
14661473
o['defines'] += ['OPENSSL_FIPS']
14671474
variables['node_fipsinstall'] = b(True)
14681475

1476+
if options.openssl_legacy_module and not options.shared_openssl:
1477+
variables['node_openssl_legacy_module'] = b(True)
1478+
14691479
if options.shared_openssl:
14701480
has_quic = getsharedopensslhasquic.get_has_quic(options.__dict__['shared_openssl_includes'])
14711481
else:

deps/openssl/config/generate_gypi.pl

+70-11
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
my $progs = "apps/progs.h";
5151
my $prov_headers = "providers/common/include/prov/der_dsa.h providers/common/include/prov/der_wrap.h providers/common/include/prov/der_rsa.h providers/common/include/prov/der_ecx.h providers/common/include/prov/der_sm2.h providers/common/include/prov/der_ec.h providers/common/include/prov/der_digests.h";
5252
my $fips_ld = ($arch =~ m/linux/ ? "providers/fips.ld" : "");
53-
my $cmd1 = "cd ../openssl; make -f $makefile clean build_generated $buildinf $progs $prov_headers $fips_ld;";
53+
my $legacy_ld = ($arch =~ m/linux/ ? "providers/legacy.ld" : "");
54+
my $cmd1 = "cd ../openssl; make -f $makefile clean build_generated $buildinf $progs $prov_headers $fips_ld $legacy_ld;";
5455
system($cmd1) == 0 or die "Error in system($cmd1)";
5556

5657
# Copy and move all arch dependent header files into config/archs
@@ -100,11 +101,19 @@
100101
copy("$src_dir/providers/common/include/prov/der_digests.h",
101102
"$base_dir/providers/common/include/prov/") or die "Copy failed: $!";
102103

103-
my $fips_linker_script = "";
104+
my $version_script_dir = "\$(srcdir)/deps/openssl/config/archs/$arch/$asm/providers";
105+
my $fips_version_script = "";
104106
if ($fips_ld ne "") {
105-
$fips_linker_script = "$base_dir/providers/fips.ld";
107+
$fips_version_script = "$version_script_dir/fips.ld";
106108
copy("$src_dir/providers/fips.ld",
107-
$fips_linker_script) or die "Copy failed: $!";
109+
"$base_dir/providers/fips.ld") or die "Copy failed: $!";
110+
}
111+
112+
my $legacy_version_script = "";
113+
if ($legacy_ld ne "") {
114+
$legacy_version_script = "$version_script_dir/legacy.ld";
115+
copy("$src_dir/providers/legacy.ld",
116+
"$base_dir/providers/legacy.ld") or die "Copy failed: $!";
108117
}
109118

110119

@@ -172,27 +181,52 @@
172181
$src =~ s\.[sS]$\.asm\ if ($is_win);
173182
push(@generated_srcs, $src);
174183
} else {
175-
if ($src =~ m/\.c$/) {
184+
if ($src =~ m/\.c$/) {
176185
push(@libcrypto_srcs, $src);
177186
}
178187
}
179188
}
180189

190+
my @liblegacy_srcs = ();
191+
181192
foreach my $obj (@{$unified_info{sources}->{'providers/liblegacy.a'}}) {
182193
my $src = ${$unified_info{sources}->{$obj}}[0];
183-
#print("liblegacy src: $src \n");
194+
#print("providers/liblegacy.a obj: $obj src: $src \n");
184195
# .S files should be preprocessed into .s
185196
if ($unified_info{generate}->{$src}) {
186197
# .S or .s files should be preprocessed into .asm for WIN
187-
$src =~ s\.[sS]$\.asm\ if ($is_win);
188-
push(@generated_srcs, $src);
198+
#$src =~ s\.[sS]$\.asm\ if ($is_win);
199+
#push(@generated_srcs, $src);
189200
} else {
190-
if ($src =~ m/\.c$/) {
191-
push(@libcrypto_srcs, $src);
201+
if ($src =~ m/\.c$/) {
202+
push(@liblegacy_srcs, $src);
203+
}
204+
}
205+
}
206+
207+
foreach my $obj (@{$unified_info{sources}->{'providers/legacy'}}) {
208+
if ($obj eq 'providers/legacy.ld') {
209+
push(@generated_srcs, $obj);
210+
} else {
211+
my $src = ${$unified_info{sources}->{$obj}}[0];
212+
#print("providers/fips obj: $obj, src: $src\n");
213+
if ($src =~ m/\.c$/) {
214+
push(@liblegacy_srcs, $src);
192215
}
193216
}
194217
}
195218

219+
my @liblegacy_defines = ();
220+
foreach my $df (@{$unified_info{defines}->{'providers/liblegacy.a'}}) {
221+
#print("liblegacy defines: $df\n");
222+
push(@liblegacy_defines, $df);
223+
}
224+
225+
foreach my $df (@{$unified_info{defines}->{'providers/legacy'}}) {
226+
#print("liblegacy defines: $df\n");
227+
push(@liblegacy_srcs, $df);
228+
}
229+
196230
my @libfips_srcs = ();
197231
foreach my $obj (@{$unified_info{sources}->{'providers/libfips.a'}}) {
198232
my $src = ${$unified_info{sources}->{$obj}}[0];
@@ -316,12 +350,37 @@
316350
arch => \$arch,
317351
lib_cppflags => \@lib_cppflags,
318352
is_win => \$is_win,
319-
linker_script => \rel2abs($fips_linker_script),
353+
version_script => $fips_version_script,
320354
});
321355

322356
open(FIPSGYPI, "> ./archs/$arch/$asm/openssl-fips.gypi");
323357
print FIPSGYPI "$fipsgypi";
324358
close(FIPSGYPI);
359+
#
360+
# Create openssl-fips.gypi
361+
my $legacytemplate =
362+
Text::Template->new(TYPE => 'FILE',
363+
SOURCE => 'openssl-legacy.gypi.tmpl',
364+
DELIMITERS => [ "%%-", "-%%" ]
365+
);
366+
my $legacygypi = $legacytemplate->fill_in(
367+
HASH => {
368+
liblegacy_srcs => \@liblegacy_srcs,
369+
liblegacy_defines => \@liblegacy_defines,
370+
#generated_srcs => \@generated_srcs,
371+
config => \%config,
372+
target => \%target,
373+
cflags => \@cflags,
374+
asm => \$asm,
375+
arch => \$arch,
376+
lib_cppflags => \@lib_cppflags,
377+
is_win => \$is_win,
378+
version_script => $legacy_version_script,
379+
});
380+
381+
open(LEGACYGYPI, "> ./archs/$arch/$asm/openssl-legacy.gypi");
382+
print LEGACYGYPI "$legacygypi";
383+
close(LEGACYGYPI);
325384

326385
# Create openssl-cl.gypi
327386
my $cltemplate =

deps/openssl/config/openssl-fips.gypi.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'openssl_ex_libs_%%-$arch-%%': [
3434
'%%-$target{ex_libs}-%%',
3535
],
36-
'linker_script': '%%-$linker_script-%%'
36+
'version_script': '%%-$version_script-%%'
3737
},
3838
'include_dirs': [
3939
'.',
@@ -46,8 +46,8 @@
4646
%%- if (!$is_win) {
4747
$OUT .= " 'cflags': ['<@(openssl_cflags_$arch)'],\n";
4848
$OUT .= " 'libraries': ['<@(openssl_ex_libs_$arch)'],\n";
49-
if ($linker_script ne "") {
50-
$OUT .= " 'ldflags': ['-Wl,--version-script=<@(linker_script)'],";
49+
if ($version_script ne "") {
50+
$OUT .= " 'ldflags': ['-Wl,--version-script=<@(version_script)'],";
5151
}
5252
} -%%
5353
'sources': ['<@(openssl_sources)', '<@(openssl_sources_%%-$arch-%%)'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
'variables': {
3+
'openssl_sources': [
4+
%%- foreach $src (@liblegacy_srcs) {
5+
$OUT .= " 'openssl/$src',\n";
6+
} -%%
7+
],
8+
'openssl_sources_%%-$arch-%%': [
9+
%%- foreach $src (@generated_srcs) {
10+
$OUT .= " './config/archs/$arch/$asm/$src',\n";
11+
} -%%
12+
],
13+
'openssl_defines_%%-$arch-%%': [
14+
%%- foreach $define (@{$config{defines}}) {
15+
$OUT .= " '$define',\n";
16+
}
17+
foreach $define (@lib_cppflags) {
18+
$OUT .= " '$define',\n";
19+
}
20+
foreach $define (@{$target{defines}}) {
21+
$OUT .= " '$define',\n";
22+
}
23+
foreach $define (@{liblegacy_defines}) {
24+
$OUT .= " '$define',\n";
25+
}
26+
foreach $define (@{$config{liblegacy_defines}}) {
27+
$OUT .= " '$define',\n";
28+
} -%% ],
29+
'openssl_cflags_%%-$arch-%%': [
30+
%%- foreach $cflag (@cflags) {
31+
$OUT .= " '$cflag',\n";
32+
} -%% ],
33+
'openssl_ex_libs_%%-$arch-%%': [
34+
'%%-$target{ex_libs}-%%',
35+
],
36+
'version_script': '%%-$version_script-%%'
37+
},
38+
'include_dirs': [
39+
'.',
40+
'./include',
41+
'./crypto',
42+
'./crypto/include/internal',
43+
'./providers/common/include',
44+
],
45+
'defines': ['<@(openssl_defines_%%-$arch-%%)'],
46+
%%- if (!$is_win) {
47+
$OUT .= " 'cflags': ['<@(openssl_cflags_$arch)'],\n";
48+
$OUT .= " 'libraries': ['<@(openssl_ex_libs_$arch)'],\n";
49+
if ($version_script ne "") {
50+
$OUT .= " 'ldflags': ['-Wl,--version-script=<@(version_script)'],";
51+
}
52+
} -%%
53+
'sources': ['<@(openssl_sources)', '<@(openssl_sources_%%-$arch-%%)'],
54+
'direct_dependent_settings': {
55+
'include_dirs': ['./include', '.'],
56+
'defines': ['<@(openssl_defines_%%-$arch-%%)'],
57+
},
58+
}

deps/openssl/openssl-legacy_asm.gypi

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
'conditions': [
3+
['target_arch=="ppc" and OS=="aix"', {
4+
'includes': ['config/archs/aix-gcc/asm/openssl-legacy.gypi'],
5+
}, 'target_arch=="ppc" and OS=="linux"', {
6+
'includes': ['config/archs/linux-ppc/asm/openssl-legacy.gypi'],
7+
}, 'target_arch=="ppc64" and OS=="aix"', {
8+
'includes': ['config/archs/aix64-gcc-as/asm/openssl-legacy.gypi'],
9+
}, 'target_arch=="ppc64" and OS=="linux" and node_byteorder =="little"', {
10+
'includes': ['config/archs/linux-ppc64le/asm/openssl-legacy.gypi'],
11+
}, 'target_arch=="ppc64" and OS=="linux"', {
12+
'includes': ['config/archs/linux-ppc64/asm/openssl-legacy.gypi'],
13+
}, 'target_arch=="s390x" and OS=="linux"', {
14+
'includes': ['config/archs/linux64-s390x/asm/openssl-legacy.gypi'],
15+
}, 'target_arch=="arm" and OS=="linux"', {
16+
'includes': ['config/archs/linux-armv4/asm/openssl-legacy.gypi'],
17+
}, 'target_arch=="arm64" and OS=="linux"', {
18+
'includes': ['config/archs/linux-aarch64/asm/openssl-legacy.gypi'],
19+
}, 'target_arch=="arm64" and OS=="mac"', {
20+
'includes': ['config/archs/darwin64-arm64-cc/asm/openssl-legacy.gypi'],
21+
}, 'target_arch=="ia32" and OS=="freebsd"', {
22+
'includes': ['config/archs/BSD-x86/asm/openssl-legacy.gypi'],
23+
}, 'target_arch=="ia32" and OS=="linux"', {
24+
'includes': ['config/archs/linux-elf/asm/openssl-legacy.gypi'],
25+
}, 'target_arch=="ia32" and OS=="mac"', {
26+
'includes': ['config/archs/darwin-i386-cc/asm/openssl-legacy.gypi'],
27+
}, 'target_arch=="ia32" and OS=="solaris"', {
28+
'includes': ['config/archs/solaris-x86-gcc/asm/openssl-legacy.gypi'],
29+
}, 'target_arch=="ia32" and OS=="win"', {
30+
'includes': ['config/archs/VC-WIN32/asm/openssl-legacy.gypi'],
31+
'rules': [
32+
{
33+
'rule_name': 'Assemble',
34+
'extension': 'asm',
35+
'inputs': [],
36+
'outputs': [
37+
'<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
38+
],
39+
'action': [
40+
'nasm.exe',
41+
'-f win32',
42+
'-o', '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
43+
'<(RULE_INPUT_PATH)',
44+
],
45+
}
46+
],
47+
}, 'target_arch=="ia32"', {
48+
'includes': ['config/archs/linux-elf/asm/openssl-legacy.gypi'],
49+
}, 'target_arch=="x64" and OS=="freebsd"', {
50+
'includes': ['config/archs/BSD-x86_64/asm/openssl-legacy.gypi'],
51+
}, 'target_arch=="x64" and OS=="mac"', {
52+
'includes': ['config/archs/darwin64-x86_64-cc/asm/openssl-legacy.gypi'],
53+
}, 'target_arch=="x64" and OS=="solaris"', {
54+
'includes': ['config/archs/solaris64-x86_64-gcc/asm/openssl-legacy.gypi'],
55+
}, 'target_arch=="x64" and OS=="win"', {
56+
'includes': ['config/archs/VC-WIN64A/asm/openssl-legacy.gypi'],
57+
'rules': [
58+
{
59+
'rule_name': 'Assemble',
60+
'extension': 'asm',
61+
'inputs': [],
62+
'outputs': [
63+
'<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
64+
],
65+
'action': [
66+
'nasm.exe',
67+
'-f win64',
68+
'-DNEAR',
69+
'-Ox',
70+
'-g',
71+
'-o', '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
72+
'<(RULE_INPUT_PATH)',
73+
],
74+
}
75+
],
76+
}, 'target_arch=="x64" and OS=="linux"', {
77+
'includes': ['config/archs/linux-x86_64/asm/openssl-legacy.gypi'],
78+
}, 'target_arch=="mips64el" and OS=="linux"', {
79+
'includes': ['config/archs/linux64-mips64/asm/openssl-legacy.gypi'],
80+
}, {
81+
# Other architectures don't use assembly
82+
'includes': ['config/archs/linux-x86_64/asm/openssl-legacy.gypi'],
83+
}],
84+
],
85+
}

0 commit comments

Comments
 (0)