title: Node.js server returning authorizationError: DEPTH_ZERO_SELF_SIGNED_CERT
body: <h2>The issue</h2>
  
  <p>I wrote a minimal server that requires a client certificate, but it always rejects connections with the following <code>authorizationError</code>: <code>DEPTH_ZERO_SELF_SIGNED_CERT</code>. I put the steps I followed below, and they are quite simple, so you should be able to reproduce this in minutes, should you want to "try this at home". This is with Node.js 0.10.24. Am I doing something wrong?</p>
  
  <h2>What I did</h2>
  
  <p>First, I generated self-signed client and server certs as follows (instructions from the <a href="http://nategood.com/client-side-certificate-authentication-in-ngi" rel="noreferrer">Client Side Certificate Auth in Nginx</a> post), this is an <code>ssl</code> subdirectory.</p>
  
  <pre><code>openssl genrsa -des3 -out ca.key 4096
  openssl req -new -x509 -days 365 -key ca.key -out ca.crt
  openssl genrsa -des3 -out server.key 1024
  openssl req -new -key server.key -out server.csr
  openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
  openssl genrsa -des3 -out client.key 1024
  openssl req -new -key client.key -out client.csr
  openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt
  </code></pre>
  
  <p>Then, I run the following program with Node.js (i.e. put it in <code>server.js</code> and run <code>node server.js</code>).</p>
  
  <pre><code>var https = require('https');
  var fs = require('fs');
  
  var options = {
      key: fs.readFileSync('ssl/server.key'),
      cert: fs.readFileSync('ssl/server.crt'),
      ca: fs.readFileSync('ssl/ca.crt'),
      requestCert: true,
      rejectUnauthorized: false
  };
  
  https.createServer(options, function (req, res) {
      if (req.client.authorized) {
          res.writeHead(200, {"Content-Type":"application/json"});
          res.end('{"status":"approved"}');
          console.log("Approved Client ", req.client.socket.remoteAddress);
      } else {
          res.writeHead(401, {"Content-Type":"application/json"});
          res.end('{"status":"denied"}');
          console.log('authorizationError:', req.client.authorizationError);
          console.log("Denied Client " , req.client.socket.remoteAddress);
      }
  }).listen(5678);
  </code></pre>
  
  <p>Finally, I try to connect with curl:</p>
  
  <pre><code>curl -v -s -k --key ssl/client.key --cert ssl/client.crt https://localhost:5678
  </code></pre>
  
  <p>This is where it fails with an <code>authorizationError</code>: <code>DEPTH_ZERO_SELF_SIGNED_CERT</code>. I've read folks are having more luck setting <code>process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";</code> rather than using <code>rejectUnauthorized: false</code>, but that doesn't seem to make a difference in my case.</p>