|
@ -6,8 +6,11 @@ var assert = require('assert'); |
|
|
var PayPro = require('../common/PayPro'); |
|
|
var PayPro = require('../common/PayPro'); |
|
|
var RootCerts = require('../common/RootCerts'); |
|
|
var RootCerts = require('../common/RootCerts'); |
|
|
|
|
|
|
|
|
|
|
|
// Documentation:
|
|
|
|
|
|
// http://kjur.github.io/jsrsasign/api/symbols/KJUR.crypto.Signature.html#.sign
|
|
|
|
|
|
// http://kjur.github.io/jsrsasign/api/symbols/RSAKey.html
|
|
|
|
|
|
|
|
|
PayPro.prototype.x509Sign = function(key) { |
|
|
PayPro.prototype.x509Sign = function(key) { |
|
|
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
|
|
|
var type = pki_type.split('+')[1].toUpperCase(); |
|
|
var type = pki_type.split('+')[1].toUpperCase(); |
|
@ -24,17 +27,23 @@ PayPro.prototype.x509Sign = function(key) { |
|
|
// throw new Error('Unstrusted certificate.');
|
|
|
// throw new Error('Unstrusted certificate.');
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var rsa = new KJUR.RSAKey(); |
|
|
|
|
|
rsa.readPrivateKeyFromPEMString(key.toString()); |
|
|
|
|
|
key = rsa; |
|
|
|
|
|
|
|
|
var jsrsaSig = new KJUR.crypto.Signature({ |
|
|
var jsrsaSig = new KJUR.crypto.Signature({ |
|
|
alg: type + 'withRSA', |
|
|
alg: type.toUpperCase() + 'withRSA', |
|
|
prov: 'cryptojs/jsrsa' |
|
|
prov: 'cryptojs/jsrsa' |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
jsrsaSig.initSign(key); |
|
|
// XXX Could use this?
|
|
|
|
|
|
//jsrsaSig.initSign(key);
|
|
|
|
|
|
|
|
|
|
|
|
jsrsaSig.init(key); |
|
|
|
|
|
|
|
|
jsrsaSig.updateHex(buf.toString('hex')); |
|
|
jsrsaSig.updateHex(buf.toString('hex')); |
|
|
|
|
|
|
|
|
var sig = new Buffer(jsrsasig.sign(), 'hex'); |
|
|
var sig = new Buffer(jsrsaSig.sign(), 'hex'); |
|
|
//var sig = new Buffer(new Uint8Array(jsrsasig.sign()), 'hex');
|
|
|
|
|
|
return sig; |
|
|
return sig; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -46,7 +55,7 @@ PayPro.prototype.x509Verify = function(key) { |
|
|
var type = pki_type.split('+')[1].toUpperCase(); |
|
|
var type = pki_type.split('+')[1].toUpperCase(); |
|
|
|
|
|
|
|
|
var jsrsaSig = new KJUR.crypto.Signature({ |
|
|
var jsrsaSig = new KJUR.crypto.Signature({ |
|
|
alg: type + 'withRSA', |
|
|
alg: type.toUpperCase() + 'withRSA', |
|
|
prov: 'cryptojs/jsrsa' |
|
|
prov: 'cryptojs/jsrsa' |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|