micro509 0.17.1 → 0.18.0

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 (126) hide show
  1. package/CHANGELOG.md +78 -6
  2. package/dist/crypto/crypto.d.ts +2 -3
  3. package/dist/crypto.d.ts +6 -0
  4. package/dist/der/der.d.ts +14 -4
  5. package/dist/der/der.js +19 -19
  6. package/dist/der.d.ts +26 -2
  7. package/dist/der.js +4 -4
  8. package/dist/index.d.ts +82 -15
  9. package/dist/index.js +19 -19
  10. package/dist/internal/asn1/asn1.d.ts +1 -2
  11. package/dist/internal/asn1/der.d.ts +1 -2
  12. package/dist/internal/asn1/oids.js +71 -353
  13. package/dist/internal/asn1/oids.js.map +1 -1
  14. package/dist/internal/asn1/oids.json.js +357 -0
  15. package/dist/internal/asn1/oids.json.js.map +1 -0
  16. package/dist/internal/crypto/algorithm-names.js +1 -1
  17. package/dist/internal/crypto/pbes2.d.ts +1 -2
  18. package/dist/internal/crypto/pbes2.js +70 -70
  19. package/dist/internal/crypto/prime-ec.js +37 -0
  20. package/dist/internal/crypto/prime-ec.js.map +1 -0
  21. package/dist/internal/crypto/rsa-pss.js +50 -50
  22. package/dist/internal/crypto/sig-verify.d.ts +1 -2
  23. package/dist/internal/crypto/sig-verify.js +60 -60
  24. package/dist/internal/crypto/signing.d.ts +1 -2
  25. package/dist/internal/crypto/signing.js +26 -26
  26. package/dist/internal/jose/json-data.js +108 -0
  27. package/dist/internal/jose/json-data.js.map +1 -0
  28. package/dist/internal/jose/strict-json.d.ts +1 -2
  29. package/dist/internal/shared/dn.d.ts +1 -2
  30. package/dist/internal/shared/dn.js +1 -1
  31. package/dist/internal/shared/ip.d.ts +1 -2
  32. package/dist/internal/verify/name-constraints-engine.js +64 -64
  33. package/dist/internal/verify/policy-engine.js +1 -1
  34. package/dist/internal/verify/verify-path.d.ts +1 -2
  35. package/dist/internal/verify/verify-path.js +19 -19
  36. package/dist/internal/x509/directory-name.js +10 -10
  37. package/dist/internal/x509/extension-errors.d.ts +1 -2
  38. package/dist/internal/x509/extension-registry.js +18 -18
  39. package/dist/internal/x509/general-name-profile.js +9 -9
  40. package/dist/internal/x509/general-name.js +32 -32
  41. package/dist/internal/x509/name-fields.js +1 -1
  42. package/dist/jose/base64url.d.ts +4 -0
  43. package/dist/jose/base64url.js +14 -0
  44. package/dist/jose/base64url.js.map +1 -0
  45. package/dist/jose/errors.d.ts +9 -3
  46. package/dist/jose/errors.js.map +1 -1
  47. package/dist/jose/jwe.d.ts +64 -0
  48. package/dist/jose/jwe.js +188 -0
  49. package/dist/jose/jwe.js.map +1 -0
  50. package/dist/jose/jwks.d.ts +38 -10
  51. package/dist/jose/jwks.js +156 -96
  52. package/dist/jose/jwks.js.map +1 -1
  53. package/dist/jose/jws.d.ts +8 -6
  54. package/dist/jose/jws.js +216 -170
  55. package/dist/jose/jws.js.map +1 -1
  56. package/dist/jose/jwt.d.ts +8 -2
  57. package/dist/jose/jwt.js +98 -98
  58. package/dist/jose/remote-jwks.d.ts +1 -2
  59. package/dist/jose/remote-jwks.js +106 -108
  60. package/dist/jose/remote-jwks.js.map +1 -1
  61. package/dist/jose.d.ts +15 -4
  62. package/dist/jose.js +7 -5
  63. package/dist/kdf/argon2.d.ts +7 -2
  64. package/dist/kdf.d.ts +6 -0
  65. package/dist/keys/keys.d.ts +31 -6
  66. package/dist/keys/keys.js +315 -233
  67. package/dist/keys/keys.js.map +1 -1
  68. package/dist/keys.d.ts +11 -2
  69. package/dist/keys.js +2 -2
  70. package/dist/pem/pem.d.ts +1 -2
  71. package/dist/pem/pem.js +40 -25
  72. package/dist/pem/pem.js.map +1 -1
  73. package/dist/pem.d.ts +6 -0
  74. package/dist/pkcs/pfx.d.ts +2 -3
  75. package/dist/pkcs/pfx.js +142 -142
  76. package/dist/pkcs/pkcs12-mac.d.ts +1 -2
  77. package/dist/pkcs/pkcs12-mac.js +122 -122
  78. package/dist/pkcs/pkcs7.d.ts +14 -3
  79. package/dist/pkcs/pkcs7.js +268 -248
  80. package/dist/pkcs/pkcs7.js.map +1 -1
  81. package/dist/pkcs.d.ts +10 -1
  82. package/dist/pkcs.js +4 -4
  83. package/dist/result/result.d.ts +1 -2
  84. package/dist/result.d.ts +6 -0
  85. package/dist/revocation/chain.d.ts +2 -3
  86. package/dist/revocation/chain.js +52 -52
  87. package/dist/revocation/crl.d.ts +2 -3
  88. package/dist/revocation/crl.js +319 -319
  89. package/dist/revocation/crl.js.map +1 -1
  90. package/dist/revocation/ocsp.d.ts +2 -3
  91. package/dist/revocation/ocsp.js +395 -395
  92. package/dist/revocation/revocation.d.ts +2 -3
  93. package/dist/revocation/revocation.js +22 -22
  94. package/dist/revocation.d.ts +12 -3
  95. package/dist/revocation.js +4 -4
  96. package/dist/ssh/ssh.d.ts +2 -3
  97. package/dist/ssh/ssh.js +165 -170
  98. package/dist/ssh/ssh.js.map +1 -1
  99. package/dist/ssh/wire.d.ts +1 -2
  100. package/dist/ssh/wire.js +10 -10
  101. package/dist/ssh.d.ts +8 -0
  102. package/dist/verify/identity.d.ts +1 -2
  103. package/dist/verify/identity.js +31 -31
  104. package/dist/verify/name-constraints.d.ts +9 -2
  105. package/dist/verify/policy.d.ts +9 -2
  106. package/dist/verify/verify.d.ts +3 -4
  107. package/dist/verify/verify.js +121 -121
  108. package/dist/verify.d.ts +9 -0
  109. package/dist/x509/certificate.d.ts +4 -5
  110. package/dist/x509/certificate.js +40 -40
  111. package/dist/x509/csr.d.ts +3 -4
  112. package/dist/x509/csr.js +15 -15
  113. package/dist/x509/extensions.d.ts +1 -2
  114. package/dist/x509/extensions.js +165 -165
  115. package/dist/x509/extensions.js.map +1 -1
  116. package/dist/x509/fingerprint.d.ts +1 -2
  117. package/dist/x509/name-text.d.ts +1 -2
  118. package/dist/x509/name.d.ts +1 -2
  119. package/dist/x509/name.js +15 -15
  120. package/dist/x509/parse.d.ts +3 -4
  121. package/dist/x509/parse.js +423 -423
  122. package/dist/x509.d.ts +17 -4
  123. package/dist/x509.js +8 -8
  124. package/package.json +22 -23
  125. package/dist/internal/asn1/oids2.js +0 -75
  126. package/dist/internal/asn1/oids2.js.map +0 -1
@@ -1,11 +1,11 @@
1
- import { failureResult as e, isResultError as t, rethrowIfInvariant as n, successResult as r, throwMicro509Error as i } from "../result/result.js";
2
- import { DECODE_LIMIT_CODES as a, decodeFailureResult as o } from "../internal/asn1/decode-refusal.js";
3
- import { concatBytes as s, integerFromNumber as c, nullValue as l, objectIdentifier as u, octetString as d, readSequenceChildren as f, sequence as p } from "../internal/asn1/der.js";
4
- import { decodeIntegerMagnitude as m, decodeObjectIdentifier as h, toArrayBuffer as g, toHex as _ } from "../internal/asn1/asn1.js";
5
- import { OIDS as v } from "../internal/asn1/oids2.js";
6
- import { getCrypto as y } from "../internal/crypto/webcrypto.js";
7
- import { DEFAULT_MAX_KDF_ITERATIONS as b, DEFAULT_MAX_PKCS12_MAC_ITERATIONS as x, WEBCRYPTO_MAX_PBKDF2_ITERATIONS as S, chargeKdfBudget as C, createKdfBudget as w, derivePbkdf2Bytes as T, isKdfIterationLimitError as E } from "../internal/crypto/pbes2.js";
8
- import { describeHashAlgorithm as D } from "../internal/crypto/algorithm-names.js";
1
+ import { decodeIntegerMagnitude as e, decodeObjectIdentifier as t, toArrayBuffer as n, toHex as r } from "../internal/asn1/asn1.js";
2
+ import { DECODE_LIMIT_CODES as i, decodeFailureResult as a } from "../internal/asn1/decode-refusal.js";
3
+ import { concatBytes as o, integerFromNumber as s, nullValue as c, objectIdentifier as l, octetString as u, readSequenceChildren as d, sequence as f } from "../internal/asn1/der.js";
4
+ import { OIDS as p } from "../internal/asn1/oids.js";
5
+ import { describeHashAlgorithm as m } from "../internal/crypto/algorithm-names.js";
6
+ import { DEFAULT_MAX_KDF_ITERATIONS as h, DEFAULT_MAX_PKCS12_MAC_ITERATIONS as g, WEBCRYPTO_MAX_PBKDF2_ITERATIONS as _, chargeKdfBudget as v, createKdfBudget as y, derivePbkdf2Bytes as b, isKdfIterationLimitError as x } from "../internal/crypto/pbes2.js";
7
+ import { getCrypto as S } from "../internal/crypto/webcrypto.js";
8
+ import { failureResult as C, isResultError as w, rethrowIfInvariant as T, successResult as E, throwMicro509Error as D } from "../result/result.js";
9
9
  // src/pkcs/pkcs12-mac.ts
10
10
  /**
11
11
  * PKCS#12 MAC data creation and verification.
@@ -17,7 +17,7 @@ import { describeHashAlgorithm as D } from "../internal/crypto/algorithm-names.j
17
17
  * @module
18
18
  */
19
19
  function throwPkcs12MacError(e, t) {
20
- i(e, t);
20
+ D(e, t);
21
21
  }
22
22
  /**
23
23
  * Computes a PKCS#12 MAC over the AuthenticatedSafe and returns the DER-encoded MacData
@@ -32,19 +32,19 @@ async function createPkcs12MacData(e, t) {
32
32
  if (t.type === "pbmac1") return await createPbmac1MacData(e, t);
33
33
  let n = t.iterations ?? 2048;
34
34
  (!Number.isSafeInteger(n) || n <= 0) && throwPkcs12MacError("invalid_iterations", `MacData iterations must be a positive safe integer, got ${n}`);
35
- let r = t.salt ?? y().getRandomValues(/* @__PURE__ */ new Uint8Array(16)), i = await computePkcs12Mac(e, t.password, r, n);
35
+ let i = t.salt ?? S().getRandomValues(/* @__PURE__ */ new Uint8Array(16)), a = await computePkcs12Mac(e, t.password, i, n);
36
36
  return {
37
- der: p([
38
- p([p([u(v.sha256), l()]), d(i)]),
39
- d(r),
40
- ...n === 1 ? [] : [c(n)]
37
+ der: f([
38
+ f([f([l(p.sha256), c()]), u(a)]),
39
+ u(i),
40
+ ...n === 1 ? [] : [s(n)]
41
41
  ]),
42
42
  parsed: {
43
43
  type: "pkcs12-kdf",
44
- digestAlgorithmOid: v.sha256,
45
- digestAlgorithmName: D(v.sha256),
46
- digestHex: _(i),
47
- saltHex: _(r),
44
+ digestAlgorithmOid: p.sha256,
45
+ digestAlgorithmName: m(p.sha256),
46
+ digestHex: r(a),
47
+ saltHex: r(i),
48
48
  iterations: n,
49
49
  verification: "valid"
50
50
  }
@@ -52,31 +52,31 @@ async function createPkcs12MacData(e, t) {
52
52
  }
53
53
  async function createPbmac1MacData(e, t) {
54
54
  let n = t.iterations ?? 1e5;
55
- (!Number.isInteger(n) || n < 1 || n > 4294967295) && throwPkcs12MacError("invalid_iterations", `PBMAC1 iterations must be an integer from 1 to ${S}, got ${n}`);
56
- let r = t.salt ?? y().getRandomValues(/* @__PURE__ */ new Uint8Array(16)), i = {
57
- salt: r,
55
+ (!Number.isInteger(n) || n < 1 || n > 4294967295) && throwPkcs12MacError("invalid_iterations", `PBMAC1 iterations must be an integer from 1 to ${_}, got ${n}`);
56
+ let i = t.salt ?? S().getRandomValues(/* @__PURE__ */ new Uint8Array(16)), a = {
57
+ salt: i,
58
58
  iterations: n,
59
59
  keyLength: 32,
60
60
  prf: "HMAC-SHA-256",
61
61
  messageAuthScheme: "HMAC-SHA-256"
62
- }, a = await computePbmac1(e, t.password, i), o = p([u(v.hmacWithSHA256), l()]), s = p([u(v.pbmac1), p([p([u(v.pbkdf2), p([
63
- d(r),
64
- c(n),
65
- c(i.keyLength),
66
- o
67
- ])]), o])]);
62
+ }, o = await computePbmac1(e, t.password, a), d = f([l(p.hmacWithSHA256), c()]), m = f([l(p.pbmac1), f([f([l(p.pbkdf2), f([
63
+ u(i),
64
+ s(n),
65
+ s(a.keyLength),
66
+ d
67
+ ])]), d])]);
68
68
  return {
69
- der: p([p([s, d(a)]), d(r)]),
69
+ der: f([f([m, u(o)]), u(i)]),
70
70
  parsed: {
71
71
  type: "pbmac1",
72
- digestAlgorithmOid: v.pbmac1,
72
+ digestAlgorithmOid: p.pbmac1,
73
73
  digestAlgorithmName: "PBMAC1",
74
- digestHex: _(a),
75
- saltHex: _(r),
74
+ digestHex: r(o),
75
+ saltHex: r(i),
76
76
  iterations: n,
77
- keyLength: i.keyLength,
78
- prf: i.prf,
79
- messageAuthScheme: i.messageAuthScheme,
77
+ keyLength: a.keyLength,
78
+ prf: a.prf,
79
+ messageAuthScheme: a.messageAuthScheme,
80
80
  verification: "valid"
81
81
  }
82
82
  };
@@ -88,7 +88,7 @@ const O = [
88
88
  "weak_mac_key_length"
89
89
  ];
90
90
  function throwMacDataError(e, t) {
91
- i(e, t);
91
+ D(e, t);
92
92
  }
93
93
  /**
94
94
  * Throwing core for {@linkcode parsePkcs12MacData}. When `password` is
@@ -102,33 +102,33 @@ function throwMacDataError(e, t) {
102
102
  * {@linkcode ParsePkcs12MacDataErrorCode} for an unsupported MAC, a PBMAC1 key
103
103
  * length below 20 octets, or a password the MAC cannot encode.
104
104
  */
105
- async function parsePkcs12MacDataOrThrow(e, t, n, r) {
106
- let i = w(r, x), a = w(r, b), o = f(e), s = o[0], c = o[1], l = o[2];
107
- if (o.length !== 2 && o.length !== 3 || s === void 0 || c === void 0 || c.tag !== 4 || l !== void 0 && l.tag !== 2) throw Error("Malformed MacData");
108
- let u = e.slice(s.start - s.headerLength, s.end), d = f(u), p = d[0], m = d[1];
109
- if (d.length !== 2 || p === void 0 || m === void 0 || m.tag !== 4) throw Error("Malformed DigestInfo");
110
- let g = u.slice(p.start - p.headerLength, p.end), y = f(g), S = y[0];
111
- if (S === void 0 || y.length !== 1 && y.length !== 2) throw Error("MacData algorithm missing");
112
- let T = h(S.value);
113
- if (T === v.pbmac1) return await verifyPbmac1MacData(g, y[1], m.value, t, n, a);
114
- T !== v.sha256 && throwMacDataError("unsupported_mac_algorithm", `Only SHA-256 PKCS#12 MAC and PBMAC1 are supported, got ${D(T)}`);
115
- let E = l === void 0 ? 1 : decodeMacIterations(l.value, i, n, "MacData iterations");
116
- if (E === 0) throw Error("MacData iterations must be a positive safe integer");
105
+ async function parsePkcs12MacDataOrThrow(e, n, i, a) {
106
+ let o = y(a, g), s = y(a, h), c = d(e), l = c[0], u = c[1], f = c[2];
107
+ if (c.length !== 2 && c.length !== 3 || l === void 0 || u === void 0 || u.tag !== 4 || f !== void 0 && f.tag !== 2) throw Error("Malformed MacData");
108
+ let _ = e.slice(l.start - l.headerLength, l.end), b = d(_), x = b[0], S = b[1];
109
+ if (b.length !== 2 || x === void 0 || S === void 0 || S.tag !== 4) throw Error("Malformed DigestInfo");
110
+ let C = _.slice(x.start - x.headerLength, x.end), w = d(C), T = w[0];
111
+ if (T === void 0 || w.length !== 1 && w.length !== 2) throw Error("MacData algorithm missing");
112
+ let E = t(T.value);
113
+ if (E === p.pbmac1) return await verifyPbmac1MacData(C, w[1], S.value, n, i, s);
114
+ E !== p.sha256 && throwMacDataError("unsupported_mac_algorithm", `Only SHA-256 PKCS#12 MAC and PBMAC1 are supported, got ${m(E)}`);
115
+ let D = f === void 0 ? 1 : decodeMacIterations(f.value, o, i, "MacData iterations");
116
+ if (D === 0) throw Error("MacData iterations must be a positive safe integer");
117
117
  let O = {
118
118
  type: "pkcs12-kdf",
119
- digestAlgorithmOid: T,
120
- digestAlgorithmName: D(T),
121
- digestHex: _(m.value),
122
- saltHex: _(c.value),
123
- iterations: E,
119
+ digestAlgorithmOid: E,
120
+ digestAlgorithmName: m(E),
121
+ digestHex: r(S.value),
122
+ saltHex: r(u.value),
123
+ iterations: D,
124
124
  verification: "unchecked"
125
125
  };
126
- if (n === void 0) return O;
127
- C(i, E);
128
- let k = await computePkcs12Mac(t, n, c.value, E);
126
+ if (i === void 0) return O;
127
+ v(o, D);
128
+ let k = await computePkcs12Mac(n, i, u.value, D);
129
129
  return {
130
130
  ...O,
131
- verification: equalBytes(k, m.value) ? "valid" : "invalid"
131
+ verification: equalBytes(k, S.value) ? "valid" : "invalid"
132
132
  };
133
133
  }
134
134
  /**
@@ -150,97 +150,97 @@ async function parsePkcs12MacDataOrThrow(e, t, n, r) {
150
150
  * {@linkcode Number.MAX_SAFE_INTEGER} is `'malformed'`, and `verification` is
151
151
  * `'unchecked'`. For the throwing form use {@linkcode parsePkcs12MacDataOrThrow}.
152
152
  */
153
- async function parsePkcs12MacData(i, s, c, l) {
153
+ async function parsePkcs12MacData(e, t, n, r) {
154
154
  try {
155
- return r(await parsePkcs12MacDataOrThrow(i, s, c, l));
156
- } catch (r) {
157
- if (n(r), E(r)) return e("kdf_iterations_exceeded", r.message);
158
- if (t(r)) {
159
- let t = O.find((e) => e === r.code);
160
- if (t !== void 0) return e(t, r.error.message);
155
+ return E(await parsePkcs12MacDataOrThrow(e, t, n, r));
156
+ } catch (e) {
157
+ if (T(e), x(e)) return C("kdf_iterations_exceeded", e.message);
158
+ if (w(e)) {
159
+ let t = O.find((t) => t === e.code);
160
+ if (t !== void 0) return C(t, e.error.message);
161
161
  }
162
- return o(r, a, "Malformed MacData");
162
+ return a(e, i, "Malformed MacData");
163
163
  }
164
164
  }
165
- function decodeMacIterations(e, t, n, r) {
166
- let i = m(e, r);
167
- if (i.type === "safe") return i.value;
168
- throw n !== void 0 && C(t, Infinity), Error(`${r} too large for safe number (${e.length} bytes)`);
165
+ function decodeMacIterations(t, n, r, i) {
166
+ let a = e(t, i);
167
+ if (a.type === "safe") return a.value;
168
+ throw r !== void 0 && v(n, Infinity), Error(`${i} too large for safe number (${t.length} bytes)`);
169
169
  }
170
- async function verifyPbmac1MacData(e, t, n, r, i, a) {
170
+ async function verifyPbmac1MacData(e, t, n, i, a, o) {
171
171
  if (t === void 0) throw Error("PBMAC1 parameters must be present");
172
- let o = parsePbmac1Parameters(e, t), s = {
172
+ let s = parsePbmac1Parameters(e, t), c = {
173
173
  type: "pbmac1",
174
- digestAlgorithmOid: v.pbmac1,
174
+ digestAlgorithmOid: p.pbmac1,
175
175
  digestAlgorithmName: "PBMAC1",
176
- digestHex: _(n),
177
- saltHex: _(o.salt),
178
- iterations: o.iterations,
179
- keyLength: o.keyLength,
180
- prf: o.prf,
181
- messageAuthScheme: o.messageAuthScheme,
176
+ digestHex: r(n),
177
+ saltHex: r(s.salt),
178
+ iterations: s.iterations,
179
+ keyLength: s.keyLength,
180
+ prf: s.prf,
181
+ messageAuthScheme: s.messageAuthScheme,
182
182
  verification: "unchecked"
183
183
  };
184
- if (i === void 0) return s;
185
- C(a, o.iterations);
186
- let c = await computePbmac1(r, i, o);
184
+ if (a === void 0) return c;
185
+ v(o, s.iterations);
186
+ let l = await computePbmac1(i, a, s);
187
187
  return {
188
- ...s,
189
- verification: equalBytes(c, n) ? "valid" : "invalid"
188
+ ...c,
189
+ verification: equalBytes(l, n) ? "valid" : "invalid"
190
190
  };
191
191
  }
192
192
  function parsePbmac1Parameters(e, t) {
193
193
  if (t.tag !== 48) throw Error("Malformed PBMAC1-params");
194
- let n = e.slice(t.start - t.headerLength, t.end), r = f(n), i = r[0], a = r[1];
194
+ let n = e.slice(t.start - t.headerLength, t.end), r = d(n), i = r[0], a = r[1];
195
195
  if (r.length !== 2 || i === void 0 || a === void 0) throw Error("Malformed PBMAC1-params");
196
196
  let o = readAlgorithmIdentifier(n, i, "PBMAC1 keyDerivationFunc");
197
- o.oid !== v.pbkdf2 && throwMacDataError("unsupported_mac_algorithm", `Unsupported PBMAC1 key derivation function ${o.oid}`);
197
+ o.oid !== p.pbkdf2 && throwMacDataError("unsupported_mac_algorithm", `Unsupported PBMAC1 key derivation function ${o.oid}`);
198
198
  let s = parseHmacAlgorithm(readAlgorithmIdentifier(n, a, "PBMAC1 messageAuthScheme"), "PBMAC1 messageAuthScheme");
199
199
  return {
200
200
  ...parsePbkdf2Parameters(o),
201
201
  messageAuthScheme: s
202
202
  };
203
203
  }
204
- function parsePbkdf2Parameters(e) {
205
- if (e.parameters === void 0 || e.parameters.tag !== 48) throw Error("Malformed PBKDF2-params");
206
- let t = e.der.slice(e.parameters.start - e.parameters.headerLength, e.parameters.end), [n, r, ...i] = f(t);
207
- if (n === void 0 || r === void 0 || r.tag !== 2) throw Error("Malformed PBKDF2-params");
208
- if (n.tag === 48 && throwMacDataError("unsupported_mac_algorithm", "PBKDF2 otherSource salt is not supported"), n.tag !== 4) throw Error("Malformed PBKDF2 salt");
209
- let a = i[0]?.tag === 2 ? i[0] : void 0, o = a === void 0 ? i : i.slice(1), s = o[0];
210
- if (o.length > 1 || s !== void 0 && s.tag !== 48) throw Error("Malformed PBKDF2-params");
211
- if (a === void 0) throw Error("PBKDF2-params in PBMAC1 must include keyLength");
212
- s === void 0 && throwMacDataError("unsupported_mac_algorithm", "PBKDF2 prf is absent and defaults to HMAC-SHA-1, which PBMAC1 verification does not accept");
213
- let c = parseHmacAlgorithm(readAlgorithmIdentifier(t, s, "PBKDF2 prf"), "PBKDF2 prf"), l = m(r.value, "PBKDF2 iterationCount");
214
- if (l.type === "unsafe" || l.value > 4294967295) throw Error(`PBKDF2 iterationCount must be at most ${S}`);
215
- if (l.value === 0) throw Error("PBKDF2 iterationCount must be at least 1");
204
+ function parsePbkdf2Parameters(t) {
205
+ if (t.parameters === void 0 || t.parameters.tag !== 48) throw Error("Malformed PBKDF2-params");
206
+ let n = t.der.slice(t.parameters.start - t.parameters.headerLength, t.parameters.end), [r, i, ...a] = d(n);
207
+ if (r === void 0 || i === void 0 || i.tag !== 2) throw Error("Malformed PBKDF2-params");
208
+ if (r.tag === 48 && throwMacDataError("unsupported_mac_algorithm", "PBKDF2 otherSource salt is not supported"), r.tag !== 4) throw Error("Malformed PBKDF2 salt");
209
+ let o = a[0]?.tag === 2 ? a[0] : void 0, s = o === void 0 ? a : a.slice(1), c = s[0];
210
+ if (s.length > 1 || c !== void 0 && c.tag !== 48) throw Error("Malformed PBKDF2-params");
211
+ if (o === void 0) throw Error("PBKDF2-params in PBMAC1 must include keyLength");
212
+ c === void 0 && throwMacDataError("unsupported_mac_algorithm", "PBKDF2 prf is absent and defaults to HMAC-SHA-1, which PBMAC1 verification does not accept");
213
+ let l = parseHmacAlgorithm(readAlgorithmIdentifier(n, c, "PBKDF2 prf"), "PBKDF2 prf"), u = e(i.value, "PBKDF2 iterationCount");
214
+ if (u.type === "unsafe" || u.value > 4294967295) throw Error(`PBKDF2 iterationCount must be at most ${_}`);
215
+ if (u.value === 0) throw Error("PBKDF2 iterationCount must be at least 1");
216
216
  return {
217
- salt: new Uint8Array(n.value),
218
- iterations: l.value,
219
- keyLength: decodePbmac1KeyLength(a.value),
220
- prf: c
217
+ salt: new Uint8Array(r.value),
218
+ iterations: u.value,
219
+ keyLength: decodePbmac1KeyLength(o.value),
220
+ prf: l
221
221
  };
222
222
  }
223
- function decodePbmac1KeyLength(e) {
224
- let t = m(e, "PBKDF2 keyLength");
225
- if ((t.type === "unsafe" || t.value > 64) && throwMacDataError("unsupported_mac_algorithm", "PBKDF2 keyLength above 64 octets is not supported"), t.value === 0) throw Error("PBKDF2 keyLength must be at least 1");
226
- return t.value < 20 && throwMacDataError("weak_mac_key_length", `PBKDF2 keyLength ${t.value} is below 20 octets`), t.value;
223
+ function decodePbmac1KeyLength(t) {
224
+ let n = e(t, "PBKDF2 keyLength");
225
+ if ((n.type === "unsafe" || n.value > 64) && throwMacDataError("unsupported_mac_algorithm", "PBKDF2 keyLength above 64 octets is not supported"), n.value === 0) throw Error("PBKDF2 keyLength must be at least 1");
226
+ return n.value < 20 && throwMacDataError("weak_mac_key_length", `PBKDF2 keyLength ${n.value} is below 20 octets`), n.value;
227
227
  }
228
- function readAlgorithmIdentifier(e, t, n) {
229
- if (t.tag !== 48) throw Error(`Malformed ${n}`);
230
- let r = e.slice(t.start - t.headerLength, t.end), i = f(r), a = i[0];
231
- if (a === void 0 || a.tag !== 6 || i.length > 2) throw Error(`Malformed ${n}`);
228
+ function readAlgorithmIdentifier(e, n, r) {
229
+ if (n.tag !== 48) throw Error(`Malformed ${r}`);
230
+ let i = e.slice(n.start - n.headerLength, n.end), a = d(i), o = a[0];
231
+ if (o === void 0 || o.tag !== 6 || a.length > 2) throw Error(`Malformed ${r}`);
232
232
  return {
233
- oid: h(a.value),
234
- parameters: i[1],
235
- der: r
233
+ oid: t(o.value),
234
+ parameters: a[1],
235
+ der: i
236
236
  };
237
237
  }
238
238
  function parseHmacAlgorithm(e, t) {
239
239
  if (e.parameters !== void 0 && (e.parameters.tag !== 5 || e.parameters.length !== 0)) throw Error(`${t} parameters must be NULL`);
240
240
  switch (e.oid) {
241
- case v.hmacWithSHA256: return "HMAC-SHA-256";
242
- case v.hmacWithSHA384: return "HMAC-SHA-384";
243
- case v.hmacWithSHA512: return "HMAC-SHA-512";
241
+ case p.hmacWithSHA256: return "HMAC-SHA-256";
242
+ case p.hmacWithSHA384: return "HMAC-SHA-384";
243
+ case p.hmacWithSHA512: return "HMAC-SHA-512";
244
244
  }
245
245
  return throwMacDataError("unsupported_mac_algorithm", `Unsupported ${t} ${e.oid}`);
246
246
  }
@@ -253,7 +253,7 @@ function hmacHash(e) {
253
253
  }
254
254
  }
255
255
  async function computePbmac1(e, t, n) {
256
- return await hmac(e, await T(encodePbmac1Password(t), n.salt, n.iterations, hmacHash(n.prf), n.keyLength), hmacHash(n.messageAuthScheme));
256
+ return await hmac(e, await b(encodePbmac1Password(t), n.salt, n.iterations, hmacHash(n.prf), n.keyLength), hmacHash(n.messageAuthScheme));
257
257
  }
258
258
  function encodePbmac1Password(e) {
259
259
  for (let t = 0; t < e.length; t += 1) {
@@ -273,12 +273,12 @@ function encodePbmac1Password(e) {
273
273
  async function computePkcs12Mac(e, t, n, r) {
274
274
  return await hmac(e, await derivePkcs12Key(t, n, r, 3, 32), "SHA-256");
275
275
  }
276
- async function hmac(e, t, n) {
277
- let r = await y().subtle.importKey("raw", g(t), {
276
+ async function hmac(e, t, r) {
277
+ let i = await S().subtle.importKey("raw", n(t), {
278
278
  name: "HMAC",
279
- hash: n
279
+ hash: r
280
280
  }, !1, ["sign"]);
281
- return new Uint8Array(await y().subtle.sign("HMAC", r, g(e)));
281
+ return new Uint8Array(await S().subtle.sign("HMAC", i, n(e)));
282
282
  }
283
283
  /**
284
284
  * PKCS#12 key derivation with SHA-256 (RFC 7292 Appendix B). `id` selects the purpose:
@@ -288,9 +288,9 @@ async function hmac(e, t, n) {
288
288
  * UTF-16 surrogate, U+FFFE or U+FFFF.
289
289
  */
290
290
  async function derivePkcs12Key(e, t, n, r, i) {
291
- let a = (/* @__PURE__ */ new Uint8Array(64)).fill(r), o = encodePkcs12Password(e), c = s([repeatToMultiple(t, 64), repeatToMultiple(o, 64)]), l = Math.ceil(i / 32), u = new Uint8Array(l * 32);
291
+ let a = (/* @__PURE__ */ new Uint8Array(64)).fill(r), s = encodePkcs12Password(e), c = o([repeatToMultiple(t, 64), repeatToMultiple(s, 64)]), l = Math.ceil(i / 32), u = new Uint8Array(l * 32);
292
292
  for (let e = 0; e < l; e += 1) {
293
- let t = await digestSha256(s([a, c]));
293
+ let t = await digestSha256(o([a, c]));
294
294
  for (let e = 1; e < n; e += 1) t = await digestSha256(t);
295
295
  if (u.set(t, e * 32), e + 1 === l) break;
296
296
  let r = repeatToLength(t, 64);
@@ -300,7 +300,7 @@ async function derivePkcs12Key(e, t, n, r, i) {
300
300
  }
301
301
  /** SHA-256 hash via WebCrypto. */
302
302
  async function digestSha256(e) {
303
- return new Uint8Array(await y().subtle.digest("SHA-256", g(e)));
303
+ return new Uint8Array(await S().subtle.digest("SHA-256", n(e)));
304
304
  }
305
305
  /** Encodes a password as a null-terminated BMPString, two big-endian bytes per character (RFC 7292 B.1). */
306
306
  function encodePkcs12Password(e) {
@@ -161,7 +161,7 @@ export type ParsePkcs7CertBagResult = {
161
161
  * supplied via {@linkcode VerifyPkcs7SignedDataOptions}.
162
162
  * `no_signers` means the SignedData carries no SignerInfo to verify.
163
163
  */
164
- export type VerifyPkcs7SignedDataErrorCode = "no_signers" | "signer_not_found" | "signature_invalid" | "message_digest_mismatch" | "detached_content_required" | ParsePkcs7ErrorCode;
164
+ export type VerifyPkcs7SignedDataErrorCode = "invalid_options" | "content_type_mismatch" | "signed_attributes_required" | "signed_attributes_forbidden" | "no_signers" | "signer_not_found" | "signature_invalid" | "message_digest_mismatch" | "detached_content_required" | ParsePkcs7ErrorCode;
165
165
  /** Error payload for a failed {@linkcode verifyPkcs7SignedData} call. */
166
166
  export interface VerifyPkcs7SignedDataFailure extends Micro509Error<VerifyPkcs7SignedDataErrorCode> {
167
167
  /** Always `false` for failures. */
@@ -169,6 +169,14 @@ export interface VerifyPkcs7SignedDataFailure extends Micro509Error<VerifyPkcs7S
169
169
  }
170
170
  /** Options for {@linkcode verifyPkcs7SignedData}. */
171
171
  export interface VerifyPkcs7SignedDataOptions {
172
+ /** Expected eContentType OID. Defaults to id-data (1.2.840.113549.1.7.1). */
173
+ readonly expectedContentTypeOid?: string;
174
+ /**
175
+ * Signed-attribute policy for every signer. Defaults to 'required'.
176
+ * 'allowed' accepts either form for id-data; 'forbidden' accepts only bare
177
+ * id-data signatures. RFC 5652 §5.3 always requires attributes for other types.
178
+ */
179
+ readonly signedAttributes?: "required" | "allowed" | "forbidden";
172
180
  /**
173
181
  * External content for a detached SignedData (RFC 5652 Section 5.2, absent `eContent`).
174
182
  * Required to verify a detached signature; ignored when the SignedData embeds its own content.
@@ -316,6 +324,10 @@ export declare function parsePkcs7SignedDataPem(pem: string): ParsePkcs7SignedDa
316
324
  * Accepts PEM text, raw DER, or an already-parsed {@linkcode ParsedPkcs7SignedData}.
317
325
  * For each signer, locates the matching certificate in the embedded set and
318
326
  * verifies the signature (including signed-attribute digest checks per RFC 5652 Section 5.4).
327
+ * Defaults to id-data and requires signed attributes on every signer. Select
328
+ * `expectedContentTypeOid` from the application's protocol, not the input envelope.
329
+ * Legacy bare id-data signatures require `signedAttributes: 'allowed'` or 'forbidden'.
330
+ * Non-id-data always requires attributes (RFC 5652 §5.3).
319
331
  *
320
332
  * For a detached SignedData (absent `eContent`), pass the externally-held
321
333
  * content via `options.content`; without it, verification fails with the
@@ -337,5 +349,4 @@ export declare function parsePkcs7SignedDataPem(pem: string): ParsePkcs7SignedDa
337
349
  * const detached = await verifyPkcs7SignedData(cmsBlob, { content: signedBytes });
338
350
  * ```
339
351
  */
340
- export declare function verifyPkcs7SignedData(input: string | Uint8Array | ParsedPkcs7SignedData, options?: VerifyPkcs7SignedDataOptions): Promise<VerifyPkcs7SignedDataResult>;
341
- //# sourceMappingURL=pkcs7.d.ts.map
352
+ export declare function verifyPkcs7SignedData(input: string | Uint8Array | ParsedPkcs7SignedData, options?: VerifyPkcs7SignedDataOptions): Promise<VerifyPkcs7SignedDataResult>;