xovris 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{apicmd-3jWpFhG3.js → apicmd-BHGPPVbb.js} +8 -1
- package/dist/cli.js +4753 -1067
- package/dist/{code-DsDiCUXb.js → code-Cv9xmjOW.js} +12 -6
- package/dist/{collector-join-CwjwINuL.js → collector-join-B_k2_7BR.js} +1 -1
- package/dist/{deploy-guard-BdzcbJTF.js → deploy-guard-D06kPPwV.js} +1 -1
- package/dist/{findings-BHh24V38.js → findings-wu3dKZAq.js} +2 -2
- package/dist/{finishing-Dsc2jn0-.js → finishing-DQEath5m.js} +1 -1
- package/dist/{gated-write-DRftDST4.js → gated-write-C1W3tG1Z.js} +1 -1
- package/dist/{hunt-BmQxPIL8.js → hunt-CKCYvtG9.js} +2 -2
- package/dist/{languages-DhPS_td-.js → languages-f62XcE8m.js} +1 -1
- package/dist/limit-zU8xPAtN.js +74 -0
- package/dist/mapping-6HQuqcRm.js +48 -0
- package/dist/{merge-BK7G5i5Q.js → merge-DYdlN4fU.js} +3 -3
- package/dist/{review-ui-DsFuGF7B.js → review-ui-D-aMGRo2.js} +1 -1
- package/dist/sbom-AGsBNlj-.js +134 -0
- package/dist/secrets-scan-BcPn_pPi.js +175 -0
- package/dist/{sourcemaps-tbnp_n01.js → sourcemaps-DFeg7Yue.js} +85 -16
- package/dist/spend-CvJZo_T1.js +118 -0
- package/dist/{src-DPO9_Gtz.js → src-F88zycxp.js} +7495 -605
- package/dist/symbols-DAUTKzoB.js +97 -0
- package/dist/tls-chain-DiOt1wwo.js +169 -0
- package/dist/{trace-DoQjPlBv.js → trace-BlK_FFnw.js} +1 -1
- package/package.json +7 -5
- package/dist/tls-chain-B3-Xk3Gg.js +0 -101
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { basename, join } from "node:path";
|
|
2
|
+
import { closeSync, openSync, readFileSync, readSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { gzipSync } from "node:zlib";
|
|
4
|
+
|
|
5
|
+
//#region src/symbols.ts
|
|
6
|
+
const MAGIC = new Set([
|
|
7
|
+
"feedface",
|
|
8
|
+
"feedfacf",
|
|
9
|
+
"cefaedfe",
|
|
10
|
+
"cffaedfe",
|
|
11
|
+
"cafebabe",
|
|
12
|
+
"cafebabf",
|
|
13
|
+
"7f454c46"
|
|
14
|
+
]);
|
|
15
|
+
function isImage(path) {
|
|
16
|
+
try {
|
|
17
|
+
const fd = openSync(path, "r");
|
|
18
|
+
const b = Buffer.alloc(4);
|
|
19
|
+
readSync(fd, b, 0, 4, 0);
|
|
20
|
+
closeSync(fd);
|
|
21
|
+
return MAGIC.has(b.toString("hex"));
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Every debug file under a path: a .dSYM's DWARF files, or each Mach-O and ELF file in a folder (never into node_modules or .git). */
|
|
27
|
+
function findDebugFiles(path) {
|
|
28
|
+
if (statSync(path).isFile()) return isImage(path) ? [path] : [];
|
|
29
|
+
const out = [];
|
|
30
|
+
const walk = (dir) => {
|
|
31
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
32
|
+
const p = join(dir, e.name);
|
|
33
|
+
if (e.isSymbolicLink()) continue;
|
|
34
|
+
if (e.isDirectory()) {
|
|
35
|
+
if (e.name !== "node_modules" && e.name !== ".git") walk(p);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (e.isFile() && isImage(p)) out.push(p);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
walk(path);
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
async function uploadSymbols(o) {
|
|
45
|
+
const files = findDebugFiles(o.path);
|
|
46
|
+
if (!files.length) return {
|
|
47
|
+
found: 0,
|
|
48
|
+
sent: [],
|
|
49
|
+
refused: [],
|
|
50
|
+
said: `No debug file was found under "${o.path}": Xcode writes a .dSYM beside the app when Debug Information Format is "DWARF with dSYM File", and an NDK build keeps unstripped libraries under build/intermediates. Name that folder: xovris symbols <path>`
|
|
51
|
+
};
|
|
52
|
+
if (!o.token || !o.project) {
|
|
53
|
+
const lacks = !o.token ? "the upload token (XOVRIS_BUILD_TOKEN)" : "its project id (XOVRIS_PROJECT)";
|
|
54
|
+
return {
|
|
55
|
+
found: files.length,
|
|
56
|
+
sent: [],
|
|
57
|
+
refused: [],
|
|
58
|
+
said: `This build ran without ${lacks}, so ${files.length} debug file${files.length === 1 ? " was" : "s were"} found but not sent and native crashes stay as addresses. Xovris sets both for you: run npx xovris in the project and it writes them into your build settings with your approval. Do it yourself instead: set XOVRIS_BUILD_TOKEN and XOVRIS_PROJECT where the build runs.`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const sent = [];
|
|
62
|
+
const refused = [];
|
|
63
|
+
for (const file of files) {
|
|
64
|
+
const url = `${o.api.replace(/\/$/, "")}/v1/projects/${encodeURIComponent(o.project)}/debug-files/native?fileName=${encodeURIComponent(basename(file))}`;
|
|
65
|
+
const res = await (o.fetch ?? fetch)(url, {
|
|
66
|
+
method: "PUT",
|
|
67
|
+
headers: {
|
|
68
|
+
authorization: `Bearer ${o.token}`,
|
|
69
|
+
"content-type": "application/octet-stream"
|
|
70
|
+
},
|
|
71
|
+
body: gzipSync(readFileSync(file))
|
|
72
|
+
}).catch((e) => ({
|
|
73
|
+
ok: false,
|
|
74
|
+
status: 0,
|
|
75
|
+
json: async () => ({ error: { message: e instanceof Error ? e.message : "the request never got an answer" } })
|
|
76
|
+
}));
|
|
77
|
+
const j = await res.json().catch(() => null);
|
|
78
|
+
if (res.ok) sent.push({
|
|
79
|
+
file,
|
|
80
|
+
debugIds: j?.debugIds ?? []
|
|
81
|
+
});
|
|
82
|
+
else refused.push({
|
|
83
|
+
file,
|
|
84
|
+
why: `${res.status || "no answer"}: ${j?.error?.message ?? "refused"}`
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const ids = sent.reduce((n, x) => n + x.debugIds.length, 0);
|
|
88
|
+
return {
|
|
89
|
+
found: files.length,
|
|
90
|
+
sent,
|
|
91
|
+
refused,
|
|
92
|
+
said: `${sent.length} of ${files.length} debug file${files.length === 1 ? "" : "s"} sent to Xovris (${ids} image${ids === 1 ? "" : "s"}): native crashes from this build read as your own code.${refused.length ? `\nNot kept: ${refused.map((r) => `${r.file} (${r.why})`).join("; ")}` : ""}`
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { findDebugFiles, uploadSymbols };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { X509Certificate } from "node:crypto";
|
|
2
|
+
import { connect, rootCertificates } from "node:tls";
|
|
3
|
+
import { connect as connect$1 } from "node:net";
|
|
4
|
+
|
|
5
|
+
//#region src/tls-chain.ts
|
|
6
|
+
const toPem = (raw) => `-----BEGIN CERTIFICATE-----\n${raw.toString("base64").match(/.{1,64}/g).join("\n")}\n-----END CERTIFICATE-----\n`;
|
|
7
|
+
/** The proxy's address as host and port (http://user:pass@proxy.acme:8080 -> proxy.acme, 8080), or null. */
|
|
8
|
+
function proxyAddress(proxy) {
|
|
9
|
+
if (!proxy) return null;
|
|
10
|
+
try {
|
|
11
|
+
const u = new URL(/^\w+:\/\//.test(proxy) ? proxy : `http://${proxy}`);
|
|
12
|
+
if (!u.hostname) return null;
|
|
13
|
+
const auth = u.username ? Buffer.from(`${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}`).toString("base64") : null;
|
|
14
|
+
return {
|
|
15
|
+
host: u.hostname.replace(/^\[|\]$/g, ""),
|
|
16
|
+
port: Number(u.port) || (u.protocol === "https:" ? 443 : 80),
|
|
17
|
+
auth
|
|
18
|
+
};
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function tunnel(proxy, host, port, timeoutMs) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const s = connect$1(proxy.port, proxy.host);
|
|
26
|
+
const timer = setTimeout(() => {
|
|
27
|
+
s.destroy();
|
|
28
|
+
reject(/* @__PURE__ */ new Error("the proxy did not answer"));
|
|
29
|
+
}, timeoutMs);
|
|
30
|
+
s.once("error", (e) => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
reject(e);
|
|
33
|
+
});
|
|
34
|
+
s.once("connect", () => s.write(`CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\n${proxy.auth ? `Proxy-Authorization: Basic ${proxy.auth}\r\n` : ""}\r\n`));
|
|
35
|
+
let head = "";
|
|
36
|
+
const onData = (d) => {
|
|
37
|
+
head += d.toString("latin1");
|
|
38
|
+
if (!head.includes("\r\n\r\n")) return;
|
|
39
|
+
s.off("data", onData);
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
if (/^HTTP\/1\.[01] 200/.test(head)) resolve(s);
|
|
42
|
+
else {
|
|
43
|
+
s.destroy();
|
|
44
|
+
reject(/* @__PURE__ */ new Error(`the proxy refused the tunnel (${head.split("\r\n")[0]})`));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
s.on("data", onData);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The self-signed root at the top of the chain the registry's address presents from this machine - through the proxy the
|
|
52
|
+
* package manager uses, or directly (a transparent proxy). A chain that ends below its root is followed to where its signer publishes
|
|
53
|
+
* the root (publishedRoot); null only when neither holds one.
|
|
54
|
+
*/
|
|
55
|
+
async function presentedRoot(registryUrl, proxy, timeoutMs = 15e3, missing) {
|
|
56
|
+
const u = new URL(registryUrl);
|
|
57
|
+
const host = u.hostname;
|
|
58
|
+
const port = Number(u.port) || 443;
|
|
59
|
+
const via = proxyAddress(proxy);
|
|
60
|
+
const socket = via ? await tunnel(via, host, port, timeoutMs) : void 0;
|
|
61
|
+
const { cert, trusted } = await new Promise((resolve, reject) => {
|
|
62
|
+
const t = connect({
|
|
63
|
+
host,
|
|
64
|
+
port,
|
|
65
|
+
servername: host,
|
|
66
|
+
rejectUnauthorized: false,
|
|
67
|
+
...socket ? { socket } : {}
|
|
68
|
+
}, () => {
|
|
69
|
+
const c = t.getPeerCertificate(true);
|
|
70
|
+
const ok = t.authorized;
|
|
71
|
+
t.end();
|
|
72
|
+
resolve({
|
|
73
|
+
cert: c,
|
|
74
|
+
trusted: ok
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
t.setTimeout(timeoutMs, () => {
|
|
78
|
+
t.destroy();
|
|
79
|
+
reject(/* @__PURE__ */ new Error("the registry did not finish the handshake"));
|
|
80
|
+
});
|
|
81
|
+
t.once("error", reject);
|
|
82
|
+
});
|
|
83
|
+
if (trusted) return null;
|
|
84
|
+
const chain = [];
|
|
85
|
+
const seen = /* @__PURE__ */ new Set();
|
|
86
|
+
for (let c = cert; c?.raw && !seen.has(c.fingerprint256); c = c.issuerCertificate) {
|
|
87
|
+
seen.add(c.fingerprint256);
|
|
88
|
+
chain.push(c);
|
|
89
|
+
if (c.issuerCertificate === c) break;
|
|
90
|
+
}
|
|
91
|
+
const top = chain[chain.length - 1];
|
|
92
|
+
if (!top) return null;
|
|
93
|
+
const x = new X509Certificate(top.raw);
|
|
94
|
+
if (x.subject === x.issuer && x.verify(x.publicKey) && (chain.length < 2 || x.ca)) return described(x, chain.length - 1, "sent");
|
|
95
|
+
if (x.subject === x.issuer) return null;
|
|
96
|
+
if (missing) {
|
|
97
|
+
const f = (k) => (/* @__PURE__ */ new RegExp(`(?:^|\\n)${k}=([^\\n]+)`)).exec(x.issuer)?.[1] ?? null;
|
|
98
|
+
missing.issuer = f("CN") ?? x.issuer.replace(/\n/g, ", ");
|
|
99
|
+
missing.organisation = f("O");
|
|
100
|
+
}
|
|
101
|
+
if (bundled().some((r) => r.subject === x.issuer && x.checkIssued(r) && x.verify(r.publicKey))) return null;
|
|
102
|
+
const found = await publishedRoot(x);
|
|
103
|
+
return found && !bundled().some((r) => r.fingerprint256 === found.root.fingerprint256) ? described(found.root, chain.length, "published", found.url) : null;
|
|
104
|
+
}
|
|
105
|
+
let bundledRoots = null;
|
|
106
|
+
/** The roots Node.js carries itself (its own bundle, never the computer's store). */
|
|
107
|
+
function bundled() {
|
|
108
|
+
bundledRoots ??= rootCertificates.flatMap((pem) => {
|
|
109
|
+
try {
|
|
110
|
+
return [new X509Certificate(pem)];
|
|
111
|
+
} catch {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return bundledRoots;
|
|
116
|
+
}
|
|
117
|
+
function described(x, depth, from, source) {
|
|
118
|
+
const field = (k) => (/* @__PURE__ */ new RegExp(`(?:^|\\n)${k}=([^\\n]+)`)).exec(x.subject)?.[1] ?? null;
|
|
119
|
+
return {
|
|
120
|
+
subject: field("CN") ?? x.subject.replace(/\n/g, ", "),
|
|
121
|
+
organisation: field("O"),
|
|
122
|
+
fingerprint256: x.fingerprint256,
|
|
123
|
+
pem: toPem(x.raw),
|
|
124
|
+
depth,
|
|
125
|
+
from,
|
|
126
|
+
...source ? { source } : {}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** The addresses a certificate names for its signer's own certificate (Authority Information Access, "CA Issuers - URI:..."). */
|
|
130
|
+
function issuerAddresses(infoAccess) {
|
|
131
|
+
return [...(infoAccess ?? "").matchAll(/CA Issuers - URI:(\S+)/g)].map((m) => m[1]).filter((u) => /^https?:\/\//i.test(u));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The root above a chain that stopped below it, read from where each signer publishes its own certificate - followed up from the
|
|
135
|
+
* chain's top, each step kept only when it really signed the one below (checkIssued and its signature), until a self-signed
|
|
136
|
+
* certificate authority; null when no address answers with one. Read only: a certificate is fetched, nothing is sent or kept.
|
|
137
|
+
*/
|
|
138
|
+
async function publishedRoot(top, fetchImpl = fetch, timeoutMs = 1e4) {
|
|
139
|
+
const seen = new Set([top.fingerprint256]);
|
|
140
|
+
for (let cur = top; cur;) {
|
|
141
|
+
const below = cur;
|
|
142
|
+
cur = null;
|
|
143
|
+
for (const url of issuerAddresses(below.infoAccess)) {
|
|
144
|
+
let cand;
|
|
145
|
+
try {
|
|
146
|
+
const r = await fetchImpl(url, {
|
|
147
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
148
|
+
redirect: "follow"
|
|
149
|
+
});
|
|
150
|
+
if (!r.ok) continue;
|
|
151
|
+
cand = new X509Certificate(Buffer.from(await r.arrayBuffer()));
|
|
152
|
+
} catch {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (seen.has(cand.fingerprint256) || !below.checkIssued(cand) || !below.verify(cand.publicKey) || !cand.ca) continue;
|
|
156
|
+
seen.add(cand.fingerprint256);
|
|
157
|
+
if (cand.subject === cand.issuer && cand.verify(cand.publicKey)) return {
|
|
158
|
+
root: cand,
|
|
159
|
+
url
|
|
160
|
+
};
|
|
161
|
+
cur = cand;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
export { issuerAddresses, presentedRoot, proxyAddress, publishedRoot };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as hostRest, C as fixTraced, D as parseError, E as openTraced, F as guardStrip, G as leaveBy, O as traceError, T as locate, j as githubRest, k as hostAuth, w as followFix } from "./src-F88zycxp.js";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xovris",
|
|
3
|
+
"gitHead": "8c4ea16632dacbd3d42aa498287016ff8445a668",
|
|
3
4
|
"homepage": "https://xovris.ai",
|
|
4
|
-
"version": "0.1
|
|
5
|
+
"version": "0.2.1",
|
|
5
6
|
"description": "npx xovris@latest init - detects your stack, signs you in through your browser, writes the configuration and verifies the first stored event. Nothing to copy or paste.",
|
|
6
7
|
"license": "Apache-2.0",
|
|
7
8
|
"type": "module",
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
"node": ">=20.19"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
20
|
+
"@ast-grep/cli": "0.50.0",
|
|
19
21
|
"@babel/parser": "^7.29.9",
|
|
20
22
|
"@clack/prompts": "^0.11.0",
|
|
21
23
|
"diff": "^8.0.4",
|
|
@@ -30,12 +32,12 @@
|
|
|
30
32
|
"@opentelemetry/sdk-node": "^0.222.0",
|
|
31
33
|
"@opentelemetry/sdk-trace-base": "^2.12.0",
|
|
32
34
|
"tsdown": "^0.15.12",
|
|
33
|
-
"@xovris/
|
|
34
|
-
"@xovris/review": "0.1.0",
|
|
35
|
-
"@xovris/checks": "0.1.0",
|
|
35
|
+
"@xovris/node": "0.1.1",
|
|
36
36
|
"@xovris/stacks": "0.1.0",
|
|
37
37
|
"@xovris/setup": "0.1.0",
|
|
38
|
-
"@xovris/
|
|
38
|
+
"@xovris/checks": "0.1.0",
|
|
39
|
+
"@xovris/mcp": "0.1.0",
|
|
40
|
+
"@xovris/review": "0.1.0"
|
|
39
41
|
},
|
|
40
42
|
"exports": {
|
|
41
43
|
"./plan": "./src/plan.ts",
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { X509Certificate } from "node:crypto";
|
|
2
|
-
import { connect } from "node:tls";
|
|
3
|
-
import { connect as connect$1 } from "node:net";
|
|
4
|
-
|
|
5
|
-
//#region src/tls-chain.ts
|
|
6
|
-
const toPem = (raw) => `-----BEGIN CERTIFICATE-----\n${raw.toString("base64").match(/.{1,64}/g).join("\n")}\n-----END CERTIFICATE-----\n`;
|
|
7
|
-
/** The proxy's address as host and port (http://user:pass@proxy.acme:8080 -> proxy.acme, 8080), or null. */
|
|
8
|
-
function proxyAddress(proxy) {
|
|
9
|
-
if (!proxy) return null;
|
|
10
|
-
try {
|
|
11
|
-
const u = new URL(/^\w+:\/\//.test(proxy) ? proxy : `http://${proxy}`);
|
|
12
|
-
if (!u.hostname) return null;
|
|
13
|
-
const auth = u.username ? Buffer.from(`${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}`).toString("base64") : null;
|
|
14
|
-
return {
|
|
15
|
-
host: u.hostname.replace(/^\[|\]$/g, ""),
|
|
16
|
-
port: Number(u.port) || (u.protocol === "https:" ? 443 : 80),
|
|
17
|
-
auth
|
|
18
|
-
};
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function tunnel(proxy, host, port, timeoutMs) {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
const s = connect$1(proxy.port, proxy.host);
|
|
26
|
-
const timer = setTimeout(() => {
|
|
27
|
-
s.destroy();
|
|
28
|
-
reject(/* @__PURE__ */ new Error("the proxy did not answer"));
|
|
29
|
-
}, timeoutMs);
|
|
30
|
-
s.once("error", (e) => {
|
|
31
|
-
clearTimeout(timer);
|
|
32
|
-
reject(e);
|
|
33
|
-
});
|
|
34
|
-
s.once("connect", () => s.write(`CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\n${proxy.auth ? `Proxy-Authorization: Basic ${proxy.auth}\r\n` : ""}\r\n`));
|
|
35
|
-
let head = "";
|
|
36
|
-
const onData = (d) => {
|
|
37
|
-
head += d.toString("latin1");
|
|
38
|
-
if (!head.includes("\r\n\r\n")) return;
|
|
39
|
-
s.off("data", onData);
|
|
40
|
-
clearTimeout(timer);
|
|
41
|
-
if (/^HTTP\/1\.[01] 200/.test(head)) resolve(s);
|
|
42
|
-
else {
|
|
43
|
-
s.destroy();
|
|
44
|
-
reject(/* @__PURE__ */ new Error(`the proxy refused the tunnel (${head.split("\r\n")[0]})`));
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
s.on("data", onData);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The self-signed root at the top of the chain the registry's address presents from this machine - through the proxy the
|
|
52
|
-
* package manager uses, or directly (a transparent proxy). null when the chain ends below a root (the root is not sent) or the
|
|
53
|
-
* top is not a certificate authority: then only the organisation's IT can hand the certificate over.
|
|
54
|
-
*/
|
|
55
|
-
async function presentedRoot(registryUrl, proxy, timeoutMs = 15e3) {
|
|
56
|
-
const u = new URL(registryUrl);
|
|
57
|
-
const host = u.hostname;
|
|
58
|
-
const port = Number(u.port) || 443;
|
|
59
|
-
const via = proxyAddress(proxy);
|
|
60
|
-
const socket = via ? await tunnel(via, host, port, timeoutMs) : void 0;
|
|
61
|
-
const cert = await new Promise((resolve, reject) => {
|
|
62
|
-
const t = connect({
|
|
63
|
-
host,
|
|
64
|
-
port,
|
|
65
|
-
servername: host,
|
|
66
|
-
rejectUnauthorized: false,
|
|
67
|
-
...socket ? { socket } : {}
|
|
68
|
-
}, () => {
|
|
69
|
-
const c = t.getPeerCertificate(true);
|
|
70
|
-
t.end();
|
|
71
|
-
resolve(c);
|
|
72
|
-
});
|
|
73
|
-
t.setTimeout(timeoutMs, () => {
|
|
74
|
-
t.destroy();
|
|
75
|
-
reject(/* @__PURE__ */ new Error("the registry did not finish the handshake"));
|
|
76
|
-
});
|
|
77
|
-
t.once("error", reject);
|
|
78
|
-
});
|
|
79
|
-
const chain = [];
|
|
80
|
-
const seen = /* @__PURE__ */ new Set();
|
|
81
|
-
for (let c = cert; c?.raw && !seen.has(c.fingerprint256); c = c.issuerCertificate) {
|
|
82
|
-
seen.add(c.fingerprint256);
|
|
83
|
-
chain.push(c);
|
|
84
|
-
if (c.issuerCertificate === c) break;
|
|
85
|
-
}
|
|
86
|
-
const top = chain[chain.length - 1];
|
|
87
|
-
if (!top || chain.length < 2) return null;
|
|
88
|
-
const x = new X509Certificate(top.raw);
|
|
89
|
-
if (!x.ca || x.subject !== x.issuer || !x.verify(x.publicKey)) return null;
|
|
90
|
-
const field = (k) => (/* @__PURE__ */ new RegExp(`(?:^|\\n)${k}=([^\\n]+)`)).exec(x.subject)?.[1] ?? null;
|
|
91
|
-
return {
|
|
92
|
-
subject: field("CN") ?? x.subject.replace(/\n/g, ", "),
|
|
93
|
-
organisation: field("O"),
|
|
94
|
-
fingerprint256: x.fingerprint256,
|
|
95
|
-
pem: toPem(top.raw),
|
|
96
|
-
depth: chain.length - 1
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
//#endregion
|
|
101
|
-
export { presentedRoot, proxyAddress };
|