Reputation: 1404
I found a neat npm package that allows for this, called sslinfo. However, this doesn't work for some reason (I'm getting Uncaught Error: Module did not self-register
). Is there some other way I can read a site's SSL info via node.js/JavaScript/jQuery?
EDIT:
For future searchers! The accepted answer is correct, but what if you want some actionable data? This is what works for me (for now):
results.toString().match(/subject=\/(.*)/)[1].match(/CN=(.*)/)[1] // Subject Common Name
results.toString().match(/subject=\/(.*)/)[1].match(/O=(.*)\//)[1] // Subject Organization Name
results.toString().match(/issuer=\/(.*)/)[1].match(/CN=(.*)/)[1] // Issuer Common Name
results.toString().match(/issuer=\/(.*)/)[1].match(/O=(.*)\//)[1] // Issuer Organization Name
All this regex is ugly but, sslinfo wasn't cooperating. Also, I modified the answer code slightly to:
openssl.exec("s_client", {
showcerts: true, connect: url // "url" is what I'm passing to the function
}, function (err, results) {
console.log(
// results.toString().match(/subject=\/(.*)/)[1].match(/CN=(.*)/)[1] // Subject Common Name
// results.toString().match(/subject=\/(.*)/)[1].match(/O=(.*)\//)[1] // Subject Organization Name
// results.toString().match(/issuer=\/(.*)/)[1].match(/CN=(.*)/)[1] // Issuer Common Name
// results.toString().match(/issuer=\/(.*)/)[1].match(/O=(.*)\//)[1] // Issuer Organization Name
);
});
Upvotes: 0
Views: 309
Reputation: 2617
sslinfo is based on openssl-wrapper, so that can be used directly. E.g:
var openssl = require('openssl-wrapper');
var url = 'www.google.com:443'
return openssl.exec('s_client', {showcerts: true, connect: url }, function(err, buffer) {
console.log(buffer.toString());
});
Equivalent to this on the command line:
openssl s_client -showcerts -connect www.google.com:443
Upvotes: 2