Repository navigation
Start TLS on the control channel right after the AUTH TLS reply - #606
Merged
hannesdejager merged 2 commits intoNov 7, 2026
Merged
Conversation
AUTH TLS spawned a task to send the internal SecureControlChannel message and returned the 234 reply at once. The control loop then went back to selecting between that message and the next bytes from the client. A client starts the TLS handshake as soon as it reads the 234 (RFC 4217, section 4), so when its ClientHello won that race it was decoded as an FTP command and answered in plain text, and the client failed with "received corrupt message of type InvalidContentType". When the message won but the codec had already read part of the ClientHello, those bytes were dropped by `into_inner()` and the handshake stalled. The control loop now starts TLS itself right after sending a 234 reply to AUTH TLS, before reading anything else from the plain connection. Bytes the codec already holds are handed to the TLS acceptor. The SecureControlChannel event still goes through the middleware chain afterwards, so the session state and logging are unchanged. tests/ftps.rs upgrades 50 control connections, with the ClientHello sent right after the reply and in the same write as the command. Under CPU load the first case failed in 19 of 20 runs before this change (1 to 5 of the 50 upgrades each); the second failed every upgrade. Both pass in 20 of 20 runs with it.
Member
|
Looks great, thanks @monurpalan |
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.
Fixes #605.
AUTH TLSspawned a task to sendSecureControlChanneland returned234at once, so the control loop could read the client's ClientHello as a command line before switching to TLS (or drop the part the codec had already buffered). Details are in the issue.Change
Auth::handleonly returns the234reply; it no longer spawns the internal message.234reply toAUTH TLS, before reading anything else from the plain connection. If the codec already holds bytes the client sent with the command, they are handed to the TLS acceptor (Framed::into_parts+tokio::io::join) instead of being dropped.SecureControlChannelevent still goes through the middleware chain after the handshake, sosession.cmd_tls, logging and metrics behave as before. Client certificates are stored on the session as before.Test
tests/ftps.rs(new) upgrades 50 control connections and sendsNOOPover TLS on each, in two variants: ClientHello right after reading234, and ClientHello in the same write asAUTH TLS. It uses a test CA and alocalhostcertificate intests/resources/ftps/(test-only key, valid until 2126) and addsrustlsas a dev-dependency for the client.234, under CPU load, 20 runsAUTH TLSWithout load the first variant rarely fails, so on an idle machine it mainly guards the change; the second one fails deterministically without the fix.
Checked on Linux with Rust 1.92:
cargo fmt --check,cargo clippy --all-features --workspace -- -D warnings,cargo test --workspace --exclude 'unftp-sbe-gcs*', doc tests, examples,cargo doc, and the feature combinations from the contributing guide.The CHANGELOG entry is under Unreleased.