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 https://github.com/nodejs/node/pull/32379

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/32917
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
James M Snell authored and Michaël Zasso committed 2020-05-13 17:52:46 +02:00
1 parent 931c0c74b0
commit becbe9e246
2 files changed
+23 -13

No files matched your search

+5 -12
View File
@@ -69,7 +69,10 @@ const {
ERR_TLS_INVALID_STATE
} = codes;
const { onpskexchange: kOnPskExchange } = internalBinding('symbols');
const { getOptionValue } = require('internal/options');
const {
getOptionValue,
getAllowUnauthorized,
} = require('internal/options');
const {
validateString,
validateBuffer,
@@ -1539,22 +1542,12 @@ function onConnectEnd() {
}
}
let warnOnAllowUnauthorized = true;
// Arguments: [port,] [host,] [options,] [cb]
exports.connect = function connect(...args) {
args = normalizeConnectArgs(args);
let options = args[0];
const cb = args[1];
const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';
if (allowUnauthorized && warnOnAllowUnauthorized) {
warnOnAllowUnauthorized = false;
process.emitWarning('Setting the NODE_TLS_REJECT_UNAUTHORIZED ' +
'environment variable to \'0\' makes TLS connections ' +
'and HTTPS requests insecure by disabling ' +
'certificate verification.');
}
const allowUnauthorized = getAllowUnauthorized();
options = {
rejectUnauthorized: !allowUnauthorized,
+18 -1
View File
@@ -3,6 +3,8 @@
const { getOptions } = internalBinding('options');
const { options, aliases } = getOptions();
let warnOnAllowUnauthorized = true;
function getOptionValue(option) {
const result = options.get(option);
if (!result) {
@@ -11,8 +13,23 @@ function getOptionValue(option) {
return result.value;
}
function getAllowUnauthorized() {
const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';
if (allowUnauthorized && warnOnAllowUnauthorized) {
warnOnAllowUnauthorized = false;
process.emitWarning(
'Setting the NODE_TLS_REJECT_UNAUTHORIZED ' +
'environment variable to \'0\' makes TLS connections ' +
'and HTTPS requests insecure by disabling ' +
'certificate verification.');
}
return allowUnauthorized;
}
module.exports = {
options,
aliases,
getOptionValue
getOptionValue,
getAllowUnauthorized,
};