Section 20.17

Tree 17: “How do rotation, activation, and revocation work together?”

Setting

A sensor gateway is a small device that collects readings from sensors and passes them on. In this invented example, the gateway also runs a small decision program, and a publisher, the one party authorized to change the gateway’s policy, sends it new programs and management requests. Everything travels through a phone that relays the bytes over a Bluetooth radio link. Each request carries a tag computed with HMAC §5.8 (hash-based message authentication code), a message authentication code §5.7 (MAC): a function that computes a short value, the tag, from a secret key and a message, so that someone without the key should have only a negligible chance of creating a valid tag for a new request.

The gateway holds three secret keys. KaK_a is the active key, the key whose tags the gateway accepts today; it belongs to generation number g=7g = 7, where the generation number counts key replacements. KpK_p is the pending key, the replacement the publisher wants to make active as generation 8. KrK_r is the recovery key §5.31: a separate key, whose copy at the publisher is kept offline, that authorizes only recovery actions, such as installing a new active key after KaK_a is lost. The gateway also keeps a floor, the lowest generation it will accept, in a monotonic counter §8.28, a stored number that can only increase.

The publisher replaces KaK_a by KpK_p in three steps, which this tree keeps apart. Staging: the publisher sends KpK_p, encrypted so that the phone cannot read it, as candidate number 101 for generation 8, and the gateway checks it and stores it without using it. Activation: the publisher confirms candidate 101, and in one write that survives loss of power the gateway makes KpK_p the active key. Revocation: the gateway stops accepting KaK_a for new requests. Every request carries a request identifier, a number the publisher chooses so that a second copy of the same request can be recognized. The phone may deliver a request twice, or late. The protocol is invented for teaching; no standard defines these commands.

Short answer

The gateway changes keys in separate, checked steps. It stages the new key KpK_p, checking and durably storing it while the old key KaK_a still works. It activates KpK_p in one durable write, after the publisher proves that it holds the same KpK_p. It then revokes KaK_a: a stored rule, kept across restarts and protected against rollback, says that KaK_a authorizes no new requests. Each authenticated request names the device, generation, candidate and operation. A durable record of the request and its result prevents a duplicate effect. A cancellation §9.29 for candidate 101 leaves candidate 102 in place.

Follow-up questions

Why stage before activation?

Staging comes first so that every step that can fail runs while the old key still works. To stage a key is to deliver, check and store it without using it. To activate it is to make it the key whose tags the gateway accepts. Here a sensor gateway accepts its publisher’s requests only with a tag of a message authentication code (MAC) computed with the active key KaK_a, and the publisher is replacing KaK_a by a new key KpK_p.

If the gateway switched to KpK_p the moment KpK_p arrived, any failure after the switch could split the two sides. A damaged transfer gives the gateway a different KpK_p from the publisher’s; a lost reply leaves the publisher unsure which key is in force. Either way, the publisher’s next request may carry a tag the gateway rejects, and no accepted request remains with which to repair the split. Staging lets the gateway do four things first:

  1. Validate. Decrypt KpK_p, check its integrity §1.9 and length, and check that it is meant for this gateway and for generation 8, one more than the active generation 7.

  2. Store durably. Write the candidate to flash memory §6.6, which keeps its content without power, and confirm that the write completed.

  3. Prove possession. The gateway sends a challenge: a nonce §5.18, a random value used only once, such as 16 fresh random bytes. The publisher returns a tag computed with KpK_p over the purpose of proving possession, the challenge, the gateway’s identifier (ID), generation 8 and candidate number 101. A correct tag shows that the publisher holds the same KpK_p that the gateway stored. This step is a proof of possession §5.30. It does not show that anything has been committed.

  4. Prepare. Reserve the memory and build the internal state that using KpK_p needs, so that no step after the commit can fail for lack of resources.

Activation is then a single durable write, the commit, after which every restart uses KpK_p. The reply can still be lost after the commit. The gateway can report the durable result again without repeating the change.

Who may authorize each operation?

Each operation needs a written rule that names the key allowed to authorize it, the states in which it is allowed, and the fields its tag must cover. A tag of a message authentication code (MAC) shows only that its maker held a particular key. Authentication §1.6 answers “which key made this tag?”; authorization §1.7 answers “may the holder of that key make this change now?”. Here a sensor gateway changes keys: KaK_a is its active key, of generation 7; KpK_p is the candidate key for generation 8, staged as candidate number 101; and KrK_r is the recovery key. One workable rule is:

The tag must cover every field the rule checks. The set of bytes a tag covers is its authentication coverage §5.41. A correct tag under KpK_p that names candidate 102, or another gateway, fails the rule for candidate 101. If the candidate number lay outside the tag, anyone relaying the message could change it without detection.

Does rotation equal revocation?

No: rotation gives the gateway a new key, revocation takes authority away from the old key, and only revocation shuts out someone who stole the old key. Key rotation §5.29 replaces the active key KaK_a of a sensor gateway, the key whose tags authorize its owner’s requests, by a new key KpK_p for future use. KaK_a still exists afterwards: in the publisher’s records, in backups, and in an attacker’s hands if it leaked. If the gateway keeps accepting KaK_a, for example to stay compatible with old tools, every holder of KaK_a keeps full authority.

Key revocation §5.32 is an enforced rule that a key no longer authorizes a named set of uses. It has three requirements:

  1. Enforced by every verifier. Every device that accepted KaK_a must reject it, including a device that was switched off when the revocation was sent.

  2. Persistent. The rule is stored in memory that keeps its content without power, so that a restart does not forget it.

  3. Proof against rollback. Replaying the old request that installed KaK_a, or restoring an old copy of the storage, must not bring KaK_a back. A floor held in a monotonic counter, a stored number that can only increase, enforces this: with the floor at 8, a key of generation 7 is rejected, because 7<87 < 8.

Revocation can be partial, and then both halves must be named. The gateway may refuse KaK_a for new requests and still keep KaK_a to verify old log entries tagged with it. With a message authentication code (MAC), the key that verifies a tag also creates tags, so whoever keeps KaK_a for verification can also forge entries that look old. A digital signature §5.14 separates the two powers: its public key verifies signatures but cannot make them.

How does a retry work?

A retry works when the gateway recognizes a repeated request and returns the result it recorded the first time, without acting again. Example: a sensor gateway receives request 41 from its publisher, “activate candidate 101 as generation 8”, which means: make the staged key KpK_p the active key. The gateway commits the change, but its reply is lost. After 5 seconds without a reply, the publisher sends request 41 again, with identical bytes. If the gateway executed it a second time, it would find no pending candidate and report failure. The publisher would conclude that the key change failed and keep using the old key KaK_a, which the gateway now rejects.

The repair is to make the request idempotent §8.31: applying it twice has the same effect as applying it once. In the same durable write that activates generation 8, the gateway records the request identifier 41, a hash of the request’s bytes and the result “generation 8 active”. The hash is a short fingerprint of the bytes, computed by a cryptographic hash function §5.1. When request 41 arrives again with the same hash, the gateway returns the recorded result and changes nothing. The gateway looks the identifier up before it checks that the request answers its current challenge, because the second copy repeats the first copy’s challenge, which the gateway no longer expects. Four rules keep this safe:

Delivery that repeats until a reply arrives, combined with recognition of repeats, gives an exactly-once effect §8.32: the change happens once, however many copies arrive. Returning a recorded result changes nothing, so an attacker who replays request 41 gains only the reply. The table of recorded results has a fixed size. For an identifier that has dropped out of the table, the gateway compares the request with its state: if generation 8 or a later one is active, it answers “already done or superseded” and does not act.

What must a cancellation do?

A cancellation must name exactly what it cancels, take effect only while that thing can still be canceled, and durably record what it did. Here a sensor gateway is replacing its active key KaK_a, generation 7, and a candidate is a staged replacement key, stored but not yet used, identified by a candidate number.

A late message shows why the name matters. The publisher stages candidate 101 for generation 8 and then cancels it. The phone, unsure whether the cancellation arrived, also sends a second copy, which is delayed. The gateway cancels 101, and the publisher then stages a new candidate 102 for generation 8. Now the delayed copy arrives. If it says only “cancel the pending candidate”, it erases candidate 102, and the publisher wrongly believes that 102 is waiting. If it says “cancel candidate 101 for generation 8 on gateway 5”, the gateway sees that 101 is no longer pending, changes nothing, and repeats its recorded answer, “candidate 101 canceled”.

A correct cancellation does four things:

Related entries: Key rotation (§5.29), Proof of possession (§5.30), Key revocation (§5.32), Key confirmation versus application confirmation (§5.42), Exactly-once effect (§8.32), Staging versus commit versus activation (§8.22), Idempotency (§8.31), Prepare before irreversible commit and allocation-free fallback (§19.3.8), Tree 20: “When can a key be retired or destroyed?” (§20.20). Further reading: [147].