Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: fix inconsistent documentation (host vs hostname) #20933

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ added: v0.5.3
`cert`, `ca`, etc).

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

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

## tls.checkServerIdentity(host, cert)
## tls.checkServerIdentity(hostname, cert)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding change needs to also be made in lib/tls.js so that argument names in error messages and stack traces match those in documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott Made changes to lib/tls.js as well

<!-- YAML
added: v0.8.4
-->

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

Verifies the certificate `cert` is issued to host `host`.
Verifies the certificate `cert` is issued to `hostname`.

Returns {Error} object, populating it with the reason, host, and cert on
failure. On success, returns {undefined}.
Expand Down
21 changes: 11 additions & 10 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ function check(hostParts, pattern, wildcards) {
}

let urlWarningEmitted = false;
exports.checkServerIdentity = function checkServerIdentity(host, cert) {
exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
const subject = cert.subject;
const altNames = cert.subjectaltname;
const dnsNames = [];
const uriNames = [];
const ips = [];

host = '' + host;
hostname = '' + hostname;

if (altNames) {
for (const name of altNames.split(', ')) {
Expand Down Expand Up @@ -200,14 +200,14 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
let valid = false;
let reason = 'Unknown reason';

if (net.isIP(host)) {
valid = ips.includes(canonicalizeIP(host));
if (net.isIP(hostname)) {
valid = ips.includes(canonicalizeIP(hostname));
if (!valid)
reason = `IP: ${host} is not in the cert's list: ${ips.join(', ')}`;
reason = `IP: ${hostname} is not in the cert's list: ${ips.join(', ')}`;
// TODO(bnoordhuis) Also check URI SANs that are IP addresses.
} else if (subject) {
host = unfqdn(host); // Remove trailing dot for error messages.
const hostParts = splitHost(host);
hostname = unfqdn(hostname); // Remove trailing dot for error messages.
const hostParts = splitHost(hostname);
const wildcard = (pattern) => check(hostParts, pattern, true);
const noWildcard = (pattern) => check(hostParts, pattern, false);

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

if (!valid)
reason = `Host: ${host}. is not cert's CN: ${cn}`;
reason = `Host: ${hostname}. is not cert's CN: ${cn}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should we also change the message prefix from Host: to Hostname:? Or is this not done because it would be a server-major change?

Copy link
Member

@Trott Trott May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpinca Hard to say. It's an error with a code (ERR_TLS_CERT_ALTNAME_INVALID). So it should be a patch change to update the message, but I don't know that we ever officially decided that message changes are no longer breaking changes in those cases. So could go either way. Maybe make that change in a separate PR just to make sure any debate about it doesn't delay the rest of these changes?

Additionally, the period seems to be an error and should be removed here and in line 229.

EDIT: Oh, yeah, we're also setting err.reason which might be used elsewhere? So maybe best to be cautious and do this in a separate PR and then if people want to run CITGM and other stuff, it doesn't delay these other more straightforward changes.

} else {
valid = dnsNames.some(wildcard) || uriNames.some(noWildcard);
if (!valid)
reason = `Host: ${host}. is not in the cert's altnames: ${altNames}`;
reason =
`Host: ${hostname}. is not in the cert's altnames: ${altNames}`;
}
} else {
reason = 'Cert is empty';
Expand All @@ -234,7 +235,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
if (!valid) {
const err = new ERR_TLS_CERT_ALTNAME_INVALID(reason);
err.reason = reason;
err.host = host;
err.host = hostname;
err.cert = cert;
return err;
}
Expand Down