Skip to content

Commit 92be663

Browse files
committed
🐛 use system certificates in binary
1 parent e5ca3e0 commit 92be663

File tree

5 files changed

+171
-3
lines changed

5 files changed

+171
-3
lines changed

binary/package-lock.json

+131-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

binary/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
"commander": "^12.0.0",
4242
"core": "file:../core",
4343
"follow-redirects": "^1.15.5",
44+
"mac-ca": "^2.0.3",
4445
"ncp": "^2.0.0",
4546
"posthog-node": "^3.6.3",
47+
"system-ca": "^1.0.2",
4648
"uuid": "^9.0.1",
47-
"vectordb": "^0.4.10"
49+
"vectordb": "^0.4.10",
50+
"win-ca": "^3.5.1"
4851
}
4952
}

binary/src/ca.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { globalAgent } from "https";
2+
import { systemCertsAsync } from "system-ca";
3+
4+
export async function setupCa() {
5+
try {
6+
switch (process.platform) {
7+
case "darwin":
8+
// https://www.npmjs.com/package/mac-ca#usage
9+
require("mac-ca").addToGlobalAgent();
10+
break;
11+
case "win32":
12+
// https://www.npmjs.com/package/win-ca#caveats
13+
require("win-ca").inject("+");
14+
break;
15+
default:
16+
// https://www.npmjs.com/package/system-ca
17+
globalAgent.options.ca = await systemCertsAsync();
18+
break;
19+
}
20+
} catch (e) {
21+
console.warn("Failed to setup CA: ", e);
22+
}
23+
}

binary/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Command } from "commander";
33
import { getCoreLogsPath } from "core/util/paths";
44
import fs from "fs";
55
import { IpcIde } from "./IpcIde";
6+
import { setupCa } from "./ca";
67
import { Core } from "./core";
78
import { IpcMessenger } from "./messenger";
89

@@ -18,6 +19,8 @@ program.action(() => {
1819
// const ide = new FileSystemIde();
1920
const core = new Core(messenger, ide);
2021

22+
setupCa();
23+
2124
// setTimeout(() => {
2225
// messenger.mock({
2326
// messageId: "2fe7823c-10bd-4771-abb5-781f520039ec",

core/util/fetchWithOptions.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { http, https } from "follow-redirects";
22
import * as fs from "fs";
33
import { HttpProxyAgent } from "http-proxy-agent";
4+
import { globalAgent } from "https";
45
import { HttpsProxyAgent } from "https-proxy-agent";
56
import fetch, { RequestInit, Response } from "node-fetch";
67
import tls from "tls";
@@ -13,7 +14,15 @@ export function fetchwithRequestOptions(
1314
): Promise<Response> {
1415
const TIMEOUT = 7200; // 7200 seconds = 2 hours
1516

16-
const ca = [...tls.rootCertificates];
17+
let globalCerts: string[] = [];
18+
if (process.env.IS_BINARY) {
19+
if (Array.isArray(globalAgent.options.ca)) {
20+
globalCerts = [...globalAgent.options.ca.map((cert) => cert.toString())];
21+
} else if (typeof globalAgent.options.ca !== "undefined") {
22+
globalCerts.push(globalAgent.options.ca.toString());
23+
}
24+
}
25+
const ca = Array.from(new Set(...tls.rootCertificates, ...globalCerts));
1726
const customCerts =
1827
typeof requestOptions?.caBundlePath === "string"
1928
? [requestOptions?.caBundlePath]

0 commit comments

Comments
 (0)