@browsercore/tls 0.4.18 → 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.
Files changed (53) hide show
  1. package/README.md +218 -6
  2. package/dist/certificates/ca-constraints.d.ts +41 -0
  3. package/dist/certificates/ca-constraints.d.ts.map +1 -0
  4. package/dist/certificates/ca-constraints.js +107 -0
  5. package/dist/certificates/ca-constraints.js.map +1 -0
  6. package/dist/certificates/cert-extensions.d.ts +47 -10
  7. package/dist/certificates/cert-extensions.d.ts.map +1 -1
  8. package/dist/certificates/cert-extensions.js +111 -10
  9. package/dist/certificates/cert-extensions.js.map +1 -1
  10. package/dist/certificates/certificate-path.d.ts +282 -0
  11. package/dist/certificates/certificate-path.d.ts.map +1 -0
  12. package/dist/certificates/certificate-path.js +499 -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 +163 -82
  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 +195 -0
  23. package/dist/certificates/extension-policy.d.ts.map +1 -0
  24. package/dist/certificates/extension-policy.js +346 -0
  25. package/dist/certificates/extension-policy.js.map +1 -0
  26. package/dist/certificates/signature-algorithm.d.ts +54 -0
  27. package/dist/certificates/signature-algorithm.d.ts.map +1 -0
  28. package/dist/certificates/signature-algorithm.js +359 -0
  29. package/dist/certificates/signature-algorithm.js.map +1 -0
  30. package/dist/connection/handshake-driver.d.ts +9 -6
  31. package/dist/connection/handshake-driver.d.ts.map +1 -1
  32. package/dist/connection/handshake-driver.js.map +1 -1
  33. package/dist/connection/handshake-messages.d.ts +9 -2
  34. package/dist/connection/handshake-messages.d.ts.map +1 -1
  35. package/dist/connection/handshake-messages.js +57 -23
  36. package/dist/connection/handshake-messages.js.map +1 -1
  37. package/dist/errors.d.ts +54 -0
  38. package/dist/errors.d.ts.map +1 -1
  39. package/dist/errors.js +22 -0
  40. package/dist/errors.js.map +1 -1
  41. package/dist/index.d.ts +8 -5
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +5 -3
  44. package/dist/index.js.map +1 -1
  45. package/dist/tls.d.ts +4 -3
  46. package/dist/tls.d.ts.map +1 -1
  47. package/dist/tls.js +4 -3
  48. package/dist/tls.js.map +1 -1
  49. package/dist/types.d.ts +2 -1
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/types.js +2 -1
  52. package/dist/types.js.map +1 -1
  53. package/package.json +3 -3
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Extension policy decisions (RFC 5280 §4.2, BoringSSL pki verify_certificate_chain.cc).
3
+ *
4
+ * Pure deciders over extension bytes — no path knowledge, no I/O. They answer
5
+ * the two questions path validation asks about every certificate on a built
6
+ * path:
7
+ *
8
+ * 1. May this CRITICAL extension be consumed (or must the certificate be
9
+ * rejected)? — mirrors BoringSSL's `IsHandledCriticalExtension` plus the
10
+ * special cases in `VerifyNoUnconsumedCriticalExtensions`, evaluated for
11
+ * Chrome's TLS-server-auth verification (KeyPurpose::SERVER_AUTH,
12
+ * allow_precertificate=false — SimplePathBuilderDelegate::AcceptPreCertificates
13
+ * returns false and cert_verify_proc_builtin.cc does not override it).
14
+ * 2. Is this certificate's EKU usable for TLS server authentication? —
15
+ * mirrors BoringSSL's `VerifyExtendedKeyUsage` SERVER_AUTH ("Legacy
16
+ * compatible") branch, the policy Chromium 140's built-in verifier runs
17
+ * (cert_verify_proc_builtin.cc passes `bssl::KeyPurpose::SERVER_AUTH` to
18
+ * the CertPathBuilder).
19
+ *
20
+ * RFC 5280 §4.2 mandates the backdrop for (1): "A certificate-using system
21
+ * MUST reject the certificate if it encounters a critical extension it does
22
+ * not recognize or a critical extension that contains information that it
23
+ * cannot process." The recognized set below is EXACTLY BoringSSL's — neither
24
+ * stricter nor looser — so this verifier behaves like Chrome.
25
+ *
26
+ * Extension STRUCTURE parsing (the Extensions SEQUENCE, the critical BOOLEAN,
27
+ * the EKU value itself) lives in cert-extensions.ts; this module only decides
28
+ * about already-decoded records and extension values.
29
+ */
30
+ /** id-ce-basicConstraints (RFC 5280 §4.2.1.9). */
31
+ export declare const BASIC_CONSTRAINTS_OID = "2.5.29.19";
32
+ /** id-ce-keyUsage (RFC 5280 §4.2.1.3). */
33
+ export declare const KEY_USAGE_OID = "2.5.29.15";
34
+ /** id-ce-subjectAltName (RFC 5280 §4.2.1.6). */
35
+ export declare const SUBJECT_ALT_NAME_OID = "2.5.29.17";
36
+ /** id-ce-nameConstraints (RFC 5280 §4.2.1.10). */
37
+ export declare const NAME_CONSTRAINTS_OID = "2.5.29.30";
38
+ /** id-ce-certificatePolicies (RFC 5280 §4.2.1.4). */
39
+ export declare const CERTIFICATE_POLICIES_OID = "2.5.29.32";
40
+ /** id-ce-inhibitAnyPolicy (RFC 5280 §4.2.1.5). */
41
+ export declare const INHIBIT_ANY_POLICY_OID = "2.5.29.54";
42
+ /** id-ce-extKeyUsage (RFC 5280 §4.2.1.12). */
43
+ export declare const EXTENDED_KEY_USAGE_OID = "2.5.29.37";
44
+ /** id-kp-serverAuth (RFC 5280 §4.2.1.12). */
45
+ export declare const SERVER_AUTH_EKU_OID = "1.3.6.1.5.5.7.3.1";
46
+ /** id-kp-clientAuth (RFC 5280 §4.2.1.12) — NOT sufficient for this client's role. */
47
+ export declare const CLIENT_AUTH_EKU_OID = "1.3.6.1.5.5.7.3.2";
48
+ /** anyExtendedKeyUsage (RFC 5280 §4.2.1.12: `{ id-ce-extKeyUsage 0 }`). */
49
+ export declare const ANY_EKU_OID = "2.5.29.37.0";
50
+ /** anyPolicy (RFC 5280 §4.2.1.4: `{ id-ce-certificatePolicies 0 }`). */
51
+ export declare const ANY_POLICY_OID = "2.5.29.32.0";
52
+ /** id-ce-policyMappings (RFC 5280 §4.2.1.5). */
53
+ export declare const POLICY_MAPPINGS_OID = "2.5.29.33";
54
+ /** id-ce-policyConstraints (RFC 5280 §4.2.1.5). */
55
+ export declare const POLICY_CONSTRAINTS_OID = "2.5.29.36";
56
+ /** XCN_OID_APPLICATION_CERT_POLICIES (MSApplicationPolicies), Windows-enrolled. */
57
+ export declare const MS_APPLICATION_POLICIES_OID = "1.3.6.1.4.1.311.21.10";
58
+ /** id-qt-cps (RFC 5280 §4.2.1.4: CPSuri qualifier). */
59
+ export declare const CPS_QUALIFIER_OID = "1.3.6.1.5.5.7.2.1";
60
+ /** id-qt-unotice (RFC 5280 §4.2.1.4: userNotice qualifier). */
61
+ export declare const USER_NOTICE_QUALIFIER_OID = "1.3.6.1.5.5.7.2.2";
62
+ /**
63
+ * The OIDs this verifier HANDLES when a certificate marks them critical.
64
+ *
65
+ * This is BoringSSL's `IsHandledCriticalExtension` (pki/verify_certificate_chain.cc
66
+ * at the revision Chromium 140 pins, boringssl 0a0009998fa180695f3e2071805dc03c9a5f3124)
67
+ * with exactly one deliberate removal — nameConstraints, whose handling is
68
+ * described at {@link NAME_CONSTRAINTS_OID} below. Conditional entries are NOT
69
+ * in this list; they are decided by {@link isCriticalExtensionHandled}:
70
+ *
71
+ * - certificatePolicies: BoringSSL accepts a critical certificatePolicies
72
+ * only if the value parses with `fail_parsing_unknown_qualifier_oids=true`
73
+ * (the quoted RFC 5280 §4.2.1.4 condition in its source) — see
74
+ * {@link criticalCertificatePoliciesProcessable}.
75
+ * - MSApplicationPolicies: ignored as critical only when the certificate
76
+ * also carries an EKU extension (`VerifyNoUnconsumedCriticalExtensions`,
77
+ * per crbug.com/1439638).
78
+ *
79
+ * Per-OID WHY (each entry: what Chrome does with it, and why accepting it
80
+ * critical cannot accept a chain Chrome would reject):
81
+ *
82
+ * - basicConstraints 2.5.29.19: PROCESSED — isCa/pathLenConstraint feed the
83
+ * issuer-authorization and path-length checks.
84
+ * - keyUsage 2.5.29.15: PROCESSED (keyCertSign on issuers). BoringSSL's own
85
+ * comment: "Key Usage is NOT processed for end-entity certificates (this
86
+ * is the responsibility of callers), however it is considered 'handled'
87
+ * here in order to allow being marked as critical."
88
+ * - extKeyUsage 2.5.29.37: PROCESSED — the SERVER_AUTH EKU rule of this
89
+ * subset.
90
+ * - subjectAltName 2.5.29.17: PROCESSED — the hostname check consumes it.
91
+ * - policyMappings 2.5.29.33 / policyConstraints 2.5.29.36 /
92
+ * inhibitAnyPolicy 2.5.29.54: BoringSSL returns true for all three (`if
93
+ * (extension.oid == der::Input(kPolicyMappingsOid)) { return true; }` etc.)
94
+ * and enforces them inside its policy graph. This verifier performs no
95
+ * policy processing (documented limitation); under Chrome's SERVER_AUTH
96
+ * verification the initial policy set is {anyPolicy}, so these constraints
97
+ * cannot make Chrome reject a path this verifier would accept — accepting
98
+ * them critical matches Chrome exactly for the purposes of this verifier.
99
+ * - nameConstraints 2.5.29.30 is deliberately NOT listed: BoringSSL marks it
100
+ * handled BECAUSE IT PROCESSES name constraints (`NameConstraints::Create`
101
+ * + `IsPermittedCert`). This verifier does not process them yet (separate
102
+ * follow-up subset), and RFC 5280 §4.2 requires rejecting an unprocessed
103
+ * critical extension — so a CRITICAL nameConstraints is rejected until the
104
+ * name-constraints subset lands (README documents this stance).
105
+ */
106
+ export declare const RECOGNIZED_CRITICAL_EXTENSION_OIDS: readonly string[];
107
+ /**
108
+ * Decide whether a CRITICAL extension with the given OID and (unwrapped,
109
+ * extnValue-content) `value` may be consumed by this verifier, or must fail
110
+ * with `unsupported-critical-extension`.
111
+ *
112
+ * Mirrors BoringSSL `VerifyNoUnconsumedCriticalExtensions` +
113
+ * `IsHandledCriticalExtension` in SERVER_AUTH mode with
114
+ * allow_precertificate=false:
115
+ *
116
+ * - RCS MLS participant-information OIDs (2.23.146.2.1.4 / 2.23.146.2.1.5)
117
+ * are exempt only for KeyPurpose::RCS_MLS_CLIENT_AUTH — not this purpose —
118
+ * so a critical one is rejected here, exactly as BoringSSL does for server
119
+ * auth.
120
+ * - The CT poison OID (RFC 6962 §3.1, 1.3.6.1.4.1.11129.2.4.3) is exempt
121
+ * only when the delegate accepts pre-certificates
122
+ * (`allow_precertificate && extension.oid == kCtPoisonOid`); Chrome's
123
+ * verifier never does (`SimplePathBuilderDelegate::AcceptPreCertificates()
124
+ * { return false; }`, not overridden by cert_verify_proc_builtin.cc), so a
125
+ * critical poison extension is rejected — the same holds for a critical
126
+ * embedded SCT list (1.3.6.1.4.1.11129.2.4.2), which appears in no
127
+ * exemption branch at all.
128
+ *
129
+ * `certificateHasEku` gates the MSApplicationPolicies special case.
130
+ */
131
+ export declare function isCriticalExtensionHandled(oid: string, value: Uint8Array, certificateHasEku: boolean): boolean;
132
+ /**
133
+ * Whether a critical certificatePolicies value is processable, mirroring
134
+ * BoringSSL `ParseCertificatePoliciesExtensionOids(value,
135
+ * fail_parsing_unknown_qualifier_oids=true, …)` exactly
136
+ * (pki/certificate_policies.cc):
137
+ *
138
+ * - the value is one SEQUENCE covering all its bytes, with at least one
139
+ * element ("The certificatePolicies sequence should have at least 1
140
+ * element" — kPoliciesEmptySequence otherwise);
141
+ * - each PolicyInformation is SEQUENCE { policyIdentifier OID, optional
142
+ * policyQualifiers SEQUENCE (≥ 1 element) }, no trailing data
143
+ * (kPolicyInformationTrailingData otherwise);
144
+ * - each PolicyQualifierInfo is SEQUENCE { policyQualifierId OID, qualifier
145
+ * ANY }, no trailing data (kPolicyQualifierInfoTrailingData), and the
146
+ * qualifier OID must be id-qt-cps or id-qt-unotice
147
+ * (`if (restrict_to_known_qualifiers && qualifier_oid != kCpsPointerId &&
148
+ * qualifier_oid != kUserNoticeId)` → kUnknownPolicyQualifierOid); the
149
+ * qualifier ANY must be present (kMissingQualifier);
150
+ * - no policy OID appears twice ("A certificate policy OID MUST NOT appear
151
+ * more than once in a certificate policies extension" — kPoliciesDuplicateOid).
152
+ *
153
+ * Returns false (never throws) for any malformation: a failed parse makes
154
+ * IsHandledCriticalExtension return false, i.e. the certificate is rejected as
155
+ * carrying an unrecognized critical extension — never a parse error.
156
+ */
157
+ export declare function criticalCertificatePoliciesProcessable(value: Uint8Array): boolean;
158
+ /**
159
+ * Whether a parsed EKU OID list makes a certificate usable for TLS server
160
+ * authentication, mirroring BoringSSL `VerifyExtendedKeyUsage` SERVER_AUTH
161
+ * ("Legacy compatible") — the policy Chromium 140 runs
162
+ * (cert_verify_proc_builtin.cc: `bssl::KeyPurpose::SERVER_AUTH`):
163
+ *
164
+ * ```
165
+ * if (required_key_purpose == KeyPurpose::SERVER_AUTH) {
166
+ * // Legacy compatible.
167
+ * if (cert.has_extended_key_usage() && !has_server_auth_eku &&
168
+ * !has_any_eku) {
169
+ * errors->AddError(cert_errors::kEkuLacksServerAuth);
170
+ * }
171
+ * }
172
+ * ```
173
+ *
174
+ * This branch runs for the target certificate AND for every issuer (the
175
+ * enclosing `is_target_cert` / `is_target_cert_issuer` code paths only add
176
+ * WARNINGS in non-strict SERVER_AUTH mode: a missing EKU extension is only a
177
+ * warning — BoringSSL's comment: "At this time (until at least 2023) some
178
+ * intermediates are lacking EKU in the world at large from common CA's, so we
179
+ * allow the noEKU case to permit everything." — and codeSigning /
180
+ * timeStamping / OCSPSigning presence goes through `add_error_if_strict`,
181
+ * i.e. warnings). The deciding error is therefore uniform for every
182
+ * non-anchor certificate on the path:
183
+ *
184
+ * - NO EKU extension → acceptable (accepted; on a leaf only the
185
+ * kEkuNotPresent warning).
186
+ * - EKU present → it must contain id-kp-serverAuth or anyExtendedKeyUsage;
187
+ * anything else (clientAuth-only, codeSigning-only, or the EMPTY SEQUENCE
188
+ * — "present" with zero OIDs) is the kEkuLacksServerAuth error.
189
+ *
190
+ * `ekuOids` is the parsed EKU OID list (dotted); whether the extension is
191
+ * present at all is decided by the caller (absent → acceptable without
192
+ * consulting this function).
193
+ */
194
+ export declare function serverAuthEkuAcceptable(ekuOids: readonly string[]): boolean;
195
+ //# sourceMappingURL=extension-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-policy.d.ts","sourceRoot":"","sources":["../../src/certificates/extension-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AASH,kDAAkD;AAClD,eAAO,MAAM,qBAAqB,cAAc,CAAC;AACjD,0CAA0C;AAC1C,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,gDAAgD;AAChD,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,kDAAkD;AAClD,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,cAAc,CAAC;AACpD,kDAAkD;AAClD,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAClD,8CAA8C;AAC9C,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAClD,6CAA6C;AAC7C,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,2EAA2E;AAC3E,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,wEAAwE;AACxE,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAC5C,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAC/C,mDAAmD;AACnD,eAAO,MAAM,sBAAsB,cAAc,CAAC;AAClD,mFAAmF;AACnF,eAAO,MAAM,2BAA2B,0BAA0B,CAAC;AACnE,uDAAuD;AACvD,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AACrD,+DAA+D;AAC/D,eAAO,MAAM,yBAAyB,sBAAsB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,kCAAkC,EAAE,SAAS,MAAM,EAQ9D,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,0BAA0B,CACtC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,EACjB,iBAAiB,EAAE,OAAO,GAC3B,OAAO,CA8BT;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CA0BjF;AAuFD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAE3E"}
@@ -0,0 +1,346 @@
1
+ /**
2
+ * Extension policy decisions (RFC 5280 §4.2, BoringSSL pki verify_certificate_chain.cc).
3
+ *
4
+ * Pure deciders over extension bytes — no path knowledge, no I/O. They answer
5
+ * the two questions path validation asks about every certificate on a built
6
+ * path:
7
+ *
8
+ * 1. May this CRITICAL extension be consumed (or must the certificate be
9
+ * rejected)? — mirrors BoringSSL's `IsHandledCriticalExtension` plus the
10
+ * special cases in `VerifyNoUnconsumedCriticalExtensions`, evaluated for
11
+ * Chrome's TLS-server-auth verification (KeyPurpose::SERVER_AUTH,
12
+ * allow_precertificate=false — SimplePathBuilderDelegate::AcceptPreCertificates
13
+ * returns false and cert_verify_proc_builtin.cc does not override it).
14
+ * 2. Is this certificate's EKU usable for TLS server authentication? —
15
+ * mirrors BoringSSL's `VerifyExtendedKeyUsage` SERVER_AUTH ("Legacy
16
+ * compatible") branch, the policy Chromium 140's built-in verifier runs
17
+ * (cert_verify_proc_builtin.cc passes `bssl::KeyPurpose::SERVER_AUTH` to
18
+ * the CertPathBuilder).
19
+ *
20
+ * RFC 5280 §4.2 mandates the backdrop for (1): "A certificate-using system
21
+ * MUST reject the certificate if it encounters a critical extension it does
22
+ * not recognize or a critical extension that contains information that it
23
+ * cannot process." The recognized set below is EXACTLY BoringSSL's — neither
24
+ * stricter nor looser — so this verifier behaves like Chrome.
25
+ *
26
+ * Extension STRUCTURE parsing (the Extensions SEQUENCE, the critical BOOLEAN,
27
+ * the EKU value itself) lives in cert-extensions.ts; this module only decides
28
+ * about already-decoded records and extension values.
29
+ */
30
+ import { parseOid, readTlv } from "./der.js";
31
+ // ---------------------------------------------------------------------------
32
+ // Named OID constants (RFC 5280 arcs — never write a dotted OID inline; every
33
+ // consumer imports the named constant).
34
+ // ---------------------------------------------------------------------------
35
+ /** id-ce-basicConstraints (RFC 5280 §4.2.1.9). */
36
+ export const BASIC_CONSTRAINTS_OID = "2.5.29.19";
37
+ /** id-ce-keyUsage (RFC 5280 §4.2.1.3). */
38
+ export const KEY_USAGE_OID = "2.5.29.15";
39
+ /** id-ce-subjectAltName (RFC 5280 §4.2.1.6). */
40
+ export const SUBJECT_ALT_NAME_OID = "2.5.29.17";
41
+ /** id-ce-nameConstraints (RFC 5280 §4.2.1.10). */
42
+ export const NAME_CONSTRAINTS_OID = "2.5.29.30";
43
+ /** id-ce-certificatePolicies (RFC 5280 §4.2.1.4). */
44
+ export const CERTIFICATE_POLICIES_OID = "2.5.29.32";
45
+ /** id-ce-inhibitAnyPolicy (RFC 5280 §4.2.1.5). */
46
+ export const INHIBIT_ANY_POLICY_OID = "2.5.29.54";
47
+ /** id-ce-extKeyUsage (RFC 5280 §4.2.1.12). */
48
+ export const EXTENDED_KEY_USAGE_OID = "2.5.29.37";
49
+ /** id-kp-serverAuth (RFC 5280 §4.2.1.12). */
50
+ export const SERVER_AUTH_EKU_OID = "1.3.6.1.5.5.7.3.1";
51
+ /** id-kp-clientAuth (RFC 5280 §4.2.1.12) — NOT sufficient for this client's role. */
52
+ export const CLIENT_AUTH_EKU_OID = "1.3.6.1.5.5.7.3.2";
53
+ /** anyExtendedKeyUsage (RFC 5280 §4.2.1.12: `{ id-ce-extKeyUsage 0 }`). */
54
+ export const ANY_EKU_OID = "2.5.29.37.0";
55
+ /** anyPolicy (RFC 5280 §4.2.1.4: `{ id-ce-certificatePolicies 0 }`). */
56
+ export const ANY_POLICY_OID = "2.5.29.32.0";
57
+ /** id-ce-policyMappings (RFC 5280 §4.2.1.5). */
58
+ export const POLICY_MAPPINGS_OID = "2.5.29.33";
59
+ /** id-ce-policyConstraints (RFC 5280 §4.2.1.5). */
60
+ export const POLICY_CONSTRAINTS_OID = "2.5.29.36";
61
+ /** XCN_OID_APPLICATION_CERT_POLICIES (MSApplicationPolicies), Windows-enrolled. */
62
+ export const MS_APPLICATION_POLICIES_OID = "1.3.6.1.4.1.311.21.10";
63
+ /** id-qt-cps (RFC 5280 §4.2.1.4: CPSuri qualifier). */
64
+ export const CPS_QUALIFIER_OID = "1.3.6.1.5.5.7.2.1";
65
+ /** id-qt-unotice (RFC 5280 §4.2.1.4: userNotice qualifier). */
66
+ export const USER_NOTICE_QUALIFIER_OID = "1.3.6.1.5.5.7.2.2";
67
+ /**
68
+ * The OIDs this verifier HANDLES when a certificate marks them critical.
69
+ *
70
+ * This is BoringSSL's `IsHandledCriticalExtension` (pki/verify_certificate_chain.cc
71
+ * at the revision Chromium 140 pins, boringssl 0a0009998fa180695f3e2071805dc03c9a5f3124)
72
+ * with exactly one deliberate removal — nameConstraints, whose handling is
73
+ * described at {@link NAME_CONSTRAINTS_OID} below. Conditional entries are NOT
74
+ * in this list; they are decided by {@link isCriticalExtensionHandled}:
75
+ *
76
+ * - certificatePolicies: BoringSSL accepts a critical certificatePolicies
77
+ * only if the value parses with `fail_parsing_unknown_qualifier_oids=true`
78
+ * (the quoted RFC 5280 §4.2.1.4 condition in its source) — see
79
+ * {@link criticalCertificatePoliciesProcessable}.
80
+ * - MSApplicationPolicies: ignored as critical only when the certificate
81
+ * also carries an EKU extension (`VerifyNoUnconsumedCriticalExtensions`,
82
+ * per crbug.com/1439638).
83
+ *
84
+ * Per-OID WHY (each entry: what Chrome does with it, and why accepting it
85
+ * critical cannot accept a chain Chrome would reject):
86
+ *
87
+ * - basicConstraints 2.5.29.19: PROCESSED — isCa/pathLenConstraint feed the
88
+ * issuer-authorization and path-length checks.
89
+ * - keyUsage 2.5.29.15: PROCESSED (keyCertSign on issuers). BoringSSL's own
90
+ * comment: "Key Usage is NOT processed for end-entity certificates (this
91
+ * is the responsibility of callers), however it is considered 'handled'
92
+ * here in order to allow being marked as critical."
93
+ * - extKeyUsage 2.5.29.37: PROCESSED — the SERVER_AUTH EKU rule of this
94
+ * subset.
95
+ * - subjectAltName 2.5.29.17: PROCESSED — the hostname check consumes it.
96
+ * - policyMappings 2.5.29.33 / policyConstraints 2.5.29.36 /
97
+ * inhibitAnyPolicy 2.5.29.54: BoringSSL returns true for all three (`if
98
+ * (extension.oid == der::Input(kPolicyMappingsOid)) { return true; }` etc.)
99
+ * and enforces them inside its policy graph. This verifier performs no
100
+ * policy processing (documented limitation); under Chrome's SERVER_AUTH
101
+ * verification the initial policy set is {anyPolicy}, so these constraints
102
+ * cannot make Chrome reject a path this verifier would accept — accepting
103
+ * them critical matches Chrome exactly for the purposes of this verifier.
104
+ * - nameConstraints 2.5.29.30 is deliberately NOT listed: BoringSSL marks it
105
+ * handled BECAUSE IT PROCESSES name constraints (`NameConstraints::Create`
106
+ * + `IsPermittedCert`). This verifier does not process them yet (separate
107
+ * follow-up subset), and RFC 5280 §4.2 requires rejecting an unprocessed
108
+ * critical extension — so a CRITICAL nameConstraints is rejected until the
109
+ * name-constraints subset lands (README documents this stance).
110
+ */
111
+ export const RECOGNIZED_CRITICAL_EXTENSION_OIDS = Object.freeze([
112
+ BASIC_CONSTRAINTS_OID,
113
+ KEY_USAGE_OID,
114
+ EXTENDED_KEY_USAGE_OID,
115
+ SUBJECT_ALT_NAME_OID,
116
+ POLICY_MAPPINGS_OID,
117
+ POLICY_CONSTRAINTS_OID,
118
+ INHIBIT_ANY_POLICY_OID,
119
+ ]);
120
+ /**
121
+ * Decide whether a CRITICAL extension with the given OID and (unwrapped,
122
+ * extnValue-content) `value` may be consumed by this verifier, or must fail
123
+ * with `unsupported-critical-extension`.
124
+ *
125
+ * Mirrors BoringSSL `VerifyNoUnconsumedCriticalExtensions` +
126
+ * `IsHandledCriticalExtension` in SERVER_AUTH mode with
127
+ * allow_precertificate=false:
128
+ *
129
+ * - RCS MLS participant-information OIDs (2.23.146.2.1.4 / 2.23.146.2.1.5)
130
+ * are exempt only for KeyPurpose::RCS_MLS_CLIENT_AUTH — not this purpose —
131
+ * so a critical one is rejected here, exactly as BoringSSL does for server
132
+ * auth.
133
+ * - The CT poison OID (RFC 6962 §3.1, 1.3.6.1.4.1.11129.2.4.3) is exempt
134
+ * only when the delegate accepts pre-certificates
135
+ * (`allow_precertificate && extension.oid == kCtPoisonOid`); Chrome's
136
+ * verifier never does (`SimplePathBuilderDelegate::AcceptPreCertificates()
137
+ * { return false; }`, not overridden by cert_verify_proc_builtin.cc), so a
138
+ * critical poison extension is rejected — the same holds for a critical
139
+ * embedded SCT list (1.3.6.1.4.1.11129.2.4.2), which appears in no
140
+ * exemption branch at all.
141
+ *
142
+ * `certificateHasEku` gates the MSApplicationPolicies special case.
143
+ */
144
+ export function isCriticalExtensionHandled(oid, value, certificateHasEku) {
145
+ if (RECOGNIZED_CRITICAL_EXTENSION_OIDS.includes(oid)) {
146
+ return true;
147
+ }
148
+ // Conditional BoringSSL case 1 — critical certificatePolicies. Its source:
149
+ //
150
+ // "Policy qualifiers are skipped during processing, so if the
151
+ // extension is marked critical need to ensure there weren't any
152
+ // qualifiers other than User Notice / CPS.
153
+ // ...
154
+ // This follows from RFC 5280 section 4.2.1.4:
155
+ // If this extension is critical, the path validation software MUST
156
+ // be able to interpret this extension (including the optional
157
+ // qualifier), or MUST reject the certificate."
158
+ //
159
+ // Decided by parsing the value strictly: an unknown qualifier OID or any
160
+ // structural fault means NOT handled → rejected (the
161
+ // kUnconsumedCriticalExtension outcome).
162
+ if (oid === CERTIFICATE_POLICIES_OID) {
163
+ return criticalCertificatePoliciesProcessable(value);
164
+ }
165
+ // Conditional BoringSSL case 2 — MSApplicationPolicies may be ignored when
166
+ // an EKU extension is also present ("The MSApplicationPolicies extension
167
+ // may be ignored if the extendedKeyUsage extension is also present",
168
+ // crbug.com/1439638); without EKU it stays an unconsumed critical
169
+ // extension.
170
+ if (oid === MS_APPLICATION_POLICIES_OID && certificateHasEku) {
171
+ return true;
172
+ }
173
+ return false;
174
+ }
175
+ /**
176
+ * Whether a critical certificatePolicies value is processable, mirroring
177
+ * BoringSSL `ParseCertificatePoliciesExtensionOids(value,
178
+ * fail_parsing_unknown_qualifier_oids=true, …)` exactly
179
+ * (pki/certificate_policies.cc):
180
+ *
181
+ * - the value is one SEQUENCE covering all its bytes, with at least one
182
+ * element ("The certificatePolicies sequence should have at least 1
183
+ * element" — kPoliciesEmptySequence otherwise);
184
+ * - each PolicyInformation is SEQUENCE { policyIdentifier OID, optional
185
+ * policyQualifiers SEQUENCE (≥ 1 element) }, no trailing data
186
+ * (kPolicyInformationTrailingData otherwise);
187
+ * - each PolicyQualifierInfo is SEQUENCE { policyQualifierId OID, qualifier
188
+ * ANY }, no trailing data (kPolicyQualifierInfoTrailingData), and the
189
+ * qualifier OID must be id-qt-cps or id-qt-unotice
190
+ * (`if (restrict_to_known_qualifiers && qualifier_oid != kCpsPointerId &&
191
+ * qualifier_oid != kUserNoticeId)` → kUnknownPolicyQualifierOid); the
192
+ * qualifier ANY must be present (kMissingQualifier);
193
+ * - no policy OID appears twice ("A certificate policy OID MUST NOT appear
194
+ * more than once in a certificate policies extension" — kPoliciesDuplicateOid).
195
+ *
196
+ * Returns false (never throws) for any malformation: a failed parse makes
197
+ * IsHandledCriticalExtension return false, i.e. the certificate is rejected as
198
+ * carrying an unrecognized critical extension — never a parse error.
199
+ */
200
+ export function criticalCertificatePoliciesProcessable(value) {
201
+ try {
202
+ // certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation.
203
+ const seq = readTlv(value, 0);
204
+ if (seq.tag !== 0x30 || seq.end !== value.length || seq.valueStart >= seq.end) {
205
+ return false;
206
+ }
207
+ const seenPolicyOids = new Set();
208
+ let o = seq.valueStart;
209
+ while (o < seq.end) {
210
+ const policyInformation = readTlv(value, o);
211
+ if (policyInformation.tag !== 0x30 || policyInformation.end > seq.end) {
212
+ return false;
213
+ }
214
+ if (!policyInformationProcessable(value, policyInformation, seenPolicyOids)) {
215
+ return false;
216
+ }
217
+ o = policyInformation.end;
218
+ }
219
+ return true;
220
+ }
221
+ catch {
222
+ // Truncated/garbled DER — readTlv/parseOid throw TlsHandshakeError;
223
+ // the BoringSSL equivalent returns false (a value-parse failure only
224
+ // means "not handled as critical extension", never a crash).
225
+ return false;
226
+ }
227
+ }
228
+ /**
229
+ * One PolicyInformation ::= SEQUENCE { policyIdentifier OID, policyQualifiers
230
+ * SEQUENCE OF PolicyQualifierInfo OPTIONAL }: OID first, no trailing data, and
231
+ * (for the duplicate check — kPoliciesDuplicateOid) a policy OID that has not
232
+ * been seen before. Returns false instead of throwing.
233
+ */
234
+ function policyInformationProcessable(value, policyInformation, seenPolicyOids) {
235
+ let p = policyInformation.valueStart;
236
+ // policyIdentifier CertPolicyId (an OBJECT IDENTIFIER).
237
+ const oidTlv = readTlv(value, p);
238
+ if (oidTlv.tag !== 0x06) {
239
+ return false;
240
+ }
241
+ const policyOid = parseOid(value, oidTlv.valueStart, oidTlv.end);
242
+ p = oidTlv.end;
243
+ if (seenPolicyOids.has(policyOid)) {
244
+ return false;
245
+ }
246
+ seenPolicyOids.add(policyOid);
247
+ // Optional policyQualifiers SEQUENCE SIZE (1..MAX) OF PolicyQualifierInfo.
248
+ if (p < policyInformation.end) {
249
+ const qualifiers = readTlv(value, p);
250
+ p = qualifiers.end;
251
+ if (qualifiers.tag !== 0x30 || qualifiers.valueStart >= qualifiers.end) {
252
+ // An empty qualifiers SEQUENCE fails ("If it is present, the
253
+ // policyQualifiers sequence should have at least 1 element" —
254
+ // kPolicyQualifiersEmptySequence).
255
+ return false;
256
+ }
257
+ if (!policyQualifiersProcessable(value, qualifiers)) {
258
+ return false;
259
+ }
260
+ }
261
+ if (p !== policyInformation.end) {
262
+ // kPolicyInformationTrailingData.
263
+ return false;
264
+ }
265
+ return true;
266
+ }
267
+ /**
268
+ * One policyQualifiers SEQUENCE: every PolicyQualifierInfo must be
269
+ * SEQUENCE { policyQualifierId OID, qualifier ANY } with no trailing data, and
270
+ * the qualifier OID must be id-qt-cps or id-qt-unotice
271
+ * (`if (restrict_to_known_qualifiers && qualifier_oid != kCpsPointerId &&
272
+ * qualifier_oid != kUserNoticeId)` → kUnknownPolicyQualifierOid — restricted
273
+ * mode is always on here, fail_parsing_unknown_qualifier_oids = true;
274
+ * BoringSSL additionally restricts when the policy OID is anyPolicy, which is
275
+ * subsumed). Returns false instead of throwing.
276
+ */
277
+ function policyQualifiersProcessable(value, qualifiers) {
278
+ let q = qualifiers.valueStart;
279
+ while (q < qualifiers.end) {
280
+ const qualifierInfo = readTlv(value, q);
281
+ if (qualifierInfo.tag !== 0x30 || qualifierInfo.end > qualifiers.end) {
282
+ return false;
283
+ }
284
+ let qi = qualifierInfo.valueStart;
285
+ const qualifierOidTlv = readTlv(value, qi);
286
+ if (qualifierOidTlv.tag !== 0x06) {
287
+ return false;
288
+ }
289
+ const qualifierOid = parseOid(value, qualifierOidTlv.valueStart, qualifierOidTlv.end);
290
+ qi = qualifierOidTlv.end;
291
+ if (qualifierOid !== CPS_QUALIFIER_OID && qualifierOid !== USER_NOTICE_QUALIFIER_OID) {
292
+ return false;
293
+ }
294
+ // qualifier ANY DEFINED BY policyQualifierId must be present
295
+ // (kMissingQualifier) — readTlv throws, caught by the caller, if it is
296
+ // truncated.
297
+ const qualifierTlv = readTlv(value, qi);
298
+ qi = qualifierTlv.end;
299
+ if (qi !== qualifierInfo.end) {
300
+ // kPolicyQualifierInfoTrailingData.
301
+ return false;
302
+ }
303
+ q = qualifierInfo.end;
304
+ }
305
+ return q === qualifiers.end;
306
+ }
307
+ /**
308
+ * Whether a parsed EKU OID list makes a certificate usable for TLS server
309
+ * authentication, mirroring BoringSSL `VerifyExtendedKeyUsage` SERVER_AUTH
310
+ * ("Legacy compatible") — the policy Chromium 140 runs
311
+ * (cert_verify_proc_builtin.cc: `bssl::KeyPurpose::SERVER_AUTH`):
312
+ *
313
+ * ```
314
+ * if (required_key_purpose == KeyPurpose::SERVER_AUTH) {
315
+ * // Legacy compatible.
316
+ * if (cert.has_extended_key_usage() && !has_server_auth_eku &&
317
+ * !has_any_eku) {
318
+ * errors->AddError(cert_errors::kEkuLacksServerAuth);
319
+ * }
320
+ * }
321
+ * ```
322
+ *
323
+ * This branch runs for the target certificate AND for every issuer (the
324
+ * enclosing `is_target_cert` / `is_target_cert_issuer` code paths only add
325
+ * WARNINGS in non-strict SERVER_AUTH mode: a missing EKU extension is only a
326
+ * warning — BoringSSL's comment: "At this time (until at least 2023) some
327
+ * intermediates are lacking EKU in the world at large from common CA's, so we
328
+ * allow the noEKU case to permit everything." — and codeSigning /
329
+ * timeStamping / OCSPSigning presence goes through `add_error_if_strict`,
330
+ * i.e. warnings). The deciding error is therefore uniform for every
331
+ * non-anchor certificate on the path:
332
+ *
333
+ * - NO EKU extension → acceptable (accepted; on a leaf only the
334
+ * kEkuNotPresent warning).
335
+ * - EKU present → it must contain id-kp-serverAuth or anyExtendedKeyUsage;
336
+ * anything else (clientAuth-only, codeSigning-only, or the EMPTY SEQUENCE
337
+ * — "present" with zero OIDs) is the kEkuLacksServerAuth error.
338
+ *
339
+ * `ekuOids` is the parsed EKU OID list (dotted); whether the extension is
340
+ * present at all is decided by the caller (absent → acceptable without
341
+ * consulting this function).
342
+ */
343
+ export function serverAuthEkuAcceptable(ekuOids) {
344
+ return ekuOids.includes(SERVER_AUTH_EKU_OID) || ekuOids.includes(ANY_EKU_OID);
345
+ }
346
+ //# sourceMappingURL=extension-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-policy.js","sourceRoot":"","sources":["../../src/certificates/extension-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE7C,8EAA8E;AAC9E,8EAA8E;AAC9E,wCAAwC;AACxC,8EAA8E;AAE9E,kDAAkD;AAClD,MAAM,CA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,CAAC,GAAG,CAAC;QACzB,IAAI,YAAY,KAAK,iBAAiB,IAAI,YAAY,KAAK,yBAAyB,EAAE,CAAC;YACnF,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,6DAA6D;QAC7D,uEAAuE;QACvE,aAAa;QACb,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACxC,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC;QACtB,IAAI,EAAE,KAAK,aAAa,CAAC,GAAG,EAAE,CAAC;YAC3B,oCAAoC;YACpC,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC;IAC1B,CAAC;IACD,OAAO,CAAC,KAAK,UAAU,CAAC,GAAG,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAA0B;IAC9D,OAAO,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Certificate signature-algorithm parsing (RFC 5280 §4.1.1.2, RFC 4055 §3.1,
3
+ * RFC 5758 §3.2, RFC 8410 §3).
4
+ *
5
+ * The handshake used to map the certificate's signature-algorithm OID to a TLS
6
+ * scheme and THROW at parse time for every OID outside four hardcoded entries —
7
+ * so any server whose chain carried sha384WithRSAEncryption, sha512WithRSA
8
+ * Encryption, ecdsa-with-SHA512, Ed25519 or RSA-PSS failed even though chain
9
+ * verification is skipped by default. This module replaces that map with a
10
+ * complete parser of the SignatureAlgorithmIdentifier (OID AND parameters) whose
11
+ * outcome is a {@link CertificateSignatureAlgorithm} union: `supported` carries
12
+ * the TLS scheme, `rejected` carries a policy reason. Parsing NEVER throws for
13
+ * an algorithm we merely do not accept — rejection policy lives in
14
+ * `validateCertificateChain` (Chrome enforces signature-algorithm policy in
15
+ * every mode, not only against a trust store).
16
+ */
17
+ import type { CertificateSignatureAlgorithm } from "@browsercore/contracts";
18
+ export type { CertificateSignatureAlgorithm };
19
+ /**
20
+ * Parse the certificate's SignatureAlgorithmIdentifier into a
21
+ * {@link CertificateSignatureAlgorithm}.
22
+ *
23
+ * `buf[start]` must be the AlgorithmIdentifier SEQUENCE inside the
24
+ * TBSCertificate (RFC 5280 §4.1.2.3 `signature`).
25
+ *
26
+ * Supported mappings (the curve/rsae component of a scheme name is the
27
+ * CONVENTIONAL pairing — see the per-family notes):
28
+ * - RSA PKCS#1 v1.5 (RFC 3279): sha256WithRSAEncryption → rsa_pkcs1_sha256,
29
+ * sha384WithRSAEncryption → rsa_pkcs1_sha384, sha512WithRSAEncryption →
30
+ * rsa_pkcs1_sha512; sha1/md5WithRSAEncryption are rejected ("sha1"/"md5").
31
+ * Parameters, when present, MUST be NULL (absent is tolerated — legacy
32
+ * encoders omitted them; RFC 4055 §3 requires NULL for new certs).
33
+ * - RSA-PSS (RFC 4055 §3.1): see {@link parsePssParameters}. The mapped names
34
+ * are the `rsa_pss_rsae_*` variants because the rsae/pss split only exists
35
+ * for TLS CertificateVerify (where it selects the SIGNATURE KEY's format);
36
+ * certificate signatures are verified with the ISSUER's key from its SPKI,
37
+ * so only the hash matters here.
38
+ * - ECDSA (RFC 3279/RFC 5758): ecdsa-with-SHA256/384/512 →
39
+ * ecdsa_secp256r1_sha256 / ecdsa_secp384r1_sha384 / ecdsa_secp521r1_sha512.
40
+ * The curve in the name is the conventional pairing, not a parsed fact —
41
+ * verification uses the issuer's ACTUAL key with the OID's hash, so an
42
+ * issuer key on any curve verifies. ecdsa-with-SHA1 is rejected ("sha1").
43
+ * NULL parameters are tolerated (RFC 5758 requires absent, but historical
44
+ * encoders add NULL and OpenSSL/Chrome accept it).
45
+ * - Ed25519 (RFC 8410): id-Ed25519 → ed25519; parameters MUST be absent —
46
+ * any parameters element is a rejection ("unknown").
47
+ * - Anything else: rejected ("unknown") carrying the OID. A recognized OID
48
+ * whose parameters do not conform (PKCS#1/ECDSA with non-NULL parameters,
49
+ * Ed25519 with parameters) also lands here: the reason vocabulary models
50
+ * hash policy (sha1/md5) and PSS conformance, and such an encoding maps to
51
+ * no scheme at all.
52
+ */
53
+ export declare function parseSignatureAlgorithm(buf: Uint8Array, start: number): CertificateSignatureAlgorithm;
54
+ //# sourceMappingURL=signature-algorithm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature-algorithm.d.ts","sourceRoot":"","sources":["../../src/certificates/signature-algorithm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,KAAK,EAAE,6BAA6B,EAAmB,MAAM,wBAAwB,CAAC;AAC7F,YAAY,EAAE,6BAA6B,EAAE,CAAC;AAiT9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,6BAA6B,CAgCrG"}