| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.verifyTLogSET = verifyTLogSET; |
| 4 |
/* |
| 5 |
Copyright 2023 The Sigstore Authors. |
| 6 |
|
| 7 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
you may not use this file except in compliance with the License. |
| 9 |
You may obtain a copy of the License at |
| 10 |
|
| 11 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
|
| 13 |
Unless required by applicable law or agreed to in writing, software |
| 14 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
See the License for the specific language governing permissions and |
| 17 |
limitations under the License. |
| 18 |
*/ |
| 19 |
const core_1 = require("@sigstore/core"); |
| 20 |
const error_1 = require("../error"); |
| 21 |
const trust_1 = require("../trust"); |
| 22 |
// Verifies the SET for the given entry against the list of trusted |
| 23 |
// transparency logs. Returns true if the SET can be verified against at least |
| 24 |
// one of the trusted logs; otherwise, returns false. |
| 25 |
function verifyTLogSET(entry, tlogs) { |
| 26 |
// Filter the list of tlog instances to only those which might be able to |
| 27 |
// verify the SET |
| 28 |
const validTLogs = (0, trust_1.filterTLogAuthorities)(tlogs, { |
| 29 |
logID: entry.logId.keyId, |
| 30 |
targetDate: new Date(Number(entry.integratedTime) * 1000), |
| 31 |
}); |
| 32 |
// Check to see if we can verify the SET against any of the valid tlogs |
| 33 |
const verified = validTLogs.some((tlog) => { |
| 34 |
// Re-create the original Rekor verification payload |
| 35 |
const payload = toVerificationPayload(entry); |
| 36 |
// Canonicalize the payload and turn into a buffer for verification |
| 37 |
const data = Buffer.from(core_1.json.canonicalize(payload), 'utf8'); |
| 38 |
// Extract the SET from the tlog entry |
| 39 |
const signature = entry.inclusionPromise.signedEntryTimestamp; |
| 40 |
return core_1.crypto.verify(data, tlog.publicKey, signature); |
| 41 |
}); |
| 42 |
if (!verified) { |
| 43 |
throw new error_1.VerificationError({ |
| 44 |
code: 'TLOG_INCLUSION_PROMISE_ERROR', |
| 45 |
message: 'inclusion promise could not be verified', |
| 46 |
}); |
| 47 |
} |
| 48 |
} |
| 49 |
// Returns a properly formatted "VerificationPayload" for one of the |
| 50 |
// transaction log entires in the given bundle which can be used for SET |
| 51 |
// verification. |
| 52 |
function toVerificationPayload(entry) { |
| 53 |
const { integratedTime, logIndex, logId, canonicalizedBody } = entry; |
| 54 |
return { |
| 55 |
body: canonicalizedBody.toString('base64'), |
| 56 |
integratedTime: Number(integratedTime), |
| 57 |
logIndex: Number(logIndex), |
| 58 |
logID: logId.keyId.toString('hex'), |
| 59 |
}; |
| 60 |
} |