tls: remove util and calls to util.format
Currently util.format is being used for string templating in tls. By replacing all of the instances of util.format with backtick string we can remove the need to require util in tls all together. PR-URL: https://github.com/nodejs/node/pull/3456 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
cdcf00a0b9
commit
6b0c906e6b
18
lib/tls.js
18
lib/tls.js
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const util = require('util');
|
|
||||||
const binding = process.binding('crypto');
|
const binding = process.binding('crypto');
|
||||||
const Buffer = require('buffer').Buffer;
|
const Buffer = require('buffer').Buffer;
|
||||||
const constants = require('constants');
|
const constants = require('constants');
|
||||||
@ -141,9 +140,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
|
|||||||
return ip === host;
|
return ip === host;
|
||||||
});
|
});
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
reason = util.format('IP: %s is not in the cert\'s list: %s',
|
reason = `IP: ${host} is not in the cert's list: ${ips.join(', ')}`;
|
||||||
host,
|
|
||||||
ips.join(', '));
|
|
||||||
}
|
}
|
||||||
} else if (cert.subject) {
|
} else if (cert.subject) {
|
||||||
// Transform hostname to canonical form
|
// Transform hostname to canonical form
|
||||||
@ -189,13 +186,11 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
|
|||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
if (cert.subjectaltname) {
|
if (cert.subjectaltname) {
|
||||||
reason = util.format('Host: %s is not in the cert\'s altnames: %s',
|
reason =
|
||||||
host,
|
`Host: ${host} is not in the cert's altnames: ` +
|
||||||
cert.subjectaltname);
|
`${cert.subjectaltname}`;
|
||||||
} else {
|
} else {
|
||||||
reason = util.format('Host: %s is not cert\'s CN: %s',
|
reason = `Host: ${host} is not cert's CN: ${cert.subject.CN}`;
|
||||||
host,
|
|
||||||
cert.subject.CN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -204,8 +199,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
|
|||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
var err = new Error(
|
var err = new Error(
|
||||||
util.format('Hostname/IP doesn\'t match certificate\'s altnames: %j',
|
`Hostname/IP doesn't match certificate's altnames: "${reason}"`);
|
||||||
reason));
|
|
||||||
err.reason = reason;
|
err.reason = reason;
|
||||||
err.host = host;
|
err.host = host;
|
||||||
err.cert = cert;
|
err.cert = cert;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user