JuliusBrussee/caveman · error

bundle public key does not match the published --pubkey

Error message

bundle public key does not match the published --pubkey

What it means

pinnedReceiptKeys() handles the `--pubkey` option of `receipts verify`. When --pubkey is a raw (non-JSON) key string, the CLI decodes it and requires it to byte-match the bundle's `public_key`. A mismatch means the bundle was not signed with the publisher's published key, so verification fails closed.

Solutions

  1. Obtain the publisher's current public key and pass that as --pubkey
  2. Re-download the bundle from the trusted publisher — the mismatch may indicate tampering or a stale bundle
  3. Remove --pubkey to fall back to embedded-key self-consistency verification (weaker trust)

Example fix

# before
caveman receipts verify bundle.json --pubkey old-rotated-key.b64
# after
caveman receipts verify bundle.json --pubkey current-published-key.b64
Defensive patterns

Strategy: validation

Validate before calling

const pinned = fs.readFileSync(pubkeyPath, 'utf8').trim();
if (!pinned.startsWith('{') && pinned !== bundle.public_key.key) throw new Error('pubkey does not match bundle');

Try / catch

try { await verify(argv) } catch (e) { if (e.message.includes('does not match the published --pubkey')) { console.error('Publisher key rotated? fetch the current key or re-download the bundle'); process.exit(1); } throw e }

Prevention

When it happens

Trigger: `caveman receipts verify bundle.json --pubkey published.key` where published.key is a raw key string whose bytes differ from bundle.public_key.

Common situations: Publisher rotated keys and the user pinned the old key, downloading a bundle from a different publisher, or truncating/corrupting the key file during transfer.

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/ff2c52e67693cd41. Report an issue: GitHub.

Appendix: source

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

  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);
  if (!pinnedCurrent || !pinnedCurrent.raw.equals(current.raw)) throw new Error("trusted --pubkey keyring does not contain the bundle public key");
  return { keys, trust: "pinned_keyring" };
}

// receiptsVerify validates a signed receipt bundle offline (no network). A raw
// --pubkey pins the current key; JSON may independently pin a full rotation
// keyring. Without either, embedded keys prove self-consistency, not publisher
// authenticity. Exits non-zero on any included content, signature, or
// scope-chain break. Tail/scope omission needs separately trusted head manifest;
// bundle output states completeness is not attested.

View on GitHub (pinned to 3ee70a1026)