12

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

Sarfaraz Khan
  • 2,166
  • 2
  • 14
  • 29
  • 2
    Googled "how to ignore self signed certificate error node.js soap.js". First result. http://stackoverflow.com/questions/10888610/ignore-invalid-self-signed-ssl-certificate-in-node-js-with-https-request – Jan Jun 25 '15 at 18:28

1 Answers1

31

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.

alex
  • 479,566
  • 201
  • 878
  • 984
Sarfaraz Khan
  • 2,166
  • 2
  • 14
  • 29
  • 2
    note - this is super insecure as it disable all SSL checking in Node. See http://stackoverflow.com/questions/20433287/node-js-request-cert-has-expired#answer-29397100 for a more secure way. – sparkFinder Jul 07 '16 at 06:38
  • 1
    Super-insecure or not, this helped me to quickly get over an early development hurdle, thank you. I will be using genuine certificates in production. – HomerPlata Aug 05 '17 at 20:42
  • 1
    I wish there was a place where all these weird env vars are documented. E.g. this one does not appear in https://nodejs.org/api/cli.html. Makes me wonder if there is another var that allows you to specify just your own certificate as trusted. – corwin.amber Dec 28 '17 at 09:11