Skip to content

Add double ratchet transport with opt-in flag - #11

Merged
LashSesh merged 1 commit into
mainfrom
codex/implement-opt-in-addons-with-audit-logging
Oct 13, 2025
Merged

LashSesh merged 1 commit into
mainfrom
codex/implement-opt-in-addons-with-audit-logging

Conversation

@LashSesh

Copy link
Copy Markdown
Owner

Summary

  • implement a reusable double ratchet core with Fernet message key derivation helpers
  • integrate ratchet sessions into the spectral engine gated by a new ENABLE_RATCHET flag
  • cover ratchet flows with round-trip and frame encryption tests

Testing

  • pytest -q

https://chatgpt.com/codex/tasks/task_e_68ec96ebda888331ac0e675f76dccf10

@LashSesh
LashSesh merged commit 76bebfa into main Oct 13, 2025
1 check failed
@LashSesh
LashSesh deleted the codex/implement-opt-in-addons-with-audit-logging branch October 13, 2025 06:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Comment thread core/ratchet.py
Comment on lines +140 to +148
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant