Debian Codegraph @

node_modules/@sigstore/verify/dist/tlog/dsse.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.DSSE_API_VERSION_V1 = void 0;
4 exports.verifyDSSETLogBody = verifyDSSETLogBody;
5 exports.verifyDSSETLogBodyV2 = verifyDSSETLogBodyV2;
6 /*
7 Copyright 2025 The Sigstore Authors.
8
9 Licensed under the Apache License, Version 2.0 (the "License");
10 you may not use this file except in compliance with the License.
11 You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
20 */
21 const error_1 = require("../error");
22 exports.DSSE_API_VERSION_V1 = '0.0.1';
23 // Compare the given dsse tlog entry to the given bundle
24 function verifyDSSETLogBody(tlogEntry, content) {
25 switch (tlogEntry.apiVersion) {
26 case exports.DSSE_API_VERSION_V1:
27 return verifyDSSE001TLogBody(tlogEntry, content);
28 default:
29 throw new error_1.VerificationError({
30 code: 'TLOG_BODY_ERROR',
31 message: `unsupported dsse version: ${tlogEntry.apiVersion}`,
32 });
33 }
34 }
35 // Compare the given dsse tlog entry to the given bundle. This function is
36 // specifically for Rekor V2 entries.
37 function verifyDSSETLogBodyV2(tlogEntry, content) {
38 const spec = tlogEntry.spec?.spec;
39 if (!spec) {
40 throw new error_1.VerificationError({
41 code: 'TLOG_BODY_ERROR',
42 message: `missing dsse spec`,
43 });
44 }
45 switch (spec.$case) {
46 case 'dsseV002':
47 return verifyDSSE002TLogBody(spec.dsseV002, content);
48 default:
49 throw new error_1.VerificationError({
50 code: 'TLOG_BODY_ERROR',
51 message: `unsupported version: ${spec.$case}`,
52 });
53 }
54 }
55 // Compare the given dsse v0.0.1 tlog entry to the given DSSE envelope.
56 function verifyDSSE001TLogBody(tlogEntry, content) {
57 // Ensure the bundle's DSSE only contains a single signature
58 if (tlogEntry.spec.signatures?.length !== 1) {
59 throw new error_1.VerificationError({
60 code: 'TLOG_BODY_ERROR',
61 message: 'signature count mismatch',
62 });
63 }
64 const tlogSig = tlogEntry.spec.signatures[0].signature;
65 // Ensure that the signature in the bundle's DSSE matches tlog entry
66 if (!content.compareSignature(Buffer.from(tlogSig, 'base64')))
67 throw new error_1.VerificationError({
68 code: 'TLOG_BODY_ERROR',
69 message: 'tlog entry signature mismatch',
70 });
71 // Ensure the digest of the bundle's DSSE payload matches the digest in the
72 // tlog entry
73 const tlogHash = tlogEntry.spec.payloadHash?.value || '';
74 if (!content.compareDigest(Buffer.from(tlogHash, 'hex'))) {
75 throw new error_1.VerificationError({
76 code: 'TLOG_BODY_ERROR',
77 message: 'DSSE payload hash mismatch',
78 });
79 }
80 }
81 // Compare the given dsse v0.0.2 tlog entry to the given DSSE envelope.
82 function verifyDSSE002TLogBody(spec, content) {
83 // Ensure the bundle's DSSE only contains a single signature
84 if (spec.signatures?.length !== 1) {
85 throw new error_1.VerificationError({
86 code: 'TLOG_BODY_ERROR',
87 message: 'signature count mismatch',
88 });
89 }
90 const tlogSig = spec.signatures[0].content;
91 // Ensure that the signature in the bundle's DSSE matches tlog entry
92 if (!content.compareSignature(tlogSig))
93 throw new error_1.VerificationError({
94 code: 'TLOG_BODY_ERROR',
95 message: 'tlog entry signature mismatch',
96 });
97 // Ensure the digest of the bundle's DSSE payload matches the digest in the
98 // tlog entry
99 const tlogHash = spec.payloadHash?.digest || Buffer.from('');
100 if (!content.compareDigest(tlogHash)) {
101 throw new error_1.VerificationError({
102 code: 'TLOG_BODY_ERROR',
103 message: 'DSSE payload hash mismatch',
104 });
105 }
106 }