Skip to content

Instantly share code, notes, and snippets.

@elmontoya7
Created July 23, 2019 19:06
Show Gist options
  • Save elmontoya7/f4e70d461ab92f44c07db7e7451aa60d to your computer and use it in GitHub Desktop.
Save elmontoya7/f4e70d461ab92f44c07db7e7451aa60d to your computer and use it in GitHub Desktop.
Check certificate validity
const tls = require('tls');
const https = require('https');
const crypto = require('crypto');
function sha256(s) {
return crypto.createHash('sha256').update(s).digest('base64');
}
const options = {
hostname: 'qaenterprise.botlers.io',
port: 443,
path: '/',
method: 'GET',
checkServerIdentity: function(host, cert) {
// Make sure the certificate is issued to the host we are connected to
const err = tls.checkServerIdentity(host, cert);
if (err) {
return err;
}
},
};
options.agent = new https.Agent(options);
const req = https.request(options, (res) => {
console.log('All OK. Server matched our pinned cert or public key');
// statusCode must be 200
console.log('statusCode:', res.statusCode);
// VALID CERTIFICATE
});
req.on('error', (e) => {
// INVALID CERTIFICATE
console.error('ERROR:', e.message);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment