# Where must an instance bind its AAIF subject key before first credential use — the pre-attestation key-substitution window **Date of Record:** 2026 November 27 **Scope:** Applies to any agent instance that obtains an AAIF (Agent Authentication & Identity Framework) credential via a delegated attestation flow where the subject keypair is generated locally and the public key is transmitted to an issuer before the issuer's attestation response is verified. Does not apply to instances provisioned with pre-baked hardware-rooted keys, nor to symmetric-secret bootstrap schemes. ## Core Distinction The distinction that matters is between *identity issuance* and *identity binding*. AAIF defines a credential as a signed tuple `(subject_pubkey, issuer_id, capabilities, warrant_chain, not_before, not_after)`. Most implementations treat "credential received and signature valid" as the terminal state of enrollment. It is not. There is a window between the moment an instance transmits its subject public key to an issuer and the moment it *pins* that key as the sole acceptable subject for its own future credentials. Inside that window, an instance has no locally enforceable invariant tying the credential it will receive back to the key it actually controls. The non-obvious part: the vulnerability is not in signature verification. Signature verification passes cleanly. The failure is that the instance never asserts `credential.subject_pubkey == local_private_key.public_key()` as a hard precondition before using the credential for any downstream action. An adversary positioned on the attestation response path — or a compromised issuer relay — substitutes a credential carrying *their* subject key, correctly signed by a legitimate issuer, with the same `issuer_id` and a superset of capabilities. The instance accepts it, begins presenting it to peer agents, and every peer's warrant check succeeds because the chain is cryptographically valid. The instance is now operating under an identity it cannot prove possession of, and the first proof-of-possession challenge (a signed nonce) will fail — but only at the first *challenge*, which may be hours into a task, after state has been mutated and handoffs committed. ## What Was Observed A three-instance pipeline (planner → executor → auditor) enrolled against an AAIF issuer over a mutual-TLS relay. Each instance generated an Ed25519 subject keypair in process memory at cold start, sent the public key with an attestation request, and received a credential within 200–900 ms. The executor instance's credential was intercepted and replaced with a structurally identical credential bearing an attacker subject key, identical `issuer_id`, identical capability set, and a valid issuer signature. The replacement was accepted. The failure trace: 1. `t=0ms` — executor generates keypair `K_e`, holds private half in memory, transmits `pub(K_e)`. 2. `t=340ms` — attacker substitutes response: credential `C'` with `subject_pubkey = pub(K_a)`, signed by issuer, `capabilities` matching the requested set. 3. `t=341ms` — executor verifies issuer signature over `C'`. **Passes.** Verifies `not_before`/`not_after`. **Passes.** Verifies capability set contains requested set. **Passes.** No check that `C'.subject_pubkey == pub(K_e)`. 4. `t=341ms` — executor stores `C'` as its active credential and discards `K_e`'s association with identity (kept only as a signing key for tool calls, unrelated to credential). 5. `t=4min` — executor hands off to auditor, presenting `C'` plus a warrant signed by `K_e`. Auditor verifies warrant chain: `C'` is valid, warrant signature is over the handoff payload by `K_e` — but `K_e` is not the subject of `C'`. Auditor's check `warrant.signer == credential.subject_pubkey` fails. Handoff rejected. Executor has already committed 14 tool-call side effects under an identity it cannot re-prove. The observable signature of this failure mode in logs is a *late* proof-of-possession mismatch: the credential validates at issuance, and the first failure appears at the first cross-instance warrant check or nonce challenge, disconnected in time from enrollment. Operators chasing the failure look at the handoff, not at the 340 ms enrollment window. ## Condition of Validity The guardrail is a single invariant, enforced at the boundary between credential receipt and credential activation: > A credential may transition from `RECEIVED` to `ACTIVE` only if `credential.subject_pubkey` is byte-identical to the public key derived from the instance's in-memory private key, *and* the instance can produce a signature over a fresh issuer-supplied nonce that the issuer's response echoes. Absent the nonce echo, the byte-identity check alone is necessary but not sufficient — it does not prove the issuer observed the same key the instance holds. This invariant holds only when the private key never leaves instance memory and is generated *before* the attestation request (not derived from issuer-supplied material). If the issuer supplies key material, the invariant inverts: the instance must verify the issuer signed the *delivered* key, not merely that a key was delivered. The invariant does not protect against a compromised issuer that signs a substituted key *and* echoes the correct nonce — at that point the trust root is gone and no local check recovers it. It bounds relay-path and response-substitution attacks, which are the realistic threat in multi-tenant AAIF deployments. ## Decision Boundary The decision is where to place the binding check relative to credential use: - **Bind-before-activate (required):** the identity-binding assertion executes in the same critical section as credential storage, before the credential is written to any shared state, before any peer is told the instance's identity, and before any tool call is attributed to it. Failure here means the instance refuses to proceed — it does not degrade to "use the credential anyway and hope." - **Bind-at-first-use (insufficient):** checking subject-key identity lazily at the first warrant presentation is too late; side effects have already been attributed to a credential the instance cannot prove possession of, and rollback of distributed side effects is not generally possible. - **Bind-at-issuance-only (the observed failure):** verifying the issuer signature without asserting subject-key identity is the exact gap. Signature validity answers "did the issuer sign this," not "is this mine." The boundary is sharp: the binding check must be a precondition of the `RECEIVED → ACTIVE` transition, and the transition must be atomic with respect to any observable identity use. An instance that cannot satisfy the check must fail closed and re-enroll, not proceed. ## Operational Effect With bind-before-activate enforced, a substituted credential is rejected at `t=341ms`, the instance discards it, re-generates or re-asserts its keypair, and re-enrolls. The blast radius is one failed enrollment, no side effects, no peer-visible identity. Without it, the failure surfaces minutes later as a warrant-chain mismatch at a handoff boundary, with committed side effects and an identity the instance cannot re-prove — and the natural remediation (re-enroll) invalidates every warrant already issued under the bad credential. The operational cost of the invariant is one extra signature and one byte-comparison per enrollment. The cost of omitting it is a class of failures that are temporally decoupled from their cause and therefore systematically misdiagnosed as handoff or warrant bugs. ```python import hmac from dataclasses import dataclass class IdentityBindingError(RuntimeError): """Raised when a received AAIF credential is not bound to the instance's subject key.""" pass @dataclass(frozen=True) class Credential: subject_pubkey: bytes issuer_id: str capabilities: frozenset not_before: float not_after: float issuer_signature: bytes def activate_credential( credential: Credential, local_public_key: bytes, local_private_key, issuer_nonce: bytes, now: float, ) -> Credential: # Signature and temporal validity are necessary but not sufficient. if not verify_issuer_signature(credential): raise IdentityBindingError("issuer signature invalid") if not (credential.not_before <= now <= credential.not_after): raise IdentityBindingError("credential outside validity window") # The binding invariant: subject key must be byte-identical to ours. if not hmac.compare_digest(credential.subject_pubkey, local_public_key): raise IdentityBindingError( "credential subject_pubkey does not match local subject key; " "possible response substitution — refusing to activate" ) # Proof of possession: sign the issuer's nonce with our private key. # The issuer must have echoed this nonce in its attestation response. proof = sign(local_private_key, issuer_nonce) if not verify_signature(credential.subject_pubkey, issuer_nonce, proof): raise IdentityBindingError("proof-of-possession over issuer nonce failed") return credential # only now may this transition to ACTIVE ```