@browsercore/tls 0.4.17 → 0.4.19
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/README.md +238 -27
- package/dist/certificates/ca-constraints.d.ts +41 -0
- package/dist/certificates/ca-constraints.d.ts.map +1 -0
- package/dist/certificates/ca-constraints.js +107 -0
- package/dist/certificates/ca-constraints.js.map +1 -0
- package/dist/certificates/cert-extensions.d.ts +47 -10
- package/dist/certificates/cert-extensions.d.ts.map +1 -1
- package/dist/certificates/cert-extensions.js +111 -10
- package/dist/certificates/cert-extensions.js.map +1 -1
- package/dist/certificates/certificate-path.d.ts +282 -0
- package/dist/certificates/certificate-path.d.ts.map +1 -0
- package/dist/certificates/certificate-path.js +499 -0
- package/dist/certificates/certificate-path.js.map +1 -0
- package/dist/certificates/certificates.d.ts +66 -47
- package/dist/certificates/certificates.d.ts.map +1 -1
- package/dist/certificates/certificates.js +163 -82
- package/dist/certificates/certificates.js.map +1 -1
- package/dist/certificates/der.d.ts +0 -8
- package/dist/certificates/der.d.ts.map +1 -1
- package/dist/certificates/der.js +0 -42
- package/dist/certificates/der.js.map +1 -1
- package/dist/certificates/extension-policy.d.ts +195 -0
- package/dist/certificates/extension-policy.d.ts.map +1 -0
- package/dist/certificates/extension-policy.js +346 -0
- package/dist/certificates/extension-policy.js.map +1 -0
- package/dist/certificates/signature-algorithm.d.ts +54 -0
- package/dist/certificates/signature-algorithm.d.ts.map +1 -0
- package/dist/certificates/signature-algorithm.js +359 -0
- package/dist/certificates/signature-algorithm.js.map +1 -0
- package/dist/connection/handshake-driver.d.ts +9 -6
- package/dist/connection/handshake-driver.d.ts.map +1 -1
- package/dist/connection/handshake-driver.js.map +1 -1
- package/dist/connection/handshake-messages.d.ts +9 -2
- package/dist/connection/handshake-messages.d.ts.map +1 -1
- package/dist/connection/handshake-messages.js +57 -23
- package/dist/connection/handshake-messages.js.map +1 -1
- package/dist/errors.d.ts +54 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +22 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/session/session-cache.d.ts +2 -16
- package/dist/session/session-cache.d.ts.map +1 -1
- package/dist/session/session-cache.js.map +1 -1
- package/dist/tls.d.ts +4 -3
- package/dist/tls.d.ts.map +1 -1
- package/dist/tls.js +4 -3
- package/dist/tls.js.map +1 -1
- package/dist/types.d.ts +43 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* These decode the higher-level X.509 structures a TLS server cert actually
|
|
5
5
|
* carries: the subject/issuer DistinguishedNames (RFC 2253), the SAN
|
|
6
|
-
* extension (the source of truth for hostname validation), KeyUsage,
|
|
7
|
-
* BasicConstraints (the cA flag that separates leaf from CA certs)
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* extension (the source of truth for hostname validation), KeyUsage,
|
|
7
|
+
* BasicConstraints (the cA flag that separates leaf from CA certs), and the
|
|
8
|
+
* extendedKeyUsage OID list (RFC 5280 §4.2.1.12). They sit on top of the raw
|
|
9
|
+
* DER primitives in `der.ts`; structural decisions (which critical extension
|
|
10
|
+
* may be consumed, whether an EKU list authorizes server auth) live in
|
|
11
|
+
* extension-policy.ts — this layer only turns bytes into structured fields.
|
|
10
12
|
*/
|
|
11
13
|
import { readTlv, peekTag, parseOid } from "./der.js";
|
|
12
14
|
import { TlsHandshakeError } from "../errors.js";
|
|
@@ -81,8 +83,31 @@ export function parseCommonName(buf, start, _end) {
|
|
|
81
83
|
return undefined;
|
|
82
84
|
}
|
|
83
85
|
/**
|
|
84
|
-
* Parse the extensions block (SEQUENCE OF Extension
|
|
85
|
-
*
|
|
86
|
+
* Parse the extensions block (SEQUENCE OF Extension, RFC 5280 §4.1.2.9) between
|
|
87
|
+
* `start` and `end` into the ordered extension inventory:
|
|
88
|
+
* `{ oid, critical, value }` per extension, where `critical` defaults to FALSE
|
|
89
|
+
* (RFC 5280 §4.2: "critical BOOLEAN DEFAULT FALSE") and `value` is the CONTENTS
|
|
90
|
+
* of the extnValue OCTET STRING.
|
|
91
|
+
*
|
|
92
|
+
* Structural faults throw the typed certificate-phase error, mirroring
|
|
93
|
+
* BoringSSL's ParseExtensions/ParseExtension (pki/parse_certificate.cc), whose
|
|
94
|
+
* failure rejects the whole certificate:
|
|
95
|
+
*
|
|
96
|
+
* - the block must be a SEQUENCE containing at least one extension ("The
|
|
97
|
+
* Extensions SEQUENCE must contains at least 1 element (otherwise it
|
|
98
|
+
* should have been omitted)" — RFC 5280 §4.1.2.9 makes the whole block
|
|
99
|
+
* OPTIONAL, so an empty one is an encoding fault);
|
|
100
|
+
* - each entry must be a SEQUENCE whose extnID is an OBJECT IDENTIFIER;
|
|
101
|
+
* - the critical BOOLEAN, when present, must be a single 0xFF byte:
|
|
102
|
+
* BoringSSL `der::ParseBool` (X.690 §11.1) accepts only 0x00/0xFF, and
|
|
103
|
+
* `ParseExtension` then rejects FALSE — "DER-encoding requires DEFAULT
|
|
104
|
+
* values be omitted" (X.690 §11.5 via RFC 5280's DER mandate);
|
|
105
|
+
* - extnValue must be an OCTET STRING with no trailing data inside the
|
|
106
|
+
* Extension element ("The Extension type does not have an extension
|
|
107
|
+
* point (everything goes in extnValue)" — HasMore check);
|
|
108
|
+
* - an OID must not appear twice ("RFC 5280 says that an extension should
|
|
109
|
+
* not appear more than once" — the duplicate insert fails in
|
|
110
|
+
* ParseExtensions).
|
|
86
111
|
*/
|
|
87
112
|
export function parseExtensionsBlock(buf, start, _end) {
|
|
88
113
|
void _end;
|
|
@@ -92,20 +117,48 @@ export function parseExtensionsBlock(buf, start, _end) {
|
|
|
92
117
|
cause: new Error(`expected extensions SEQUENCE, got tag 0x${seq.tag.toString(16)}`),
|
|
93
118
|
});
|
|
94
119
|
}
|
|
120
|
+
if (seq.valueStart >= seq.end) {
|
|
121
|
+
throw new TlsHandshakeError("certificate", {
|
|
122
|
+
cause: new Error("empty extensions SEQUENCE — RFC 5280 §4.1.2.9 requires at least one extension when the block is present"),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
95
125
|
const extensions = [];
|
|
126
|
+
const seenOids = new Set();
|
|
96
127
|
let o = seq.valueStart;
|
|
97
128
|
while (o < seq.end) {
|
|
98
129
|
const ext = readTlv(buf, o);
|
|
99
130
|
if (ext.tag !== 0x30) {
|
|
100
|
-
|
|
131
|
+
throw new TlsHandshakeError("certificate", {
|
|
132
|
+
cause: new Error(`expected Extension SEQUENCE inside extensions block, got tag 0x${ext.tag.toString(16)}`),
|
|
133
|
+
});
|
|
101
134
|
}
|
|
102
135
|
let p = ext.valueStart;
|
|
103
136
|
const oidTlv = readTlv(buf, p);
|
|
137
|
+
if (oidTlv.tag !== 0x06) {
|
|
138
|
+
throw new TlsHandshakeError("certificate", {
|
|
139
|
+
cause: new Error(`expected extnID OBJECT IDENTIFIER, got tag 0x${oidTlv.tag.toString(16)}`),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
104
142
|
const oid = parseOid(buf, oidTlv.valueStart, oidTlv.end);
|
|
105
143
|
p = oidTlv.end;
|
|
106
|
-
// Optional critical BOOLEAN
|
|
144
|
+
// Optional critical BOOLEAN — DER TRUE is exactly one 0xFF byte
|
|
145
|
+
// (X.690 §11.1); FALSE (or any non-canonical byte) is rejected because
|
|
146
|
+
// DEFAULT values must be omitted in DER (X.690 §11.5), which is
|
|
147
|
+
// BoringSSL ParseExtension's `if (!out->critical) { return false; }`.
|
|
148
|
+
let critical = false;
|
|
107
149
|
if (peekTag(buf, p) === 0x01) {
|
|
108
|
-
|
|
150
|
+
const criticalTlv = readTlv(buf, p);
|
|
151
|
+
const contentLength = criticalTlv.end - criticalTlv.valueStart;
|
|
152
|
+
const contentByte = contentLength === 1 ? buf[criticalTlv.valueStart] : undefined;
|
|
153
|
+
if (contentByte !== 0xff) {
|
|
154
|
+
throw new TlsHandshakeError("certificate", {
|
|
155
|
+
cause: new Error(`critical BOOLEAN must be a single 0xFF byte in DER (got ${contentLength} byte(s), ` +
|
|
156
|
+
`value ${contentByte === undefined ? "absent" : `0x${contentByte.toString(16)}`}) — ` +
|
|
157
|
+
"DEFAULT FALSE must be omitted, never encoded"),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
critical = true;
|
|
161
|
+
p = criticalTlv.end;
|
|
109
162
|
}
|
|
110
163
|
const valueTlv = readTlv(buf, p);
|
|
111
164
|
if (valueTlv.tag !== 0x04) {
|
|
@@ -113,12 +166,60 @@ export function parseExtensionsBlock(buf, start, _end) {
|
|
|
113
166
|
cause: new Error(`expected extnValue OCTET STRING, got tag 0x${valueTlv.tag.toString(16)}`),
|
|
114
167
|
});
|
|
115
168
|
}
|
|
169
|
+
if (valueTlv.end !== ext.end) {
|
|
170
|
+
// The Extension type has no extension point — trailing data after
|
|
171
|
+
// extnValue is a structural fault (BoringSSL's HasMore check).
|
|
172
|
+
throw new TlsHandshakeError("certificate", {
|
|
173
|
+
cause: new Error(`unexpected trailing data after extnValue of extension ${oid} ` +
|
|
174
|
+
`(${ext.end - valueTlv.end} byte(s))`),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (seenOids.has(oid)) {
|
|
178
|
+
throw new TlsHandshakeError("certificate", {
|
|
179
|
+
cause: new Error(`duplicate extension OID ${oid} — RFC 5280 §4.2 forbids more than one instance of an extension`),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
seenOids.add(oid);
|
|
116
183
|
// The extnValue OCTET STRING *contains* the DER-encoded extension value.
|
|
117
|
-
extensions.push({ oid, value: buf.subarray(valueTlv.valueStart, valueTlv.end) });
|
|
184
|
+
extensions.push({ oid, critical, value: buf.subarray(valueTlv.valueStart, valueTlv.end) });
|
|
118
185
|
o = ext.end;
|
|
119
186
|
}
|
|
120
187
|
return extensions;
|
|
121
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Parse the extendedKeyUsage extension value (already unwrapped from its OCTET
|
|
191
|
+
* STRING): SEQUENCE OF KeyPurposeId, i.e. a SEQUENCE whose every element is an
|
|
192
|
+
* OBJECT IDENTIFIER (RFC 5280 §4.2.1.12). Returns the OIDs in dotted form,
|
|
193
|
+
* in order; an empty SEQUENCE is valid DER and yields an empty list (the
|
|
194
|
+
* SERVER_AUTH policy then rejects the certificate — "present but permitting
|
|
195
|
+
* nothing").
|
|
196
|
+
*
|
|
197
|
+
* A malformed value throws the typed certificate-phase error: BoringSSL parses
|
|
198
|
+
* the EKU at certificate-parse time and a failed `ParseEKUExtension` rejects
|
|
199
|
+
* the whole certificate (parsed_certificate.cc: `if (!ParseEKUExtension(...))
|
|
200
|
+
* { errors->AddError(kFailedParsingEku); return nullptr; }`).
|
|
201
|
+
*/
|
|
202
|
+
export function parseExtendedKeyUsage(value) {
|
|
203
|
+
const seq = readTlv(value, 0);
|
|
204
|
+
if (seq.tag !== 0x30) {
|
|
205
|
+
throw new TlsHandshakeError("certificate", {
|
|
206
|
+
cause: new Error(`expected extendedKeyUsage SEQUENCE, got tag 0x${seq.tag.toString(16)}`),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const oids = [];
|
|
210
|
+
let o = seq.valueStart;
|
|
211
|
+
while (o < seq.end) {
|
|
212
|
+
const oidTlv = readTlv(value, o);
|
|
213
|
+
if (oidTlv.tag !== 0x06) {
|
|
214
|
+
throw new TlsHandshakeError("certificate", {
|
|
215
|
+
cause: new Error(`expected KeyPurposeId OBJECT IDENTIFIER in extendedKeyUsage, got tag 0x${oidTlv.tag.toString(16)}`),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
oids.push(parseOid(value, oidTlv.valueStart, oidTlv.end));
|
|
219
|
+
o = oidTlv.end;
|
|
220
|
+
}
|
|
221
|
+
return Object.freeze(oids);
|
|
222
|
+
}
|
|
122
223
|
/**
|
|
123
224
|
* Parse the SAN extension value (already unwrapped from its OCTET STRING).
|
|
124
225
|
* The value is a SEQUENCE OF GeneralName; we only extract dNSName entries
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cert-extensions.js","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cert-extensions.js","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,GAAe,EAAE,KAAa,EAAE,IAAY;IAClE,KAAK,IAAI,CAAC;IACV,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;IACd,CAAC;IACD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC;IACvB,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;QACjB,oEAAoE;QACpE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC/B,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM;QACV,CAAC;QACD,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC;QAC5B,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;YAClB,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;YACf,SAAS;QACb,CAAC;QACD,MAAM,GAAG,GAAG,OAAO,CAAC,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ildCertificatePath` runs a depth-first search with backtracking from the
|
|
5
|
+
* leaf. At every step the candidates for the current certificate's issuer are
|
|
6
|
+
* tried in order: first the certificate ITSELF as a pinned anchor (identity
|
|
7
|
+
* match, see below), then the trust anchors as issuers, then the remaining
|
|
8
|
+
* server-sent certificates in wire order. A candidate matches when its
|
|
9
|
+
* subject DN equals the current certificate's issuer DN byte-for-byte AND its
|
|
10
|
+
* public key verifies the current certificate's signature; each such
|
|
11
|
+
* verification performed during building IS the chain verification (RFC 5280
|
|
12
|
+
* §6.1.3 (a)), so no pair is ever verified twice.
|
|
13
|
+
*
|
|
14
|
+
* PINNED ANCHORS — matched by identity, never verified: a certificate that is
|
|
15
|
+
* itself an anchor (self-signed, subject DN bytes AND subjectPublicKeyInfo
|
|
16
|
+
* bytes equal to the anchor's) ends the path immediately WITHOUT any
|
|
17
|
+
* signature verification, because there is no issuer edge left to verify —
|
|
18
|
+
* trust rests on the anchor identity, not on the certificate's own signature
|
|
19
|
+
* (old pinned leaves/roots are commonly self-signed with SHA-1 or another
|
|
20
|
+
* rejected algorithm). A NON-self-signed certificate whose ISSUER is an
|
|
21
|
+
* anchor is a real edge and stays signature-verified. A self-signed
|
|
22
|
+
* certificate that merely SHARES the anchor's subject DN but not its SPKI is
|
|
23
|
+
* a name collision: it is not the anchor and has no (real) issuer, so it
|
|
24
|
+
* fails with no-issuer.
|
|
25
|
+
*
|
|
26
|
+
* BACKTRACKING: reaching an anchor completes a candidate path; the path
|
|
27
|
+
* checks below then decide whether it is valid. The FIRST FULLY VALID path
|
|
28
|
+
* (anchored and passing every check) is the result; a candidate whose
|
|
29
|
+
* completed path fails a check is abandoned and the NEXT candidate is tried,
|
|
30
|
+
* so the outcome never depends on the order the server happened to choose
|
|
31
|
+
* (e.g. a cross-signed intermediate sent in a constrained and an unconstrained
|
|
32
|
+
* variant). Termination is unconditional: a certificate is never used twice
|
|
33
|
+
* on one path, and at most {@link MAX_PATH_INTERMEDIATES} intermediates are
|
|
34
|
+
* accepted, so the search visits at most (candidates × path length) states.
|
|
35
|
+
*
|
|
36
|
+
* FAILURE REPORTING: only when every candidate is exhausted is the path
|
|
37
|
+
* reported unanchored, with the failure observed at the DEEPEST search depth —
|
|
38
|
+
* the attempt that got closest to acceptance, where a completed-but-invalid
|
|
39
|
+
* path (anchor edge already added) outranks a dead end at the same prefix —
|
|
40
|
+
* ties resolved by the FIRST attempt recorded at that depth. The message
|
|
41
|
+
* always names the offending certificate.
|
|
42
|
+
*
|
|
43
|
+
* The signature-algorithm policy is deliberately NOT re-checked here — it
|
|
44
|
+
* lives in `validateCertificateChain`'s sweep, which runs in every mode.
|
|
45
|
+
*
|
|
46
|
+
* DN comparison detail: candidate filtering compares the DER byte spans of the
|
|
47
|
+
* candidate's subject and the current certificate's issuer. The signature check
|
|
48
|
+
* is what actually binds issuer to subject — DN equality only selects the
|
|
49
|
+
* candidate set (BoringSSL matches names byte-exactly for the same reason). A
|
|
50
|
+
* false-negative filter (differing encodings of the same DN) yields no-issuer,
|
|
51
|
+
* never a false-accept: nothing is trusted without a verifying signature (or
|
|
52
|
+
* an identity match with a pinned anchor).
|
|
53
|
+
*/
|
|
54
|
+
import type { Certificate, CryptoProvider } from "@browsercore/contracts";
|
|
55
|
+
import { type CertificateFailureReason } from "../errors.js";
|
|
56
|
+
/**
|
|
57
|
+
* One entry of the ordered extension inventory of a parsed certificate
|
|
58
|
+
* (RFC 5280 §4.1.2.9): the dotted extnID, the critical flag (DEFAULT FALSE per
|
|
59
|
+
* §4.2), and the CONTENTS of the extnValue OCTET STRING. Produced by
|
|
60
|
+
* parseExtensionsBlock; consumed by the critical-extension policy
|
|
61
|
+
* (pathCriticalExtensionsError via extension-policy.ts).
|
|
62
|
+
*/
|
|
63
|
+
export interface CertificateExtension {
|
|
64
|
+
/** Dotted extnID OBJECT IDENTIFIER (RFC 5280 §4.1.2.9). */
|
|
65
|
+
readonly oid: string;
|
|
66
|
+
/** critical BOOLEAN, DEFAULT FALSE (RFC 5280 §4.2). */
|
|
67
|
+
readonly critical: boolean;
|
|
68
|
+
/** CONTENTS of the extnValue OCTET STRING (the DER-encoded extension value). */
|
|
69
|
+
readonly value: Uint8Array;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* tls-internal parsed certificate: the contract's {@link Certificate} plus the
|
|
73
|
+
* fields path building needs that the contract deliberately does not carry.
|
|
74
|
+
*
|
|
75
|
+
* The DN byte spans are the issuer↔subject comparison key (see the module
|
|
76
|
+
* comment); keyUsage presence and the keyCertSign bit, and the BasicConstraints
|
|
77
|
+
* pathLenConstraint, feed the RFC 5280 §6.1.3 issuer-authorization checks; the
|
|
78
|
+
* extension inventory and the parsed extendedKeyUsage feed the extension-policy
|
|
79
|
+
* checks (RFC 5280 §4.2 criticals, SERVER_AUTH EKU).
|
|
80
|
+
* `parseCertificate` keeps returning the bare contract type at the public
|
|
81
|
+
* boundary — this superset travels only inside the package.
|
|
82
|
+
*/
|
|
83
|
+
export interface ParsedCertificate extends Certificate {
|
|
84
|
+
/** DER byte span of the subject Name (candidate-filter key). */
|
|
85
|
+
readonly subjectDn: Uint8Array;
|
|
86
|
+
/** DER byte span of the issuer Name (candidate-filter key). */
|
|
87
|
+
readonly issuerDn: Uint8Array;
|
|
88
|
+
/** True when a keyUsage extension was present at all (RFC 5280 §4.2.1.3). */
|
|
89
|
+
readonly keyUsagePresent: boolean;
|
|
90
|
+
/** True when a present keyUsage extension asserts the keyCertSign bit. */
|
|
91
|
+
readonly keyUsageKeyCertSign: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* BasicConstraints pathLenConstraint (RFC 5280 §4.2.1.9); null when
|
|
94
|
+
* absent. A sign-violating or non-minimal INTEGER is a malformed
|
|
95
|
+
* certificate and throws at parse time (see parsePathLenConstraint).
|
|
96
|
+
*/
|
|
97
|
+
readonly pathLenConstraint: number | null;
|
|
98
|
+
/**
|
|
99
|
+
* The ordered extension inventory (RFC 5280 §4.1.2.9) — every extension
|
|
100
|
+
* the certificate carries, in wire order, with its critical flag and raw
|
|
101
|
+
* extnValue contents. The critical-extension policy iterates this list.
|
|
102
|
+
*/
|
|
103
|
+
readonly extensions: readonly CertificateExtension[];
|
|
104
|
+
/**
|
|
105
|
+
* True when an extendedKeyUsage extension was present at all (RFC 5280
|
|
106
|
+
* §4.2.1.12). Presence matters independently of the OID list: an EMPTY
|
|
107
|
+
* EKU sequence is "present, permitting nothing" and fails the SERVER_AUTH
|
|
108
|
+
* rule, while an absent extension is accepted (Chrome's kEkuNotPresent
|
|
109
|
+
* warning only).
|
|
110
|
+
*/
|
|
111
|
+
readonly extendedKeyUsagePresent: boolean;
|
|
112
|
+
/** The parsed EKU OID list (dotted, in order); empty when the extension is absent or empty. */
|
|
113
|
+
readonly extendedKeyUsage: readonly string[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The server-sent certificate list: the leaf first, then every following
|
|
117
|
+
* CertificateEntry in wire order. There is deliberately NO `root` field —
|
|
118
|
+
* servers almost always omit the root, and whether the last entry is a root,
|
|
119
|
+
* an intermediate or an unrelated certificate is decided by path building,
|
|
120
|
+
* not by wire position.
|
|
121
|
+
*/
|
|
122
|
+
export interface CertificateChain {
|
|
123
|
+
readonly leaf: ParsedCertificate;
|
|
124
|
+
readonly intermediates: readonly ParsedCertificate[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A trust anchor: a parsed certificate trusted a priori (RFC 5280 §6.1.1).
|
|
128
|
+
* Consumers parse the anchor DER (typically a self-signed root) with
|
|
129
|
+
* `parseCertificateDetails`; its SPKI + subject DN identify it (identity
|
|
130
|
+
* match for a pinned certificate) and its key verifies the top of the path.
|
|
131
|
+
*/
|
|
132
|
+
export type TrustAnchor = ParsedCertificate;
|
|
133
|
+
/**
|
|
134
|
+
* Maximum intermediates between the leaf and the anchor. Chrome caps path
|
|
135
|
+
* length the same way; without a limit a degenerate chain (or a hostile
|
|
136
|
+
* server) could make the search walk hundreds of useless entries.
|
|
137
|
+
*/
|
|
138
|
+
export declare const MAX_PATH_INTERMEDIATES = 8;
|
|
139
|
+
/**
|
|
140
|
+
* Why building stopped short of a fully valid path: the two search-level
|
|
141
|
+
* failures plus every path-check failure (the builder validates each
|
|
142
|
+
* completed candidate path, so an expired/not-CA/path-too-long intermediate
|
|
143
|
+
* surfaces through the same union). This is {@link CertificateFailureReason}
|
|
144
|
+
* minus "no-anchors", which verifyChain raises before building starts.
|
|
145
|
+
*/
|
|
146
|
+
export type CertificatePathFailureReason = Exclude<CertificateFailureReason, "no-anchors">;
|
|
147
|
+
/**
|
|
148
|
+
* The discriminated build result: `anchored` carries the ordered path from the
|
|
149
|
+
* leaf to the certificate that ended it plus the anchor (for an issuer edge
|
|
150
|
+
* the anchor is NOT part of the path — RFC 5280 §6.1 treats it as trusted a
|
|
151
|
+
* priori; for a pinned identity match the anchor IS the path's last
|
|
152
|
+
* certificate). `unanchored` names the failure of the deepest attempted path:
|
|
153
|
+
* `certificate`/`certificateIndex` identify the certificate whose issuer
|
|
154
|
+
* search failed (or that would exceed the limit / whose completed path failed
|
|
155
|
+
* a check), and `message` is the fully rendered diagnostic.
|
|
156
|
+
*/
|
|
157
|
+
export type CertificatePath = {
|
|
158
|
+
readonly kind: "anchored";
|
|
159
|
+
readonly path: readonly ParsedCertificate[];
|
|
160
|
+
readonly anchor: TrustAnchor;
|
|
161
|
+
} | {
|
|
162
|
+
readonly kind: "unanchored";
|
|
163
|
+
readonly reason: CertificatePathFailureReason;
|
|
164
|
+
/** Diagnostic for the reported (deepest) failure; names the offender. */
|
|
165
|
+
readonly message: string;
|
|
166
|
+
/** The certificate the failure is attributed to. */
|
|
167
|
+
readonly certificate: ParsedCertificate;
|
|
168
|
+
/** Wire index of `certificate` in the server-sent list (leaf is 0). */
|
|
169
|
+
readonly certificateIndex: number;
|
|
170
|
+
/** DN-matching candidates tried at the failure level whose signature failed. */
|
|
171
|
+
readonly candidateCount: number;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* A structured path-check failure: the discriminated reason plus the fully
|
|
175
|
+
* rendered diagnostic (narrowed to the path-check reasons — the cores never
|
|
176
|
+
* produce "no-anchors", which verifyChain raises before building). Exported
|
|
177
|
+
* because the extension-policy path checks live beside the other checks here
|
|
178
|
+
* and share the shape with their throwing wrappers.
|
|
179
|
+
*/
|
|
180
|
+
export interface PathCheckFailure {
|
|
181
|
+
readonly reason: CertificatePathFailureReason;
|
|
182
|
+
readonly message: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Build the certification path from the leaf to a trust anchor.
|
|
186
|
+
*
|
|
187
|
+
* Depth-first search with backtracking: candidates are tried anchors-first,
|
|
188
|
+
* then server certificates in wire order; the first FULLY VALID path (reaching
|
|
189
|
+
* an anchor and passing every check) wins; exhausted candidates yield an
|
|
190
|
+
* unanchored result carrying the deepest failure (see the module comment).
|
|
191
|
+
* Unanchored results never throw — the caller decides how to surface them.
|
|
192
|
+
*/
|
|
193
|
+
export declare function buildCertificatePath(chain: CertificateChain, trustAnchors: readonly TrustAnchor[], provider: CryptoProvider, now: number): CertificatePath;
|
|
194
|
+
/**
|
|
195
|
+
* Validity window for EVERY certificate on the built path (RFC 5280 §6.1.2
|
|
196
|
+
* (a)/(b) + §6.1.3) — including a pinned leaf: the path's certificates come
|
|
197
|
+
* from the wire, and the wire target's validity is checked unconditionally
|
|
198
|
+
* (BoringSSL's verify_certificate_chain does the same for a directly trusted
|
|
199
|
+
* leaf). The trust anchor itself is never part of the built path when it acts
|
|
200
|
+
* as the ISSUER of the top certificate, so its own expiry is never checked
|
|
201
|
+
* (old roots outlive their notAfter all the time); there is deliberately no
|
|
202
|
+
* object-identity shortcut here — whether the pinned match reuses the same
|
|
203
|
+
* parsed object or a second parse of the same DER, the outcome is identical.
|
|
204
|
+
*/
|
|
205
|
+
export declare function pathValidityWindowError(path: readonly ParsedCertificate[], now: number): PathCheckFailure | undefined;
|
|
206
|
+
/** Throwing wrapper around {@link pathValidityWindowError} (see it for the WHY). */
|
|
207
|
+
export declare function checkPathValidityWindow(path: readonly ParsedCertificate[], now: number): void;
|
|
208
|
+
/**
|
|
209
|
+
* Issuer-authorization constraints for every intermediate on the built path
|
|
210
|
+
* (RFC 5280 §6.1.3 (k)/(l) + §4.2.1.3): an intermediate must carry
|
|
211
|
+
* basicConstraints cA=TRUE, and when it carries a keyUsage extension, that
|
|
212
|
+
* extension must assert keyCertSign. Absence of the keyUsage EXTENSION is
|
|
213
|
+
* tolerated (RFC 5280 makes it optional); absence of the cA flag is not. The
|
|
214
|
+
* anchor is exempt because it is trusted a priori AND never part of the built
|
|
215
|
+
* path when it acts as the issuer of the top certificate (a legacy root
|
|
216
|
+
* without basicConstraints or keyCertSign must still verify paths under it);
|
|
217
|
+
* a WIRE certificate that merely matches an anchor by DN+SPKI is checked like
|
|
218
|
+
* any other intermediate.
|
|
219
|
+
*/
|
|
220
|
+
export declare function pathCaConstraintsError(path: readonly ParsedCertificate[]): PathCheckFailure | undefined;
|
|
221
|
+
/** Throwing wrapper around {@link pathCaConstraintsError} (see it for the WHY). */
|
|
222
|
+
export declare function checkPathCaConstraints(path: readonly ParsedCertificate[]): void;
|
|
223
|
+
/**
|
|
224
|
+
* pathLenConstraint along the built path (RFC 5280 §4.2.1.9): a certificate's
|
|
225
|
+
* constraint bounds the number of NON-self-issued intermediates that may
|
|
226
|
+
* FOLLOW it ("below" it, towards the leaf). Every issuer on the path is
|
|
227
|
+
* checked — each intermediate, and the anchor as issuer of the top
|
|
228
|
+
* intermediate (RFC 5280 §6.1.1 (h) seeds max_path_length from the anchor's
|
|
229
|
+
* constraint; the anchor's own status is a priori trusted, but its constraint
|
|
230
|
+
* is a delegation LIMIT on the certificates below it). RFC 5280 counts
|
|
231
|
+
* non-self-issued certificates only; our `selfSigned` flag (subject DN bytes
|
|
232
|
+
* equal issuer DN bytes) is exactly the subject==issuer test. The counting
|
|
233
|
+
* loop skips `anchor` by POSITION (the certificate in anchor position is the
|
|
234
|
+
* issuer, never one of the intermediates it constrains) — a WIRE certificate
|
|
235
|
+
* that merely matches the anchor by DN+SPKI is counted like any other
|
|
236
|
+
* intermediate, so the outcome does not depend on whether the pinned match
|
|
237
|
+
* reused the same parsed object.
|
|
238
|
+
*/
|
|
239
|
+
export declare function pathLengthConstraintsError(path: readonly ParsedCertificate[], anchor: TrustAnchor): PathCheckFailure | undefined;
|
|
240
|
+
/** Throwing wrapper around {@link pathLengthConstraintsError} (see it for the WHY). */
|
|
241
|
+
export declare function checkPathLengthConstraints(path: readonly ParsedCertificate[], anchor: TrustAnchor): void;
|
|
242
|
+
/**
|
|
243
|
+
* extendedKeyUsage as Chrome 140 enforces it (RFC 5280 §4.2.1.12, BoringSSL
|
|
244
|
+
* `VerifyExtendedKeyUsage` with KeyPurpose::SERVER_AUTH — the value
|
|
245
|
+
* cert_verify_proc_builtin.cc passes for every TLS-server verification): every
|
|
246
|
+
* certificate on the built path that carries an EKU extension must include
|
|
247
|
+
* id-kp-serverAuth (1.3.6.1.5.5.7.3.1) or anyExtendedKeyUsage (2.5.29.37.0);
|
|
248
|
+
* the deciding SERVER_AUTH error is `kEkuLacksServerAuth`, raised by "if
|
|
249
|
+
* (cert.has_extended_key_usage() && !has_server_auth_eku && !has_any_eku)" for
|
|
250
|
+
* the target and for EVERY issuer alike ("Legacy compatible" branch). A
|
|
251
|
+
* MISSING extension is accepted (leaf: only the kEkuNotPresent warning;
|
|
252
|
+
* intermediates: "At this time … some intermediates are lacking EKU in the
|
|
253
|
+
* world at large from common CA's, so we allow the noEKU case to permit
|
|
254
|
+
* everything."), and an EMPTY EKU sequence is present-but-permitting-nothing,
|
|
255
|
+
* so it fails. Code-signing/time-stamping/OCSP-signing EKUs alongside
|
|
256
|
+
* serverAuth are only warnings in this mode (`add_error_if_strict` → warning).
|
|
257
|
+
* The anchor is exempt (see {@link isAnchorOnPath}).
|
|
258
|
+
*/
|
|
259
|
+
export declare function pathServerAuthEkuError(path: readonly ParsedCertificate[], anchor: TrustAnchor): PathCheckFailure | undefined;
|
|
260
|
+
/** Throwing wrapper around {@link pathServerAuthEkuError} (see it for the WHY). */
|
|
261
|
+
export declare function checkPathServerAuthEku(path: readonly ParsedCertificate[], anchor: TrustAnchor): void;
|
|
262
|
+
/**
|
|
263
|
+
* Unrecognized critical extensions on the built path (RFC 5280 §4.2: "A
|
|
264
|
+
* certificate-using system MUST reject the certificate if it encounters a
|
|
265
|
+
* critical extension it does not recognize or a critical extension that
|
|
266
|
+
* contains information that it cannot process."), applied exactly like
|
|
267
|
+
* Chrome's built-in verifier: BoringSSL's `VerifyNoUnconsumedCriticalExtensions`
|
|
268
|
+
* runs for the target certificate (WrapUp) and for every intermediate
|
|
269
|
+
* (PrepareForNextCertificate), but NOT for the trust anchor ("Don't do any
|
|
270
|
+
* other checks for root certificates" in the verification loop; the anchor is
|
|
271
|
+
* only checked when trust-anchor CONSTRAINT enforcement is enabled, which
|
|
272
|
+
* Chrome does not do by default) — hence the {@link isAnchorOnPath} exemption.
|
|
273
|
+
* The recognized set is decided by extension-policy.ts
|
|
274
|
+
* ({@link isCriticalExtensionHandled}); a critical nameConstraints is
|
|
275
|
+
* deliberately rejected there until the name-constraints subset lands (this
|
|
276
|
+
* verifier does not process name constraints, and RFC 5280 §4.2 requires
|
|
277
|
+
* rejecting unprocessed critical extensions).
|
|
278
|
+
*/
|
|
279
|
+
export declare function pathCriticalExtensionsError(path: readonly ParsedCertificate[], anchor: TrustAnchor): PathCheckFailure | undefined;
|
|
280
|
+
/** Throwing wrapper around {@link pathCriticalExtensionsError} (see it for the WHY). */
|
|
281
|
+
export declare function checkPathCriticalExtensions(path: readonly ParsedCertificate[], anchor: TrustAnchor): void;
|
|
282
|
+
//# sourceMappingURL=certificate-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"certificate-path.d.ts","sourceRoot":"","sources":["../../src/certificates/certificate-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAo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