Skip to content

Commit 2268d00

Browse files
danbevMylesBorins
authored andcommitted
src: add openssl-system-ca-path configure option
The motivation for this commit is that we need to specify system CA certificates when building node. While we are aware of the environment variable NODE_EXTRA_CA_CERTS this is not a great solution as we build an RPM and we also don't want users to be able to unset them. The suggestion is to add a configure time property like this: --openssl-system-ca-path=OPENSSL_SYSTEM_CA_PATH Use the specified path to system CA (PEM format) in addition to the OpenSSL supplied CA store or compiled- in Mozilla CA copy. Usage example: $ ./configure --openssl-system-ca-path=/etc/pki/tls/certs/ca-bundle.crt This would add the specified CA certificates in addition to the ones already being used. Backport-PR-URL: #18173 PR-URL: #16790 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 1390c28 commit 2268d00

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

configure

+8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ parser.add_option('--openssl-use-def-ca-store',
172172
dest='use_openssl_ca_store',
173173
help='Use OpenSSL supplied CA store instead of compiled-in Mozilla CA copy.')
174174

175+
parser.add_option('--openssl-system-ca-path',
176+
action='store',
177+
dest='openssl_system_ca_path',
178+
help='Use the specified path to system CA (PEM format) in addition to '
179+
'the OpenSSL supplied CA store or compiled-in Mozilla CA copy.')
180+
175181
shared_optgroup.add_option('--shared-http-parser',
176182
action='store_true',
177183
dest='shared_http_parser',
@@ -988,6 +994,8 @@ def configure_openssl(o):
988994
o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
989995
if options.use_openssl_ca_store:
990996
o['defines'] += ['NODE_OPENSSL_CERT_STORE']
997+
if options.openssl_system_ca_path:
998+
o['variables']['openssl_system_ca_path'] = options.openssl_system_ca_path
991999
o['variables']['node_without_node_options'] = b(options.without_node_options)
9921000
if options.without_node_options:
9931001
o['defines'] += ['NODE_WITHOUT_NODE_OPTIONS']

node.gyp

+10
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,28 @@
234234
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
235235
],
236236

237+
'variables': {
238+
'openssl_system_ca_path%': '',
239+
},
240+
237241
'defines': [
238242
'NODE_ARCH="<(target_arch)"',
239243
'NODE_PLATFORM="<(OS)"',
240244
'NODE_WANT_INTERNALS=1',
241245
# Warn when using deprecated V8 APIs.
242246
'V8_DEPRECATION_WARNINGS=1',
247+
'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"',
243248
],
244249
'conditions': [
245250
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
246251
'product_extension': '<(shlib_suffix)',
247252
}]
248253
],
254+
'direct_dependent_settings': {
255+
'defines': [
256+
'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"',
257+
],
258+
},
249259
},
250260
{
251261
'target_name': 'mkssldef',

src/node_crypto.cc

+5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ static const char* const root_certs[] = {
124124
#include "node_root_certs.h" // NOLINT(build/include_order)
125125
};
126126

127+
static const char system_cert_path[] = NODE_OPENSSL_SYSTEM_CERT_PATH;
128+
127129
static std::string extra_root_certs_file; // NOLINT(runtime/string)
128130

129131
static X509_STORE* root_cert_store;
@@ -724,6 +726,9 @@ static X509_STORE* NewRootCertStore() {
724726
}
725727

726728
X509_STORE* store = X509_STORE_new();
729+
if (*system_cert_path != '\0') {
730+
X509_STORE_load_locations(store, system_cert_path, nullptr);
731+
}
727732
if (ssl_openssl_cert_store) {
728733
X509_STORE_set_default_paths(store);
729734
} else {

test/parallel/test-process-config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ if (!fs.existsSync(configPath)) {
2424
let config = fs.readFileSync(configPath, 'utf8');
2525

2626
// Clean up comment at the first line.
27-
config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
27+
config = config.split('\n').slice(1).join('\n');
28+
config = config.replace(/"/g, '\\"');
29+
config = config.replace(/'/g, '"');
2830
config = JSON.parse(config, function(key, value) {
2931
if (value === 'true') return true;
3032
if (value === 'false') return false;

0 commit comments

Comments
 (0)