# RFC-0032: Naming the Recipient a Rewrap Replaces - **Status:** Proposed; amends section 8.4 of the envelope specification. - **Owner:** API and security leads. - **Last updated:** 2026-11-30 ## Context `rewrap` replaces exactly one recipient. Section 8.4 chose it implicitly: the recipient of the destination's logical key, if the envelope has one, and otherwise the recipient that unwrapped. The second rule suits migrating the primary key, which is what unwraps first. It does not suit any other recipient. Writing the incident runbooks showed the failure: rotating a compromised escrow key to a successor under a new name, the natural thing to do under pressure, replaces the *primary* recipient and keeps the compromised escrow recipient. The result opens with the compromised key and no longer with the key service. ## Binding decision `Protector.rewrap` and `Protector.rewrap_stream` take `replace: KeyRef | None = None`, and `cryptosuite rewrap` takes `--replace-key NAME`. When given, it names the recipient to replace, by provider and key identifier, and by version when the reference has one. | Envelope holds | Result | | --- | --- | | The named recipient, and no other version of the destination's key | The named recipient is replaced by the destination. | | The named recipient and the destination's exact version | The named recipient is removed; nothing is wrapped. | | The destination's exact version, not the named recipient | Unchanged, so a rewrap job can be rerun. | | The named recipient and another version of the destination's key | `POLICY_DENIED`: one envelope never holds two versions of one key. | | Neither | `KEY_NOT_FOUND`. | The refusals are decided from the recipient section alone, before any key is used, so a request that cannot apply makes no unwrap call. Without `replace`, behavior is unchanged. The named recipient need not be a trusted key, or a key of a configured provider: removing a recipient never uses its key. Unwrapping still uses only trusted keys (RFC-0031), and the recipient-manifest MAC is recomputed from the data key as before. ## Alternatives considered - **Change the default** to refuse a rewrap to a new name unless the unwrapping recipient is the primary key. It breaks migrations that are correct today and still leaves the caller guessing which recipient moves. - **Separate `add` and `remove` operations.** More general, but adding a recipient changes the recipient count, which the policy bounds, and neither operation is needed by the incidents that prompted this one. ## Test and validation requirements `tests/integration/test_rewrap_replace.py` covers each row of the table, the version match, the policy check on removal, `rewrap_stream`, and argument types; the case that motivated this RFC opens with the successor escrow key alone. `tests/cli/test_cli.py` covers `--replace-key`. The public-surface snapshot records the new parameter and option.