From 1bd9dd577f78db82c73a9244cf43ffc4c1e1514a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 25 Aug 2014 15:44:33 -0700 Subject: [PATCH] paypro: refactor extension execution. --- lib/PayPro.js | 66 ++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/lib/PayPro.js b/lib/PayPro.js index fcb4409..55e0d11 100644 --- a/lib/PayPro.js +++ b/lib/PayPro.js @@ -179,14 +179,42 @@ PayPro.prototype.x509Verify = function() { // Authority Key Identifier case 35: extensions.authorityKeyIdentifier = ext.extnValue; + // parse + extensions.authorityKeyIdentifier = rfc5280.AuthorityKeyIdentifier.decode( + extensions.authorityKeyIdentifier, + 'der'); + print(extensions.authorityKeyIdentifier); break; // Subject Key Identifier case 14: extensions.subjectKeyIdentifier = ext.extnValue; + // parse + // extensions.subjectKeyIdentifier = rfc5280.SubjectKeyIdentifier.decode( + // extensions.subjectKeyIdentifier, + // 'der'); + // print(extensions.subjectKeyIdentifier); break; // Key Usage case 15: extensions.keyUsage = ext.extnValue; + // parse + data = rfc5280.KeyUsage.decode( + extensions.keyUsage, + 'der').data[0]; + extensions.keyUsage = { + digitalSignature: !!((data >> 0) & 1), + nonRepudiation: !!((data >> 1) & 1), + // nonRepudiation renamed to contentCommitment: + contentCommitment: !!((data >> 1) & 1), + keyEncipherment: !!((data >> 2) & 1), + dataEncipherment: !!((data >> 3) & 1), + keyAgreement: !!((data >> 4) & 1), + keyCertSign: !!((data >> 5) & 1), + cRLSign: !!((data >> 6) & 1), + encipherOnly: !!((data >> 7) & 1), + decipherOnly: !!((data >> 8) & 1) + }; + print(extensions.keyUsage); break; // Certificate Policies case 32: @@ -281,44 +309,6 @@ PayPro.prototype.x509Verify = function() { return ext.critical; }).length; - // - // Execute Extension Behavior - // - - if (extensions.authorityKeyIdentifier) { - extensions.authorityKeyIdentifier = rfc5280.AuthorityKeyIdentifier.decode( - extensions.authorityKeyIdentifier, - 'der'); - print(extensions.authorityKeyIdentifier); - } - - // if (extensions.subjectKeyIdentifier) { - // extensions.subjectKeyIdentifier = rfc5280.SubjectKeyIdentifier.decode( - // extensions.subjectKeyIdentifier, - // 'der'); - // print(extensions.subjectKeyIdentifier); - // } - - if (extensions.keyUsage) { - data = rfc5280.KeyUsage.decode( - extensions.keyUsage, - 'der').data[0]; - extensions.keyUsage = { - digitalSignature: !!((data >> 0) & 1), - nonRepudiation: !!((data >> 1) & 1), - // nonRepudiation renamed to contentCommitment: - contentCommitment: !!((data >> 1) & 1), - keyEncipherment: !!((data >> 2) & 1), - dataEncipherment: !!((data >> 3) & 1), - keyAgreement: !!((data >> 4) & 1), - keyCertSign: !!((data >> 5) & 1), - cRLSign: !!((data >> 6) & 1), - encipherOnly: !!((data >> 7) & 1), - decipherOnly: !!((data >> 8) & 1) - }; - print(extensions.keyUsage); - } - // // Verify current certificate signature //