how to ignore self signed certificate error node.js soap.js

28.6k views Asked by At

I have created a soap client in node.js using soap.js.Soap communication is done over https. When I try to connect I keep getting this error

{ [Error: self signed certificate] code: 'DEPTH_ZERO_SELF_SIGNED_CERT' }

Below is my code

var url = '../public/test.wsdl';

var client = soap.createClient(url,sslOptions, function(err, client) {
    client.setSecurity(new soap.WSSecurity('testuser', 'testpassword'));
      client.CheckStatus(args, function(err, result) {
          console.log(err);
        //  console.log(result);
      });

  });

I've also tried the following ssl setting but did't work out

sslOptions = {
  key: fs.readFileSync( '../certs/test-key.pem'),
  cert: fs.readFileSync( '../certs/test-cert.pem'),
  rejectUnauthorized : false,
  secureOptions : constants.SSL_OP_NO_TLSv1_2,
  strictSSL : false
};

Any help would be appreciated !!

1

There are 1 answers

3
Sarfaraz Khan On BEST ANSWER

Found it yesterday on their github repo

@tesfel tesfel commented on 17 Feb

Add the cert to your trusted list at you computer or add

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"

to your code.