JuliusBrussee/caveman · error

public_key conflicts with public_keys entry

Error message

public_key conflicts with public_keys entry ${current.info.key_id}

What it means

When decoding an embedded keyring, embeddedReceiptKeys() looks up the bundle's `public_key` key_id inside `public_keys`. If an entry with the same key_id exists but its raw key bytes differ, the bundle is internally inconsistent — possibly tampered — and verification aborts with the conflicting key_id in the message.

Solutions

  1. Regenerate or re-export the bundle so `public_key` and the matching `public_keys` entry agree
  2. Remove the stale/conflicting entry from `public_keys`
  3. If tampering is suspected, obtain the bundle from the publisher again

Example fix

// before
{"public_key":{"key_id":"k1","key":"AAA"},"public_keys":[{"key_id":"k1","key":"BBB"}]}
// after
{"public_key":{"key_id":"k1","key":"AAA"},"public_keys":[{"key_id":"k1","key":"AAA"}]}
Defensive patterns

Strategy: validation

Validate before calling

const byId = new Map(bundle.public_keys.map(k => [k.key_id, k]));
const cur = byId.get(bundle.public_key.key_id);
if (cur && cur.key !== bundle.public_key.key) throw new Error(`conflict on ${bundle.public_key.key_id}`);

Type guard

const keyringConsistent = (b: ReceiptBundle): boolean => {
  const hit = b.public_keys?.find(k => k.key_id === b.public_key.key_id);
  return !hit || hit.key === b.public_key.key;
};

Try / catch

try { verifyBundle(bundle) } catch (e) { if (e.message.includes('conflicts with public_keys entry')) { /* treat bundle as tampered; re-download */ } else throw e }

Prevention

When it happens

Trigger: Verifying a bundle where `public_keys` contains an entry with key_id X whose key material differs from the `public_key` field that also declares key_id X (template literal inserts the id).

Common situations: Manual merge of two bundles, a key re-generated with the same id, or copy/paste errors assembling the JSON by hand.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/9673f9adb839b9fd. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:17875

  const keys = new Map<string, DecodedReceiptKey>();
  for (const [index, info] of infos.entries()) {
    const decoded = decodeReceiptKey(info, `${label}[${index}]`);
    if (keys.has(decoded.info.key_id)) throw new Error(`${label} contains duplicate key_id ${decoded.info.key_id}`);
    keys.set(decoded.info.key_id, decoded);
  }
  return keys;
}

function embeddedReceiptKeys(bundle: ReceiptBundle): { current: DecodedReceiptKey; keys: Map<string, DecodedReceiptKey> } {
  if (bundle.schema !== RECEIPT_BUNDLE_V1 && bundle.schema !== RECEIPT_BUNDLE_V2) throw new Error(`unsupported bundle schema ${String(bundle.schema)}`);
  if (bundle.verification_coverage !== undefined && bundle.verification_coverage !== INCLUDED_RECEIPTS_ONLY) throw new Error(`unsupported unsigned verification coverage ${String(bundle.verification_coverage)}`);
  if (bundle.completeness_attested === true) throw new Error("bundle completeness cannot be attested by unsigned export metadata");
  const current = decodeReceiptKey(bundle.public_key, "public_key");
  if (bundle.public_keys !== undefined && !Array.isArray(bundle.public_keys)) throw new Error("public_keys must be an array");
  if (bundle.schema === RECEIPT_BUNDLE_V2 && (!Array.isArray(bundle.public_keys) || bundle.public_keys.length === 0)) throw new Error("v2 bundle requires public_keys");
  const keys = decodeUniqueKeyring(bundle.public_keys ?? [], "public_keys");
  const currentInRing = keys.get(current.info.key_id);
  if (currentInRing && !currentInRing.raw.equals(current.raw)) throw new Error(`public_key conflicts with public_keys entry ${current.info.key_id}`);
  if (bundle.schema === RECEIPT_BUNDLE_V2 && !currentInRing) throw new Error("v2 public_keys must include public_key");
  if (!currentInRing) keys.set(current.info.key_id, current);
  return { current, keys };
}

async function pinnedReceiptKeys(file: string, current: DecodedReceiptKey): Promise<{ keys: Map<string, DecodedReceiptKey>; trust: string }> {
  const source = (await readFile(file, "utf8")).trim();
  if (!source.startsWith("{")) {
    const pinned = decodeReceiptKey({ ...current.info, key: source }, "--pubkey");
    if (!pinned.raw.equals(current.raw)) throw new Error("bundle public key does not match the published --pubkey");
    return { keys: new Map([[current.info.key_id, pinned]]), trust: "pinned_public_key" };
  }
  let parsed: { public_key?: ReceiptPublicKey; public_keys?: ReceiptPublicKey[] };
  try { parsed = JSON.parse(source); } catch { throw new Error("--pubkey JSON is malformed"); }
  const infos = Array.isArray(parsed.public_keys) ? parsed.public_keys : parsed.public_key ? [parsed.public_key] : [];
  if (infos.length === 0) throw new Error("--pubkey JSON must contain public_key or public_keys");
  const keys = decodeUniqueKeyring(infos, "--pubkey public_keys");
  const pinnedCurrent = keys.get(current.info.key_id);

View on GitHub (pinned to 3ee70a1026)