paypro: add isTrusted function to RootCerts.

This commit is contained in:
Christopher Jeffrey 2014-07-21 13:59:55 -07:00
parent 672e667e9c
commit cec71a51fd
4 changed files with 26 additions and 6 deletions

View File

@ -29,13 +29,23 @@ function getRootCerts(callback) {
body = body.replace(/^"/gm, '+ "');
body = body.replace(/^\+ "-----B/gm, '"-----B');
body += ''
+ '\n'
+ '// Use hash table for efficiency:\n'
+ 'RootCerts = RootCerts.reduce(function(trusted, cert) {\n'
+ ' cert = cert.replace(/\\s+/g, "");\n'
+ ' trusted[cert] = true;\n'
+ ' return trusted;\n'
+ '}, {});\n'
+ 'module.exports = RootCerts;\n';
+ '\n'
+ 'function isTrusted(pem) {\n'
+ ' pem = pem + "";\n'
+ ' pem = pem.replace(/\\s+/g, "");\n'
+ ' return !!RootCerts[pem];\n'
+ '}\n'
+ '\n'
+ 'exports = RootCerts;\n'
+ 'exports.isTrusted = isTrusted;\n'
+ 'module.exports = exports;\n';
return callback(null, body);
});
}

View File

@ -251,7 +251,7 @@ PayPro.prototype.x509Sign = function(key) {
var trusted = [].concat(pki_data).every(function(cert) {
var der = cert.toString('hex');
var pem = self._DERtoPEM(der, 'CERTIFICATE');
return !!RootCerts[pem.replace(/\s+/g, '')];
return RootCerts.isTrusted(pem);
});
if (!trusted) {
@ -282,7 +282,7 @@ PayPro.prototype.x509Verify = function() {
var der = cert.toString('hex');
var pem = self._DERtoPEM(der, 'CERTIFICATE');
if (!RootCerts[pem.replace(/\s+/g, '')]) {
if (!RootCerts.isTrusted(pem)) {
// throw new Error('Unstrusted certificate.');
}

View File

@ -25,7 +25,7 @@ PayPro.sign = function(key) {
var trusted = [].concat(pki_data).every(function(cert) {
var der = cert.toString('hex');
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
return !!RootCerts[pem.replace(/\s+/g, '')];
return RootCerts.isTrusted(pem);
});
if (!trusted) {
@ -75,7 +75,7 @@ PayPro.verify = function() {
var der = cert.toString('hex');
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
if (!RootCerts[pem.replace(/\s+/g, '')]) {
if (!RootCerts.isTrusted(pem)) {
// throw new Error('Unstrusted certificate.');
}

View File

@ -3560,10 +3560,20 @@ var RootCerts = [
+ "-----END CERTIFICATE-----\n",
];
// Use hash table for efficiency:
RootCerts = RootCerts.reduce(function(trusted, cert) {
cert = cert.replace(/\s+/g, "");
trusted[cert] = true;
return trusted;
}, {});
module.exports = RootCerts;
function isTrusted(pem) {
pem = pem + "";
pem = pem.replace(/\s+/g, "");
return !!RootCerts[pem];
}
exports = RootCerts;
exports.isTrusted = isTrusted;
module.exports = exports;