On 8/11/26 15:24, Peter Eisentraut wrote:
I was curious about the hardcoded FILE_DH2048 in src/include/libpq/
libpq-be.h -- how did it get there, do we ever need to update it, how do
we know, etc. -- and it seems that there is a more modern approach that
allows us to get rid of it.
Previously, if ssl_dh_params_file was not set, the compiled-in default
parameters in FILE_DH2048 were used. Instead, we can call
SSL_CTX_set_dh_auto() and have OpenSSL choose appropriate, well-known,
and appropriately sized parameters. In particular, the size of the
parameters is chosen consistent with the size of the key and
certificate, and so it can automatically grow with new standards and
best practices. This facility was not available at the time FILE_DH2048
was added, but it is now available in all relevant OpenSSL and LibreSSL
versions.
Nice! This simplifies our code. And SSL_CTX_set_dh_auto() was introduced
in OpenSSL 1.1.0 and in LibreSSL 2.1.2 so everything we support should
have the function.
I think this new behavior is preferable (also consistent with
recommendations in the OpenSSL documentation), so I have tweaked the
documentation a bit in that direction.
There was also some not-very-modern text about this in README.SSL,
which I have deleted.
Good.
Note that if you use a very small certificate/key size, then this
could mean that the size of the chosen DH parameters could also end up
smaller than the previous hard-coded default. But that could only
happen if you disregarded all current security best practices anyway.
Sounds reasonable to me.
Note a small behavior change: Previously, if loading the DH file
failed during a server reload, the system would then fall back to
using the built-in parameters, instead of failing the reload and
keeping the old SSL context, which is what it would do if some other
aspect of reinitializing SSL would fail. I think this is actually a
bug. I have fixed this here as part of reflowing the relevant function.
Agreed, I would say the previous behviour was a bug.
Anyway, this is all very complicated and obscure. Reviews are welcome.
The code and documentation change looks simple and good to me.
And Heikki asked a good question: maybe we can just remove the GUC. But
I do not think that discussion should block merging this as this is
useful on its own and a separate commit can add a deprecation warning or
remove the GUC.
--
Andreas Karlsson
Percona