ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.59k stars 1.33k forks source link

There is no ability to provide passphrase for a private key #1558

Open venkhatv opened 4 years ago

venkhatv commented 4 years ago

There should be an ability to provide a passphrase for a private key. Https.request supports it. From https://nodejs.org/api/https.html#https_https_request_options_callback

The following additional options from tls.connect() are also accepted: ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder, key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, sessionIdContext.

// Example piece of https code
const key,cert,passphrase, ca; //Will have correct values. Leaving it blank for brevity.
const options = {
        host: 'https',
        path: '',
        method: post,
        headers: {
          'Content-Type': 'application/json',
          'Contentlength': 100
        },
        key,
        cert,
        passphrase,
        ca,
        rejectUnauthorized: false,
        checkServerIdentity: function (host, cert) {
          return undefined;
        }
      };
      options.agent = new https.Agent(options);

      const req = https.request(options, (res) => {
        console.log('All OK. Server matched our pinned cert or public key');
        console.log('statusCode:', res.statusCode);
        console.log('headers:', res.headers);
        res.on('data', console.log);
      });