hashedrekord.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.verifyHashedRekordTLogBody = verifyHashedRekordTLogBody;
  4. /*
  5. Copyright 2023 The Sigstore Authors.
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  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. const error_1 = require("../error");
  17. // Compare the given hashedrekord tlog entry to the given bundle
  18. function verifyHashedRekordTLogBody(tlogEntry, content) {
  19. switch (tlogEntry.apiVersion) {
  20. case '0.0.1':
  21. return verifyHashedrekord001TLogBody(tlogEntry, content);
  22. default:
  23. throw new error_1.VerificationError({
  24. code: 'TLOG_BODY_ERROR',
  25. message: `unsupported hashedrekord version: ${tlogEntry.apiVersion}`,
  26. });
  27. }
  28. }
  29. // Compare the given hashedrekord v0.0.1 tlog entry to the given message
  30. // signature
  31. function verifyHashedrekord001TLogBody(tlogEntry, content) {
  32. // Ensure that the bundles message signature matches the tlog entry
  33. const tlogSig = tlogEntry.spec.signature.content || '';
  34. if (!content.compareSignature(Buffer.from(tlogSig, 'base64'))) {
  35. throw new error_1.VerificationError({
  36. code: 'TLOG_BODY_ERROR',
  37. message: 'signature mismatch',
  38. });
  39. }
  40. // Ensure that the bundle's message digest matches the tlog entry
  41. const tlogDigest = tlogEntry.spec.data.hash?.value || '';
  42. if (!content.compareDigest(Buffer.from(tlogDigest, 'hex'))) {
  43. throw new error_1.VerificationError({
  44. code: 'TLOG_BODY_ERROR',
  45. message: 'digest mismatch',
  46. });
  47. }
  48. }