How do I trust a self signed cert using https?

Posted by dave on Stack Overflow See other posts from Stack Overflow or by dave
Published on 2014-06-10T13:38:09Z Indexed on 2014/06/11 3:25 UTC
Read the original article Hit count: 103

Filed under:
|
|

Edit: I originally thought the server's certificate was self signed. Turns out it was signed by a self-signed CA certificate.

I'm trying to write a Node.js application that accesses an HTTPS site that's protected using a self-signed certificate certificate signed by a private, self-signed CA certificate. I'd also like to not completely disable certificate checking.

I tried putting the self signed certificate server's certificate in the request options, but that doesn't seem to be working. Anyone know how to do this?

I expect the following code to print statusCode 200, but instead it prints [Error: SELF_SIGNED_CERT_IN_CHAIN].

I've tried similar code with request with the same results.

var https = require('https');
var fs = require('fs');

var opts = {
    hostname: host,
    port: 443,
    path: '/',
    method: 'GET',
    ca: fs.readFileSync(serverCertificateFile, 'utf-8')
};

var req = https.request(opts, function (res) {
    console.log('statusCode', res.statusCode);
});

req.end();
req.on('error', function (err) {
    console.error(err);
});

© Stack Overflow or respective owner

Related posts about node.js

Related posts about ssl