@calimero-network/mero-js 19.27.1 → 20.0.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/dist/index.cjs CHANGED
@@ -100,6 +100,7 @@ __export(index_exports, {
100
100
  signRoutingChallenge: () => signRoutingChallenge,
101
101
  signWarrant: () => signWarrant,
102
102
  transportKeyBinding: () => transportKeyBinding,
103
+ trustedMeasurementsFromReleases: () => trustedMeasurementsFromReleases,
103
104
  withCap: () => withCap,
104
105
  withRetry: () => withRetry,
105
106
  withoutCap: () => withoutCap
@@ -7173,17 +7174,32 @@ async function defaultNonceSource(deviceSecret) {
7173
7174
 
7174
7175
  // src/sealed/verify.ts
7175
7176
  var MEASUREMENT_HEX = /^[0-9a-f]{96}$/;
7177
+ var REGISTERS = ["mrtd", "rtmr0", "rtmr1", "rtmr2", "rtmr3"];
7176
7178
  function createQuoteVerifier(options) {
7177
- const allowedMrtd = measurements(options.allowedMrtd, "allowedMrtd");
7178
- if (allowedMrtd.length === 0) {
7179
- throw new Error("allowedMrtd is empty, so no quote would ever be accepted");
7180
- }
7179
+ const allowedMrtd = measurements(options.allowedMrtd ?? [], "allowedMrtd");
7180
+ const allowedImages = (options.allowedMeasurements ?? []).map((image, index) => {
7181
+ const label = `allowedMeasurements[${index}]`;
7182
+ return REGISTERS.map((register) => measurements([image?.[register] ?? ""], `${label}.${register}`)[0]).join();
7183
+ });
7181
7184
  const allowedRtmr = [
7182
7185
  measurements(options.allowedRtmr0 ?? [], "allowedRtmr0"),
7183
7186
  measurements(options.allowedRtmr1 ?? [], "allowedRtmr1"),
7184
7187
  measurements(options.allowedRtmr2 ?? [], "allowedRtmr2"),
7185
7188
  measurements(options.allowedRtmr3 ?? [], "allowedRtmr3")
7186
7189
  ];
7190
+ if (options.allowedMeasurements !== void 0 && allowedImages.length === 0) {
7191
+ throw new Error("allowedMeasurements is empty, so no quote would ever be accepted");
7192
+ }
7193
+ if (allowedImages.length === 0) {
7194
+ if (allowedMrtd.length === 0) {
7195
+ throw new Error("No image is trusted: give allowedMeasurements, or allowedMrtd with allowedRtmr1-3");
7196
+ }
7197
+ if (allowedRtmr.slice(1).some((list) => list.length === 0)) {
7198
+ throw new Error(
7199
+ "allowedMrtd alone does not name an image: the MRTD measures the TD firmware, which images share, and the image is in RTMR1-3. Give allowedMeasurements, or allowedRtmr1-3 too"
7200
+ );
7201
+ }
7202
+ }
7187
7203
  const allowedStatuses = options.allowedTcbStatuses ?? ["UpToDate"];
7188
7204
  const now = options.now ?? Date.now;
7189
7205
  const verifier = async ({
@@ -7209,8 +7225,14 @@ function createQuoteVerifier(options) {
7209
7225
  throw new Error(`The platform's TCB status is ${verified.status}, which is not accepted`);
7210
7226
  }
7211
7227
  const td = tdReport(verified.report);
7212
- if (!allowedMrtd.includes(hex(td.mrTd))) {
7213
- throw new Error(`MRTD ${hex(td.mrTd)} is not an image this verifier trusts`);
7228
+ const measured = [td.mrTd, td.rtMr0, td.rtMr1, td.rtMr2, td.rtMr3].map((register) => hex(register));
7229
+ if (allowedImages.length > 0 && !allowedImages.includes(measured.join())) {
7230
+ throw new Error(
7231
+ `The measurements (MRTD ${measured[0]}, RTMR0-3 ${measured.slice(1).join(", ")}) are not an image this verifier trusts`
7232
+ );
7233
+ }
7234
+ if (allowedMrtd.length > 0 && !allowedMrtd.includes(measured[0])) {
7235
+ throw new Error(`MRTD ${measured[0]} is not an image this verifier trusts`);
7214
7236
  }
7215
7237
  const registers = [td.rtMr0, td.rtMr1, td.rtMr2, td.rtMr3];
7216
7238
  registers.forEach((register, index) => {
@@ -7247,6 +7269,51 @@ function fromBase64(value) {
7247
7269
  for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
7248
7270
  return bytes;
7249
7271
  }
7272
+ var TCB_STATUSES = [
7273
+ "UpToDate",
7274
+ "SWHardeningNeeded",
7275
+ "ConfigurationNeeded",
7276
+ "ConfigurationAndSWHardeningNeeded",
7277
+ "OutOfDate",
7278
+ "OutOfDateConfigurationNeeded"
7279
+ ];
7280
+ function trustedMeasurementsFromReleases(releases, { profile }) {
7281
+ if (releases.length === 0) {
7282
+ throw new Error("No release given, so no image would be trusted");
7283
+ }
7284
+ let statuses;
7285
+ const allowedMeasurements = releases.map((release, index) => {
7286
+ const name = release?.tag ?? `releases[${index}]`;
7287
+ if (release?.role !== void 0 && release.role !== "node") {
7288
+ throw new Error(`${name} lists the measurements of a ${release.role}, not of a node image`);
7289
+ }
7290
+ const image = release?.profiles?.[profile];
7291
+ if (!image) {
7292
+ const known = Object.keys(release?.profiles ?? {}).join(", ") || "none";
7293
+ throw new Error(`${name} has no profile ${JSON.stringify(profile)} (it has: ${known})`);
7294
+ }
7295
+ const accepted = (image.allowed_tcb_statuses ?? ["uptodate"]).map((status) => tcbStatus(status, name));
7296
+ statuses = statuses === void 0 ? accepted : statuses.filter((status) => accepted.includes(status));
7297
+ return {
7298
+ mrtd: image.mrtd,
7299
+ rtmr0: image.rtmr0,
7300
+ rtmr1: image.rtmr1,
7301
+ rtmr2: image.rtmr2,
7302
+ rtmr3: image.rtmr3
7303
+ };
7304
+ });
7305
+ if (!statuses || statuses.length === 0) {
7306
+ throw new Error("The releases given accept no TCB status in common");
7307
+ }
7308
+ return { allowedMeasurements, allowedTcbStatuses: statuses };
7309
+ }
7310
+ function tcbStatus(status, release) {
7311
+ const known = TCB_STATUSES.find((candidate) => candidate.toLowerCase() === String(status).toLowerCase());
7312
+ if (!known) {
7313
+ throw new Error(`${release} accepts TCB status ${JSON.stringify(status)}, which this verifier does not know`);
7314
+ }
7315
+ return known;
7316
+ }
7250
7317
 
7251
7318
  // src/namespace-op/namespace-op.ts
7252
7319
  var SIGNED_NAMESPACE_OP_SCHEMA_VERSION = 8;