@blamejs/pki 0.5.17 → 0.5.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.
package/lib/x509-sign.js CHANGED
@@ -53,6 +53,27 @@ var OID_SKI = O("subjectKeyIdentifier");
53
53
 
54
54
  // The recognized keys of the `extensions` spec object; an unknown key is a typo and throws at
55
55
  // config-time (a custom extension is passed as pre-encoded DER via the array form).
56
+ // The three caller-owned objects pki.x509.sign reads, each with its own door. A key nothing here
57
+ // names is a typo or a misplaced argument, and the failure it causes is invisible: the certificate
58
+ // builds, signs, and simply does not carry what was asked for. `spec.extension` (one letter short
59
+ // of `extensions`) emitted a certificate with NO extensions at all -- no basicConstraints on an
60
+ // intended CA, no keyUsage on an intended constrained leaf. `spec.issuer` is the other shape: the
61
+ // issuer is argument TWO, and nesting it in the spec left the certificate SELF-SIGNED with nothing
62
+ // to read as a failure.
63
+ //
64
+ // Every table is derived from what the function actually reads, not from the doc block, because a
65
+ // table naming a key nothing reads reopens the hole it was added to close.
66
+ var KNOWN_SPEC_KEYS = {
67
+ subject: 1, subjectPublicKey: 1, notBefore: 1, notAfter: 1, serialNumber: 1, extensions: 1,
68
+ };
69
+ // The issuer names itself in one of two FORMS, and the cert form wins unconditionally: when
70
+ // `issuer.cert` is present the builder takes the DN and the public key from it and never reads
71
+ // `name` or `publicKey`. A union accepted `{ key, cert, name: "Different CA", publicKey }` and
72
+ // signed under the certificate's identity while discarding the identity the caller wrote out.
73
+ var KNOWN_ISSUER_CERT_KEYS = { key: 1, cert: 1 };
74
+ var KNOWN_ISSUER_EXPLICIT_KEYS = { key: 1, name: 1, publicKey: 1 };
75
+ var KNOWN_SIGN_OPTS = { digestAlgorithm: 1, pem: 1, pss: 1 };
76
+
56
77
  var KNOWN_EXT_KEYS = {
57
78
  subjectKeyIdentifier: 1, authorityKeyIdentifier: 1, keyUsage: 1, keyUsageCritical: 1,
58
79
  extendedKeyUsage: 1, extendedKeyUsageCritical: 1, basicConstraints: 1, subjectAltName: 1,
@@ -282,6 +303,22 @@ function _sign(spec, issuer, opts) {
282
303
  opts = opts || {};
283
304
  if (!spec || typeof spec !== "object" || Buffer.isBuffer(spec)) throw _err("x509/bad-input", "the certificate spec must be an object");
284
305
  issuer = issuer || {};
306
+ // Before a single field is read, so a misspelling is a refusal rather than an omission carried
307
+ // into a signed certificate. The issuer message names its own argument because the mistake this
308
+ // catches most often is putting the issuer inside the spec, where it self-signed in silence.
309
+ guard.identifier.assertKnownKeys(spec, KNOWN_SPEC_KEYS, _err, "x509/bad-input", function (k) {
310
+ return "unknown certificate spec field " + JSON.stringify(k) +
311
+ (k === "issuer" ? "; the issuer is the SECOND argument to pki.x509.sign, not a spec field" : "") +
312
+ (k === "extension" ? "; the extensions spec field is `extensions`" : "");
313
+ });
314
+ var byCert = issuer.cert != null;
315
+ guard.identifier.assertKnownKeys(issuer, byCert ? KNOWN_ISSUER_CERT_KEYS : KNOWN_ISSUER_EXPLICIT_KEYS,
316
+ _err, "x509/bad-input", function (k) {
317
+ return "unknown issuer field " + JSON.stringify(k) + " for the " + (byCert
318
+ ? "certificate form; issuer.cert supplies the name and the public key, so they are not read here"
319
+ : "explicit form; the issuer takes { key, name, publicKey }, or { key, cert } to take both from a certificate");
320
+ });
321
+ guard.identifier.assertKnownKeys(opts, KNOWN_SIGN_OPTS, _err, "x509/bad-input", "pki.x509.sign has an unknown option ");
285
322
  if (issuer.key == null) throw _err("x509/bad-input", "a signing key (issuer.key, a PKCS#8 private key) is required");
286
323
 
287
324
  var spki = _reqDer(spec.subjectPublicKey, "spec.subjectPublicKey (the SPKI DER of the certified key)");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/pki",
3
- "version": "0.5.17",
3
+ "version": "0.5.19",
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:b8b3d2cf-001e-4a5b-8644-a627ed3ce3c5",
5
+ "serialNumber": "urn:uuid:d0064cbc-a37c-4d4f-ae67-0b9ba6887de2",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-08-20T14:50:41.972Z",
8
+ "timestamp": "2026-08-20T21:35:06.293Z",
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.5.17",
22
+ "bom-ref": "@blamejs/pki@0.5.19",
23
23
  "type": "application",
24
24
  "name": "pki",
25
- "version": "0.5.17",
25
+ "version": "0.5.19",
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.5.17",
29
+ "purl": "pkg:npm/%40blamejs/pki@0.5.19",
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.5.17",
57
+ "ref": "@blamejs/pki@0.5.19",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]