Skip to content

Commit 8a7db9d

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: #12083 PR-URL: #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 4d255b0 commit 8a7db9d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/node.cc

+14
Original file line numberDiff line numberDiff line change
@@ -3637,6 +3637,8 @@ static void ParseArgs(int* argc,
36373637
const char** new_v8_argv = new const char*[nargs];
36383638
const char** new_argv = new const char*[nargs];
36393639
const char** local_preload_modules = new const char*[nargs];
3640+
bool use_bundled_ca = false;
3641+
bool use_openssl_ca = false;
36403642

36413643
for (unsigned int i = 0; i < nargs; ++i) {
36423644
new_exec_argv[i] = nullptr;
@@ -3751,7 +3753,9 @@ static void ParseArgs(int* argc,
37513753
default_cipher_list = arg + 18;
37523754
} else if (strncmp(arg, "--use-openssl-ca", 16) == 0) {
37533755
ssl_openssl_cert_store = true;
3756+
use_openssl_ca = true;
37543757
} else if (strncmp(arg, "--use-bundled-ca", 16) == 0) {
3758+
use_bundled_ca = true;
37553759
ssl_openssl_cert_store = false;
37563760
#if NODE_FIPS_MODE
37573761
} else if (strcmp(arg, "--enable-fips") == 0) {
@@ -3786,6 +3790,16 @@ static void ParseArgs(int* argc,
37863790
index += args_consumed;
37873791
}
37883792

3793+
#if HAVE_OPENSSL
3794+
if (use_openssl_ca && use_bundled_ca) {
3795+
fprintf(stderr,
3796+
"%s: either --use-openssl-ca or --use-bundled-ca can be used, "
3797+
"not both\n",
3798+
argv[0]);
3799+
exit(9);
3800+
}
3801+
#endif
3802+
37893803
// Copy remaining arguments.
37903804
const unsigned int args_left = nargs - index;
37913805
memcpy(new_argv + new_argc, argv + index, args_left * sizeof(*argv));
+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)