This test program connects to the https server and receives some content. I checked my server in browsers and with curls, and the certificate works correctly. If I run curl to grab data from the server, it correctly complains about the unknown certificate, if I do not transfer it with -cacert or disable protection with -k.
So the problem is that although I think that my client should authenticate the certificate and I say where the public certificate is, it always works. If I remove the ca: option so that it does not know what the certificate is from the server, it silently works. I would like to catch an authentication error, but I cannot do this.
var https = require('https'); var fs = require('fs'); function main() { var data = ''; var get = https.get({ path: '/', host: 'localhost', port: 8000, agent: false, ca: [ fs.readFileSync('https_simple/cacert.pem') ] }, function(x) { x.setEncoding('utf8'); x.on('data', function(c) {data += c}); x.on('error', function(e) { throw e; }); x.on('end', function() { console.log('Hai!. Here is the response:'); console.log(data); }); }); get.on('error', function(e) {throw e}); get.end(); } main();
source share