Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to ignore self signed certificate error node.js soap.js [duplicate]

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 !!

like image 387
Sarfaraz Khan Avatar asked Jun 24 '15 16:06

Sarfaraz Khan


People also ask

How do you resolve certificate errors in a node js app with SSL calls?

The easiest solution to resolve these errors is to use the “rejectUnauthorized” option shown below. However, this method is unsafe because it disables the server certificate verification, making the Node app open to MITM attack.

What is Node_extra_ca_certs?

env. NODE_EXTRA_CA_CERTS . process stores information about the node process running. env stores all the environment variables (that get populated by dotenv-webpack ).

What is rejectUnauthorized?

By setting rejectUnauthorized: false , you're saying "I don't care if I can't verify the server's identity." Obviously this is not a good solution as it leaves you vulnerable to MITM attacks.


1 Answers

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.

like image 157
Sarfaraz Khan Avatar answered Oct 10 '22 08:10

Sarfaraz Khan