Skip to content

Commit 38c938a

Browse files
davisokothapapirovski
authored andcommitted
doc: fix inconsistent documentation (host vs hostname)
Update reference to read `hostname` instead of `host` for consistency. Also update function signature to use `hostname` rather than `host` PR-URL: #20933 Refs: #20892 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 8055bdb commit 38c938a

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

doc/api/deprecations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ deprecated and support will be removed in the future.
10611061
[`tls.SecureContext`]: tls.html#tls_tls_createsecurecontext_options
10621062
[`tls.SecurePair`]: tls.html#tls_class_securepair
10631063
[`tls.TLSSocket`]: tls.html#tls_class_tls_tlssocket
1064-
[`tls.checkServerIdentity()`]: tls.html#tls_tls_checkserveridentity_host_cert
1064+
[`tls.checkServerIdentity()`]: tls.html#tls_tls_checkserveridentity_hostname_cert
10651065
[`tls.createSecureContext()`]: tls.html#tls_tls_createsecurecontext_options
10661066
[`util._extend()`]: util.html#util_util_extend_target_source
10671067
[`util.debug()`]: util.html#util_util_debug_string

doc/api/tls.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ added: v0.5.3
358358
`cert`, `ca`, etc).
359359

360360
The `server.addContext()` method adds a secure context that will be used if
361-
the client request's SNI hostname matches the supplied `hostname` (or wildcard).
361+
the client request's SNI name matches the supplied `hostname` (or wildcard).
362362

363363
### server.address()
364364
<!-- YAML
@@ -796,17 +796,17 @@ and their processing can be delayed due to packet loss or reordering. However,
796796
smaller fragments add extra TLS framing bytes and CPU overhead, which may
797797
decrease overall server throughput.
798798

799-
## tls.checkServerIdentity(host, cert)
799+
## tls.checkServerIdentity(hostname, cert)
800800
<!-- YAML
801801
added: v0.8.4
802802
-->
803803

804-
* `host` {string} The hostname to verify the certificate against
804+
* `hostname` {string} The hostname to verify the certificate against
805805
* `cert` {Object} An object representing the peer's certificate. The returned
806806
object has some properties corresponding to the fields of the certificate.
807807
* Returns: {Error|undefined}
808808

809-
Verifies the certificate `cert` is issued to host `host`.
809+
Verifies the certificate `cert` is issued to `hostname`.
810810

811811
Returns {Error} object, populating it with the reason, host, and cert on
812812
failure. On success, returns {undefined}.

lib/tls.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ function check(hostParts, pattern, wildcards) {
161161
}
162162

163163
let urlWarningEmitted = false;
164-
exports.checkServerIdentity = function checkServerIdentity(host, cert) {
164+
exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
165165
const subject = cert.subject;
166166
const altNames = cert.subjectaltname;
167167
const dnsNames = [];
168168
const uriNames = [];
169169
const ips = [];
170170

171-
host = '' + host;
171+
hostname = '' + hostname;
172172

173173
if (altNames) {
174174
for (const name of altNames.split(', ')) {
@@ -200,14 +200,14 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
200200
let valid = false;
201201
let reason = 'Unknown reason';
202202

203-
if (net.isIP(host)) {
204-
valid = ips.includes(canonicalizeIP(host));
203+
if (net.isIP(hostname)) {
204+
valid = ips.includes(canonicalizeIP(hostname));
205205
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(', ')}`;
207207
// TODO(bnoordhuis) Also check URI SANs that are IP addresses.
208208
} 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);
211211
const wildcard = (pattern) => check(hostParts, pattern, true);
212212
const noWildcard = (pattern) => check(hostParts, pattern, false);
213213

@@ -221,11 +221,12 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
221221
valid = wildcard(cn);
222222

223223
if (!valid)
224-
reason = `Host: ${host}. is not cert's CN: ${cn}`;
224+
reason = `Host: ${hostname}. is not cert's CN: ${cn}`;
225225
} else {
226226
valid = dnsNames.some(wildcard) || uriNames.some(noWildcard);
227227
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}`;
229230
}
230231
} else {
231232
reason = 'Cert is empty';
@@ -234,7 +235,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
234235
if (!valid) {
235236
const err = new ERR_TLS_CERT_ALTNAME_INVALID(reason);
236237
err.reason = reason;
237-
err.host = host;
238+
err.host = hostname;
238239
err.cert = cert;
239240
return err;
240241
}

0 commit comments

Comments
 (0)