node.js - how to check/get ssl certificate expiry date

Viewed 10119

I have the Let's encrypt certificate bundle. It includes the private key and certificate.crt

Using node.js and node-forge (not openssl), how can I get the expiry date of the certificate.crt?

3 Answers

You can use x509 module

var crt_pem = "<certificate in pem format which is content of your certificate.crt>";
const x509 = require('x509');
var crt_obj = x509.parseCert(crt_pem);
console.log(crt_obj.notBefore);
console.log(crt_obj.notAfter);

You can use Node SSL Checker

$ npm install ssl-checker --save # npm i -s ssh-checker

In your code:

var sslChecker = require("ssl-checker")
sslChecker('example.com', 'GET', 443).then(result => console.info(result));

the response will look like this:

{
"valid": true,
"days_remaining" : 90,
"valid_from" : "issue date",
"valid_to" : "expiry date"
}

You can use built-in crypto module:

const { X509Certificate } = require('crypto');

const { validTo } = new X509Certificate(certificate);
Related