Skip to content

Instantly share code, notes, and snippets.

@csabapalfi
Created July 30, 2018 20:05
Show Gist options
  • Save csabapalfi/f4ac8ac99a30bace288dd4d135a91fa7 to your computer and use it in GitHub Desktop.
Save csabapalfi/f4ac8ac99a30bace288dd4d135a91fa7 to your computer and use it in GitHub Desktop.
Check TLS certificates with node.js
const https = require('https');
const [,,domain] = process.argv;
const options = {
host: domain,
port: 443,
method: 'GET',
rejectUnauthorized: true
};
const req = https.request(options, function(res) {
const cert = res.connection.getPeerCertificate();
const SANs = cert.subjectaltname;
const currentDate = new Date();
if(Date.parse(cert.valid_from) > currentDate || Date.parse(cert.valid_to) < currentDate) {
process.exit(1);
}
if ((!SANs.indexOf(domain) || (!SANs.indexOf(`*.${domain}`)))) {
process.exit(1);
}
process.exit(0);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment