diff --git a/lib/tls.js b/lib/tls.js index 714fdebfc079bd..0e22242bc47feb 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -151,7 +151,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { host, ips.join(', ')); } - } else { + } else if (cert.subject) { // Transform hostname to canonical form if (!/\.$/.test(host)) host += '.'; @@ -204,6 +204,8 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { cert.subject.CN); } } + } else { + reason = 'Cert is empty'; } if (!valid) { diff --git a/test/parallel/test-tls-check-server-identity.js b/test/parallel/test-tls-check-server-identity.js index e659f40aa90232..8d2155b94ea9af 100644 --- a/test/parallel/test-tls-check-server-identity.js +++ b/test/parallel/test-tls-check-server-identity.js @@ -30,6 +30,13 @@ var tests = [ 'DNS:omg.com' }, + // Empty Cert + { + host: 'a.com', + cert: { }, + error: 'Cert is empty' + }, + // Multiple CN fields { host: 'foo.com', cert: {