Skip to content

feat:Support for TLSv1.3#3319

Open
neilxxxxx wants to merge 2 commits into
apache:masterfrom
neilxxxxx:feat-TLS1.3
Open

feat:Support for TLSv1.3#3319
neilxxxxx wants to merge 2 commits into
apache:masterfrom
neilxxxxx:feat-TLS1.3

Conversation

@neilxxxxx
Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: resolve #

Problem Summary:

Previously, brpc only supported TLSv1.0/1.1/1.2 for SSL/TLS connections.
With the increasing industry adoption of TLSv1.3 (RFC 8446) and the deprecation
of older TLS versions by major cloud services and browsers, there is a need
to add TLSv1.3 support in brpc to:

  • Improve security with stronger cryptographic algorithms (e.g., ChaCha20-Poly1305, AES-256-GCM)
  • Improve performance with reduced handshake round-trips (1-RTT and 0-RTT)
  • Meet compliance requirements for modern security standards

What is changed and the side effects?

Changed:

  • Added TLSv1.3 support in SSL options
  • Updated the underlying OpenSSL initialization and context configuration to
    enable TLSv1.3 protocol methods when available
  • Added related unit tests to verify TLSv1.3 handshake and data transmission

Side effects:

  • Performance effects:

    • Positive: TLSv1.3 reduces handshake latency from 2-RTT to 1-RTT,
      and supports 0-RTT resumption for returning connections
    • No negative performance impact on existing TLSv1.2 connections
  • Breaking backward compatibility:

    • No. TLSv1.3 support is opt-in. Existing configurations defaulting to
      TLSv1.2 remain unchanged. Users must explicitly set the TLS version
      to enable TLSv1.3.

Check List:

  • Please make sure your changes are compilable.
  • When providing us with a new feature, it is best to add related tests.
  • Please follow https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds explicit TLSv1.3 protocol selection support to brpc’s SSL/TLS configuration by extending protocol parsing/bitmasks and wiring TLSv1.3 enable/disable into SSL_CTX option setup, plus a unit test that validates TLSv1.3 negotiation.

Changes:

  • Add TLSv1_3 protocol flag, parse "TLSv1.3" in ChannelSSLOptions::protocols, and apply SSL_OP_NO_TLSv1_3 when appropriate.
  • Update client-side default protocol list / documentation to include TLSv1.3.
  • Add a unit test that performs a direct OpenSSL handshake and asserts "TLSv1.3" is negotiated (when supported by the SSL library).

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
test/brpc_ssl_unittest.cpp Adds TLSv1.3 negotiation test via direct SSL_do_handshake() and SSL_get_version().
src/brpc/ssl_options.h Updates documented available/default protocol strings to include TLSv1.3.
src/brpc/ssl_options.cpp Updates ChannelSSLOptions default protocols string to include TLSv1.3.
src/brpc/details/ssl_helper.h Adds TLSv1_3 to SSLProtocol bitmask enum.
src/brpc/details/ssl_helper.cpp Adds TLSv1.3 parsing and SSL_OP_NO_TLSv1_3 handling; enables TLSv1.3 in server default protocol mask.
Comments suppressed due to low confidence (1)

src/brpc/details/ssl_helper.cpp:600

  • CreateServerSSLContext now enables TLSv1.3 in the server-side default protocol mask. If the feature is meant to be strictly opt-in (as stated in the PR description), the server side also needs a way to control/disable TLSv1.3 (e.g., a protocols field in ServerSSLOptions, similar to ChannelSSLOptions), otherwise non-brpc clients that support TLSv1.3 may negotiate it by default.
    int protocols = TLSv1 | TLSv1_1 | TLSv1_2 | TLSv1_3;
    if (!options.disable_ssl3) {
        protocols |= SSLv3;
    }
    if (SetSSLOptions(ssl_ctx.get(), options.ciphers,

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

Comment on lines +89 to 93
} else if (strncasecmp(protocol.data(), "TLSv1.3", protocol.size()) == 0) {
protocol_flag |= TLSv1_3;
} else {
LOG(ERROR) << "Unknown SSL protocol=" << protocol;
return -1;
Comment on lines +449 to +453
#ifdef SSL_OP_NO_TLSv1_3
if (!(protocols & TLSv1_3)) {
ssloptions |= SSL_OP_NO_TLSv1_3;
}
#endif // SSL_OP_NO_TLSv1_3
Comment thread src/brpc/ssl_options.cpp
Comment on lines 28 to 31
ChannelSSLOptions::ChannelSSLOptions()
: ciphers("DEFAULT")
, protocols("TLSv1, TLSv1.1, TLSv1.2")
, protocols("TLSv1, TLSv1.1, TLSv1.2, TLSv1.3")
{}
Comment thread src/brpc/ssl_options.h
Comment on lines 81 to 84
// SSL protocols used for SSL handshake, separated by comma.
// Available protocols: SSLv3, TLSv1, TLSv1.1, TLSv1.2
// Default: TLSv1, TLSv1.1, TLSv1.2
// Available protocols: SSLv3, TLSv1, TLSv1.1, TLSv1.2, TLSv1.3
// Default: TLSv1, TLSv1.1, TLSv1.2, TLSv1.3
std::string protocols;
@wwbmmm
Copy link
Copy Markdown
Contributor

wwbmmm commented Jun 5, 2026

This PR has merge conflict now.

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.

3 participants