|
@ -8,6 +8,10 @@ var PayPro = require('./common/PayPro'); |
|
|
|
|
|
|
|
|
var KJUR = require('jsrsasign'); |
|
|
var KJUR = require('jsrsasign'); |
|
|
|
|
|
|
|
|
|
|
|
var asn1 = require('asn1.js'); |
|
|
|
|
|
var rfc3280 = require('asn1.js/rfc/3280'); |
|
|
|
|
|
var Certificate = rfc3280.Certificate; |
|
|
|
|
|
|
|
|
PayPro.prototype.x509Sign = function(key) { |
|
|
PayPro.prototype.x509Sign = function(key) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var crypto = require('crypto'); |
|
|
var crypto = require('crypto'); |
|
@ -91,25 +95,71 @@ PayPro.prototype.x509Verify = function() { |
|
|
var nder = ncert.toString('hex'); |
|
|
var nder = ncert.toString('hex'); |
|
|
var npem = self._DERtoPEM(nder, 'CERTIFICATE'); |
|
|
var npem = self._DERtoPEM(nder, 'CERTIFICATE'); |
|
|
|
|
|
|
|
|
// get sig from current cert - BAD
|
|
|
/* |
|
|
var sig = new Buffer(der.slice(-(blen * 2)), 'hex'); |
|
|
https://www.ietf.org/rfc/rfc2459
|
|
|
|
|
|
https://en.wikipedia.org/wiki/X509
|
|
|
// Should work but doesn't:
|
|
|
https://github.com/indutny/asn1.js
|
|
|
// get sig from current cert
|
|
|
https://github.com/indutny/asn1.js/blob/master/rfc/3280/index.js
|
|
|
// var o = new KJUR.asn1.cms.SignerInfo();
|
|
|
~/work/node_modules/bitcore/node_modules/asn1.js/rfc/3280/index.js |
|
|
// o.setSignerIdentifier(pem);
|
|
|
Error: Failed to match tag: "objid" at: |
|
|
// var sig = o.getEncodedHex();
|
|
|
["tbsCertificate"]["issuerUniqueID"]["subjectUniqueID"]["extensions"]["extnID"] |
|
|
|
|
|
PR: https://github.com/indutny/asn1.js/pull/22
|
|
|
// get public key from next cert
|
|
|
*/ |
|
|
var js = new KJUR.crypto.Signature({ |
|
|
|
|
|
alg: type + 'withRSA', |
|
|
// Get public key from next certificate.
|
|
|
prov: 'cryptojs/jsrsa' |
|
|
var data = new Buffer(nder, 'hex'); |
|
|
}); |
|
|
var nc = Certificate.decode(data, 'der'); |
|
|
js.initVerifyByCertificatePEM(npem); |
|
|
var npubKey = nc.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey.data; |
|
|
var npubKey = KJUR.KEYUTIL.getPEM(js.pubKey); |
|
|
// Need to convert this to PEM:
|
|
|
|
|
|
// Doesn't work because KJUR is terrible:
|
|
|
|
|
|
// npubKey = KJUR.KEYUTIL.getPEM(npubKey.toString('hex'));
|
|
|
|
|
|
npubKey = self._DERtoPEM(npubKey, 'RSA PUBLIC KEY'); |
|
|
|
|
|
|
|
|
|
|
|
// Get signature from current certificate.
|
|
|
|
|
|
var data = new Buffer(der, 'hex'); |
|
|
|
|
|
//var c = Certificate.decode(data, 'der', { partial: true });
|
|
|
|
|
|
var c = Certificate.decode(data, 'der'); |
|
|
|
|
|
var sig = c.signature.data; |
|
|
|
|
|
|
|
|
var verifier = crypto.createVerify('RSA-' + type); |
|
|
var verifier = crypto.createVerify('RSA-' + type); |
|
|
|
|
|
|
|
|
|
|
|
var t = c.tbsCertificate; |
|
|
|
|
|
|
|
|
|
|
|
// Messy work:
|
|
|
|
|
|
// Fails on Issuer:
|
|
|
|
|
|
/* |
|
|
|
|
|
var cur = Certificate.encode({ |
|
|
|
|
|
tbsCertificate: { |
|
|
|
|
|
version: t.version, |
|
|
|
|
|
serialNumber: t.serialNumber, |
|
|
|
|
|
signature: t.signature, |
|
|
|
|
|
// Fails on issuer:
|
|
|
|
|
|
//issuer: t.issuer,
|
|
|
|
|
|
//issuer: t.issuer.value,
|
|
|
|
|
|
//issuer: t.issuer.value.map(function(obj) {
|
|
|
|
|
|
// return obj.value;
|
|
|
|
|
|
//}),
|
|
|
|
|
|
//issuer: t.issuer.type,
|
|
|
|
|
|
//issuer: 'rdh',
|
|
|
|
|
|
//issuer: rfc3280.Name.decode(t.issuer, 'der'),
|
|
|
|
|
|
validity: t.validity, |
|
|
|
|
|
subject: t.subject, |
|
|
|
|
|
subjectPublicKeyInfo: t.subjectPublicKeyInfo, |
|
|
|
|
|
extensions: t.extensions |
|
|
|
|
|
}, |
|
|
|
|
|
signatureAlgorithm: '', |
|
|
|
|
|
signature: '' |
|
|
|
|
|
}, 'der'); |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
var cur = Certificate.encode({ |
|
|
|
|
|
tbsCertificate: c.tbsCertificate, |
|
|
|
|
|
signatureAlgorithm: '', |
|
|
|
|
|
signature: '' |
|
|
|
|
|
}, 'der'); |
|
|
|
|
|
|
|
|
|
|
|
// console.log(cur);
|
|
|
|
|
|
|
|
|
// NOTE: We need to slice off the signatureAlgorithm and signatureValue.
|
|
|
// NOTE: We need to slice off the signatureAlgorithm and signatureValue.
|
|
|
// consult the x509 spec:
|
|
|
// consult the x509 spec:
|
|
|
// https://www.ietf.org/rfc/rfc2459
|
|
|
// https://www.ietf.org/rfc/rfc2459
|
|
|