Skip to content

Commit 8a000e8

Browse files
danbevgibfahn
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. PR-URL: #16790 Backport-PR-URL: #18174 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 f99aba1 commit 8a000e8

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

configure

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ parser.add_option('--openssl-use-def-ca-store',
174174
dest='use_openssl_ca_store',
175175
help='Use OpenSSL supplied CA store instead of compiled-in Mozilla CA copy.')
176176

177+
parser.add_option('--openssl-system-ca-path',
178+
action='store',
179+
dest='openssl_system_ca_path',
180+
help='Use the specified path to system CA (PEM format) in addition to '
181+
'the OpenSSL supplied CA store or compiled-in Mozilla CA copy.')
182+
177183
shared_optgroup.add_option('--shared-http-parser',
178184
action='store_true',
179185
dest='shared_http_parser',
@@ -1035,6 +1041,8 @@ def configure_openssl(o):
10351041
o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
10361042
if options.use_openssl_ca_store:
10371043
o['defines'] += ['NODE_OPENSSL_CERT_STORE']
1044+
if options.openssl_system_ca_path:
1045+
o['variables']['openssl_system_ca_path'] = options.openssl_system_ca_path
10381046
o['variables']['node_without_node_options'] = b(options.without_node_options)
10391047
if options.without_node_options:
10401048
o['defines'] += ['NODE_WITHOUT_NODE_OPTIONS']

node.gyp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,17 @@
287287
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
288288
],
289289

290+
'variables': {
291+
'openssl_system_ca_path%': '',
292+
},
293+
290294
'defines': [
291295
'NODE_ARCH="<(target_arch)"',
292296
'NODE_PLATFORM="<(OS)"',
293297
'NODE_WANT_INTERNALS=1',
294298
# Warn when using deprecated V8 APIs.
295299
'V8_DEPRECATION_WARNINGS=1',
300+
'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"',
296301
],
297302
'conditions': [
298303
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
@@ -444,6 +449,11 @@
444449
'defines': [ 'HAVE_OPENSSL=0' ]
445450
}],
446451
],
452+
'direct_dependent_settings': {
453+
'defines': [
454+
'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"',
455+
],
456+
},
447457
},
448458
{
449459
'target_name': 'mkssldef',

src/node_crypto.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ static const char* const root_certs[] = {
258258
#include "node_root_certs.h" // NOLINT(build/include_order)
259259
};
260260

261+
static const char system_cert_path[] = NODE_OPENSSL_SYSTEM_CERT_PATH;
262+
261263
static std::string extra_root_certs_file; // NOLINT(runtime/string)
262264

263265
static X509_STORE* root_cert_store;
@@ -910,6 +912,9 @@ static X509_STORE* NewRootCertStore() {
910912
}
911913

912914
X509_STORE* store = X509_STORE_new();
915+
if (*system_cert_path != '\0') {
916+
X509_STORE_load_locations(store, system_cert_path, nullptr);
917+
}
913918
if (ssl_openssl_cert_store) {
914919
X509_STORE_set_default_paths(store);
915920
} else {

test/parallel/test-process-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ if (!fs.existsSync(configPath)) {
4545
let config = fs.readFileSync(configPath, 'utf8');
4646

4747
// Clean up comment at the first line.
48-
config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
48+
config = config.split('\n').slice(1).join('\n');
49+
config = config.replace(/"/g, '\\"');
50+
config = config.replace(/'/g, '"');
4951
config = JSON.parse(config, function(key, value) {
5052
if (value === 'true') return true;
5153
if (value === 'false') return false;

0 commit comments

Comments
 (0)