# Revoke a signing key

> Destroy a signing key version so nothing it signed verifies again, in the right order when a key is exposed.

You believe a signing key has leaked, or you're retiring old keys after a rotation. Revoking a version destroys it in
the key store: it leaves the published key set, and every token it signed stops verifying. Users holding such tokens
sign in again, or their apps refresh.

**Before you start:** you need the `MODIFY` right on the realm's `keySettings`. The key that is signing now can't be
revoked, so if it's the one you distrust, you'll rotate first. It's done through the API, with your session in
`$CVYUH_SESSION`: [Call the API](/develop/api/) shows how to get it.

## Revoke

<Steps>

1. Find the version. Call `GET https://foobar.cvyuh.com/api/v0/am/keys/v1`. Each signing key version is an entry whose `key` is
   `oauth2/signing`, with its `version`, `alg`, `state` and `validFrom`. The one signing now for an algorithm is the
   `valid` entry with the latest `validFrom` already past.

2. If it's the key signing now, [rotate](/platform/guides/rotate-signing-keys/) that algorithm to a new key, with `validFrom` as
   soon as the publish lead allows, and wait until the new key has been signing for a minute (`rotation.skewSecs`).

3. Revoke the version:

   ```sh
   curl -X DELETE https://foobar.cvyuh.com/api/v0/am/keys/v1/signing/<version> \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

   The realm answers `204`.

</Steps>

## Check it worked

Call `GET https://foobar.cvyuh.com/api/v0/am/keys/v1` again: a revoked version is destroyed, so it is no longer listed. Its `kid` is gone from
`https://foobar.cvyuh.com/oauth2/jwks`.

<Aside type="note" title="When verifiers stop accepting it">
  The realm and its introspection refuse the key's tokens at once. Your gateways and APIs refuse them once their
  cached key set drops it: within `publication.maxAgeSecs`, five minutes by default.
</Aside>

## If it fails

- **`400`.** The version is signing now, or started within `rotation.skewSecs` (60 seconds by default). Rotate, wait
  until the new key has signed for longer than that, and revoke again.
- **`404`.** No such version, or it's already revoked. List the keys and check the number.
- **`403`.** Your rights don't include `MODIFY` on `keySettings`.

Each revocation is recorded on the realm's audit trail as a `DELETED` record for the key version, under your name: see
[Signing keys](/platform/keys/signing-keys/#audit-record).

## Undo it

A revocation can't be undone: the key is destroyed. Tokens it signed can't be made to verify again; their users sign
in again.

## Related

- [Rotate signing keys](/platform/guides/rotate-signing-keys/): put a new key in place first.
- [Signing keys](/platform/keys/signing-keys/): what the realm refuses, and why.
