@blamejs/pki 0.1.32 → 0.2.1

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/webcrypto.js CHANGED
@@ -36,6 +36,7 @@
36
36
  var nodeCrypto = require("node:crypto");
37
37
  var frameworkError = require("./framework-error");
38
38
  var guard = require("./guard-all");
39
+ var constants = require("./constants");
39
40
 
40
41
  // Single-owner error class -- co-located with its module (framework-error
41
42
  // stays the cross-module home; this is webcrypto-private). withCause: a
@@ -55,7 +56,13 @@ function _toArrayBuffer(buf) {
55
56
  return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
56
57
  }
57
58
 
58
- function _b64urlToBuf(s) { return Buffer.from(String(s), "base64url"); }
59
+ function _wcErr(code, msg) { return new WebCryptoError(code, msg); }
60
+ // STRICT base64url decode via the shared encoding guard: a missing / non-canonical
61
+ // / non-alphabet value throws webcrypto/data rather than silently importing WRONG
62
+ // key material (the lenient Buffer.from(String(undefined),"base64url") returned a
63
+ // bogus 6-byte key). Node's own canonical JWK export (_rawPublic) round-trips
64
+ // cleanly, so the strictness is benign there and fail-closed on untrusted import.
65
+ function _b64urlToBuf(s, who) { return guard.encoding.base64url(s, null, _wcErr, "webcrypto/data", who || "base64url value"); }
59
66
  function _bufToB64url(buf) { return Buffer.from(buf).toString("base64url"); }
60
67
 
61
68
  function _normalizeAlg(algorithm, who) {
@@ -548,11 +555,15 @@ SubtleCrypto.prototype.unwrapKey = async function unwrapKey(format, wrappedKey,
548
555
  var keyData;
549
556
  if (format === "jwk") {
550
557
  // A NON-authenticating unwrap algorithm (AES-CBC / AES-CTR) decrypts
551
- // tampered bytes "successfully", so this JSON.parse is the first point
552
- // that can notice -- its failure must surface as the module's typed
553
- // error (W3C: DataError), never a raw SyntaxError from the public API.
554
- try { keyData = JSON.parse(bytes.toString()); }
555
- catch (e) { throw new WebCryptoError("webcrypto/data", "unwrapKey: unwrapped bytes are not a valid JWK", e); }
558
+ // tampered bytes "successfully", so this parse is the first point that can
559
+ // notice. The shared JSON guard parses strictly (bounded, fatal UTF-8, and a
560
+ // smuggled duplicate member rejected rather than resolved last-wins), and its
561
+ // failure surfaces as the module's typed webcrypto/data (W3C: DataError).
562
+ keyData = guard.json.parse(bytes, WebCryptoError, {
563
+ maxBytes: constants.LIMITS.JSON_MAX_BYTES, maxDepth: constants.LIMITS.JSON_MAX_DEPTH,
564
+ badJson: "webcrypto/data", tooDeep: "webcrypto/data", duplicateMember: "webcrypto/data",
565
+ tooLarge: "webcrypto/data", badInput: "webcrypto/data", label: "the unwrapped JWK",
566
+ });
556
567
  } else {
557
568
  keyData = bytes;
558
569
  }
@@ -592,7 +603,7 @@ SubtleCrypto.prototype.importKey = async function importKey(format, keyData, alg
592
603
  if (format === "jwk") {
593
604
  var jwk = keyData;
594
605
  if (jwk.kty === "oct") {
595
- var kbuf = _b64urlToBuf(jwk.k);
606
+ var kbuf = _b64urlToBuf(jwk.k, "JWK oct key material");
596
607
  var s2 = nodeCrypto.createSecretKey(kbuf);
597
608
  var a2 = (name === "HMAC") ? { name: name, hash: _hashObj(alg.hash), length: kbuf.length * 8 } : { name: name, length: kbuf.length * 8 };
598
609
  return new CryptoKey("secret", extractable, a2, usages, s2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/pki",
3
- "version": "0.1.32",
3
+ "version": "0.2.1",
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:87ae1f84-9b42-4b45-820b-1323915f3fbe",
5
+ "serialNumber": "urn:uuid:1e68f63c-e550-4432-9b59-4cca3a0ddc64",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-07-11T18:49:24.325Z",
8
+ "timestamp": "2026-07-12T01:48:49.026Z",
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.1.32",
22
+ "bom-ref": "@blamejs/pki@0.2.1",
23
23
  "type": "application",
24
24
  "name": "pki",
25
- "version": "0.1.32",
25
+ "version": "0.2.1",
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.1.32",
29
+ "purl": "pkg:npm/%40blamejs/pki@0.2.1",
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.1.32",
57
+ "ref": "@blamejs/pki@0.2.1",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]