diff --git a/browser/root-certs b/browser/root-certs index ec7b733..943bbe4 100755 --- a/browser/root-certs +++ b/browser/root-certs @@ -46,7 +46,7 @@ function getRootCerts(callback) { + '}, {});\n' + '\n' + 'function getTrusted(pem) {\n' - + ' pem = parsePEM(pem).pem;\n' + + ' pem = parsePEM(pem)[0].pem;\n' + ' if (!Object.prototype.hasOwnProperty.call(trusted, pem)) return;\n' + ' return trusted[pem];\n' + '}\n' @@ -59,8 +59,17 @@ function getRootCerts(callback) { + '\n' + 'function parsePEM(pem) {\n' + ' pem = pem + "";\n' - + ' pem = pem.replace(/-----BEGIN CERTIFICATE-----/g, "");\n' - + ' pem = pem.replace(/-----END CERTIFICATE-----/g, "");\n' + + ' var concatted = pem.trim().split(/-----BEGIN [^\\-\\r\\n]+-----/);\n' + + ' if (concatted.length > 2) {\n' + + ' return concatted.reduce(function(out, pem) {\n' + + ' if (!pem) return out;\n' + + ' pem = parsePEM(pem)[0].pem;\n' + + ' if (pem) out.push(pem);\n' + + ' return out;\n' + + ' }, []);\n' + + ' }\n' + + ' pem = pem.replace(/-----BEGIN [^\\-\\r\\n]+-----/, "");\n' + + ' pem = pem.replace(/-----END [^\\-\\r\\n]+-----/, "");\n' + ' var parts = pem.trim().split(/(?:\\r?\\n){2,}/);\n' + ' var headers = {};\n' + ' if (parts.length > 1) {\n' @@ -77,12 +86,12 @@ function getRootCerts(callback) { +' var der = pem\n' + ' ? new Buffer(pem, "base64")\n' + ' : null;\n' - + ' return {\n' + + ' return [{\n' + ' headers: headers,\n' + ' pem: pem,\n' + ' der: der,\n' + ' body: der || new Buffer([0])\n' - + ' };\n' + + ' }];\n' + '}\n' + '\n' + 'exports.certs = certs;\n' diff --git a/lib/common/RootCerts.js b/lib/common/RootCerts.js index 20c7a14..ee28620 100644 --- a/lib/common/RootCerts.js +++ b/lib/common/RootCerts.js @@ -3715,7 +3715,7 @@ var trusted = Object.keys(certs).reduce(function(trusted, key) { }, {}); function getTrusted(pem) { - pem = parsePEM(pem).pem; + pem = parsePEM(pem)[0].pem; if (!Object.prototype.hasOwnProperty.call(trusted, pem)) return; return trusted[pem]; } @@ -3728,8 +3728,17 @@ function getCert(name) { function parsePEM(pem) { pem = pem + ""; - pem = pem.replace(/-----BEGIN CERTIFICATE-----/g, ""); - pem = pem.replace(/-----END CERTIFICATE-----/g, ""); + var concatted = pem.trim().split(/-----BEGIN [^\-\r\n]+-----/); + if (concatted.length > 2) { + return concatted.reduce(function(out, pem) { + if (!pem) return out; + pem = parsePEM(pem)[0].pem; + if (pem) out.push(pem); + return out; + }, []); + } + pem = pem.replace(/-----BEGIN [^\-\r\n]+-----/, ""); + pem = pem.replace(/-----END [^\-\r\n]+-----/, ""); var parts = pem.trim().split(/(?:\r?\n){2,}/); var headers = {}; if (parts.length > 1) { @@ -3746,12 +3755,12 @@ function parsePEM(pem) { var der = pem ? new Buffer(pem, "base64") : null; - return { + return [{ headers: headers, pem: pem, der: der, body: der || new Buffer([0]) - }; + }]; } exports.certs = certs;