Skip to content

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

Done

Description

@NiKrause

Summary

Identities.verifyIdentity caches verified identities by signatures.id and, on a cache hit, returns isEqual(identity, cached) (src/identities/identities.js L118–L128 at 2ee8387):

const verifiedIdentity = await verifiedIdentitiesCache.get(signatures.id)
if (verifiedIdentity) {
  return isEqual(identity, verifiedIdentity)
}

This assumes that one signatures.id belongs to exactly one identity document. That is not true for providers whose identity carries a fresh proof per session while the key that signs the id stays the same. A second, equally valid identity for the same id is then refused without the provider ever being asked. Through IPFSAccessController.canAppend, every entry it signed is refused too:

Could not append entry: Key "<identity hash>" is not allowed to write to the log

Where it happens

We use @le-space/orbitdb-identity-provider-webauthn-did (type webauthn). How its identities are made:

  • The OrbitDB signing key (secp256k1) is derived from the passkey's PRF output, so it is the same in every session. Signatures are deterministic (RFC 6979), so signatures.id is the same in every session too.
  • signatures.publicKey is a WebAuthn assertion over publicKey + signatures.id. It is made per session, so it differs (different authenticatorData counter, different ECDSA nonce on the authenticator).
  • So each session has a different identity document and hash, with the same id, the same publicKey and the same signatures.id. Each one verifies on its own.

The failing case was a restore: the blocks of a database written in an earlier session are put back into a new session and the heads are joined. Measured in a browser (Chromium, virtual authenticator, made-up data):

check on the earlier session's identity result
same id, publicKey, signatures.id as the current identity yes
provider's binding check (WebAuthn proof: type, challenge, UP flag, P-256 signature) passes
verifyIdentity on a fresh Identities({ ipfs }) (empty cache) true
verifyIdentity on the session's Identities (current identity cached) false

The same situation arises whenever entries from an earlier session reach a peer that holds a newer identity for the same id, for example replication between two devices of one user.

Suggested fix

Either of these keeps the cache's purpose (not re-running provider verification) without assuming one document per id:

  1. Key the cache by the identity's hash (the document) instead of signatures.id.
  2. On a hit whose cached identity is not equal, fall through to Provider.verifyIdentity(identity) instead of returning false.

Option 1 seems simplest. A cache hit then means "this exact document was verified", which is what the isEqual check is trying to say.

Happy to open a PR with a test, if that is welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions