title: MTLS: send client certificate in nodejs soap - and check server certificate
body: <p>I'm trying to send a client certificate from a nodejs app using <a href="https://github.com/vpulim/node-soap" rel="nofollow noreferrer">node-soap</a></p>
  <pre><code>const clientURL = 'prod.wsdl';
  const wsdl_options = {
             wsdl_options: {
                 &quot;cert&quot;: fs.readFileSync('/etc/ssl/certs/client.crt'),
                 &quot;key&quot;: fs.readFileSync('/etc/ssl/certs/client.key'),
             }
  };
  soap.createClient(clientURL, wsdl_options,  function (err, client) {
    if (!err) {
      client[my-method](args, function (error, result) {
      if (error) console.log(JSON.stringify(error))
    
    }
  })
  </code></pre>
  <p>But I'm getting an error: <strong>{&quot;errno&quot;:&quot;EPROTO&quot;,&quot;code&quot;:&quot;EPROTO&quot;,&quot;syscall&quot;:&quot;write&quot;}</strong></p>
  <p>When I'm sending a curl, the server gets my request with the correct cert:</p>
  <pre><code>curl -X POST https://host:4431/func --cert /etc/ssl/certs/client.crt --key /etc/ssl/certs/client.key
  </code></pre>
  <p>what can be the problem here? am I missing something at wsdlOptions?</p>
  <p>Also, My customer gave me the certificate of the soap-server (and NOT the ca itself) and I need to check the ssl certificate of this response against the one he gave me.</p>
  <p>How can I do that?</p>
  <p>for request library we can do: <code>res.connection.getPeerCertificate() / res.connection.getPeerX509Certificate()</code> like <a href="https://stackoverflow.com/a/31553483">this</a>.</p>
  <p><strong>UPDATE</strong>:</p>
  <p>I found the solution to the first issue with the client certificate and key.</p>
  <p>I was missing:</p>
  <pre><code>client.setSecurity
  </code></pre>
  <p>After creating the proxy!</p>
  <p>For createClient, there is no need to put the cert and key.
  So the code now looks like this:</p>
  <pre><code>const clientURL = 'prod.wsdl';
  
  soap.createClient(clientURL, {},  function (err, client) {
    if (!err) {
      client.setSecurity(new soap.ClientSSLSecurity('/path/to/key','path/to/cert'));
      client[my-method](args, function (error, result) {
          ...
    }
  })
  </code></pre>
  <p><strong>Now how can I get the certificate of the server from the response and compare it to the one I have?</strong></p>