Skip to content

Commit 2d4775a

Browse files
committed
src: add --use-bundled-ca --use-openssl-ca check
The --use-bundled-ca and --use-openssl-ca command line arguments are mutually exclusive but can both be used on the same command line. This commit adds a check if both options are used. Fixes: nodejs#12083 PR-URL: nodejs#12087 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent 3f6199c commit 2d4775a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/node.cc

+13
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,7 @@ static void ParseArgs(int* argc,
36323632
const char** new_exec_argv = new const char*[nargs];
36333633
const char** new_v8_argv = new const char*[nargs];
36343634
const char** new_argv = new const char*[nargs];
3635+
const char** local_preload_modules = new const char*[nargs];
36353636
bool use_bundled_ca = false;
36363637
bool use_openssl_ca = false;
36373638

@@ -3747,7 +3748,9 @@ static void ParseArgs(int* argc,
37473748
default_cipher_list = arg + 18;
37483749
} else if (strncmp(arg, "--use-openssl-ca", 16) == 0) {
37493750
ssl_openssl_cert_store = true;
3751+
use_openssl_ca = true;
37503752
} else if (strncmp(arg, "--use-bundled-ca", 16) == 0) {
3753+
use_bundled_ca = true;
37513754
ssl_openssl_cert_store = false;
37523755
#if NODE_FIPS_MODE
37533756
} else if (strcmp(arg, "--enable-fips") == 0) {
@@ -3782,6 +3785,16 @@ static void ParseArgs(int* argc,
37823785
index += args_consumed;
37833786
}
37843787

3788+
#if HAVE_OPENSSL
3789+
if (use_openssl_ca && use_bundled_ca) {
3790+
fprintf(stderr,
3791+
"%s: either --use-openssl-ca or --use-bundled-ca can be used, "
3792+
"not both\n",
3793+
argv[0]);
3794+
exit(9);
3795+
}
3796+
#endif
3797+
37853798
// Copy remaining arguments.
37863799
const unsigned int args_left = nargs - index;
37873800

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
// This test checks the usage of --use-bundled-ca and --use-openssl-ca arguments
3+
// to verify that both are not used at the same time.
4+
const common = require('../common');
5+
if (!common.hasCrypto) {
6+
common.skip('missing crypto');
7+
return;
8+
}
9+
const assert = require('assert');
10+
const os = require('os');
11+
const childProcess = require('child_process');
12+
const result = childProcess.spawnSync(process.execPath, [
13+
'--use-bundled-ca',
14+
'--use-openssl-ca',
15+
'-p', 'process.version'],
16+
{encoding: 'utf8'});
17+
18+
assert.strictEqual(result.stderr,
19+
process.execPath + ': either --use-openssl-ca or ' +
20+
'--use-bundled-ca can be used, not both' + os.EOL);
21+
assert.strictEqual(result.status, 9);
22+
23+
const useBundledCA = childProcess.spawnSync(process.execPath, [
24+
'--use-bundled-ca',
25+
'-p', 'process.version']);
26+
assert.strictEqual(useBundledCA.status, 0);
27+
28+
const useOpenSSLCA = childProcess.spawnSync(process.execPath, [
29+
'--use-openssl-ca',
30+
'-p', 'process.version']);
31+
assert.strictEqual(useOpenSSLCA.status, 0);

0 commit comments

Comments
 (0)