@blamejs/pki 0.6.13 → 0.6.15

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 (114) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +1 -1
  3. package/index.js +1 -1
  4. package/lib/acme.js +59 -815
  5. package/lib/asn1-der.js +7 -245
  6. package/lib/attrcert-sign.js +12 -260
  7. package/lib/attrcert-verify.js +1 -7
  8. package/lib/byte-reader.js +0 -8
  9. package/lib/byte-writer.js +0 -11
  10. package/lib/cbor-det.js +0 -54
  11. package/lib/cmc-build.js +15 -357
  12. package/lib/cmc-verify.js +6 -239
  13. package/lib/cmp-build.js +41 -317
  14. package/lib/cmp-session.js +73 -760
  15. package/lib/cmp-verify.js +32 -488
  16. package/lib/cms-compress.js +3 -32
  17. package/lib/cms-decrypt.js +29 -294
  18. package/lib/cms-encrypt.js +14 -234
  19. package/lib/cms-sign.js +29 -324
  20. package/lib/cms-verify.js +9 -500
  21. package/lib/composite-kem.js +2 -102
  22. package/lib/composite-sig.js +1 -77
  23. package/lib/constants.js +0 -249
  24. package/lib/crl-sign.js +9 -237
  25. package/lib/crl-verify.js +1 -10
  26. package/lib/crmf-sign.js +19 -198
  27. package/lib/crmf-verify.js +1 -12
  28. package/lib/csr-sign.js +3 -34
  29. package/lib/csr-verify.js +1 -12
  30. package/lib/ct.js +28 -253
  31. package/lib/edwards-point.js +10 -44
  32. package/lib/est.js +28 -764
  33. package/lib/framework-error.js +4 -182
  34. package/lib/guard-all.js +1 -58
  35. package/lib/guard-async.js +1 -36
  36. package/lib/guard-bytes.js +6 -650
  37. package/lib/guard-compress.js +5 -102
  38. package/lib/guard-crypto.js +1 -40
  39. package/lib/guard-der.js +2 -93
  40. package/lib/guard-encoding.js +2 -60
  41. package/lib/guard-header.js +1 -36
  42. package/lib/guard-identifier.js +7 -531
  43. package/lib/guard-intrinsic.js +1 -150
  44. package/lib/guard-json.js +10 -73
  45. package/lib/guard-limits.js +1 -77
  46. package/lib/guard-list.js +1 -49
  47. package/lib/guard-name.js +3 -209
  48. package/lib/guard-parsed.js +7 -335
  49. package/lib/guard-range.js +1 -71
  50. package/lib/guard-secret.js +1 -102
  51. package/lib/guard-text.js +1 -64
  52. package/lib/guard-time.js +1 -97
  53. package/lib/hpke.js +3 -105
  54. package/lib/http-digest.js +14 -142
  55. package/lib/http-retry-after.js +1 -47
  56. package/lib/http-transport.js +21 -131
  57. package/lib/inspect.js +30 -284
  58. package/lib/ip-utils.js +6 -47
  59. package/lib/jose.js +7 -142
  60. package/lib/key.js +2 -67
  61. package/lib/lint.js +9 -194
  62. package/lib/merkle.js +1 -27
  63. package/lib/mime.js +9 -82
  64. package/lib/ocsp-request-verify.js +1 -14
  65. package/lib/ocsp-verify.js +1 -82
  66. package/lib/ocsp.js +11 -169
  67. package/lib/oid.js +5 -337
  68. package/lib/path-validate.js +103 -1492
  69. package/lib/pbes2.js +2 -89
  70. package/lib/pkcs12-build.js +31 -379
  71. package/lib/pki-build.js +64 -290
  72. package/lib/rc2.js +2 -18
  73. package/lib/rfc3339.js +4 -27
  74. package/lib/scep.js +59 -233
  75. package/lib/schema-all.js +0 -122
  76. package/lib/schema-attrcert.js +4 -146
  77. package/lib/schema-c509.js +153 -802
  78. package/lib/schema-cmc.js +5 -220
  79. package/lib/schema-cmp.js +2 -223
  80. package/lib/schema-cms.js +13 -427
  81. package/lib/schema-crl.js +5 -68
  82. package/lib/schema-crmf.js +6 -167
  83. package/lib/schema-csr.js +1 -54
  84. package/lib/schema-csrattrs.js +2 -87
  85. package/lib/schema-engine.js +0 -152
  86. package/lib/schema-ocsp.js +0 -117
  87. package/lib/schema-pkcs12.js +2 -93
  88. package/lib/schema-pkcs8.js +3 -35
  89. package/lib/schema-pkix.js +24 -655
  90. package/lib/schema-smime.js +0 -54
  91. package/lib/schema-tsp.js +3 -99
  92. package/lib/schema-x509.js +4 -63
  93. package/lib/shbs.js +11 -95
  94. package/lib/sign-scheme.js +2 -97
  95. package/lib/sigstore.js +9 -169
  96. package/lib/sleep.js +2 -8
  97. package/lib/smime.js +15 -408
  98. package/lib/tls-cert-compress.js +0 -62
  99. package/lib/trust.js +19 -185
  100. package/lib/tsp-sign.js +16 -270
  101. package/lib/validator-all.js +1 -30
  102. package/lib/validator-attcert.js +2 -46
  103. package/lib/validator-cose.js +2 -153
  104. package/lib/validator-keydesc.js +1 -37
  105. package/lib/validator-sig.js +1 -46
  106. package/lib/validator-tls.js +1 -88
  107. package/lib/validator-tpm.js +19 -122
  108. package/lib/verify-seam.js +1 -24
  109. package/lib/webauthn-mds.js +3 -400
  110. package/lib/webauthn.js +12 -833
  111. package/lib/webcrypto.js +5 -485
  112. package/lib/x509-sign.js +4 -108
  113. package/package.json +1 -1
  114. package/sbom.cdx.json +6 -6
@@ -33,17 +33,15 @@ var _charCodeAt = intrinsic.uncurry(String.prototype.charCodeAt);
33
33
  var _String = intrinsic.String;
34
34
  var _defineProperty = intrinsic.defineProperty;
35
35
 
36
- // The frozen shape of every error code: a `domain/reason` string -- one or more lowercase alphanumerics or
37
- // dashes, a single "/", then one or more of the same. Decided by character scan (no regex).
38
36
  function _isCodeShape(c) {
39
37
  var n = c.length, i, ch, slash = -1;
40
- if (n < 3) return false; // shortest is "a/b"
38
+ if (n < 3) return false;
41
39
  for (i = 0; i < n; i += 1) {
42
40
  ch = _charCodeAt(c, i);
43
- if (ch === 47) { if (slash !== -1) return false; slash = i; } // "/" -- at most one
44
- else if (!((ch >= 97 && ch <= 122) || (ch >= 48 && ch <= 57) || ch === 45)) return false; // a-z 0-9 "-"
41
+ if (ch === 47) { if (slash !== -1) return false; slash = i; }
42
+ else if (!((ch >= 97 && ch <= 122) || (ch >= 48 && ch <= 57) || ch === 45)) return false;
45
43
  }
46
- return slash > 0 && slash < n - 1; // one slash, both sides non-empty
44
+ return slash > 0 && slash < n - 1;
47
45
  }
48
46
 
49
47
  /**
@@ -135,251 +133,75 @@ function defineClass(name, opts) {
135
133
  return GeneratedError;
136
134
  }
137
135
 
138
- // ---- Per-domain error classes ----
139
136
 
140
- // ConstantsError -- a bad scale argument to C.TIME.* / C.BYTES.* (an
141
- // authoring bug caught at config time).
142
137
  var ConstantsError = defineClass("ConstantsError");
143
138
 
144
- // Asn1Error -- malformed / non-canonical DER: truncated TLV, indefinite
145
- // length, non-minimal length or integer, leftover trailing bytes, depth
146
- // or size cap exceeded. DER is a canonical encoding, so anything the
147
- // decoder rejects is permanently invalid. withCause threads a raw byte-view
148
- // failure (a detached backing ArrayBuffer) as the cause rather than discarding it.
149
139
  var Asn1Error = defineClass("Asn1Error", { withCause: true });
150
140
 
151
- // CborError -- malformed / non-deterministic CBOR: a reserved or indefinite
152
- // additional-info value, a stray break, a non-minimal ("preferred") argument,
153
- // a non-shortest or non-canonical-NaN float, an out-of-order or duplicate map
154
- // key, a non-minimal / oversized bignum, bad UTF-8, a wrong-typed tag body,
155
- // leftover trailing bytes, or a depth / size cap exceeded. RFC 8949 core-
156
- // deterministic encoding (sec. 4.2.1) is canonical, so anything the decoder
157
- // rejects is permanently invalid. withCause threads a raw byte-view failure
158
- // (a detached backing ArrayBuffer) as the cause rather than discarding it.
159
141
  var CborError = defineClass("CborError", { withCause: true });
160
142
 
161
- // OidError -- a malformed object-identifier: fewer than two arcs, a first
162
- // arc outside 0..2, a second arc >= 40 under arcs 0/1, or a non-minimal
163
- // base-128 sub-identifier. withCause threads a raw byte-view failure (a detached
164
- // backing ArrayBuffer at fromDER) as the cause rather than discarding it.
165
143
  var OidError = defineClass("OidError", { withCause: true });
166
144
 
167
- // PemError -- a malformed PEM envelope: missing / mismatched BEGIN/END
168
- // markers, a bad label, or non-base64 body.
169
145
  var PemError = defineClass("PemError", { withCause: true });
170
146
 
171
- // CertificateError -- a byte sequence that is not a well-formed X.509
172
- // certificate (wrong outer structure, unparseable field, unsupported
173
- // version).
174
147
  var CertificateError = defineClass("CertificateError", { withCause: true });
175
148
 
176
- // CrlError -- a byte sequence that is not a well-formed X.509 CRL
177
- // (CertificateList / TBSCertList -- RFC 5280 sec. 5).
178
149
  var CrlError = defineClass("CrlError", { withCause: true });
179
150
 
180
- // SchemaError -- the schema-family orchestrator's own errors (input that matches
181
- // no registered format / does not decode). (code, message) shape like the rest.
182
151
  var SchemaError = defineClass("SchemaError", { withCause: true });
183
152
 
184
- // CsrError -- a byte sequence that is not a well-formed PKCS#10 CertificationRequest
185
- // (RFC 2986).
186
153
  var CsrError = defineClass("CsrError", { withCause: true });
187
154
 
188
- // Pkcs8Error -- a byte sequence that is not a well-formed PKCS#8 PrivateKeyInfo /
189
- // OneAsymmetricKey or EncryptedPrivateKeyInfo (RFC 5208 sec. 5, RFC 5958 sec. 2/sec. 3).
190
155
  var Pkcs8Error = defineClass("Pkcs8Error", { withCause: true });
191
156
 
192
- // CmsError -- a byte sequence that is not a well-formed CMS ContentInfo /
193
- // SignedData (RFC 5652). Carries the underlying leaf fault as `.cause`.
194
157
  var CmsError = defineClass("CmsError", { withCause: true });
195
158
 
196
- // OcspError -- a byte sequence that is not a well-formed OCSP request or response
197
- // (OCSPRequest / OCSPResponse -- RFC 6960 sec. 4). Carries the leaf fault as `.cause`.
198
159
  var OcspError = defineClass("OcspError", { withCause: true });
199
160
 
200
- // TspError -- a byte sequence that is not a well-formed RFC 3161 timestamp token,
201
- // TSTInfo, or TimeStampResp. Carries the underlying leaf fault as `.cause`.
202
161
  var TspError = defineClass("TspError", { withCause: true });
203
162
 
204
- // AttrCertError -- a byte sequence that is not a well-formed X.509 Attribute
205
- // Certificate (AttributeCertificate / AttributeCertificateInfo -- RFC 5755 sec. 4),
206
- // or a recognized-and-deferred legacy AttributeCertificateV1. Carries the
207
- // underlying leaf fault as `.cause`.
208
163
  var AttrCertError = defineClass("AttrCertError", { withCause: true });
209
164
 
210
- // CrmfError -- a byte sequence that is not a well-formed RFC 4211 CertReqMessages
211
- // / CertReqMsg / CertRequest / CertTemplate. Carries the underlying leaf fault as
212
- // `.cause`.
213
165
  var CrmfError = defineClass("CrmfError", { withCause: true });
214
166
 
215
- // Pkcs12Error -- a byte sequence that is not a well-formed RFC 7292 PFX
216
- // (AuthenticatedSafe / SafeContents / SafeBag), or a PFX violating a sec. 4
217
- // coherence rule (version, integrity mode, bag dispatch, MacData). Carries
218
- // the underlying leaf fault as `.cause`.
219
167
  var Pkcs12Error = defineClass("Pkcs12Error", { withCause: true });
220
168
 
221
- // CmpError -- a byte sequence that is not a well-formed RFC 9810 PKIMessage
222
- // (PKIHeader / PKIBody / protection / extraCerts), or one violating a sec. 5
223
- // coherence rule (protection<=>protectionAlg, certConf-hashAlg<=>pvno). Carries
224
- // the underlying leaf fault as `.cause`.
225
169
  var CmpError = defineClass("CmpError", { withCause: true });
226
170
 
227
- // PathError -- a certification path that fails RFC 5280 sec. 6 validation, or a
228
- // malformed input handed to the validator (an extension value that does not
229
- // decode, an empty path, an unsupported signature algorithm). Carries the
230
- // per-check reason in `.code` (`path/*`) and the underlying leaf fault as
231
- // `.cause`.
232
171
  var PathError = defineClass("PathError", { withCause: true });
233
172
 
234
- // SmimeError -- a byte sequence that is not a well-formed RFC 5035 ESS
235
- // signing-certificate attribute (SigningCertificate / SigningCertificateV2 /
236
- // ESSCertID(v2) / IssuerSerial) or RFC 8551 SMIMECapabilities, or a CMS
237
- // attribute violating a sec. 2.5 coherence rule (single-AttributeValue, certs
238
- // non-empty, non-canonical DEFAULT hashAlgorithm). Carries the underlying leaf
239
- // fault (e.g. the inner asn1/* decode error) as `.cause`.
240
173
  var SmimeError = defineClass("SmimeError", { withCause: true });
241
174
 
242
- // CtError -- a byte sequence that is not a well-formed RFC 6962 Certificate
243
- // Transparency SCT list: a malformed inner DER OCTET-STRING wrap, or a TLS
244
- // presentation-language framing violation (a lying vector length, a field read
245
- // past its bound, a truncated element). An SCT whose version this parser does
246
- // not define is NOT an error -- RFC 6962 sec. 3.3 makes unknown versions skippable,
247
- // so they are preserved opaque. Carries the underlying leaf fault (e.g. the
248
- // inner `asn1/*` decode error) as `.cause`.
249
175
  var CtError = defineClass("CtError", { withCause: true });
250
176
 
251
- // ScepError -- a byte sequence that is not a well-formed SCEP pkiMessage (RFC 8894): a
252
- // malformed CMS layering, a missing or mis-encoded transaction attribute, an unknown
253
- // messageType / pkiStatus / failInfo enumerant, a nonce mismatch, or a weak-algorithm
254
- // profile violation. Fail-closed: a malformed or off-profile message is a typed verdict.
255
177
  var ScepError = defineClass("ScepError", { withCause: true });
256
178
 
257
- // TlsError -- a byte sequence that is not a well-formed TLS handshake structure:
258
- // an RFC 8879 CompressedCertificate whose framing is violated (a lying vector
259
- // length, a field read past its bound, an empty compressed message), whose
260
- // compression algorithm this toolkit does not implement or the caller did not
261
- // offer, whose declared uncompressed length disagrees with what the stream
262
- // actually produces, or whose compressed body is a decompression bomb. Carries
263
- // the underlying leaf fault (the decompressor's own error) as `.cause`.
264
179
  var TlsError = defineClass("TlsError", { withCause: true });
265
180
 
266
- // C509Error -- a CBOR byte sequence that is not a well-formed C509 certificate
267
- // (draft-ietf-cose-cbor-encoded-cert): a root that is not the 11-element array, a
268
- // c509CertificateType outside {2,3}, a field encoded against its ~biguint/~time/~oid
269
- // contract, an algorithm/attribute/extension int with no registry row, or a type-3
270
- // cert that does not invert byte-for-byte to its original DER. Carries the underlying
271
- // leaf fault (the inner `cbor/*` or `asn1/*` decode error) as `.cause`.
272
181
  var C509Error = defineClass("C509Error", { withCause: true });
273
182
 
274
- // MerkleError -- a malformed input to the RFC 6962 / RFC 9162 Merkle-tree
275
- // proof-verification core: a tree coordinate that is not a non-negative integer
276
- // (or a Number above 2^53 where an exact BigInt is required), a leafIndex
277
- // outside its tree, an inverted consistency window, a hash chunk that is not 32
278
- // bytes, or a proof whose node count does not match the tree geometry. The final
279
- // root comparison is a constant-time boolean (root matched / did not), NOT an
280
- // error -- only a structurally malformed input throws. Carries an underlying
281
- // leaf fault as `.cause`.
282
183
  var MerkleError = defineClass("MerkleError", { withCause: true });
283
184
 
284
- // CsrattrsError -- a byte sequence that is not a well-formed RFC 8951 sec. 3.5
285
- // CsrAttrs (SEQUENCE OF AttrOrOID), or one violating an RFC 9908 semantic rule
286
- // (a repeated id-ExtensionReq, an extension-request values SET that is not
287
- // exactly one Extensions, a template version other than v1(0), a mixed
288
- // extension-request template). Carries the underlying leaf fault as `.cause`.
289
185
  var CsrattrsError = defineClass("CsrattrsError", { withCause: true });
290
186
 
291
- // EstError -- an RFC 7030 / 8951 / 9908 Enrollment-over-Secure-Transport
292
- // protocol fault: a payload that fails a per-operation validator (a non-certs-
293
- // only /cacerts response, a serverkeygen recipient-arm mismatch), a transfer /
294
- // multipart framing violation, or an HTTP response the classifier rejects.
295
- // Carries the underlying leaf / delegated fault (e.g. a cms/* or asn1/*) as
296
- // `.cause`.
297
187
  var EstError = defineClass("EstError", { withCause: true });
298
188
 
299
- // CmcError -- an RFC 5272 / 6402 Certificate Management over CMS message-layer
300
- // fault: a PKIData / PKIResponse whose structure, body-part identity, control
301
- // placement or status encoding is malformed, a control this side must act on
302
- // that cannot be decoded, or an exchange binding (transactionId / recipientNonce)
303
- // that does not match the request it answers. Distinct from EstError because the
304
- // CMC layer is the MESSAGE and EST is the TRANSPORT that carried it: an operator
305
- // needs to know whether the CA's answer was unreadable or the HTTP hop failed.
306
- // Carries the underlying cms/* or asn1/* leaf fault as `.cause`.
307
189
  var CmcError = defineClass("CmcError", { withCause: true });
308
190
 
309
- // TransportError -- a fault from the shared node:https transport (pki.transport):
310
- // a non-https / unparseable request URL, a missing trust anchor, a TLS handshake /
311
- // server-authentication failure, a negotiated protocol below the floor, a response
312
- // over the size cap, or a connect / read timeout. A protocol client (est / acme /
313
- // cmp) may parameterize the transport with its OWN error factory + code prefix so
314
- // the same choke point surfaces domain codes; this is the default identity when the
315
- // transport is used directly. Carries the underlying socket / TLS fault as `.cause`.
316
191
  var TransportError = defineClass("TransportError", { withCause: true });
317
192
 
318
- // JoseError -- a JOSE (RFC 7515 JWS / RFC 7518 JWA / RFC 7638 thumbprint)
319
- // fault: a non-canonical base64url field, a duplicate JSON member, a
320
- // bounds violation, a header that fails its profile (alg/nonce/url/jwk-kid),
321
- // an unknown or MAC algorithm on the outer profile, a signature of the wrong
322
- // length for its alg, or a verify failure. Carries the underlying leaf fault
323
- // (a webcrypto / asn1 error) as `.cause`.
324
193
  var JoseError = defineClass("JoseError", { withCause: true });
325
194
 
326
- // AcmeError -- an RFC 8555 / 8737 / 8738 / 9773 ACME message-layer fault: a
327
- // resource object that fails its spec (bad status enum, a missing
328
- // conditionally-required field, an immutable field mutated), an illegal state
329
- // transition, an identifier/token/nonce that fails validation, a CSR whose
330
- // identifiers or key do not match the order, or a renewal window inversion.
331
- // Carries the delegated jose/* or a DER leaf fault as `.cause`.
332
195
  var AcmeError = defineClass("AcmeError", { withCause: true });
333
196
 
334
- // TrustError -- a Mozilla/NSS certdata.txt or CCADB CSV root-store input that
335
- // fails ingestion: a malformed or oversized object block, a bad \ooo octal
336
- // escape, an unrecognized CK_TRUST value, a certificate/trust-object pairing
337
- // disagreement (metadata must never attach to the wrong root), an undecodable
338
- // distrust-after time, a CSV framing / required-column violation, a CKA_VALUE
339
- // or PEM cell that is not a well-formed certificate, or a purpose the entry is
340
- // not a trusted delegator for. Carries the underlying leaf fault (an x509/* or
341
- // asn1/* error) as `.cause`.
342
197
  var TrustError = defineClass("TrustError", { withCause: true });
343
198
  var ShbsError = defineClass("ShbsError", { withCause: true });
344
199
  var HpkeError = defineClass("HpkeError", { withCause: true });
345
- // KemError -- a malformed composite ML-KEM key or ciphertext, or an unsupported
346
- // composite algorithm (draft-ietf-lamps-pq-composite-kem). Raised by pki.kem.
347
200
  var KemError = defineClass("KemError", { withCause: true });
348
- // SigstoreError -- a Sigstore bundle (npm --provenance artifact) that is not a
349
- // well-formed / verifiable keyless signature: a malformed or oversize JSON
350
- // bundle, an unknown media type or content arm, a DSSE envelope missing a
351
- // required field or whose signature does not verify under the Fulcio leaf key, a
352
- // Rekor inclusion proof that does not reconstruct the signed tree root, an
353
- // unsigned/attacker-supplied root, an entry that does not bind this signature, a
354
- // Fulcio identity that fails the caller policy, or a payload that is not the
355
- // expected in-toto Statement. Carries the underlying leaf fault (an x509/*,
356
- // merkle/*, or asn1/* error) as `.cause`.
357
201
  var SigstoreError = defineClass("SigstoreError", { withCause: true });
358
- // InspectError -- a bad input to the human-readable inspector (pki.inspect): a
359
- // value that is neither a parsed structure, DER Buffer, nor PEM string, or a PEM
360
- // whose label does not decode. Rendering itself is best-effort and never throws on
361
- // a malformed field -- an undecodable extension falls back to a hex dump.
362
202
  var InspectError = defineClass("InspectError", { withCause: true });
363
- // WebauthnError -- a malformed or unverifiable WebAuthn attestation (pki.webauthn):
364
- // a non-well-formed attestation object / COSE key, an authenticatorData that fails
365
- // its bounded layout, an attestation-statement signature that does not verify, or a
366
- // trust path that does not reach the caller's anchor. Fail-closed, typed reason.
367
203
  var WebauthnError = defineClass("WebauthnError", { withCause: true });
368
- // LintError -- CONFIG-time misuse of the certificate linter (pki.lint) ONLY: an
369
- // unknown profile name, an out-of-range severity threshold, or an input that is
370
- // neither a parsed structure, DER Buffer, nor PEM string. This is the lint engine's
371
- // SOLE throw path: unlike every other toolkit entry, the lint DATA path never throws
372
- // on malformed input -- a linter surveys a corpus that includes malformed members,
373
- // so hostile bytes surface a `fatal` finding (lint/unparseable) and return a report.
374
204
  var LintError = defineClass("LintError", { withCause: true });
375
- // KeyError -- the pki.key key-material lifecycle domain: a bad export/import
376
- // input (not a CryptoKey / DER / PEM), an unsupported key or PBES2 algorithm, a
377
- // malformed EncryptedPrivateKeyInfo / PBES2 parameter set, an attacker-controlled
378
- // PBKDF2 salt or iteration count over its cap, a version<=>publicKey mismatch on a
379
- // produced OneAsymmetricKey, or a failed PBES2 decryption. A MAC-less PBES2-CBC
380
- // decrypt collapses every post-derivation failure (wrong password, valid pad but
381
- // not a PrivateKeyInfo) into ONE uniform key/decrypt-failed so it is not a padding
382
- // oracle; the structural pre-derivation faults stay distinct and typed.
383
205
  var KeyError = defineClass("KeyError", { withCause: true });
384
206
 
385
207
  module.exports = {
package/lib/guard-all.js CHANGED
@@ -1,55 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // Copyright (c) blamejs contributors
3
3
  "use strict";
4
- //
5
- // @internal -- no operator-facing namespace. This is lib composition only; the
6
- // documented surface is the primitives whose boundaries compose these guards.
7
- //
8
- // guard-all -- the guard-family orchestrator (schema-all's role for the guard
9
- // family). It assembles the per-shape fail-closed guards into one namespaced
10
- // surface every input boundary composes, so a boundary depends on the family
11
- // itself, with no guard re-implemented inline:
12
- //
13
- // guard.bytes.view / .source -- untrusted byte-source -> Buffer re-view
14
- // (detached-buffer fail-open defense)
15
- // guard.text.decode -- byte-source -> string, cap before copy
16
- // (parser-DoS string-allocation defense)
17
- // guard.limits.cap / .depthCap -- config-time resource-cap validation
18
- // (recursion / allocation DoS defense)
19
- // guard.crypto.constantTimeEqual -- length-checked constant-time compare
20
- // (timing side-channel defense)
21
- // guard.range.int / .uint31 / .positiveInt31
22
- // -- bound a decoded integer before narrowing
23
- // to Number (silent-narrowing defense)
24
- // guard.time.assertValid / .within -- validate a Date-instant before a temporal
25
- // comparison (NaN-Date fail-open defense)
26
- // guard.name.dnEqual / .rdnEqual / .assertNoControlBytes / .assertPrintableIa5
27
- // -- canonical DN identity + name-string integrity
28
- // guard.name.escapeControlBytes / .escapeDnValue
29
- // -- render-side name safety: control-byte + RFC 4514 escaping
30
- // (CVE-2009-2408 truncation / identity defense)
31
- // guard.encoding.base64url / .base64 / .hex
32
- // -- strict textual-encoding decode, canonical
33
- // + capped (encoding-malleability defense)
34
- // guard.identifier.assertCanonicalOid
35
- // -- canonical dotted-decimal OID string form
36
- // (canonicalization-divergence defense)
37
- // guard.compress.bounded -- decompress an untrusted stream under a hard
38
- // output cap, whole-input (decompression-bomb +
39
- // trailing-frame malleability defense)
40
- // guard.header.assertField -- emitted MIME/RFC 5322 header field name +
41
- // value integrity (CR/LF/NUL header-injection
42
- // defense, CWE-93)
43
- // guard.parsed.accept -- a CLAIMED-parsed structure carries every
44
- // field the consuming code dereferences
45
- // (type confusion / unverified provenance,
46
- // CWE-843 / CWE-345)
47
- //
48
- // Each shape is enforced by a codebase-patterns detector: the characteristic
49
- // token of a guard (the Buffer.from(x.buffer, byteOffset) re-view, the
50
- // timingSafeEqual call, the MAX_DECODE_DEPTH_CEILING check) must appear only in
51
- // its guard module, so a new boundary cannot re-inline the shape and forget the
52
- // defense.
4
+ // @internal
53
5
 
54
6
  var _freeze = require("./guard-intrinsic").freeze;
55
7
  var bytes = require("./guard-bytes");
@@ -69,16 +21,7 @@ var compress = require("./guard-compress");
69
21
  var secret = require("./guard-secret");
70
22
  var parsed = require("./guard-parsed");
71
23
  var async_ = require("./guard-async");
72
- // guard-intrinsic is deliberately NOT re-exported here. Re-exporting it gave taking the captures a
73
- // second spelling, and the check that holds a module to the discipline could then be satisfied
74
- // around: a module reached them as `guard.intrinsic.<x>` and never entered scope, so its remaining
75
- // live reads were never named. With one spelling, a module's own require IS the fact, and the check
76
- // reads it off the loaded module graph rather than guessing at the text.
77
24
 
78
- // Frozen, like every module it gathers. A boundary reaches its guard as `guard.<family>.<fn>(...)`
79
- // at the call, and the registry hands every module this same object, so one property assignment
80
- // would replace a fail-closed check everywhere at once -- which is the substitution the family
81
- // exists to refuse. Nothing writes to it after load.
82
25
  module.exports = _freeze({
83
26
  bytes: bytes,
84
27
  text: text,
@@ -2,50 +2,15 @@
2
2
  // Copyright (c) blamejs contributors
3
3
  "use strict";
4
4
 
5
- // The two settle operations, taken at load and uncurried so the call sites read no property of
6
- // them. These are how a synchronous fault becomes the rejection this guard promises, so a replaced
7
- // `reject` returning a resolved promise turns a refusal into a pass at the one place the exit shape
8
- // is decided. See guard-intrinsic for the whole captured set.
9
5
  var _intrinsic = require("./guard-intrinsic");
10
6
  var _resolve = _intrinsic.uncurry(_intrinsic.promiseResolve);
11
7
  var _reject = _intrinsic.uncurry(_intrinsic.promiseReject);
12
8
  var _Promise = Promise;
13
- //
14
- // @internal -- no operator-facing namespace. The documented surface is every verb whose
15
- // @signature says `-> Promise<...>`; this is how each of them refuses.
16
- //
17
- // guard-async -- a verb documented as Promise-returning refuses by REJECTING, never by throwing.
18
- //
19
- // The failure is invisible at the call site, which is what makes it worth a choke point. An operator
20
- // reads `-> Promise<...>` in the reference and writes the documented shape:
21
- //
22
- // pki.acme.newOrder(opts).catch(handleIt);
23
- //
24
- // A validation that runs before the promise is created throws straight past that `.catch`, so a
25
- // misspelled option or a malformed input becomes an uncaught exception in code that already handles
26
- // errors -- and nothing in the shape of the call tells the caller which verbs do that. Eleven verbs
27
- // across five modules had it (pki.cms.verify / sign / countersign, pki.ocsp.sign, pki.tsp.sign and
28
- // six pki.acme verbs), each having grown the same way: a cheap synchronous check added at the top of
29
- // a function that returns a promise further down.
30
- //
31
- // What this does not change is when the work happens. The body still runs synchronously, because
32
- // several of these verbs must resolve a caller's mutable options object before any turn passes --
33
- // reading a key, a nonce, or a request's bytes a turn later is a different value than the one that
34
- // was checked. Only the exit changes: a fault leaves as a rejection instead of a throw.
35
- //
9
+ // @internal
36
10
  // @enforced-by behavioral -- the rule has no rename-proof code shape (it is the ABSENCE of a wrapper
37
- // around a synchronous prefix, which no lexical pattern can see). The guard is the derived test
38
- // test/layer-0-primitives/promise-contract.test.js, which reads every `-> Promise<` @signature out
39
- // of lib/ and calls each verb to prove the refusal arrives as a rejection. A new verb is in
40
- // scope the day it is documented, so no list here can go stale.
41
- // Both taken at load. These are how a synchronous fault becomes the rejection this guard promises,
42
- // so a replaced `reject` returning a resolved promise turns a refusal into a pass at the one place
43
- // the exit shape is decided. See guard-intrinsic for the whole captured set.
44
11
  function deferred(body) {
45
12
  try { return _resolve(_Promise, body()); }
46
13
  catch (e) { return _reject(_Promise, e); }
47
14
  }
48
15
 
49
- // Frozen for the reason the family header gives: a boundary reads its guard off this object at the
50
- // call, so a writable export would let a caller replace the check rather than pass it.
51
16
  module.exports = _intrinsic.freeze({ deferred: deferred });