@blamejs/pki 0.2.11 → 0.2.12

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/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to `@blamejs/pki` are documented here. The format
4
4
  follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this
5
5
  project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## v0.2.12 — 2026-07-13
8
+
9
+ pki.ct.verifySct verifies a Signed Certificate Timestamp's signature against a Certificate Transparency log's public key.
10
+
11
+ ### Added
12
+
13
+ - pki.ct.verifySct(entry, sct, logPublicKey) verifies a Signed Certificate Timestamp's signature against a CT log's public key (RFC 6962 section 3.2), composing pki.ct.reconstructSignedData, the shared ECDSA-Sig-Value conformance gate, and pki.webcrypto. Resolves true/false on the cryptographic verdict; throws a typed CtError on a structural fault.
14
+
7
15
  ## v0.2.11 — 2026-07-13
8
16
 
9
17
  The pki command-line tool gains inspect, lint, convert, and verify -- front-ends over the certificate inspector, the linter, the PEM codecs, and RFC 5280 path validation.
package/README.md CHANGED
@@ -221,7 +221,7 @@ is callable today; nothing below is a stub.
221
221
  | `pki.schema.smime` | Decode S/MIME ESS signed-attribute values (RFC 5035 / RFC 8551) — `parseSigningCertificate` / `parseSigningCertificateV2` bind a signature to its signing certificate (cert hash, hash algorithm, issuer `GeneralNames` + serial), `parseSmimeCapabilities` decodes the ordered capability list, and `decodeAttribute` OID-dispatches a CMS attribute (enforcing the single-value rule, recognize-and-defer for unknown types). A companion decoder for CMS signed attributes, not an auto-routed format, fail-closed — `parseSigningCertificate`, `parseSigningCertificateV2`, `parseSmimeCapabilities`, `decodeAttribute` |
222
222
  | `pki.schema.engine` | The declarative ASN.1 structure-schema engine every format parser composes — `walk` / `encode` / `embeddedDer` plus the schema combinators |
223
223
  | `pki.path` | RFC 5280 §6 certification-path validation — `validate` runs the §6.1 state machine (signature chaining across RSA, ECDSA, EdDSA, ML-DSA, SLH-DSA and hybrid composite ML-DSA signatures — a composite is accepted only when **both** its post-quantum and traditional components verify; validity windows, name chaining, basic constraints and path length, key usage, name constraints, the certificate-policy tree) over an ordered path and a trust anchor, returning a structured verdict with per-check reason codes, and enforces a `pki.trust` anchor's per-purpose distrust-after dates and delegator purposes via `checkPurpose`; `crlChecker` supplies CRL-based revocation — including partitioned/sharded CRLs, whose §6.3.3 Distribution Point ↔ IDP correspondence lets a corresponding full-reason shard establish non-revocation — and `ocspChecker` supplies OCSP-based revocation (RFC 6960 — CertID binding, responder authorization, signature, currency) over the same pluggable hook. Pure and re-entrant, fail-closed — `validate`, `crlChecker`, `ocspChecker` |
224
- | `pki.ct` | Parse RFC 6962 Certificate Transparency SCT lists — `parseSctList` decodes the `SignedCertificateTimestampList` a certificate or OCSP response carries in the SCT extension (a TLS-presentation-language payload inside the §3.3 double DER wrap) into per-SCT log id, exact `timestamp` (BigInt), named signature algorithm, and raw signature; `reconstructSignedData` rebuilds the exact `digitally-signed` preimage for external verification. Structure decoded, crypto surfaced raw, bounded decode, fail-closed — `parseSctList`, `reconstructSignedData` |
224
+ | `pki.ct` | RFC 6962 Certificate Transparency SCTs — `parseSctList` decodes the `SignedCertificateTimestampList` a certificate or OCSP response carries in the SCT extension (a TLS-presentation-language payload inside the §3.3 double DER wrap) into per-SCT log id, exact `timestamp` (BigInt), named signature algorithm, and raw signature; `reconstructSignedData` rebuilds the exact `digitally-signed` preimage; `verifySct(entry, sct, logKey)` verifies the SCT signature against a log's public key — reconstructing the signed data, routing an ECDSA signature through the strict DER-conformance gate, and verifying through the crypto engine (resolves `true`/`false`, throws typed `ct/*` on a structural fault). Structure decoded, crypto fail-closed — `parseSctList`, `reconstructSignedData`, `verifySct` |
225
225
  | `pki.merkle` | RFC 6962 / RFC 9162 Merkle-tree proof verification — `leafHash` / `nodeHash` / `emptyRootHash` build the domain-separated (0x00 leaf / 0x01 node) SHA-256 tree hashes; `verifyInclusion` folds an audit proof back to a root and `verifyConsistency` reconstructs both the old and new root (the append-only guarantee), each constant-time-compared to a trusted checkpoint root. Fail-closed on bad geometry, sync hashing, transport-free — `leafHash`, `nodeHash`, `emptyRootHash`, `verifyInclusion`, `verifyConsistency` |
226
226
  | `pki.trust` | Mozilla / CCADB trust-store ingestion — `parseCertdata` reads the NSS `certdata.txt` object stream and `parseCcadbCsv` the CCADB CSV export into one identical constraint-carrying anchor shape: the per-purpose trust bits (only `CKT_NSS_TRUSTED_DELEGATOR` grants) and the per-purpose distrust-after dates the bare root list omits. Certificate and trust objects pair by byte-exact issuer + serial (never adjacency) and are cross-checked against the parsed DER, so metadata can never attach to the wrong root; `anchor()` hands an entry to `pki.path.validate({ trustAnchor, checkPurpose })`. Offline, fail-closed, bounded — `parseCertdata`, `parseCcadbCsv`, `anchor` |
227
227
  | `pki.shbs` | Stateful hash-based signature **verification** — HSS/LMS (RFC 8554), carried in X.509 by RFC 9802 and CMS by RFC 9708, profiled by NIST SP 800-208 (CNSA 2.0 firmware signing). `verify` checks an HSS signature (every level must pass) and `verifyLms` a single-tree LMS, over the raw public-key / signature blobs the parsers already surface. Pure public-input SHA-256 / SHAKE256 hashing, a data-driven typecode registry, bounds-before-slice reads; a malformed blob throws a typed `ShbsError`, a well-formed-but-wrong signature returns `false`. **Verify only by design** — stateful signing needs atomic one-time-key state that belongs in an HSM — `verify`, `verifyLms` |
package/lib/ct.js CHANGED
@@ -43,6 +43,10 @@ var constants = require("./constants.js");
43
43
  var frameworkError = require("./framework-error.js");
44
44
  var guard = require("./guard-all.js");
45
45
  var ByteReader = require("./byte-reader.js");
46
+ var oid = require("./oid.js");
47
+ var webcrypto = require("./webcrypto.js");
48
+ var validator = require("./validator-all.js");
49
+ var subtle = webcrypto.webcrypto.subtle;
46
50
 
47
51
  var CtError = frameworkError.CtError;
48
52
  var C = constants;
@@ -287,9 +291,128 @@ function reconstructSignedData(entry, sct) {
287
291
  return Buffer.concat(parts);
288
292
  }
289
293
 
294
+ // RFC 6962 sec. 2.1.4 constrains an SCT to SHA-256 with either ECDSA (NIST P-256) or RSA;
295
+ // the verifier enforces exactly that rather than accepting an off-profile hash / curve a
296
+ // conformant log never uses. The SCT hash name -> the WebCrypto digest.
297
+ var CT_HASH = { sha256: "SHA-256" };
298
+ // The one EC named curve an SCT log key may use (P-256), keyed by the curve OID its SPKI
299
+ // carries -> the WebCrypto curve name + the r/s coordinate width.
300
+ var CT_EC_CURVE = {};
301
+ CT_EC_CURVE[oid.byName("prime256v1")] = { curve: "P-256", coordLen: 32 };
302
+
303
+ // Read the SubjectPublicKeyInfo algorithm OID (+ the EC curve OID) off a log key SPKI so
304
+ // the verifier picks the WebCrypto import descriptor from the KEY, not just the SCT's
305
+ // self-declared signature type. Fail-closed: a non-SPKI shape throws a typed ct/bad-input.
306
+ function _spkiAlg(spki) {
307
+ var node;
308
+ try { node = asn1.decode(spki); } catch (e) { throw new CtError("ct/bad-input", "the CT log public key is not a well-formed SubjectPublicKeyInfo", e); }
309
+ var algId = node.children && node.children[0];
310
+ if (!algId || !algId.children || !algId.children.length) throw new CtError("ct/bad-input", "the CT log public key is not a SubjectPublicKeyInfo");
311
+ var out;
312
+ try { out = { algOid: asn1.read.oid(algId.children[0]) }; }
313
+ catch (e1) { throw new CtError("ct/bad-input", "the CT log key SPKI algorithm identifier is not an OID", e1); }
314
+ if (out.algOid === oid.byName("ecPublicKey")) {
315
+ if (!algId.children[1]) throw new CtError("ct/bad-input", "the EC log key SPKI is missing its named-curve parameters");
316
+ try { out.curveOid = asn1.read.oid(algId.children[1]); }
317
+ catch (e2) { throw new CtError("ct/bad-input", "the EC log key SPKI curve parameters are not a named-curve OID", e2); }
318
+ } else if (out.algOid === oid.byName("rsaEncryption")) {
319
+ // RFC 6962 sec. 2.1.4 requires an RSA log key of at least 2048 bits -- size it from the
320
+ // RSAPublicKey modulus in the subjectPublicKey BIT STRING.
321
+ var mod, exp;
322
+ try {
323
+ var rsaSeq = asn1.decode(asn1.read.bitString(node.children[1]).bytes);
324
+ mod = asn1.read.integer(rsaSeq.children[0]);
325
+ exp = asn1.read.integer(rsaSeq.children[1]);
326
+ } catch (e3) { throw new CtError("ct/bad-input", "the RSA log key SPKI is not a well-formed RSAPublicKey", e3); }
327
+ // A non-positive modulus is malformed -- fail closed rather than size its absolute value.
328
+ if (mod <= 0n) throw new CtError("ct/bad-input", "the RSA log key modulus is not a positive integer");
329
+ // A small or even public exponent makes RSASSA-PKCS1-v1_5 verification forgeable (with
330
+ // e=1 the signature is simply the encoded DigestInfo). Require an odd exponent >= 3 --
331
+ // critical when the log key is taken from an untrusted log list rather than a pinned key.
332
+ if (exp < 3n || (exp & 1n) === 0n) throw new CtError("ct/bad-input", "the RSA log key public exponent must be an odd integer >= 3");
333
+ out.rsaBits = mod.toString(2).length;
334
+ }
335
+ return out;
336
+ }
337
+
338
+ /**
339
+ * @primitive pki.ct.verifySct
340
+ * @signature pki.ct.verifySct(entry, sct, logPublicKey) -> Promise<boolean>
341
+ * @since 0.2.12
342
+ * @status experimental
343
+ * @spec RFC 6962
344
+ * @defends sct-signature-forgery (CWE-347)
345
+ * @related pki.ct.parseSctList, pki.ct.reconstructSignedData
346
+ *
347
+ * Verify a Signed Certificate Timestamp's signature against a Certificate Transparency
348
+ * log's public key (RFC 6962 sec. 3.2). `entry` is the log entry the SCT covers
349
+ * (`{ entryType: 0, leafCert }` or `{ entryType: 1, tbsCertificate, issuerKeyHash }`,
350
+ * as for `reconstructSignedData`), `sct` a decoded v1 SCT from `parseSctList().scts[]`,
351
+ * and `logPublicKey` the log's SubjectPublicKeyInfo (DER `Buffer`). Reconstructs the exact
352
+ * signed data, imports the log key, and verifies the SCT signature -- an ECDSA signature is
353
+ * routed through the strict DER ECDSA-Sig-Value conformance gate before conversion to the
354
+ * raw r||s WebCrypto expects, an RSA signature verifies directly.
355
+ *
356
+ * Resolves `true` on a valid signature and `false` on a cryptographic mismatch (a false
357
+ * verdict is a verdict). Throws a typed `CtError` on structural failure -- a malformed
358
+ * entry/SCT, an unusable log key, or an unsupported hash/signature algorithm.
359
+ *
360
+ * @example
361
+ * var sct = pki.ct.parseSctList(sctExtValue).scts[0];
362
+ * // Resolve the CT log's DER SubjectPublicKeyInfo from a trusted log list, keyed by log id.
363
+ * var logKeysByLogId = {}; // { sct.logIdHex: <SPKI Buffer>, ... }
364
+ * var logKey = logKeysByLogId[sct.logIdHex];
365
+ * var ok = await pki.ct.verifySct({ entryType: 0, leafCert: certDer }, sct, logKey);
366
+ */
367
+ async function verifySct(entry, sct, logPublicKey) {
368
+ // reconstructSignedData validates the entry + SCT and rebuilds the exact preimage.
369
+ var message = reconstructSignedData(entry, sct);
370
+ var spki = _toBuffer(logPublicKey, "the CT log public key (SPKI)");
371
+ // RFC 6962 sec. 3.2: an SCT names its log by LogID = SHA-256(log SPKI). When the SCT
372
+ // carries a logId, it MUST match the key it is verified against, so an SCT is never
373
+ // accepted against a different log's key (a key-confusion the bare signature check misses).
374
+ if (sct.logId != null) {
375
+ var keyId = Buffer.from(await subtle.digest("SHA-256", spki));
376
+ if (!keyId.equals(_toBuffer(sct.logId, "sct.logId"))) {
377
+ throw new CtError("ct/log-id-mismatch", "the SCT logId does not match SHA-256 of the provided log key (RFC 6962 sec. 3.2)");
378
+ }
379
+ }
380
+ var sigInfo = sct.signatureAlgorithm || {};
381
+ var hashName = CT_HASH[sigInfo.hashName];
382
+ if (!hashName) throw new CtError("ct/unsupported-algorithm", "unsupported SCT hash algorithm " + JSON.stringify(sigInfo.hashName) + " (RFC 6962 sec. 2.1.4 mandates sha256)");
383
+ var alg = _spkiAlg(spki);
384
+ var imp, ver, sig = _toBuffer(sct.signature, "sct.signature");
385
+ if (sigInfo.signatureName === "ecdsa") {
386
+ if (alg.algOid !== oid.byName("ecPublicKey")) throw new CtError("ct/bad-input", "the SCT declares an ECDSA signature but the log key is not an EC key");
387
+ var ec = CT_EC_CURVE[alg.curveOid];
388
+ if (!ec) throw new CtError("ct/unsupported-algorithm", "unsupported SCT log EC curve (RFC 6962 sec. 2.1.4 mandates NIST P-256)");
389
+ imp = { name: "ECDSA", namedCurve: ec.curve };
390
+ ver = { name: "ECDSA", hash: hashName };
391
+ // The SCT signature is a DER ECDSA-Sig-Value; route it through the strict conformance
392
+ // gate (primitive, minimal, positive, bounded r/s) before converting to raw r||s.
393
+ sig = validator.sig.ecdsaSigToRaw(sig, ec.coordLen, CtError, "ct/bad-signature");
394
+ } else if (sigInfo.signatureName === "rsa") {
395
+ if (alg.algOid !== oid.byName("rsaEncryption")) throw new CtError("ct/bad-input", "the SCT declares an RSA signature but the log key is not an RSA key");
396
+ if (!(alg.rsaBits >= 2048)) throw new CtError("ct/unsupported-algorithm", "the SCT log RSA key is below the RFC 6962 sec. 2.1.4 minimum of 2048 bits");
397
+ imp = { name: "RSASSA-PKCS1-v1_5", hash: hashName };
398
+ ver = { name: "RSASSA-PKCS1-v1_5" };
399
+ } else {
400
+ throw new CtError("ct/unsupported-algorithm", "unsupported SCT signature algorithm " + JSON.stringify(sigInfo.signatureName) + " (RFC 6962 sec. 2.1.4 supports ecdsa/rsa)");
401
+ }
402
+ // A wrong signature resolves false from subtle.verify (a verdict); a structural failure
403
+ // -- an unimportable key, an algorithm/key mismatch -- is re-thrown fail-closed.
404
+ try {
405
+ var key = await subtle.importKey("spki", spki, imp, false, ["verify"]);
406
+ return await subtle.verify(ver, key, sig, message);
407
+ } catch (e) {
408
+ throw new CtError("ct/verify-error", "the SCT signature could not be evaluated", e);
409
+ }
410
+ }
411
+
290
412
  module.exports = {
291
413
  parseSctList: parseSctList,
292
414
  reconstructSignedData: reconstructSignedData,
415
+ verifySct: verifySct,
293
416
  HASH_ALGORITHMS: HASH_ALGORITHMS,
294
417
  SIGNATURE_ALGORITHMS: SIGNATURE_ALGORITHMS,
295
418
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/pki",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",
package/sbom.cdx.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
3
3
  "bomFormat": "CycloneDX",
4
4
  "specVersion": "1.5",
5
- "serialNumber": "urn:uuid:a5150e4c-cfd7-4241-8d30-2a5f74cea49e",
5
+ "serialNumber": "urn:uuid:f99392dd-064e-4cea-b273-77302f5d396d",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-07-13T17:30:07.505Z",
8
+ "timestamp": "2026-07-13T18:39:01.236Z",
9
9
  "lifecycles": [
10
10
  {
11
11
  "phase": "build"
@@ -19,14 +19,14 @@
19
19
  }
20
20
  ],
21
21
  "component": {
22
- "bom-ref": "@blamejs/pki@0.2.11",
22
+ "bom-ref": "@blamejs/pki@0.2.12",
23
23
  "type": "application",
24
24
  "name": "pki",
25
- "version": "0.2.11",
25
+ "version": "0.2.12",
26
26
  "scope": "required",
27
27
  "author": "blamejs contributors",
28
28
  "description": "Pure-JavaScript PKI toolkit that owns its stack — X.509, ASN.1/DER, CMS, PQC-first.",
29
- "purl": "pkg:npm/%40blamejs/pki@0.2.11",
29
+ "purl": "pkg:npm/%40blamejs/pki@0.2.12",
30
30
  "properties": [],
31
31
  "externalReferences": [
32
32
  {
@@ -54,7 +54,7 @@
54
54
  "components": [],
55
55
  "dependencies": [
56
56
  {
57
- "ref": "@blamejs/pki@0.2.11",
57
+ "ref": "@blamejs/pki@0.2.12",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]