|
|
@ -6,13 +6,16 @@ var expect = chai.expect; |
|
|
|
var bitcore = bitcore || require('../bitcore'); |
|
|
|
var fs = require('fs'); |
|
|
|
|
|
|
|
var KJUR = require('jsrsasign'); |
|
|
|
|
|
|
|
var PayPro = bitcore.PayPro; |
|
|
|
var Key = bitcore.Key; |
|
|
|
|
|
|
|
var x509 = { |
|
|
|
priv: fs.readFileSync(__dirname + '/data/x509.key'), |
|
|
|
pub: fs.readFileSync(__dirname + '/data/x509.pub'), |
|
|
|
crt: fs.readFileSync(__dirname + '/data/x509.der'), |
|
|
|
der: fs.readFileSync(__dirname + '/data/x509.der'), |
|
|
|
pem: fs.readFileSync(__dirname + '/data/x509.crt'), |
|
|
|
sig1: new Buffer(0), |
|
|
|
sig2: new Buffer(0), |
|
|
|
sig3: new Buffer(0) |
|
|
@ -276,7 +279,7 @@ describe('PayPro', function() { |
|
|
|
paypro.makePaymentRequest(); |
|
|
|
paypro.set('serialized_payment_details', pdbuf); |
|
|
|
paypro.set('pki_type', 'x509+sha256'); |
|
|
|
paypro.set('pki_data', x509.crt); |
|
|
|
paypro.set('pki_data', x509.der); |
|
|
|
paypro.sign(x509.priv); |
|
|
|
x509.sig1 = paypro.get('signature'); |
|
|
|
x509.sig1.length.should.be.greaterThan(0); |
|
|
@ -311,7 +314,7 @@ describe('PayPro', function() { |
|
|
|
paypro.set('serialized_payment_details', pdbuf); |
|
|
|
paypro.set('pki_type', 'x509+sha256'); |
|
|
|
paypro.set('signature', x509.sig1); // sig buffer
|
|
|
|
paypro.set('pki_data', x509.crt); // contains one or more x509 certs
|
|
|
|
paypro.set('pki_data', x509.der); // contains one or more x509 certs
|
|
|
|
var verify = paypro.verify(); |
|
|
|
verify.should.equal(true); |
|
|
|
}); |
|
|
@ -369,7 +372,7 @@ describe('PayPro', function() { |
|
|
|
|
|
|
|
paypro.set('serialized_payment_details', pdbuf); |
|
|
|
paypro.set('pki_type', 'x509+sha256'); |
|
|
|
paypro.set('pki_data', x509.crt); |
|
|
|
paypro.set('pki_data', x509.der); |
|
|
|
|
|
|
|
var sig = paypro.x509Sign(x509.priv); |
|
|
|
paypro.set('signature', sig); |
|
|
@ -393,7 +396,7 @@ describe('PayPro', function() { |
|
|
|
paypro.set('pki_type', 'x509+sha256'); |
|
|
|
|
|
|
|
paypro.set('signature', x509.sig2); // sig buffer
|
|
|
|
paypro.set('pki_data', x509.crt); // contains one or more x509 certs
|
|
|
|
paypro.set('pki_data', x509.der); // contains one or more x509 certs
|
|
|
|
|
|
|
|
var verify = paypro.x509Verify(); |
|
|
|
verify.should.equal(true); |
|
|
@ -412,7 +415,7 @@ describe('PayPro', function() { |
|
|
|
|
|
|
|
paypro.set('serialized_payment_details', pdbuf); |
|
|
|
paypro.set('pki_type', 'x509+sha1'); |
|
|
|
paypro.set('pki_data', x509.crt); |
|
|
|
paypro.set('pki_data', x509.der); |
|
|
|
|
|
|
|
var sig = paypro.x509Sign(x509.priv); |
|
|
|
paypro.set('signature', sig); |
|
|
@ -436,11 +439,36 @@ describe('PayPro', function() { |
|
|
|
paypro.set('pki_type', 'x509+sha1'); |
|
|
|
|
|
|
|
paypro.set('signature', x509.sig3); // sig buffer
|
|
|
|
paypro.set('pki_data', x509.crt); // contains one or more x509 certs
|
|
|
|
paypro.set('pki_data', x509.der); // contains one or more x509 certs
|
|
|
|
|
|
|
|
var verify = paypro.x509Verify(); |
|
|
|
verify.should.equal(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#PEMtoDER', function() { |
|
|
|
it('should convert a PEM cert to DER', function() { |
|
|
|
var paypro = new PayPro(); |
|
|
|
var der1 = paypro._PEMtoDERParam(x509.pem.toString(), 'CERTIFICATE').map(function(der) { |
|
|
|
return der.toString('hex'); |
|
|
|
}); |
|
|
|
der1 = der1[0]; |
|
|
|
var der2 = x509.der.toString('hex'); |
|
|
|
der1.should.equal(der2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#DERtoPEM', function() { |
|
|
|
it('convert a DER cert to PEM', function() { |
|
|
|
var paypro = new PayPro(); |
|
|
|
var pem1 = paypro._DERtoPEM(x509.der, 'CERTIFICATE'); |
|
|
|
var pem2 = KJUR.asn1.ASN1Util.getPEMStringFromHex(x509.der.toString('hex'), 'CERTIFICATE'); |
|
|
|
pem1 = pem1.trim(); |
|
|
|
pem2 = pem2.trim(); |
|
|
|
pem1 = pem1.replace(/\s+/g, ''); |
|
|
|
pem2 = pem2.replace(/\s+/g, ''); |
|
|
|
pem1.should.equal(pem2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|