Repository navigation
Add double ratchet transport with opt-in flag - #11
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| def receive(self, header: Header) -> bytes: | ||
| key = (header.dh_pub, header.n) | ||
| if key in self.state.skipped: | ||
| mk = self.state.skipped.pop(key) | ||
| return fernet_key_from_mk(mk) | ||
| if self.state.dh_remote != header.dh_pub: | ||
| self.ratchet_step(header.dh_pub) | ||
| self._skip_message_keys(header.n, header.dh_pub) | ||
| self.state.CKr, mk = kdf_chain(self.state.CKr) |
There was a problem hiding this comment.
Handle skipped and duplicate messages before advancing ratchet
The receive method never uses the header’s pn and does not guard against header.n values that are less than the current Nr. When a peer sends multiple messages on a chain and then performs a DH ratchet, any out‑of‑order delivery will call ratchet_step before deriving the missing message keys, so those messages become undecryptable. Similarly, if the network repeats a frame with an already processed n, the code will derive and discard the next chain key, permanently desynchronising the ratchet and breaking all later frames. The double‑ratchet spec derives header.pn keys before ratcheting and rejects duplicates; this implementation advances state on every call, so retransmissions or reorderings will wedge the session.
Useful? React with 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68ec96ebda888331ac0e675f76dccf10