nodejs - error self signed certificate in certificate chain

前端 未结 6 1736
孤街浪徒
孤街浪徒 2020-12-07 22:51

I am facing a problem with client side https requests.

A snippet can look like this:

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

var o         


        
6条回答
  •  离开以前
    2020-12-07 23:34

    Turning off verification is quite a dangerous thing to do. Much better to verify the certificate.

    You can pull the Certificate Authority certificate into the request with the ca key of the options object, like this:

    let opts = {
        method: 'GET',
        hostname: "localhost",
        port: listener.address().port,
        path: '/',
        ca: await fs.promises.readFile("cacert.pem")
      };
    
    https.request(opts, (response) => { }).end();
    

    I put a whole demo together of this so you can see how to construct SSL tests.

    It's here.

提交回复
热议问题