paypro: potentially stop using jsrsasign in node.
This commit is contained in:
parent
0db74604db
commit
eb9fd652d2
|
@ -220,6 +220,7 @@ PayPro.prototype.sign = function(key) {
|
|||
var trusted = [].concat(pki_data).every(function(cert) {
|
||||
var der = cert.toString('hex');
|
||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||
// var pem = DERtoPEM(der, 'CERTIFICATE');
|
||||
return !!RootCerts[pem.replace(/\s+/g, '')];
|
||||
});
|
||||
|
||||
|
@ -264,6 +265,7 @@ PayPro.prototype.verify = function() {
|
|||
return [].concat(pki_data).every(function(cert) {
|
||||
var der = cert.toString('hex');
|
||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||
// var pem = DERtoPEM(der, 'CERTIFICATE');
|
||||
|
||||
if (!RootCerts[pem.replace(/\s+/g, '')]) {
|
||||
// throw new Error('Unstrusted certificate.');
|
||||
|
@ -293,4 +295,58 @@ PayPro.prototype.sinVerify = function() {
|
|||
return Message.verifyWithPubKey(pubkey, buf, sig);
|
||||
};
|
||||
|
||||
// Helpers
|
||||
|
||||
function PEMtoDER(pem) {
|
||||
pem = pem.replace(/^-----END [^-]+-----$/gmi/, '');
|
||||
var parts = pem.split(/-----BEGIN [^-]+-----/);
|
||||
return parts.map(function(part) {
|
||||
part = part.replace(/\s+/g, '');
|
||||
return new Buffer(part, 'base64');
|
||||
});
|
||||
}
|
||||
|
||||
function PEMtoDERParam(pem, param) {
|
||||
var start = new RegExp('(?=-----BEGIN ' + param + '-----)', 'i');
|
||||
var end = new RegExp('^-----END ' + param + '-----$', 'gmi');
|
||||
pem = pem.replace(end, '');
|
||||
var parts = pem.split(start);
|
||||
return parts.map(function(part) {
|
||||
part = part.replace(/\s+/g, '');
|
||||
var type = /-----BEGIN ([^-]+)-----/.exec(part)[1];
|
||||
part = part.replace(/-----BEGIN ([^-]+)-----/g, '');
|
||||
if (type !== param) return;
|
||||
return new Buffer(part, 'base64');
|
||||
}).filter(Boolean);
|
||||
}
|
||||
|
||||
function wrapText(text, cols) {
|
||||
var j = 0;
|
||||
var part = '';
|
||||
var parts = [];
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
if (j === cols) {
|
||||
parts.push(part);
|
||||
j = 0;
|
||||
part = ''
|
||||
continue;
|
||||
}
|
||||
part += text[i];
|
||||
j++;
|
||||
}
|
||||
var total = parts.join('').length;
|
||||
if (total < text.length) {
|
||||
parts.push(text.slice(-(text.length - total)));
|
||||
}
|
||||
return parts.join('\n');
|
||||
}
|
||||
|
||||
function DERtoPEM(der, type) {
|
||||
var type = type || 'UNKNOWN';
|
||||
return ''
|
||||
+ '-----BEGIN ' + type + '-----'
|
||||
+ wrapText(der.toString('base64'), 64)
|
||||
+ '-----END ' + type + '-----';
|
||||
}
|
||||
|
||||
module.exports = PayPro;
|
||||
|
|
Loading…
Reference in New Issue