micro509 0.13.0 → 0.14.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/README.md +78 -30
- package/dist/crypto/crypto.d.ts +73 -0
- package/dist/crypto/crypto.js +74 -0
- package/dist/crypto/crypto.js.map +1 -0
- package/dist/crypto.d.ts +4 -0
- package/dist/crypto.js +2 -0
- package/dist/der/der.d.ts +1 -1
- package/dist/index.d.ts +13 -9
- package/dist/index.js +17 -15
- package/dist/internal/asn1/asn1.js +21 -10
- package/dist/internal/asn1/asn1.js.map +1 -1
- package/dist/internal/asn1/der.d.ts +4 -2
- package/dist/internal/asn1/der.js +18 -5
- package/dist/internal/asn1/der.js.map +1 -1
- package/dist/internal/asn1/oids.js +7 -1
- package/dist/internal/crypto/algorithm-names.js +4 -0
- package/dist/internal/crypto/algorithm-names.js.map +1 -1
- package/dist/internal/crypto/pbes2.d.ts +38 -0
- package/dist/internal/crypto/pbes2.js +9 -10
- package/dist/internal/crypto/pbes2.js.map +1 -1
- package/dist/internal/crypto/rsa-pss.js +2 -0
- package/dist/internal/crypto/rsa-pss.js.map +1 -1
- package/dist/internal/crypto/sig-verify.d.ts +31 -0
- package/dist/internal/crypto/sig-verify.js +10 -8
- package/dist/internal/crypto/sig-verify.js.map +1 -1
- package/dist/internal/shared/base64.js +7 -1
- package/dist/internal/shared/base64.js.map +1 -1
- package/dist/internal/shared/dn.d.ts +16 -0
- package/dist/internal/shared/dn.js +13 -6
- package/dist/internal/shared/dn.js.map +1 -1
- package/dist/internal/shared/ip.d.ts +69 -0
- package/dist/internal/shared/ip.js +18 -1
- package/dist/internal/shared/ip.js.map +1 -1
- package/dist/internal/verify/verify-path.d.ts +7 -0
- package/dist/internal/verify/verify-path.js +36 -36
- package/dist/internal/x509/directory-name.js +24 -0
- package/dist/internal/x509/directory-name.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +13 -10
- package/dist/internal/x509/extension-bits.js.map +1 -1
- package/dist/internal/x509/extension-errors.d.ts +6 -0
- package/dist/internal/x509/extension-errors.js +20 -0
- package/dist/internal/x509/extension-errors.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +113 -55
- package/dist/internal/x509/extension-registry.js.map +1 -1
- package/dist/internal/x509/general-name-tags.js +28 -0
- package/dist/internal/x509/general-name-tags.js.map +1 -0
- package/dist/internal/x509/general-name.js +97 -0
- package/dist/internal/x509/general-name.js.map +1 -0
- package/dist/internal/x509/name-fields.js +20 -10
- package/dist/internal/x509/name-fields.js.map +1 -1
- package/dist/keys/keys.d.ts +16 -2
- package/dist/keys/keys.js +311 -170
- package/dist/keys/keys.js.map +1 -1
- package/dist/keys.d.ts +3 -2
- package/dist/keys.js +3 -2
- package/dist/pem/pem.d.ts +3 -2
- package/dist/pem/pem.js +112 -30
- package/dist/pem/pem.js.map +1 -1
- package/dist/pkcs/pkcs12-mac.js +3 -3
- package/dist/pkcs/pkcs12-mac.js.map +1 -1
- package/dist/pkcs/pkcs7.d.ts +85 -21
- package/dist/pkcs/pkcs7.js +261 -186
- package/dist/pkcs/pkcs7.js.map +1 -1
- package/dist/pkcs.d.ts +2 -2
- package/dist/result/result.d.ts +18 -10
- package/dist/result/result.js +20 -12
- package/dist/result/result.js.map +1 -1
- package/dist/result.d.ts +2 -2
- package/dist/result.js +2 -2
- package/dist/revocation/chain.js +77 -81
- package/dist/revocation/chain.js.map +1 -1
- package/dist/revocation/crl.d.ts +13 -2
- package/dist/revocation/crl.js +415 -236
- package/dist/revocation/crl.js.map +1 -1
- package/dist/revocation/ocsp.d.ts +58 -17
- package/dist/revocation/ocsp.js +185 -173
- package/dist/revocation/ocsp.js.map +1 -1
- package/dist/revocation/revocation.d.ts +4 -4
- package/dist/revocation/revocation.js +48 -30
- package/dist/revocation/revocation.js.map +1 -1
- package/dist/revocation.d.ts +4 -4
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +2 -1
- package/dist/verify/identity.js +2 -1
- package/dist/verify/identity.js.map +1 -1
- package/dist/verify/policy.d.ts +6 -1
- package/dist/verify/verify.d.ts +4 -2
- package/dist/verify/verify.js +32 -14
- package/dist/verify/verify.js.map +1 -1
- package/dist/verify.d.ts +2 -1
- package/dist/verify.js +4 -3
- package/dist/x509/certificate.d.ts +36 -13
- package/dist/x509/certificate.js +36 -19
- package/dist/x509/certificate.js.map +1 -1
- package/dist/x509/csr.d.ts +6 -3
- package/dist/x509/extensions.d.ts +58 -21
- package/dist/x509/extensions.js +384 -117
- package/dist/x509/extensions.js.map +1 -1
- package/dist/x509/name-text.js +2 -0
- package/dist/x509/name-text.js.map +1 -1
- package/dist/x509/name.d.ts +8 -5
- package/dist/x509/name.js +17 -12
- package/dist/x509/name.js.map +1 -1
- package/dist/x509/parse.d.ts +104 -18
- package/dist/x509/parse.js +127 -163
- package/dist/x509/parse.js.map +1 -1
- package/dist/x509.d.ts +8 -5
- package/dist/x509.js +10 -8
- package/package.json +28 -20
package/dist/pkcs/pkcs7.js
CHANGED
|
@@ -1,51 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { childrenOf as
|
|
3
|
-
import { OIDS as
|
|
4
|
-
import { getCrypto as
|
|
5
|
-
import { base64Encode as
|
|
6
|
-
import { failureResult as
|
|
7
|
-
import { pemEncode as
|
|
8
|
-
import { describeHashAlgorithm as
|
|
9
|
-
import { nameFieldKeyFromOid as
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import { explicitContext as e, integer as t, integerFromNumber as n, objectIdentifier as r, octetString as i, readElement as a, readRootElement as o, readSequenceChildren as s, sequence as c, setOf as l } from "../internal/asn1/der.js";
|
|
2
|
+
import { childrenOf as u, decodeIntegerNumber as d, decodeObjectIdentifier as f, decodeString as p, hexToBytes as m, requireElement as h, toArrayBuffer as g, toHex as _ } from "../internal/asn1/asn1.js";
|
|
3
|
+
import { OIDS as v } from "../internal/asn1/oids2.js";
|
|
4
|
+
import { getCrypto as y } from "../internal/crypto/webcrypto.js";
|
|
5
|
+
import { base64Encode as b } from "../internal/shared/base64.js";
|
|
6
|
+
import { failureResult as x } from "../result/result.js";
|
|
7
|
+
import { pemEncode as S, splitPemBlocksOrThrow as C } from "../pem/pem.js";
|
|
8
|
+
import { describeHashAlgorithm as w, describeSignatureAlgorithm as T } from "../internal/crypto/algorithm-names.js";
|
|
9
|
+
import { nameFieldKeyFromOid as E } from "../internal/x509/name-fields.js";
|
|
10
|
+
import { compareDistinguishedNames as D } from "../internal/shared/dn.js";
|
|
11
|
+
import { parseCertificateDerOrThrow as O } from "../x509/parse.js";
|
|
12
|
+
import { getVerifySignatureConfigResult as k, verifySignedDataDetailed as A } from "../internal/crypto/sig-verify.js";
|
|
12
13
|
import { encodeAlgorithmIdentifier as j, getSignatureAlgorithm as M, signBytes as N } from "../internal/crypto/signing.js";
|
|
13
|
-
import { compareDistinguishedNames as P } from "../internal/shared/dn.js";
|
|
14
14
|
//#region src/pkcs/pkcs7.ts
|
|
15
15
|
/**
|
|
16
16
|
* PKCS#7/CMS certificate bags and SignedData.
|
|
17
17
|
*
|
|
18
|
-
* Creates degenerate (signature-less) certificate bags, parses RFC
|
|
19
|
-
* SignedData
|
|
18
|
+
* Creates degenerate (signature-less) certificate bags, parses RFC 5652
|
|
19
|
+
* SignedData (and the RFC 2315 form whose contentInfo content is an OCTET
|
|
20
|
+
* STRING), and verifies signer signatures including signed-attribute flows.
|
|
21
|
+
* A CertificateSet is decoded as RFC 5652 §10.2.2 CertificateChoices, so an
|
|
22
|
+
* attribute certificate or other-format entry is preserved rather than dropped.
|
|
20
23
|
*
|
|
21
24
|
* @module
|
|
22
25
|
*/
|
|
26
|
+
/** RFC 7468 Section 8 armors an RFC 2315 ContentInfo; Section 9 armors an RFC 5652 one. */
|
|
27
|
+
const P = ["PKCS7", "CMS"];
|
|
23
28
|
/**
|
|
24
29
|
* Creates a degenerate PKCS#7 SignedData structure containing only
|
|
25
30
|
* certificates (no signers), returning DER, PEM, and base64 forms, or a
|
|
26
31
|
* typed `invalid_certificate` failure when a certificate source is not
|
|
27
32
|
* valid PEM/DER.
|
|
28
33
|
*/
|
|
29
|
-
function createPkcs7CertBag(
|
|
34
|
+
function createPkcs7CertBag(t) {
|
|
30
35
|
let i;
|
|
31
36
|
try {
|
|
32
|
-
i =
|
|
37
|
+
i = t.flatMap(normalizeCertificateSource);
|
|
38
|
+
for (let e of i) O(e);
|
|
33
39
|
} catch {
|
|
34
40
|
return createCertBagFailure("invalid_certificate", "Each PKCS#7 certificate source must be valid PEM or DER");
|
|
35
41
|
}
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
let a = new Uint8Array(l(i));
|
|
43
|
+
a[0] = 160;
|
|
44
|
+
let o = c([
|
|
45
|
+
n(1),
|
|
46
|
+
l([]),
|
|
47
|
+
c([r(v.pkcs7Data)]),
|
|
48
|
+
a,
|
|
49
|
+
l([])
|
|
50
|
+
]), s = c([r(v.pkcs7SignedData), e(0, o)]);
|
|
43
51
|
return {
|
|
44
52
|
ok: !0,
|
|
45
53
|
value: {
|
|
46
54
|
der: s,
|
|
47
|
-
pem:
|
|
48
|
-
base64:
|
|
55
|
+
pem: S("PKCS7", s),
|
|
56
|
+
base64: b(s)
|
|
49
57
|
}
|
|
50
58
|
};
|
|
51
59
|
}
|
|
@@ -65,40 +73,41 @@ function createPkcs7CertBag(n) {
|
|
|
65
73
|
*
|
|
66
74
|
* Returns a {@linkcode CreatePkcs7SignedDataResult}: DER, PEM, and base64
|
|
67
75
|
* forms on success, or a typed failure for caller-correctable input (no
|
|
68
|
-
* signers, a signer source that is not exactly one certificate,
|
|
76
|
+
* signers, a signer source that is not exactly one certificate, a signer
|
|
77
|
+
* certificate whose public key cannot verify the signer key's algorithm, or an
|
|
69
78
|
* unsupported signer key).
|
|
70
79
|
*/
|
|
71
|
-
async function createPkcs7SignedData(
|
|
72
|
-
if (
|
|
73
|
-
let
|
|
74
|
-
let t =
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
for (let
|
|
78
|
-
let
|
|
79
|
-
if (!
|
|
80
|
-
addCertificate(
|
|
80
|
+
async function createPkcs7SignedData(t) {
|
|
81
|
+
if (t.signers.length === 0) return createPkcs7Failure("no_signers", "createPkcs7SignedData requires at least one signer");
|
|
82
|
+
let a = t.encapsulatedContentTypeOid ?? v.pkcs7Data, o = t.content.slice(), s = [], u = /* @__PURE__ */ new Set(), addCertificate = (e) => {
|
|
83
|
+
let t = _(e);
|
|
84
|
+
u.has(t) || (u.add(t), s.push(e));
|
|
85
|
+
}, d = /* @__PURE__ */ new Set(), f = [];
|
|
86
|
+
for (let e of t.signers) {
|
|
87
|
+
let t = await buildPkcs7SignerInfo(e, o, a);
|
|
88
|
+
if (!t.ok) return t;
|
|
89
|
+
addCertificate(t.certificateDer), d.add(t.digestOid), f.push(t.signerInfoDer);
|
|
81
90
|
}
|
|
82
|
-
for (let
|
|
83
|
-
for (let
|
|
91
|
+
for (let e of t.additionalCertificates ?? []) try {
|
|
92
|
+
for (let t of normalizeCertificateSource(e)) O(t), addCertificate(t);
|
|
84
93
|
} catch {
|
|
85
94
|
return createPkcs7Failure("invalid_certificate", "Each additional PKCS#7 certificate source must be valid PEM or DER");
|
|
86
95
|
}
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
let
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
]),
|
|
96
|
+
let p = a === v.pkcs7Data ? 1 : 3, m = new Uint8Array(l(s));
|
|
97
|
+
m[0] = 160;
|
|
98
|
+
let h = c([
|
|
99
|
+
n(p),
|
|
100
|
+
l([...d].map((e) => c([r(e)]))),
|
|
101
|
+
t.detached === !0 ? c([r(a)]) : c([r(a), e(0, i(o))]),
|
|
102
|
+
m,
|
|
103
|
+
l(f)
|
|
104
|
+
]), g = c([r(v.pkcs7SignedData), e(0, h)]);
|
|
96
105
|
return {
|
|
97
106
|
ok: !0,
|
|
98
107
|
value: {
|
|
99
|
-
der:
|
|
100
|
-
pem:
|
|
101
|
-
base64:
|
|
108
|
+
der: g,
|
|
109
|
+
pem: S(p === 1 ? "PKCS7" : "CMS", g),
|
|
110
|
+
base64: b(g)
|
|
102
111
|
}
|
|
103
112
|
};
|
|
104
113
|
}
|
|
@@ -108,46 +117,47 @@ async function createPkcs7SignedData(e) {
|
|
|
108
117
|
* caller-correctable input — malformed PEM/DER, unsupported key — so each is
|
|
109
118
|
* mapped to a typed failure rather than rejecting the public Promise.
|
|
110
119
|
*/
|
|
111
|
-
async function buildPkcs7SignerInfo(e,
|
|
112
|
-
let
|
|
120
|
+
async function buildPkcs7SignerInfo(e, a, o) {
|
|
121
|
+
let s;
|
|
113
122
|
try {
|
|
114
|
-
|
|
123
|
+
s = normalizeCertificateSource(e.certificate);
|
|
115
124
|
} catch {
|
|
116
125
|
return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate source must be valid PEM or DER");
|
|
117
126
|
}
|
|
118
|
-
let l =
|
|
119
|
-
if (l === void 0 ||
|
|
120
|
-
let
|
|
127
|
+
let l = s[0];
|
|
128
|
+
if (l === void 0 || s.length !== 1) return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer must provide exactly one certificate");
|
|
129
|
+
let u;
|
|
121
130
|
try {
|
|
122
|
-
|
|
131
|
+
u = O(l);
|
|
123
132
|
} catch {
|
|
124
133
|
return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate must be a parseable X.509 certificate");
|
|
125
134
|
}
|
|
126
|
-
let
|
|
135
|
+
let d;
|
|
127
136
|
try {
|
|
128
|
-
|
|
137
|
+
d = M(e.privateKey, e.signature);
|
|
129
138
|
} catch {
|
|
130
139
|
return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key or signature profile");
|
|
131
140
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
if (!k(d.algorithmOid, d.parameters, u.publicKeyAlgorithmOid, u.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");
|
|
142
|
+
let f = contentDigestForPrivateKey(e.privateKey);
|
|
143
|
+
if (f === void 0) return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key algorithm for content digest");
|
|
144
|
+
let { setForSigning: p, implicitForEmit: h } = buildSignedAttributes(o, new Uint8Array(await y().subtle.digest(f.hashName, g(a)))), _;
|
|
135
145
|
try {
|
|
136
|
-
_ = await N(e.privateKey,
|
|
146
|
+
_ = await N(e.privateKey, d, p);
|
|
137
147
|
} catch {
|
|
138
148
|
return createPkcs7Failure("unsupported_signer_key", "Signer key could not produce a PKCS#7 signature");
|
|
139
149
|
}
|
|
140
150
|
return {
|
|
141
151
|
ok: !0,
|
|
142
|
-
signerInfoDer:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
signerInfoDer: c([
|
|
153
|
+
n(1),
|
|
154
|
+
c([m(u.issuer.derHex), t(m(u.serialNumberHex))]),
|
|
155
|
+
c([r(f.digestOid)]),
|
|
146
156
|
h,
|
|
147
|
-
j(
|
|
148
|
-
|
|
157
|
+
j(d),
|
|
158
|
+
i(_)
|
|
149
159
|
]),
|
|
150
|
-
digestOid:
|
|
160
|
+
digestOid: f.digestOid,
|
|
151
161
|
certificateDer: l
|
|
152
162
|
};
|
|
153
163
|
}
|
|
@@ -156,43 +166,50 @@ function parsePkcs7CertBagDer(e) {
|
|
|
156
166
|
let t = parsePkcs7SignedDataDer(e);
|
|
157
167
|
return t.ok ? {
|
|
158
168
|
ok: !0,
|
|
159
|
-
value: t.value.
|
|
169
|
+
value: x509CertificatesOf(t.value.certificateChoices)
|
|
160
170
|
} : t;
|
|
161
171
|
}
|
|
162
|
-
/**
|
|
163
|
-
function
|
|
172
|
+
/** The DER of the single `PKCS7` or `CMS` block in `pem`, or a typed failure. */
|
|
173
|
+
function contentInfoPemBytes(e) {
|
|
164
174
|
try {
|
|
165
|
-
let t =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
175
|
+
let t = C(e).filter((e) => P.some((t) => t === e.label)), n = t[0];
|
|
176
|
+
return n === void 0 || t.length !== 1 ? pkcs7Failure("malformed", "Expected exactly one PKCS7 or CMS PEM block") : {
|
|
177
|
+
ok: !0,
|
|
178
|
+
bytes: n.bytes
|
|
179
|
+
};
|
|
169
180
|
} catch {
|
|
170
|
-
return pkcs7Failure("malformed", "Expected exactly one PKCS7 PEM block");
|
|
181
|
+
return pkcs7Failure("malformed", "Expected exactly one PKCS7 or CMS PEM block");
|
|
171
182
|
}
|
|
172
183
|
}
|
|
184
|
+
/** Parses a PEM-armored PKCS#7/CMS cert bag. Expects exactly one `PKCS7` or `CMS` PEM block. */
|
|
185
|
+
function parsePkcs7CertBagPem(e) {
|
|
186
|
+
let t = contentInfoPemBytes(e);
|
|
187
|
+
return t.ok ? parsePkcs7CertBagDer(t.bytes) : t;
|
|
188
|
+
}
|
|
173
189
|
/** Decodes a DER-encoded PKCS#7 ContentInfo expecting `signedData` content type. */
|
|
174
190
|
function parsePkcs7SignedDataDer(e) {
|
|
175
191
|
try {
|
|
176
|
-
let t =
|
|
177
|
-
if (n === void 0 ||
|
|
178
|
-
let i =
|
|
179
|
-
if (i !==
|
|
180
|
-
|
|
192
|
+
let t = s(e, { maxDepth: 64 }), n = t[0], r = t[1];
|
|
193
|
+
if (n === void 0 || t.length > 2 || n.tag !== 6 || r !== void 0 && (r.tag !== 160 || u(e, r).length !== 1)) return pkcs7Failure("malformed", "Malformed PKCS#7 content info");
|
|
194
|
+
let i = f(n.value);
|
|
195
|
+
if (i !== v.pkcs7SignedData) return pkcs7Failure("not_signed_data", "PKCS#7 content is not signedData");
|
|
196
|
+
if (r === void 0) return pkcs7Failure("malformed", "PKCS#7 signedData content info carries no content");
|
|
197
|
+
let a = u(e, childAt(e, r, 0, "signedData")), o = a[0], c = a[1], l = a[2], p = a.slice(3), m = p[p.length - 1], h = parseSignedDataOptionalFields(p.slice(0, -1));
|
|
181
198
|
if (!h.ok) return h;
|
|
182
|
-
if (o === void 0 ||
|
|
183
|
-
let g = e.slice(
|
|
184
|
-
return
|
|
199
|
+
if (o === void 0 || c === void 0 || l === void 0 || m === void 0 || m.tag !== 49) return pkcs7Failure("malformed", "Malformed SignedData");
|
|
200
|
+
let g = e.slice(l.start - l.headerLength, l.end), _ = s(g), y = _[0], b = _[1], x = parseDigestAlgorithms(e, c);
|
|
201
|
+
return y === void 0 || _.length > 2 || y.tag !== 6 ? pkcs7Failure("malformed", "Malformed EncapsulatedContentInfo") : {
|
|
185
202
|
ok: !0,
|
|
186
203
|
value: {
|
|
187
204
|
der: new Uint8Array(e),
|
|
188
205
|
contentTypeOid: i,
|
|
189
|
-
version:
|
|
206
|
+
version: d(o.value),
|
|
190
207
|
digestAlgorithmOids: x,
|
|
191
|
-
digestAlgorithmNames: x.map((e) =>
|
|
192
|
-
encapsulatedContentTypeOid:
|
|
193
|
-
...
|
|
194
|
-
|
|
195
|
-
signerInfos: parseSignerInfos(e,
|
|
208
|
+
digestAlgorithmNames: x.map((e) => w(e)),
|
|
209
|
+
encapsulatedContentTypeOid: f(y.value),
|
|
210
|
+
...b === void 0 ? {} : { encapsulatedContent: extractEncapsulatedContent(g, b) },
|
|
211
|
+
certificateChoices: parseCertificateSet(e, h.value.certificates),
|
|
212
|
+
signerInfos: parseSignerInfos(e, m)
|
|
196
213
|
}
|
|
197
214
|
};
|
|
198
215
|
} catch {
|
|
@@ -223,14 +240,10 @@ function parseSignedDataOptionalFields(e) {
|
|
|
223
240
|
}
|
|
224
241
|
};
|
|
225
242
|
}
|
|
226
|
-
/** Decodes a PEM-armored PKCS#7 SignedData. Expects exactly one `PKCS7` PEM block. */
|
|
243
|
+
/** Decodes a PEM-armored PKCS#7/CMS SignedData. Expects exactly one `PKCS7` or `CMS` PEM block. */
|
|
227
244
|
function parsePkcs7SignedDataPem(e) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return n === void 0 || t.length !== 1 ? pkcs7Failure("malformed", "Expected exactly one PKCS7 PEM block") : parsePkcs7SignedDataDer(n.bytes);
|
|
231
|
-
} catch {
|
|
232
|
-
return pkcs7Failure("malformed", "Expected exactly one PKCS7 PEM block");
|
|
233
|
-
}
|
|
245
|
+
let t = contentInfoPemBytes(e);
|
|
246
|
+
return t.ok ? parsePkcs7SignedDataDer(t.bytes) : t;
|
|
234
247
|
}
|
|
235
248
|
/**
|
|
236
249
|
* Verifies all signer signatures in a PKCS#7 SignedData structure.
|
|
@@ -250,7 +263,9 @@ function parsePkcs7SignedDataPem(e) {
|
|
|
250
263
|
*
|
|
251
264
|
* const result = await verifyPkcs7SignedData(pkcs7Pem);
|
|
252
265
|
* if (result.ok) {
|
|
253
|
-
*
|
|
266
|
+
* for (const { signerInfo, certificate } of result.signers) {
|
|
267
|
+
* console.log(signerInfo.digestAlgorithmOid, certificate.subject);
|
|
268
|
+
* }
|
|
254
269
|
* }
|
|
255
270
|
*
|
|
256
271
|
* // Detached signature: supply the content externally
|
|
@@ -262,13 +277,19 @@ async function verifyPkcs7SignedData(e, t = {}) {
|
|
|
262
277
|
if (!n.ok) return n;
|
|
263
278
|
let r = n.value, i = r.encapsulatedContent ?? t.content?.slice();
|
|
264
279
|
if (i === void 0) return verifyPkcs7Failure("detached_content_required", "SignedData has no encapsulated content; supply the detached content via options.content");
|
|
280
|
+
let a = [];
|
|
265
281
|
for (let e of r.signerInfos) {
|
|
266
282
|
let t = await verifyPkcs7SignerInfo(r, e, i);
|
|
267
283
|
if (!t.ok) return t;
|
|
284
|
+
a.push({
|
|
285
|
+
signerInfo: e,
|
|
286
|
+
certificate: t.certificate
|
|
287
|
+
});
|
|
268
288
|
}
|
|
269
289
|
return {
|
|
270
290
|
ok: !0,
|
|
271
|
-
value: r
|
|
291
|
+
value: r,
|
|
292
|
+
signers: a
|
|
272
293
|
};
|
|
273
294
|
}
|
|
274
295
|
/** Normalizes encoded or parsed SignedData into a freshly parsed verification input. */
|
|
@@ -277,8 +298,13 @@ function normalizePkcs7SignedDataForVerification(e) {
|
|
|
277
298
|
}
|
|
278
299
|
/** Resolves and verifies one signer entry in a parsed PKCS#7 SignedData value. */
|
|
279
300
|
async function verifyPkcs7SignerInfo(e, t, n) {
|
|
280
|
-
let r = e.
|
|
281
|
-
|
|
301
|
+
let r = x509CertificatesOf(e.certificateChoices).find((e) => signerIdentifierMatches(e, t));
|
|
302
|
+
if (r === void 0) return verifyPkcs7Failure("signer_not_found", "Signer certificate not found in SignedData certificates");
|
|
303
|
+
let i = t.hasSignedAttrs ? await verifySignedAttrs(t, r, n, e.encapsulatedContentTypeOid) : await verifyPkcs7BareSignerInfo(t, r, n);
|
|
304
|
+
return i.ok ? {
|
|
305
|
+
ok: !0,
|
|
306
|
+
certificate: r
|
|
307
|
+
} : i;
|
|
282
308
|
}
|
|
283
309
|
async function verifyPkcs7BareSignerInfo(e, t, n) {
|
|
284
310
|
try {
|
|
@@ -290,23 +316,28 @@ async function verifyPkcs7BareSignerInfo(e, t, n) {
|
|
|
290
316
|
}
|
|
291
317
|
/** Shorthand for constructing a PKCS#7 parse failure result. */
|
|
292
318
|
function pkcs7Failure(e, t) {
|
|
293
|
-
return
|
|
319
|
+
return x(e, t);
|
|
294
320
|
}
|
|
295
321
|
/** Shorthand for constructing a PKCS#7 verification failure result. */
|
|
296
322
|
function verifyPkcs7Failure(e, t) {
|
|
297
|
-
return
|
|
323
|
+
return x(e, t);
|
|
298
324
|
}
|
|
299
325
|
/** Shorthand for constructing a PKCS#7 certificate bag creation failure result. */
|
|
300
326
|
function createCertBagFailure(e, t) {
|
|
301
|
-
return
|
|
327
|
+
return x(e, t);
|
|
302
328
|
}
|
|
303
329
|
/** Shorthand for constructing a PKCS#7 SignedData creation failure result. */
|
|
304
330
|
function createPkcs7Failure(e, t) {
|
|
305
|
-
return
|
|
331
|
+
return x(e, t);
|
|
306
332
|
}
|
|
307
333
|
/** Converts PEM text to an array of DER certificate blobs, or wraps raw DER. */
|
|
308
334
|
function normalizeCertificateSource(e) {
|
|
309
|
-
|
|
335
|
+
if (typeof e == "string") {
|
|
336
|
+
let t = C(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
|
|
337
|
+
if (t.length === 0) throw Error("Certificate PEM required");
|
|
338
|
+
return t;
|
|
339
|
+
}
|
|
340
|
+
return e instanceof Uint8Array ? [new Uint8Array(e)] : [new Uint8Array(e.der)];
|
|
310
341
|
}
|
|
311
342
|
/** Type guard: key algorithm carries an RSA `hash`. */
|
|
312
343
|
function signerHasHash(e) {
|
|
@@ -319,9 +350,10 @@ function signerHasNamedCurve(e) {
|
|
|
319
350
|
/**
|
|
320
351
|
* Resolves the content-digest hash and its OID for a signer key.
|
|
321
352
|
*
|
|
322
|
-
*
|
|
323
|
-
* P-
|
|
324
|
-
*
|
|
353
|
+
* ECDSA curve pairing follows RFC 5753 §8: P-256 → SHA-256, P-384 → SHA-384,
|
|
354
|
+
* P-521 → SHA-512. RSA uses the hash bound to the key.
|
|
355
|
+
* Digest OIDs are from RFC 5754 §2.
|
|
356
|
+
* Ed25519 uses SHA-512 for the messageDigest attribute, per RFC 8419.
|
|
325
357
|
*/
|
|
326
358
|
function contentDigestForPrivateKey(e) {
|
|
327
359
|
let t = e.algorithm;
|
|
@@ -330,15 +362,15 @@ function contentDigestForPrivateKey(e) {
|
|
|
330
362
|
switch (t.namedCurve) {
|
|
331
363
|
case "P-256": return {
|
|
332
364
|
hashName: "SHA-256",
|
|
333
|
-
digestOid:
|
|
365
|
+
digestOid: v.sha256
|
|
334
366
|
};
|
|
335
367
|
case "P-384": return {
|
|
336
368
|
hashName: "SHA-384",
|
|
337
|
-
digestOid:
|
|
369
|
+
digestOid: v.sha384
|
|
338
370
|
};
|
|
339
371
|
case "P-521": return {
|
|
340
372
|
hashName: "SHA-512",
|
|
341
|
-
digestOid:
|
|
373
|
+
digestOid: v.sha512
|
|
342
374
|
};
|
|
343
375
|
default: return;
|
|
344
376
|
}
|
|
@@ -348,22 +380,22 @@ function contentDigestForPrivateKey(e) {
|
|
|
348
380
|
switch (t.hash.name) {
|
|
349
381
|
case "SHA-256": return {
|
|
350
382
|
hashName: "SHA-256",
|
|
351
|
-
digestOid:
|
|
383
|
+
digestOid: v.sha256
|
|
352
384
|
};
|
|
353
385
|
case "SHA-384": return {
|
|
354
386
|
hashName: "SHA-384",
|
|
355
|
-
digestOid:
|
|
387
|
+
digestOid: v.sha384
|
|
356
388
|
};
|
|
357
389
|
case "SHA-512": return {
|
|
358
390
|
hashName: "SHA-512",
|
|
359
|
-
digestOid:
|
|
391
|
+
digestOid: v.sha512
|
|
360
392
|
};
|
|
361
393
|
default: return;
|
|
362
394
|
}
|
|
363
395
|
}
|
|
364
396
|
if (t.name === "Ed25519") return {
|
|
365
397
|
hashName: "SHA-512",
|
|
366
|
-
digestOid:
|
|
398
|
+
digestOid: v.sha512
|
|
367
399
|
};
|
|
368
400
|
}
|
|
369
401
|
/**
|
|
@@ -373,87 +405,129 @@ function contentDigestForPrivateKey(e) {
|
|
|
373
405
|
* SignerInfo. The two differ only in the leading tag byte.
|
|
374
406
|
*/
|
|
375
407
|
function buildSignedAttributes(e, t) {
|
|
376
|
-
let n =
|
|
377
|
-
return
|
|
408
|
+
let n = l([c([r(v.cmsContentType), l([r(e)])]), c([r(v.cmsMessageDigest), l([i(t)])])]), a = new Uint8Array(n);
|
|
409
|
+
return a[0] = 160, {
|
|
378
410
|
setForSigning: n,
|
|
379
|
-
implicitForEmit:
|
|
411
|
+
implicitForEmit: a
|
|
380
412
|
};
|
|
381
413
|
}
|
|
382
|
-
/**
|
|
383
|
-
function
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
414
|
+
/** The X.509 subset of a decoded CertificateSet. */
|
|
415
|
+
function x509CertificatesOf(e) {
|
|
416
|
+
return e.flatMap((e) => e.type === "certificate" ? [e.certificate] : []);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* `otherCertFormat` from an `other [3] IMPLICIT OtherCertificateFormat` entry.
|
|
420
|
+
*
|
|
421
|
+
* The IMPLICIT tag replaces the SEQUENCE tag, so the OID and the `ANY DEFINED BY`
|
|
422
|
+
* value are direct children of the `[3]` element.
|
|
423
|
+
*/
|
|
424
|
+
function parseOtherCertificateFormatOid(e, t) {
|
|
425
|
+
let n = h(u(e, t)[0], "otherCertFormat");
|
|
426
|
+
if (n.tag !== 6) throw Error("otherCertFormat must be an OBJECT IDENTIFIER");
|
|
427
|
+
return f(n.value);
|
|
428
|
+
}
|
|
429
|
+
/** Decodes one RFC 5652 §10.2.2 CertificateChoices alternative. */
|
|
430
|
+
function parseCertificateChoice(e, t, n) {
|
|
431
|
+
switch (t.tag) {
|
|
432
|
+
case 48: return {
|
|
433
|
+
type: "certificate",
|
|
434
|
+
certificate: O(n)
|
|
435
|
+
};
|
|
436
|
+
case 160: return {
|
|
437
|
+
type: "extendedCertificate",
|
|
438
|
+
der: n
|
|
439
|
+
};
|
|
440
|
+
case 161: return {
|
|
441
|
+
type: "attributeCertificateV1",
|
|
442
|
+
der: n
|
|
443
|
+
};
|
|
444
|
+
case 162: return {
|
|
445
|
+
type: "attributeCertificateV2",
|
|
446
|
+
der: n
|
|
447
|
+
};
|
|
448
|
+
case 163: return {
|
|
449
|
+
type: "other",
|
|
450
|
+
formatOid: parseOtherCertificateFormatOid(e, t),
|
|
451
|
+
der: n
|
|
452
|
+
};
|
|
453
|
+
default: throw Error(`Unsupported CertificateChoices tag: ${t.tag}`);
|
|
389
454
|
}
|
|
390
|
-
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Parses the IMPLICIT [0] certificate set from a SignedData structure as
|
|
458
|
+
* RFC 5652 §10.2.3 `CertificateSet ::= SET OF CertificateChoices`.
|
|
459
|
+
*/
|
|
460
|
+
function parseCertificateSet(e, t) {
|
|
461
|
+
return t === void 0 || t.tag !== 160 ? [] : u(e, t).map((t) => parseCertificateChoice(e, t, e.slice(t.start - t.headerLength, t.end)));
|
|
391
462
|
}
|
|
392
463
|
/** Extracts the list of digest algorithm OIDs from the digestAlgorithms SET. */
|
|
393
464
|
function parseDigestAlgorithms(e, t) {
|
|
394
465
|
let n = [];
|
|
395
466
|
if (t.tag !== 49) throw Error("digestAlgorithms must use SET");
|
|
396
|
-
for (let r of
|
|
467
|
+
for (let r of u(e, t)) {
|
|
397
468
|
if (r.tag !== 48) throw Error("digestAlgorithm must use AlgorithmIdentifier SEQUENCE");
|
|
398
|
-
let t =
|
|
469
|
+
let t = s(e.slice(r.start - r.headerLength, r.end)), i = t[0];
|
|
399
470
|
if (i === void 0 || t.length < 1 || t.length > 2 || i.tag !== 6) throw Error("Malformed digest AlgorithmIdentifier");
|
|
400
|
-
n.push(
|
|
471
|
+
n.push(f(i.value));
|
|
401
472
|
}
|
|
402
473
|
return n;
|
|
403
474
|
}
|
|
404
475
|
/** Decodes the signerInfos SET OF from a SignedData structure. */
|
|
405
476
|
function parseSignerInfos(e, t) {
|
|
406
|
-
return
|
|
477
|
+
return u(e, t).map((t) => parseSignerInfo(e, t));
|
|
407
478
|
}
|
|
408
479
|
function parseSignerInfo(e, t) {
|
|
409
|
-
let n = e.slice(t.start - t.headerLength, t.end), r =
|
|
410
|
-
|
|
411
|
-
let u = r[
|
|
412
|
-
if (i === void 0 || a === void 0 || o === void 0 || u === void 0 ||
|
|
413
|
-
let
|
|
480
|
+
let n = e.slice(t.start - t.headerLength, t.end), r = s(n), i = r[0], a = r[1], o = r[2], c = 3, l = r[c]?.tag === 160 ? r[c] : void 0;
|
|
481
|
+
l !== void 0 && (c += 1);
|
|
482
|
+
let u = r[c], p = r[c + 1], m = r[c + 2];
|
|
483
|
+
if (i === void 0 || a === void 0 || o === void 0 || u === void 0 || p === void 0 || p.tag !== 4 || r.length > c + 3 || m !== void 0 && m.tag !== 161) throw Error("Malformed SignerInfo");
|
|
484
|
+
let g = parsePkcs7AlgorithmOid(n, o, "digest algorithm OID"), v = n.slice(u.start - u.headerLength, u.end), y = s(v), b = f(h(y[0], "signature algorithm OID").value), x = y[1];
|
|
414
485
|
return {
|
|
415
|
-
version:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
digestAlgorithmOid: h,
|
|
420
|
-
digestAlgorithmName: E(h),
|
|
486
|
+
version: d(i.value),
|
|
487
|
+
signerIdentifier: parseSignerIdentifier(n.slice(a.start - a.headerLength, a.end)),
|
|
488
|
+
digestAlgorithmOid: g,
|
|
489
|
+
digestAlgorithmName: w(g),
|
|
421
490
|
signatureAlgorithmOid: b,
|
|
422
|
-
signatureAlgorithmName:
|
|
423
|
-
...x === void 0 ? {} : { signatureAlgorithmParametersDer: new Uint8Array(
|
|
424
|
-
signatureHex:
|
|
425
|
-
signature: new Uint8Array(
|
|
426
|
-
...
|
|
491
|
+
signatureAlgorithmName: T(b, x === void 0 ? void 0 : new Uint8Array(v.slice(x.start - x.headerLength, x.end))),
|
|
492
|
+
...x === void 0 ? {} : { signatureAlgorithmParametersDer: new Uint8Array(v.slice(x.start - x.headerLength, x.end)) },
|
|
493
|
+
signatureHex: _(p.value),
|
|
494
|
+
signature: new Uint8Array(p.value),
|
|
495
|
+
...l === void 0 ? { hasSignedAttrs: !1 } : {
|
|
427
496
|
hasSignedAttrs: !0,
|
|
428
|
-
signedAttrsDer: new Uint8Array(n.slice(
|
|
497
|
+
signedAttrsDer: new Uint8Array(n.slice(l.start - l.headerLength, l.end))
|
|
429
498
|
}
|
|
430
499
|
};
|
|
431
500
|
}
|
|
432
501
|
function parsePkcs7AlgorithmOid(e, t, n) {
|
|
433
|
-
return
|
|
502
|
+
return f(h(s(e.slice(t.start - t.headerLength, t.end))[0], n).value);
|
|
434
503
|
}
|
|
435
504
|
/** Unwraps the OCTET STRING inside the IMPLICIT [0] encapsulated content. */
|
|
436
505
|
function extractEncapsulatedContent(e, t) {
|
|
437
506
|
if (t.tag !== 160) throw Error("Unexpected encapsulated content tag");
|
|
438
|
-
let n =
|
|
507
|
+
let n = a(e, t.start);
|
|
439
508
|
if (n.tag !== 4) throw Error("Expected encapsulated OCTET STRING");
|
|
509
|
+
if (n.end !== t.end) throw Error("Encapsulated content must hold exactly one element");
|
|
440
510
|
return n.value;
|
|
441
511
|
}
|
|
442
512
|
/** Extracts issuer Name and serial number from an issuerAndSerialNumber SEQUENCE, or subjectKeyIdentifier from [0] IMPLICIT. */
|
|
443
513
|
function parseSignerIdentifier(e) {
|
|
444
|
-
let t =
|
|
514
|
+
let t = o(e, { maxDepth: 64 });
|
|
445
515
|
if (t.tag === 128) {
|
|
446
516
|
if (t.value.length === 0) throw Error("SignerIdentifier subjectKeyIdentifier must not be empty");
|
|
447
|
-
return {
|
|
517
|
+
return {
|
|
518
|
+
type: "subjectKeyIdentifier",
|
|
519
|
+
subjectKeyIdentifier: _(t.value)
|
|
520
|
+
};
|
|
448
521
|
}
|
|
449
522
|
if (t.tag === 48) {
|
|
450
|
-
let t =
|
|
523
|
+
let t = s(e), n = t[0], r = t[1];
|
|
451
524
|
if (n === void 0 || r === void 0 || t.length !== 2) throw Error("SignerIdentifier issuerAndSerialNumber is malformed");
|
|
452
525
|
if (n.tag !== 48) throw Error("SignerIdentifier issuer must use Name SEQUENCE");
|
|
453
526
|
if (r.tag !== 2) throw Error("SignerIdentifier serialNumber must use INTEGER");
|
|
454
527
|
return assertImplicitSerialNumberEncoding(r.value, "SignerIdentifier serialNumber"), {
|
|
528
|
+
type: "issuerAndSerialNumber",
|
|
455
529
|
issuer: parseSignerIssuerName(e, n),
|
|
456
|
-
serialNumberHex:
|
|
530
|
+
serialNumberHex: _(r.value)
|
|
457
531
|
};
|
|
458
532
|
}
|
|
459
533
|
throw Error(`Unsupported SignerIdentifier tag: ${String(t.tag)}`);
|
|
@@ -461,30 +535,30 @@ function parseSignerIdentifier(e) {
|
|
|
461
535
|
const F = new TextDecoder();
|
|
462
536
|
/** Parses a Name SEQUENCE element from a PKCS#7 signer identifier into a {@linkcode ParsedName}. */
|
|
463
537
|
function parseSignerIssuerName(e, t) {
|
|
464
|
-
let n =
|
|
465
|
-
for (let n of
|
|
538
|
+
let n = _(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
|
|
539
|
+
for (let n of u(e, t)) {
|
|
466
540
|
let t = [], o = {};
|
|
467
|
-
for (let r of
|
|
468
|
-
let n =
|
|
541
|
+
for (let r of u(e, n)) {
|
|
542
|
+
let n = u(e, r), s = h(n[0], "signer issuer attribute OID"), c = h(n[1], "signer issuer attribute value"), l = f(s.value), d;
|
|
469
543
|
try {
|
|
470
|
-
|
|
544
|
+
d = p(c.tag, c.value);
|
|
471
545
|
} catch {
|
|
472
|
-
|
|
546
|
+
d = F.decode(c.value);
|
|
473
547
|
}
|
|
474
|
-
let
|
|
548
|
+
let m = E(l), g = m === void 0 ? {
|
|
475
549
|
oid: l,
|
|
476
550
|
valueTag: c.tag,
|
|
477
|
-
value:
|
|
551
|
+
value: d
|
|
478
552
|
} : {
|
|
479
553
|
oid: l,
|
|
480
|
-
key:
|
|
554
|
+
key: m,
|
|
481
555
|
valueTag: c.tag,
|
|
482
|
-
value:
|
|
556
|
+
value: d
|
|
483
557
|
};
|
|
484
|
-
t.push(
|
|
558
|
+
t.push(g), i.push(g), m !== void 0 && (o[m] === void 0 && (o[m] = d), a[m] === void 0 && (a[m] = d));
|
|
485
559
|
}
|
|
486
560
|
r.push({
|
|
487
|
-
derHex:
|
|
561
|
+
derHex: _(e.slice(n.start - n.headerLength, n.end)),
|
|
488
562
|
attributes: t,
|
|
489
563
|
values: o
|
|
490
564
|
});
|
|
@@ -498,27 +572,27 @@ function parseSignerIssuerName(e, t) {
|
|
|
498
572
|
}
|
|
499
573
|
/** Returns the nth child element inside a constructed ASN.1 element, or throws. */
|
|
500
574
|
function childAt(e, t, n, r) {
|
|
501
|
-
let i = t.start,
|
|
575
|
+
let i = t.start, o = 0;
|
|
502
576
|
for (; i < t.end;) {
|
|
503
|
-
let t =
|
|
504
|
-
if (
|
|
505
|
-
i = t.end,
|
|
577
|
+
let t = a(e, i);
|
|
578
|
+
if (o === n) return t;
|
|
579
|
+
i = t.end, o += 1;
|
|
506
580
|
}
|
|
507
581
|
throw Error(`Missing ${r}`);
|
|
508
582
|
}
|
|
509
583
|
/** Maps a digest algorithm OID to the WebCrypto hash name. */
|
|
510
584
|
function digestAlgorithmHash(e) {
|
|
511
585
|
switch (e) {
|
|
512
|
-
case
|
|
513
|
-
case
|
|
514
|
-
case
|
|
586
|
+
case v.sha256: return "SHA-256";
|
|
587
|
+
case v.sha384: return "SHA-384";
|
|
588
|
+
case v.sha512: return "SHA-512";
|
|
515
589
|
default: throw Error(`Unsupported digest algorithm OID: ${e}`);
|
|
516
590
|
}
|
|
517
591
|
}
|
|
518
592
|
/** Parses required signed attributes and enforces uniqueness + exact-one-value shape. */
|
|
519
593
|
function parseSignedAttributeRequirements(e) {
|
|
520
|
-
let t =
|
|
521
|
-
for (let r of
|
|
594
|
+
let t = a(e), n = {};
|
|
595
|
+
for (let r of u(e, t)) parseSignedAttributeRequirement(e, r, n);
|
|
522
596
|
if (n.messageDigest === void 0) throw Error("Missing messageDigest attribute in signedAttrs");
|
|
523
597
|
if (n.contentTypeOid === void 0) throw Error("Missing contentType attribute in signedAttrs");
|
|
524
598
|
return {
|
|
@@ -527,22 +601,22 @@ function parseSignedAttributeRequirements(e) {
|
|
|
527
601
|
};
|
|
528
602
|
}
|
|
529
603
|
function parseSignedAttributeRequirement(e, t, n) {
|
|
530
|
-
let r = e.slice(t.start - t.headerLength, t.end), i =
|
|
604
|
+
let r = e.slice(t.start - t.headerLength, t.end), i = s(r), a = i[0], o = i[1];
|
|
531
605
|
if (a === void 0 || o === void 0 || i.length !== 2 || o.tag !== 49) throw Error("Malformed signedAttrs attribute");
|
|
532
|
-
let
|
|
533
|
-
|
|
606
|
+
let c = f(a.value), l = u(r, o);
|
|
607
|
+
c === v.cmsMessageDigest && (n.messageDigest = parseUniqueSignedAttributeOctetString(n.messageDigest, l, "messageDigest")), c === v.cmsContentType && (n.contentTypeOid = parseUniqueSignedAttributeOid(n.contentTypeOid, l, "contentType"));
|
|
534
608
|
}
|
|
535
609
|
function parseUniqueSignedAttributeOctetString(e, t, n) {
|
|
536
610
|
if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
|
|
537
|
-
let r =
|
|
611
|
+
let r = h(t[0], `${n} attribute value`);
|
|
538
612
|
if (r.tag !== 4) throw Error(`${n} attribute value must use OCTET STRING`);
|
|
539
613
|
return r.value;
|
|
540
614
|
}
|
|
541
615
|
function parseUniqueSignedAttributeOid(e, t, n) {
|
|
542
616
|
if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
|
|
543
|
-
let r =
|
|
617
|
+
let r = h(t[0], `${n} attribute value`);
|
|
544
618
|
if (r.tag !== 6) throw Error(`${n} attribute value must use OBJECT IDENTIFIER`);
|
|
545
|
-
return
|
|
619
|
+
return f(r.value);
|
|
546
620
|
}
|
|
547
621
|
/** Replaces the IMPLICIT [0] tag (0xa0) with SET OF (0x31) per RFC 5652 Section 5.4. */
|
|
548
622
|
function retagSignedAttrsAsSet(e) {
|
|
@@ -569,7 +643,7 @@ async function verifySignedAttrs(e, t, n, r) {
|
|
|
569
643
|
let a;
|
|
570
644
|
try {
|
|
571
645
|
let t = digestAlgorithmHash(e.digestAlgorithmOid);
|
|
572
|
-
a = new Uint8Array(await
|
|
646
|
+
a = new Uint8Array(await y().subtle.digest(t, g(n)));
|
|
573
647
|
} catch {
|
|
574
648
|
return verifyPkcs7Failure("malformed", "Unsupported digest algorithm in SignedData");
|
|
575
649
|
}
|
|
@@ -591,10 +665,11 @@ async function verifySignedAttrs(e, t, n, r) {
|
|
|
591
665
|
return s ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature over signedAttrs does not verify");
|
|
592
666
|
}
|
|
593
667
|
function signerIdentifierMatches(e, t) {
|
|
594
|
-
|
|
668
|
+
let n = t.signerIdentifier;
|
|
669
|
+
return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && D(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
|
|
595
670
|
}
|
|
596
671
|
function assertImplicitSignedAttrsDer(e) {
|
|
597
|
-
if (
|
|
672
|
+
if (a(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
|
|
598
673
|
}
|
|
599
674
|
function hasReparseablePkcs7SignedData(e) {
|
|
600
675
|
return "der" in e && e.der instanceof Uint8Array;
|