Skip to content

Commit

Permalink
tls: fix inconsistent (hostname vs host)
Browse files Browse the repository at this point in the history
Updated error messages and function arguments
Refs: nodejs#20892
  • Loading branch information
thatshailesh committed Jun 21, 2018
1 parent 40b1f08 commit e7dc777
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ exports.convertALPNProtocols = function(protocols, out) {
}
};

function unfqdn(host) {
return host.replace(/[.]$/, '');
function unfqdn(hostname) {
return hostname.replace(/[.]$/, '');
}

function splitHost(host) {
function splitHost(hostname) {
// String#toLowerCase() is locale-sensitive so we use
// a conservative version that only lowercases A-Z.
const replacer = (c) => String.fromCharCode(32 + c.charCodeAt(0));
return unfqdn(host).replace(/[A-Z]/g, replacer).split('.');
return unfqdn(hostname).replace(/[A-Z]/g, replacer).split('.');
}

function check(hostParts, pattern, wildcards) {
Expand Down Expand Up @@ -221,12 +221,12 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
valid = wildcard(cn);

if (!valid)
reason = `Host: ${hostname}. is not cert's CN: ${cn}`;
reason = `Hostname: ${hostname} is not cert's CN: ${cn}`;
} else {
valid = dnsNames.some(wildcard) || uriNames.some(noWildcard);
if (!valid)
reason =
`Host: ${hostname}. is not in the cert's altnames: ${altNames}`;
`Hostname: ${hostname} is not in the cert's altnames: ${altNames}`;
}
} else {
reason = 'Cert is empty';
Expand Down
40 changes: 20 additions & 20 deletions test/parallel/test-tls-check-server-identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ const tests = [
{
host: false,
cert: { subject: { CN: 'a.com' } },
error: 'Host: false. is not cert\'s CN: a.com'
error: 'Hostname: false is not cert\'s CN: a.com'
},
{
host: null,
cert: { subject: { CN: 'a.com' } },
error: 'Host: null. is not cert\'s CN: a.com'
error: 'Hostname: null is not cert\'s CN: a.com'
},
{
host: undefined,
cert: { subject: { CN: 'a.com' } },
error: 'Host: undefined. is not cert\'s CN: a.com'
error: 'Hostname: undefined is not cert\'s CN: a.com'
},

// Basic CN handling
Expand All @@ -61,37 +61,37 @@ const tests = [
{
host: 'a.com',
cert: { subject: { CN: 'b.com' } },
error: 'Host: a.com. is not cert\'s CN: b.com'
error: 'Hostname: a.com is not cert\'s CN: b.com'
},
{ host: 'a.com', cert: { subject: { CN: 'a.com.' } } },
{
host: 'a.com',
cert: { subject: { CN: '.a.com' } },
error: 'Host: a.com. is not cert\'s CN: .a.com'
error: 'Hostname: a.com is not cert\'s CN: .a.com'
},

// Wildcards in CN
{ host: 'b.a.com', cert: { subject: { CN: '*.a.com' } } },
{
host: 'ba.com',
cert: { subject: { CN: '*.a.com' } },
error: 'Host: ba.com. is not cert\'s CN: *.a.com'
error: 'Hostname: ba.com is not cert\'s CN: *.a.com'
},
{
host: '\n.b.com',
cert: { subject: { CN: '*n.b.com' } },
error: 'Host: \n.b.com. is not cert\'s CN: *n.b.com'
error: 'Hostname: \n.b.com is not cert\'s CN: *n.b.com'
},
{ host: 'b.a.com', cert: {
subjectaltname: 'DNS:omg.com',
subject: { CN: '*.a.com' } },
error: 'Host: b.a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: b.a.com is not in the cert\'s altnames: ' +
'DNS:omg.com'
},
{
host: 'b.a.com',
cert: { subject: { CN: 'b*b.a.com' } },
error: 'Host: b.a.com. is not cert\'s CN: b*b.a.com'
error: 'Hostname: b.a.com is not cert\'s CN: b*b.a.com'
},

// Empty Cert
Expand All @@ -114,15 +114,15 @@ const tests = [
subjectaltname: 'DNS:*',
subject: { CN: 'b.com' }
},
error: 'Host: a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.com is not in the cert\'s altnames: ' +
'DNS:*'
},
{
host: 'a.com', cert: {
subjectaltname: 'DNS:*.com',
subject: { CN: 'b.com' }
},
error: 'Host: a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.com is not in the cert\'s altnames: ' +
'DNS:*.com'
},
{
Expand All @@ -136,15 +136,15 @@ const tests = [
subjectaltname: 'DNS:*.a.com',
subject: { CN: 'a.com' }
},
error: 'Host: a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.com is not in the cert\'s altnames: ' +
'DNS:*.a.com'
},
{
host: 'a.com', cert: {
subjectaltname: 'DNS:*.a.com',
subject: { CN: 'b.com' }
},
error: 'Host: a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.com is not in the cert\'s altnames: ' +
'DNS:*.a.com'
},
{
Expand All @@ -166,7 +166,7 @@ const tests = [
subjectaltname: 'DNS:*.a.com',
subject: {}
},
error: 'Host: a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.com is not in the cert\'s altnames: ' +
'DNS:*.a.com'
},
{
Expand All @@ -180,7 +180,7 @@ const tests = [
subjectaltname: 'DNS:*.a.com',
subject: {}
},
error: 'Host: c.b.a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: c.b.a.com is not in the cert\'s altnames: ' +
'DNS:*.a.com'
},
{
Expand All @@ -200,7 +200,7 @@ const tests = [
subjectaltname: 'DNS:*b.a.com',
subject: {}
},
error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.b.a.com is not in the cert\'s altnames: ' +
'DNS:*b.a.com'
},
// Multiple DNS names
Expand All @@ -222,7 +222,7 @@ const tests = [
subjectaltname: 'URI:http://*.b.a.com/',
subject: {}
},
error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.b.a.com is not in the cert\'s altnames: ' +
'URI:http://*.b.a.com/'
},
// Invalid URI
Expand All @@ -238,7 +238,7 @@ const tests = [
subjectaltname: 'IP Address:127.0.0.1',
subject: {}
},
error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' +
error: 'Hostname: a.b.a.com is not in the cert\'s altnames: ' +
'IP Address:127.0.0.1'
},
{
Expand Down Expand Up @@ -267,7 +267,7 @@ const tests = [
subjectaltname: 'DNS:a.com',
subject: { CN: 'localhost' }
},
error: 'Host: localhost. is not in the cert\'s altnames: ' +
error: 'Hostname: localhost is not in the cert\'s altnames: ' +
'DNS:a.com'
},
// IDNA
Expand All @@ -281,7 +281,7 @@ const tests = [
{
host: 'xn--bcher-kva.example.com',
cert: { subject: { CN: 'xn--*.example.com' } },
error: 'Host: xn--bcher-kva.example.com. is not cert\'s CN: ' +
error: 'Hostname: xn--bcher-kva.example.com is not cert\'s CN: ' +
'xn--*.example.com',
},
];
Expand Down

0 comments on commit e7dc777

Please sign in to comment.