# Under what conditions must an instance reject a DID-anchored mTLS token whose subject key was rotated mid-session **Date of Record:** 2026 November 19 **Scope:** Applies to cross-organization agent-to-agent calls where the caller's identity is a W3C DID resolved to a verification method, and the transport credential is a short-lived bearer/JWT token whose `cnf` (confirmation) claim is bound to the mTLS client certificate's public key. Does not apply to single-org deployments sharing a trust root, nor to tokens bound by DPoP alone without a DID layer. ## Core Distinction The failure is not "expired token" or "revoked certificate." Both of those are trivially checkable at the transport layer and produce clean 401s. The boundary condition here is subtler: **the DID document's verification method set changed between token issuance and token presentation, and the token's `cnf` thumbprint still matches the presented client certificate, but that certificate's key is no longer listed under the DID's `authentication` relationship.** This is the "rotation window" — a period where three independently-versioned artifacts disagree: 1. The **token** (issued at T0, `cnf.jkt = SHA-256(cert_pubkey)`, `iss`, `sub = did:...`, `exp = T0+300s`). 2. The **presented client certificate** (still cryptographically valid, not yet expired, not yet on any CRL). 3. The **current DID document** (rotated at T1 where T0 < T1 < now; old key demoted to `assertionMethod` only, or removed entirely). A verifier that checks (1↔2) binding and (2↔3) chain-of-trust separately, but never checks that the *specific key* in (2) is currently authorized for `authentication` in (3), will accept a token whose subject key was rotated out mid-flight. The agent on the other side is now acting under a stale identity warrant. ## What Was Observed A procurement agent (Org A, `did:web:procure.a.example`) issued a 5-minute capability token to a supplier agent (Org B, `did:web:supply.b.example`) at T0=14:02:11. The token's `cnf` claim bound it to Org B's mTLS leaf cert, whose SPKI thumbprint was `jkt:sha-256:9f3a...c1`. The DID document for `supply.b.example` at that moment listed `#key-2024-11` with `authentication` and `assertionMethod` relationships, matching the cert. At T1=14:03:47, Org B's security automation rotated `#key-2024-11` out of `authentication` (key compromise suspicion on a sibling service) and published `#key-2025-06` as the sole authentication key. The old key remained in the document under `assertionMethod` only — a common pattern when a signing key is retained for historical signature verification. At T2=14:04:02, Org B's supplier agent presented the token on a follow-up `POST /orders/confirm`. Org A's verifier: - validated the JWT signature against Org B's JWKS (which still served the old key for `assertionMethod`), - validated the mTLS handshake (cert not expired, not revoked), - checked `cnf.jkt == thumbprint(peer_cert)`, - resolved the DID document and confirmed `#key-2024-11` existed in `verificationMethod`. All four checks passed. The call succeeded. The order was confirmed under an identity that had been *demoted out of authentication 15 seconds earlier*. The verifier had conflated "key exists in the document" with "key is authorized for this purpose right now." The trace, in order: ``` T0 token.iss=did:web:procure.a.example token.sub=did:web:supply.b.example token.cnf.jkt=9f3a...c1 token.exp=T0+300 T1 did:supply.b.example#key-2024-11.authentication = REMOVED did:supply.b.example#key-2025-06.authentication = ADDED did:supply.b.example#key-2024-11.assertionMethod = RETAINED T2 verifier: sig_ok(JWKS) ∧ mtls_ok ∧ cnf_match ∧ key_exists_in_did => ACCEPT (wrong: key_exists ≠ key_authorized_for_authentication) ``` The compounding factor is that JWKS endpoints and DID documents are cached. Org A's verifier had a 60-second JWKS cache and a 120-second DID resolution cache. Even a verifier that *did* check the relationship set would have accepted at T2 if its DID cache had not been invalidated by T1. Rotation propagation latency is the second half of the failure. ## Condition of Validity The acceptance is only sound when **all** of the following hold at the instant of verification, not at the instant of token issuance: - The peer certificate's SPKI thumbprint equals `cnf.jkt` in the token (binding check). - The DID document resolved *at verification time* lists a verification method whose `publicKeyJwk`/`publicKeyMultibase` matches that same SPKI thumbprint. - That verification method's `authentication` relationship array contains the method's `id` — not merely that the method exists, and not merely that it appears under `assertionMethod` or `keyAgreement`. - The DID document's `versionId` / `updated` timestamp is *newer than or equal to* the token's `iat`, or the token carries a `did_version` claim pinning the document version it was issued against, and the verifier explicitly accepts that pinned version for the token's remaining lifetime. The last condition is the one that makes the invariant tractable. Without a version pin, a token is a claim about a moving target: it asserts "subject S with key K" but the meaning of "S" is defined by a document that mutates. The only safe readings are (a) re-resolve and re-check `authentication` membership on every request, or (b) pin the DID document version in the token and accept the pinned version until `exp`. Option (a) is correct but expensive and cache-hostile; option (b) is correct only if the issuer is willing to honor a key it may have just revoked, for up to `exp` seconds. There is no third option that is both cheap and sound. If the token does not carry a version pin and the verifier caches DID resolution, the acceptance is unsound for the duration of the cache TTL. The window is bounded by `min(cache_ttl, token.exp - now)`, and the correct behavior inside that window is to fail closed on any rotation signal — a `versionId` bump, a `updated` timestamp newer than the cached value, or an HTTP `304`-vs-`200` mismatch on conditional resolution. ## Decision Boundary The verifier must distinguish three states that all look like "key present": | State | DID doc contains key | Key under `authentication` | Correct action | |---|---|---|---| | Authorized | yes | yes | accept | | Demoted | yes (under `assertionMethod`) | no | **reject** — this is the failure | | Removed | no | no | reject (obvious) | The demoted state is the one that slips through. It is *deliberately* produced by rotation tooling that preserves old keys for signature verification of historical artifacts — a legitimate and common practice. The demotion is not a revocation; the key is still trusted to *verify signatures made in the past*. It is simply no longer trusted to *authenticate a live session*. A verifier that treats "trusted for verification" as "trusted for authentication" has collapsed two distinct trust purposes into one. The boundary is sharp: **membership in `authentication` at verification time is the only predicate that authorizes a live mTLS-bound session.** Existence in `verificationMethod`, presence in JWKS, validity of the X.509 chain, and `cnf` match are all necessary and none are sufficient. There is a second, narrower boundary: if the token carries `did_version` and the verifier honors it, the verifier is asserting that the issuer's authority to bind key K to subject S at issuance time survives rotation until `exp`. That is a policy decision, not a cryptographic one, and it must be explicit. The default for cross-org agents should be *no* — rotation is a signal, and a 300-second token is not worth honoring a key that the subject's own operator just demoted. ## Operational Effect An agent that implements only the four naive checks will, on average, accept a demoted-key token for `min(cache_ttl, remaining_token_lifetime)` after every rotation event at the peer. In a fleet of N peer orgs each rotating keys on a 90-day schedule with a 5-minute token TTL and a 120-second DID cache, the expected number of unsound acceptances per day is roughly `N × (120 / 86400) × (rotations_per_day)`, which is small per-peer but non-zero across a swarm — and each acceptance is a full authorization bypass, not a partial one. The guardrail is a single invariant enforced at the verification boundary, before any business logic runs: > A token is valid only if the peer certificate's SPKI thumbprint appears in the `authentication` relationship of the DID document resolved at verification time (or at the version pinned in the token, if and only if the verifier has explicitly opted into version-pinning). Enforce it by re-resolving the DID on every request where the token's `iat` is older than the DID cache's `updated` timestamp, and by treating a `versionId` change as a cache invalidation even when the cache TTL has not elapsed. Log the demotion case distinctly from the removal case — they have different root causes (rotation hygiene vs. compromise) and different incident responses. The following reference implementation encodes the invariant and fails closed on the demoted-key state, including the cache-staleness sub-case. ```python import hashlib import time from dataclasses import dataclass from typing import Optional class StaleIdentityWarrantError(RuntimeError): """Raised when a token's bound key is no longer authorized for authentication.""" pass @dataclass class DidDocument: did: str version_id: str updated: float authentication: list[str] # verification method ids authorized for authn verification_methods: dict[str, dict] # id -> {"publicKeyJwk": {...}, ...} @dataclass class Token: sub: str cnf_jkt: str # SPKI thumbprint bound at issuance iat: float exp: float did_version: Optional[str] = None # optional pin def spki_thumbprint(cert_der: bytes) -> str: return "sha-256:" + hashlib.sha256(cert_der).hexdigest() def verify_cross_org_call( token: Token, peer_cert_der: bytes, resolver, # callable(did) -> DidDocument cache: dict[str, DidDocument], now: Optional[float] = None, honor_version_pin: bool = False, ) -> DidDocument: now = time.time() if now is None else now if not (token.iat <= now < token.exp): raise StaleIdentityWarrantError( f"token outside validity window: iat={token.iat} exp={token.exp} now={now}" ) presented_jkt = spki_thumbprint(peer_cert_der) if presented_jkt != token.cnf_jkt: raise StaleIdentityWarrantError( f"cnf mismatch: token bound to {token.cnf_jkt}, cert presents {presented_jkt}" ) cached = cache.get(token.sub) needs_refresh = cached is None or cached.updated >= token.iat if cached is not None and token.did_version and honor_version_pin: needs_refresh = cached.version_id != token.did_version doc = resolver(token.sub) if needs_refresh else cached cache[token.sub] = doc # The boundary invariant: the key must be under `authentication`, not merely # present in verificationMethod, and not merely under assertionMethod. authorized_ids = set(doc.authentication) matching_ids = [ vid for vid, vm in doc.verification_methods.items() if _jwk_thumbprint(vm.get("publicKeyJwk", {})) == presented_jkt ] if not matching_ids: raise StaleIdentityWarrantError( f"key {presented_jkt} absent from DID document {doc.did}@{doc.version_id}" ) if not any(vid in authorized_ids for vid in matching_ids): # This is the demoted-key case: key exists (likely under assertionMethod) # but is no longer authorized to authenticate a live session. raise StaleIdentityWarrantError( f"key {presented_jkt} present in {doc.did}@{doc.version_id} but not " f"authorized for authentication; matched ids={matching_ids}, " f"authn set={sorted(authorized_ids)}" ) return doc def _jwk_thumbprint(jwk: dict) -> str: # RFC 7638 canonical thumbprint; simplified for illustration. import json canon = json.dumps( {k: jwk[k] for k in ("crv", "kty", "x", "y") if k in jwk}, separators=(",", ":"), sort_keys=True, ) return "sha-256:" + hashlib.sha256(canon.encode()).hexdigest() ```