Skip to content

Commit becbe9e

Browse files
jasnelltargos
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 931c0c7 commit becbe9e

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
@@ -69,7 +69,10 @@ const {
6969
ERR_TLS_INVALID_STATE
7070
} = codes;
7171
const { onpskexchange: kOnPskExchange } = internalBinding('symbols');
72-
const { getOptionValue } = require('internal/options');
72+
const {
73+
getOptionValue,
74+
getAllowUnauthorized,
75+
} = require('internal/options');
7376
const {
7477
validateString,
7578
validateBuffer,
@@ -1539,22 +1542,12 @@ function onConnectEnd() {
15391542
}
15401543
}
15411544

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

15591552
options = {
15601553
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)