Skip to content

Commit 3086813

Browse files
jasnellBethGriggs
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 6fc4d17 commit 3086813

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,
@@ -1533,22 +1536,12 @@ function onConnectEnd() {
15331536
}
15341537
}
15351538

1536-
let warnOnAllowUnauthorized = true;
1537-
15381539
// Arguments: [port,] [host,] [options,] [cb]
15391540
exports.connect = function connect(...args) {
15401541
args = normalizeConnectArgs(args);
15411542
let options = args[0];
15421543
const cb = args[1];
1543-
const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';
1544-
1545-
if (allowUnauthorized && warnOnAllowUnauthorized) {
1546-
warnOnAllowUnauthorized = false;
1547-
process.emitWarning('Setting the NODE_TLS_REJECT_UNAUTHORIZED ' +
1548-
'environment variable to \'0\' makes TLS connections ' +
1549-
'and HTTPS requests insecure by disabling ' +
1550-
'certificate verification.');
1551-
}
1544+
const allowUnauthorized = getAllowUnauthorized();
15521545

15531546
options = {
15541547
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)