@@ -169,14 +169,14 @@ function check(hostParts, pattern, wildcards) {
169
169
return true ;
170
170
}
171
171
172
- exports . checkServerIdentity = function checkServerIdentity ( host , cert ) {
172
+ exports . checkServerIdentity = function checkServerIdentity ( hostname , cert ) {
173
173
const subject = cert . subject ;
174
174
const altNames = cert . subjectaltname ;
175
175
const dnsNames = [ ] ;
176
176
const uriNames = [ ] ;
177
177
const ips = [ ] ;
178
178
179
- host = '' + host ;
179
+ hostname = '' + hostname ;
180
180
181
181
if ( altNames ) {
182
182
for ( const name of altNames . split ( ', ' ) ) {
@@ -194,14 +194,14 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
194
194
let valid = false ;
195
195
let reason = 'Unknown reason' ;
196
196
197
- if ( net . isIP ( host ) ) {
198
- valid = ips . includes ( canonicalizeIP ( host ) ) ;
197
+ if ( net . isIP ( hostname ) ) {
198
+ valid = ips . includes ( canonicalizeIP ( hostname ) ) ;
199
199
if ( ! valid )
200
- reason = `IP: ${ host } is not in the cert's list: ${ ips . join ( ', ' ) } ` ;
200
+ reason = `IP: ${ hostname } is not in the cert's list: ${ ips . join ( ', ' ) } ` ;
201
201
// TODO(bnoordhuis) Also check URI SANs that are IP addresses.
202
202
} else if ( subject ) {
203
- host = unfqdn ( host ) ; // Remove trailing dot for error messages.
204
- const hostParts = splitHost ( host ) ;
203
+ hostname = unfqdn ( hostname ) ; // Remove trailing dot for error messages.
204
+ const hostParts = splitHost ( hostname ) ;
205
205
const wildcard = ( pattern ) => check ( hostParts , pattern , true ) ;
206
206
const noWildcard = ( pattern ) => check ( hostParts , pattern , false ) ;
207
207
@@ -215,11 +215,12 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
215
215
valid = wildcard ( cn ) ;
216
216
217
217
if ( ! valid )
218
- reason = `Host: ${ host } . is not cert's CN: ${ cn } ` ;
218
+ reason = `Host: ${ hostname } . is not cert's CN: ${ cn } ` ;
219
219
} else {
220
220
valid = dnsNames . some ( wildcard ) || uriNames . some ( noWildcard ) ;
221
221
if ( ! valid )
222
- reason = `Host: ${ host } . is not in the cert's altnames: ${ altNames } ` ;
222
+ reason =
223
+ `Host: ${ hostname } . is not in the cert's altnames: ${ altNames } ` ;
223
224
}
224
225
} else {
225
226
reason = 'Cert is empty' ;
@@ -228,7 +229,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
228
229
if ( ! valid ) {
229
230
const err = new ERR_TLS_CERT_ALTNAME_INVALID ( reason ) ;
230
231
err . reason = reason ;
231
- err . host = host ;
232
+ err . host = hostname ;
232
233
err . cert = cert ;
233
234
return err ;
234
235
}
0 commit comments