paypro: use jsrsasign for browser.

This commit is contained in:
Christopher Jeffrey 2014-07-16 09:31:31 -07:00
parent 12bfe8268d
commit 11b67a6404
2 changed files with 6 additions and 17 deletions

View File

@ -1,9 +1,8 @@
"use strict";
var Key = require('./Key');
var bignum = require('bignum');
var x509 = require('./x509');
var assert = require('assert');
var elliptic = require('elliptic');
var PayPro = require('../PayPro');
PayPro.sign = function(key) {
@ -17,17 +16,15 @@ PayPro.sign = function(key) {
} else if (pki_type === 'none' || pki_type === 'x509+sha256' || pki_type === 'x509+sha1') {
throw new Error('x509 currently unsuported.');
} else if (pki_type === 'x509+sha1' || pki_type === 'x509+sha256') {
// XXX node only
var crypto = require('crypto');
var pki_data = this.get('pki_data'); // contains one or more x509 certs
//var details = this.get('serialized_payment_details');
var type = pki_type.split('+').toUpperCase();
// var signature = crypto.createSign('RSA-' + type);
var buf = this.serializeForSig();
// signature.update(buf);
//var hexSig = _rsasign_getHexPaddedDigestInfoForString("aaa", 1024, 'sha1');
var hexSig = _rsasign_getHexPaddedDigestInfoForString(buf.toString(16), 2048, type);
// var sig = signature.sign(pki_data);
var size = hexSig.length / 2;
if (size % 2) size++
var bbuf = new Uint8Array(size);
var sig = new Buffer(bbuf);
} else if (pki_type === 'none') {
return this;
} else {
@ -52,22 +49,13 @@ PayPro.verify = function() {
var pki_data = this.get('pki_data');
var buf = this.serializeForSig();
var type = pki_type.split('+').toUpperCase();
// var pubKey = PKCS5PKEY.getRSAKeyFromPublicPKCS8PEM(sKp1PubPEM);
// var result = pubKey.verifyPSS("aaa", sKp1SigAAA1, "sha1", -1);
var pubKey = PKCS5PKEY.getRSAKeyFromPublicPKCS8PEM(pki_data);
var result = pubKey.verifyPSS(buf, buf.toString(16), type, -1);
return result;
// var verifier = crypto.createVerify('RSA-' + type);
// verifier.update(buf);
// return verifier.verify(pki_data, sig);
} else if (pki_type === 'none') {
return true;
}
throw new Error('Unsupported pki_type');
};

View File

@ -65,6 +65,7 @@
"sjcl": "=1.0.1",
"hash.js": "=0.3.1",
"bn.js": "=0.13.3",
"jsrsasign": "=0.0.3",
"elliptic": "=0.15.7",
"bindings": "=1.1.1",
"bufferput": "git://github.com/bitpay/node-bufferput.git",