{"record":{"id":"15004f0f0fc575af","repo":"JuliusBrussee/caveman","slug":"trusted-pubkey-keyring-does-not-contain-the-bund","errorCode":null,"errorMessage":"trusted --pubkey keyring does not contain the bundle public key","messagePattern":"trusted --pubkey keyring does not contain the bundle public key","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17894,"sourceCode":"  if (bundle.schema === RECEIPT_BUNDLE_V2 && !currentInRing) throw new Error(\"v2 public_keys must include public_key\");\n  if (!currentInRing) keys.set(current.info.key_id, current);\n  return { current, keys };\n}\n\nasync function pinnedReceiptKeys(file: string, current: DecodedReceiptKey): Promise<{ keys: Map<string, DecodedReceiptKey>; trust: string }> {\n  const source = (await readFile(file, \"utf8\")).trim();\n  if (!source.startsWith(\"{\")) {\n    const pinned = decodeReceiptKey({ ...current.info, key: source }, \"--pubkey\");\n    if (!pinned.raw.equals(current.raw)) throw new Error(\"bundle public key does not match the published --pubkey\");\n    return { keys: new Map([[current.info.key_id, pinned]]), trust: \"pinned_public_key\" };\n  }\n  let parsed: { public_key?: ReceiptPublicKey; public_keys?: ReceiptPublicKey[] };\n  try { parsed = JSON.parse(source); } catch { throw new Error(\"--pubkey JSON is malformed\"); }\n  const infos = Array.isArray(parsed.public_keys) ? parsed.public_keys : parsed.public_key ? [parsed.public_key] : [];\n  if (infos.length === 0) throw new Error(\"--pubkey JSON must contain public_key or public_keys\");\n  const keys = decodeUniqueKeyring(infos, \"--pubkey public_keys\");\n  const pinnedCurrent = keys.get(current.info.key_id);\n  if (!pinnedCurrent || !pinnedCurrent.raw.equals(current.raw)) throw new Error(\"trusted --pubkey keyring does not contain the bundle public key\");\n  return { keys, trust: \"pinned_keyring\" };\n}\n\n// receiptsVerify validates a signed receipt bundle offline (no network). A raw\n// --pubkey pins the current key; JSON may independently pin a full rotation\n// keyring. Without either, embedded keys prove self-consistency, not publisher\n// authenticity. Exits non-zero on any included content, signature, or\n// scope-chain break. Tail/scope omission needs separately trusted head manifest;\n// bundle output states completeness is not attested.\n//   caveman receipts verify <bundle.json> [--pubkey <file>]\nasync function receiptsVerify(argv: string[]) {\n  const file = positionalAfterOptions(argv.slice(1), new Set([\"--pubkey\"]));\n  if (!file) throw new Error(`usage: ${invokedCommand(\"receipts\")} verify <bundle.json> [--pubkey <file>]`);\n  let bundle: ReceiptBundle;\n  try { bundle = JSON.parse(await readFile(file, \"utf8\")) as ReceiptBundle; } catch (e) { return fail(`invalid bundle JSON: ${(e as Error).message}`); }\n  if (!Array.isArray(bundle.receipts)) return fail(\"bundle receipts must be an array\");\n\n  try {","sourceCodeStart":17876,"sourceCodeEnd":17912,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L17876-L17912","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Publisher rotated to a new key after the user saved the keyring; verifying a bundle from a different publisher; stale keyring cached locally.","solutions":["Refresh the --pubkey keyring from the publisher so it includes the current signing key","Re-download the bundle from the trusted source if the key should already be pinned","Drop --pubkey to use embedded-key verification (weaker, self-consistency only)"],"exampleFix":"# before\n{\"public_keys\":[{\"key_id\":\"k1\",...}]}\n# after (adds rotated current key k2)\n{\"public_keys\":[{\"key_id\":\"k1\",...},{\"key_id\":\"k2\",...}]}","handlingStrategy":"validation","validationCode":"const ring = new Map(j.public_keys.map(k => [k.key_id, k]));\nconst cur = ring.get(bundle.public_key.key_id);\nif (!cur || cur.key !== bundle.public_key.key) throw new Error('keyring lacks bundle current key');","typeGuard":"const keyringCovers = (j: { public_keys?: ReceiptPublicKey[] }, b: ReceiptBundle): boolean =>\n  !!j.public_keys?.some(k => k.key_id === b.public_key.key_id && k.key === b.public_key.key);","tryCatchPattern":"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 }","preventionTips":["Subscribe to publisher key-rotation notices and refresh keyrings","Cache keyrings with a TTL and re-fetch on verification failure","Verify bundle provenance before assuming the keyring is stale"],"tags":["security","keyring","key-pinning","receipt-bundle"],"backgroundTag":"checksum-mismatch","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}