Skip to content

CASSCPP-16 Fix TLS 1.3 handshake race with in-flight Finished write - #591

Open
cpansuriya-simba wants to merge 1 commit into
apache:trunkfrom
cpansuriya-simba:tls-13-support
Open

CASSCPP-16 Fix TLS 1.3 handshake race with in-flight Finished write#591
cpansuriya-simba wants to merge 1 commit into
apache:trunkfrom
cpansuriya-simba:tls-13-support

Conversation

@cpansuriya-simba

Copy link
Copy Markdown

Problem
The driver pinned OpenSSL to TLS 1.2 because the handshake state machine assumed a 2-RTT flow where writes and "handshake done" are always sequential. TLS 1.3's 1-RTT handshake breaks that assumption: SSL_connect() can report completion in the same call that produces the outgoing Finished message, so "done" and "still have data to write" happen simultaneously rather than one after another.

Root cause
The old code only checked is_handshake_done() when there was nothing left to write (size == 0). Under TLS 1.3, that check could pass while the Finished message write was still in flight — causing the driver to verify the peer cert and hand the socket off to the post-handshake handler/write-recycling pool before the write actually completed, racing with (and risking corruption of) that write.

Fix

  1. ssl_openssl_impl.cpp — Raise max negotiated protocol to TLS 1.3; log negotiated protocol/cipher on successful handshake.
  2. socket_connector.hpp/.cpp — Extract cert verification + handshake completion into ssl_handshake_finish(). If the handshake completes while the Finished write is still queued, completion is now deferred to on_write (i.e., after the write actually lands) instead of firing immediately.
  3. socket.hpp/.cpp — Add a handler_generation_ counter to Socket/SocketWriteBase so a plain write object allocated during the handshake can't be recycled into a later request after the handler has since switched to SSL — closing a use-after-handoff/leak path into the encrypted session.

Net effect
TLS 1.3 connections now complete the handshake safely, with no race on the final handshake write and no stale pre-handoff write object leaking into the encrypted session.

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.

1 participant