oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73k stars 2.66k forks source link

UNABLE_TO_GET_ISSUER_CERT error when connecting with mTLS #8616

Open ilbertt opened 7 months ago

ilbertt commented 7 months ago

What version of Bun is running?

1.0.22

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

I'm trying to execute an HTTPS request to a server that has a self signed TLS certificate and requires mTLS authentication. So, I'm basically importing the https library and executing the request using an https.Agent. Since the server has a self signed TLS certificate, I'm setting the rejectUnauthorized field of the https.Agent options to false. Here's my pseudo-code:

// index.ts
import * as https from "https";

const uri = new URL("https://server.com");

const agent = new https.Agent({
  cert: // my x509 certificate
  key: // my private key for the certificate
  rejectUnauthorized: false,
});

const req = https.request({
      hostname: uri.hostname,
      port: uri.port,
      path: "/path",
      method: "GET",
      agent: agent,
    }, (res) => {
      // res handling here
    });

    req.on("error", reject);
    req.end();
  });

What is the expected behavior?

I'm expecting to be able to make the HTTPS request without any certificate error, since if I transpile the code to js and execute it with Node (v20), everything goes fine and the request is successfully received from the server.

What do you see instead?

The request gives me this error:

UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate
 path: "https://server.com/path"

Additional information

Might be related: #6520

eslym commented 3 months ago

mtls support for undici is missing too

# index.mjs
import { fetch, Agent } from 'undici';
import fs from 'fs';

const res = await fetch('https://certauth.idrix.fr/json', {
    dispatcher: new Agent({
        connect: {
            cert: fs.readFileSync('cert.pem'),
            key: fs.readFileSync('key.pem'),
        }
    })
});

console.log(res.status, res.statusText);
console.log(await res.json());

nodejs can run it without problem but bun override udinci fetch with bun fetch which does not support mtls

schettn commented 2 months ago

Any updates?