@freedomofpress/sigstore-browser 0.1.14 → 0.1.16
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 +20 -16
- package/dist/bundle.d.ts +3 -2
- package/dist/bundle.js +66 -1
- package/dist/bundle.js.map +1 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js.map +1 -1
- package/dist/dsse.d.ts +0 -1
- package/dist/dsse.js.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +9 -10
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +18 -4
- package/dist/interfaces.js +15 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/oid.d.ts +0 -1
- package/dist/oid.js.map +1 -1
- package/dist/policy.d.ts +3 -4
- package/dist/policy.js +5 -5
- package/dist/policy.js.map +1 -1
- package/dist/rfc3161/error.d.ts +0 -1
- package/dist/rfc3161/error.js.map +1 -1
- package/dist/rfc3161/index.d.ts +0 -1
- package/dist/rfc3161/index.js.map +1 -1
- package/dist/rfc3161/timestamp.d.ts +0 -1
- package/dist/rfc3161/timestamp.js.map +1 -1
- package/dist/rfc3161/tstinfo.d.ts +0 -1
- package/dist/rfc3161/tstinfo.js.map +1 -1
- package/dist/sigstore.d.ts +10 -20
- package/dist/sigstore.js +167 -400
- package/dist/sigstore.js.map +1 -1
- package/dist/timestamp/tsa.d.ts +6 -3
- package/dist/timestamp/tsa.js +16 -19
- package/dist/timestamp/tsa.js.map +1 -1
- package/dist/tlog/body.d.ts +3 -2
- package/dist/tlog/body.js +19 -6
- package/dist/tlog/body.js.map +1 -1
- package/dist/tlog/checkpoint.d.ts +2 -3
- package/dist/tlog/checkpoint.js +17 -95
- package/dist/tlog/checkpoint.js.map +1 -1
- package/dist/tlog/dsse.d.ts +3 -3
- package/dist/tlog/dsse.js +11 -5
- package/dist/tlog/dsse.js.map +1 -1
- package/dist/tlog/hashedrekord.d.ts +3 -3
- package/dist/tlog/hashedrekord.js +8 -5
- package/dist/tlog/hashedrekord.js.map +1 -1
- package/dist/tlog/intoto.d.ts +3 -3
- package/dist/tlog/intoto.js +3 -1
- package/dist/tlog/intoto.js.map +1 -1
- package/dist/tlog/merkle.d.ts +0 -1
- package/dist/tlog/merkle.js.map +1 -1
- package/dist/trust/tuf-root.d.ts +0 -1
- package/dist/trust/tuf-root.js.map +1 -1
- package/dist/trust/tuf.d.ts +0 -1
- package/dist/trust/tuf.js.map +1 -1
- package/dist/x509/cert.d.ts +0 -1
- package/dist/x509/cert.js +1 -1
- package/dist/x509/cert.js.map +1 -1
- package/dist/x509/chain.d.ts +0 -1
- package/dist/x509/chain.js +2 -2
- package/dist/x509/chain.js.map +1 -1
- package/dist/x509/ext.d.ts +0 -1
- package/dist/x509/ext.js.map +1 -1
- package/dist/x509/index.d.ts +1 -2
- package/dist/x509/index.js +1 -1
- package/dist/x509/index.js.map +1 -1
- package/dist/x509/sct.d.ts +0 -1
- package/dist/x509/sct.js.map +1 -1
- package/package.json +15 -8
- package/.github/workflows/conformance.yml +0 -29
- package/.github/workflows/publish.yml +0 -47
- package/dist/bundle.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/dsse.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interfaces.d.ts.map +0 -1
- package/dist/oid.d.ts.map +0 -1
- package/dist/policy.d.ts.map +0 -1
- package/dist/rfc3161/error.d.ts.map +0 -1
- package/dist/rfc3161/index.d.ts.map +0 -1
- package/dist/rfc3161/timestamp.d.ts.map +0 -1
- package/dist/rfc3161/tstinfo.d.ts.map +0 -1
- package/dist/sigstore.d.ts.map +0 -1
- package/dist/timestamp/tsa.d.ts.map +0 -1
- package/dist/tlog/body.d.ts.map +0 -1
- package/dist/tlog/checkpoint.d.ts.map +0 -1
- package/dist/tlog/dsse.d.ts.map +0 -1
- package/dist/tlog/hashedrekord.d.ts.map +0 -1
- package/dist/tlog/intoto.d.ts.map +0 -1
- package/dist/tlog/merkle.d.ts.map +0 -1
- package/dist/trust/tuf-root.d.ts.map +0 -1
- package/dist/trust/tuf.d.ts.map +0 -1
- package/dist/x509/cert.d.ts.map +0 -1
- package/dist/x509/chain.d.ts.map +0 -1
- package/dist/x509/ext.d.ts.map +0 -1
- package/dist/x509/index.d.ts.map +0 -1
- package/dist/x509/sct.d.ts.map +0 -1
- package/eslint.config.mjs +0 -31
- package/src/bundle.ts +0 -99
- package/src/cli.ts +0 -290
- package/src/dsse.ts +0 -49
- package/src/errors.ts +0 -82
- package/src/index.browser.test.ts +0 -290
- package/src/index.ts +0 -93
- package/src/interfaces.ts +0 -123
- package/src/oid.ts +0 -34
- package/src/policy.ts +0 -476
- package/src/rfc3161/error.ts +0 -16
- package/src/rfc3161/index.ts +0 -17
- package/src/rfc3161/timestamp.ts +0 -268
- package/src/rfc3161/tstinfo.ts +0 -78
- package/src/sigstore.ts +0 -948
- package/src/timestamp/tsa.ts +0 -211
- package/src/tlog/body.ts +0 -65
- package/src/tlog/checkpoint.ts +0 -254
- package/src/tlog/dsse.ts +0 -147
- package/src/tlog/hashedrekord.ts +0 -130
- package/src/tlog/intoto.ts +0 -106
- package/src/tlog/merkle.ts +0 -152
- package/src/trust/README.md +0 -38
- package/src/trust/tuf-root.ts +0 -3
- package/src/trust/tuf.ts +0 -233
- package/src/x509/cert.ts +0 -569
- package/src/x509/chain.ts +0 -212
- package/src/x509/ext.ts +0 -356
- package/src/x509/index.ts +0 -19
- package/src/x509/sct.ts +0 -156
- package/tsconfig.json +0 -18
- package/vite.config.playwright.ts +0 -14
- package/vite.config.ts +0 -18
package/src/rfc3161/timestamp.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2023 The Sigstore Authors.
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { ASN1Obj, uint8ArrayEqual, verifySignature } from "@freedomofpress/crypto-browser";
|
|
17
|
-
import { HashAlgorithms } from "../interfaces.js";
|
|
18
|
-
import { ECDSA_SIGNATURE_ALGOS, RSA_SIGNATURE_ALGOS, SHA2_HASH_ALGOS } from "../oid.js";
|
|
19
|
-
import { RFC3161TimestampVerificationError } from "./error.js";
|
|
20
|
-
import { TSTInfo } from "./tstinfo.js";
|
|
21
|
-
|
|
22
|
-
const OID_PKCS9_CONTENT_TYPE_SIGNED_DATA = "1.2.840.113549.1.7.2";
|
|
23
|
-
const OID_PKCS9_CONTENT_TYPE_TSTINFO = "1.2.840.113549.1.9.16.1.4";
|
|
24
|
-
const OID_PKCS9_MESSAGE_DIGEST_KEY = "1.2.840.113549.1.9.4";
|
|
25
|
-
|
|
26
|
-
export class RFC3161Timestamp {
|
|
27
|
-
public root: ASN1Obj;
|
|
28
|
-
|
|
29
|
-
constructor(asn1: ASN1Obj) {
|
|
30
|
-
this.root = asn1;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public static parse(der: Uint8Array): RFC3161Timestamp {
|
|
34
|
-
const asn1 = ASN1Obj.parseBuffer(der);
|
|
35
|
-
return new RFC3161Timestamp(asn1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get status(): bigint {
|
|
39
|
-
return this.pkiStatusInfoObj.subs[0].toInteger();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get contentType(): string {
|
|
43
|
-
return this.contentTypeObj.toOID();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get eContentType(): string {
|
|
47
|
-
return this.eContentTypeObj.toOID();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get signingTime(): Date {
|
|
51
|
-
return this.tstInfo.genTime;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get signerIssuer(): Uint8Array {
|
|
55
|
-
return this.signerSidObj.subs[0].value;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get signerSerialNumber(): Uint8Array {
|
|
59
|
-
return this.signerSidObj.subs[1].value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get signerDigestAlgorithm(): string {
|
|
63
|
-
const oid = this.signerDigestAlgorithmObj.subs[0].toOID();
|
|
64
|
-
const algo = SHA2_HASH_ALGOS[oid];
|
|
65
|
-
if (!algo) {
|
|
66
|
-
throw new Error(`Unknown digest algorithm OID: ${oid}`);
|
|
67
|
-
}
|
|
68
|
-
return algo;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get signatureAlgorithm(): string {
|
|
72
|
-
const oid = this.signatureAlgorithmObj.subs[0].toOID();
|
|
73
|
-
const algo = ECDSA_SIGNATURE_ALGOS[oid] || RSA_SIGNATURE_ALGOS[oid];
|
|
74
|
-
return algo;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get signatureValue(): Uint8Array {
|
|
78
|
-
return this.signatureValueObj.value;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get tstInfo(): TSTInfo {
|
|
82
|
-
// Need to unpack tstInfo from an OCTET STRING
|
|
83
|
-
return new TSTInfo(this.eContentObj.subs[0].subs[0]);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public async verify(data: Uint8Array, publicKey: CryptoKey): Promise<void> {
|
|
87
|
-
if (!this.timeStampTokenObj) {
|
|
88
|
-
throw new RFC3161TimestampVerificationError("timeStampToken is missing");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Check for expected ContentInfo content type
|
|
92
|
-
if (this.contentType !== OID_PKCS9_CONTENT_TYPE_SIGNED_DATA) {
|
|
93
|
-
throw new RFC3161TimestampVerificationError(
|
|
94
|
-
`incorrect content type: ${this.contentType}`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Check for expected encapsulated content type
|
|
99
|
-
if (this.eContentType !== OID_PKCS9_CONTENT_TYPE_TSTINFO) {
|
|
100
|
-
throw new RFC3161TimestampVerificationError(
|
|
101
|
-
`incorrect encapsulated content type: ${this.eContentType}`,
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Check that the tstInfo references the correct artifact
|
|
106
|
-
await this.tstInfo.verify(data);
|
|
107
|
-
// Check that the signed message digest matches the tstInfo
|
|
108
|
-
await this.verifyMessageDigest();
|
|
109
|
-
// Check that the signature is valid for the signed attributes
|
|
110
|
-
await this.verifySignature(publicKey);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private async verifyMessageDigest(): Promise<void> {
|
|
114
|
-
// Check that the tstInfo matches the signed data
|
|
115
|
-
const hashAlg = this.signerDigestAlgorithm;
|
|
116
|
-
|
|
117
|
-
// Convert hash algorithm name to the format expected by WebCrypto
|
|
118
|
-
const hashAlgName = hashAlg === "sha256" ? HashAlgorithms.SHA256 :
|
|
119
|
-
hashAlg === "sha384" ? HashAlgorithms.SHA384 :
|
|
120
|
-
hashAlg === "sha512" ? HashAlgorithms.SHA512 : hashAlg;
|
|
121
|
-
|
|
122
|
-
const tstInfoDigest = await crypto.subtle.digest(
|
|
123
|
-
hashAlgName,
|
|
124
|
-
this.tstInfo.raw as BufferSource,
|
|
125
|
-
);
|
|
126
|
-
const expectedDigest = this.messageDigestAttributeObj.subs[1].subs[0].value;
|
|
127
|
-
|
|
128
|
-
if (!uint8ArrayEqual(new Uint8Array(tstInfoDigest), expectedDigest)) {
|
|
129
|
-
throw new RFC3161TimestampVerificationError(
|
|
130
|
-
"signed data does not match tstInfo",
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private async verifySignature(key: CryptoKey): Promise<void> {
|
|
136
|
-
// Encode the signed attributes for verification
|
|
137
|
-
const signedAttrs = this.signedAttrsObj.toDER();
|
|
138
|
-
signedAttrs[0] = 0x31; // Change context-specific tag to SET
|
|
139
|
-
|
|
140
|
-
const oid = this.signatureAlgorithmObj.subs[0].toOID();
|
|
141
|
-
// Try both ECDSA and RSA signature algorithms
|
|
142
|
-
const algo = ECDSA_SIGNATURE_ALGOS[oid] || RSA_SIGNATURE_ALGOS[oid];
|
|
143
|
-
|
|
144
|
-
if (!algo) {
|
|
145
|
-
throw new RFC3161TimestampVerificationError(
|
|
146
|
-
`Unsupported signature algorithm OID: ${oid}`,
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Check that the signature is valid for the signed attributes
|
|
151
|
-
const verified = await verifySignature(
|
|
152
|
-
key,
|
|
153
|
-
signedAttrs,
|
|
154
|
-
this.signatureValue,
|
|
155
|
-
algo,
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
if (!verified) {
|
|
159
|
-
throw new RFC3161TimestampVerificationError(
|
|
160
|
-
"signature verification failed",
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// https://www.rfc-editor.org/rfc/rfc3161#section-2.4.2
|
|
166
|
-
private get pkiStatusInfoObj(): ASN1Obj {
|
|
167
|
-
// pkiStatusInfo is the first element of the timestamp response sequence
|
|
168
|
-
return this.root.subs[0];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// https://www.rfc-editor.org/rfc/rfc3161#section-2.4.2
|
|
172
|
-
private get timeStampTokenObj(): ASN1Obj {
|
|
173
|
-
// timeStampToken is the first element of the timestamp response sequence
|
|
174
|
-
return this.root.subs[1];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-3
|
|
178
|
-
private get contentTypeObj(): ASN1Obj {
|
|
179
|
-
return this.timeStampTokenObj.subs[0];
|
|
180
|
-
}
|
|
181
|
-
// https://www.rfc-editor.org/rfc/rfc5652#section-3
|
|
182
|
-
private get signedDataObj(): ASN1Obj {
|
|
183
|
-
const obj = this.timeStampTokenObj.subs.find((sub) =>
|
|
184
|
-
sub.tag.isContextSpecific(0x00),
|
|
185
|
-
);
|
|
186
|
-
if (!obj) {
|
|
187
|
-
throw new RFC3161TimestampVerificationError(
|
|
188
|
-
"Missing timeStampTokenObj sub.",
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
return obj.subs[0];
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.1
|
|
195
|
-
private get encapContentInfoObj(): ASN1Obj {
|
|
196
|
-
return this.signedDataObj.subs[2];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.1
|
|
200
|
-
private get signerInfosObj(): ASN1Obj {
|
|
201
|
-
// SignerInfos is the last element of the signed data sequence
|
|
202
|
-
const sd = this.signedDataObj;
|
|
203
|
-
return sd.subs[sd.subs.length - 1];
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// https://www.rfc-editor.org/rfc/rfc5652#section-5.1
|
|
207
|
-
private get signerInfoObj(): ASN1Obj {
|
|
208
|
-
// Only supporting one signer
|
|
209
|
-
return this.signerInfosObj.subs[0];
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.2
|
|
213
|
-
private get eContentTypeObj(): ASN1Obj {
|
|
214
|
-
return this.encapContentInfoObj.subs[0];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.2
|
|
218
|
-
private get eContentObj(): ASN1Obj {
|
|
219
|
-
return this.encapContentInfoObj.subs[1];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
223
|
-
private get signedAttrsObj(): ASN1Obj {
|
|
224
|
-
const signedAttrs = this.signerInfoObj.subs.find((sub) =>
|
|
225
|
-
sub.tag.isContextSpecific(0x00),
|
|
226
|
-
);
|
|
227
|
-
if (!signedAttrs) {
|
|
228
|
-
throw new RFC3161TimestampVerificationError("Missing signedAttrsObj.");
|
|
229
|
-
}
|
|
230
|
-
return signedAttrs;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
234
|
-
private get messageDigestAttributeObj(): ASN1Obj {
|
|
235
|
-
const messageDigest = this.signedAttrsObj.subs.find(
|
|
236
|
-
(sub) =>
|
|
237
|
-
sub.subs[0].tag.isOID() &&
|
|
238
|
-
sub.subs[0].toOID() === OID_PKCS9_MESSAGE_DIGEST_KEY,
|
|
239
|
-
);
|
|
240
|
-
if (!messageDigest) {
|
|
241
|
-
throw new RFC3161TimestampVerificationError("Missing messageDigest.");
|
|
242
|
-
}
|
|
243
|
-
return messageDigest;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
247
|
-
private get signerSidObj(): ASN1Obj {
|
|
248
|
-
return this.signerInfoObj.subs[1];
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
252
|
-
private get signerDigestAlgorithmObj(): ASN1Obj {
|
|
253
|
-
// Signature is the 2nd element of the signerInfoObj object
|
|
254
|
-
return this.signerInfoObj.subs[2];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
258
|
-
private get signatureAlgorithmObj(): ASN1Obj {
|
|
259
|
-
// Signature is the 4th element of the signerInfoObj object
|
|
260
|
-
return this.signerInfoObj.subs[4];
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
264
|
-
private get signatureValueObj(): ASN1Obj {
|
|
265
|
-
// Signature is the 6th element of the signerInfoObj object
|
|
266
|
-
return this.signerInfoObj.subs[5];
|
|
267
|
-
}
|
|
268
|
-
}
|
package/src/rfc3161/tstinfo.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2023 The Sigstore Authors.
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { ASN1Obj, uint8ArrayEqual } from "@freedomofpress/crypto-browser";
|
|
17
|
-
import { HashAlgorithms } from "../interfaces.js";
|
|
18
|
-
import { SHA2_HASH_ALGOS } from "../oid.js";
|
|
19
|
-
import { RFC3161TimestampVerificationError } from "./error.js";
|
|
20
|
-
|
|
21
|
-
export class TSTInfo {
|
|
22
|
-
public root: ASN1Obj;
|
|
23
|
-
|
|
24
|
-
constructor(asn1: ASN1Obj) {
|
|
25
|
-
this.root = asn1;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get version(): bigint {
|
|
29
|
-
return this.root.subs[0].toInteger();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get genTime(): Date {
|
|
33
|
-
return this.root.subs[4].toDate();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get messageImprintHashAlgorithm(): string {
|
|
37
|
-
const oid = this.messageImprintObj.subs[0].subs[0].toOID();
|
|
38
|
-
const algo = SHA2_HASH_ALGOS[oid];
|
|
39
|
-
if (!algo) {
|
|
40
|
-
throw new Error(`Unknown message imprint hash algorithm OID: ${oid}`);
|
|
41
|
-
}
|
|
42
|
-
return algo;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get messageImprintHashedMessage(): Uint8Array {
|
|
46
|
-
return this.messageImprintObj.subs[1].value;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get raw(): Uint8Array {
|
|
50
|
-
return this.root.toDER();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async verify(data: Uint8Array): Promise<void> {
|
|
54
|
-
const hashAlg = this.messageImprintHashAlgorithm;
|
|
55
|
-
|
|
56
|
-
// Convert hash algorithm name to the format expected by WebCrypto
|
|
57
|
-
const hashAlgName = hashAlg === "sha256" ? HashAlgorithms.SHA256 :
|
|
58
|
-
hashAlg === "sha384" ? HashAlgorithms.SHA384 :
|
|
59
|
-
hashAlg === "sha512" ? HashAlgorithms.SHA512 : hashAlg;
|
|
60
|
-
|
|
61
|
-
const digest = await crypto.subtle.digest(
|
|
62
|
-
hashAlgName,
|
|
63
|
-
data as BufferSource,
|
|
64
|
-
);
|
|
65
|
-
if (
|
|
66
|
-
!uint8ArrayEqual(new Uint8Array(digest), this.messageImprintHashedMessage)
|
|
67
|
-
) {
|
|
68
|
-
throw new RFC3161TimestampVerificationError(
|
|
69
|
-
"message imprint does not match artifact",
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// https://www.rfc-editor.org/rfc/rfc3161#section-2.4.2
|
|
75
|
-
private get messageImprintObj(): ASN1Obj {
|
|
76
|
-
return this.root.subs[2];
|
|
77
|
-
}
|
|
78
|
-
}
|