THRIFT-6073: Allow injecting external SSL_CTX into C++ SSLContext#3606
THRIFT-6073: Allow injecting external SSL_CTX into C++ SSLContext#3606hongzhi-gao wants to merge 5 commits into
Conversation
Enable building libthrift against Tongsuo via -DWITH_TONGSUO and expose NTLS dual-certificate APIs on TSSLSocketFactory for TLCP workloads.
Code reviewFound 2 issues:
thrift/lib/cpp/src/thrift/transport/TSSLSocket.cpp Lines 1110 to 1115 in 0d5e69a
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
| TLSv1_0 = 3, // Supports TLSv1_0 or later. | ||
| TLSv1_1 = 4, // Supports TLSv1_1 or later. | ||
| TLSv1_2 = 5, // Supports TLSv1_2 or later. | ||
| NTLS = 6, // Tongsuo NTLS/TLCP; requires dual signing and encryption certificates. |
There was a problem hiding this comment.
NTLS = 6 was removed with the provider-specific APIs.
|
Thanks for putting this together. Could we consider narrowing the upstream change to a generic TLS-provider compatibility layer, rather than making Tongsuo/NTLS a first-class Thrift backend? The current patch adds Tongsuo-specific build plumbing, An alternative might be to expose a small backend-neutral extension point around That would still let users avoid carrying a private transport fork, but keeps the provider-specific dependency and policy choices outside the core Thrift tree. Would you be open to reshaping the patch in that direction? |
|
Done — the patch is reshaped to a backend-neutral SSLContext wrapper around an application-provided SSL_CTX, using the existing SSLContextFactory hook. Tongsuo/NTLS dual-cert setup lives in application (or local test) code; Thrift core stays OpenSSL-compatible and provider-agnostic. |
Replace Tongsuo-specific build options, NTLS protocol enum, and dual-certificate factory APIs with SSLContext(SSL_CTX*, bool takeOwnership) so applications can inject a pre-configured OpenSSL-compatible context through SSLContextFactory.
Prevent implicit conversion from SSL_CTX* to avoid accidental ownership mistakes.
Clarify that CTest expects a sibling Tongsuo source checkout for SM2 fixtures and that shared TLS libraries from a build tree need LD_LIBRARY_PATH.
Keep the PR focused on backend-neutral SSLContext injection; SecurityTest covers the wrapped-context API.
Code reviewFound 6 issues (adversarially verified):
thrift/lib/cpp/src/thrift/transport/TSSLSocket.cpp Lines 216 to 221 in 0870077 Verified: no
thrift/lib/cpp/src/thrift/transport/TSSLSocket.h Lines 365 to 374 in 0870077 Verified: member absent in base, no SOVERSION in CMakeLists.txt, no
thrift/lib/cpp/test/SecurityTest.cpp Lines 286 to 306 in 0870077 Verified:
thrift/lib/cpp/src/thrift/transport/TSSLSocket.h Lines 367 to 374 in 0870077 Verified: no
thrift/lib/cpp/src/thrift/transport/TSSLSocket.h Lines 367 to 374 in 0870077 Verified:
Verified: AGENTS.md requirement confirmed; PR body grep for "threat" returns no output; 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
|
One housekeeping note: for a change of this scope, it is worth making sure the JIRA ticket captures the key design decisions and rationale in addition to what is in the commit messages. Commit messages are squashed on merge and can be hard to find later; JIRA comments and the ticket description remain a stable reference for anyone reviewing the issue in future. If there is technical context currently spread across individual commit messages (e.g. the rationale for the |
Summary
Add a backend-neutral extension point to the C++
TSSLSocketstack: applications can inject a pre-configured OpenSSLSSL_CTXthrough the existingSSLContextFactory/TSSLSocketFactoryhook.This makes it easier for applications to supply a fully configured TLS context—protocol options, cipher suites, certificate loading, and other OpenSSL settings—in application code, without patching libthrift or replacing the transport layer.
Background
Thrift C++ already provides SSL/TLS through
TSSLSocket/TSSLSocketFactory, backed by OpenSSL. The default factory covers the common case: a single certificate/key pair vialoadCertificate()/loadPrivateKey(), and protocol selection viaSSLProtocol.TSSLSocketFactoryalready accepts a customSSLContextFactory, butSSLContextcould previously only be created fromSSLProtocol. Applications that need a context configured outside Thrift's helpers—multi-step cert setup, non-default methods, or options not exposed byTSSLSocketFactory—had to patch Thrift locally.This PR adds a small wrapper constructor on
SSLContextwhile keeping the default OpenSSL build unchanged.What changed
SSLContext:explicit SSLContext(SSL_CTX* ctx, bool takeOwnership = true)— wrap an application-owned context; destructor respects ownership.lib/cpp/README.md: document the injection pattern.SecurityTest: wrapped-context and null-validation coverage.Removed from the earlier draft:
WITH_TONGSUO,SSLProtocol::NTLS,loadSign*/loadEnc*, vendored test keys, and the optional local NTLS integration test.Usage
Standard TLS (unchanged):
Injected
SSL_CTX(application owns OpenSSL configuration):Link your application against whichever OpenSSL-compatible TLS library you choose; libthrift continues to default to system OpenSSL at build time.
Licensing
Thrift introduces no new build-time dependency. Nothing is vendored; no
LICENSE/NOTICEupdate is required.Test plan
ctest -R SecurityTest(wrapped_ssl_context,wrapped_ssl_context_null)