Skip to content

Commit 388b6d3

Browse files
AdamMajeritaloacasas
authored andcommitted
crypto: Use system CAs instead of using bundled ones
NodeJS can already use an external, shared OpenSSL library. This library knows where to look for OS managed certificates. Allow a compile-time option to use this CA store by default instead of using bundled certificates. In case when using bundled OpenSSL, the paths are also valid for majority of Linux systems without additional intervention. If this is not set, we can use SSL_CERT_DIR to point it to correct location. Fixes: nodejs#3159 PR-URL: nodejs#8334 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
1 parent 8d6a087 commit 388b6d3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

configure

+7
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ parser.add_option('--openssl-fips',
144144
dest='openssl_fips',
145145
help='Build OpenSSL using FIPS canister .o file in supplied folder')
146146

147+
parser.add_option('--openssl-use-def-ca-store',
148+
action='store_true',
149+
dest='use_openssl_ca_store',
150+
help='Use OpenSSL supplied CA store instead of compiled-in Mozilla CA copy.')
151+
147152
shared_optgroup.add_option('--shared-http-parser',
148153
action='store_true',
149154
dest='shared_http_parser',
@@ -940,6 +945,8 @@ def configure_openssl(o):
940945
o['variables']['node_use_openssl'] = b(not options.without_ssl)
941946
o['variables']['node_shared_openssl'] = b(options.shared_openssl)
942947
o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
948+
if options.use_openssl_ca_store:
949+
o['defines'] += ['NODE_OPENSSL_CERT_STORE']
943950
if options.openssl_fips:
944951
o['variables']['openssl_fips'] = options.openssl_fips
945952
fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips')

src/node_crypto.cc

+4
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,14 @@ static X509_STORE* NewRootCertStore() {
707707
}
708708

709709
X509_STORE* store = X509_STORE_new();
710+
#if defined(NODE_OPENSSL_CERT_STORE)
711+
X509_STORE_set_default_paths(store);
712+
#else
710713
for (X509 *cert : root_certs_vector) {
711714
X509_up_ref(cert);
712715
X509_STORE_add_cert(store, cert);
713716
}
717+
#endif
714718

715719
return store;
716720
}

0 commit comments

Comments
 (0)