title: NodeJS forwarding client SSL certificates
body: <p>I am working on Node.js server application which is SSL enabled and accepts client certificates. I am using following code to create https server.</p>
  
  <pre><code>const options = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem'),
    ca: fs.readFileSync('ca.pem'),
    requestCert: true,
    rejectUnauthorized: true
  };
  
  https.createServer(options,app).listen(8090, function(){
      console.log("Listening on 8090");
  });
  </code></pre>
  
  <p>Other Node.js based client apps are able to connect using their SSL certficate and get the service response.</p>
  
  <p>However from my sever, I want to make another server call and wish to pass on the same client certificate I received. I simply want to forward the same ceritifcate, I understand I can get the certificate details in request object, but how to retrieve the crt and key from that object?</p>
  
  <p>I am looking to do something like below:</p>
  
  <pre><code>app.get('/myservice', (req,res) =&gt; {
      //req.socket.getPeerCertificate(true);
      var agent = new https.Agent({
          cert: somelibrary(req.socket.getPeerCertificate(true).??????),
              key: somelibrary(req.socket.getPeerCertificate(true).??????),
      });
      fetch('http://AnotherServiceURL', { method: 'GET' agent}).then(function(response){
          res.json(response);
      });
  
  });
  </code></pre>
  
  <p>Is there any library which can convert request certificate details in a way so as to forward those as <code>key</code> and <code>cert</code>? Or is there any other/better way of doing this?</p>