From 19d6ac68dec1b2a43c82e689b75527123edcf545 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 9 Aug 2016 14:43:13 -0400 Subject: [PATCH] parse domains from cert info --- lib/cert-info.js | 25 +++++++++++++++++++++++++ tests/cert-info.js | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/lib/cert-info.js b/lib/cert-info.js index 394b7bf..3664fb3 100644 --- a/lib/cert-info.js +++ b/lib/cert-info.js @@ -35,6 +35,25 @@ certInfo.getCertInfo = function (pem) { return certSimpl; }; +certInfo.getBasicInfo = function (pem) { + var c = certInfo.getCertInfo(pem); + var domains = []; + + c.extensions.forEach(function (ext) { + if (ext.parsedValue && ext.parsedValue.altNames) { + ext.parsedValue.altNames.forEach(function (alt) { + domains.push(alt.Name); + }); + } + }); + + return { + issuedAt: c.notBefore.value + , expiresAt: c.notAfter.value + , domains: domains + }; +}; + certInfo.getCertInfoFromFile = function (pemFile) { return require('fs').readFileSync(pemFile, 'ascii'); }; @@ -45,6 +64,12 @@ certInfo.testGetCertInfo = function () { return certInfo.getCertInfo(certInfo.getCertInfoFromFile(pemFile)); }; +certInfo.testBasicCertInfo = function () { + var path = require('path'); + var pemFile = path.join(__dirname, '..', 'tests', 'example.cert.pem'); + return certInfo.getBasicInfo(certInfo.getCertInfoFromFile(pemFile)); +}; + if (require.main === module) { var c = certInfo.testGetCertInfo(); diff --git a/tests/cert-info.js b/tests/cert-info.js index 525ce94..ddab280 100644 --- a/tests/cert-info.js +++ b/tests/cert-info.js @@ -16,6 +16,12 @@ console.info(new Date(c.notAfter.value).valueOf()); console.info(''); +var json = certInfo.testBasicCertInfo(); + +console.log(''); +console.log(JSON.stringify(json, null, ' ')); +console.log(''); + console.info(''); console.info('If we got values at all, it must have passed.'); console.info('');