@browsercore/tls 0.4.18 → 0.4.20

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.
Files changed (69) hide show
  1. package/README.md +291 -6
  2. package/dist/certificates/ca-constraints.d.ts +43 -0
  3. package/dist/certificates/ca-constraints.d.ts.map +1 -0
  4. package/dist/certificates/ca-constraints.js +89 -0
  5. package/dist/certificates/ca-constraints.js.map +1 -0
  6. package/dist/certificates/cert-extensions.d.ts +106 -19
  7. package/dist/certificates/cert-extensions.d.ts.map +1 -1
  8. package/dist/certificates/cert-extensions.js +203 -48
  9. package/dist/certificates/cert-extensions.js.map +1 -1
  10. package/dist/certificates/certificate-path.d.ts +341 -0
  11. package/dist/certificates/certificate-path.d.ts.map +1 -0
  12. package/dist/certificates/certificate-path.js +613 -0
  13. package/dist/certificates/certificate-path.js.map +1 -0
  14. package/dist/certificates/certificates.d.ts +66 -47
  15. package/dist/certificates/certificates.d.ts.map +1 -1
  16. package/dist/certificates/certificates.js +251 -92
  17. package/dist/certificates/certificates.js.map +1 -1
  18. package/dist/certificates/der.d.ts +0 -8
  19. package/dist/certificates/der.d.ts.map +1 -1
  20. package/dist/certificates/der.js +0 -42
  21. package/dist/certificates/der.js.map +1 -1
  22. package/dist/certificates/extension-policy.d.ts +205 -0
  23. package/dist/certificates/extension-policy.d.ts.map +1 -0
  24. package/dist/certificates/extension-policy.js +357 -0
  25. package/dist/certificates/extension-policy.js.map +1 -0
  26. package/dist/certificates/extension-values.d.ts +131 -0
  27. package/dist/certificates/extension-values.d.ts.map +1 -0
  28. package/dist/certificates/extension-values.js +443 -0
  29. package/dist/certificates/extension-values.js.map +1 -0
  30. package/dist/certificates/general-names.d.ts +142 -0
  31. package/dist/certificates/general-names.d.ts.map +1 -0
  32. package/dist/certificates/general-names.js +354 -0
  33. package/dist/certificates/general-names.js.map +1 -0
  34. package/dist/certificates/name-constraints.d.ts +245 -0
  35. package/dist/certificates/name-constraints.d.ts.map +1 -0
  36. package/dist/certificates/name-constraints.js +692 -0
  37. package/dist/certificates/name-constraints.js.map +1 -0
  38. package/dist/certificates/name-match.d.ts +59 -0
  39. package/dist/certificates/name-match.d.ts.map +1 -0
  40. package/dist/certificates/name-match.js +271 -0
  41. package/dist/certificates/name-match.js.map +1 -0
  42. package/dist/certificates/signature-algorithm.d.ts +54 -0
  43. package/dist/certificates/signature-algorithm.d.ts.map +1 -0
  44. package/dist/certificates/signature-algorithm.js +359 -0
  45. package/dist/certificates/signature-algorithm.js.map +1 -0
  46. package/dist/connection/handshake-driver.d.ts +9 -6
  47. package/dist/connection/handshake-driver.d.ts.map +1 -1
  48. package/dist/connection/handshake-driver.js.map +1 -1
  49. package/dist/connection/handshake-messages.d.ts +9 -2
  50. package/dist/connection/handshake-messages.d.ts.map +1 -1
  51. package/dist/connection/handshake-messages.js +57 -23
  52. package/dist/connection/handshake-messages.js.map +1 -1
  53. package/dist/errors.d.ts +100 -0
  54. package/dist/errors.d.ts.map +1 -1
  55. package/dist/errors.js +54 -0
  56. package/dist/errors.js.map +1 -1
  57. package/dist/index.d.ts +8 -5
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +5 -3
  60. package/dist/index.js.map +1 -1
  61. package/dist/tls.d.ts +4 -3
  62. package/dist/tls.d.ts.map +1 -1
  63. package/dist/tls.js +4 -3
  64. package/dist/tls.js.map +1 -1
  65. package/dist/types.d.ts +2 -1
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/types.js +2 -1
  68. package/dist/types.js.map +1 -1
  69. package/package.json +3 -3
package/README.md CHANGED
@@ -3,11 +3,11 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@browsercore/tls)](https://www.npmjs.com/package/@browsercore/tls)
4
4
  [![CI](https://img.shields.io/github/actions/workflow/status/jverneuer/browsercore-tls/ci.yml?label=ci)](https://github.com/jverneuer/browsercore-tls/actions/workflows/ci.yml)
5
5
 
6
- A TLS 1.3 client implemented entirely in TypeScript, with optional TLS 1.2
7
- fallback (RFC 5246). TLS 1.2 support is gated behind server negotiation: if the
8
- server selects a TLS 1.2 cipher suite, the handshake driver branches to
9
- runTls12Handshake(). Requesting a TLS 1.2-only handshake (one that cannot
10
- negotiate TLS 1.3) is rejected up front with a typed error.
6
+ A TLS 1.3-only client implemented entirely in TypeScript (RFC 8446). There is
7
+ no TLS 1.2 fallback: a profile that cannot negotiate TLS 1.3 is rejected up
8
+ front with a typed `TlsHandshakeError`, and a server that answers with a
9
+ TLS 1.2 cipher suite or a downgrade sentinel aborts the handshake with the
10
+ same typed error.
11
11
 
12
12
  ## Responsibility
13
13
 
@@ -68,11 +68,296 @@ await tls.close();
68
68
  | `resolveProfile()` | function | Look up a profile by name and fill in serverName |
69
69
  | `TlsError` | class | Base typed error |
70
70
  | `TlsHandshakeError` | class | Handshake failure at a specific phase |
71
+ | `TlsCertificateError` | class | Certificate validation failure with a typed `reason` (extends `TlsHandshakeError`, phase `"certificate"`) |
72
+ | `CertificateFailureReason` | string-literal union | Why certificate validation failed: `no-anchors`, `no-issuer`, `bad-signature`, `expired`, `not-yet-valid`, `not-a-ca`, `missing-key-cert-sign`, `path-too-long`, `unsupported-critical-extension`, `missing-server-auth-eku` |
71
73
  | `TlsDecryptError` | class | Record decryption / auth failure |
72
74
  | `TlsAlertError` | class | TLS alert with level + description |
75
+ | `Certificate` | interface | Parsed X.509 certificate (validation-relevant fields; the canonical contract type) |
76
+ | `ParsedCertificate` | interface | tls-internal superset of `Certificate` carrying the subject/issuer DN byte spans, keyUsage presence + keyCertSign bit, `pathLenConstraint`, the ordered extension inventory (`extensions`: `{ oid, critical, value }` per RFC 5280 §4.1.2.9), and the parsed extendedKeyUsage OID list (`extendedKeyUsagePresent` + `extendedKeyUsage`) |
77
+ | `CertificateChain` | interface | The server-sent list: `leaf` first, `intermediates` = every following entry in wire order (breaking change in 0.4.19: the forced `root` field is gone) |
78
+ | `TrustAnchor` | type alias | A parsed certificate trusted a priori (= `ParsedCertificate`; breaking change in 0.4.19: was `{ subjectPublicKeyInfo, subject }`) |
79
+ | `CertificatePath` | discriminated union | `buildCertificatePath` result: `anchored` (path + anchor) or `unanchored` — `reason` is one of `no-issuer`, `bad-signature`, `expired`, `not-yet-valid`, `not-a-ca`, `missing-key-cert-sign`, `path-too-long`, `unsupported-critical-extension`, `missing-server-auth-eku` (every certificate failure reason except `no-anchors`, which `verifyChain` raises before building), plus the fully rendered `message` and the certificate the failure names |
80
+ | `buildCertificatePath()` / `parseCertificateDetails()` | functions | The pure RFC 5280 §6.1 path builder; the full internal parse behind `parseCertificate` |
81
+ | `CertificateSignatureAlgorithm` | discriminated union | The certificate's signature algorithm: `supported` (with TLS scheme) or `rejected` (with reason + OID) |
73
82
  | `Clock` | interface (re-export) | Canonical time source from `@browsercore/contracts`, injected via `TlsOptions.clock` |
74
83
  | `systemClock` | const | Default `Clock` over the plain JS globals (`Date.now`, `performance.now`, `setTimeout`) |
75
84
 
85
+ ## Certificate signature algorithms
86
+
87
+ `parseCertificate` never rejects a structurally valid certificate because of
88
+ its signature algorithm. Instead it reports the parsed SignatureAlgorithm
89
+ Identifier (OID **and** parameters, RFC 5280 §4.1.1.2 / RFC 4055 §3.1) as a
90
+ `Certificate.signatureAlgorithm` discriminated union:
91
+
92
+ - `{ kind: "supported", scheme }` — maps to a TLS `SignatureScheme` usable for
93
+ chain-signature verification.
94
+ - `{ kind: "rejected", reason, oid }` — `reason` is one of `"sha1"`, `"md5"`,
95
+ `"pss-parameters"` (missing/non-conforming RSA-PSS parameters) or `"unknown"`.
96
+
97
+ Supported mappings: RSA PKCS#1 v1.5 SHA-256/384/512 (`rsa_pkcs1_*`), RSA-PSS
98
+ SHA-256/384/512 with MGF1 using the same hash and salt = digest length
99
+ (`rsa_pss_rsae_*` — the rsae/pss split only exists for TLS CertificateVerify;
100
+ certificate signatures are verified with the issuer's key, so only the hash
101
+ matters), ECDSA with SHA-256/384/512 (`ecdsa_secp256r1_sha256`,
102
+ `ecdsa_secp384r1_sha384`, `ecdsa_secp521r1_sha512` — the curve in the name is
103
+ the conventional pairing; verification uses the issuer's actual key), and
104
+ Ed25519 (parameters absent).
105
+
106
+ This is a breaking rename in 0.4.19: `Certificate.signatureScheme: SignatureScheme`
107
+ (a scalar that threw at parse time for every OID outside four hardcoded
108
+ entries) is replaced by `Certificate.signatureAlgorithm` above.
109
+
110
+ ### Rejection policy
111
+
112
+ `validateCertificateChain` enforces signature-algorithm policy in EVERY mode —
113
+ with or without trust anchors — the way Chrome does: a chain certificate whose
114
+ signature algorithm is `rejected` fails the handshake with a typed
115
+ `TlsHandshakeError` (phase `"certificate"`) naming the certificate (index +
116
+ issuer), the reason, and the OID. Self-signed certificates are EXEMPT: their
117
+ signature covers nothing the client relies on, and old trust anchors are
118
+ commonly self-signed with SHA-1 — so a SHA-1-self-signed root parses, can sit
119
+ in `trustAnchors`, and is never refused. When trust anchors are supplied,
120
+ `verifyChain` verifies each signature with the certificate's real scheme and
121
+ fails with a typed error for a rejected scheme before touching the crypto
122
+ provider.
123
+
124
+ Related diagnostics: the "certificate data may be compressed (RFC 8879)" hint
125
+ in a `Certificate`-message parse failure appears only when the offending entry
126
+ does not start with a DER SEQUENCE tag (0x30); a 0x30-prefixed entry surfaces
127
+ the parser's own error unchanged.
128
+
129
+ ## Certificate chain validation
130
+
131
+ `parseCertificateMessage` keeps the server-sent list VERBATIM (`leaf` +
132
+ `intermediates` in wire order); there is no forced `root` field, because
133
+ servers almost always omit the root and whether the last entry is a root, an
134
+ intermediate, or an unrelated certificate is decided by path building, never by
135
+ wire position. When trust anchors are supplied (`TlsOptions.trustAnchors`, raw
136
+ DER), `verifyChain` builds the certification path per RFC 5280 §6.1 with a
137
+ DEPTH-FIRST SEARCH WITH BACKTRACKING: at each step the candidates for the
138
+ current certificate's issuer are tried anchors-first, then the remaining
139
+ server-sent certificates in wire order. A candidate matches when its subject
140
+ DN equals the current certificate's issuer DN **byte-for-byte** (the same
141
+ comparison the parser uses for `selfSigned`; the DN is only the candidate
142
+ filter — the signature check with the candidate's public key is what actually
143
+ binds issuer to subject) and its key verifies the current certificate's
144
+ signature over its TBSCertificate using the certificate's own
145
+ `signatureAlgorithm` scheme. Every completed candidate path is then checked
146
+ (validity window, basicConstraints/keyCertSign, pathLenConstraint); the
147
+ result is the FIRST FULLY VALID path, and a candidate whose completed path
148
+ fails a check is abandoned for the next candidate — so the outcome never
149
+ depends on the order the server happened to choose (e.g. a cross-signed
150
+ intermediate sent in a pathlen-constrained and an unconstrained variant).
151
+ Only when every candidate is exhausted is the path reported unanchored, with
152
+ the failure observed at the DEEPEST search depth (the attempt that got
153
+ closest to acceptance; a completed-but-invalid path outranks a dead end at
154
+ the same prefix; ties resolve to the first attempt in search order). Every
155
+ signature verification performed while building IS the chain verification —
156
+ no pair is verified twice (the number of verifications is bounded by
157
+ candidates × path length). A certificate is never used twice on one path
158
+ (cycles terminate) and at most 8 intermediates are accepted
159
+ (`MAX_PATH_INTERMEDIATES`).
160
+
161
+ PINNED ANCHORS — matched by identity, never signature-verified: a certificate
162
+ that is itself an anchor (self-signed, subject DN bytes AND
163
+ subjectPublicKeyInfo bytes equal to the anchor's) ends the path immediately
164
+ WITHOUT any signature verification, because there is no issuer edge left to
165
+ verify — so a pinned leaf verifies regardless of its own signature algorithm
166
+ (a SHA-1 or unknown-OID self-signature is accepted). A pinned leaf is still a
167
+ WIRE certificate, and wire certificates are always validity-checked: an
168
+ EXPIRED pinned leaf fails with reason `expired` (the outcome is identical
169
+ whether the pinned match reuses the same parsed object or a second parse of
170
+ the same DER — there is no object-identity exemption). Only the trust anchor
171
+ ITSELF, in its position as the ISSUER of the top certificate (the parsed
172
+ anchor object, which is never part of the built path), is exempt from the
173
+ validity and CA checks — this matches BoringSSL, which checks the target's
174
+ validity unconditionally even for a directly trusted leaf. A NON-self-signed
175
+ certificate whose issuer is an anchor is a real edge and stays
176
+ signature-verified. A self-signed certificate that merely SHARES the anchor's
177
+ subject DN but not its SPKI is a name collision: it is not the anchor and has
178
+ no (real) issuer, so it fails with `no-issuer`.
179
+
180
+ Exactly what is checked, and when:
181
+
182
+ 1. **Hostname** — always, first: SAN DNS names, then the legacy CommonName
183
+ (RFC 6125). A mismatch fails before anything else, in every mode (before
184
+ even the no-anchors guard in `verifyChain`).
185
+ 2. **Signature-algorithm policy** — always: a `rejected` algorithm on a
186
+ non-self-signed chain certificate fails the handshake (see the previous
187
+ section). Self-signed certificates are exempt.
188
+ 3. **Chain building + signatures** — only when trust anchors are supplied:
189
+ the path must reach an anchor — by issuer-edge verification or by pinned
190
+ identity — and be fully valid.
191
+ 4. **Validity window** — on EVERY wire certificate of the built path (leaf +
192
+ intermediates, a pinned leaf included) at the injected `now`; only the
193
+ trust anchor itself is exempt (RFC 5280 §6.1: an anchor is trusted a
194
+ priori and, as the issuer of the top certificate, is not part of the
195
+ built path), so a chain under an EXPIRED anchor still verifies while an
196
+ expired intermediate — or an expired pinned leaf — fails.
197
+ 5. **Issuer authorization** — on the built path: every intermediate must
198
+ carry basicConstraints cA=TRUE (RFC 5280 §6.1.3 (k)) and, when it carries
199
+ a keyUsage extension, the keyCertSign bit (§4.2.1.3). Absence of keyUsage
200
+ is tolerated; absence of the cA flag is not.
201
+ 6. **pathLenConstraint** — on the built path: every issuer (each
202
+ intermediate, and the anchor as issuer of the top intermediate — RFC 5280
203
+ §6.1.1 (h) seeds the limit from the anchor) may have at most its
204
+ `pathLenConstraint` non-self-issued intermediates below it.
205
+ 7. **extendedKeyUsage (SERVER_AUTH)** — on the built path, exactly as Chrome
206
+ 140 enforces it (BoringSSL `VerifyExtendedKeyUsage` with
207
+ `KeyPurpose::SERVER_AUTH` — the value cert_verify_proc_builtin.cc passes for
208
+ every TLS-server verification — "Legacy compatible" branch): every path
209
+ certificate that CARRIES an EKU extension must include id-kp-serverAuth
210
+ (1.3.6.1.5.5.7.3.1) or anyExtendedKeyUsage (2.5.29.37.0), or the path fails
211
+ with `missing-server-auth-eku` (BoringSSL: `if (cert.has_extended_key_usage()
212
+ && !has_server_auth_eku && !has_any_eku) errors->AddError(kEkuLacksServerAuth)`
213
+ — raised for the target AND every issuer alike). An ABSENT extension is
214
+ accepted (on a leaf it is only Chrome's `kEkuNotPresent` warning; on
215
+ intermediates "we allow the noEKU case to permit everything"); an EMPTY EKU
216
+ sequence is present-but-permitting-nothing and fails; codeSigning /
217
+ timeStamping / OCSP-signing EKUs alongside serverAuth are warnings-only in
218
+ this mode (`add_error_if_strict`). The trust anchor is exempt (BoringSSL's
219
+ verification loop: "Don't do any other checks for root certificates").
220
+ 8. **Unrecognized critical extensions** — on the built path (RFC 5280 §4.2: "A
221
+ certificate-using system MUST reject the certificate if it encounters a
222
+ critical extension it does not recognize or a critical extension that
223
+ contains information that it cannot process"), mirroring BoringSSL's
224
+ `VerifyNoUnconsumedCriticalExtensions` + `IsHandledCriticalExtension` at the
225
+ BoringSSL revision Chromium 140 pins (0a0009998fa180695f3e2071805dc03c9a5f3124):
226
+ a CRITICAL extension fails the path with `unsupported-critical-extension`
227
+ (naming the OID and the certificate) unless it is in the recognized set —
228
+ exactly BoringSSL's: basicConstraints (2.5.29.19, processed),
229
+ keyUsage (2.5.29.15, keyCertSign processed; BoringSSL's own comment: "Key
230
+ Usage is NOT processed for end-entity certificates … however it is
231
+ considered 'handled' here in order to allow being marked as critical"),
232
+ extendedKeyUsage (2.5.29.37, processed — rule 7), subjectAltName
233
+ (2.5.29.17, processed — the hostname check), nameConstraints (2.5.29.30,
234
+ processed — rule 9; BoringSSL's branch is unconditional `return true`
235
+ BECAUSE it processes the constraints), policyMappings (2.5.29.33),
236
+ policyConstraints (2.5.29.36) and inhibitAnyPolicy (2.5.29.54) (accepted
237
+ like BoringSSL's unconditional `return true`; policy ENFORCEMENT is a
238
+ documented limitation below), certificatePolicies (2.5.29.32) when the
239
+ value parses with only CPS (1.3.6.1.5.5.7.2.1) or userNotice
240
+ (1.3.6.1.5.5.7.2.2) qualifiers — BoringSSL: "if the extension is marked
241
+ critical need to ensure there weren't any qualifiers other than User Notice
242
+ / CPS" — and MSApplicationPolicies (1.3.6.1.4.1.311.21.10) when an EKU
243
+ extension is also present (crbug.com/1439638). Everything else critical —
244
+ including cRLDistributionPoints (2.5.29.31), authorityInfoAccess
245
+ (1.3.6.1.5.5.7.1.1), the embedded SCT list (1.3.6.1.4.1.11129.2.4.2), the
246
+ CT poison extension (1.3.6.1.4.1.11129.2.4.3 — Chrome never accepts
247
+ pre-certificates here: `SimplePathBuilderDelegate::AcceptPreCertificates()`
248
+ returns false), and the Netscape certificate-type extension
249
+ (2.16.840.1.113730.1.1) — is rejected. The trust anchor is exempt in every
250
+ position (issuer or pinned identity — Chrome's loop skips the root), and
251
+ the checks run ONLY when trust anchors are supplied: hostname-only mode
252
+ performs no chain validation at all. The extension STRUCTURE is validated
253
+ at parse time like BoringSSL's `ParseExtensions`: at least one extension
254
+ when the block is present, every entry a SEQUENCE { OID, critical?,
255
+ OCTET STRING } with no trailing data, an explicit critical=FALSE rejected
256
+ (DER requires DEFAULT values be omitted, X.690 §11.5), duplicate OIDs
257
+ rejected, and a present-but-malformed EKU value rejected
258
+ (`kFailedParsingEku`).
259
+
260
+ 9. **nameConstraints (RFC 5280 §4.2.1.10)** — on the built path, processed
261
+ EXACTLY as BoringSSL pki/name_constraints.cc processes it for TLS server
262
+ authentication at the pinned revision. The extension VALUE is parsed for
263
+ EVERY certificate carrying it, critical or not (`kFailedParsingName
264
+ Constraints` rejects the certificate): the extnValue is one SEQUENCE {
265
+ permittedSubtrees [0] OPTIONAL, excludedSubtrees [1] OPTIONAL }, at least
266
+ one side present ("Conforming CAs MUST NOT issue certificates where name
267
+ constraints is an empty sequence"), each side SEQUENCE SIZE (1..MAX) OF
268
+ GeneralSubtree { base } with NO minimum/maximum (name_constraints.cc
269
+ 179-181 rejects any element after the base — including an explicitly
270
+ encoded DEFAULT minimum), an iPAddress base of exactly 8 or 32 octets with
271
+ a contiguous-ones CIDR netmask, ASCII dNSName/rfc822Name bases, and no
272
+ unknown GeneralName tag. CONSTRAINTS apply to every certificate BELOW the
273
+ carrier — the trust anchor's included (Chrome arms caller-supplied
274
+ constrained anchors with `.WithEnforceAnchorConstraints()`) and never the
275
+ carrier itself ("Don't do any other checks for root certificates";
276
+ name_constraints_list_ is consumed by the NEXT certificates). A
277
+ SELF-ISSUED non-target certificate is skipped ("If certificate i is
278
+ self-issued and it is not the final certificate in the path, skip this
279
+ step for certificate i"). The per-name rules: dNSName suffix matching,
280
+ case-insensitive, label-boundary enforced ("foobar.com is not a match for
281
+ bar.com"), a leading-dot constraint permits SUBDOMAINS ONLY ("foo.bar.com
282
+ matches constraint .bar.com, but bar.com doesn't"), one trailing dot
283
+ stripped from BOTH sides, the EMPTY constraint matches everything,
284
+ wildcards are literal strings with BoringSSL's two special cases
285
+ (exclusions: "*.bar.com" matches constraint "foo.bar.com" — any expansion;
286
+ permissions: it matches only a constraint matching EVERY expansion);
287
+ iPAddress by netmask with no cross-family matching (an IPv6 SAN under
288
+ IPv4-only permitted subtrees is not permitted); directoryName by
289
+ RFC 5280 §7.1 subtree match (prefix-of-RDNs-in-order, per-attribute
290
+ normalization — verify_name_match.cc) applied to SAN directoryNames AND
291
+ the subject DN (unless the subject is empty with a SAN — RFC 5280 §4.1.2.6);
292
+ rfc822Name mailbox/domain forms plus the subject's emailAddress attributes
293
+ when NO SAN exists (RFC 5280 §4.2.1.10 legacy rule). commonName is NEVER
294
+ consulted: "this method does not check hostname or IP address in
295
+ commonName, which is deprecated (crbug.com/308330)"
296
+ (name_constraints.h:59-60) — and there is NO empty-SAN rejection rule at
297
+ the pinned revision (every check iterates the names actually present).
298
+ Constraints on forms BoringSSL does not process (URI, otherName,
299
+ x400Address, ediPartyName, registeredID) are ignored when the extension is
300
+ NON-critical (`constrained_name_types_ & kSupportedNameTypes` mask) and —
301
+ when critical — reject any certificate whose SAN carries that form
302
+ (name_constraints.cc:450-454, RFC 5280's MUST-process-or-reject). A DoS
303
+ ceiling caps name × constraint combinations at 2^20
304
+ (`kMaxChecks = 1048576`). Violations fail with
305
+ `name-constraint-violation`, naming the constrained certificate (wire
306
+ index + issuer DN), the constraint holder, the offending name and whether
307
+ it matched an excludedSubtrees entry or no permittedSubtrees entry.
308
+
309
+ 10. **Malformed NON-critical extension values are rejected (Part B parity)** —
310
+ BoringSSL's ParsedCertificate::Create parses the VALUE of basic
311
+ Constraints, keyUsage, extendedKeyUsage, subjectAltName, nameConstraints,
312
+ authorityInfoAccess, certificatePolicies, policyConstraints,
313
+ policyMappings, inhibitAnyPolicy, subjectKeyIdentifier and
314
+ authorityKeyIdentifier at certificate-parse time — critical or NOT — and
315
+ rejects the whole certificate on a malformed value (`kFailedParsing…`).
316
+ This verifier does the same with a typed `TlsMalformedExtensionError`
317
+ naming the extension OID. Faults per extension follow BoringSSL exactly
318
+ (e.g. an empty AIA list, an empty certificatePolicies sequence, duplicate
319
+ policy OIDs, qualifiers under anyPolicy restricted to CPS/userNotice —
320
+ unknown qualifier OIDs under OTHER policies are TOLERATED at parse time —
321
+ an empty policyConstraints sequence, an inhibitAnyPolicy that is not one
322
+ uint8 INTEGER, an authorityKeyIdentifier with only one of [1]/[2]);
323
+ explicitly-encoded cA=FALSE in basicConstraints is tolerated (BoringSSL's
324
+ own TODO — real certificates use the broken encoding), and an EMPTY
325
+ AuthorityKeyIdentifier SEQUENCE is legal. cRLDistributionPoints is
326
+ deliberately NOT value-parsed: `ParseCrlDistributionPoints` has no caller
327
+ in the parse path at the pinned revision, so a malformed value does not
328
+ reject the certificate in Chrome — and does not here.
329
+
330
+ Every certificate-phase failure is a `TlsCertificateError` (a
331
+ `TlsHandshakeError` with phase `"certificate"`) carrying a discriminated
332
+ `reason`: `no-anchors` (verifyChain called with an empty anchor list — never a
333
+ vacuous success), `no-issuer`, `bad-signature`, `expired`, `not-yet-valid`,
334
+ `not-a-ca`, `missing-key-cert-sign`, `path-too-long`,
335
+ `unsupported-critical-extension`, `missing-server-auth-eku`,
336
+ `name-constraint-violation`. The message names the offending certificate (wire
337
+ index + issuer DN — and, for the extension, EKU and name-constraint failures,
338
+ the offending OID / offending name) so an operator can identify it without
339
+ re-running the handshake. A malformed extension VALUE at PARSE time throws a
340
+ `TlsMalformedExtensionError` (a `TlsHandshakeError` subclass with phase
341
+ "certificate" carrying the `extensionOid`).
342
+
343
+ Explicit limitations — current scope, tracked as separate follow-up subsets
344
+ (not permanent design decisions): no revocation checking of any kind (no
345
+ CRL, no OCSP — neither stapled nor fetched); no AIA fetching; no policy
346
+ constraints / policy mappings / certificate-policies ENFORCEMENT (the
347
+ critical-acceptance of those OIDs mirrors BoringSSL's parseability bar and the
348
+ values are parsed per rule 10 — but the policy GRAPH is not evaluated, exactly
349
+ like BoringSSL's own policy processing which this verifier does not implement;
350
+ under Chrome's SERVER_AUTH verification the initial policy set is {anyPolicy},
351
+ so these cannot make Chrome reject a path this verifier would accept); no
352
+ IP-address SAN matching for the HOSTNAME check (name-constraint iPAddress
353
+ checking IS implemented — rule 9). Additionally, DN comparison for path
354
+ BUILDING is byte-exact: a path whose issuer/subject encodings differ for the
355
+ same DN (rare; real CAs copy the DER bytes) fails with `no-issuer` rather than
356
+ being leniently matched (the name-constraint DN matcher, by contrast, is
357
+ BoringSSL's normalized per-attribute comparison — rule 9), and the
358
+ inner/outer AlgorithmIdentifier equality of RFC 5280 §4.1.2.2 is not enforced
359
+ (the TBSCertificate identifier is authoritative).
360
+
76
361
  ## Dependency graph
77
362
 
78
363
  ```
@@ -165,7 +450,7 @@ directly and receives the engine via injection, exactly like crypto/transport
165
450
  - NewSessionTicket / session resumption / PSK / 0-RTT
166
451
  - Mutual TLS (client certificate)
167
452
  - Certificate compression
168
- - Additional key-share groups beyond X25519
453
+ - Key-share groups beyond X25519, secp256r1, secp384r1, and the X25519MLKEM768 hybrid (secp521r1 / x448 / FFDHE fail with a typed error — the crypto backend does not expose them)
169
454
 
170
455
  ## Development
171
456
 
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Certificate-authority constraint bits for path validation (RFC 5280
3
+ * §4.2.1.3 KeyUsage, §4.2.1.9 BasicConstraints pathLenConstraint).
4
+ *
5
+ * This module holds ONLY the delta the path builder needs beyond what
6
+ * `cert-extensions.ts` already parses (digitalSignature/keyEncipherment bits
7
+ * and the cA flag): the keyCertSign bit and the pathLenConstraint integer.
8
+ * Keeping the additions beside the path checks means the RFC 5280 §6.1
9
+ * issuer-authorization inputs have one owner; `certificates.ts` feeds the same
10
+ * unwrapped extension values to both parsers.
11
+ */
12
+ /**
13
+ * keyUsage BIT STRING bit position of keyCertSign (RFC 5280 §4.2.1.3):
14
+ * digitalSignature(0), nonRepudiation(1), keyEncipherment(2),
15
+ * dataEncipherment(3), keyAgreement(4), keyCertSign(5), cRLSign(6).
16
+ */
17
+ export declare const KEY_USAGE_KEY_CERT_SIGN_BIT = 5;
18
+ /**
19
+ * True when the keyUsage BIT STRING (unwrapped from its extnValue OCTET
20
+ * STRING) asserts the bit at `bitIndex`. Bits are numbered from the most
21
+ * significant bit of the first content byte (after the unused-bits count),
22
+ * exactly the layout parseKeyUsage decodes.
23
+ */
24
+ export declare function hasKeyUsageBit(value: Uint8Array, bitIndex: number): boolean;
25
+ /**
26
+ * Parse the pathLenConstraint INTEGER element (RFC 5280 §4.2.1.9,
27
+ * `intTlv` already read inside the BasicConstraints SEQUENCE) under
28
+ * BoringSSL der::ParseUint8's rule — the same test ParseBasicConstraints
29
+ * applies at certificate-parse time, whose failure rejects the whole
30
+ * certificate (kFailedParsingBasicConstraints): the INTEGER must be
31
+ * non-negative (no high-bit-set leading byte), minimally encoded (a leading
32
+ * 0x00 is allowed only before a byte with the high bit set), and its value
33
+ * must fit one unsigned byte (≤ 255).
34
+ *
35
+ * Returns the constraint value, or null when the element is absent. Throws
36
+ * the typed malformed-extension error otherwise.
37
+ */
38
+ export declare function parsePathLenConstraint(value: Uint8Array, intTlv: {
39
+ tag: number;
40
+ valueStart: number;
41
+ end: number;
42
+ }, extensionOid: string): number | null;
43
+ //# sourceMappingURL=ca-constraints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ca-constraints.d.ts","sourceRoot":"","sources":["../../src/certificates/ca-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAe3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACxD,YAAY,EAAE,MAAM,GACrB,MAAM,GAAG,IAAI,CAgDf"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Certificate-authority constraint bits for path validation (RFC 5280
3
+ * §4.2.1.3 KeyUsage, §4.2.1.9 BasicConstraints pathLenConstraint).
4
+ *
5
+ * This module holds ONLY the delta the path builder needs beyond what
6
+ * `cert-extensions.ts` already parses (digitalSignature/keyEncipherment bits
7
+ * and the cA flag): the keyCertSign bit and the pathLenConstraint integer.
8
+ * Keeping the additions beside the path checks means the RFC 5280 §6.1
9
+ * issuer-authorization inputs have one owner; `certificates.ts` feeds the same
10
+ * unwrapped extension values to both parsers.
11
+ */
12
+ import { readTlv } from "./der.js";
13
+ import { TlsMalformedExtensionError } from "../errors.js";
14
+ /**
15
+ * keyUsage BIT STRING bit position of keyCertSign (RFC 5280 §4.2.1.3):
16
+ * digitalSignature(0), nonRepudiation(1), keyEncipherment(2),
17
+ * dataEncipherment(3), keyAgreement(4), keyCertSign(5), cRLSign(6).
18
+ */
19
+ export const KEY_USAGE_KEY_CERT_SIGN_BIT = 5;
20
+ /**
21
+ * True when the keyUsage BIT STRING (unwrapped from its extnValue OCTET
22
+ * STRING) asserts the bit at `bitIndex`. Bits are numbered from the most
23
+ * significant bit of the first content byte (after the unused-bits count),
24
+ * exactly the layout parseKeyUsage decodes.
25
+ */
26
+ export function hasKeyUsageBit(value, bitIndex) {
27
+ const bitString = readTlv(value, 0);
28
+ if (bitString.tag !== 0x03) {
29
+ return false;
30
+ }
31
+ // BIT STRING content: first byte = number of unused bits, then the bits.
32
+ const usedBytes = value.subarray(bitString.valueStart + 1, bitString.end);
33
+ const byteIndex = Math.floor(bitIndex / 8);
34
+ const byte = usedBytes[byteIndex];
35
+ if (byte === undefined) {
36
+ // The extension simply does not extend to this bit — not asserted.
37
+ return false;
38
+ }
39
+ const bitInByte = bitIndex % 8;
40
+ return (byte & (1 << (7 - bitInByte))) !== 0;
41
+ }
42
+ /**
43
+ * Parse the pathLenConstraint INTEGER element (RFC 5280 §4.2.1.9,
44
+ * `intTlv` already read inside the BasicConstraints SEQUENCE) under
45
+ * BoringSSL der::ParseUint8's rule — the same test ParseBasicConstraints
46
+ * applies at certificate-parse time, whose failure rejects the whole
47
+ * certificate (kFailedParsingBasicConstraints): the INTEGER must be
48
+ * non-negative (no high-bit-set leading byte), minimally encoded (a leading
49
+ * 0x00 is allowed only before a byte with the high bit set), and its value
50
+ * must fit one unsigned byte (≤ 255).
51
+ *
52
+ * Returns the constraint value, or null when the element is absent. Throws
53
+ * the typed malformed-extension error otherwise.
54
+ */
55
+ export function parsePathLenConstraint(value, intTlv, extensionOid) {
56
+ const content = value.subarray(intTlv.valueStart, intTlv.end);
57
+ const first = content[0];
58
+ if (first === undefined) {
59
+ throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint INTEGER has no content bytes (der::ParseUint8)");
60
+ }
61
+ if ((first & 0x80) !== 0) {
62
+ // High bit of the first byte set: a negative two's-complement
63
+ // INTEGER — never a valid pathLenConstraint.
64
+ throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint must be a non-negative INTEGER; the leading byte makes it negative (der::ParseUint8)");
65
+ }
66
+ if (content.length === 1) {
67
+ return first;
68
+ }
69
+ const second = content[1] ?? 0;
70
+ if (first === 0x00) {
71
+ // Padded form: DER minimality permits the 0x00 only when the next
72
+ // byte's high bit is set (otherwise the padding octet is redundant —
73
+ // CBS_is_valid_asn1_integer rejects it, so der::ParseUint8 does too).
74
+ if ((second & 0x80) === 0) {
75
+ throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint INTEGER is not minimally encoded (a leading 0x00 is only valid before a byte with the high bit set)");
76
+ }
77
+ if (content.length > 2) {
78
+ // [0x00, 0x80, ...] — the value is ≥ 2^15, far above one byte.
79
+ throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint must fit one unsigned byte — der::ParseUint8 (ParseUint64) rejects values above 255");
80
+ }
81
+ // [0x00, 0x80..0xFF] — the two's-complement leading zero makes the
82
+ // value the unsigned second byte (128..255).
83
+ return second;
84
+ }
85
+ // first in 0x01..0x7F with ≥ 2 content bytes: a minimal encoding whose
86
+ // value is ≥ 256 — above the uint8 range ParseUint8 accepts.
87
+ throw new TlsMalformedExtensionError(extensionOid, "pathLenConstraint must fit one unsigned byte — der::ParseUint8 (ParseUint64) rejects values above 255");
88
+ }
89
+ //# sourceMappingURL=ca-constraints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ca-constraints.js","sourceRoot":"","sources":["../../src/certificates/ca-constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB,EAAE,QAAgB;IAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACpC,IAAI,SAAS,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,yEAAyE;IACzE,MAAM,SAAS,GAAG,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,kEAAkE;QAClE,qEAAqE;QACrE,sEAAsE;QACtE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,uHAAuH,CAC1H,CAAC;QACN,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,+DAA+D;YAC/D,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,uGAAuG,CAC1G,CAAC;QACN,CAAC;QACD,mEAAmE;QACnE,6CAA6C;QAC7C,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,uEAAuE;IACvE,6DAA6D;IAC7D,MAAM,IAAI,0BAA0B,CAChC,YAAY,EACZ,uGAAuG,CAC1G,CAAC;AACN,CAAC"}
@@ -3,11 +3,20 @@
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, and
7
- * BasicConstraints (the cA flag that separates leaf from CA certs). They sit on
8
- * top of the raw DER primitives in `der.ts` but are agnostic to validation
9
- * policy — they only turn bytes into structured fields.
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
  */
13
+ import type { CertificateExtension } from "./certificate-path.js";
14
+ import { parseGeneralNames, type GeneralNames } from "./general-names.js";
15
+ import { parseNameConstraints, type NameConstraints } from "./name-constraints.js";
16
+ import { BASIC_CONSTRAINTS_OID, EXTENDED_KEY_USAGE_OID, KEY_USAGE_OID, SUBJECT_ALT_NAME_OID } from "./extension-policy.js";
17
+ export { parseGeneralNames, parseNameConstraints };
18
+ export type { GeneralNames, NameConstraints };
19
+ export { BASIC_CONSTRAINTS_OID, EXTENDED_KEY_USAGE_OID, KEY_USAGE_OID, SUBJECT_ALT_NAME_OID };
11
20
  /**
12
21
  * Parse the subject Name and return a readable DN string (RFC 2253-ish).
13
22
  * Used only for the `issuer` field and debug-friendliness.
@@ -16,31 +25,109 @@ export declare function parseName(buf: Uint8Array, start: number, _end: number):
16
25
  /** Extract the CN (OID 2.5.4.3) from a subject Name, if present. */
17
26
  export declare function parseCommonName(buf: Uint8Array, start: number, _end: number): string | undefined;
18
27
  /**
19
- * Parse the extensions block (SEQUENCE OF Extension) between `start` and `end`.
20
- * Each extension is SEQUENCE { extnID OID, critical BOOLEAN?, extnValue OCTET STRING }.
28
+ * Parse the extensions block (SEQUENCE OF Extension, RFC 5280 §4.1.2.9) between
29
+ * `start` and `end` into the ordered extension inventory:
30
+ * `{ oid, critical, value }` per extension, where `critical` defaults to FALSE
31
+ * (RFC 5280 §4.2: "critical BOOLEAN DEFAULT FALSE") and `value` is the CONTENTS
32
+ * of the extnValue OCTET STRING.
33
+ *
34
+ * Structural faults throw the typed certificate-phase error, mirroring
35
+ * BoringSSL's ParseExtensions/ParseExtension (pki/parse_certificate.cc), whose
36
+ * failure rejects the whole certificate:
37
+ *
38
+ * - the block must be a SEQUENCE containing at least one extension ("The
39
+ * Extensions SEQUENCE must contains at least 1 element (otherwise it
40
+ * should have been omitted)" — RFC 5280 §4.1.2.9 makes the whole block
41
+ * OPTIONAL, so an empty one is an encoding fault);
42
+ * - each entry must be a SEQUENCE whose extnID is an OBJECT IDENTIFIER;
43
+ * - the critical BOOLEAN, when present, must be a single 0xFF byte:
44
+ * BoringSSL `der::ParseBool` (X.690 §11.1) accepts only 0x00/0xFF, and
45
+ * `ParseExtension` then rejects FALSE — "DER-encoding requires DEFAULT
46
+ * values be omitted" (X.690 §11.5 via RFC 5280's DER mandate);
47
+ * - extnValue must be an OCTET STRING with no trailing data inside the
48
+ * Extension element ("The Extension type does not have an extension
49
+ * point (everything goes in extnValue)" — HasMore check);
50
+ * - an OID must not appear twice ("RFC 5280 says that an extension should
51
+ * not appear more than once" — the duplicate insert fails in
52
+ * ParseExtensions).
53
+ */
54
+ export declare function parseExtensionsBlock(buf: Uint8Array, start: number, _end: number): readonly CertificateExtension[];
55
+ /**
56
+ * Parse the extendedKeyUsage extension value (already unwrapped from its OCTET
57
+ * STRING): SEQUENCE OF KeyPurposeId, i.e. a SEQUENCE whose every element is an
58
+ * OBJECT IDENTIFIER (RFC 5280 §4.2.1.12). Returns the OIDs in dotted form,
59
+ * in order; an empty SEQUENCE is valid DER and yields an empty list (the
60
+ * SERVER_AUTH policy then rejects the certificate — "present but permitting
61
+ * nothing").
62
+ *
63
+ * A malformed value throws the typed certificate-phase error: BoringSSL parses
64
+ * the EKU at certificate-parse time and a failed `ParseEKUExtension` rejects
65
+ * the whole certificate (parsed_certificate.cc: `if (!ParseEKUExtension(...))
66
+ * { errors->AddError(kFailedParsingEku); return nullptr; }`).
21
67
  */
22
- export declare function parseExtensionsBlock(buf: Uint8Array, start: number, _end: number): readonly {
23
- readonly oid: string;
24
- readonly value: Uint8Array;
25
- }[];
68
+ export declare function parseExtendedKeyUsage(value: Uint8Array): readonly string[];
26
69
  /**
27
- * Parse the SAN extension value (already unwrapped from its OCTET STRING).
28
- * The value is a SEQUENCE OF GeneralName; we only extract dNSName entries
29
- * (context tag [2]).
70
+ * Parse the SAN extension value (already unwrapped from its OCTET STRING) —
71
+ * the STRICT GeneralNames::Create twin (see general-names.ts for the exact
72
+ * fault list): BoringSSL parses the SAN value for EVERY certificate carrying
73
+ * the extension, critical or not, and a fault rejects the whole certificate
74
+ * (kFailedParsingSubjectAltName). Returns the full parsed name set (the DNS
75
+ * names the hostname check uses, plus the rfc822 / iPAddress / directoryName
76
+ * forms the name-constraint engine consumes).
30
77
  */
31
- export declare function parseSubjectAltNames(value: Uint8Array): readonly string[];
78
+ export declare function parseSubjectAltNames(value: Uint8Array): GeneralNames;
32
79
  /**
33
80
  * Parse the KeyUsage extension value (unwrapped OCTET STRING holding a BIT
34
- * STRING). Returns the digitalSignature (bit 0) and keyEncipherment (bit 2)
35
- * flags.
81
+ * STRING) — the STRICT ParseKeyUsage twin (pki/parse_certificate.cc:794):
82
+ * BoringSSL runs this for every keyUsage extension, critical or not, and a
83
+ * fault rejects the certificate (kFailedParsingKeyUsage):
84
+ *
85
+ * - the value must be exactly one BIT STRING (nothing before or after —
86
+ * "By definition the input was a single BIT STRING");
87
+ * - the unused-bits byte must be < 8 and a BIT STRING with no data bytes
88
+ * must declare 0 unused bits (CBS_asn1_bitstring rules);
89
+ * - "When the keyUsage extension appears in a certificate, at least one of
90
+ * the bits MUST be set to 1" (RFC 5280 §4.2.1.3) — an all-zero BIT STRING
91
+ * is the parse failure (`if (BitStringIsAllZeros(...)) { return false; }`).
92
+ *
93
+ * Returns the digitalSignature (bit 0) and keyEncipherment (bit 2) flags.
36
94
  */
37
95
  export declare function parseKeyUsage(value: Uint8Array): {
38
96
  readonly digitalSignature: boolean;
39
97
  readonly keyEncipherment: boolean;
40
98
  };
41
99
  /**
42
- * Parse the BasicConstraints extension value (unwrapped OCTET STRING holding a
43
- * SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER? }).
100
+ * The strict BasicConstraints parse result (see {@link parseBasicConstraints}).
101
+ */
102
+ export interface BasicConstraints {
103
+ readonly isCa: boolean;
104
+ /**
105
+ * pathLenConstraint (RFC 5280 §4.2.1.9), or null when absent. A value
106
+ * outside 0..255 or with a non-minimal / negative DER encoding is a
107
+ * malformed certificate (BoringSSL der::ParseUint8 fails →
108
+ * kFailedParsingBasicConstraints) and THROWS.
109
+ */
110
+ readonly pathLenConstraint: number | null;
111
+ }
112
+ /**
113
+ * Parse the BasicConstraints extension value (unwrapped OCTET STRING holding
114
+ * SEQUENCE { cA BOOLEAN DEFAULT FALSE, pathLenConstraint INTEGER? }) — the
115
+ * STRICT ParseBasicConstraints twin (pki/parse_certificate.cc:735): BoringSSL
116
+ * runs this for every basicConstraints extension, critical or not, and a
117
+ * fault rejects the certificate (kFailedParsingBasicConstraints):
118
+ *
119
+ * - the value must be exactly one SEQUENCE (nothing trailing);
120
+ * - the cA BOOLEAN, when present, is der::ParseBool — one byte, 0x00 or
121
+ * 0xFF (X.690 §11.1); an explicitly-encoded FALSE is TOLERATED
122
+ * (BoringSSL's own TODO: "Should reject if CA was set to false… In
123
+ * practice however there are a lot of certificates that use the broken
124
+ * encoding");
125
+ * - the pathLenConstraint INTEGER, when present, must decode as uint8 —
126
+ * non-negative, minimally encoded, value ≤ 255 (der::ParseUint8; a larger
127
+ * constraint cannot appear in a certificate Chrome accepts);
128
+ * - nothing may follow inside the SEQUENCE.
129
+ *
130
+ * An empty SEQUENCE parses fine with cA = FALSE (the DEFAULT applies).
44
131
  */
45
- export declare function parseBasicConstraints(value: Uint8Array): boolean;
132
+ export declare function parseBasicConstraints(value: Uint8Array): BasicConstraints;
46
133
  //# sourceMappingURL=cert-extensions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cert-extensions.d.ts","sourceRoot":"","sources":["../../src/certificates/cert-extensions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAiC9E;AAED,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA8BhG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS;IACzF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC9B,EA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