|
|
@ -45,60 +45,8 @@ function getRootCerts(callback) { |
|
|
|
+ ' return trusted;\n' |
|
|
|
+ '}, {});\n' |
|
|
|
+ '\n' |
|
|
|
+ 'function getTrusted(pem) {\n' |
|
|
|
+ ' pem = parsePEM(pem)[0].pem;\n' |
|
|
|
+ ' if (!Object.prototype.hasOwnProperty.call(trusted, pem)) return;\n' |
|
|
|
+ ' return trusted[pem];\n' |
|
|
|
+ '}\n' |
|
|
|
+ '\n' |
|
|
|
+ 'function getCert(name) {\n' |
|
|
|
+ ' name = name.replace(/^\s+|\s+$/g, "");\n' |
|
|
|
+ ' if (!Object.prototype.hasOwnProperty.call(certs, name)) return;\n' |
|
|
|
+ ' return certs[name];\n' |
|
|
|
+ '}\n' |
|
|
|
+ '\n' |
|
|
|
+ 'function parsePEM(pem) {\n' |
|
|
|
+ ' pem = pem + "";\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' |
|
|
|
+ ' headers = parts[0].trim().split(/[\\r\\n]/).reduce(function(out, line) {\n' |
|
|
|
+ ' var parts = line.split(/:[ \\t]+/);\n' |
|
|
|
+ ' var key = parts[0].trim().toLowerCase();\n' |
|
|
|
+ ' var value = (parts.slice(1).join("") || "").trim();\n' |
|
|
|
+ ' out[key] = value;\n' |
|
|
|
+ ' return out;\n' |
|
|
|
+ ' }, {});\n' |
|
|
|
+ ' pem = parts.slice(1).join("");\n' |
|
|
|
+ ' }\n' |
|
|
|
+ ' pem = pem.replace(/\\s+/g, "");\n' |
|
|
|
+' var der = pem\n' |
|
|
|
+ ' ? new Buffer(pem, "base64")\n' |
|
|
|
+ ' : null;\n' |
|
|
|
+ ' return [{\n' |
|
|
|
+ ' headers: headers,\n' |
|
|
|
+ ' pem: pem,\n' |
|
|
|
+ ' der: der,\n' |
|
|
|
+ ' body: der || new Buffer([0])\n' |
|
|
|
+ ' }];\n' |
|
|
|
+ '}\n' |
|
|
|
+ '\n' |
|
|
|
+ 'exports.certs = certs;\n' |
|
|
|
+ 'exports.trusted = trusted;\n' |
|
|
|
+ 'exports.getCert = getCert;\n' |
|
|
|
+ 'exports.getTrusted = getTrusted;\n'; |
|
|
|
+ 'exports.parsePEM = parsePEM;\n'; |
|
|
|
+ 'exports.trusted = trusted;\n'; |
|
|
|
return callback(null, body); |
|
|
|
}); |
|
|
|
} |
|
|
|