paypro: start using our own DERtoPEM functions so we don't have to require jsrsasign.
This commit is contained in:
parent
fa1c4b3570
commit
92b7fad243
@ -2,7 +2,7 @@
|
|||||||
var protobufjs = protobufjs || require('protobufjs/dist/ProtoBuf');
|
var protobufjs = protobufjs || require('protobufjs/dist/ProtoBuf');
|
||||||
var Message = Message || require('./Message');
|
var Message = Message || require('./Message');
|
||||||
|
|
||||||
var KJUR = require('jsrsasign');
|
// var KJUR = require('jsrsasign');
|
||||||
var RootCerts = require('./RootCerts');
|
var RootCerts = require('./RootCerts');
|
||||||
|
|
||||||
// BIP 70 - payment protocol
|
// BIP 70 - payment protocol
|
||||||
@ -242,6 +242,7 @@ PayPro.prototype.verify = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PayPro.prototype.x509Sign = function(key) {
|
PayPro.prototype.x509Sign = function(key) {
|
||||||
|
var self = this;
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var pki_type = this.get('pki_type');
|
var pki_type = this.get('pki_type');
|
||||||
var pki_data = this.get('pki_data'); // contains one or more x509 certs
|
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 trusted = [].concat(pki_data).every(function(cert) {
|
||||||
var der = cert.toString('hex');
|
var der = cert.toString('hex');
|
||||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
// var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||||
// var pem = this._DERtoPEM(der, 'CERTIFICATE');
|
var pem = self._DERtoPEM(der, 'CERTIFICATE');
|
||||||
return !!RootCerts[pem.replace(/\s+/g, '')];
|
return !!RootCerts[pem.replace(/\s+/g, '')];
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -267,6 +268,7 @@ PayPro.prototype.x509Sign = function(key) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PayPro.prototype.x509Verify = function() {
|
PayPro.prototype.x509Verify = function() {
|
||||||
|
var self = this;
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var pki_type = this.get('pki_type');
|
var pki_type = this.get('pki_type');
|
||||||
var sig = this.get('signature');
|
var sig = this.get('signature');
|
||||||
@ -280,8 +282,8 @@ PayPro.prototype.x509Verify = function() {
|
|||||||
|
|
||||||
return [].concat(pki_data).every(function(cert) {
|
return [].concat(pki_data).every(function(cert) {
|
||||||
var der = cert.toString('hex');
|
var der = cert.toString('hex');
|
||||||
var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
// var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
|
||||||
// var pem = this._DERtoPEM(der, 'CERTIFICATE');
|
var pem = self._DERtoPEM(der, 'CERTIFICATE');
|
||||||
|
|
||||||
if (!RootCerts[pem.replace(/\s+/g, '')]) {
|
if (!RootCerts[pem.replace(/\s+/g, '')]) {
|
||||||
// throw new Error('Unstrusted certificate.');
|
// throw new Error('Unstrusted certificate.');
|
||||||
@ -313,6 +315,9 @@ PayPro.prototype._PEMtoDER = function(pem) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PayPro.prototype._PEMtoDERParam = function(pem, param) {
|
PayPro.prototype._PEMtoDERParam = function(pem, param) {
|
||||||
|
if (Buffer.isBuffer(pem)) {
|
||||||
|
pem = pem.toString();
|
||||||
|
}
|
||||||
var start = new RegExp('(?=-----BEGIN ' + (param || '[^-]+') + '-----)', 'i');
|
var start = new RegExp('(?=-----BEGIN ' + (param || '[^-]+') + '-----)', 'i');
|
||||||
var end = new RegExp('^-----END ' + (param || '[^-]+') + '-----$', 'gmi');
|
var end = new RegExp('^-----END ' + (param || '[^-]+') + '-----$', 'gmi');
|
||||||
pem = pem.replace(end, '');
|
pem = pem.replace(end, '');
|
||||||
@ -327,6 +332,9 @@ PayPro.prototype._PEMtoDERParam = function(pem, param) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PayPro.prototype._DERtoPEM = function(der, type) {
|
PayPro.prototype._DERtoPEM = function(der, type) {
|
||||||
|
if (typeof der === 'string') {
|
||||||
|
der = new Buffer(der, 'hex');
|
||||||
|
}
|
||||||
var type = type || 'UNKNOWN';
|
var type = type || 'UNKNOWN';
|
||||||
der = der.toString('base64');
|
der = der.toString('base64');
|
||||||
der = der.replace(/(.{64})/g, '$1\r\n');
|
der = der.replace(/(.{64})/g, '$1\r\n');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user