tls: using %StringSplit to split `cert.subjectaltname`
authorYazhong Liu <yorkiefixer@gmail.com>
Sun, 22 Jun 2014 15:34:47 +0000 (23:34 +0800)
committerFedor Indutny <fedor@indutny.com>
Tue, 24 Jun 2014 05:55:26 +0000 (09:55 +0400)
Signed-off-by: Fedor Indutny <fedor@indutny.com>
lib/tls.js

index 197e968e08be61ace4fc48880ee8b38401293c2a..9345632353b3a4a5c84b48b1f92e5164d1a2853c 100644 (file)
@@ -122,12 +122,15 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
   // Walk through altnames and generate lists of those names
   if (cert.subjectaltname) {
     cert.subjectaltname.split(/, /g).forEach(function(altname) {
-      if (/^DNS:/.test(altname)) {
-        dnsNames.push(altname.slice(4));
-      } else if (/^IP Address:/.test(altname)) {
-        ips.push(altname.slice(11));
-      } else if (/^URI:/.test(altname)) {
-        var uri = url.parse(altname.slice(4));
+      var option = altname.match(/^(DNS|IP Address|URI):(.*)$/);
+      if (!option)
+        return;
+      if (option[1] === 'DNS') {
+        dnsNames.push(option[2]);
+      } else if (option[1] === 'IP Address') {
+        ips.push(option[2]);
+      } else if (option[1] === 'URI') {
+        var uri = url.parse(option[2]);
         if (uri) uriNames.push(uri.hostname);
       }
     });