support non-blocking client #6

Merged
vimacs merged 18 commits from wehack-dev/ssh_protocol-ada:dev into main 2026-11-24 04:30:35 +00:00
Contributor
No description provided.
AES-CTR (RFC 4344) used a fresh EVP context with the initial IV for every
packet, so every packet reused the first packet's keystream.  It also left
the encrypted packet_length field undecrypted and had no way to report a
length-decryption failure.

- Persist the 128-bit big-endian counter and intra-block offset in the
  cipher state and advance them across packets (SDCTR semantics).
- Add an AES-128/192/256 Decrypt_Len peek callback that works on a state
  copy and never consumes keystream.
- Change Decrypt_Length_Func / Decrypt_Packet_Length to report OK, and
  adapt the ChaCha20 backends, sessions, example and tests.
- Compute the non-AEAD MAC over the plaintext packet before encryption
  (RFC 4253 Section 6.4) and include the MAC in capacity checks.
- Add Get_Recv_Auth_Length (AEAD tag or MAC, keyed on Encrypt_Recv) so the
  high-level readers keep the old authentication length during rekey.
- Add AES-CTR NIST, multi-packet, peek, counter-carry, partial-block and
  two-session AES-CTR+HMAC transport integration tests.
- Update doc/api.md and doc/develop.md.
Replace the single Pending_Payload slot with a bounded byte-ring FIFO so
messages that arrive during a rekey can no longer overwrite each other
(RFC 4253 Section 7.1).

- Add SSH_Protocol.Transport.Pending_Queue with enqueue/dequeue/clear.
  Queue_Full is returned without overwriting older messages;
  Pending_Too_Small leaves the oldest message queued; Resource_Error
  reports broken metadata.  The queue holds one maximum-size payload.
- Route all four pending-message producers through the FIFO and wipe it
  during disconnect cleanup.
- Pop one message per Get_Pending_Data call and add Get_Pending_Count /
  Has_Pending_Data; expose only the produced payload slice.
- Gate client application sends while KEXINIT has been sent but our
  NEWKEYS has not (Rekey_In_Progress), leaving connection state untouched.
- Add Process_Status values needed by this and later stages.
- Add FIFO, rekey in-flight, send-gating, and queue-full tests; the queue
  unit proves 19 checks with GNATprove.
Document that Transport_Process and Parse_Packet accept exactly one
complete on-wire packet.  Cleartext prefixes are memoryless retries;
encrypted prefixes may consume stream-cipher state and must not be
retried.  Empty input is restricted to the explicit no-input actions.

Reject trailing bytes after the declared packet with Protocol_Error and
reject short decrypted frames instead of returning Need_More_Data.

Add transport tests for fragmented cleartext KEXINIT, exact-length
enforcement, and non-retryable encrypted prefixes using a stateful test
cipher.  Record phase 0.2 in doc/develop.md.
Unify packet-length validation and remove the remaining framing defects
required before the non-blocking receive path.

- Define Min_Packet_Length, Max_Recv_Auth_Length, Max_Packet_Length,
  Max_Payload_Length, Max_Wire_Packet and Max_Step_Output; extend
  Byte_Array and its index subtype to Max_Buffer_Size for Step output.
- Add Validate_Packet_Length and use it from Parse_Packet and both
  Read_SSH_Packet paths; reject padding larger than packet_length - 1,
  empty payloads, and lengths outside the min/max/block-aligned range.
- Bound Build_Packet with Max_Payload_Length and Max_Packet_Length,
  include MAC/tag space in the capacity check, and encrypt in place
  because Packet is now required to be 1-based.
- Advance Seq_Num_Recv (and Data_Recv) when first_kex_packet_follows
  drops a guessed packet; during rekey run framing first so the old
  MAC/stream state is consumed.
- Move Parse_Packet and state-handler payload buffers into session
  scratch storage, check Emit_NEWKEYS output capacity, and wipe cipher
  state, scratch and the pending FIFO on disconnect.
- Add framing boundary, padding underflow, maximum packet, and dropped
  packet post-NEWKEYS MAC tests; document the stack/session sizes.
- Update doc/api.md for the new constants and Validate_Packet_Length.
Use Transport.Max_Wire_Packet for the high-level read buffers and update
the phase 0.2 follow-up note now that phase 0.3 is complete.
Introduce Feed/Feed_EOF and framing queries backed by a bounded receive buffer in Client_Sessions. Resolve and cache packet_length with the shared transport validation, respect receive MAC/AEAD lengths during rekey, preserve bytes on backpressure, and report EOF after draining complete packets. Add plaintext framing tests covering fragmentation, multi-packet feeds, retry after Buffer_Full, EOF, and length boundaries.
Pre_Service now sends SERVICE_REQUEST after KEX and validates the matching SERVICE_ACCEPT, Auth_Service initialises the auth layer and sends the none probe once, and Connection_Service only dispatches upper-layer messages. Perform_KEX, Authenticate, Establish_Connection_Service and Receive_And_Dispatch become thin Step plus Needed_Bytes wrappers so the blocking and non-blocking paths share one state machine. The client-side Read_SSH_Packet is removed; all client reads use the RX accumulator.
Add scripted tests for Pre_Service to Connection_Service progression, SERVICE_ACCEPT queue ordering, wrong or unsolicited SERVICE_ACCEPT, truncated authentication fields, MAC_Error poisoning, and byte-for-byte equivalence between the blocking wrappers and Feed/Step. Add a rejecting cipher stub for the MAC failure path.
vimacs merged commit 31c49e7f03 into main 2026-11-24 04:30:35 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
vimacs/ssh_protocol-ada!6
No description provided.