Skip to content

THRIFT-3165: Disable TLSv1.0 and TLSv1.1 by default#3600

Open
HTHou wants to merge 1 commit into
apache:masterfrom
HTHou:THRIFT-3165
Open

THRIFT-3165: Disable TLSv1.0 and TLSv1.1 by default#3600
HTHou wants to merge 1 commit into
apache:masterfrom
HTHou:THRIFT-3165

Conversation

@HTHou

@HTHou HTHou commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Set the C++ TSSLSocketFactory default SSLTLS context to keep version-flexible negotiation while using TLS 1.2 as the default protocol floor.
  • Add a custom SSLContext factory constructor so applications can adjust OpenSSL context options before socket creation when they need a different protocol range.
  • Update the C++ SSL security tests and README note for the default behavior.

Validation

  • PATH="/opt/homebrew/opt/bison/bin:$PATH" BOOST_ROOT=/opt/homebrew/opt/boost ./configure --with-boost=/opt/homebrew/opt/boost --with-boost-libdir=/opt/homebrew/opt/boost/lib --with-openssl=/opt/homebrew/opt/openssl@3
  • PATH="/opt/homebrew/opt/bison/bin:$PATH" make -C lib/cpp CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
  • PATH="/opt/homebrew/opt/bison/bin:$PATH" make -C lib/cpp/test CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include" BOOST_SYSTEM_LDADD= SecurityTest SecurityFromBufferTest
  • cd lib/cpp/test && DYLD_LIBRARY_PATH="../.libs:.libs:$DYLD_LIBRARY_PATH" ./SecurityTest -- ../../../test/keys
  • cd lib/cpp/test && DYLD_LIBRARY_PATH="../.libs:.libs:$DYLD_LIBRARY_PATH" ./SecurityFromBufferTest -- ../../../test/keys

The SSL matrix tests print expected shutdown messages for protocol combinations that do not complete negotiation.

AI assistance

Co-Authored-By: Codex noreply@openai.com

@mergeable mergeable Bot added the c++ Pull requests that update C++ code label Jun 17, 2026
@HTHou HTHou changed the title THRIFT-3165: Set C++ default TLS protocol floor THRIFT-3165: Disable TLSv1.0 and TLSv1.1 by default Jun 17, 2026
@HTHou HTHou force-pushed the THRIFT-3165 branch 2 times, most recently from 5948ff4 to 79a85c8 Compare June 17, 2026 10:23
@HTHou HTHou marked this pull request as ready for review June 17, 2026 10:32
@HTHou HTHou requested review from emmenlau and mhlakhani as code owners June 17, 2026 10:32
Copilot AI review requested due to automatic review settings June 17, 2026 10:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates Thrift C++ SSL defaults to require TLS 1.2+ by default, while enabling applications to inject a custom SSLContext when different protocol ranges are needed.

Changes:

  • Raise the default SSLTLS protocol floor by disabling TLS 1.0 and TLS 1.1 in SSLContext.
  • Add TSSLSocketFactory constructor overload that accepts an SSLContext factory callback.
  • Update SSL security matrix expectations, add targeted tests, and document the new default behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/cpp/src/thrift/transport/TSSLSocket.cpp Enforces TLS 1.2+ for SSLTLS and introduces factory-based SSLContext construction with safer init/cleanup handling.
lib/cpp/src/thrift/transport/TSSLSocket.h Adds SSLContextFactory type + new TSSLSocketFactory ctor; updates protocol documentation.
lib/cpp/test/SecurityTest.cpp Adds tests for default/custom SSL context options; updates expected protocol compatibility matrix.
lib/cpp/test/SecurityFromBufferTest.cpp Updates expected protocol compatibility matrix for buffer-based SSL tests.
lib/cpp/README.md Documents new default minimum TLS version and how to override via custom context factory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/cpp/src/thrift/transport/TSSLSocket.cpp
Comment thread lib/cpp/src/thrift/transport/TSSLSocket.h
Comment thread lib/cpp/src/thrift/transport/TSSLSocket.cpp
Comment thread lib/cpp/test/SecurityTest.cpp
@Jens-G

Jens-G commented Jun 17, 2026

Copy link
Copy Markdown
Member

Code review

Found 2 issues:

  1. ctx_.reset() is called outside the mutex in the destructor, regressing the fix from THRIFT-2225 (commit 301dfa94d). That commit explicitly placed ctx_.reset() inside Guard guard(mutex_) to prevent a race between concurrent destructor calls and createSocket() threads reading ctx_ without the lock. The refactor here splits the lock into cleanupOpenSSLState() but leaves the reset unguarded.

TSSLSocketFactory::~TSSLSocketFactory() {
ctx_.reset();
cleanupOpenSSLState();
}

  1. The SSL_OP_NO_TLSv1 and SSL_OP_NO_TLSv1_1 assertions in the new test cases are not wrapped in #if guards, unlike the adjacent SSL_OP_NO_SSLv2 check on line 236. On OpenSSL 3.0+ these constants can evaluate to 0, making the unguarded BOOST_CHECK((options & SSL_OP_NO_TLSv1) != 0) assertions fail unconditionally even when the protocol floor is correctly set.

#if SSL_OP_NO_SSLv2 != 0
BOOST_CHECK((options & SSL_OP_NO_SSLv2) != 0);
#endif
BOOST_CHECK((options & SSL_OP_NO_SSLv3) != 0);
BOOST_CHECK((options & SSL_OP_NO_TLSv1) != 0);
BOOST_CHECK((options & SSL_OP_NO_TLSv1_1) != 0);
}

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Copilot AI review requested due to automatic review settings June 17, 2026 14:56
@HTHou

HTHou commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Jens-G, addressed both in the latest push.

  • Moved ctx_.reset() back under TSSLSocketFactory::mutex_ via cleanupOpenSSLState(), preserving the THRIFT-2225 locking/order.
  • Made the SSL_OP_NO_* option assertions conditional at runtime when each option bit is observable, including the custom-context checks.

Validation run locally:

  • git diff --check
  • object compile of TSSLSocket.cpp and SecurityTest.cpp with OpenSSL 3 / Homebrew Boost

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment on lines +261 to +266
std::shared_ptr<apache::thrift::transport::SSLContext> context;
TSSLSocketFactory factory([&context]() {
context = std::make_shared<CustomSSLContext>();
return context;
});
const auto options = SSL_CTX_get_options(context->get());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in the latest push. custom_ssl_context_options now explicitly resets the captured SSLContext before the test exits, so the extra shared reference is released before TSSLSocketFactory reaches its destructor/cleanup path.

Comment on lines +284 to +299
catch (const TSSLException& ex)
{
BOOST_CHECK_EQUAL("SSLContextFactory must not be empty", ex.what());
}

try
{
TSSLSocketFactory factory([]() {
return std::shared_ptr<apache::thrift::transport::SSLContext>();
});
BOOST_FAIL("Expected null SSLContextFactory result to throw");
}
catch (const TSSLException& ex)
{
BOOST_CHECK_EQUAL("SSLContextFactory must not return null", ex.what());
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in the latest push. The TSSLException message checks now compare against std::string(ex.what()), making the assertions explicit content comparisons.

Client: cpp

Co-Authored-By: Codex <noreply@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Pull requests that update C++ code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants