Browse Source

paypro: better extension parsing with more debugging.

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

102
lib/PayPro.js

@ -133,40 +133,62 @@ PayPro.prototype.x509Verify = function() {
// http://tools.ietf.org/html/rfc5280#section-4.2 // http://tools.ietf.org/html/rfc5280#section-4.2
// //
// Basic Constraints var ext;
var basicConstraints = nc.tbsCertificate.extensions.filter(function(ext) { var eid;
return ext.extnID[3] === 19; var extensions = {
})[0]; basicConstraints: null,
keyUsage: null,
// Key Usage subjectKeyIdentifier: null,
var keyUsage = nc.tbsCertificate.extensions.filter(function(ext) { authKeyIdentifier: null,
return ext.extnID[3] === 15; CRLDistributionPoints: null,
})[0]; certificatePolicies: null,
standardUnknown: [],
// Subject Key Identifier unknown: [],
var authKeyIdentifier = nc.tbsCertificate.extensions.filter(function(ext) { };
return ext.extnID[3] === 14;
})[0]; for (var i = 0; i < nc.tbsCertificate.extensions.length; i++) {
ext = nc.tbsCertificate.extensions[i];
// Authority Key Identifier eid = ext.extnID;
var authKeyIdentifier = nc.tbsCertificate.extensions.filter(function(ext) { if (eid.length === 4 && eid[0] === 2 && eid[1] === 5 && eid[2] === 29) {
return ext.extnID[3] === 35; switch (eid[3]) {
})[0]; // Basic Constraints
case 19:
// Unknown Extension (not documented anywhere, probably non-standard) extensions.basicConstraints = ext;
var unknown = nc.tbsCertificate.extensions.filter(function(ext) { break;
return ext.extnID[3] === 1; // Key Usage
})[0]; case 15:
extensions.keyUsage = ext;
// CRL Distribution Points break;
var CRLDistributionPoints = nc.tbsCertificate.extensions.filter(function(ext) { // Subject Key Identifier
return ext.extnID[3] === 31; case 14:
})[0]; extensions.subjectKeyIdentifier = ext;
break;
// Certificate Policies // Authority Key Identifier
var certPolicies = nc.tbsCertificate.extensions.filter(function(ext) { case 35:
return ext.extnID[3] === 32; extensions.authKeyIdentifier = ext;
})[0]; break;
// CRL Distribution Points
case 31:
extensions.CRLDistributionPoints = ext;
break;
// Certificate Policies
case 32:
extensions.certificatePolicies = ext;
break;
// Unknown Extension (not documented anywhere, probably non-standard)
default:
extensions.standardUnknown.push(ext);
break;
}
} else {
extensions.unknown.push(ext);
}
}
print(c);
print(nc);
print('issuerVerified: %s', issuerVerified);
print(extensions);
// //
// Create a To-Be-Signed Certificate to verify using asn1.js: // Create a To-Be-Signed Certificate to verify using asn1.js:
@ -184,4 +206,16 @@ PayPro.prototype.x509Verify = function() {
return verified && chainVerified; return verified && chainVerified;
}; };
var util = require('util');
function inspect(obj) {
return typeof obj !== 'string'
? util.inspect(obj, false, 20, true)
: obj;
}
function print(obj) {
return typeof obj === 'object'
? process.stdout.write(inspect(obj) + '\n')
: console.log.apply(console, arguments);
}
module.exports = PayPro; module.exports = PayPro;

Loading…
Cancel
Save