Skip to content

Commit bfa19c4

Browse files
jasnellBridgeAR
authored andcommitted
tls: move getAllowUnauthorized to internal/options
Make it so that the allow unauthorized warning can be easily reused by the QUIC impl once that lands. Extracted from #32379 Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #32917 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 4432bb2 commit bfa19c4

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

lib/_tls_wrap.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ const {
7070
ERR_TLS_INVALID_STATE
7171
} = codes;
7272
const { onpskexchange: kOnPskExchange } = internalBinding('symbols');
73-
const { getOptionValue } = require('internal/options');
73+
const {
74+
getOptionValue,
75+
getAllowUnauthorized,
76+
} = require('internal/options');
7477
const {
7578
validateString,
7679
validateBuffer,
@@ -1540,22 +1543,12 @@ function onConnectEnd() {
15401543
}
15411544
}
15421545

1543-
let warnOnAllowUnauthorized = true;
1544-
15451546
// Arguments: [port,] [host,] [options,] [cb]
15461547
exports.connect = function connect(...args) {
15471548
args = normalizeConnectArgs(args);
15481549
let options = args[0];
15491550
const cb = args[1];
1550-
const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';
1551-
1552-
if (allowUnauthorized && warnOnAllowUnauthorized) {
1553-
warnOnAllowUnauthorized = false;
1554-
process.emitWarning('Setting the NODE_TLS_REJECT_UNAUTHORIZED ' +
1555-
'environment variable to \'0\' makes TLS connections ' +
1556-
'and HTTPS requests insecure by disabling ' +
1557-
'certificate verification.');
1558-
}
1551+
const allowUnauthorized = getAllowUnauthorized();
15591552

15601553
options = {
15611554
rejectUnauthorized: !allowUnauthorized,

lib/internal/options.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const { getOptions } = internalBinding('options');
44
const { options, aliases } = getOptions();
55

6+
let warnOnAllowUnauthorized = true;
7+
68
function getOptionValue(option) {
79
const result = options.get(option);
810
if (!result) {
@@ -11,8 +13,23 @@ function getOptionValue(option) {
1113
return result.value;
1214
}
1315

16+
function getAllowUnauthorized() {
17+
const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';
18+
19+
if (allowUnauthorized && warnOnAllowUnauthorized) {
20+
warnOnAllowUnauthorized = false;
21+
process.emitWarning(
22+
'Setting the NODE_TLS_REJECT_UNAUTHORIZED ' +
23+
'environment variable to \'0\' makes TLS connections ' +
24+
'and HTTPS requests insecure by disabling ' +
25+
'certificate verification.');
26+
}
27+
return allowUnauthorized;
28+
}
29+
1430
module.exports = {
1531
options,
1632
aliases,
17-
getOptionValue
33+
getOptionValue,
34+
getAllowUnauthorized,
1835
};

0 commit comments

Comments
 (0)