forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-self-signed-cert-1.34.0.js
More file actions
40 lines (33 loc) · 1.07 KB
/
load-self-signed-cert-1.34.0.js
File metadata and controls
40 lines (33 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function initialize() {
if (process.platform !== "darwin") {
return;
}
const splitPattern = /(?=-----BEGIN\sCERTIFICATE-----)/g;
const systemRootCertsPath =
"/System/Library/Keychains/SystemRootCertificates.keychain";
const args = ["find-certificate", "-a", "-p"];
const childProcess = require("child_process");
const allTrusted = childProcess
.spawnSync("/usr/bin/security", args)
.stdout.toString()
.split(splitPattern);
const allRoot = childProcess
.spawnSync("/usr/bin/security", args.concat(systemRootCertsPath))
.stdout.toString()
.split(splitPattern);
const all = allTrusted.concat(allRoot);
const tls = require("tls");
const origCreateSecureContext = tls.createSecureContext;
tls.createSecureContext = (options) => {
const ctx = origCreateSecureContext(options);
all.filter(duplicated).forEach((cert) => {
ctx.context.addCACert(cert.trim());
});
return ctx;
};
}
function duplicated(cert, index, arr) {
return arr.indexOf(cert) === index;
}
initialize();
require("./copilot/dist/language-server.js");