Skip to content

Instantly share code, notes, and snippets.

@jzevin
Last active September 9, 2022 16:06
Show Gist options
  • Save jzevin/3ee3feac9fdf90ea8c26ed35c62471f0 to your computer and use it in GitHub Desktop.
Save jzevin/3ee3feac9fdf90ea8c26ed35c62471f0 to your computer and use it in GitHub Desktop.
github copilot prepend for user cert
const tls = require("tls");
const fs = require("fs");
const origCreateSecureContext = tls.createSecureContext;
tls.createSecureContext = options => {
const context = origCreateSecureContext(options);
const pem = fs
.readFileSync(process.env.NODE_EXTRA_CA_CERTS, { encoding: "ascii" })
.replace(/\r\n/g, "\n");
console.log(pem);
const certs = pem.match(/-----BEGIN CERTIFICATE-----\n[\s\S]+?\n-----END CERTIFICATE-----/g);
if (!certs) {
throw new Error(`Could not parse certificate ${process.env.NODE_EXTRA_CA_CERTS}`);
}
certs.forEach(cert => {
context.context.addCACert(cert.trim());
});
return context;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment