|
|
@ -2,7 +2,7 @@ |
|
|
|
var protobufjs = protobufjs || require('protobufjs/dist/ProtoBuf'); |
|
|
|
var Message = Message || require('./Message'); |
|
|
|
|
|
|
|
var KJUR = require('jsrsasign'); |
|
|
|
// var KJUR = require('jsrsasign');
|
|
|
|
var RootCerts = require('./RootCerts'); |
|
|
|
|
|
|
|
// BIP 70 - payment protocol
|
|
|
@ -242,6 +242,7 @@ PayPro.prototype.verify = function() { |
|
|
|
}; |
|
|
|
|
|
|
|
PayPro.prototype.x509Sign = function(key) { |
|
|
|
var self = this; |
|
|
|
var crypto = require('crypto'); |
|
|
|
var pki_type = this.get('pki_type'); |
|
|
|
var pki_data = this.get('pki_data'); // contains one or more x509 certs
|
|
|
@ -250,8 +251,8 @@ PayPro.prototype.x509Sign = 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 = this._DERtoPEM(der, 'CERTIFICATE');
|
|
|
|
// var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
|
|
|
var pem = self._DERtoPEM(der, 'CERTIFICATE'); |
|
|
|
return !!RootCerts[pem.replace(/\s+/g, '')]; |
|
|
|
}); |
|
|
|
|
|
|
@ -267,6 +268,7 @@ PayPro.prototype.x509Sign = function(key) { |
|
|
|
}; |
|
|
|
|
|
|
|
PayPro.prototype.x509Verify = function() { |
|
|
|
var self = this; |
|
|
|
var crypto = require('crypto'); |
|
|
|
var pki_type = this.get('pki_type'); |
|
|
|
var sig = this.get('signature'); |
|
|
@ -280,8 +282,8 @@ PayPro.prototype.x509Verify = function() { |
|
|
|
|
|
|
|
return [].concat(pki_data).every(function(cert) { |
|
|
|
var der = cert.toString('hex'); |
|
|
|
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE'); |
|
|
|
// var pem = this._DERtoPEM(der, 'CERTIFICATE');
|
|
|
|
// var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
|
|
|
var pem = self._DERtoPEM(der, 'CERTIFICATE'); |
|
|
|
|
|
|
|
if (!RootCerts[pem.replace(/\s+/g, '')]) { |
|
|
|
// throw new Error('Unstrusted certificate.');
|
|
|
@ -313,6 +315,9 @@ PayPro.prototype._PEMtoDER = function(pem) { |
|
|
|
}; |
|
|
|
|
|
|
|
PayPro.prototype._PEMtoDERParam = function(pem, param) { |
|
|
|
if (Buffer.isBuffer(pem)) { |
|
|
|
pem = pem.toString(); |
|
|
|
} |
|
|
|
var start = new RegExp('(?=-----BEGIN ' + (param || '[^-]+') + '-----)', 'i'); |
|
|
|
var end = new RegExp('^-----END ' + (param || '[^-]+') + '-----$', 'gmi'); |
|
|
|
pem = pem.replace(end, ''); |
|
|
@ -327,6 +332,9 @@ PayPro.prototype._PEMtoDERParam = function(pem, param) { |
|
|
|
}; |
|
|
|
|
|
|
|
PayPro.prototype._DERtoPEM = function(der, type) { |
|
|
|
if (typeof der === 'string') { |
|
|
|
der = new Buffer(der, 'hex'); |
|
|
|
} |
|
|
|
var type = type || 'UNKNOWN'; |
|
|
|
der = der.toString('base64'); |
|
|
|
der = der.replace(/(.{64})/g, '$1\r\n'); |
|
|
|