Skip to content

Commit 758dc81

Browse files
danbevMylesBorins
authored andcommitted
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 Backport-PR-URL: #17783 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 2d4fca2 commit 758dc81

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/node.cc

+14
Original file line numberDiff line numberDiff line change
@@ -3887,6 +3887,8 @@ static void ParseArgs(int* argc,
38873887
const char** new_exec_argv = new const char*[nargs];
38883888
const char** new_v8_argv = new const char*[nargs];
38893889
const char** new_argv = new const char*[nargs];
3890+
bool use_bundled_ca = false;
3891+
bool use_openssl_ca = false;
38903892

38913893
for (unsigned int i = 0; i < nargs; ++i) {
38923894
new_exec_argv[i] = nullptr;
@@ -3992,7 +3994,9 @@ static void ParseArgs(int* argc,
39923994
default_cipher_list = arg + 18;
39933995
} else if (strncmp(arg, "--use-openssl-ca", 16) == 0) {
39943996
ssl_openssl_cert_store = true;
3997+
use_openssl_ca = true;
39953998
} else if (strncmp(arg, "--use-bundled-ca", 16) == 0) {
3999+
use_bundled_ca = true;
39964000
ssl_openssl_cert_store = false;
39974001
#if NODE_FIPS_MODE
39984002
} else if (strcmp(arg, "--enable-fips") == 0) {
@@ -4027,6 +4031,16 @@ static void ParseArgs(int* argc,
40274031
index += args_consumed;
40284032
}
40294033

4034+
#if HAVE_OPENSSL
4035+
if (use_openssl_ca && use_bundled_ca) {
4036+
fprintf(stderr,
4037+
"%s: either --use-openssl-ca or --use-bundled-ca can be used, "
4038+
"not both\n",
4039+
argv[0]);
4040+
exit(9);
4041+
}
4042+
#endif
4043+
40304044
// Copy remaining arguments.
40314045
const unsigned int args_left = nargs - index;
40324046

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
8+
const assert = require('assert');
9+
const os = require('os');
10+
const childProcess = require('child_process');
11+
const result = childProcess.spawnSync(
12+
process.execPath,
13+
[ '--use-bundled-ca', '--use-openssl-ca', '-p', 'process.version' ],
14+
{ encoding: 'utf8' }
15+
);
16+
17+
assert.strictEqual(result.stderr, `${process.execPath
18+
}: either --use-openssl-ca or --use-bundled-ca can be used, not both${os.EOL}`
19+
);
20+
assert.strictEqual(result.status, 9);
21+
22+
const useBundledCA = childProcess.spawnSync(process.execPath, [
23+
'--use-bundled-ca',
24+
'-p', 'process.version']);
25+
assert.strictEqual(useBundledCA.status, 0);
26+
27+
const useOpenSSLCA = childProcess.spawnSync(process.execPath, [
28+
'--use-openssl-ca',
29+
'-p', 'process.version']);
30+
assert.strictEqual(useOpenSSLCA.status, 0);

0 commit comments

Comments
 (0)