Skip to content

Conversation

rhenium
Copy link
Member

@rhenium rhenium commented Aug 1, 2025

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.

Also, a few cleanups in related code:


provider: load "default" provider in test_openssl_legacy_provider

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.


ssl: fix extconf.rb check for SSL_CTX_set0_tmp_dh_pkey()

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.


ssl: refactor tmp_dh_callback handling

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.

@rhenium
Copy link
Member Author

rhenium commented Aug 1, 2025

I don't think the failure with openssl-master with the fips provider is relevant, but I haven't been able to reproduce it locally.

@junaruga
Copy link
Member

junaruga commented Aug 1, 2025

I don't think the failure with openssl-master with the fips provider is relevant, but I haven't been able to reproduce it locally.

I executed the current latest master branch dfbbac6 with the latest OpenSSL master branch openssl/openssl@b20da23. I can see the failure below.

https://github.com/junaruga/ruby-openssl/actions/runs/16680199093/job/47216748820

@junaruga
Copy link
Member

junaruga commented Aug 1, 2025

I opened the issue ticket #926 for the FIPS test failures.

@rhenium rhenium force-pushed the ky/ssl-dh-auto branch 2 times, most recently from 127b28e to c4185e6 Compare September 17, 2025 13:11
Update the test case to explicitly load both the "default" and the
"legacy" providers.

Currently, the "default" provider as a side effect by the
OpenSSL::PKey::DH.new call in lib/openssl/ssl.rb. It will be cleaned up
in a following patch.
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.
Rely on OpenSSL's builtin DH parameters for TLS 1.2 and earlier instead
of providing a default SSLContext#tmp_dh_callback proc.
SSL_CTX_set_dh_auto() has been available since OpenSSL 1.1.0.

The parameters can still be overridden by specifying
SSLContext#tmp_dh_callback or #tmp_dh, as confirmed by existing tests.

SSLContext#tmp_dh_callback depends on a deprecated OpenSSL feature. We
also prefer not to hard-code parameters, which is a maintenance burden.
This change also improves Ractor compatibility by removing the
unshareable proc.
tmp_dh_callback no longer has a default value. It also no longer has to
share code with tmp_ecdh_callback, which has been removed in v3.0.0.
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.

2 participants