@blamejs/blamejs-shop 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/returns.js CHANGED
@@ -429,6 +429,16 @@ function create(opts) {
429
429
  return await _hydrate(r.rows[0] || null);
430
430
  },
431
431
 
432
+ // The moderation events legal from a given status, as {on, to} —
433
+ // drives the action buttons on the operator return-detail page. A
434
+ // terminal status returns []. Synchronous (pure lookup over the
435
+ // transition table). `on` is the API method name (approve / reject /
436
+ // markReceived / refund).
437
+ transitionsFrom: function (status) {
438
+ var edges = TRANSITIONS[status] || {};
439
+ return Object.keys(edges).map(function (on) { return { on: on, to: edges[on] }; });
440
+ },
441
+
432
442
  byCode: async function (rmaCode) {
433
443
  var canonical = _canonicalCode(rmaCode);
434
444
  var r = await query(
@@ -3,8 +3,8 @@
3
3
  "_about": "blamejs.shop vendors a single framework — blamejs — which itself bundles every server-side crypto/identity dependency. The transitive packages blamejs ships are surfaced in its own MANIFEST.json at lib/vendor/blamejs/lib/vendor/MANIFEST.json — Trivy / Grype rely on that nested data for CVE attribution.",
4
4
  "packages": {
5
5
  "blamejs": {
6
- "version": "0.12.50",
7
- "tag": "v0.12.50",
6
+ "version": "0.12.51",
7
+ "tag": "v0.12.51",
8
8
  "license": "Apache-2.0",
9
9
  "author": "blamejs contributors",
10
10
  "source": "https://github.com/blamejs/blamejs",
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
8
8
 
9
9
  ## v0.12.x
10
10
 
11
+ - v0.12.51 (2026-05-25) — **`b.network.dns.dane.matchCertificate` — DANE / TLSA certificate matching (RFC 6698 / 7671).** Pin a service's certificate through DNS instead of a public CA. matchCertificate checks a server certificate against a set of TLSA records: the selected data — the full certificate (selector 0) or its subjectPublicKeyInfo (selector 1) — is hashed per the matching type (exact / SHA-256 / SHA-512) and compared in constant time to the record's association data. For a DANE-EE (usage 3) record a match is self-authenticating — the TLSA pins the key, so no public-CA path is needed (the common SMTP-DANE case, RFC 7672); for the PKIX usages a match is reported as necessary-but-not-sufficient so the caller still runs PKIX. This is the payoff of the DNSSEC verifier: verify the TLSA RRset with b.network.dns.dnssec, then match the certificate. Verified against a live DNSSEC-signed TLSA record and the matching server certificate. **Added:** *`b.network.dns.dane.matchCertificate(opts)`* — Matches a leaf certificate (and optional `chain`) against a TLSA RRset (`{ usage, selector, matchingType, data }`). Selector 0 hashes the full certificate DER, selector 1 the subjectPublicKeyInfo; matching type 0 is an exact comparison, 1 SHA-256, 2 SHA-512 (SHA-1 and any other type are refused, not guessed). End-entity usages (PKIX-EE 1, DANE-EE 3) match the leaf; trust-anchor usages (PKIX-TA 0, DANE-TA 2) match the leaf or any supplied chain certificate. Returns `{ ok, matched, daneAuthenticated, trustAnchorMatch, pkixRequired, matchedCertIndex }` — `daneAuthenticated` is true only for a DANE-EE match (the key is pinned, no CA needed); `pkixRequired` flags the PKIX usages. Throws `dane/no-match` when nothing matches, and refuses unknown usage / selector / matching values and unparseable certificates. Verify the TLSA RRset with `b.network.dns.dnssec` first — an unauthenticated TLSA record proves nothing.
12
+
11
13
  - v0.12.50 (2026-05-25) — **`b.network.dns.dnssec.verifyChain` — validate a DNSSEC delegation chain to a pinned root anchor.** Completes local DNSSEC verification: validate a full delegation chain from the root down to a zone against a pinned trust anchor (RFC 4035 §5), instead of trusting any single resolver. For each link, the zone's DNSKEY RRset must be self-signed by one of its keys, and that key must be vouched for either by a pinned anchor (at the root) or by a DS record served + signed by the already-trusted parent — so trust flows root → TLD → zone with no gap. The IANA root KSKs (KSK-2017 tag 20326, KSK-2024 tag 38696) ship as the default anchors; override with opts.trustAnchors for a private root. verifyChain returns the leaf zone's trusted DNSKEY set, which you then hand to verifyRrset / verifyDenial for the actual answer. Composes verifyRrset + verifyDs + the key tag; verified end-to-end against a live root→org chain. **Added:** *`b.network.dns.dnssec.verifyChain(opts)`* — Walks an ordered, root-first list of `links` ({ zone, dnskeys, dnskeyRrsig, dsRdatas?, dsRrsig? }). At each link it verifies the DNSKEY RRset's self-signature (composing `verifyRrset`), then establishes trust in the signing key: at the root by matching a pinned anchor's DS digest (`verifyDs`), at every delegation by verifying the parent-served DS RRset's signature with the already-trusted parent key and confirming the signing KSK matches one of those DS records. Returns `{ ok, zone, keys, path }` with the leaf zone's trusted DNSKEY set. Refuses a root key that matches no anchor (`dnssec/chain-anchor-mismatch`), a KSK that matches no parent DS (`dnssec/chain-ds-mismatch`), and a missing parent key (`dnssec/chain-no-parent-key`). The default `DEFAULT_ROOT_ANCHORS` are the published IANA root KSK DS records; `opts.trustAnchors` overrides them for a private or test root.
12
14
 
13
15
  - v0.12.49 (2026-05-25) — **`b.network.dns.dnssec.verifyDenial` — NSEC / NSEC3 denial-of-existence.** Prove a DNS name does not exist, or has no records of a given type, from the signed NSEC (RFC 4034 §4) or NSEC3 (RFC 5155) records a server returns. This is the other half of local DNSSEC verification: verifyRrset proves a positive answer, verifyDenial proves a negative — so a resolver client can confirm an NXDOMAIN / NODATA itself instead of trusting the upstream resolver. NSEC3 proofs run the closest-encloser / next-closer / covering-range logic over iterated-SHA-1 hashes, with the iteration count capped (default 500) to bound the work an attacker can force, and an Opt-Out NXDOMAIN refused unless explicitly accepted (opt-out only proves 'no signed records', not non-existence). The companion b.network.dns.dnssec.nsec3Hash computes the RFC 5155 §5 hash directly. NSEC verifyRrset support is also enabled: per RFC 6840 §5.1 the NSEC Next Domain Name is not downcased, so its RDATA is verbatim-canonical. **Added:** *`b.network.dns.dnssec.verifyDenial(opts)`* — Proves NXDOMAIN or NODATA from already-verified NSEC / NSEC3 records (supply one of `opts.nsec3` or `opts.nsec`). Like `verifyDs`, it checks the denial RELATION — closest-encloser matching, covering ranges, and type-bitmap absence — not the record signatures, which the caller verifies with `verifyRrset` first. NSEC3 supports name-error proofs (matching closest encloser + covered next-closer + covered wildcard), NODATA (matching record with the type and CNAME absent from the bitmap), Opt-Out DS NODATA, and wildcard NODATA. The iterated-SHA-1 count is capped by `opts.maxIterations` (default 500); an NXDOMAIN proof that depends on an Opt-Out NSEC3 is refused unless `opts.allowOptOut` is set. NSEC supports covering-name NXDOMAIN (with the source-of-synthesis wildcard) and matching-name NODATA. Verified end-to-end against a live iana.org NXDOMAIN proof. · *`b.network.dns.dnssec.nsec3Hash(name, opts)`* — Computes the RFC 5155 §5 NSEC3 hash of a name — iterated SHA-1 over the canonical (lowercased, root-terminated) wire form with the zone salt. The base32hex encoding of the result is the NSEC3 owner label. SHA-1 is the only hash IANA registers for NSEC3, so this is a wire-protocol constant rather than a cryptographic default. Useful for checking an owner label or analyzing a zone's hashing parameters. **Changed:** *`verifyRrset` now accepts NSEC and NSEC3 RRsets* — NSEC (type 47) and NSEC3 (type 50) are no longer refused as uncanonicalizable: NSEC3's next-owner is a hash, and per RFC 6840 §5.1 the NSEC Next Domain Name field is not downcased for DNSSEC canonical form, so both RDATAs are verbatim-canonical. This lets a caller verify the signatures on the records that `verifyDenial` then reasons over.
@@ -120,7 +120,7 @@ The framework bundles the surface a typical Node app reaches for. Every primitiv
120
120
  - In-process CIDR fence (`b.middleware.networkAllowlist`)
121
121
  - `Cache-Control: no-store` on every 401 from `requireAuth` / `requireAal` / `requireStepUp` per RFC 9111 §5.2.2.5
122
122
  - **Outbound HTTP client** — HTTP/1.1 + HTTP/2 with SSRF gate (cloud-metadata IPs hard-denied; private / loopback / link-local overridable per call); scheme + userinfo + per-host destination allowlist; redirects, multipart, interceptors, progress, encrypted cookie jar (`b.httpClient`, `b.ssrfGuard`, `b.safeUrl`)
123
- - **Network configurability (`b.network`)** — env-driven NTP / NTS (RFC 8915), IPv4/IPv6 NTP, DNS with IPv6 / DoH / DoT (private-CA pinning) / cache / lookup timeout; local DNSSEC signature verification (RFC 4035 — `b.network.dns.dnssec.verifyRrset` over a canonicalised RRset against RSA / ECDSA P-256·P-384 / Ed25519 DNSKEYs, plus DS-digest + key-tag, plus `verifyDenial` for NSEC / NSEC3 (RFC 5155) NXDOMAIN / NODATA proofs with iteration caps + Opt-Out handling, plus `verifyChain` to validate a full root→TLD→zone delegation chain against the pinned IANA root anchors) so a resolver client can verify both positive and negative answers instead of trusting the upstream AD bit; outbound HTTP proxy (`HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY`); runtime DPI trust-store CA additions; application-level heartbeats; TCP socket defaults
123
+ - **Network configurability (`b.network`)** — env-driven NTP / NTS (RFC 8915), IPv4/IPv6 NTP, DNS with IPv6 / DoH / DoT (private-CA pinning) / cache / lookup timeout; local DNSSEC signature verification (RFC 4035 — `b.network.dns.dnssec.verifyRrset` over a canonicalised RRset against RSA / ECDSA P-256·P-384 / Ed25519 DNSKEYs, plus DS-digest + key-tag, plus `verifyDenial` for NSEC / NSEC3 (RFC 5155) NXDOMAIN / NODATA proofs with iteration caps + Opt-Out handling, plus `verifyChain` to validate a full root→TLD→zone delegation chain against the pinned IANA root anchors) so a resolver client can verify both positive and negative answers instead of trusting the upstream AD bit; DANE / TLSA certificate matching (RFC 6698/7671 — `b.network.dns.dane.matchCertificate`) to pin a service's key through DNSSEC instead of a public CA; outbound HTTP proxy (`HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY`); runtime DPI trust-store CA additions; application-level heartbeats; TCP socket defaults
124
124
  - **Error pages** — operator-rendered, no app-frame leakage (`b.errorPage`)
125
125
  ### Defensive parsers
126
126
 
@@ -351,7 +351,7 @@ This is the minimum-viable security posture for a production deployment. The fra
351
351
  - [ ] At boot, before any outbound socket opens: call `b.network.bootFromEnv({ env: process.env, audit: b.audit })` so operator-supplied NTP / DNS / proxy / DPI-trust / TCP socket settings (`BLAMEJS_NTP_*`, `BLAMEJS_DNS_*`, `HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY`, `BLAMEJS_EXTRA_CA_CERTS`, `BLAMEJS_SOCKET_*`) apply uniformly
352
352
  - [ ] If the deployment sits behind a deep-packet-inspection proxy with its own re-signing CA: install the CA via `b.network.tls.addCa("/path/to/corp-ca.pem", { label: "corp-mitm" })` and pass `allowDpiTrust: true` to `b.security.assertProduction` — every CA addition audits with subject + fingerprint so a forensic review can reconstruct the trust path
353
353
  - [ ] For authenticated time (HIPAA / PCI / FIPS shops): use `b.network.ntp.nts.query({ host: ntsKeServer })` (RFC 8915) instead of plain SNTP; set `BLAMEJS_NTS_REQUIRE=1` to fail closed on negotiation failure
354
- - [ ] When a DNS answer drives a trust decision (DANE / TLSA pinning, SSHFP, CAA enforcement, OPENPGPKEY lookup) and the upstream resolver isn't itself trusted: verify the answer's DNSSEC signature with `b.network.dns.dnssec.verifyRrset(...)` rather than trusting the resolver's AD bit — an on-path or compromised resolver can set AD on a forged answer, but cannot forge the RRSIG. Validate the whole delegation chain root→TLD→zone with `b.network.dns.dnssec.verifyChain(...)` (default-pinned to the IANA root KSKs, or `trustAnchors` for a private root) so trust is anchored, not borrowed from the resolver. For a negative answer that drives a fail-closed decision (an allowlist lookup, a revocation check), verify the NSEC / NSEC3 proof with `b.network.dns.dnssec.verifyDenial(...)` so a forged NXDOMAIN cannot suppress a record; keep the default Opt-Out refusal unless the zone's opt-out spans are acceptable for that decision
354
+ - [ ] When a DNS answer drives a trust decision (DANE / TLSA pinning, SSHFP, CAA enforcement, OPENPGPKEY lookup) and the upstream resolver isn't itself trusted: verify the answer's DNSSEC signature with `b.network.dns.dnssec.verifyRrset(...)` rather than trusting the resolver's AD bit — an on-path or compromised resolver can set AD on a forged answer, but cannot forge the RRSIG. Validate the whole delegation chain root→TLD→zone with `b.network.dns.dnssec.verifyChain(...)` (default-pinned to the IANA root KSKs, or `trustAnchors` for a private root) so trust is anchored, not borrowed from the resolver. For a negative answer that drives a fail-closed decision (an allowlist lookup, a revocation check), verify the NSEC / NSEC3 proof with `b.network.dns.dnssec.verifyDenial(...)` so a forged NXDOMAIN cannot suppress a record; keep the default Opt-Out refusal unless the zone's opt-out spans are acceptable for that decision. For DANE / TLSA, once the TLSA RRset is DNSSEC-verified, pin the peer certificate with `b.network.dns.dane.matchCertificate(...)` — a DANE-EE(3) match authenticates the key with no public CA, while PKIX usages are flagged as still needing PKIX
355
355
  - [ ] At boot in production: call `await b.security.assertProduction({ vault: "wrapped", dbAtRest: "encrypted", auditSigning: "wrapped", ntpStrict: true, requireEnv: ["BLAMEJS_VAULT_PASSPHRASE"], dataDir: "./data" })` to refuse to start on weak posture instead of warning
356
356
  - [ ] At boot: call `await b.configDrift.create({ dataDir, audit }).checkpoint({ allowedOrigins, csp, vaultMode, ... })` so the next boot detects + audits any silent runtime config change
357
357
  - [ ] At boot, before any listener opens: call `b.configDrift.verifyVendorIntegrity({ manifestPath: "./lib/vendor/MANIFEST.json", audit: b.audit })` so a tampered `lib/vendor/*.cjs` artifact aborts start instead of running with a swapped crypto bundle
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 1,
3
- "frameworkVersion": "0.12.50",
4
- "createdAt": "2026-05-25T13:31:06.521Z",
3
+ "frameworkVersion": "0.12.51",
4
+ "createdAt": "2026-05-25T14:53:56.538Z",
5
5
  "exports": {
6
6
  "a2a": {
7
7
  "type": "object",
@@ -41574,6 +41574,53 @@
41574
41574
  "type": "function",
41575
41575
  "arity": 0
41576
41576
  },
41577
+ "dane": {
41578
+ "type": "object",
41579
+ "members": {
41580
+ "DaneError": {
41581
+ "type": "function",
41582
+ "arity": 4
41583
+ },
41584
+ "SELECTORS": {
41585
+ "type": "object",
41586
+ "members": {
41587
+ "0": {
41588
+ "type": "primitive",
41589
+ "valueType": "string"
41590
+ },
41591
+ "1": {
41592
+ "type": "primitive",
41593
+ "valueType": "string"
41594
+ }
41595
+ }
41596
+ },
41597
+ "USAGES": {
41598
+ "type": "object",
41599
+ "members": {
41600
+ "0": {
41601
+ "type": "primitive",
41602
+ "valueType": "string"
41603
+ },
41604
+ "1": {
41605
+ "type": "primitive",
41606
+ "valueType": "string"
41607
+ },
41608
+ "2": {
41609
+ "type": "primitive",
41610
+ "valueType": "string"
41611
+ },
41612
+ "3": {
41613
+ "type": "primitive",
41614
+ "valueType": "string"
41615
+ }
41616
+ }
41617
+ },
41618
+ "matchCertificate": {
41619
+ "type": "function",
41620
+ "arity": 1
41621
+ }
41622
+ }
41623
+ },
41577
41624
  "discoverEncrypted": {
41578
41625
  "type": "function",
41579
41626
  "arity": 1
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ /**
3
+ * @module b.network.dns.dane
4
+ * @nav Network
5
+ * @title DANE / TLSA
6
+ *
7
+ * @intro
8
+ * DNS-Based Authentication of Named Entities (RFC 6698, updated by
9
+ * RFC 7671) — match a server certificate against a TLSA record so the
10
+ * DNS, not a public CA, vouches for which key a service uses. This is
11
+ * the payoff of DNSSEC: verify the TLSA RRset with
12
+ * <code>b.network.dns.dnssec</code> first, then
13
+ * <code>matchCertificate</code> checks the certificate against it.
14
+ *
15
+ * A TLSA record carries a certificate usage (PKIX-TA 0, PKIX-EE 1,
16
+ * DANE-TA 2, DANE-EE 3 — RFC 7218 mnemonics), a selector (full
17
+ * certificate 0, or subjectPublicKeyInfo 1), and a matching type
18
+ * (exact 0, SHA-256 1, SHA-512 2). The selected certificate data is
19
+ * hashed per the matching type and compared, in constant time, to the
20
+ * record's association data. For DANE-EE(3) a match means the
21
+ * certificate IS the pinned end-entity key — no public-CA path is
22
+ * needed (the common SMTP-DANE case, RFC 7672). For the PKIX usages a
23
+ * match is necessary but the caller still performs PKIX validation.
24
+ *
25
+ * @card
26
+ * DANE / TLSA certificate matching (RFC 6698 / 7671). Pin a service's
27
+ * key through DNSSEC instead of a public CA — verify the TLSA RRset,
28
+ * then match the certificate (DANE-EE / DANE-TA / PKIX usages,
29
+ * full-cert or SPKI selector, SHA-256 / SHA-512).
30
+ */
31
+
32
+ var nodeCrypto = require("node:crypto");
33
+ var bCrypto = require("./crypto");
34
+ var validateOpts = require("./validate-opts");
35
+ var { defineClass } = require("./framework-error");
36
+
37
+ var DaneError = defineClass("DaneError", { alwaysPermanent: true });
38
+
39
+ // RFC 6698 §2.1 + RFC 7218 mnemonics.
40
+ var USAGES = { 0: "PKIX-TA", 1: "PKIX-EE", 2: "DANE-TA", 3: "DANE-EE" };
41
+ var SELECTORS = { 0: "Cert", 1: "SPKI" };
42
+ // Matching types: 0 = exact match on the selected data, 1 = SHA-256,
43
+ // 2 = SHA-512. SHA-1 is not registered for TLSA, so anything else is
44
+ // refused rather than guessed.
45
+ var MATCHING = { 0: null, 1: "sha256", 2: "sha512" };
46
+
47
+ function _bytes(x, what) {
48
+ if (Buffer.isBuffer(x)) return x;
49
+ if (x instanceof Uint8Array) return Buffer.from(x);
50
+ if (typeof x === "string") return Buffer.from(x, "hex");
51
+ throw new DaneError("dane/bad-bytes", "dane: " + what + " must be a Buffer / Uint8Array / hex string");
52
+ }
53
+
54
+ function _selectedData(x509, selector) {
55
+ if (selector === 0) return Buffer.from(x509.raw); // full certificate DER
56
+ if (selector === 1) return x509.publicKey.export({ format: "der", type: "spki" }); // subjectPublicKeyInfo DER
57
+ throw new DaneError("dane/unsupported-selector", "dane: unsupported TLSA selector " + selector + " (0 = full cert, 1 = SPKI)");
58
+ }
59
+
60
+ function _associationOf(selected, matchingType) {
61
+ if (matchingType === 0) return selected;
62
+ var hashName = MATCHING[matchingType];
63
+ if (!hashName) throw new DaneError("dane/unsupported-matching", "dane: unsupported TLSA matching type " + matchingType + " (0 = exact, 1 = SHA-256, 2 = SHA-512)");
64
+ return nodeCrypto.createHash(hashName).update(selected).digest();
65
+ }
66
+
67
+ function _parseCert(der, what) {
68
+ try { return new nodeCrypto.X509Certificate(_bytes(der, what)); }
69
+ catch (e) { throw new DaneError("dane/bad-certificate", "dane: could not parse " + what + ": " + ((e && e.message) || e)); }
70
+ }
71
+
72
+ // Validate a TLSA enum field: it must be an actual integer that is an
73
+ // OWN key of the lookup table. Rejecting non-numbers stops a string like
74
+ // "1" (which coerces on key lookup but then fails the strict-=== usage
75
+ // checks below), and the own-property test stops prototype keys such as
76
+ // "__proto__" that `in` / `[x] !== undefined` would wrongly accept.
77
+ function _enumField(v, table, code, label, i) {
78
+ if (typeof v !== "number" || !Number.isInteger(v) || !Object.prototype.hasOwnProperty.call(table, v)) {
79
+ throw new DaneError(code, "dane: tlsa[" + i + "] " + label + " must be a numeric " + Object.keys(table).join(" / ") + " (got " + JSON.stringify(v) + ")");
80
+ }
81
+ }
82
+ function _normaliseTlsa(rec, i) {
83
+ if (!rec || typeof rec !== "object") throw new DaneError("dane/bad-tlsa", "dane: tlsa[" + i + "] must be an object");
84
+ _enumField(rec.usage, USAGES, "dane/unsupported-usage", "certificate usage", i);
85
+ _enumField(rec.selector, SELECTORS, "dane/unsupported-selector", "selector", i);
86
+ _enumField(rec.matchingType, MATCHING, "dane/unsupported-matching", "matching type", i);
87
+ return { usage: rec.usage, selector: rec.selector, matchingType: rec.matchingType, data: _bytes(rec.data, "tlsa[" + i + "].data") };
88
+ }
89
+
90
+ /**
91
+ * @primitive b.network.dns.dane.matchCertificate
92
+ * @signature b.network.dns.dane.matchCertificate(opts)
93
+ * @since 0.12.51
94
+ * @status stable
95
+ * @compliance soc2
96
+ * @related b.network.dns.dnssec.verifyChain, b.network.dns.dnssec.verifyRrset
97
+ *
98
+ * Match a server certificate against a set of (DNSSEC-verified) TLSA
99
+ * records (RFC 6698 / 7671). For each record the selected data — the
100
+ * full certificate DER (selector 0) or its subjectPublicKeyInfo
101
+ * (selector 1) — is hashed per the matching type (exact / SHA-256 /
102
+ * SHA-512) and compared, constant-time, to the record's association
103
+ * data. End-entity usages (PKIX-EE 1, DANE-EE 3) are matched against the
104
+ * leaf certificate; trust-anchor usages (PKIX-TA 0, DANE-TA 2) are
105
+ * matched against the leaf and any supplied <code>chain</code>.
106
+ *
107
+ * Returns the matching record plus what the caller must still do: a
108
+ * DANE-EE match is self-sufficient (the TLSA pins the key); a DANE-TA
109
+ * match still needs chain-to-anchor verification; PKIX usages still need
110
+ * full PKIX validation. Throws <code>dane/no-match</code> if nothing
111
+ * matches. Verify the TLSA RRset with <code>b.network.dns.dnssec</code>
112
+ * before trusting the records — an unauthenticated TLSA proves nothing.
113
+ *
114
+ * @opts
115
+ * {
116
+ * tlsa: [ { usage, selector, matchingType, data: Buffer|hex } ], // the TLSA RRset
117
+ * certificate: Buffer, // leaf certificate (DER)
118
+ * chain?: Buffer[], // intermediate / CA certs (DER), for TA usages
119
+ * }
120
+ *
121
+ * @example
122
+ * var r = b.network.dns.dane.matchCertificate({ tlsa: records, certificate: leafDer });
123
+ * // → { ok: true, matched: { usage: 3, selector: 1, matchingType: 1 }, daneAuthenticated: true, pkixRequired: false }
124
+ */
125
+ function matchCertificate(opts) {
126
+ validateOpts.requireObject(opts, "dane.matchCertificate", DaneError);
127
+ validateOpts(opts, ["tlsa", "certificate", "chain"], "dane.matchCertificate");
128
+ if (!Array.isArray(opts.tlsa) || opts.tlsa.length === 0) throw new DaneError("dane/bad-arg", "dane.matchCertificate: opts.tlsa must be a non-empty array");
129
+ var records = opts.tlsa.map(_normaliseTlsa);
130
+ var leaf = _parseCert(opts.certificate, "certificate");
131
+ var chain = Array.isArray(opts.chain) ? opts.chain.map(function (c, i) { return _parseCert(c, "chain[" + i + "]"); }) : [];
132
+
133
+ for (var i = 0; i < records.length; i++) {
134
+ var rec = records[i];
135
+ var eeUsage = rec.usage === 1 || rec.usage === 3; // PKIX-EE / DANE-EE → leaf only
136
+ var certs = eeUsage ? [leaf] : [leaf].concat(chain); // TA usages may match a chain cert
137
+ for (var c = 0; c < certs.length; c++) {
138
+ var assoc = _associationOf(_selectedData(certs[c], rec.selector), rec.matchingType);
139
+ if (bCrypto.timingSafeEqual(assoc, rec.data)) {
140
+ return {
141
+ ok: true,
142
+ matched: { usage: rec.usage, usageName: USAGES[rec.usage], selector: rec.selector, matchingType: rec.matchingType },
143
+ matchedCertIndex: c, // 0 = leaf, >0 = chain[c-1]
144
+ daneAuthenticated: rec.usage === 3, // DANE-EE: TLSA pins the key, no CA path needed
145
+ trustAnchorMatch: rec.usage === 0 || rec.usage === 2,
146
+ pkixRequired: rec.usage === 0 || rec.usage === 1,
147
+ };
148
+ }
149
+ }
150
+ }
151
+ throw new DaneError("dane/no-match", "dane.matchCertificate: no TLSA record matched the certificate" + (chain.length ? " or chain" : ""));
152
+ }
153
+
154
+ module.exports = {
155
+ matchCertificate: matchCertificate,
156
+ USAGES: USAGES,
157
+ SELECTORS: SELECTORS,
158
+ DaneError: DaneError,
159
+ };
@@ -36,6 +36,7 @@ var nts = require("./network-nts");
36
36
  var networkDns = require("./network-dns");
37
37
  networkDns.resolver = require("./network-dns-resolver");
38
38
  networkDns.dnssec = require("./network-dnssec");
39
+ networkDns.dane = require("./network-dane");
39
40
  var networkProxy = require("./network-proxy");
40
41
  var networkTls = require("./network-tls");
41
42
  var heartbeat = require("./network-heartbeat");
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/core",
3
- "version": "0.12.50",
3
+ "version": "0.12.51",
4
4
  "description": "The Node framework that owns its stack.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "../scripts/release-notes-schema.json",
3
+ "version": "0.12.51",
4
+ "date": "2026-05-25",
5
+ "headline": "`b.network.dns.dane.matchCertificate` — DANE / TLSA certificate matching (RFC 6698 / 7671)",
6
+ "summary": "Pin a service's certificate through DNS instead of a public CA. matchCertificate checks a server certificate against a set of TLSA records: the selected data — the full certificate (selector 0) or its subjectPublicKeyInfo (selector 1) — is hashed per the matching type (exact / SHA-256 / SHA-512) and compared in constant time to the record's association data. For a DANE-EE (usage 3) record a match is self-authenticating — the TLSA pins the key, so no public-CA path is needed (the common SMTP-DANE case, RFC 7672); for the PKIX usages a match is reported as necessary-but-not-sufficient so the caller still runs PKIX. This is the payoff of the DNSSEC verifier: verify the TLSA RRset with b.network.dns.dnssec, then match the certificate. Verified against a live DNSSEC-signed TLSA record and the matching server certificate.",
7
+ "sections": [
8
+ {
9
+ "heading": "Added",
10
+ "items": [
11
+ {
12
+ "title": "`b.network.dns.dane.matchCertificate(opts)`",
13
+ "body": "Matches a leaf certificate (and optional `chain`) against a TLSA RRset (`{ usage, selector, matchingType, data }`). Selector 0 hashes the full certificate DER, selector 1 the subjectPublicKeyInfo; matching type 0 is an exact comparison, 1 SHA-256, 2 SHA-512 (SHA-1 and any other type are refused, not guessed). End-entity usages (PKIX-EE 1, DANE-EE 3) match the leaf; trust-anchor usages (PKIX-TA 0, DANE-TA 2) match the leaf or any supplied chain certificate. Returns `{ ok, matched, daneAuthenticated, trustAnchorMatch, pkixRequired, matchedCertIndex }` — `daneAuthenticated` is true only for a DANE-EE match (the key is pinned, no CA needed); `pkixRequired` flags the PKIX usages. Throws `dane/no-match` when nothing matches, and refuses unknown usage / selector / matching values and unparseable certificates. Verify the TLSA RRset with `b.network.dns.dnssec` first — an unauthenticated TLSA record proves nothing."
14
+ }
15
+ ]
16
+ }
17
+ ]
18
+ }
@@ -2267,10 +2267,13 @@ async function testNoDuplicateCodeBlocks() {
2267
2267
  mode: "family-subset",
2268
2268
  files: [
2269
2269
  "lib/cose.js:_coseKeyBytes",
2270
+ "lib/cose.js:_bstr",
2270
2271
  "lib/mdoc.js:_bytes",
2271
2272
  "lib/network-dnssec.js:_bytes",
2273
+ "lib/network-dane.js:_bytes",
2274
+ "lib/tsa.js:_bytes",
2272
2275
  ],
2273
- reason: "v0.12.48 — Buffer-coercion guard (`if (Buffer.isBuffer(x)) return x; if (x instanceof Uint8Array) return Buffer.from(x); throw <Error>`) repeats across three byte-string-consuming primitives. Each throws a MODULE-LOCAL typed error code (cose/bad-cose-key, mdoc/bad-input, dnssec/bad-bytes) naming the local argument; the duplicated three-line shape is the symptom, the cause is that JS can't throw a caller-namespaced ErrorClass without the local closure. Same documented exception as the v0.12.7 require-non-empty-string cluster — the typed-error CODE is the divergence the dup detector can't see.",
2276
+ reason: "v0.12.48 / v0.12.51 — Buffer-coercion guard (`if (Buffer.isBuffer(x)) return x; if (x instanceof Uint8Array) return Buffer.from(x); throw <Error>`) repeats across byte-string-consuming primitives. Each throws a MODULE-LOCAL typed error code (cose/bad-cose-key, mdoc/bad-input, dnssec/bad-bytes, dane/bad-bytes, tsa/bad-input) naming the local argument; network-dane additionally coerces a hex string. The duplicated three-line shape is the symptom, the cause is that JS can't throw a caller-namespaced ErrorClass without the local closure. Same documented exception as the v0.12.7 require-non-empty-string cluster — the typed-error CODE is the divergence the dup detector can't see.",
2274
2277
  },
2275
2278
  {
2276
2279
  mode: "family-subset",
@@ -6290,6 +6293,20 @@ var KNOWN_ANTIPATTERNS = [
6290
6293
  allowlist: [],
6291
6294
  reason: "DNSSEC key-tag collision false-negative — a 16-bit DNSKEY tag is not unique within an RRset (RFC 4034 Appendix B explicitly permits collisions). Picking the first key with a matching tag and verifying only against it rejects an otherwise-valid chain when a colliding non-signing key sorts earlier. RFC 4035 §5.3.1 requires trying every key whose tag and algorithm match until one validates; the framework does this via `_keysByTag` + `_verifyRrsetWithAnyKey`. The single-result `_findKeyByTag` helper must not be (re)introduced for signature key selection.",
6292
6295
  },
6296
+ {
6297
+ // Wire-enum validation against a lookup table must use an integer +
6298
+ // own-property check, never `key in TABLE` or `TABLE[key] !==
6299
+ // undefined`: `in` / member access walk the prototype chain, so an
6300
+ // attacker-supplied `"__proto__"` (or a string `"1"` that coerces on
6301
+ // lookup but then fails strict-=== comparisons) slips past. The
6302
+ // dane TLSA usage / selector / matching-type enums are validated via
6303
+ // `_enumField` (typeof number + Number.isInteger + hasOwnProperty).
6304
+ id: "dane-enum-unsafe-membership",
6305
+ primitive: "_enumField(v, TABLE, ...) — integer + Object.prototype.hasOwnProperty, never `v in TABLE` / `TABLE[v] === undefined`",
6306
+ regex: /\b(?:in\s+(?:USAGES|SELECTORS|MATCHING)\b|(?:USAGES|SELECTORS|MATCHING)\s*\[[^\]]+\]\s*===?\s*undefined)/,
6307
+ allowlist: [],
6308
+ reason: "Prototype-key / string-coercion bypass — validating an untrusted wire enum with `key in TABLE` or `TABLE[key] !== undefined` accepts inherited keys such as `__proto__` (and string keys like `\"1\"` that coerce on lookup but break later strict-=== branches). The DANE TLSA enums (certificate usage / selector / matching type) must be validated with a numeric + integer + own-property test (`_enumField`). The unsafe membership forms must not appear for these tables.",
6309
+ },
6293
6310
  {
6294
6311
  // CVE-2026-23552 — cross-realm JWT acceptance via non-CT iss
6295
6312
  // compare. `payload.iss !== expectedIssuer` (or claims.iss / token.iss)
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /**
3
+ * Layer 0 — b.network.dns.dane (DANE / TLSA certificate matching).
4
+ * The oracle is a REAL DNSSEC-signed TLSA record for dane.sys4.de plus
5
+ * that server's actual leaf certificate (captured via `openssl s_client
6
+ * -connect dane.sys4.de:443`): the SHA-256 of the certificate's
7
+ * subjectPublicKeyInfo equals the record's association data, so a wrong
8
+ * SPKI extraction or hash would fail this match.
9
+ */
10
+
11
+ var b = require("../../index");
12
+ var helpers = require("../helpers");
13
+ var check = helpers.check;
14
+
15
+ // Real `_443._tcp.dane.sys4.de` TLSA: usage 3 (DANE-EE), selector 1
16
+ // (SPKI), matching 1 (SHA-256).
17
+ var TLSA_DANE_EE = { usage: 3, selector: 1, matchingType: 1, data: "eb74fe41c51d2876a50f0fe95ba6441119a38597a177e1ba54d68acb9a91efa3" };
18
+ // dane.sys4.de's real leaf certificate (DER).
19
+ var CERT_HEX = "308205f1308204d9a0030201020212061d670ec5c40f0709b0eb3279dfbf4a0780300d06092a864886f70d01010b05003033310b300906035504061302555331163014060355040a130d4c6574277320456e6372797074310c300a06035504031303523133301e170d3236303430373232303134395a170d3236303730363232303134385a3017311530130603550403130c64616e652e737973342e646530820222300d06092a864886f70d01010105000382020f003082020a0282020100a1e920d22e53fcd7ea5d47fa4c8ad99701e47cbeca1a1d290c5c5bfaecec805d8248174a7561c5f7ee23b68f5e4561df143eeccc1e849d6ad3b49a60a294798131bf0704364fd230803c7327d7a82b7c4e87daabc5f5474781a56003c1f0c3ad03960475b2bcb93b2a998f53531c0bdac8a9ddd0fe064b9a19a18c1b7220456c530a27c1cb39253e14157d805b17e0866a80e866d00cbf2e0a2481b72f1a9db141e557594c5e93a26fbe6f3548cff8a7d0ca82a0e0771cafd539da8e9dc13c8ceb618891994010a9a1b91e6a0e41ada62b1ad5018e654e0dad0274a6c2c4567afd7b71575ff597223071b5e4c15474ed6c3ee39763f996bbc5d99b908e89ead08058a3a65f5fa6ed962e7a891eba1fe68464db135a076db758ebd7fc3e665aed18ffadddf2f9deb76c164b56f9a91ba852608b1d562512f56e8ed30cad51d4cd0208a6e563eaf7ec94dd6ab7cca8616ca1a9c9c116bf4dcaad8cc7691a69e6e054a8f227c35c80b2dbcd1c2ec042af00bf7b98a1b531736f0d44c94fab6906be1fbdb3b7eff9d1c212d3e139a8d0aef994504ea3f4fffb8a11cf17fcdf012545779621ee4302b123fcb5ee02cc1cfb8389cb99d764fe305bc7f87bd9611bc0ab02012bd1cee8e8eeef9f77d9fa91c911283468d79a03c3ba9a8b1377ef2fdf8fc4ffb4d27b0af8d24686aa260593600e962ec7dee76c259aad77b0ed06f59acd0203010001a382021930820215300e0603551d0f0101ff0404030205a030130603551d25040c300a06082b06010505070301300c0603551d130101ff04023000301d0603551d0e0416041490d876e1363cedc1e8f840acea8a001831415abb301f0603551d23041830168014e7ab9f0f2c33a053d35e4f78c8b2840e3bd69233303306082b0601050507010104273025302306082b060105050730028617687474703a2f2f7231332e692e6c656e63722e6f72672f30170603551d110410300e820c64616e652e737973342e646530130603551d20040c300a3008060667810c010201302d0603551d1f042630243022a020a01e861c687474703a2f2f7231332e632e6c656e63722e6f72672f312e63726c3082010c060a2b06010401d6790204020481fd0481fa00f8007600d76d7d10d1a7f577c2c7e95fd700bff982c9335a65e1d0b3017317c0c8c569770000019d6a2ce2560000040300473045022100997e2a727dd924aa0ee78fad453a1822e3c4739c7bef6d8c4fead20f6ac99dd502200a744a3f55fa27f1f6d23b25d857676a34468a9c0df525c6313e6308907d7860007e00a826cbe30ac6351246533fe065f14f19d96e190813c41dd96d7900b3123c55270000019d6a2ce5920008000005000604e6ca040300473045022100b180e6e36983a8c109a115b948a5efa5f0b1f1a135cf961caafefbd69e38d64a022010e833f73d2c8f9069170c3803bb5bbab0f5ffd4e00b4ef0bc599bba59f7a9e2300d06092a864886f70d01010b050003820101006f7523afa8550ff4ee625ce6fd892b3a76584af142f53829b9976b4ffe4f0c8d3dab67a8298b17d0e3bad9f93c831832bfd60a9b7609eb1cd414e91ee094e633b972c2858b07dee4efdfccf5909d51fc2234229b783ab7fa598e9579aa3fd1089df4f3a33840ae6ed75ac27ad4645f2b87a32adc9a62dade43b97955d1395ff2b9c3ac30967da3211d04dbb6b3a470021a9218600c6c1158854f4fc4673a50f0be9e137705ab44e9a4fa0bccc247d01e7fda67475b8471075b8bb7b72229817af1d3688f55607edd7a3cd8259470c8f4fe5faa7e184aeb15582dc8a3b82666b3502d8d39a9a1130bf06ef82a072c84a432f016fb1d555bebaa4533d8b432ddba";
20
+
21
+ function cert() { return Buffer.from(CERT_HEX, "hex"); }
22
+ function code(fn) { try { fn(); return "NO-THROW"; } catch (e) { return e.code; } }
23
+
24
+ function testSurface() {
25
+ check("b.network.dns.dane.matchCertificate is a function", typeof b.network.dns.dane.matchCertificate === "function");
26
+ check("b.network.dns.dane.USAGES maps 3 to DANE-EE", b.network.dns.dane.USAGES[3] === "DANE-EE");
27
+ }
28
+
29
+ function testRealVector() {
30
+ var out = b.network.dns.dane.matchCertificate({ tlsa: [TLSA_DANE_EE], certificate: cert() });
31
+ check("matchCertificate: real dane.sys4.de DANE-EE TLSA matches the real cert (SPKI/SHA-256)", out.ok && out.matched.usage === 3);
32
+ check("matchCertificate: DANE-EE is self-authenticating (no PKIX required)", out.daneAuthenticated === true && out.pkixRequired === false);
33
+
34
+ // The same cert matched by a full-cert (selector 0) exact (matching 0)
35
+ // record — derive the association from the cert DER itself.
36
+ var full = { usage: 3, selector: 0, matchingType: 0, data: cert() };
37
+ var out2 = b.network.dns.dane.matchCertificate({ tlsa: [full], certificate: cert() });
38
+ check("matchCertificate: full-cert exact selector matches", out2.ok && out2.matched.selector === 0 && out2.matched.matchingType === 0);
39
+ }
40
+
41
+ function testRefusals() {
42
+ // A flipped association byte no longer matches.
43
+ var bad = { usage: 3, selector: 1, matchingType: 1, data: TLSA_DANE_EE.data.replace(/^eb/, "ec") };
44
+ check("matchCertificate: wrong association refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [bad], certificate: cert() }); }) === "dane/no-match");
45
+ // Unknown usage / selector / matching are refused, not guessed.
46
+ check("matchCertificate: unsupported usage refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [{ usage: 9, selector: 1, matchingType: 1, data: TLSA_DANE_EE.data }], certificate: cert() }); }) === "dane/unsupported-usage");
47
+ check("matchCertificate: unsupported selector refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [{ usage: 3, selector: 9, matchingType: 1, data: TLSA_DANE_EE.data }], certificate: cert() }); }) === "dane/unsupported-selector");
48
+ check("matchCertificate: unsupported matching type (e.g. SHA-1) refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [{ usage: 3, selector: 1, matchingType: 3, data: TLSA_DANE_EE.data }], certificate: cert() }); }) === "dane/unsupported-matching");
49
+ // Garbage certificate refused.
50
+ check("matchCertificate: bad certificate refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [TLSA_DANE_EE], certificate: Buffer.from("not a cert") }); }) === "dane/bad-certificate");
51
+ // Empty TLSA set refused.
52
+ check("matchCertificate: empty TLSA set refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [], certificate: cert() }); }) === "dane/bad-arg");
53
+ // String enum values are refused (they coerce on key lookup but break
54
+ // the strict-=== usage logic), not silently accepted.
55
+ check("matchCertificate: string usage refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [{ usage: "3", selector: 1, matchingType: 1, data: TLSA_DANE_EE.data }], certificate: cert() }); }) === "dane/unsupported-usage");
56
+ // Prototype-chain keys must not slip past the enum check.
57
+ check("matchCertificate: __proto__ matchingType refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [{ usage: 3, selector: 1, matchingType: "__proto__", data: TLSA_DANE_EE.data }], certificate: cert() }); }) === "dane/unsupported-matching");
58
+ check("matchCertificate: __proto__ selector refused", code(function () { b.network.dns.dane.matchCertificate({ tlsa: [{ usage: 3, selector: "__proto__", matchingType: 1, data: TLSA_DANE_EE.data }], certificate: cert() }); }) === "dane/unsupported-selector");
59
+ }
60
+
61
+ function testPkixUsage() {
62
+ // A PKIX-EE(1) match flags that PKIX validation is still required.
63
+ var pkixEe = { usage: 1, selector: 1, matchingType: 1, data: TLSA_DANE_EE.data };
64
+ var out = b.network.dns.dane.matchCertificate({ tlsa: [pkixEe], certificate: cert() });
65
+ check("matchCertificate: PKIX-EE match flags pkixRequired", out.ok && out.matched.usage === 1 && out.pkixRequired === true && out.daneAuthenticated === false);
66
+ }
67
+
68
+ async function run() {
69
+ testSurface();
70
+ testRealVector();
71
+ testRefusals();
72
+ testPkixUsage();
73
+ }
74
+
75
+ module.exports = { run: run };
76
+
77
+ if (require.main === module) {
78
+ run().then(
79
+ function () { console.log("[dane] OK — " + helpers.getChecks() + " checks passed"); },
80
+ function (e) { console.error("FAIL:", e && e.stack || e); process.exit(1); }
81
+ );
82
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/blamejs-shop",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Open-source framework built on blamejs. Vendored stack, zero npm runtime deps, PQC-first crypto, security-on by default.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {