micro509 0.9.0 → 0.11.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/dist/index.d.ts +5 -4
- package/dist/index.js +16 -15
- package/dist/internal/asn1/asn1.js +145 -186
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +210 -227
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +297 -101
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/asn1/oids2.js +69 -0
- package/dist/internal/asn1/oids2.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +37 -35
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +25 -28
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +56 -117
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.js +122 -133
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +118 -124
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +87 -99
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +12 -8
- package/dist/internal/crypto/signing.js +53 -55
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +5 -3
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +10 -9
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +50 -57
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +43 -53
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +211 -239
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +228 -247
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +213 -228
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +62 -59
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +133 -164
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +35 -41
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +583 -547
- package/dist/keys/keys.js +519 -431
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +46 -46
- package/dist/pem/pem.js +62 -81
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.js +2 -2
- package/dist/pkcs/pfx.d.ts +96 -80
- package/dist/pkcs/pfx.js +191 -231
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +20 -18
- package/dist/pkcs/pkcs12-mac.js +90 -111
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +118 -69
- package/dist/pkcs/pkcs7.js +401 -443
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +37 -32
- package/dist/result/result.js +46 -44
- package/dist/result/result.js.map +1 -0
- package/dist/result.js +2 -2
- package/dist/revocation/chain.d.ts +138 -119
- package/dist/revocation/chain.js +248 -281
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +125 -123
- package/dist/revocation/crl.js +653 -745
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +183 -177
- package/dist/revocation/ocsp.js +579 -636
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +26 -26
- package/dist/revocation/revocation.js +104 -125
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +42 -42
- package/dist/verify/identity.js +158 -167
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +7 -7
- package/dist/verify/policy.d.ts +10 -10
- package/dist/verify/verify.d.ts +163 -163
- package/dist/verify/verify.js +396 -392
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.js +3 -3
- package/dist/x509/certificate.d.ts +117 -117
- package/dist/x509/certificate.js +51 -60
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +25 -25
- package/dist/x509/csr.js +26 -30
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +228 -184
- package/dist/x509/extensions.js +175 -200
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/fingerprint.d.ts +55 -0
- package/dist/x509/fingerprint.js +55 -0
- package/dist/x509/fingerprint.js.map +1 -0
- package/dist/x509/name.d.ts +94 -93
- package/dist/x509/name.js +30 -29
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +288 -185
- package/dist/x509/parse.js +762 -677
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.d.ts +3 -2
- package/dist/x509.js +7 -6
- package/package.json +79 -41
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OIDS } from "../asn1/
|
|
2
|
-
import { compareDistinguishedNames } from "../shared/dn.js";
|
|
1
|
+
import { OIDS as e } from "../asn1/oids2.js";
|
|
2
|
+
import { compareDistinguishedNames as t } from "../shared/dn.js";
|
|
3
3
|
//#region src/internal/verify/policy-engine.ts
|
|
4
4
|
/**
|
|
5
5
|
* Internal RFC 9618 policy-validation engine.
|
|
@@ -15,13 +15,13 @@ import { compareDistinguishedNames } from "../shared/dn.js";
|
|
|
15
15
|
* Counter values default to `chainLength + 1` (effectively disabled) unless
|
|
16
16
|
* the corresponding input flag is `true`.
|
|
17
17
|
*/
|
|
18
|
-
function createPolicyValidationState(
|
|
19
|
-
|
|
18
|
+
function createPolicyValidationState(e, t) {
|
|
19
|
+
let n = t + 1;
|
|
20
20
|
return {
|
|
21
|
-
initialPolicySet:
|
|
22
|
-
explicitPolicy:
|
|
23
|
-
inhibitPolicyMapping:
|
|
24
|
-
inhibitAnyPolicy:
|
|
21
|
+
initialPolicySet: e.initialPolicySet ?? "any",
|
|
22
|
+
explicitPolicy: e.requireExplicitPolicy === !0 ? 0 : n,
|
|
23
|
+
inhibitPolicyMapping: e.inhibitPolicyMapping === !0 ? 0 : n,
|
|
24
|
+
inhibitAnyPolicy: e.inhibitAnyPolicy === !0 ? 0 : n,
|
|
25
25
|
validPolicyGraph: createInitialPolicyGraph()
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -29,354 +29,335 @@ function createPolicyValidationState(input, chainLength) {
|
|
|
29
29
|
* Walks the chain root-to-leaf, updating policy state per certificate,
|
|
30
30
|
* then checks whether the resulting policy set satisfies caller requirements.
|
|
31
31
|
*/
|
|
32
|
-
function evaluatePolicyChain(
|
|
33
|
-
if (
|
|
34
|
-
processPolicyState(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
ok:
|
|
32
|
+
function evaluatePolicyChain(e, t) {
|
|
33
|
+
if (e.length === 0) throw RangeError("policy validation requires at least one certificate");
|
|
34
|
+
processPolicyState(e, t);
|
|
35
|
+
let n = derivePolicyValidationOutcome(e, t);
|
|
36
|
+
return t.explicitPolicy === 0 && n.userConstrainedPolicies.length === 0 ? {
|
|
37
|
+
ok: !1,
|
|
38
38
|
error: {
|
|
39
39
|
code: "explicit_policy_required",
|
|
40
40
|
message: "policy validation requires an explicit permitted policy",
|
|
41
41
|
details: {
|
|
42
|
-
expected:
|
|
43
|
-
actual: describeFinalPolicies(
|
|
42
|
+
expected: t.initialPolicySet === "any" ? "explicit policy" : t.initialPolicySet.join(","),
|
|
43
|
+
actual: describeFinalPolicies(n.userConstrainedPolicies)
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
ok: false,
|
|
46
|
+
} : t.initialPolicySet !== "any" && n.userConstrainedPolicies.length === 0 ? {
|
|
47
|
+
ok: !1,
|
|
49
48
|
error: {
|
|
50
49
|
code: "initial_policy_set_not_satisfied",
|
|
51
50
|
message: "certificate chain does not satisfy the requested initial policy set",
|
|
52
51
|
details: {
|
|
53
|
-
expected:
|
|
54
|
-
actual: describeFinalPolicies(
|
|
52
|
+
expected: t.initialPolicySet.join(","),
|
|
53
|
+
actual: describeFinalPolicies(n.userConstrainedPolicies)
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
value: outcome
|
|
56
|
+
} : {
|
|
57
|
+
ok: !0,
|
|
58
|
+
value: n
|
|
61
59
|
};
|
|
62
60
|
}
|
|
63
61
|
/** Builds the depth-0 graph with a single anyPolicy root node. */
|
|
64
62
|
function createInitialPolicyGraph() {
|
|
65
|
-
|
|
66
|
-
return { nodesByDepth: [/* @__PURE__ */ new Map([[policyNodeKey(0,
|
|
63
|
+
let t = createPolicyGraphNode(0, e.anyPolicy, void 0, [e.anyPolicy], []);
|
|
64
|
+
return { nodesByDepth: [/* @__PURE__ */ new Map([[policyNodeKey(0, e.anyPolicy), t]])] };
|
|
67
65
|
}
|
|
68
66
|
/** Constructs a new {@linkcode PolicyGraphNode} with empty child-key set. */
|
|
69
|
-
function createPolicyGraphNode(
|
|
67
|
+
function createPolicyGraphNode(e, t, n, r, i) {
|
|
70
68
|
return {
|
|
71
|
-
depth,
|
|
72
|
-
validPolicy,
|
|
73
|
-
...
|
|
74
|
-
expectedPolicySet: new Set(
|
|
75
|
-
parentKeys: new Set(
|
|
69
|
+
depth: e,
|
|
70
|
+
validPolicy: t,
|
|
71
|
+
...n === void 0 ? {} : { qualifierSet: n },
|
|
72
|
+
expectedPolicySet: new Set(r),
|
|
73
|
+
parentKeys: new Set(i),
|
|
76
74
|
childKeys: /* @__PURE__ */ new Set()
|
|
77
75
|
};
|
|
78
76
|
}
|
|
79
77
|
/** Canonical map key for a graph node: `"depth:policyOID"`. */
|
|
80
|
-
function policyNodeKey(
|
|
81
|
-
return `${String(
|
|
78
|
+
function policyNodeKey(e, t) {
|
|
79
|
+
return `${String(e)}:${t}`;
|
|
82
80
|
}
|
|
83
81
|
/** Iterates root-to-leaf (skipping root), applying each certificate's policies to the state. */
|
|
84
|
-
function processPolicyState(
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
processPolicyCertificate(
|
|
82
|
+
function processPolicyState(e, t) {
|
|
83
|
+
if (e.length === 1) {
|
|
84
|
+
let n = e[0];
|
|
85
|
+
if (n === void 0) throw Error(`missing certificate at chain index 0 (chain length ${String(e.length)})`);
|
|
86
|
+
processPolicyCertificate(t, n, 1, !0);
|
|
89
87
|
return;
|
|
90
88
|
}
|
|
91
|
-
|
|
92
|
-
for (let
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
processPolicyCertificate(
|
|
89
|
+
let n = e.length - 1;
|
|
90
|
+
for (let r = e.length - 2; r >= 0; --r) {
|
|
91
|
+
let i = e[r];
|
|
92
|
+
if (i === void 0) throw Error(`missing certificate at chain index ${String(r)} (chain length ${String(e.length)})`);
|
|
93
|
+
let a = n - r;
|
|
94
|
+
processPolicyCertificate(t, i, a, a === n);
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
/** Extracts the final authority- and user-constrained policy sets from the completed graph. */
|
|
100
|
-
function derivePolicyValidationOutcome(
|
|
101
|
-
|
|
102
|
-
const rootDomainPolicies = collectRootDomainPolicies(chain, state.validPolicyGraph);
|
|
98
|
+
function derivePolicyValidationOutcome(e, t) {
|
|
99
|
+
let n = collectAuthorityConstrainedPolicies(e, t.validPolicyGraph), r = collectRootDomainPolicies(e, t.validPolicyGraph);
|
|
103
100
|
return {
|
|
104
|
-
authorityConstrainedPolicies: [...
|
|
105
|
-
userConstrainedPolicies: deriveUserConstrainedPolicies(
|
|
101
|
+
authorityConstrainedPolicies: [...n.values()].sort(comparePolicies),
|
|
102
|
+
userConstrainedPolicies: deriveUserConstrainedPolicies(n, r, t.initialPolicySet)
|
|
106
103
|
};
|
|
107
104
|
}
|
|
108
105
|
/** Collects leaf-depth policies whose graph paths trace back to the anyPolicy root. */
|
|
109
|
-
function collectAuthorityConstrainedPolicies(
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
authorityPolicies.set(OIDS.anyPolicy, buildConstrainedPolicy(OIDS.anyPolicy, node.qualifierSet));
|
|
106
|
+
function collectAuthorityConstrainedPolicies(t, n) {
|
|
107
|
+
if (n === null) return /* @__PURE__ */ new Map();
|
|
108
|
+
let r = Math.max(1, t.length - 1), i = n.nodesByDepth[r];
|
|
109
|
+
if (i === void 0) return /* @__PURE__ */ new Map();
|
|
110
|
+
let a = /* @__PURE__ */ new Map();
|
|
111
|
+
for (let [t, r] of i) {
|
|
112
|
+
if (r.validPolicy === e.anyPolicy) {
|
|
113
|
+
a.set(e.anyPolicy, buildConstrainedPolicy(e.anyPolicy, r.qualifierSet));
|
|
118
114
|
continue;
|
|
119
115
|
}
|
|
120
|
-
|
|
116
|
+
reachesAuthorityRoot(n, t) && a.set(r.validPolicy, buildConstrainedPolicy(r.validPolicy, r.qualifierSet));
|
|
121
117
|
}
|
|
122
|
-
return
|
|
118
|
+
return a;
|
|
123
119
|
}
|
|
124
120
|
/** DFS upward through parent links to check if the node ultimately connects to the depth-0 anyPolicy root. */
|
|
125
|
-
function reachesAuthorityRoot(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
pending.push(parentKey);
|
|
121
|
+
function reachesAuthorityRoot(t, n) {
|
|
122
|
+
let r = [n], i = /* @__PURE__ */ new Set();
|
|
123
|
+
for (; r.length > 0;) {
|
|
124
|
+
let n = r.pop();
|
|
125
|
+
if (n === void 0 || i.has(n)) continue;
|
|
126
|
+
i.add(n);
|
|
127
|
+
let a = getPolicyGraphNode(t, n);
|
|
128
|
+
if (a !== void 0) for (let n of a.parentKeys) {
|
|
129
|
+
let i = getPolicyGraphNode(t, n);
|
|
130
|
+
if (i !== void 0) {
|
|
131
|
+
if (i.depth === 0 && i.validPolicy === e.anyPolicy) return !0;
|
|
132
|
+
r.push(n);
|
|
133
|
+
}
|
|
139
134
|
}
|
|
140
135
|
}
|
|
141
|
-
return
|
|
136
|
+
return !1;
|
|
142
137
|
}
|
|
143
138
|
/** Like authority-constrained, but records the OID at the depth-1 node that connects to root. */
|
|
144
|
-
function collectRootDomainPolicies(
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
rootPolicies.set(OIDS.anyPolicy, buildConstrainedPolicy(OIDS.anyPolicy, node.qualifierSet));
|
|
139
|
+
function collectRootDomainPolicies(t, n) {
|
|
140
|
+
if (n === null) return /* @__PURE__ */ new Map();
|
|
141
|
+
let r = Math.max(1, t.length - 1), i = n.nodesByDepth[r];
|
|
142
|
+
if (i === void 0) return /* @__PURE__ */ new Map();
|
|
143
|
+
let a = /* @__PURE__ */ new Map();
|
|
144
|
+
for (let [t, r] of i) {
|
|
145
|
+
if (r.validPolicy === e.anyPolicy) {
|
|
146
|
+
a.set(e.anyPolicy, buildConstrainedPolicy(e.anyPolicy, r.qualifierSet));
|
|
153
147
|
continue;
|
|
154
148
|
}
|
|
155
|
-
collectAuthorityConstrainedPolicyRoots(
|
|
149
|
+
collectAuthorityConstrainedPolicyRoots(n, t, a);
|
|
156
150
|
}
|
|
157
|
-
return
|
|
151
|
+
return a;
|
|
158
152
|
}
|
|
159
153
|
/** Walks parent links upward, collecting the depth-1 OID that first connects to the root anyPolicy. */
|
|
160
|
-
function collectAuthorityConstrainedPolicyRoots(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
154
|
+
function collectAuthorityConstrainedPolicyRoots(t, n, r) {
|
|
155
|
+
let i = [n], a = /* @__PURE__ */ new Set();
|
|
156
|
+
for (; i.length > 0;) {
|
|
157
|
+
let o = i.pop();
|
|
158
|
+
if (o === void 0 || a.has(o)) continue;
|
|
159
|
+
a.add(o);
|
|
160
|
+
let s = getPolicyGraphNode(t, o);
|
|
161
|
+
if (s !== void 0) for (let a of s.parentKeys) {
|
|
162
|
+
let c = getPolicyGraphNode(t, a);
|
|
163
|
+
if (c !== void 0) {
|
|
164
|
+
if (c.depth === 0 && c.validPolicy === e.anyPolicy) {
|
|
165
|
+
r.set(s.validPolicy, buildConstrainedPolicy(s.validPolicy, o === n ? s.qualifierSet : void 0));
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
i.push(a);
|
|
175
169
|
}
|
|
176
|
-
pending.push(parentKey);
|
|
177
170
|
}
|
|
178
171
|
}
|
|
179
172
|
}
|
|
180
173
|
/** Intersects root-domain policies with the caller's initial-policy-set. */
|
|
181
|
-
function deriveUserConstrainedPolicies(
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (direct !== void 0) {
|
|
189
|
-
constrained.set(policyIdentifier, direct);
|
|
174
|
+
function deriveUserConstrainedPolicies(t, n, r) {
|
|
175
|
+
if (r === "any") return [...t.values()].sort(comparePolicies);
|
|
176
|
+
let i = n.get(e.anyPolicy), a = t.has(e.anyPolicy), o = /* @__PURE__ */ new Map();
|
|
177
|
+
for (let e of r) {
|
|
178
|
+
let r = n.get(e);
|
|
179
|
+
if (r !== void 0) {
|
|
180
|
+
o.set(e, r);
|
|
190
181
|
continue;
|
|
191
182
|
}
|
|
192
|
-
|
|
183
|
+
i !== void 0 && (t.has(e) || a) && o.set(e, buildConstrainedPolicy(e, i.policyQualifiers));
|
|
193
184
|
}
|
|
194
|
-
return [...
|
|
185
|
+
return [...o.values()].sort(comparePolicies);
|
|
195
186
|
}
|
|
196
187
|
/** Constructs a {@linkcode ConstrainedPolicy}, omitting qualifiers when absent. */
|
|
197
|
-
function buildConstrainedPolicy(
|
|
188
|
+
function buildConstrainedPolicy(e, t) {
|
|
198
189
|
return {
|
|
199
|
-
policyIdentifier,
|
|
200
|
-
...
|
|
190
|
+
policyIdentifier: e,
|
|
191
|
+
...t === void 0 ? {} : { policyQualifiers: t }
|
|
201
192
|
};
|
|
202
193
|
}
|
|
203
194
|
/** Lexicographic comparator for sorting policies by OID string. */
|
|
204
|
-
function comparePolicies(
|
|
205
|
-
return
|
|
195
|
+
function comparePolicies(e, t) {
|
|
196
|
+
return e.policyIdentifier.localeCompare(t.policyIdentifier);
|
|
206
197
|
}
|
|
207
198
|
/** Human-readable comma-joined OID list for error messages; `"<none>"` when empty. */
|
|
208
|
-
function describeFinalPolicies(
|
|
209
|
-
return
|
|
199
|
+
function describeFinalPolicies(e) {
|
|
200
|
+
return e.length === 0 ? "<none>" : e.map((e) => e.policyIdentifier).join(",");
|
|
210
201
|
}
|
|
211
202
|
/** Applies one certificate's policies, mappings, and constraints to the running state. */
|
|
212
|
-
function processPolicyCertificate(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
else if (state.validPolicyGraph !== null && certificatePolicies !== void 0) {
|
|
216
|
-
applyCertificatePolicyStep(state.validPolicyGraph, certificatePolicies, depth, state.inhibitAnyPolicy > 0 || !isLeaf && isSelfIssued(certificate));
|
|
217
|
-
if (certificate.policyMappings !== void 0) applyPolicyMappingsStep(state.validPolicyGraph, depth, certificate.policyMappings, state.inhibitPolicyMapping > 0);
|
|
218
|
-
}
|
|
219
|
-
updatePolicyCounters(state, certificate, isLeaf);
|
|
203
|
+
function processPolicyCertificate(e, t, n, r) {
|
|
204
|
+
let i = normalizeCertificatePolicies(t.certificatePolicies);
|
|
205
|
+
e.validPolicyGraph !== null && i === void 0 ? e.validPolicyGraph = null : e.validPolicyGraph !== null && i !== void 0 && (applyCertificatePolicyStep(e.validPolicyGraph, i, n, e.inhibitAnyPolicy > 0 || !r && isSelfIssued(t)), t.policyMappings !== void 0 && applyPolicyMappingsStep(e.validPolicyGraph, n, t.policyMappings, e.inhibitPolicyMapping > 0)), updatePolicyCounters(e, t, r);
|
|
220
206
|
}
|
|
221
207
|
/** Deduplicates certificate policies by OID, keeping the first occurrence. */
|
|
222
|
-
function normalizeCertificatePolicies(
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
for (
|
|
226
|
-
return
|
|
208
|
+
function normalizeCertificatePolicies(e) {
|
|
209
|
+
if (e === void 0) return;
|
|
210
|
+
let t = /* @__PURE__ */ new Map();
|
|
211
|
+
for (let n of e) t.has(n.policyIdentifier) || t.set(n.policyIdentifier, n);
|
|
212
|
+
return t;
|
|
227
213
|
}
|
|
228
214
|
/** Extends the policy graph by one depth level using a certificate's policy extension. */
|
|
229
|
-
function applyCertificatePolicyStep(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const previousAnyPolicyKey = policyNodeKey(depth - 1, OIDS.anyPolicy);
|
|
242
|
-
for (const policy of certificatePolicies.values()) {
|
|
243
|
-
if (policy.policyIdentifier === OIDS.anyPolicy) continue;
|
|
244
|
-
if (currentDepth.has(policyNodeKey(depth, policy.policyIdentifier))) continue;
|
|
245
|
-
addOrMergePolicyNode(graph, currentDepth, depth, policy.policyIdentifier, policy.policyQualifiers, [previousAnyPolicyKey], [policy.policyIdentifier]);
|
|
246
|
-
}
|
|
215
|
+
function applyCertificatePolicyStep(t, n, r, i) {
|
|
216
|
+
let a = t.nodesByDepth[r - 1] ?? /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
217
|
+
t.nodesByDepth[r] = o;
|
|
218
|
+
let s = n.get(e.anyPolicy), c = a.get(policyNodeKey(r - 1, e.anyPolicy)), l = policyNodeKey(r - 1, e.anyPolicy);
|
|
219
|
+
addPolicyNodesFromExpectedParents(t, o, a, n, r), c !== void 0 && addPolicyNodesFromPreviousAnyPolicy(t, o, n, r, l), s !== void 0 && i && addAnyPolicyExpansionNodes(t, o, a, r, s, l, c !== void 0), prunePolicyGraph(t, r - 1);
|
|
220
|
+
}
|
|
221
|
+
/** Adds explicit certificate-policy nodes whose expected policies match parent nodes. */
|
|
222
|
+
function addPolicyNodesFromExpectedParents(t, n, r, i, a) {
|
|
223
|
+
for (let o of i.values()) {
|
|
224
|
+
if (o.policyIdentifier === e.anyPolicy) continue;
|
|
225
|
+
let i = collectParentsForExpectedPolicy(r, o.policyIdentifier);
|
|
226
|
+
i.length !== 0 && addOrMergePolicyNode(t, n, a, o.policyIdentifier, o.policyQualifiers, i, [o.policyIdentifier]);
|
|
247
227
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
228
|
+
}
|
|
229
|
+
function addPolicyNodesFromPreviousAnyPolicy(t, n, r, i, a) {
|
|
230
|
+
for (let o of r.values()) o.policyIdentifier !== e.anyPolicy && (n.has(policyNodeKey(i, o.policyIdentifier)) || addOrMergePolicyNode(t, n, i, o.policyIdentifier, o.policyQualifiers, [a], [o.policyIdentifier]));
|
|
231
|
+
}
|
|
232
|
+
/** Expands an accepted anyPolicy entry into the policies expected by the previous depth. */
|
|
233
|
+
function addAnyPolicyExpansionNodes(e, t, n, r, i, a, o) {
|
|
234
|
+
for (let [s, c] of collectExpectedPolicyParents(n)) {
|
|
235
|
+
if (t.has(policyNodeKey(r, s))) continue;
|
|
236
|
+
let n = collectAnyPolicyExpansionParents(s, c, a, o);
|
|
237
|
+
n.length !== 0 && addOrMergePolicyNode(e, t, r, s, i.policyQualifiers, n, [s]);
|
|
253
238
|
}
|
|
254
|
-
|
|
239
|
+
}
|
|
240
|
+
function collectAnyPolicyExpansionParents(t, n, r, i) {
|
|
241
|
+
return t === e.anyPolicy ? i ? [r] : [] : n;
|
|
255
242
|
}
|
|
256
243
|
/** Finds all previous-depth nodes whose expectedPolicySet contains the given OID. */
|
|
257
|
-
function collectParentsForExpectedPolicy(
|
|
258
|
-
|
|
259
|
-
for (
|
|
260
|
-
return
|
|
244
|
+
function collectParentsForExpectedPolicy(e, t) {
|
|
245
|
+
let n = [];
|
|
246
|
+
for (let [r, i] of e) i.expectedPolicySet.has(t) && n.push(r);
|
|
247
|
+
return n;
|
|
261
248
|
}
|
|
262
249
|
/** Groups all previous-depth nodes by each OID in their expectedPolicySet. */
|
|
263
|
-
function collectExpectedPolicyParents(
|
|
264
|
-
|
|
265
|
-
for (
|
|
266
|
-
|
|
267
|
-
if (
|
|
268
|
-
|
|
250
|
+
function collectExpectedPolicyParents(e) {
|
|
251
|
+
let t = /* @__PURE__ */ new Map();
|
|
252
|
+
for (let [n, r] of e) for (let e of r.expectedPolicySet) {
|
|
253
|
+
let r = t.get(e);
|
|
254
|
+
if (r === void 0) {
|
|
255
|
+
t.set(e, [n]);
|
|
269
256
|
continue;
|
|
270
257
|
}
|
|
271
|
-
|
|
258
|
+
r.push(n);
|
|
272
259
|
}
|
|
273
|
-
return
|
|
260
|
+
return t;
|
|
274
261
|
}
|
|
275
262
|
/** Inserts a node at the current depth, or merges parents/expected-policies into an existing one. */
|
|
276
|
-
function addOrMergePolicyNode(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
for (
|
|
281
|
-
|
|
282
|
-
getPolicyGraphNode(graph, parentKey)?.childKeys.add(key);
|
|
283
|
-
}
|
|
284
|
-
for (const expectedPolicy of expectedPolicySet) existing.expectedPolicySet.add(expectedPolicy);
|
|
285
|
-
if (existing.qualifierSet === void 0 && qualifierSet !== void 0) existing.qualifierSet = qualifierSet;
|
|
263
|
+
function addOrMergePolicyNode(e, t, n, r, i, a, o) {
|
|
264
|
+
let s = policyNodeKey(n, r), c = t.get(s);
|
|
265
|
+
if (c !== void 0) {
|
|
266
|
+
for (let t of a) c.parentKeys.add(t), getPolicyGraphNode(e, t)?.childKeys.add(s);
|
|
267
|
+
for (let e of o) c.expectedPolicySet.add(e);
|
|
268
|
+
c.qualifierSet === void 0 && i !== void 0 && (c.qualifierSet = i);
|
|
286
269
|
return;
|
|
287
270
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
for (
|
|
271
|
+
let l = createPolicyGraphNode(n, r, i, o, a);
|
|
272
|
+
t.set(s, l);
|
|
273
|
+
for (let t of a) getPolicyGraphNode(e, t)?.childKeys.add(s);
|
|
291
274
|
}
|
|
292
275
|
/** Looks up a node by its `"depth:oid"` key, parsing the depth prefix. */
|
|
293
|
-
function getPolicyGraphNode(
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (Number.isNaN(depth)) return;
|
|
299
|
-
return graph.nodesByDepth[depth]?.get(key);
|
|
276
|
+
function getPolicyGraphNode(e, t) {
|
|
277
|
+
let n = t.indexOf(":");
|
|
278
|
+
if (n <= 0) return;
|
|
279
|
+
let r = t.slice(0, n), i = Number.parseInt(r, 10);
|
|
280
|
+
if (!Number.isNaN(i)) return e.nodesByDepth[i]?.get(t);
|
|
300
281
|
}
|
|
301
282
|
/** Removes childless leaf nodes bottom-up, cascading deletions through parent links. */
|
|
302
|
-
function prunePolicyGraph(
|
|
303
|
-
for (let
|
|
304
|
-
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (node === void 0 || node.childKeys.size > 0) continue;
|
|
309
|
-
deletePolicyGraphNode(graph, key);
|
|
283
|
+
function prunePolicyGraph(e, t) {
|
|
284
|
+
for (let n = t; n >= 0; --n) {
|
|
285
|
+
let t = e.nodesByDepth[n];
|
|
286
|
+
if (t !== void 0) for (let n of [...t.keys()]) {
|
|
287
|
+
let r = t.get(n);
|
|
288
|
+
r === void 0 || r.childKeys.size > 0 || deletePolicyGraphNode(e, n);
|
|
310
289
|
}
|
|
311
290
|
}
|
|
312
291
|
}
|
|
313
292
|
/** Removes a node and recursively prunes its parents if they become childless. */
|
|
314
|
-
function deletePolicyGraphNode(
|
|
315
|
-
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (parent.childKeys.size === 0) deletePolicyGraphNode(graph, parentKey);
|
|
293
|
+
function deletePolicyGraphNode(e, t) {
|
|
294
|
+
let n = getPolicyGraphNode(e, t);
|
|
295
|
+
if (n !== void 0) {
|
|
296
|
+
e.nodesByDepth[n.depth]?.delete(t);
|
|
297
|
+
for (let r of n.parentKeys) {
|
|
298
|
+
let n = getPolicyGraphNode(e, r);
|
|
299
|
+
n !== void 0 && (n.childKeys.delete(t), n.childKeys.size === 0 && deletePolicyGraphNode(e, r));
|
|
300
|
+
}
|
|
323
301
|
}
|
|
324
302
|
}
|
|
325
303
|
/** Applies issuer→subject policy mappings at the current depth, or deletes mapped nodes when disallowed. */
|
|
326
|
-
function applyPolicyMappingsStep(
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
for (
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
if (
|
|
334
|
-
|
|
304
|
+
function applyPolicyMappingsStep(t, n, r, i) {
|
|
305
|
+
let a = t.nodesByDepth[n];
|
|
306
|
+
if (a === void 0) return;
|
|
307
|
+
let o = /* @__PURE__ */ new Map();
|
|
308
|
+
for (let t of r) {
|
|
309
|
+
if (t.issuerDomainPolicy === e.anyPolicy || t.subjectDomainPolicy === e.anyPolicy) continue;
|
|
310
|
+
let n = o.get(t.issuerDomainPolicy);
|
|
311
|
+
if (n === void 0) {
|
|
312
|
+
o.set(t.issuerDomainPolicy, [t.subjectDomainPolicy]);
|
|
335
313
|
continue;
|
|
336
314
|
}
|
|
337
|
-
|
|
315
|
+
n.push(t.subjectDomainPolicy);
|
|
338
316
|
}
|
|
339
|
-
|
|
340
|
-
for (
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
node.expectedPolicySet = new Set(subjectDomainPolicies);
|
|
317
|
+
let s = a.get(policyNodeKey(n, e.anyPolicy));
|
|
318
|
+
for (let [e, r] of o) {
|
|
319
|
+
let o = policyNodeKey(n, e), c = a.get(o);
|
|
320
|
+
if (i) {
|
|
321
|
+
if (c !== void 0) {
|
|
322
|
+
c.expectedPolicySet = new Set(r);
|
|
346
323
|
continue;
|
|
347
324
|
}
|
|
348
|
-
|
|
325
|
+
s !== void 0 && addOrMergePolicyNode(t, a, n, e, s.qualifierSet, [...s.parentKeys], r);
|
|
349
326
|
continue;
|
|
350
327
|
}
|
|
351
|
-
|
|
328
|
+
c !== void 0 && deletePolicyGraphNode(t, o);
|
|
352
329
|
}
|
|
353
|
-
prunePolicyGraph(
|
|
330
|
+
prunePolicyGraph(t, n - 1);
|
|
354
331
|
}
|
|
355
332
|
/** Decrements explicitPolicy / inhibitPolicyMapping / inhibitAnyPolicy and applies policyConstraints overrides. */
|
|
356
|
-
function updatePolicyCounters(
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
if (isNonNegativeInteger(certificate.policyConstraints?.requireExplicitPolicy)) {
|
|
360
|
-
if (certificate.policyConstraints.requireExplicitPolicy === 0) state.explicitPolicy = 0;
|
|
361
|
-
}
|
|
333
|
+
function updatePolicyCounters(e, t, n) {
|
|
334
|
+
if (n) {
|
|
335
|
+
updateLeafPolicyCounter(e, t);
|
|
362
336
|
return;
|
|
363
337
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
338
|
+
isSelfIssued(t) || decrementPolicyCounters(e), applyPolicyCounterOverrides(e, t);
|
|
339
|
+
}
|
|
340
|
+
function updateLeafPolicyCounter(e, t) {
|
|
341
|
+
decrementPositiveCounter(e, "explicitPolicy"), t.policyConstraints?.requireExplicitPolicy === 0 && (e.explicitPolicy = 0);
|
|
342
|
+
}
|
|
343
|
+
function decrementPolicyCounters(e) {
|
|
344
|
+
decrementPositiveCounter(e, "explicitPolicy"), decrementPositiveCounter(e, "inhibitPolicyMapping"), decrementPositiveCounter(e, "inhibitAnyPolicy");
|
|
345
|
+
}
|
|
346
|
+
function decrementPositiveCounter(e, t) {
|
|
347
|
+
e[t] > 0 && --e[t];
|
|
348
|
+
}
|
|
349
|
+
function applyPolicyCounterOverrides(e, t) {
|
|
350
|
+
let n = t.policyConstraints;
|
|
351
|
+
isNonNegativeInteger(n?.requireExplicitPolicy) && n.requireExplicitPolicy < e.explicitPolicy && (e.explicitPolicy = n.requireExplicitPolicy), isNonNegativeInteger(n?.inhibitPolicyMapping) && n.inhibitPolicyMapping < e.inhibitPolicyMapping && (e.inhibitPolicyMapping = n.inhibitPolicyMapping), isNonNegativeInteger(t.inhibitAnyPolicy?.skipCerts) && t.inhibitAnyPolicy.skipCerts < e.inhibitAnyPolicy && (e.inhibitAnyPolicy = t.inhibitAnyPolicy.skipCerts);
|
|
373
352
|
}
|
|
374
|
-
function isNonNegativeInteger(
|
|
375
|
-
return
|
|
353
|
+
function isNonNegativeInteger(e) {
|
|
354
|
+
return e !== void 0 && Number.isInteger(e) && e >= 0;
|
|
376
355
|
}
|
|
377
356
|
/** A certificate is self-issued when subject and issuer DNs are semantically equal (RFC 5280 §7.1). */
|
|
378
|
-
function isSelfIssued(
|
|
379
|
-
return
|
|
357
|
+
function isSelfIssued(e) {
|
|
358
|
+
return t(e.subject, e.issuer);
|
|
380
359
|
}
|
|
381
360
|
//#endregion
|
|
382
361
|
export { createPolicyValidationState, evaluatePolicyChain };
|
|
362
|
+
|
|
363
|
+
//# sourceMappingURL=policy-engine.js.map
|