Skip to content

ssl: allow SSLContext#set_params to be used from non-main Ractors #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rhenium
Copy link
Member

@rhenium rhenium commented Aug 1, 2025

Freeze OpenSSL::SSL::SSLContext::DEFAULT_PARAMS to make it Ractor-shareable.

When called from a non-main Ractor, SSLContext#set_params now prepares a new OpenSSL::X509::Store in Ractor-local storage.


This applies on top of #924. Fixes #521.

Note that you need https://bugs.ruby-lang.org/issues/21109 to use SSLSocket in a non-main Ractor, which will be part of Ruby 3.5.

rhenium added 5 commits August 1, 2025 21:02
Explicitly load both the "default" and "legacy" providers in the test
case.

The "legacy" provider is intended to be used with the "default"
provider. The "default" provider is typically loaded automatically, but
that only happens when no other provider has been loaded yet.
Check for the function we actually use. Both SSL_set0_tmp_dh_pkey() and
SSL_CTX_set0_tmp_dh_pkey() were added in OpenSSL 3.0.
Enable automatic DH parameters for TLS 1.2 or earlier when neither
SSLSocket#tmp_dh nor SSLSocket#tmp_dh_callback is set. This is supported
since OpenSSL 1.1.0.

This allows us to remove the default tmp_dh_callback proc defined in
lib/openssl/ssl.rb, which uses hard-coded parameters and is not
Ractor-shareable.
tmp_dh_callback no longer has a default value. It also no longer has to
share code with tmp_ecdh_callback, which was removed in v3.0.0.
Freeze OpenSSL::SSL::SSLContext::DEFAULT_PARAMS to make it
Ractor-shareable.

When called from a non-main Ractor, SSLContext#set_params now prepares
a new OpenSSL::X509::Store in Ractor-local storage.
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.

OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE is not shareable across ractors
1 participant