parse domains from cert info

This commit is contained in:
AJ ONeal 2016-08-09 14:43:13 -04:00
parent 40c336f204
commit 19d6ac68de
2 changed files with 31 additions and 0 deletions

View File

@ -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();

View File

@ -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('');