print subject and fix notBefore parsing

This commit is contained in:
Girish Ramakrishnan
2023-02-01 12:38:09 +01:00
parent c63e0036cb
commit 3f70edf3ec

View File

@@ -67,18 +67,18 @@ function nginxLocation(s) {
function getCertificateDatesSync(cert) {
assert.strictEqual(typeof cert, 'string');
const result = safe.child_process.spawnSync('/usr/bin/openssl', [ 'x509', '-startdate', '-enddate', '-noout' ], { input: cert, encoding: 'utf8' });
const result = safe.child_process.spawnSync('/usr/bin/openssl', [ 'x509', '-startdate', '-enddate', '-subject', '-noout' ], { input: cert, encoding: 'utf8' });
if (!result) return { startDate: null, endDate: null } ; // some error
const lines = result.stdout.trim().split('\n');
const notBefore = lines[1].split('=')[0];
const notBefore = lines[0].split('=')[1];
const notBeforeDate = new Date(notBefore);
const notAfter = lines[1].split('=')[1];
const notAfterDate = new Date(notAfter);
const daysLeft = (notAfterDate - new Date())/(24 * 60 * 60 * 1000);
debug(`expiryDate: notBefore=${notBefore} notAfter=${notAfter} daysLeft=${daysLeft}`);
debug(`expiryDate: ${lines[2]} notBefore=${notBefore} notAfter=${notAfter} daysLeft=${daysLeft}`);
return { startDate: notBeforeDate, endDate: notAfterDate };
}