@blamejs/pki 0.6.14 → 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 (112) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/lib/acme.js +59 -815
  3. package/lib/asn1-der.js +7 -245
  4. package/lib/attrcert-sign.js +12 -260
  5. package/lib/attrcert-verify.js +1 -7
  6. package/lib/byte-reader.js +0 -8
  7. package/lib/byte-writer.js +0 -11
  8. package/lib/cbor-det.js +0 -54
  9. package/lib/cmc-build.js +15 -357
  10. package/lib/cmc-verify.js +6 -239
  11. package/lib/cmp-build.js +41 -317
  12. package/lib/cmp-session.js +73 -760
  13. package/lib/cmp-verify.js +32 -488
  14. package/lib/cms-compress.js +3 -32
  15. package/lib/cms-decrypt.js +29 -294
  16. package/lib/cms-encrypt.js +14 -234
  17. package/lib/cms-sign.js +29 -324
  18. package/lib/cms-verify.js +9 -500
  19. package/lib/composite-kem.js +2 -102
  20. package/lib/composite-sig.js +1 -77
  21. package/lib/constants.js +0 -249
  22. package/lib/crl-sign.js +9 -237
  23. package/lib/crl-verify.js +1 -10
  24. package/lib/crmf-sign.js +19 -198
  25. package/lib/crmf-verify.js +1 -12
  26. package/lib/csr-sign.js +3 -34
  27. package/lib/csr-verify.js +1 -12
  28. package/lib/ct.js +28 -253
  29. package/lib/edwards-point.js +10 -44
  30. package/lib/est.js +28 -764
  31. package/lib/framework-error.js +4 -182
  32. package/lib/guard-all.js +1 -58
  33. package/lib/guard-async.js +1 -36
  34. package/lib/guard-bytes.js +6 -650
  35. package/lib/guard-compress.js +5 -102
  36. package/lib/guard-crypto.js +1 -40
  37. package/lib/guard-der.js +2 -93
  38. package/lib/guard-encoding.js +2 -60
  39. package/lib/guard-header.js +1 -36
  40. package/lib/guard-identifier.js +7 -531
  41. package/lib/guard-intrinsic.js +1 -150
  42. package/lib/guard-json.js +10 -73
  43. package/lib/guard-limits.js +1 -77
  44. package/lib/guard-list.js +1 -49
  45. package/lib/guard-name.js +3 -209
  46. package/lib/guard-parsed.js +7 -335
  47. package/lib/guard-range.js +1 -71
  48. package/lib/guard-secret.js +1 -102
  49. package/lib/guard-text.js +1 -64
  50. package/lib/guard-time.js +1 -97
  51. package/lib/hpke.js +3 -105
  52. package/lib/http-digest.js +14 -142
  53. package/lib/http-retry-after.js +1 -47
  54. package/lib/http-transport.js +21 -131
  55. package/lib/inspect.js +30 -284
  56. package/lib/ip-utils.js +6 -47
  57. package/lib/jose.js +7 -142
  58. package/lib/key.js +2 -67
  59. package/lib/lint.js +9 -194
  60. package/lib/merkle.js +1 -27
  61. package/lib/mime.js +9 -82
  62. package/lib/ocsp-request-verify.js +1 -14
  63. package/lib/ocsp-verify.js +1 -82
  64. package/lib/ocsp.js +11 -169
  65. package/lib/oid.js +5 -337
  66. package/lib/path-validate.js +103 -1492
  67. package/lib/pbes2.js +2 -89
  68. package/lib/pkcs12-build.js +31 -379
  69. package/lib/pki-build.js +64 -290
  70. package/lib/rc2.js +2 -18
  71. package/lib/rfc3339.js +4 -27
  72. package/lib/scep.js +8 -252
  73. package/lib/schema-all.js +0 -122
  74. package/lib/schema-attrcert.js +4 -146
  75. package/lib/schema-c509.js +153 -802
  76. package/lib/schema-cmc.js +5 -220
  77. package/lib/schema-cmp.js +2 -223
  78. package/lib/schema-cms.js +13 -427
  79. package/lib/schema-crl.js +5 -68
  80. package/lib/schema-crmf.js +6 -167
  81. package/lib/schema-csr.js +1 -54
  82. package/lib/schema-csrattrs.js +2 -87
  83. package/lib/schema-engine.js +0 -152
  84. package/lib/schema-ocsp.js +0 -117
  85. package/lib/schema-pkcs12.js +2 -93
  86. package/lib/schema-pkcs8.js +3 -35
  87. package/lib/schema-pkix.js +24 -655
  88. package/lib/schema-smime.js +0 -54
  89. package/lib/schema-tsp.js +3 -99
  90. package/lib/schema-x509.js +4 -63
  91. package/lib/shbs.js +11 -95
  92. package/lib/sign-scheme.js +2 -97
  93. package/lib/sigstore.js +9 -169
  94. package/lib/sleep.js +2 -8
  95. package/lib/smime.js +15 -408
  96. package/lib/tls-cert-compress.js +0 -62
  97. package/lib/trust.js +19 -185
  98. package/lib/tsp-sign.js +16 -270
  99. package/lib/validator-all.js +1 -30
  100. package/lib/validator-attcert.js +2 -46
  101. package/lib/validator-cose.js +2 -153
  102. package/lib/validator-keydesc.js +1 -37
  103. package/lib/validator-sig.js +1 -46
  104. package/lib/validator-tls.js +1 -88
  105. package/lib/validator-tpm.js +19 -122
  106. package/lib/verify-seam.js +1 -24
  107. package/lib/webauthn-mds.js +3 -400
  108. package/lib/webauthn.js +12 -833
  109. package/lib/webcrypto.js +5 -485
  110. package/lib/x509-sign.js +4 -108
  111. package/package.json +1 -1
  112. package/sbom.cdx.json +6 -6
@@ -1,74 +1,51 @@
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. Composed by validator-cose to validate an
6
- // OKP (Ed25519 / Ed448) credential public-key point.
7
- //
8
- // edwards-point -- point validation for the Edwards curves EdDSA uses. node:crypto imports
9
- // an RFC 8410 OKP SubjectPublicKeyInfo without checking the point is a valid, full-order
10
- // Edwards point (an all-zeroes Ed25519/Ed448 key parses, and an all-zeroes key with an
11
- // all-zeroes signature even verifies true, a trivial forgery), so an OKP credential key
12
- // needs an explicit check. This decodes the compressed point per RFC 8032 sec. 5.1.3
13
- // (Ed25519) / sec. 5.2.3 (Ed448); the decode fails closed on an off-curve or non-canonical
14
- // encoding. It then rejects a low-order point via the cofactor check [8]P == identity (an
15
- // all-zeroes key is a low-order point on the curve, so the decode alone does not catch it).
16
- // A conformant authenticator never emits a low-order credential key.
17
- //
18
- // Pure BigInt modular arithmetic (constant-time is not a goal here: the input is a public
19
- // key, and the verdict is a public validity bit, not a secret).
4
+ // @internal
20
5
 
21
6
  var asn1 = require("./asn1-der");
22
7
 
23
- // ---- field parameters ------------------------------------------------------
24
8
  var P25519 = (1n << 255n) - 19n;
25
- // d = -121665 / 121666 (mod p); sqrt(-1) = 2^((p-1)/4) (mod p).
26
9
  var D25519 = _mul(P25519 - 121665n, _inv(121666n, P25519), P25519);
27
10
  var SQRTM1 = _pow(2n, (P25519 - 1n) / 4n, P25519);
28
11
  var P448 = (1n << 448n) - (1n << 224n) - 1n;
29
- var D448 = P448 - 39081n; // d = -39081 (mod p)
12
+ var D448 = P448 - 39081n;
30
13
 
31
14
  var CURVE = {
32
- 6: { p: P25519, d: D25519, a: P25519 - 1n, len: 32, signBit: 255n }, // Ed25519, a = -1
33
- 7: { p: P448, d: D448, a: 1n, len: 57, signBit: 455n }, // Ed448, a = 1
15
+ 6: { p: P25519, d: D25519, a: P25519 - 1n, len: 32, signBit: 255n },
16
+ 7: { p: P448, d: D448, a: 1n, len: 57, signBit: 455n },
34
17
  };
35
18
 
36
19
  function _mul(x, y, p) { return (x % p) * (y % p) % p; }
37
20
  function _pow(b, e, p) { var r = 1n; b %= p; while (e > 0n) { if (e & 1n) r = r * b % p; b = b * b % p; e >>= 1n; } return r; }
38
- function _inv(a, p) { return _pow(((a % p) + p) % p, p - 2n, p); } // Fermat inverse (p prime)
39
- // A fixed 32/57-byte little-endian public key -> BigInt in one shot (big-endian hex of the
40
- // reversed bytes), never a per-byte shift-accumulate (the quadratic-BigInt antipattern).
21
+ function _inv(a, p) { return _pow(((a % p) + p) % p, p - 2n, p); }
41
22
  function _leToBig(buf) { return BigInt("0x" + Buffer.from(buf).reverse().toString("hex")); }
42
23
 
43
- // Decode a compressed Edwards point (RFC 8032) -> { x, y } or null (off-curve / non-canonical).
44
24
  function _decode(raw, c) {
45
25
  var num = _leToBig(raw);
46
26
  var sign = (num >> c.signBit) & 1n;
47
27
  var y = num & ((1n << c.signBit) - 1n);
48
- if (y >= c.p) return null; // non-canonical y
28
+ if (y >= c.p) return null;
49
29
  var p = c.p, y2 = y * y % p, x;
50
30
  var u = ((y2 - 1n) % p + p) % p;
51
31
  if (c.a === 1n) {
52
- // Ed448: v = d*y^2 - 1; x = u^3 v (u^5 v^3)^((p-3)/4); require v*x^2 == u.
53
32
  var v = ((c.d * y2 % p - 1n) % p + p) % p;
54
33
  x = _mul(_mul(_pow(u, 3n, p), v, p), _pow(_mul(_pow(u, 5n, p), _pow(v, 3n, p), p), (p - 3n) / 4n, p), p);
55
34
  if (_mul(v, x * x % p, p) !== u) return null;
56
35
  } else {
57
- // Ed25519: v = d*y^2 + 1; x = u v^3 (u v^7)^((p-5)/8); v*x^2 == u, or == -u then x *= sqrt(-1).
58
36
  var v25 = (c.d * y2 % p + 1n) % p;
59
37
  x = _mul(_mul(u, _pow(v25, 3n, p), p), _pow(_mul(u, _pow(v25, 7n, p), p), (p - 5n) / 8n, p), p);
60
38
  var vxx = _mul(v25, x * x % p, p);
61
- if (vxx === u) { /* x is a root */ }
62
- else if (vxx === (p - u) % p) { x = x * SQRTM1 % p; }
63
- else return null;
39
+ if (vxx !== u) {
40
+ if (vxx === (p - u) % p) { x = x * SQRTM1 % p; }
41
+ else return null;
42
+ }
64
43
  }
65
44
  if (x === 0n && sign === 1n) return null;
66
45
  if ((x & 1n) !== sign) x = (p - x) % p;
67
46
  return { x: x, y: y };
68
47
  }
69
48
 
70
- // Affine doubling on a*x^2 + y^2 = 1 + d*x^2*y^2: x3 = 2xy/(a x^2 + y^2),
71
- // y3 = (y^2 - a x^2)/(2 - a x^2 - y^2).
72
49
  function _double(P, c) {
73
50
  var p = c.p, x2 = P.x * P.x % p, y2 = P.y * P.y % p, ax2 = c.a * x2 % p;
74
51
  var nx = 2n * P.x % p * P.y % p, dx = (ax2 + y2) % p;
@@ -76,27 +53,16 @@ function _double(P, c) {
76
53
  return { x: _mul(nx, _inv(dx, p), p), y: _mul(ny, _inv(dy, p), p) };
77
54
  }
78
55
 
79
- // validate(raw, crv) -> true iff `raw` is a canonical, on-curve, full-order Edwards point for
80
- // the OKP curve (6 = Ed25519, 7 = Ed448). Off-curve, non-canonical, wrong-length, and
81
- // low-order (cofactor) points all return false.
82
56
  function validate(raw, crv) {
83
57
  var c = CURVE[crv];
84
58
  if (!c || !Buffer.isBuffer(raw) || raw.length !== c.len) return false;
85
59
  var pt = _decode(raw, c);
86
60
  if (!pt) return false;
87
- // Low-order iff [8]P is the identity (0, 1). One double per cofactor bit (8 = 2^3).
88
61
  var q = _double(_double(_double(pt, c), c), c);
89
62
  if (q.x === 0n && q.y === 1n) return false;
90
63
  return true;
91
64
  }
92
65
 
93
- // validateSpki(spkiBytes, crv, E, code) -> throws new E(code, ...) unless the
94
- // SubjectPublicKeyInfo's subjectPublicKey (its BIT STRING body, past the unused-bits octet) is a
95
- // canonical, on-curve, full-order Edwards point for the OKP curve (6 = Ed25519, 7 = Ed448). This
96
- // is the one home every EdDSA verify path routes an SPKI through before importKey/verify, because
97
- // node imports a low-order (e.g. all-zeroes) OKP SPKI without complaint and such a key verifies a
98
- // forged signature. Error-parameterized like the guard family: the caller passes its own typed
99
- // error CONSTRUCTOR `E` and domain `code`, so the shared gate keeps no error domain of its own.
100
66
  function validateSpki(spkiBytes, crv, E, code) {
101
67
  var point;
102
68
  try {