Created
July 30, 2018 20:05
-
-
Save csabapalfi/f4ac8ac99a30bace288dd4d135a91fa7 to your computer and use it in GitHub Desktop.
Check TLS certificates with node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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