Skip to content

fix(identities): key the verified-identity cache by identity hash, not by signatures.id - #1259

Open
NiKrause wants to merge 1 commit into
orbitdb:mainfrom
NiKrause:fix/identity-cache-by-hash
Open

NiKrause wants to merge 1 commit into
orbitdb:mainfrom
NiKrause:fix/identity-cache-by-hash

Conversation

@NiKrause

Copy link
Copy Markdown
Contributor

Fixes #1258.

What goes wrong

Identities.verifyIdentity caches a verified identity under signatures.id and, on a hit, answers isEqual(identity, cached). Two identity documents can carry the same id signature — the same key signing the same id, deterministically — and still differ in the provider's proof, signatures.publicKey. Whichever of them is verified first then makes every other one fail the comparison, although the provider would have verified it.

With the WebAuthn DID identity provider (signing key derived from the passkey's PRF output, proof a fresh WebAuthn assertion per session) this is every second session of the same passkey: after joining entries another session wrote, a device cannot write to its own database — "Could not append entry: Key … is not allowed to write to the log". Two applications carry a workaround for it today.

The fix

Key the cache by the identity's hash, which names one document. The comparison on a hit stays as a cheap integrity check. No API change.

Test

verify two identities with the same id signature: two documents of one key with the same id signature and different proofs, under a provider that verifies both; both must verify whichever came first. Fails on main, passes with the change. npm run lint clean.

…t by signatures.id

Two identity documents can carry the same id signature — the same key signing
the same id, deterministically — and still differ in the provider's proof,
`signatures.publicKey`. Keyed by `signatures.id`, the cache let whichever of
them was verified first make every other one fail the `isEqual` comparison,
although the provider would have verified it. Seen with the WebAuthn DID
identity provider, whose signing key is derived from the passkey and whose
proof is a fresh assertion per session: a device could not write to a
database after joining entries another session of the same passkey had
written (orbitdb#1258).

The identity's hash names one document, so the cache is keyed by it; the
comparison on a hit stays as a cheap integrity check.

The test builds two documents of one key with the same id signature and
different proofs under a provider that verifies both, and expects both to
verify whichever came first. It fails on the previous code.

Fixes orbitdb#1258

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@NiKrause

Copy link
Copy Markdown
Contributor Author

The failing job is the browser suite's Log - Replication › replicates logs (a 5 s timeout in a two-peer test). It fails on unpatched main too: locally, with a fresh relay, npm run test:browser on main's identities.js/identities.test.js failed that same test once, while the branch passed the full browser suite (544) twice in a row. The Node suite passes on the branch (546). So this looks like the known flakiness of the browser peer tests rather than the change; a re-run of test-browser should go green. Happy to add anything else.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

verifyIdentity refuses a valid identity when another one with the same signatures.id is cached

1 participant