JuliusBrussee/caveman · error

trusted --pubkey keyring does not contain the bundle public…

Error message

trusted --pubkey keyring does not contain the bundle public key

What it means

With a JSON --pubkey keyring, the trusted ring must contain an entry whose key_id matches the bundle's `public_key` AND whose raw bytes are identical. Otherwise the bundle's current key is not covered by the publisher's published keyring, and verification is refused — the bundle may come from an unknown key.

Solutions

  1. Refresh the --pubkey keyring from the publisher so it includes the current signing key
  2. Re-download the bundle from the trusted source if the key should already be pinned
  3. Drop --pubkey to use embedded-key verification (weaker, self-consistency only)

Example fix

# before
{"public_keys":[{"key_id":"k1",...}]}
# after (adds rotated current key k2)
{"public_keys":[{"key_id":"k1",...},{"key_id":"k2",...}]}
Defensive patterns

Strategy: validation

Validate before calling

const ring = new Map(j.public_keys.map(k => [k.key_id, k]));
const cur = ring.get(bundle.public_key.key_id);
if (!cur || cur.key !== bundle.public_key.key) throw new Error('keyring lacks bundle current key');

Type guard

const keyringCovers = (j: { public_keys?: ReceiptPublicKey[] }, b: ReceiptBundle): boolean =>
  !!j.public_keys?.some(k => k.key_id === b.public_key.key_id && k.key === b.public_key.key);

Try / catch

try { await verify(argv) } catch (e) { if (e.message.includes('keyring does not contain the bundle public key')) { console.error('Refresh the publisher keyring (key rotation?) or re-download the bundle'); process.exit(1); } throw e }

Prevention

When it happens

Trigger: `caveman receipts verify bundle.json --pubkey keys.json` where keys.json lacks the bundle's current key_id, or has it with different key bytes.

Common situations: Publisher rotated to a new key after the user saved the keyring; verifying a bundle from a different publisher; stale keyring cached locally.

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

Appendix: source

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

  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.
//   caveman receipts verify <bundle.json> [--pubkey <file>]
async function receiptsVerify(argv: string[]) {
  const file = positionalAfterOptions(argv.slice(1), new Set(["--pubkey"]));
  if (!file) throw new Error(`usage: ${invokedCommand("receipts")} verify <bundle.json> [--pubkey <file>]`);
  let bundle: ReceiptBundle;
  try { bundle = JSON.parse(await readFile(file, "utf8")) as ReceiptBundle; } catch (e) { return fail(`invalid bundle JSON: ${(e as Error).message}`); }
  if (!Array.isArray(bundle.receipts)) return fail("bundle receipts must be an array");

  try {

View on GitHub (pinned to 3ee70a1026)