Skip to content

Abort TLS transport on session verification failure#3323

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/3245-tls-handshake-failure
Open

Abort TLS transport on session verification failure#3323
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/3245-tls-handshake-failure

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 11, 2026

Copy link
Copy Markdown
Member

Motivation

A failed post-handshake session verifier was handled as if the SSLEngine itself had failed. When the verifier returned an SSLException, the GraphStage TLS implementation caught it in the engine failure path and called closeOutbound(). Because the handshake had already succeeded and there was no pending fatal alert, this generated close_notify and completed the transport gracefully instead of aborting it.

Engine-originated handshake failures are intentionally left unchanged: those paths must continue wrapping and flushing pending fatal alerts such as certificate_unknown.

Modification

  • Handle a failed verifySession result as an explicit TLS stage failure.
  • Stop wrap/unwrap handshake processing immediately after the verifier rejects the session.
  • Use structured if/else control flow rather than a non-local return.
  • Add a directional regression test that observes the cipher-side transport termination and checks that the original verifier exception fails it.
  • Run the shared test for both the GraphStage and legacy actor implementations, covering TLS 1.2 and TLS 1.3.

Result

Post-handshake session verification failures now abort the transport with the original exception. The GraphStage behavior matches the legacy TLS actor, while engine-originated TLS failures continue to flush their fatal alerts.

Tests

  • stream-tests / Test / testOnly org.apache.pekko.stream.io.TlsGraphStageSpec — 113 passed
  • stream-tests / Test / testOnly org.apache.pekko.stream.io.TlsSpec — 113 passed
  • stream-tests / Test / testOnly org.apache.pekko.stream.io.TlsGraphStageDeferredCloseSpec — 3 passed
  • stream-tests / Test / testOnly org.apache.pekko.stream.io.TlsGraphStageIsolatedSpec — 7 passed
  • +mimaReportBinaryIssues — passed for Scala 2.13 and Scala 3
  • checkCodeStyle — passed
  • +headerCheckAll — passed
  • scalafmt --list --mode diff-ref=origin/main — passed
  • git diff --check origin/main...HEAD — passed
  • validatePullRequest — not run per request; focused TLS, compatibility, style, and header checks above were run
  • Qoder stdout blocker review — no must-fix findings

References

Refs #3245

@He-Pin He-Pin added this to the 2.0.0-M4 milestone Jul 11, 2026
@He-Pin He-Pin requested a review from pjfanning July 11, 2026 10:26
Comment thread stream/src/main/scala/org/apache/pekko/stream/impl/io/TlsGraphStage.scala Outdated
@He-Pin He-Pin force-pushed the fix/3245-tls-handshake-failure branch 2 times, most recently from 7b342cb to b08e5e4 Compare July 14, 2026 03:22
@He-Pin He-Pin requested a review from pjfanning July 14, 2026 03:57
Motivation:
When TLS session verification fails, the transport did not
properly abort, leaving the connection in an inconsistent state
that could lead to security issues or hangs.

Modification:
- Abort the TLS transport immediately on session verification
  failure
- Address review feedback on error handling

Result:
TLS connections are properly torn down when session verification
fails, preventing potential security issues.

Tests:
- Existing TLS transport tests

References:
Fixes apache#3245
@He-Pin He-Pin force-pushed the fix/3245-tls-handshake-failure branch from b08e5e4 to 66c0a59 Compare July 14, 2026 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants