Skip to content

Expose SSL_set1_groups to Efficiently Set Curves on SSL Session#346

Merged
kornelski merged 3 commits intocloudflare:masterfrom
Justin-Kwan:cf-set-session-curves
Jun 6, 2025
Merged

Expose SSL_set1_groups to Efficiently Set Curves on SSL Session#346
kornelski merged 3 commits intocloudflare:masterfrom
Justin-Kwan:cf-set-session-curves

Conversation

@Justin-Kwan
Copy link
Contributor

@Justin-Kwan Justin-Kwan commented May 2, 2025

Description

  • Exposes BoringSSL method SslRef::set_groups -> SSL_set1_groups to directly set curve groups against an ongoing SSL session. This is necessary because in boringssl, calling SSL_set_SSL_CTX to switch the SSL_CTX does not update the supported group list (supported_group_list) on the existing SSL session object. We must set the curve list directly on the session after the SSL object is created but before the handshake begins.
    b377876c-b3eb-492f-b392-b18746ba605a

  • SSL_set1_groups is more efficient than the currently exposed SslRef::set_curves_list -> SSL_set1_groups_list which uses more complicated parsing logic to parse colon delimited groups in string
    113e324c-a2a1-489f-b65c-6300f1366c8a

  • Exposes BoringSSL method SslRef::set_options -> SSL_set_options to directly set options against an ongoing SSL session (ex. enable boring::ssl::SslOptions::CIPHER_SERVER_PREFERENCE for a specific SNI only)

@cjpatton
Copy link
Collaborator

cjpatton commented May 2, 2025

@Justin-Kwan
Copy link
Contributor Author

Justin-Kwan commented May 2, 2025

Hi @cjpatton! I believe SslContextBuilder::set_curves applies the curve list to the SSL_CTX template globally for SSL session objects. However, it doesn't allow setting different curves per connection or per SNI at runtime (which we need).

Since BoringSSL doesn't copy the curve list from the context into the SSL object, we need to set the curves directly on each SSL session to support different configurations for different SNIs.

@bwesterb
Copy link
Member

bwesterb commented May 3, 2025

We're talking about deprecating set_curves in favour of set_curves_list. Does that cause problems for you?

@Justin-Kwan
Copy link
Contributor Author

Hi @bwesterb. Are you referring to the [SSL_set1_curves_list](https://www.openssl.org/docs/manmaster/man3/SSL_set1_curves_list.html) onto the SSL session itself?

Ideally, we'd like to use the set_curves method directly, to avoid any colon delimited string parsing overhead upon each new SSL session.

https://github.com/google/boringssl/blob/bf4cf6938a77f1aca83ef529dce96681efd1e6c5/ssl/ssl_lib.cc#L1861

@bwesterb
Copy link
Member

bwesterb commented May 5, 2025

Ideally, we'd like to use the set_curves method directly, to avoid any colon delimited string parsing overhead upon each new SSL session.

Have you timed it? If it's significant, we can work with upstream to allow preparsing.

Copy link
Collaborator

@kornelski kornelski left a comment

Choose a reason for hiding this comment

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

Looks okay, except I'd prefer a newtype instead of c_int in the API.

@Justin-Kwan Justin-Kwan force-pushed the cf-set-session-curves branch from f13c651 to 1be437c Compare May 31, 2025 00:25
@Justin-Kwan
Copy link
Contributor Author

Thanks for the feedback and review @kornelski!

@Justin-Kwan
Copy link
Contributor Author

@kornelski Thank you for the help, happy to see build is passing!

@kornelski kornelski merged commit 17d137e into cloudflare:master Jun 6, 2025
23 checks passed
@Justin-Kwan Justin-Kwan deleted the cf-set-session-curves branch June 6, 2025 16:37
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.

4 participants