test: the skipped keys, half closed and half pinned (marmot-kmp, Phases 5 and 6)
Phase 6 is a probe with no code of its own, so it rides along: both fork tests pass unchanged, which means marmot-kmp 2.2.1 still scores a fork this device is half of the way quartz 1.15.2 did. The assertion whose message is "the two sides agree -- the library has been fixed" did not fire. What changed is that the fix docs/marmot-v2.md predicts is now a first-class thing on the library's side -- MlsGroup.stageCommit, with the staged commit in MlsGroupState from its STATE_VERSION 9 -- so it is a choice in MlsCandidateStateEngine between replaying a branch and taking the state that was kept. Both notes say so. Phase 5 is the skipped keys, and it is half closed. mls-kmp's state carries them: skippedApplicationSecrets and skippedHandshakeSecrets, exported by saveState and imported by restore, arriving at STATE_VERSION 5 so a version-4 blob reads them as an empty map. That is steps 1 to 3 of the fix docs/mls-skipped-keys.md proposed. Step 4 is not done: consumedGenerations, the replay guard, is still one SecretTree's field. The app does not benefit yet, and the first draft of this test claimed it did. MlsGroupManager.decrypt persists only when the message was a commit that advanced the epoch, so the secret reaches the live group and never the row. The draft delivered generation 1, rebuilt the engine, delivered generation 0 and asserted it decrypted -- and it did, for the wrong reason: a rebuilt engine restores a blob whose sender ratchet never moved, so generation 0 is simply the next one it expects. A green test proving nothing, caught by the assertion beside it that looked redundant. So the three tests say what is true: the secret is in the state the engine would save, a group rebuilt from those bytes reads the late message, and the stored state does not carry it. The last one is pinned in the style of the authored fork, with its KDoc saying what to invert when the receive path starts persisting -- deliberately not done here, because it is a write per inbound message that re-encodes the ratchet tree, the group context and every epoch secret. saveSenderRatchet is the library's answer to that cost on the send side. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b2539773ce
commit
3b2b5e3614
5 files changed
+318
-3
No files matched your search
@@ -451,6 +451,47 @@ leave its mitigation section as the history of how it was lived with.
|
||||
**Check:** the new test, and `MarmotEngine`'s own doc comment, whose last paragraph
|
||||
currently names this gap as open.
|
||||
|
||||
**Built, and half of it is closed — not the half the plan assumed.** The engine-level gap
|
||||
is gone: `MlsGroupState` carries `skippedApplicationSecrets` and
|
||||
`skippedHandshakeSecrets` from STATE_VERSION 5, `saveState` exports them from the secret
|
||||
tree and `restore` imports them, and because they arrived at version 5 while the decoder
|
||||
accepts 1..10, a version-4 blob reads them as an empty map. That is steps 1 to 3 of the
|
||||
fix [mls-skipped-keys.md](./mls-skipped-keys.md) proposed, in the library the app now
|
||||
depends on. Step 4 is not: `consumedGenerations`, the guard against a replayed message
|
||||
re-using a cached key, is still one `SecretTree` instance's field and is in no version of
|
||||
the state.
|
||||
|
||||
**The app does not benefit yet, and the first draft of this test said it did.**
|
||||
`MlsGroupManager.decrypt` persists only when the message was a commit that advanced the
|
||||
epoch; an application message is decrypted and nothing is written. So the secret reaches
|
||||
the live group's state and never reaches `ChatRoom.mlsGroupState`.
|
||||
|
||||
That matters for how the test had to be written, and the first attempt is worth recording
|
||||
because it passed. It delivered generation 1, rebuilt the engine with `MarmotEngine(db)`,
|
||||
delivered generation 0 and asserted it decrypted — and it did, for the wrong reason
|
||||
entirely. The rebuilt engine restores a blob whose sender ratchet never moved, so
|
||||
generation 0 is simply the next generation it expects and no skipped key is involved. A
|
||||
green test proving nothing, and what caught it was the one assertion that looked redundant
|
||||
beside it: that the secret is in the stored state. It was not.
|
||||
|
||||
So `SkippedGenerationJvmTest` is three tests that say what is true:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| the secret is in the state the engine *would* save | `MlsGroupManager.snapshot` after generation 1 arrives first — exactly one skipped secret, where the old engine had none |
|
||||
| a group rebuilt from those bytes reads the late message | the full round trip through `encodeTls`/`decodeTls`/`restore`, which is what a restart is |
|
||||
| the *stored* state does not carry it | pinned, in the style of `ConvergenceForkJvmTest`'s authored fork, with the KDoc saying what to invert the day the receive path starts persisting |
|
||||
|
||||
The fix for the third is one call — the app owns the store, so
|
||||
`store.save(routingId, groupManager.snapshot(routingId)!!.encodeTls())` after an
|
||||
application message would do it — and it is deliberately not made here, because it is a
|
||||
write per inbound message that re-encodes the ratchet tree, the group context and every
|
||||
epoch secret. `MlsGroupStateStore.saveSenderRatchet` is the library's answer to exactly
|
||||
that cost on the send side; the receive side wants the same shape, and that is Phase 7's
|
||||
business rather than this one's. [mls-skipped-keys.md](./mls-skipped-keys.md) has a new
|
||||
last section saying all of this, and its mitigation section stands word for word with a
|
||||
new cause.
|
||||
|
||||
## Phase 6 — the authored fork
|
||||
|
||||
marmot-v2.md ends on a gap that is the library's and not the app's: a member cannot replay
|
||||
@@ -470,6 +511,37 @@ fix.
|
||||
**Check:** `ConvergenceForkJvmTest`, and whichever way it goes, this note and
|
||||
marmot-v2.md's closing paragraph both say so.
|
||||
|
||||
**Probed: the gap is still open, and the test still pins the swap.** Both fork tests pass
|
||||
unchanged — the one that proves two observers of somebody else's fork settle on the same
|
||||
state byte for byte, and the one whose last assertion is
|
||||
|
||||
```kotlin
|
||||
assertNotEquals(ours.contextBytes().toHexKey(), theirsAfter.contextBytes().toHexKey(),
|
||||
"the two sides agree -- the library has been fixed; rewrite this test as the agreement")
|
||||
```
|
||||
|
||||
That message is the probe, and it did not fire. So marmot-kmp 2.2.1 scores a fork this
|
||||
device is half of the same way quartz 1.15.2 did: `MlsCandidateStateEngine` rebuilds each
|
||||
candidate branch with `MlsGroup.processFramedCommit`, a member cannot replay a commit it
|
||||
authored, and two committers swap branches rather than agree. Reading says the same thing
|
||||
the test does — the suggestive line in `MlsCandidateStateEngine` about holding "an inbound
|
||||
commit and one we authored to one rule rather than two" is about *authorization*, not
|
||||
replay.
|
||||
|
||||
What did change is that the fix marmot-v2.md predicts is now visibly available. Its
|
||||
closing note says "the state the missing replay would produce is already retained, and
|
||||
using it is the fix", and mls-kmp has made exactly that state a first-class thing:
|
||||
`stageCommit`/`mergePendingCommit`, with the staged commit persisted in `MlsGroupState`
|
||||
from its STATE_VERSION 9. The app already holds the same state twice over, as
|
||||
`MarmotPublishObligation.pendingState`. So the fix is a change to the candidate engine's
|
||||
choice of how to get a branch's state — replay it, or take the one we kept — and it
|
||||
belongs in marmot-kmp rather than here.
|
||||
|
||||
Unchanged, therefore: the practical exposure is small, because a device that never applies
|
||||
before publishing rarely authors one side of a fork, and the Phase 5 follow-up in
|
||||
marmot-v2.md (marking a losing branch's rows withdrawn) still waits on the same fix. No
|
||||
code in this phase.
|
||||
|
||||
## Phase 7 — what the library now offers, and the guard
|
||||
|
||||
Four things, each its own commit, none of them required by the move:
|
||||
|
||||
@@ -65,6 +65,13 @@ the fix. Until then the practical exposure is small -- a device that never appli
|
||||
before publishing rarely authors one side of a fork -- and the follow-up in Phase 5
|
||||
(marking a losing branch's rows withdrawn) waits on the same fix.
|
||||
|
||||
*Still true of marmot-kmp 2.2.1, which is where that engine lives now
|
||||
([marmot-kmp.md](./marmot-kmp.md), Phase 6): both fork tests pass unchanged, so the swap
|
||||
is still the swap. What has changed is that the state the missing replay would produce is
|
||||
a first-class thing on the library's side too -- `MlsGroup.stageCommit` with the staged
|
||||
commit persisted in `MlsGroupState` -- so the fix is now a choice in
|
||||
`MlsCandidateStateEngine` between replaying a branch and taking the state that was kept.*
|
||||
|
||||
Written against the code as it stood at `2bbe1fc9`.
|
||||
|
||||
## Where "v2" comes from, and what it asks
|
||||
|
||||
@@ -7,6 +7,13 @@ This is a conformance gap in quartz's MLS implementation, not in this app. What
|
||||
this app can do about it from outside the library is partial, and is described
|
||||
at the end.
|
||||
|
||||
**Half of it is closed.** The engine left quartz for mls-kmp
|
||||
([marmot-kmp.md](./marmot-kmp.md)), and mls-kmp's state format carries the skipped
|
||||
keys -- steps 1 to 3 of "The fix, in quartz" below, landed in the library the app now
|
||||
depends on. What is left is not the same gap, and the last section says what it is.
|
||||
Everything between here and there is the account as it stood, and is kept because it
|
||||
is still why any of it matters.
|
||||
|
||||
## Symptom
|
||||
|
||||
The receiver stores the kind:445 group event and produces nothing from it. No
|
||||
@@ -215,3 +222,41 @@ work for any other flow in the table above that someone can be asked to repeat.
|
||||
The staleness check is what keeps the cache from being *worse* than no cache: a
|
||||
group that has been overtaken by another writer is never carried on with, so the
|
||||
fallback is always the old behaviour rather than a diverged ratchet.
|
||||
|
||||
## What the move to marmot-kmp changed
|
||||
|
||||
The engine is not quartz's any more. quartz 2.3.0 dropped it, and the RFC 9420 half
|
||||
is [mls-kmp](https://github.com/vitorpamplona/mls-kmp) now
|
||||
([marmot-kmp.md](./marmot-kmp.md)). Three of the four steps above are in it:
|
||||
|
||||
| the fix above | mls-kmp 1.3.0 |
|
||||
|---|---|
|
||||
| 1. export and import the skipped keys | `SecretTree.exportSkippedApplicationSecrets` / `importSkippedSecrets`, and the same pair for the handshake ratchet |
|
||||
| 2. put them in the group state | `MlsGroupState.skippedApplicationSecrets` and `.skippedHandshakeSecrets`, written by `saveState` and read by `restore` |
|
||||
| 3. keep old state readable | they arrived at `STATE_VERSION` 5 and the decoder accepts 1 to 10, so a version-4 blob -- which is what quartz 1.15.2 wrote, and what every device holds -- reads as an empty map, exactly as this note asked |
|
||||
| 4. the consumed-generation replay guard travels with them | **not done.** `consumedGenerations` is still a field of one `SecretTree` instance, in no version of the state, so the guard against a replayed message re-using a cached key still weakens across a restart |
|
||||
|
||||
So the test this note asked for -- "save and restore a group between the two messages
|
||||
of an out-of-order pair, and assert the older one still decrypts" -- now passes, and it
|
||||
is `SkippedGenerationJvmTest`.
|
||||
|
||||
**What is still broken, for a different reason.** `MlsGroupManager.decrypt` persists
|
||||
only when the message was a commit that advanced the epoch. An application message is
|
||||
decrypted and nothing is written, so the secret reaches the live group's state and never
|
||||
reaches `ChatRoom.mlsGroupState` -- and a process that dies between the two messages
|
||||
still loses the late one. The mitigation section above therefore still stands, word for
|
||||
word, including its three bullets; only its first sentence has a new cause. It is no
|
||||
longer "the cache is never written" but "the state is not saved after a receive", which
|
||||
is a decision about write amplification rather than an oversight: persisting per inbound
|
||||
message re-encodes the ratchet tree, the group context and every epoch secret, per
|
||||
message, growing with the group. `MlsGroupStateStore.saveSenderRatchet` is the shape of
|
||||
the answer on the send side, and the receive side wants the same treatment.
|
||||
|
||||
`SkippedGenerationJvmTest` pins all of it: the secret is in the state the engine would
|
||||
save, a group rebuilt from those bytes reads the late message, and the stored state does
|
||||
not carry it yet. Its last test says what to do the day that changes.
|
||||
|
||||
One thing this does not change: a device that loses a message this way can still be sent
|
||||
a new one, which is encrypted at a generation it has not passed. That is still the
|
||||
recovery, and [frost-session-resend.md](./frost-session-resend.md) is still where it
|
||||
is built.
|
||||
Reference in new issue
Block a user