@pkistudio/asn1defsifter 0.1.0
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/LICENSE +21 -0
- package/README.md +193 -0
- package/dist/app.js +821 -0
- package/dist/core.js +25 -0
- package/dist/index.js +25 -0
- package/dist/pki-report-CX5tXXqU.js +688 -0
- package/dist/styles.css +1 -0
- package/dist/types/adapters/asn1instancebuilder.d.ts +2 -0
- package/dist/types/adapters/pkistudiojs.d.ts +23 -0
- package/dist/types/app.d.ts +32 -0
- package/dist/types/core/annotated-tree.d.ts +2 -0
- package/dist/types/core/candidates.d.ts +2 -0
- package/dist/types/core/corpus.d.ts +3 -0
- package/dist/types/core/document.d.ts +2 -0
- package/dist/types/core/features.d.ts +2 -0
- package/dist/types/core/index.d.ts +18 -0
- package/dist/types/core/matcher.d.ts +2 -0
- package/dist/types/core/scoring.d.ts +3 -0
- package/dist/types/core/tags.d.ts +4 -0
- package/dist/types/core/types.d.ts +153 -0
- package/dist/types/core.d.ts +1 -0
- package/dist/types/corpus/pki-components.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/profiles/pki-report.d.ts +8 -0
- package/dist/types/profiles/pki.d.ts +3 -0
- package/dist/types/report/agent-report.d.ts +3 -0
- package/dist/types/viewer.d.ts +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
import { parseAsn1Definition as z } from "@pkistudio/asn1instancebuilder";
|
|
2
|
+
import $ from "@pkistudio/pkistudiojs/core";
|
|
3
|
+
import H from "@pkistudio/pkistudiojs/oid-resolver";
|
|
4
|
+
const J = /* @__PURE__ */ new Map([
|
|
5
|
+
[1, "BOOLEAN"],
|
|
6
|
+
[2, "INTEGER"],
|
|
7
|
+
[3, "BIT STRING"],
|
|
8
|
+
[4, "OCTET STRING"],
|
|
9
|
+
[5, "NULL"],
|
|
10
|
+
[6, "OBJECT IDENTIFIER"],
|
|
11
|
+
[12, "UTF8String"],
|
|
12
|
+
[16, "SEQUENCE"],
|
|
13
|
+
[17, "SET"],
|
|
14
|
+
[19, "PrintableString"],
|
|
15
|
+
[22, "IA5String"],
|
|
16
|
+
[23, "UTCTime"],
|
|
17
|
+
[24, "GeneralizedTime"]
|
|
18
|
+
]);
|
|
19
|
+
function O(e) {
|
|
20
|
+
return e.tagName ? e.tagName : e.tagClass === "universal" ? J.get(e.tagNumber) ?? `UNIVERSAL ${e.tagNumber}` : `${e.tagClass.toUpperCase()} ${e.tagNumber}`;
|
|
21
|
+
}
|
|
22
|
+
function X(e) {
|
|
23
|
+
return `${e.tagClass}:${e.tagNumber}:${e.constructed ? "constructed" : "primitive"}`;
|
|
24
|
+
}
|
|
25
|
+
function R(e) {
|
|
26
|
+
switch (e) {
|
|
27
|
+
case "boolean":
|
|
28
|
+
return 1;
|
|
29
|
+
case "integer":
|
|
30
|
+
case "enumerated":
|
|
31
|
+
return e === "integer" ? 2 : 10;
|
|
32
|
+
case "bitString":
|
|
33
|
+
return 3;
|
|
34
|
+
case "octetString":
|
|
35
|
+
return 4;
|
|
36
|
+
case "null":
|
|
37
|
+
return 5;
|
|
38
|
+
case "objectIdentifier":
|
|
39
|
+
return 6;
|
|
40
|
+
case "utf8String":
|
|
41
|
+
return 12;
|
|
42
|
+
case "printableString":
|
|
43
|
+
return 19;
|
|
44
|
+
case "ia5String":
|
|
45
|
+
return 22;
|
|
46
|
+
case "utcTime":
|
|
47
|
+
return 23;
|
|
48
|
+
case "generalizedTime":
|
|
49
|
+
return 24;
|
|
50
|
+
default:
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function _(e, i) {
|
|
55
|
+
return [x(e, "$", i)];
|
|
56
|
+
}
|
|
57
|
+
function x(e, i, t) {
|
|
58
|
+
const n = t == null ? void 0 : t.matchedPaths.find((s) => s.nodePath === i), r = W(n == null ? void 0 : n.schemaPath, t == null ? void 0 : t.typeName);
|
|
59
|
+
return {
|
|
60
|
+
id: e.id,
|
|
61
|
+
tagName: O(e),
|
|
62
|
+
...r,
|
|
63
|
+
schemaPath: n == null ? void 0 : n.schemaPath,
|
|
64
|
+
start: e.start,
|
|
65
|
+
end: e.end,
|
|
66
|
+
children: (e.children ?? []).map((s, a) => x(s, `${i}.${a}`, t))
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function W(e, i) {
|
|
70
|
+
if (!e) return {};
|
|
71
|
+
const t = e.split(".").map((s) => s.replace(/\[\]$/, "")).filter((s) => s.length > 0 && !/^\[\d+\]$/.test(s)), n = [...t].reverse().find((s) => /^[a-z]/.test(s)), r = [...t].reverse().find((s) => s !== n && s !== i && /^[A-Z]/.test(s)) ?? (t.length === 1 ? t[0] : void 0);
|
|
72
|
+
return {
|
|
73
|
+
...r ? { asn1Type: r } : {},
|
|
74
|
+
...n ? { fieldName: n } : {}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function D(e) {
|
|
78
|
+
return Array.isArray(e) ? { modules: e } : "modules" in e ? e : { modules: [e] };
|
|
79
|
+
}
|
|
80
|
+
function Y(e) {
|
|
81
|
+
return D(e).modules.flatMap((t) => t.types.map((n) => ({ module: t, definition: n })));
|
|
82
|
+
}
|
|
83
|
+
function Z(e, i, t, n, r = "$") {
|
|
84
|
+
const s = { schema: t, evidence: [], diagnostics: [], ambiguities: [], matchedPaths: [] }, a = E(e, i, s, n, r);
|
|
85
|
+
return {
|
|
86
|
+
score: a,
|
|
87
|
+
possible: a > 0,
|
|
88
|
+
evidence: s.evidence,
|
|
89
|
+
diagnostics: s.diagnostics,
|
|
90
|
+
ambiguities: s.ambiguities,
|
|
91
|
+
matchedPaths: s.matchedPaths
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function E(e, i, t, n, r) {
|
|
95
|
+
if (i.kind === "defined") {
|
|
96
|
+
const s = V(t.schema, i.typeName);
|
|
97
|
+
return s ? E(e, s, t, `${n}.${i.typeName}`, r) : (d(t, "warning", n, `Defined type ${i.typeName} is not available in module ${t.schema.name}.`), 0.15);
|
|
98
|
+
}
|
|
99
|
+
return i.kind === "tagged" ? te(e, i, t, n, r) : i.kind === "sequence" ? ie(e, i.fields, t, n, r, 16, "SEQUENCE") : i.kind === "set" ? re(e, i.fields, t, n, r) : i.kind === "choice" ? se(e, i.alternatives, t, n, r) : i.kind === "sequenceOf" ? y(e, i.elementType, t, n, r, 16, "SEQUENCE OF") : i.kind === "setOf" ? y(e, i.elementType, t, n, r, 17, "SET OF") : ee(e, i.kind, t, n, r);
|
|
100
|
+
}
|
|
101
|
+
function ee(e, i, t, n, r) {
|
|
102
|
+
const s = R(i);
|
|
103
|
+
return s === void 0 ? (d(t, "warning", n, `Primitive type ${i} is not supported by the current matcher.`), 0.2) : e.tagClass !== "universal" || e.tagNumber !== s ? (d(t, "error", r, `Expected ${i}, found ${h(e)}.`), 0) : (i === "objectIdentifier" && e.oid ? (g(t, r, `Node matches objectIdentifier with value ${e.oid}.`), e.oidName && g(t, r, `OID ${e.oid} resolves to ${e.oidName}.`)) : g(t, r, `Node matches ${i}.`), T(t, r, n), e.constructed ? 0.7 : 1);
|
|
104
|
+
}
|
|
105
|
+
function te(e, i, t, n, r) {
|
|
106
|
+
var u;
|
|
107
|
+
if (e.tagClass !== "context" || e.tagNumber !== i.tag.number)
|
|
108
|
+
return d(t, "error", r, `Expected context-specific tag [${i.tag.number}], found ${h(e)}.`), 0;
|
|
109
|
+
if (g(t, r, `Context-specific tag [${i.tag.number}] matches ${i.tag.mode} tagging.`), T(t, r, n), i.tag.mode === "explicit") {
|
|
110
|
+
const c = (u = e.children) == null ? void 0 : u[0];
|
|
111
|
+
return c ? 0.25 + 0.75 * E(c, i.type, t, `${n}.[${i.tag.number}]`, `${r}.0`) : (d(t, "error", r, "Expected explicitly tagged content, but the node has no child."), 0.45);
|
|
112
|
+
}
|
|
113
|
+
const s = P(i.type, t.schema);
|
|
114
|
+
if (s === void 0)
|
|
115
|
+
return t.ambiguities.push(`Implicit tag ${n} matched [${i.tag.number}], but the underlying universal tag could not be inferred.`), 0.65;
|
|
116
|
+
const a = { ...e, tagClass: "universal", tagNumber: s };
|
|
117
|
+
return 0.25 + 0.75 * E(a, i.type, t, n, r);
|
|
118
|
+
}
|
|
119
|
+
function ie(e, i, t, n, r, s, a) {
|
|
120
|
+
if (e.tagClass !== "universal" || e.tagNumber !== s || !e.constructed)
|
|
121
|
+
return d(t, "error", r, `Expected ${a}, found ${h(e)}.`), 0;
|
|
122
|
+
const u = e.children ?? [];
|
|
123
|
+
let c = 0, o = 0, l = 0;
|
|
124
|
+
g(t, r, `Root node matches ${a}.`), T(t, r, n);
|
|
125
|
+
for (const m of i) {
|
|
126
|
+
if (!u[c]) {
|
|
127
|
+
if (m.optional || m.defaultValue !== void 0) {
|
|
128
|
+
g(t, r, `Field ${m.name} is absent and allowed by OPTIONAL or DEFAULT.`), d(t, "info", `${n}.${m.name}`, `Field ${m.name} is absent and allowed by OPTIONAL or DEFAULT.`), o += I(m), l += 1;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
d(t, "error", `${n}.${m.name}`, `Required field ${m.name} is missing.`), l += 1;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const S = ne(u, c, m, t, n, r);
|
|
135
|
+
if (S.score === 0 && (m.optional || m.defaultValue !== void 0)) {
|
|
136
|
+
g(t, `${n}.${m.name}`, `Field ${m.name} may be omitted.`), d(t, "info", `${n}.${m.name}`, `Field ${m.name} is absent and allowed by OPTIONAL or DEFAULT.`), o += I(m), l += 1;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
S.score === 0 && C(t, S.branchState, !0), o += S.score, l += 1, c = S.nextIndex;
|
|
140
|
+
}
|
|
141
|
+
c < u.length && d(t, "warning", r, `${u.length - c} unexpected child node(s) remain after matching ${a}.`);
|
|
142
|
+
const f = l === 0 ? 0.85 : o / l, N = c < u.length ? 0.85 : 1;
|
|
143
|
+
return (0.25 + 0.75 * f) * N;
|
|
144
|
+
}
|
|
145
|
+
function ne(e, i, t, n, r, s) {
|
|
146
|
+
const a = e[i], u = `${r}.${t.name}`, c = `${s}.${i}`, o = U(n.schema), l = E(a, t.type, o, u, c);
|
|
147
|
+
return l > 0 ? (C(n, o), g(n, c, `Field ${t.name} is compatible with the child node.`), { nextIndex: i + 1, score: l, branchState: o }) : { nextIndex: i, score: l, branchState: o };
|
|
148
|
+
}
|
|
149
|
+
function re(e, i, t, n, r) {
|
|
150
|
+
if (e.tagClass !== "universal" || e.tagNumber !== 17 || !e.constructed)
|
|
151
|
+
return d(t, "error", r, `Expected SET, found ${h(e)}.`), 0;
|
|
152
|
+
const s = e.children ?? [], a = new Set(s.map((f, N) => N));
|
|
153
|
+
let u = 0, c = 0;
|
|
154
|
+
g(t, r, "Root node matches SET."), T(t, r, n);
|
|
155
|
+
for (const f of i) {
|
|
156
|
+
let N;
|
|
157
|
+
for (const m of a) {
|
|
158
|
+
const b = U(t.schema), S = E(s[m], f.type, b, `${n}.${f.name}`, `${r}.${m}`);
|
|
159
|
+
S > 0 && (!N || S > N.score) && (N = { childIndex: m, branchState: b, score: S });
|
|
160
|
+
}
|
|
161
|
+
if (N) {
|
|
162
|
+
a.delete(N.childIndex), C(t, N.branchState), g(t, `${r}.${N.childIndex}`, `SET field ${f.name} is compatible with this child node.`), u += N.score, c += 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (f.optional || f.defaultValue !== void 0) {
|
|
166
|
+
g(t, r, `SET field ${f.name} is absent and allowed by OPTIONAL or DEFAULT.`), d(t, "info", `${n}.${f.name}`, `SET field ${f.name} is absent and allowed by OPTIONAL or DEFAULT.`), u += I(f), c += 1;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
d(t, "error", `${n}.${f.name}`, `Required SET field ${f.name} is missing.`), c += 1;
|
|
170
|
+
}
|
|
171
|
+
a.size > 0 && d(t, "warning", r, `${a.size} unexpected child node(s) remain after matching SET.`);
|
|
172
|
+
const o = c === 0 ? 0.85 : u / c, l = a.size > 0 ? 0.85 : 1;
|
|
173
|
+
return (0.25 + 0.75 * o) * l;
|
|
174
|
+
}
|
|
175
|
+
function I(e) {
|
|
176
|
+
return e.optional || e.defaultValue !== void 0 ? 1 : 0;
|
|
177
|
+
}
|
|
178
|
+
function se(e, i, t, n, r) {
|
|
179
|
+
const s = i.map((c) => {
|
|
180
|
+
const o = { schema: t.schema, evidence: [], diagnostics: [], ambiguities: [], matchedPaths: [] }, l = E(e, c.type, o, `${n}.${c.name}`, r);
|
|
181
|
+
return { alternative: c, branchState: o, score: l };
|
|
182
|
+
}).sort((c, o) => o.score - c.score), a = s[0];
|
|
183
|
+
if (!a || a.score === 0)
|
|
184
|
+
return d(t, "error", r, `No CHOICE alternative matched ${n}.`), 0;
|
|
185
|
+
t.evidence.push(...a.branchState.evidence), t.diagnostics.push(...a.branchState.diagnostics.filter((c) => c.severity !== "error")), t.ambiguities.push(...a.branchState.ambiguities), t.matchedPaths.push(...a.branchState.matchedPaths), g(t, r, `CHOICE alternative ${a.alternative.name} is the strongest match.`);
|
|
186
|
+
const u = s.filter((c) => c !== a && Math.abs(c.score - a.score) < 0.05 && c.score > 0);
|
|
187
|
+
return u.length > 0 && t.ambiguities.push(`CHOICE ${n} has similarly scored alternatives: ${u.map((c) => c.alternative.name).join(", ")}.`), a.score;
|
|
188
|
+
}
|
|
189
|
+
function y(e, i, t, n, r, s, a) {
|
|
190
|
+
if (e.tagClass !== "universal" || e.tagNumber !== s || !e.constructed)
|
|
191
|
+
return d(t, "error", r, `Expected ${a}, found ${h(e)}.`), 0;
|
|
192
|
+
const u = e.children ?? [];
|
|
193
|
+
if (g(t, r, `Node matches ${a} container.`), T(t, r, n), u.length === 0) return 0.85;
|
|
194
|
+
const c = u.map((o, l) => E(o, i, t, `${n}[]`, `${r}.${l}`));
|
|
195
|
+
return c.reduce((o, l) => o + l, 0) / c.length;
|
|
196
|
+
}
|
|
197
|
+
function V(e, i) {
|
|
198
|
+
var t;
|
|
199
|
+
return (t = e.types.find((n) => n.name === i)) == null ? void 0 : t.type;
|
|
200
|
+
}
|
|
201
|
+
function P(e, i) {
|
|
202
|
+
if (e.kind === "defined") {
|
|
203
|
+
const t = V(i, e.typeName);
|
|
204
|
+
return t ? P(t, i) : void 0;
|
|
205
|
+
}
|
|
206
|
+
if (e.kind === "tagged") return e.tag.number;
|
|
207
|
+
if (e.kind === "sequence" || e.kind === "sequenceOf") return 16;
|
|
208
|
+
if (e.kind === "set" || e.kind === "setOf") return 17;
|
|
209
|
+
if (e.kind !== "choice")
|
|
210
|
+
return R(e.kind);
|
|
211
|
+
}
|
|
212
|
+
function g(e, i, t) {
|
|
213
|
+
e.evidence.push({ path: i, message: t });
|
|
214
|
+
}
|
|
215
|
+
function d(e, i, t, n) {
|
|
216
|
+
e.diagnostics.push({ severity: i, path: t, message: n });
|
|
217
|
+
}
|
|
218
|
+
function T(e, i, t) {
|
|
219
|
+
e.matchedPaths.push({ nodePath: i, schemaPath: t });
|
|
220
|
+
}
|
|
221
|
+
function U(e) {
|
|
222
|
+
return { schema: e, evidence: [], diagnostics: [], ambiguities: [], matchedPaths: [] };
|
|
223
|
+
}
|
|
224
|
+
function C(e, i, t = !1) {
|
|
225
|
+
e.evidence.push(...i.evidence), e.diagnostics.push(...i.diagnostics.filter((n) => t || n.severity !== "error")), e.ambiguities.push(...i.ambiguities), e.matchedPaths.push(...i.matchedPaths);
|
|
226
|
+
}
|
|
227
|
+
function h(e) {
|
|
228
|
+
return `${e.tagClass} tag ${e.tagNumber}`;
|
|
229
|
+
}
|
|
230
|
+
function ce(e) {
|
|
231
|
+
return Number.isNaN(e) ? 0 : Math.max(0, Math.min(1, Number(e.toFixed(4))));
|
|
232
|
+
}
|
|
233
|
+
function ae(e) {
|
|
234
|
+
return e >= 0.8 ? "high" : e >= 0.5 ? "medium" : "low";
|
|
235
|
+
}
|
|
236
|
+
function L(e, i) {
|
|
237
|
+
const t = i.maxResults ?? 20, n = i.minScore ?? Number.MIN_VALUE;
|
|
238
|
+
return Y(i.schemaCorpus).filter((r) => ue(r, i)).map(({ module: r, definition: s }) => {
|
|
239
|
+
const a = Z(e, s.type, r, s.name), u = ce(oe(e, r.name, s.name, a.score));
|
|
240
|
+
return {
|
|
241
|
+
typeName: s.name,
|
|
242
|
+
moduleName: r.name,
|
|
243
|
+
score: u,
|
|
244
|
+
confidence: ae(u),
|
|
245
|
+
evidence: a.evidence.map((c) => c.message),
|
|
246
|
+
diagnostics: a.diagnostics,
|
|
247
|
+
ambiguities: a.ambiguities,
|
|
248
|
+
matchedPaths: a.matchedPaths
|
|
249
|
+
};
|
|
250
|
+
}).filter((r) => r.score > 0 && r.score >= n).sort((r, s) => s.score - r.score || r.typeName.localeCompare(s.typeName)).slice(0, t);
|
|
251
|
+
}
|
|
252
|
+
function ue(e, i) {
|
|
253
|
+
const t = i.includeTypes ? new Set(i.includeTypes) : void 0, n = i.excludeTypes ? new Set(i.excludeTypes) : void 0, r = [e.definition.name, `${e.module.name}.${e.definition.name}`];
|
|
254
|
+
return !(t && !r.some((s) => t.has(s)) || n && r.some((s) => n.has(s)));
|
|
255
|
+
}
|
|
256
|
+
function oe(e, i, t, n) {
|
|
257
|
+
return i === "PkiComponents" && t === "RSAPublicKey" && !le(e) ? 0 : n;
|
|
258
|
+
}
|
|
259
|
+
function le(e) {
|
|
260
|
+
const i = e.children ?? [];
|
|
261
|
+
return e.tagClass === "universal" && e.tagNumber === 16 && e.constructed && i.length === 2 && i.every(me);
|
|
262
|
+
}
|
|
263
|
+
function me(e) {
|
|
264
|
+
return e.tagClass !== "universal" || e.tagNumber !== 2 || e.constructed ? !1 : !e.valueBytes || e.valueBytes.length === 0 ? !0 : (e.valueBytes[0] & 128) === 0 && e.valueBytes.some((i) => i !== 0);
|
|
265
|
+
}
|
|
266
|
+
function fe(e, i) {
|
|
267
|
+
const t = L(e, i);
|
|
268
|
+
return t.map((n) => ({
|
|
269
|
+
rootType: n.typeName,
|
|
270
|
+
moduleName: n.moduleName,
|
|
271
|
+
score: n.score,
|
|
272
|
+
confidence: n.confidence,
|
|
273
|
+
evidence: n.evidence,
|
|
274
|
+
diagnostics: n.diagnostics,
|
|
275
|
+
annotatedTree: _(e, n),
|
|
276
|
+
alternatives: t.filter((r) => r !== n)
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
function de(e) {
|
|
280
|
+
var r;
|
|
281
|
+
const i = e.children ?? [], t = F(e), n = w(e);
|
|
282
|
+
return {
|
|
283
|
+
tagClass: e.tagClass,
|
|
284
|
+
tagNumber: e.tagNumber,
|
|
285
|
+
constructed: e.constructed,
|
|
286
|
+
tagName: O(e),
|
|
287
|
+
childCount: i.length,
|
|
288
|
+
childTagSequence: i.map(X),
|
|
289
|
+
oidValues: t,
|
|
290
|
+
oidNames: n,
|
|
291
|
+
primitiveValueKind: ge(e),
|
|
292
|
+
valueLength: (r = e.valueBytes) == null ? void 0 : r.length
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function F(e) {
|
|
296
|
+
const i = e.oid ? [e.oid] : [], t = (e.children ?? []).flatMap(F);
|
|
297
|
+
return [...i, ...t];
|
|
298
|
+
}
|
|
299
|
+
function w(e) {
|
|
300
|
+
const i = e.oidName ? [e.oidName] : [], t = (e.children ?? []).flatMap(w);
|
|
301
|
+
return [...i, ...t];
|
|
302
|
+
}
|
|
303
|
+
function ge(e) {
|
|
304
|
+
if (!e.constructed && e.tagClass === "universal")
|
|
305
|
+
switch (e.tagNumber) {
|
|
306
|
+
case 1:
|
|
307
|
+
return "boolean";
|
|
308
|
+
case 2:
|
|
309
|
+
return "integer";
|
|
310
|
+
case 3:
|
|
311
|
+
return "bitString";
|
|
312
|
+
case 4:
|
|
313
|
+
return "octetString";
|
|
314
|
+
case 5:
|
|
315
|
+
return "null";
|
|
316
|
+
case 6:
|
|
317
|
+
return "objectIdentifier";
|
|
318
|
+
case 10:
|
|
319
|
+
return "enumerated";
|
|
320
|
+
case 12:
|
|
321
|
+
return "utf8String";
|
|
322
|
+
case 19:
|
|
323
|
+
return "printableString";
|
|
324
|
+
case 22:
|
|
325
|
+
return "ia5String";
|
|
326
|
+
case 23:
|
|
327
|
+
return "utcTime";
|
|
328
|
+
case 24:
|
|
329
|
+
return "generalizedTime";
|
|
330
|
+
default:
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function Ne(e) {
|
|
335
|
+
const i = Array.isArray(e) ? e : [e];
|
|
336
|
+
return D(i.map((t) => z(t)));
|
|
337
|
+
}
|
|
338
|
+
async function Se(e, i) {
|
|
339
|
+
return ($.parseInput(e, i).nodes ?? []).map(B);
|
|
340
|
+
}
|
|
341
|
+
function B(e) {
|
|
342
|
+
var t, n;
|
|
343
|
+
const i = e.oid ?? e.oidValue ?? Te(e);
|
|
344
|
+
return {
|
|
345
|
+
id: e.id,
|
|
346
|
+
tagClass: Ee(e.tagClass ?? e.className),
|
|
347
|
+
tagNumber: e.tagNumber ?? e.tag ?? 0,
|
|
348
|
+
constructed: e.constructed ?? e.isConstructed ?? !!((t = e.children) != null && t.length),
|
|
349
|
+
tagName: e.tagName,
|
|
350
|
+
valueBytes: p(e.valueBytes ?? e.contentBytes),
|
|
351
|
+
encodedBytes: p(e.bytes),
|
|
352
|
+
value: e.value,
|
|
353
|
+
oid: i,
|
|
354
|
+
oidName: i ? he(i) : void 0,
|
|
355
|
+
children: (n = e.children) == null ? void 0 : n.map(B),
|
|
356
|
+
start: e.start,
|
|
357
|
+
end: e.end
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function Ee(e) {
|
|
361
|
+
return e === 0 || e === "universal" || e === "UNIVERSAL" ? "universal" : e === 1 || e === "application" || e === "APPLICATION" ? "application" : e === 2 || e === "context" || e === "context-specific" || e === "CONTEXT" ? "context" : e === 3 || e === "private" || e === "PRIVATE" ? "private" : "universal";
|
|
362
|
+
}
|
|
363
|
+
function p(e) {
|
|
364
|
+
if (e)
|
|
365
|
+
return e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
366
|
+
}
|
|
367
|
+
function Te(e) {
|
|
368
|
+
if ((e.tagNumber ?? e.tag) !== 6) return;
|
|
369
|
+
const i = p(e.valueBytes ?? e.contentBytes);
|
|
370
|
+
if (!(!i || i.length === 0))
|
|
371
|
+
return $.decodeOid(i);
|
|
372
|
+
}
|
|
373
|
+
function he(e) {
|
|
374
|
+
return H.resolve(e) || void 0;
|
|
375
|
+
}
|
|
376
|
+
const be = `PkiComponents DEFINITIONS EXPLICIT TAGS ::= BEGIN
|
|
377
|
+
Version ::= INTEGER { v1(0), v2(1), v3(2) }
|
|
378
|
+
CertificateSerialNumber ::= INTEGER
|
|
379
|
+
AlgorithmIdentifier ::= SEQUENCE {
|
|
380
|
+
algorithm OBJECT IDENTIFIER,
|
|
381
|
+
parameters CHOICE { null NULL, namedCurve OBJECT IDENTIFIER } OPTIONAL
|
|
382
|
+
}
|
|
383
|
+
AttributeTypeAndValue ::= SEQUENCE {
|
|
384
|
+
type OBJECT IDENTIFIER,
|
|
385
|
+
value DirectoryString
|
|
386
|
+
}
|
|
387
|
+
DirectoryString ::= CHOICE {
|
|
388
|
+
utf8String UTF8String,
|
|
389
|
+
printableString PrintableString,
|
|
390
|
+
ia5String IA5String
|
|
391
|
+
}
|
|
392
|
+
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
|
|
393
|
+
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
|
|
394
|
+
Name ::= CHOICE {
|
|
395
|
+
rdnSequence RDNSequence
|
|
396
|
+
}
|
|
397
|
+
Time ::= CHOICE {
|
|
398
|
+
utcTime UTCTime,
|
|
399
|
+
generalizedTime GeneralizedTime
|
|
400
|
+
}
|
|
401
|
+
Validity ::= SEQUENCE {
|
|
402
|
+
notBefore Time,
|
|
403
|
+
notAfter Time
|
|
404
|
+
}
|
|
405
|
+
SubjectPublicKeyInfo ::= SEQUENCE {
|
|
406
|
+
algorithm AlgorithmIdentifier,
|
|
407
|
+
subjectPublicKey BIT STRING
|
|
408
|
+
}
|
|
409
|
+
RSAPublicKey ::= SEQUENCE {
|
|
410
|
+
modulus INTEGER,
|
|
411
|
+
publicExponent INTEGER
|
|
412
|
+
}
|
|
413
|
+
DSA-Sig-Value ::= SEQUENCE {
|
|
414
|
+
r INTEGER,
|
|
415
|
+
s INTEGER
|
|
416
|
+
}
|
|
417
|
+
ECDSA-Sig-Value ::= SEQUENCE {
|
|
418
|
+
r INTEGER,
|
|
419
|
+
s INTEGER
|
|
420
|
+
}
|
|
421
|
+
SignatureValue ::= BIT STRING
|
|
422
|
+
Extension ::= SEQUENCE {
|
|
423
|
+
extnID OBJECT IDENTIFIER,
|
|
424
|
+
critical BOOLEAN DEFAULT FALSE,
|
|
425
|
+
extnValue OCTET STRING
|
|
426
|
+
}
|
|
427
|
+
Extensions ::= SEQUENCE OF Extension
|
|
428
|
+
TBSCertificate ::= SEQUENCE {
|
|
429
|
+
version [0] EXPLICIT Version DEFAULT v1,
|
|
430
|
+
serialNumber CertificateSerialNumber,
|
|
431
|
+
signature AlgorithmIdentifier,
|
|
432
|
+
issuer Name,
|
|
433
|
+
validity Validity,
|
|
434
|
+
subject Name,
|
|
435
|
+
subjectPublicKeyInfo SubjectPublicKeyInfo,
|
|
436
|
+
issuerUniqueID [1] IMPLICIT BIT STRING OPTIONAL,
|
|
437
|
+
subjectUniqueID [2] IMPLICIT BIT STRING OPTIONAL,
|
|
438
|
+
extensions [3] EXPLICIT Extensions OPTIONAL
|
|
439
|
+
}
|
|
440
|
+
Certificate ::= SEQUENCE {
|
|
441
|
+
tbsCertificate TBSCertificate,
|
|
442
|
+
signatureAlgorithm AlgorithmIdentifier,
|
|
443
|
+
signatureValue SignatureValue
|
|
444
|
+
}
|
|
445
|
+
CertificationRequestInfo ::= SEQUENCE {
|
|
446
|
+
version INTEGER,
|
|
447
|
+
subject Name,
|
|
448
|
+
subjectPKInfo SubjectPublicKeyInfo,
|
|
449
|
+
attributes [0] IMPLICIT SET OF AttributeTypeAndValue OPTIONAL
|
|
450
|
+
}
|
|
451
|
+
CertificationRequest ::= SEQUENCE {
|
|
452
|
+
certificationRequestInfo CertificationRequestInfo,
|
|
453
|
+
signatureAlgorithm AlgorithmIdentifier,
|
|
454
|
+
signature SignatureValue
|
|
455
|
+
}
|
|
456
|
+
PrivateKeyInfo ::= SEQUENCE {
|
|
457
|
+
version INTEGER,
|
|
458
|
+
privateKeyAlgorithm AlgorithmIdentifier,
|
|
459
|
+
privateKey OCTET STRING,
|
|
460
|
+
attributes [0] IMPLICIT SET OF AttributeTypeAndValue OPTIONAL
|
|
461
|
+
}
|
|
462
|
+
ContentInfo ::= SEQUENCE {
|
|
463
|
+
contentType OBJECT IDENTIFIER,
|
|
464
|
+
content [0] EXPLICIT OCTET STRING OPTIONAL
|
|
465
|
+
}
|
|
466
|
+
END`;
|
|
467
|
+
let v;
|
|
468
|
+
function k() {
|
|
469
|
+
return v ?? (v = Ne(be)), v;
|
|
470
|
+
}
|
|
471
|
+
const Ie = {
|
|
472
|
+
components: [
|
|
473
|
+
"AlgorithmIdentifier",
|
|
474
|
+
"AttributeTypeAndValue",
|
|
475
|
+
"DirectoryString",
|
|
476
|
+
"DSA-Sig-Value",
|
|
477
|
+
"ECDSA-Sig-Value",
|
|
478
|
+
"Extension",
|
|
479
|
+
"Extensions",
|
|
480
|
+
"Name",
|
|
481
|
+
"RelativeDistinguishedName",
|
|
482
|
+
"RDNSequence",
|
|
483
|
+
"RSAPublicKey",
|
|
484
|
+
"SignatureValue",
|
|
485
|
+
"SubjectPublicKeyInfo",
|
|
486
|
+
"Time",
|
|
487
|
+
"Validity"
|
|
488
|
+
],
|
|
489
|
+
x509: [
|
|
490
|
+
"Certificate",
|
|
491
|
+
"TBSCertificate",
|
|
492
|
+
"Version",
|
|
493
|
+
"CertificateSerialNumber",
|
|
494
|
+
"AlgorithmIdentifier",
|
|
495
|
+
"DSA-Sig-Value",
|
|
496
|
+
"ECDSA-Sig-Value",
|
|
497
|
+
"Name",
|
|
498
|
+
"Validity",
|
|
499
|
+
"RSAPublicKey",
|
|
500
|
+
"SignatureValue",
|
|
501
|
+
"SubjectPublicKeyInfo",
|
|
502
|
+
"Extension",
|
|
503
|
+
"Extensions"
|
|
504
|
+
],
|
|
505
|
+
pkcs10: [
|
|
506
|
+
"CertificationRequest",
|
|
507
|
+
"CertificationRequestInfo",
|
|
508
|
+
"AlgorithmIdentifier",
|
|
509
|
+
"DSA-Sig-Value",
|
|
510
|
+
"ECDSA-Sig-Value",
|
|
511
|
+
"Name",
|
|
512
|
+
"RSAPublicKey",
|
|
513
|
+
"SignatureValue",
|
|
514
|
+
"SubjectPublicKeyInfo",
|
|
515
|
+
"AttributeTypeAndValue"
|
|
516
|
+
],
|
|
517
|
+
pkcs8: [
|
|
518
|
+
"PrivateKeyInfo",
|
|
519
|
+
"AlgorithmIdentifier",
|
|
520
|
+
"AttributeTypeAndValue"
|
|
521
|
+
],
|
|
522
|
+
cms: [
|
|
523
|
+
"ContentInfo",
|
|
524
|
+
"AlgorithmIdentifier"
|
|
525
|
+
]
|
|
526
|
+
};
|
|
527
|
+
function pe(e) {
|
|
528
|
+
const i = Array.isArray(e) ? e : [e];
|
|
529
|
+
return [...new Set(i.flatMap((t) => Ie[t]))];
|
|
530
|
+
}
|
|
531
|
+
const Ce = /* @__PURE__ */ new Set(["DSA-Sig-Value", "ECDSA-Sig-Value"]);
|
|
532
|
+
async function ye(e, i = {}) {
|
|
533
|
+
const t = await Se(e, i.parseOptions);
|
|
534
|
+
return G(t, i);
|
|
535
|
+
}
|
|
536
|
+
function G(e, i = {}) {
|
|
537
|
+
const t = i.schemaCorpus ?? k(), n = i.maxResults ?? 10, r = i.minScore, s = {
|
|
538
|
+
schemaCorpus: t,
|
|
539
|
+
maxResults: n,
|
|
540
|
+
minScore: r,
|
|
541
|
+
includeTypes: i.includeTypes,
|
|
542
|
+
excludeTypes: i.excludeTypes
|
|
543
|
+
};
|
|
544
|
+
return {
|
|
545
|
+
roots: (Array.isArray(e) ? e : [e]).map((u, c) => {
|
|
546
|
+
const o = K(u, s), l = Ae(o.candidates), f = $e(o.candidates);
|
|
547
|
+
return {
|
|
548
|
+
index: c,
|
|
549
|
+
...i.includeNodes ? { node: u } : {},
|
|
550
|
+
...o,
|
|
551
|
+
hypotheses: fe(u, s),
|
|
552
|
+
...i.includeSubtrees ? { subtrees: ve(u, s, i, l, f) } : {}
|
|
553
|
+
};
|
|
554
|
+
})
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
function K(e, i) {
|
|
558
|
+
const t = L(e, i), n = M(t.flatMap((s) => s.diagnostics)), r = [...new Set(t.flatMap((s) => s.ambiguities))];
|
|
559
|
+
return {
|
|
560
|
+
features: de(e),
|
|
561
|
+
summary: j(t, n, r),
|
|
562
|
+
candidates: t,
|
|
563
|
+
diagnostics: n,
|
|
564
|
+
ambiguities: r
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function ve(e, i, t, n, r) {
|
|
568
|
+
const s = t.maxSubtreeDepth ?? 3, a = t.maxSubtreeReports ?? 20, u = [];
|
|
569
|
+
return q(e, "$", 0, s, a, u, (c, o) => {
|
|
570
|
+
const l = Oe({
|
|
571
|
+
path: o,
|
|
572
|
+
...t.includeNodes ? { node: c } : {},
|
|
573
|
+
...K(c, i)
|
|
574
|
+
}, n, r);
|
|
575
|
+
return t.includeEmptySubtrees || l.candidates.length > 0 ? l : void 0;
|
|
576
|
+
}), u;
|
|
577
|
+
}
|
|
578
|
+
function Ae(e) {
|
|
579
|
+
const i = /* @__PURE__ */ new Set();
|
|
580
|
+
for (const t of e)
|
|
581
|
+
if (!(t.typeName !== "Certificate" && t.typeName !== "CertificationRequest" || t.score < 0.8))
|
|
582
|
+
for (const n of t.matchedPaths)
|
|
583
|
+
(n.schemaPath.endsWith(".signatureValue.SignatureValue") || n.schemaPath.endsWith(".signature.SignatureValue")) && i.add(n.nodePath);
|
|
584
|
+
return i;
|
|
585
|
+
}
|
|
586
|
+
function $e(e) {
|
|
587
|
+
const i = /* @__PURE__ */ new Set();
|
|
588
|
+
for (const t of e)
|
|
589
|
+
if (!(t.score < 0.8))
|
|
590
|
+
for (const n of t.matchedPaths)
|
|
591
|
+
n.schemaPath.endsWith(".subjectPublicKey") && i.add(n.nodePath);
|
|
592
|
+
return i;
|
|
593
|
+
}
|
|
594
|
+
function Oe(e, i, t) {
|
|
595
|
+
if (i.has(e.path)) return e;
|
|
596
|
+
const n = A(e.path, i), r = A(e.path, t), s = e.candidates.filter((c) => c.typeName !== "SignatureValue" && !(n && c.typeName === "RSAPublicKey") && !(r && Ce.has(c.typeName)));
|
|
597
|
+
if (s.length === e.candidates.length) return e;
|
|
598
|
+
const a = M(s.flatMap((c) => c.diagnostics)), u = [...new Set(s.flatMap((c) => c.ambiguities))];
|
|
599
|
+
return {
|
|
600
|
+
...e,
|
|
601
|
+
candidates: s,
|
|
602
|
+
diagnostics: a,
|
|
603
|
+
ambiguities: u,
|
|
604
|
+
summary: j(s, a, u)
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
function A(e, i) {
|
|
608
|
+
for (const t of i)
|
|
609
|
+
if (e.startsWith(`${t}.`)) return !0;
|
|
610
|
+
return !1;
|
|
611
|
+
}
|
|
612
|
+
function q(e, i, t, n, r, s, a) {
|
|
613
|
+
if (!(t >= n || s.length >= r))
|
|
614
|
+
for (const [u, c] of (e.children ?? []).entries()) {
|
|
615
|
+
if (s.length >= r) return;
|
|
616
|
+
const o = `${i}.${u}`, l = a(c, o);
|
|
617
|
+
l && s.push(l), q(c, o, t + 1, n, r, s, a);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
function j(e, i, t) {
|
|
621
|
+
const n = e[0] ? {
|
|
622
|
+
typeName: e[0].typeName,
|
|
623
|
+
moduleName: e[0].moduleName,
|
|
624
|
+
score: e[0].score,
|
|
625
|
+
confidence: e[0].confidence
|
|
626
|
+
} : void 0;
|
|
627
|
+
return {
|
|
628
|
+
candidateCount: e.length,
|
|
629
|
+
...n ? { bestCandidate: n } : {},
|
|
630
|
+
diagnosticCounts: Re(i),
|
|
631
|
+
ambiguityCount: t.length
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function Re(e) {
|
|
635
|
+
return e.reduce(
|
|
636
|
+
(i, t) => ({ ...i, [t.severity]: i[t.severity] + 1 }),
|
|
637
|
+
{ info: 0, warning: 0, error: 0 }
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
function M(e) {
|
|
641
|
+
const i = /* @__PURE__ */ new Set();
|
|
642
|
+
return e.filter((t) => {
|
|
643
|
+
const n = `${t.severity}\0${t.path}\0${t.message}`;
|
|
644
|
+
return i.has(n) ? !1 : (i.add(n), !0);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
async function Ue(e, i = {}) {
|
|
648
|
+
return ye(e, Q(i));
|
|
649
|
+
}
|
|
650
|
+
function Le(e, i = {}) {
|
|
651
|
+
return G(e, Q(i));
|
|
652
|
+
}
|
|
653
|
+
function Q(e) {
|
|
654
|
+
const { profiles: i, includeTypes: t, ...n } = e;
|
|
655
|
+
return {
|
|
656
|
+
...n,
|
|
657
|
+
schemaCorpus: k(),
|
|
658
|
+
includeTypes: xe(i, t)
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function xe(e, i) {
|
|
662
|
+
const t = e ? pe(e) : [], n = [.../* @__PURE__ */ new Set([...t, ...i ?? []])];
|
|
663
|
+
return n.length > 0 ? n : void 0;
|
|
664
|
+
}
|
|
665
|
+
export {
|
|
666
|
+
ae as a,
|
|
667
|
+
_ as b,
|
|
668
|
+
ce as c,
|
|
669
|
+
ye as d,
|
|
670
|
+
G as e,
|
|
671
|
+
Ue as f,
|
|
672
|
+
Le as g,
|
|
673
|
+
k as h,
|
|
674
|
+
D as i,
|
|
675
|
+
X as j,
|
|
676
|
+
de as k,
|
|
677
|
+
L as l,
|
|
678
|
+
O as m,
|
|
679
|
+
pe as n,
|
|
680
|
+
fe as o,
|
|
681
|
+
Y as p,
|
|
682
|
+
Z as q,
|
|
683
|
+
Ne as r,
|
|
684
|
+
Se as s,
|
|
685
|
+
be as t,
|
|
686
|
+
Ie as u,
|
|
687
|
+
B as v
|
|
688
|
+
};
|