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

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎lib/_tls_wrap.js‎

Lines changed: 5 additions & 12 deletions
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-
letwarnOnAllowUnauthorized=true;
1537-
15381539
// Arguments: [port,] [host,] [options,] [cb]
15391540
exports.connect=functionconnect(...args){
15401541
args=normalizeConnectArgs(args);
15411542
letoptions=args[0];
15421543
constcb=args[1];
1543-
constallowUnauthorized=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+
constallowUnauthorized=getAllowUnauthorized();
15521545

15531546
options={
15541547
rejectUnauthorized: !allowUnauthorized,

‎lib/internal/options.js‎

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

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

16+
functiongetAllowUnauthorized(){
17+
constallowUnauthorized=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+
returnallowUnauthorized;
28+
}
29+
1430
module.exports={
1531
options,
1632
aliases,
17-
getOptionValue
33+
getOptionValue,
34+
getAllowUnauthorized,
1835
};

0 commit comments

Comments
 (0)