-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undici or node native fetch is not working with mTLS #4034
Labels
bug
Something isn't working
Comments
I've used https://github.com/platformatic/undici-tls-dispatcher in the past and it worked very well. |
this is failing for me |
What is the error output you are seeing? |
fetch failed |
yes, but what's the output in the console? |
|
using |
It seems it is mostly an issue with the way the example was set, if you only use import https from 'node:https';
import fs from 'node:fs';
import { config } from './config';
const port = 3000;
const options = {
// key: fs.readFileSync('server-private-key.pem', 'utf-8').toString(),
// cert: fs.readFileSync('server.crt', 'utf-8').toString(),
// ca: fs.readFileSync('rootCA.crt', 'utf-8').toString(),
key: fs.readFileSync(config.SERVER_PRIVATE_KEY),
cert: fs.readFileSync(config.SERVER_CERT),
ca: fs.readFileSync(config.ROOT_CA_CERT),
requestCert: true,
rejectUnauthorized: false,
};
console.log({
...options,
key: options.key.toString(),
cert: options.cert.toString(),
ca: options.ca.toString(),
});
const server = https.createServer(options, (req, res) => {
console.log('hello!');
res.writeHead(200, { ['content-type']: 'text/plain' });
res.end('200');
});
server.listen(port, () => {
console.log(`Server running at https://localhost:${port}`);
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Description
this works with node-fetch
this does not work
Reproducible By
You can use this repo https://github.com/sibelius/node-mtls
to create cert, key for a server and for a client
Expected Behavior
mTLS should work with undici and node native fetch
Logs & Screenshots
FETCH 604571: request to GET https://endpoint errored - read ECONNRESET
Environment
System:
OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
CPU: (12) x64 Intel(R) Xeon(R) Platinum 8160 CPU @ 2.10GHz
Memory: 52.21 GB / 64.00 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
pnpm: 9.15.4 - ~/.nvm/versions/node/v22.13.0/bin/pnpm
Additional context
trying to make undici mTLS work
The text was updated successfully, but these errors were encountered: