Browse Source

paypro: move x509 sign and verify to their own methods.

patch-2
Christopher Jeffrey 11 years ago
parent
commit
aafbca46d9
  1. 55
      lib/PayPro.js

55
lib/PayPro.js

@ -212,6 +212,36 @@ PayPro.prototype.sign = function(key) {
if (pki_type === 'SIN') { if (pki_type === 'SIN') {
var sig = this.sinSign(key); var sig = this.sinSign(key);
} else if (pki_type === 'x509+sha1' || pki_type === 'x509+sha256') { } else if (pki_type === 'x509+sha1' || pki_type === 'x509+sha256') {
var sig = this.x509Sign(key);
} else if (pki_type === 'none') {
return this;
} else {
throw new Error('Unsupported pki_type');
}
this.set('signature', sig);
return this;
};
PayPro.prototype.verify = function() {
if (this.messageType !== 'PaymentRequest')
throw new Error('Verifying can only be performed on a PaymentRequest');
var pki_type = this.get('pki_type');
if (pki_type === 'SIN') {
return this.sinVerify();
} else if (pki_type === 'x509+sha1' || pki_type === 'x509+sha256') {
return this.x509Verify();
} else if (pki_type === 'none') {
return true;
}
throw new Error('Unsupported pki_type');
};
PayPro.prototype.x509Sign = function(key) {
var crypto = require('crypto'); var crypto = require('crypto');
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
var details = this.get('serialized_payment_details'); var details = this.get('serialized_payment_details');
@ -232,26 +262,10 @@ PayPro.prototype.sign = function(key) {
var buf = this.serializeForSig(); var buf = this.serializeForSig();
signature.update(buf); signature.update(buf);
var sig = signature.sign(key); var sig = signature.sign(key);
} else if (pki_type === 'none') { return sig;
return this;
} else {
throw new Error('Unsupported pki_type');
}
this.set('signature', sig);
return this;
}; };
PayPro.prototype.verify = function() { PayPro.prototype.x509Verify = function() {
if (this.messageType !== 'PaymentRequest')
throw new Error('Verifying can only be performed on a PaymentRequest');
var pki_type = this.get('pki_type');
if (pki_type === 'SIN') {
return this.sinVerify();
} else if (pki_type === 'x509+sha1' || pki_type === 'x509+sha256') {
var crypto = require('crypto'); var crypto = require('crypto');
var sig = this.get('signature'); var sig = this.get('signature');
var pki_data = this.get('pki_data'); var pki_data = this.get('pki_data');
@ -273,11 +287,6 @@ PayPro.prototype.verify = function() {
return verifier.verify(pem, sig); return verifier.verify(pem, sig);
}); });
} else if (pki_type === 'none') {
return true;
}
throw new Error('Unsupported pki_type');
}; };
//default signing function for prototype.sign //default signing function for prototype.sign

Loading…
Cancel
Save