Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A transport could hold a completed handshake with no session keys, or keys with no completed handshake, because the phase was recomputed from two independently settable fields on every read. The handshake state machine separately accepted any transition legal in either ECIES or CMS, relying on the orchestrators to never attempt the other protocol's moves.
Related Issues
None
Changes Made
Testing
make test-all: passesBreaking Changes
TcpHandshakeStateis removed. MatchSessionPhaseinstead.EncryptedProtocolStatereplaces four state setters withsession_phaseandset_session_phase.ClientStateMachineandServerStateMachinetake a flow parameter,CmsorEcies.P: CryptoProvider + Send + Sync + 'static, which the trait already demanded.Note
Medium Risk
Refactors handshake completion, session keys, and protocol transitions across TCP transport and CMS/ECIES orchestrators—security-critical paths where regressions would affect encryption gating or handshake validity.
Overview
This PR tightens transport and handshake state so invalid combinations cannot be held in memory, and CMS vs ECIES flows are separated at the type level.
Session lifecycle:
TcpHandshakeStateand separatesession_keysare replaced by a storedSessionPhase(Cleartext,Provisioned,Handshaking { initiated_at },Encrypted(SessionKeys)). Keys are installed only viacomplete_handshake, resets usereset_session, and handshake start usesbegin_handshake/HandshakeInstantfor deadlines. I/O and messaging now match onSessionPhaseinstead of handshake enums.Protocol state machines:
ClientStateMachine/ServerStateMachineare generic overCmsorEcieswith per-flow transition tables, so cross-protocol jumps (e.g. CMS skipping Finished) returnInvalidStateinstead of relying on orchestrator ordering alone.Orchestrators: CMS/ECIES clients and servers drop
HandshakeInvariantand the relatedHandshakeErrorinvariant variants; ordering is enforced by flow-specific transitions and transport phase helpers instead.Breaking API:
EncryptedProtocolStatedropsset_handshake_state/set_session_keys/unset_session_keysin favor ofsession_phase/set_session_phaseand the helper transitions above; listener impls requireP: CryptoProvider + Send + Sync + 'static.Reviewed by Cursor Bugbot for commit e3ae60e. Bugbot is set up for automated code reviews on this repo. Configure here.