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

Use extra/self-signed https certificates#286

Open
ianldgs wants to merge 1 commit into
znck:mainfrom
ianldgs:self-signed-extrta-certs
Open

Use extra/self-signed https certificates#286
ianldgs wants to merge 1 commit into
znck:mainfrom
ianldgs:self-signed-extrta-certs

Conversation

@ianldgs

@ianldgs ianldgs commented Jun 8, 2022

Copy link
Copy Markdown

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

changeset-bot Bot commented Jun 8, 2022

Copy link
Copy Markdown

⚠️ 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

ianldgs commented Jun 13, 2022

Copy link
Copy Markdown
Author

@znck think you could review this PR pls?

@znck

znck commented Jun 17, 2022

Copy link
Copy Markdown
Owner

I am not sure what's happening here.

/cc @wachunga

@ianldgs

ianldgs commented Jun 21, 2022

Copy link
Copy Markdown
Author

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

@ianldgs
ianldgs force-pushed the self-signed-extrta-certs branch from 286ac18 to 68f5603 Compare July 15, 2022 08:09
@ianldgs

ianldgs commented Jul 15, 2022

Copy link
Copy Markdown
Author

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

@znck

znck commented Jul 20, 2022

Copy link
Copy Markdown
Owner

I'll get this merged this week.

@znck

znck commented Jul 26, 2022

Copy link
Copy Markdown
Owner

Is there an easy way to test this?

@ianldgs

ianldgs commented Aug 5, 2022

Copy link
Copy Markdown
Author

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
Copy Markdown
Contributor

Just pinging this space to see what the latest update is

@papb

papb commented Feb 14, 2023

Copy link
Copy Markdown

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