Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Use extra/self-signed https certificates #286

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ianldgs
Copy link

@ianldgs ianldgs commented Jun 8, 2022

Users behind corporate firewall typically have custom certificates used by the company to decrypt HTTPS traffic.

NodeJS will by default complain about those "self-signed" certificates and not perform the requests.

One workaround is to disable TLS completely for NodeJS, which is obviously dangerours or to export an environment variable on the bashrc/zshrc pointing to the custom certificates that you know to be safe:
https://nodejs.org/api/cli.html#node_extra_ca_certsfile

The latter doesn't work with this extension, likely for one of those reasons given in the NodeJS docs:

  • Neither the well known nor extra certificates are used when the ca options property is explicitly specified for a TLS or HTTPS client or server.
  • This environment variable is ignored when node runs as setuid root or has Linux file capabilities set.

So, to use this extension in such corporate environments without disabling TLS completely, have to manually read those files and inject them into the global HTTPS agent. That will mimic NodeJS's default behaviour.

Closes #243

@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2022

⚠️ No Changeset found

Latest commit: 68f5603

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ianldgs ianldgs changed the title Use extra/self-signed https certificatesCloses #243 Use extra/self-signed https certificates Jun 8, 2022
@ianldgs
Copy link
Author

ianldgs commented Jun 13, 2022

@znck think you could review this PR pls?

@znck
Copy link
Owner

znck commented Jun 17, 2022

I am not sure what's happening here.

/cc @wachunga

@ianldgs
Copy link
Author

ianldgs commented Jun 21, 2022

@znck sorry about that, I should've written a good description. Please take a look again?

@ianldgs
Copy link
Author

ianldgs commented Jul 15, 2022

@znck friendly ping... I see github bot closed the issue as stale.

@znck
Copy link
Owner

znck commented Jul 20, 2022

I'll get this merged this week.

@znck
Copy link
Owner

znck commented Jul 26, 2022

Is there an easy way to test this?

@ianldgs
Copy link
Author

ianldgs commented Aug 5, 2022

Well, it's easy for me to test because I'm behind the company's firewall/vpn.
Maybe you could try following this, if you're on a mac.

And then what I did was:

test-certs.mjs:

import "./extra-certs.mjs";
import fetch from "node-fetch";

fetch("https://js.grammarly.com/grammarly-sdk");

extra-certs.mjs:

import https from "node:https";
import tls from "node:tls";
import fs from "node:fs";

if (typeof process.env.NODE_EXTRA_CA_CERTS === "string") {
  const extraCerts = process.env.NODE_EXTRA_CA_CERTS.split(",").map((certPath) =>
    fs.readFileSync(certPath, "utf8")
  );

  https.globalAgent.options.ca = [...tls.rootCertificates, ...extraCerts];
}

And run:

export NODE_EXTRA_CA_CERTS="/path/to/cert.pem"
node test-certs.mjs

@haydencbarnes
Copy link
Contributor

Just pinging this space to see what the latest update is

@papb
Copy link

papb commented Feb 14, 2023

Hello, is there any way I can help to get this merged? :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unable to get local issuer certificate
4 participants