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.
- package/CHANGELOG.md +78 -6
- package/dist/crypto/crypto.d.ts +2 -3
- package/dist/crypto.d.ts +6 -0
- package/dist/der/der.d.ts +14 -4
- package/dist/der/der.js +19 -19
- package/dist/der.d.ts +26 -2
- package/dist/der.js +4 -4
- package/dist/index.d.ts +82 -15
- package/dist/index.js +19 -19
- package/dist/internal/asn1/asn1.d.ts +1 -2
- package/dist/internal/asn1/der.d.ts +1 -2
- package/dist/internal/asn1/oids.js +71 -353
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/asn1/oids.json.js +357 -0
- package/dist/internal/asn1/oids.json.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +1 -1
- package/dist/internal/crypto/pbes2.d.ts +1 -2
- package/dist/internal/crypto/pbes2.js +70 -70
- package/dist/internal/crypto/prime-ec.js +37 -0
- package/dist/internal/crypto/prime-ec.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +50 -50
- package/dist/internal/crypto/sig-verify.d.ts +1 -2
- package/dist/internal/crypto/sig-verify.js +60 -60
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +26 -26
- package/dist/internal/jose/json-data.js +108 -0
- package/dist/internal/jose/json-data.js.map +1 -0
- package/dist/internal/jose/strict-json.d.ts +1 -2
- package/dist/internal/shared/dn.d.ts +1 -2
- package/dist/internal/shared/dn.js +1 -1
- package/dist/internal/shared/ip.d.ts +1 -2
- package/dist/internal/verify/name-constraints-engine.js +64 -64
- package/dist/internal/verify/policy-engine.js +1 -1
- package/dist/internal/verify/verify-path.d.ts +1 -2
- package/dist/internal/verify/verify-path.js +19 -19
- package/dist/internal/x509/directory-name.js +10 -10
- package/dist/internal/x509/extension-errors.d.ts +1 -2
- package/dist/internal/x509/extension-registry.js +18 -18
- package/dist/internal/x509/general-name-profile.js +9 -9
- package/dist/internal/x509/general-name.js +32 -32
- package/dist/internal/x509/name-fields.js +1 -1
- package/dist/jose/base64url.d.ts +4 -0
- package/dist/jose/base64url.js +14 -0
- package/dist/jose/base64url.js.map +1 -0
- package/dist/jose/errors.d.ts +9 -3
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.d.ts +64 -0
- package/dist/jose/jwe.js +188 -0
- package/dist/jose/jwe.js.map +1 -0
- package/dist/jose/jwks.d.ts +38 -10
- package/dist/jose/jwks.js +156 -96
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.d.ts +8 -6
- package/dist/jose/jws.js +216 -170
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.d.ts +8 -2
- package/dist/jose/jwt.js +98 -98
- package/dist/jose/remote-jwks.d.ts +1 -2
- package/dist/jose/remote-jwks.js +106 -108
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/jose.d.ts +15 -4
- package/dist/jose.js +7 -5
- package/dist/kdf/argon2.d.ts +7 -2
- package/dist/kdf.d.ts +6 -0
- package/dist/keys/keys.d.ts +31 -6
- package/dist/keys/keys.js +315 -233
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +11 -2
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +1 -2
- package/dist/pem/pem.js +40 -25
- package/dist/pem/pem.js.map +1 -1
- package/dist/pem.d.ts +6 -0
- package/dist/pkcs/pfx.d.ts +2 -3
- package/dist/pkcs/pfx.js +142 -142
- package/dist/pkcs/pkcs12-mac.d.ts +1 -2
- package/dist/pkcs/pkcs12-mac.js +122 -122
- package/dist/pkcs/pkcs7.d.ts +14 -3
- package/dist/pkcs/pkcs7.js +268 -248
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +10 -1
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +1 -2
- package/dist/result.d.ts +6 -0
- package/dist/revocation/chain.d.ts +2 -3
- package/dist/revocation/chain.js +52 -52
- package/dist/revocation/crl.d.ts +2 -3
- package/dist/revocation/crl.js +319 -319
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +2 -3
- package/dist/revocation/ocsp.js +395 -395
- package/dist/revocation/revocation.d.ts +2 -3
- package/dist/revocation/revocation.js +22 -22
- package/dist/revocation.d.ts +12 -3
- package/dist/revocation.js +4 -4
- package/dist/ssh/ssh.d.ts +2 -3
- package/dist/ssh/ssh.js +165 -170
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.d.ts +1 -2
- package/dist/ssh/wire.js +10 -10
- package/dist/ssh.d.ts +8 -0
- package/dist/verify/identity.d.ts +1 -2
- package/dist/verify/identity.js +31 -31
- package/dist/verify/name-constraints.d.ts +9 -2
- package/dist/verify/policy.d.ts +9 -2
- package/dist/verify/verify.d.ts +3 -4
- package/dist/verify/verify.js +121 -121
- package/dist/verify.d.ts +9 -0
- package/dist/x509/certificate.d.ts +4 -5
- package/dist/x509/certificate.js +40 -40
- package/dist/x509/csr.d.ts +3 -4
- package/dist/x509/csr.js +15 -15
- package/dist/x509/extensions.d.ts +1 -2
- package/dist/x509/extensions.js +165 -165
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.d.ts +1 -2
- package/dist/x509/name-text.d.ts +1 -2
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +15 -15
- package/dist/x509/parse.d.ts +3 -4
- package/dist/x509/parse.js +423 -423
- package/dist/x509.d.ts +17 -4
- package/dist/x509.js +8 -8
- package/package.json +22 -23
- package/dist/internal/asn1/oids2.js +0 -75
- package/dist/internal/asn1/oids2.js.map +0 -1
package/dist/pkcs/pkcs12-mac.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DECODE_LIMIT_CODES as
|
|
3
|
-
import { concatBytes as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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
|
-
|
|
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
|
|
35
|
+
let i = t.salt ?? S().getRandomValues(/* @__PURE__ */ new Uint8Array(16)), a = await computePkcs12Mac(e, t.password, i, n);
|
|
36
36
|
return {
|
|
37
|
-
der:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
...n === 1 ? [] : [
|
|
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:
|
|
45
|
-
digestAlgorithmName:
|
|
46
|
-
digestHex:
|
|
47
|
-
saltHex:
|
|
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 ${
|
|
56
|
-
let
|
|
57
|
-
salt:
|
|
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
|
-
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
])]),
|
|
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:
|
|
69
|
+
der: f([f([m, u(o)]), u(i)]),
|
|
70
70
|
parsed: {
|
|
71
71
|
type: "pbmac1",
|
|
72
|
-
digestAlgorithmOid:
|
|
72
|
+
digestAlgorithmOid: p.pbmac1,
|
|
73
73
|
digestAlgorithmName: "PBMAC1",
|
|
74
|
-
digestHex:
|
|
75
|
-
saltHex:
|
|
74
|
+
digestHex: r(o),
|
|
75
|
+
saltHex: r(i),
|
|
76
76
|
iterations: n,
|
|
77
|
-
keyLength:
|
|
78
|
-
prf:
|
|
79
|
-
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
|
-
|
|
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,
|
|
106
|
-
let
|
|
107
|
-
if (
|
|
108
|
-
let
|
|
109
|
-
if (
|
|
110
|
-
let
|
|
111
|
-
if (
|
|
112
|
-
let
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
if (
|
|
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:
|
|
120
|
-
digestAlgorithmName:
|
|
121
|
-
digestHex:
|
|
122
|
-
saltHex:
|
|
123
|
-
iterations:
|
|
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 (
|
|
127
|
-
|
|
128
|
-
let k = await computePkcs12Mac(
|
|
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,
|
|
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(
|
|
153
|
+
async function parsePkcs12MacData(e, t, n, r) {
|
|
154
154
|
try {
|
|
155
|
-
return
|
|
156
|
-
} catch (
|
|
157
|
-
if (
|
|
158
|
-
if (
|
|
159
|
-
let t = O.find((
|
|
160
|
-
if (t !== void 0) return
|
|
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
|
|
162
|
+
return a(e, i, "Malformed MacData");
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
function decodeMacIterations(
|
|
166
|
-
let
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
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,
|
|
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
|
|
172
|
+
let s = parsePbmac1Parameters(e, t), c = {
|
|
173
173
|
type: "pbmac1",
|
|
174
|
-
digestAlgorithmOid:
|
|
174
|
+
digestAlgorithmOid: p.pbmac1,
|
|
175
175
|
digestAlgorithmName: "PBMAC1",
|
|
176
|
-
digestHex:
|
|
177
|
-
saltHex:
|
|
178
|
-
iterations:
|
|
179
|
-
keyLength:
|
|
180
|
-
prf:
|
|
181
|
-
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 (
|
|
185
|
-
|
|
186
|
-
let
|
|
184
|
+
if (a === void 0) return c;
|
|
185
|
+
v(o, s.iterations);
|
|
186
|
+
let l = await computePbmac1(i, a, s);
|
|
187
187
|
return {
|
|
188
|
-
...
|
|
189
|
-
verification: equalBytes(
|
|
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 =
|
|
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 !==
|
|
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(
|
|
205
|
-
if (
|
|
206
|
-
let
|
|
207
|
-
if (
|
|
208
|
-
if (
|
|
209
|
-
let
|
|
210
|
-
if (
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
let
|
|
214
|
-
if (
|
|
215
|
-
if (
|
|
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(
|
|
218
|
-
iterations:
|
|
219
|
-
keyLength: decodePbmac1KeyLength(
|
|
220
|
-
prf:
|
|
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(
|
|
224
|
-
let
|
|
225
|
-
if ((
|
|
226
|
-
return
|
|
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,
|
|
229
|
-
if (
|
|
230
|
-
let
|
|
231
|
-
if (
|
|
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:
|
|
234
|
-
parameters:
|
|
235
|
-
der:
|
|
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
|
|
242
|
-
case
|
|
243
|
-
case
|
|
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
|
|
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,
|
|
277
|
-
let
|
|
276
|
+
async function hmac(e, t, r) {
|
|
277
|
+
let i = await S().subtle.importKey("raw", n(t), {
|
|
278
278
|
name: "HMAC",
|
|
279
|
-
hash:
|
|
279
|
+
hash: r
|
|
280
280
|
}, !1, ["sign"]);
|
|
281
|
-
return new Uint8Array(await
|
|
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),
|
|
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(
|
|
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
|
|
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) {
|
package/dist/pkcs/pkcs7.d.ts
CHANGED
|
@@ -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>;
|