From e7dc7771dd667f33256dffd8f38f0126ab6b065a Mon Sep 17 00:00:00 2001 From: Shailesh Shekhawat Date: Fri, 22 Jun 2018 02:29:38 +0800 Subject: [PATCH] tls: fix inconsistent (hostname vs host) Updated error messages and function arguments Refs: https://github.com/nodejs/node/issues/20892 --- lib/tls.js | 12 +++--- .../test-tls-check-server-identity.js | 40 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index f13c5c1c8601c2..69af13cd6fd43a 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -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) { @@ -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'; diff --git a/test/parallel/test-tls-check-server-identity.js b/test/parallel/test-tls-check-server-identity.js index fe27770c1ebc84..163c304f93953f 100644 --- a/test/parallel/test-tls-check-server-identity.js +++ b/test/parallel/test-tls-check-server-identity.js @@ -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 @@ -61,13 +61,13 @@ 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 @@ -75,23 +75,23 @@ const tests = [ { 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 @@ -114,7 +114,7 @@ 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:*' }, { @@ -122,7 +122,7 @@ const tests = [ 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' }, { @@ -136,7 +136,7 @@ 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' }, { @@ -144,7 +144,7 @@ const tests = [ 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' }, { @@ -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' }, { @@ -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' }, { @@ -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 @@ -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 @@ -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' }, { @@ -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 @@ -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', }, ];