micro509 0.18.0 → 0.19.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 +88 -1
- package/dist/crypto/crypto.d.ts +11 -2
- package/dist/crypto/crypto.js +30 -17
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/crypto.d.ts +2 -2
- package/dist/der/der.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/internal/asn1/asn1.js +10 -2
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/ber.js.map +1 -1
- package/dist/internal/asn1/decode-refusal.js.map +1 -1
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js.map +1 -1
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/ecdsa.js.map +1 -1
- package/dist/internal/crypto/hash.js.map +1 -1
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/prime-ec.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +40 -0
- package/dist/internal/crypto/sig-verify.js +152 -65
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/crypto/signing.js.map +1 -1
- package/dist/internal/jose/base64url.js.map +1 -1
- package/dist/internal/jose/json-data.js.map +1 -1
- package/dist/internal/jose/strict-json.js.map +1 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/idna.js.map +1 -1
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/shared/mailbox.js.map +1 -1
- package/dist/internal/shared/punycode.js.map +1 -1
- package/dist/internal/shared/uri-host.js.map +1 -1
- package/dist/internal/verify/name-constraints-engine.js.map +1 -1
- package/dist/internal/verify/policy-engine.js.map +1 -1
- package/dist/internal/verify/spki-distrust.js.map +1 -1
- package/dist/internal/verify/verify-path.js +222 -116
- package/dist/internal/verify/verify-path.js.map +1 -1
- package/dist/internal/x509/directory-name.js.map +1 -1
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.js.map +1 -1
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-profile.js.map +1 -1
- package/dist/internal/x509/general-name.js.map +1 -1
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/internal/x509/or-address.js.map +1 -1
- package/dist/jose/base64url.js.map +1 -1
- package/dist/jose/errors.js.map +1 -1
- package/dist/jose/jwe.js.map +1 -1
- package/dist/jose/jwks.js.map +1 -1
- package/dist/jose/jws.js.map +1 -1
- package/dist/jose/jwt.js.map +1 -1
- package/dist/jose/remote-jwks.js.map +1 -1
- package/dist/kdf/argon2-arithmetic.js.map +1 -1
- package/dist/kdf/argon2-core.js.map +1 -1
- package/dist/kdf/argon2-memory.js.map +1 -1
- package/dist/kdf/argon2-portable.js.map +1 -1
- package/dist/kdf/argon2.js.map +1 -1
- package/dist/keys/keys.js.map +1 -1
- package/dist/pem/pem.js.map +1 -1
- package/dist/pkcs/pfx.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.js +1 -1
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +10 -0
- package/dist/pkcs/pkcs7.js +106 -88
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/result/result.js.map +1 -1
- package/dist/revocation/chain.d.ts +67 -13
- package/dist/revocation/chain.js +429 -301
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +65 -11
- package/dist/revocation/crl.js +492 -202
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +79 -24
- package/dist/revocation/ocsp.js +417 -231
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +68 -13
- package/dist/revocation/revocation.js +194 -73
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +4 -4
- package/dist/ssh/ssh.js.map +1 -1
- package/dist/ssh/wire.js.map +1 -1
- package/dist/verify/identity.d.ts +2 -2
- package/dist/verify/identity.js +2 -2
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/verify.d.ts +84 -32
- package/dist/verify/verify.js +221 -171
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +3 -2
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.js.map +1 -1
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/fingerprint.js.map +1 -1
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +6 -2
- package/dist/x509/parse.js +121 -121
- package/dist/x509/parse.js.map +1 -1
- package/package.json +11 -11
package/dist/pkcs/pkcs7.js
CHANGED
|
@@ -3,15 +3,15 @@ import { decodeRefusalOf as c } from "../internal/asn1/decode-refusal.js";
|
|
|
3
3
|
import { explicitContext as l, integer as u, integerFromNumber as d, objectIdentifier as f, octetString as p, readElement as m, readRootElement as h, readSequenceChildren as g, sequence as _, setOf as v } from "../internal/asn1/der.js";
|
|
4
4
|
import { OIDS as y } from "../internal/asn1/oids.js";
|
|
5
5
|
import { describeHashAlgorithm as b, describeSignatureAlgorithm as x } from "../internal/crypto/algorithm-names.js";
|
|
6
|
-
import {
|
|
7
|
-
import { encodeAlgorithmIdentifier as
|
|
8
|
-
import { getCrypto as
|
|
9
|
-
import { base64Encode as
|
|
10
|
-
import { compareDistinguishedNames as
|
|
11
|
-
import { pemEncode as
|
|
12
|
-
import { DECODE_REFUSAL_CODES as
|
|
13
|
-
import { nameFieldKeyFromOid as
|
|
14
|
-
import { parseCertificateDerOrThrow as
|
|
6
|
+
import { callerVerification as S, getVerifySignatureConfigResult as C, verifySignedDataDetailed as w } from "../internal/crypto/sig-verify.js";
|
|
7
|
+
import { encodeAlgorithmIdentifier as T, getSignatureAlgorithm as E, signBytes as D } from "../internal/crypto/signing.js";
|
|
8
|
+
import { getCrypto as O } from "../internal/crypto/webcrypto.js";
|
|
9
|
+
import { base64Encode as k } from "../internal/shared/base64.js";
|
|
10
|
+
import { compareDistinguishedNames as A } from "../internal/shared/dn.js";
|
|
11
|
+
import { pemEncode as j, splitPemBlocksOrThrow as M } from "../pem/pem.js";
|
|
12
|
+
import { DECODE_REFUSAL_CODES as N, failureResult as P, rethrowIfInvariant as F } from "../result/result.js";
|
|
13
|
+
import { nameFieldKeyFromOid as I } from "../internal/x509/name-fields.js";
|
|
14
|
+
import { parseCertificateDerOrThrow as L } from "../x509/parse.js";
|
|
15
15
|
// src/pkcs/pkcs7.ts
|
|
16
16
|
/**
|
|
17
17
|
* PKCS#7/CMS certificate bags and SignedData.
|
|
@@ -25,7 +25,7 @@ import { parseCertificateDerOrThrow as I } from "../x509/parse.js";
|
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
/** RFC 7468 Section 8 armors an RFC 2315 ContentInfo; Section 9 armors an RFC 5652 one. */
|
|
28
|
-
const
|
|
28
|
+
const R = ["PKCS7", "CMS"];
|
|
29
29
|
/**
|
|
30
30
|
* Creates a degenerate PKCS#7 SignedData structure containing only
|
|
31
31
|
* certificates (no signers), returning DER, PEM, and base64 forms, or a
|
|
@@ -36,9 +36,9 @@ function createPkcs7CertBag(e) {
|
|
|
36
36
|
let t;
|
|
37
37
|
try {
|
|
38
38
|
t = e.flatMap(normalizeCertificateSource);
|
|
39
|
-
for (let e of t)
|
|
39
|
+
for (let e of t) L(e);
|
|
40
40
|
} catch (e) {
|
|
41
|
-
let t = c(e,
|
|
41
|
+
let t = c(e, N);
|
|
42
42
|
return t === void 0 ? createCertBagFailure("invalid_certificate", "Each PKCS#7 certificate source must be valid PEM or DER") : createCertBagFailure(t.code, t.message);
|
|
43
43
|
}
|
|
44
44
|
let n = new Uint8Array(v(t));
|
|
@@ -54,8 +54,8 @@ function createPkcs7CertBag(e) {
|
|
|
54
54
|
ok: !0,
|
|
55
55
|
value: {
|
|
56
56
|
der: i,
|
|
57
|
-
pem:
|
|
58
|
-
base64:
|
|
57
|
+
pem: j("PKCS7", i),
|
|
58
|
+
base64: k(i)
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -81,7 +81,7 @@ function createPkcs7CertBag(e) {
|
|
|
81
81
|
*/
|
|
82
82
|
async function createPkcs7SignedData(e) {
|
|
83
83
|
if (e.signers.length === 0) return createPkcs7Failure("no_signers", "createPkcs7SignedData requires at least one signer");
|
|
84
|
-
let t = e.encapsulatedContentTypeOid ?? y.pkcs7Data, n = e.content
|
|
84
|
+
let t = e.encapsulatedContentTypeOid ?? y.pkcs7Data, n = new Uint8Array(e.content), r = [], i = /* @__PURE__ */ new Set(), addCertificate = (e) => {
|
|
85
85
|
let t = s(e);
|
|
86
86
|
i.has(t) || (i.add(t), r.push(e));
|
|
87
87
|
}, a = /* @__PURE__ */ new Set(), o = [];
|
|
@@ -91,9 +91,9 @@ async function createPkcs7SignedData(e) {
|
|
|
91
91
|
addCertificate(e.certificateDer), a.add(e.digestOid), o.push(e.signerInfoDer);
|
|
92
92
|
}
|
|
93
93
|
for (let t of e.additionalCertificates ?? []) try {
|
|
94
|
-
for (let e of normalizeCertificateSource(t))
|
|
94
|
+
for (let e of normalizeCertificateSource(t)) L(e), addCertificate(e);
|
|
95
95
|
} catch (e) {
|
|
96
|
-
let t = c(e,
|
|
96
|
+
let t = c(e, N);
|
|
97
97
|
return t === void 0 ? createPkcs7Failure("invalid_certificate", "Each additional PKCS#7 certificate source must be valid PEM or DER") : createPkcs7Failure(t.code, t.message);
|
|
98
98
|
}
|
|
99
99
|
let u = t === y.pkcs7Data ? 1 : 3, m = new Uint8Array(v(r));
|
|
@@ -109,8 +109,8 @@ async function createPkcs7SignedData(e) {
|
|
|
109
109
|
ok: !0,
|
|
110
110
|
value: {
|
|
111
111
|
der: g,
|
|
112
|
-
pem:
|
|
113
|
-
base64:
|
|
112
|
+
pem: j(u === 1 ? "PKCS7" : "CMS", g),
|
|
113
|
+
base64: k(g)
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
}
|
|
@@ -131,23 +131,23 @@ async function buildPkcs7SignerInfo(e, t, n) {
|
|
|
131
131
|
if (a === void 0 || r.length !== 1) return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer must provide exactly one certificate");
|
|
132
132
|
let s;
|
|
133
133
|
try {
|
|
134
|
-
s =
|
|
134
|
+
s = L(a);
|
|
135
135
|
} catch (e) {
|
|
136
|
-
let t = c(e,
|
|
136
|
+
let t = c(e, N);
|
|
137
137
|
return t === void 0 ? createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate must be a parseable X.509 certificate") : createPkcs7Failure(t.code, t.message);
|
|
138
138
|
}
|
|
139
139
|
let l;
|
|
140
140
|
try {
|
|
141
|
-
l =
|
|
141
|
+
l = E(e.privateKey, e.signature);
|
|
142
142
|
} catch {
|
|
143
143
|
return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key or signature profile");
|
|
144
144
|
}
|
|
145
|
-
if (!
|
|
145
|
+
if (!C(l.algorithmOid, l.parameters, s.publicKeyAlgorithmOid, s.publicKeyParametersOid, "signer").ok) return createPkcs7Failure("signer_certificate_key_mismatch", "Each PKCS#7 signer certificate must carry a public key that verifies the signer key algorithm");
|
|
146
146
|
let m = contentDigestForPrivateKey(e.privateKey);
|
|
147
147
|
if (m === void 0) return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key algorithm for content digest");
|
|
148
|
-
let { setForSigning: h, implicitForEmit: g } = buildSignedAttributes(n, new Uint8Array(await
|
|
148
|
+
let { setForSigning: h, implicitForEmit: g } = buildSignedAttributes(n, new Uint8Array(await O().subtle.digest(m.hashName, o(t)))), v;
|
|
149
149
|
try {
|
|
150
|
-
v = await
|
|
150
|
+
v = await D(e.privateKey, l, h);
|
|
151
151
|
} catch {
|
|
152
152
|
return createPkcs7Failure("unsupported_signer_key", "Signer key could not produce a PKCS#7 signature");
|
|
153
153
|
}
|
|
@@ -158,7 +158,7 @@ async function buildPkcs7SignerInfo(e, t, n) {
|
|
|
158
158
|
_([i(s.issuer.derHex), u(i(s.serialNumberHex))]),
|
|
159
159
|
_([f(m.digestOid)]),
|
|
160
160
|
g,
|
|
161
|
-
|
|
161
|
+
T(l),
|
|
162
162
|
p(v)
|
|
163
163
|
]),
|
|
164
164
|
digestOid: m.digestOid,
|
|
@@ -176,7 +176,7 @@ function parsePkcs7CertBagDer(e) {
|
|
|
176
176
|
/** The DER of the single `PKCS7` or `CMS` block in `pem`, or a typed failure. */
|
|
177
177
|
function contentInfoPemBytes(e) {
|
|
178
178
|
try {
|
|
179
|
-
let t =
|
|
179
|
+
let t = M(e).filter((e) => R.some((t) => t === e.label)), n = t[0];
|
|
180
180
|
return n === void 0 || t.length !== 1 ? pkcs7Failure("malformed", "Expected exactly one PKCS7 or CMS PEM block") : {
|
|
181
181
|
ok: !0,
|
|
182
182
|
bytes: n.bytes
|
|
@@ -217,8 +217,8 @@ function parsePkcs7SignedDataDer(r) {
|
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
219
|
} catch (e) {
|
|
220
|
-
|
|
221
|
-
let t = c(e,
|
|
220
|
+
F(e);
|
|
221
|
+
let t = c(e, N);
|
|
222
222
|
return t === void 0 ? pkcs7Failure("malformed", "Malformed PKCS#7 structure") : pkcs7Failure(t.code, t.message);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -277,40 +277,31 @@ function parsePkcs7SignedDataPem(e) {
|
|
|
277
277
|
* ```
|
|
278
278
|
*/
|
|
279
279
|
async function verifyPkcs7SignedData(e, t = {}) {
|
|
280
|
-
let
|
|
281
|
-
if (!
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return verifyPkcs7Failure("
|
|
290
|
-
}
|
|
291
|
-
let a = normalizePkcs7SignedDataForVerification(e);
|
|
292
|
-
if (!a.ok) return a;
|
|
293
|
-
let o = a.value, s = o.encapsulatedContent ?? t.content?.slice();
|
|
294
|
-
if (s === void 0) return verifyPkcs7Failure("detached_content_required", "SignedData has no encapsulated content; supply the detached content via options.content");
|
|
295
|
-
if (o.signerInfos.length === 0) return verifyPkcs7Failure("no_signers", "SignedData contains no signer information");
|
|
296
|
-
if (o.encapsulatedContentTypeOid !== r) return verifyPkcs7Failure("content_type_mismatch", "Unexpected SignedData content type");
|
|
297
|
-
for (let e of o.signerInfos) {
|
|
298
|
-
if (!e.hasSignedAttrs && (i === "required" || o.encapsulatedContentTypeOid !== y.pkcs7Data)) return verifyPkcs7Failure("signed_attributes_required", "Signed attributes are required");
|
|
280
|
+
let n = resolvePkcs7VerifyPolicy(t);
|
|
281
|
+
if (!n.ok) return n;
|
|
282
|
+
let { expectedContentTypeOid: r, signedAttributes: i, verification: a } = n, o = normalizePkcs7SignedDataForVerification(e);
|
|
283
|
+
if (!o.ok) return o;
|
|
284
|
+
let s = o.value, c = s.encapsulatedContent ?? (t.content === void 0 ? void 0 : new Uint8Array(t.content));
|
|
285
|
+
if (c === void 0) return verifyPkcs7Failure("detached_content_required", "SignedData has no encapsulated content; supply the detached content via options.content");
|
|
286
|
+
if (s.signerInfos.length === 0) return verifyPkcs7Failure("no_signers", "SignedData contains no signer information");
|
|
287
|
+
if (s.encapsulatedContentTypeOid !== r) return verifyPkcs7Failure("content_type_mismatch", "Unexpected SignedData content type");
|
|
288
|
+
for (let e of s.signerInfos) {
|
|
289
|
+
if (!e.hasSignedAttrs && (i === "required" || s.encapsulatedContentTypeOid !== y.pkcs7Data)) return verifyPkcs7Failure("signed_attributes_required", "Signed attributes are required");
|
|
299
290
|
if (e.hasSignedAttrs && i === "forbidden") return verifyPkcs7Failure("signed_attributes_forbidden", "Signed attributes are forbidden");
|
|
300
291
|
}
|
|
301
|
-
let
|
|
302
|
-
for (let e of
|
|
303
|
-
let t = await verifyPkcs7SignerInfo(
|
|
292
|
+
let l = [];
|
|
293
|
+
for (let e of s.signerInfos) {
|
|
294
|
+
let t = await verifyPkcs7SignerInfo(s, e, c, a);
|
|
304
295
|
if (!t.ok) return t;
|
|
305
|
-
|
|
296
|
+
l.push({
|
|
306
297
|
signerInfo: e,
|
|
307
298
|
certificate: t.certificate
|
|
308
299
|
});
|
|
309
300
|
}
|
|
310
301
|
return {
|
|
311
302
|
ok: !0,
|
|
312
|
-
value:
|
|
313
|
-
signers:
|
|
303
|
+
value: s,
|
|
304
|
+
signers: l
|
|
314
305
|
};
|
|
315
306
|
}
|
|
316
307
|
/** Normalizes encoded or parsed SignedData into a freshly parsed verification input. */
|
|
@@ -318,48 +309,75 @@ function normalizePkcs7SignedDataForVerification(e) {
|
|
|
318
309
|
return typeof e == "string" ? parsePkcs7SignedDataPem(e) : e instanceof Uint8Array ? parsePkcs7SignedDataDer(e) : hasReparseablePkcs7SignedData(e) ? parsePkcs7SignedDataDer(new Uint8Array(e.der)) : verifyPkcs7Failure("malformed", "SignedData parsed input is malformed");
|
|
319
310
|
}
|
|
320
311
|
/** Resolves and verifies one signer entry in a parsed PKCS#7 SignedData value. */
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
312
|
+
/** Validates the caller policy in {@linkcode VerifyPkcs7SignedDataOptions}. */
|
|
313
|
+
function resolvePkcs7VerifyPolicy(e) {
|
|
314
|
+
let t = e.signedAttributes ?? "required";
|
|
315
|
+
if (![
|
|
316
|
+
"required",
|
|
317
|
+
"allowed",
|
|
318
|
+
"forbidden"
|
|
319
|
+
].includes(t)) return verifyPkcs7Failure("invalid_options", "Unknown signed-attribute policy");
|
|
320
|
+
let r;
|
|
321
|
+
try {
|
|
322
|
+
r = n(m(f(e.expectedContentTypeOid ?? y.pkcs7Data)).value);
|
|
323
|
+
} catch {
|
|
324
|
+
return verifyPkcs7Failure("invalid_options", "Expected content type must be an OID");
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
let n = S(e.signatureVerifiers);
|
|
328
|
+
return {
|
|
329
|
+
ok: !0,
|
|
330
|
+
expectedContentTypeOid: r,
|
|
331
|
+
signedAttributes: t,
|
|
332
|
+
verification: n
|
|
333
|
+
};
|
|
334
|
+
} catch (e) {
|
|
335
|
+
if (e instanceof RangeError) return verifyPkcs7Failure("invalid_options", e.message);
|
|
336
|
+
throw e;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async function verifyPkcs7SignerInfo(e, t, n, r) {
|
|
340
|
+
let i = x509CertificatesOf(e.certificateChoices).find((e) => signerIdentifierMatches(e, t));
|
|
341
|
+
if (i === void 0) return verifyPkcs7Failure("signer_not_found", "Signer certificate not found in SignedData certificates");
|
|
342
|
+
let a = t.hasSignedAttrs ? await verifySignedAttrs(t, i, n, e.encapsulatedContentTypeOid, r) : await verifyPkcs7BareSignerInfo(t, i, n, r);
|
|
343
|
+
return a.ok ? {
|
|
326
344
|
ok: !0,
|
|
327
|
-
certificate:
|
|
328
|
-
} :
|
|
345
|
+
certificate: i
|
|
346
|
+
} : a;
|
|
329
347
|
}
|
|
330
|
-
async function verifyPkcs7BareSignerInfo(e, t, n) {
|
|
348
|
+
async function verifyPkcs7BareSignerInfo(e, t, n, r) {
|
|
331
349
|
try {
|
|
332
|
-
let
|
|
333
|
-
return
|
|
350
|
+
let i = await w(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, 0, n, r);
|
|
351
|
+
return i.ok ? i.valid ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature does not verify") : i.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
|
|
334
352
|
} catch (e) {
|
|
335
353
|
return signatureVerificationThrowFailure(e);
|
|
336
354
|
}
|
|
337
355
|
}
|
|
338
356
|
/** Shorthand for constructing a PKCS#7 parse failure result. */
|
|
339
357
|
function pkcs7Failure(e, t) {
|
|
340
|
-
return
|
|
358
|
+
return P(e, t);
|
|
341
359
|
}
|
|
342
360
|
/** Shorthand for constructing a PKCS#7 verification failure result. */
|
|
343
361
|
/** A signer's signature verification that threw: its decode refusal, else `malformed`. */
|
|
344
362
|
function signatureVerificationThrowFailure(e) {
|
|
345
|
-
let t = c(e,
|
|
363
|
+
let t = c(e, N);
|
|
346
364
|
return t === void 0 ? verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData") : verifyPkcs7Failure(t.code, t.message);
|
|
347
365
|
}
|
|
348
366
|
function verifyPkcs7Failure(e, t) {
|
|
349
|
-
return
|
|
367
|
+
return P(e, t);
|
|
350
368
|
}
|
|
351
369
|
/** Shorthand for constructing a PKCS#7 certificate bag creation failure result. */
|
|
352
370
|
function createCertBagFailure(e, t) {
|
|
353
|
-
return
|
|
371
|
+
return P(e, t);
|
|
354
372
|
}
|
|
355
373
|
/** Shorthand for constructing a PKCS#7 SignedData creation failure result. */
|
|
356
374
|
function createPkcs7Failure(e, t) {
|
|
357
|
-
return
|
|
375
|
+
return P(e, t);
|
|
358
376
|
}
|
|
359
377
|
/** Converts PEM text to an array of DER certificate blobs, or wraps raw DER. */
|
|
360
378
|
function normalizeCertificateSource(e) {
|
|
361
379
|
if (typeof e == "string") {
|
|
362
|
-
let t =
|
|
380
|
+
let t = M(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
|
|
363
381
|
if (t.length === 0) throw Error("Certificate PEM required");
|
|
364
382
|
return t;
|
|
365
383
|
}
|
|
@@ -457,7 +475,7 @@ function parseCertificateChoice(e, t, n) {
|
|
|
457
475
|
switch (t.tag) {
|
|
458
476
|
case 48: return {
|
|
459
477
|
type: "certificate",
|
|
460
|
-
certificate:
|
|
478
|
+
certificate: L(n)
|
|
461
479
|
};
|
|
462
480
|
case 160: return {
|
|
463
481
|
type: "extendedCertificate",
|
|
@@ -565,7 +583,7 @@ function parseSignerIssuerName(t, i) {
|
|
|
565
583
|
for (let o of e(t, i)) {
|
|
566
584
|
let i = [], d = {};
|
|
567
585
|
for (let s of e(t, o)) {
|
|
568
|
-
let o = e(t, s), c = a(o[0], "signer issuer attribute OID"), f = a(o[1], "signer issuer attribute value"), p = n(c.value), m = r(f.tag, f.value), h =
|
|
586
|
+
let o = e(t, s), c = a(o[0], "signer issuer attribute OID"), f = a(o[1], "signer issuer attribute value"), p = n(c.value), m = r(f.tag, f.value), h = I(p), g = h === void 0 ? {
|
|
569
587
|
oid: p,
|
|
570
588
|
valueTag: f.tag,
|
|
571
589
|
value: m
|
|
@@ -651,44 +669,44 @@ function constantTimeEqual(e, t) {
|
|
|
651
669
|
return n === 0;
|
|
652
670
|
}
|
|
653
671
|
/** Verifies a signed-attributes flow: digest match + signature over re-tagged attrs. */
|
|
654
|
-
async function verifySignedAttrs(e, t, n, r) {
|
|
672
|
+
async function verifySignedAttrs(e, t, n, r, i) {
|
|
655
673
|
if (!e.hasSignedAttrs) return verifyPkcs7Failure("malformed", "Missing signedAttrs DER");
|
|
656
|
-
let
|
|
674
|
+
let a;
|
|
657
675
|
try {
|
|
658
|
-
assertImplicitSignedAttrsDer(e.signedAttrsDer),
|
|
676
|
+
assertImplicitSignedAttrsDer(e.signedAttrsDer), a = parseSignedAttributeRequirements(e.signedAttrsDer);
|
|
659
677
|
} catch (e) {
|
|
660
|
-
|
|
661
|
-
let t = c(e,
|
|
678
|
+
F(e);
|
|
679
|
+
let t = c(e, N);
|
|
662
680
|
return t === void 0 ? verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData") : verifyPkcs7Failure(t.code, t.message);
|
|
663
681
|
}
|
|
664
|
-
if (
|
|
665
|
-
let
|
|
682
|
+
if (a.contentTypeOid !== r) return verifyPkcs7Failure("malformed", "SignedData contentType attribute does not match");
|
|
683
|
+
let s;
|
|
666
684
|
try {
|
|
667
685
|
let t = digestAlgorithmHash(e.digestAlgorithmOid);
|
|
668
|
-
|
|
686
|
+
s = new Uint8Array(await O().subtle.digest(t, o(n)));
|
|
669
687
|
} catch {
|
|
670
688
|
return verifyPkcs7Failure("malformed", "Unsupported digest algorithm in SignedData");
|
|
671
689
|
}
|
|
672
|
-
if (!constantTimeEqual(
|
|
673
|
-
let
|
|
690
|
+
if (!constantTimeEqual(s, a.messageDigest)) return verifyPkcs7Failure("message_digest_mismatch", "Content digest does not match messageDigest attribute");
|
|
691
|
+
let l;
|
|
674
692
|
try {
|
|
675
|
-
|
|
693
|
+
l = retagSignedAttrsAsSet(e.signedAttrsDer);
|
|
676
694
|
} catch {
|
|
677
695
|
return verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData");
|
|
678
696
|
}
|
|
679
|
-
let
|
|
697
|
+
let u;
|
|
680
698
|
try {
|
|
681
|
-
let n = await
|
|
699
|
+
let n = await w(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, 0, l, i);
|
|
682
700
|
if (!n.ok) return n.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
|
|
683
|
-
|
|
701
|
+
u = n.valid;
|
|
684
702
|
} catch (e) {
|
|
685
703
|
return signatureVerificationThrowFailure(e);
|
|
686
704
|
}
|
|
687
|
-
return
|
|
705
|
+
return u ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature over signedAttrs does not verify");
|
|
688
706
|
}
|
|
689
707
|
function signerIdentifierMatches(e, t) {
|
|
690
708
|
let n = t.signerIdentifier;
|
|
691
|
-
return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex &&
|
|
709
|
+
return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && A(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
|
|
692
710
|
}
|
|
693
711
|
function assertImplicitSignedAttrsDer(e) {
|
|
694
712
|
if (m(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
|