@@ -161,14 +161,14 @@ function check(hostParts, pattern, wildcards) {
161
161
}
162
162
163
163
let urlWarningEmitted = false ;
164
- exports . checkServerIdentity = function checkServerIdentity ( host , cert ) {
164
+ exports . checkServerIdentity = function checkServerIdentity ( hostname , cert ) {
165
165
const subject = cert . subject ;
166
166
const altNames = cert . subjectaltname ;
167
167
const dnsNames = [ ] ;
168
168
const uriNames = [ ] ;
169
169
const ips = [ ] ;
170
170
171
- host = '' + host ;
171
+ hostname = '' + hostname ;
172
172
173
173
if ( altNames ) {
174
174
for ( const name of altNames . split ( ', ' ) ) {
@@ -200,14 +200,14 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
200
200
let valid = false ;
201
201
let reason = 'Unknown reason' ;
202
202
203
- if ( net . isIP ( host ) ) {
204
- valid = ips . includes ( canonicalizeIP ( host ) ) ;
203
+ if ( net . isIP ( hostname ) ) {
204
+ valid = ips . includes ( canonicalizeIP ( hostname ) ) ;
205
205
if ( ! valid )
206
- reason = `IP: ${ host } is not in the cert's list: ${ ips . join ( ', ' ) } ` ;
206
+ reason = `IP: ${ hostname } is not in the cert's list: ${ ips . join ( ', ' ) } ` ;
207
207
// TODO(bnoordhuis) Also check URI SANs that are IP addresses.
208
208
} else if ( subject ) {
209
- host = unfqdn ( host ) ; // Remove trailing dot for error messages.
210
- const hostParts = splitHost ( host ) ;
209
+ hostname = unfqdn ( hostname ) ; // Remove trailing dot for error messages.
210
+ const hostParts = splitHost ( hostname ) ;
211
211
const wildcard = ( pattern ) => check ( hostParts , pattern , true ) ;
212
212
const noWildcard = ( pattern ) => check ( hostParts , pattern , false ) ;
213
213
@@ -221,11 +221,12 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
221
221
valid = wildcard ( cn ) ;
222
222
223
223
if ( ! valid )
224
- reason = `Host: ${ host } . is not cert's CN: ${ cn } ` ;
224
+ reason = `Host: ${ hostname } . is not cert's CN: ${ cn } ` ;
225
225
} else {
226
226
valid = dnsNames . some ( wildcard ) || uriNames . some ( noWildcard ) ;
227
227
if ( ! valid )
228
- reason = `Host: ${ host } . is not in the cert's altnames: ${ altNames } ` ;
228
+ reason =
229
+ `Host: ${ hostname } . is not in the cert's altnames: ${ altNames } ` ;
229
230
}
230
231
} else {
231
232
reason = 'Cert is empty' ;
@@ -234,7 +235,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
234
235
if ( ! valid ) {
235
236
const err = new ERR_TLS_CERT_ALTNAME_INVALID ( reason ) ;
236
237
err . reason = reason ;
237
- err . host = host ;
238
+ err . host = hostname ;
238
239
err . cert = cert ;
239
240
return err ;
240
241
}
0 commit comments