LibreSSL and OpenSSL separation in libpq to support 1.1.1 deprecation
LibreSSL and OpenSSL separation in libpq to support 1.1.1 deprecation
Since the discussion on the minimum supported version of OpenSSL for v20 has
kicked off, I wanted to share what I believe is an important step on the path
to OpenSSL modernization; namely how to deal with LibreSSL.
Our LibreSSL support is currently based on the OpenSSL code and the OpenSSL
compatibility in LibreSSL, so much so that for quite some time we didn't even
document that it was supported even though it was buildfarm tested. Over time
we've accumulated more ifdefs for differences in API support. If we want to
modernize our OpenSSL support in libpq with v3+ API's once we've deprecated
1.1.1, the code will soon become unreadable and IMHO, a CVE hazard.
LibreSSL supports the 1.1.1 API, and they dont have the manpower to keep up
with the rapid pace of OpenSSL development so are likely to stay there for the
foreseeable future. The libraries have already started diverging quite a lot
and it will continue (LibreSSL have also developed their own API which if I
were them is what I'd focus on).
As I can see it we have two choices wrt LibreSSL if we want to move past 1.1.1;
either deprecate support or separate it out such that OpenSSL and LibreSSL can
move at their own pace. I don't like the idea of deprecating LibreSSL so I
favor the latter alternative.
The attached implements LibreSSL as a separate TLS library implementation (*)
in libpq with fe-secure-libressl.c and be-secure-libressl.c along with build
and test infrastructure. This is a PoC rather than a polished for-inclusion
patch as of now, since I wanted to get the discussion going. Some of the known
TODO items include:
- Autoconf support is a POC and not tested at all yet, only the
Meson side has been tested as of now
- include/common/openssl.h needs to either be renamed, copied
or at least have its comments extended
- test/ssl/t/SSL/Backend/OpenSSL.pm has been hackily extended
for now, the exact level of changes required here are not
clear, and a future move to pytest may influence how much we
want to invest here
- the discovery in meson.build is likely rubbish and could be
cleaned up by our Meson experts
- there are likely lots of comments still that mention OpenSSL
which could be expanded to say something about LibreSSL
- documentation of the build option is missing
- we can simplify a few uses of USE_OPENSSL || USE_LIBRESSL to
just USE_SSL
There are no new features introduced (and none removed) or API usage changes,
the only changes are to cut away the ifdefs and only keep the code we actually
need per file. This way the differences are quite easy to check by diffing
{fe|be}-secure-{openssl|libressl}.c.
While this duplicate a lot of code, it doesn't really add a maintenance burden
we don't already carry since we do support LibreSSL already, but it does alter
the burden for sure (not least when it comes to backpatching). That being
said, staying on a long-since deprecated API level (we are at 1.0.1 with
warnings silenced) also doesn't sound great.
One option is to not do this until we have a case where we want to use a v3+
API and only do it then as a prerequisite step; keeping the patch rebased in
the back-pocket till that day comes. Personally I have serverside SNI support
for LibreSSL on my radar for v20, which will need such a split in order to keep
the files readable as it will be implemented quite differently from its OpenSSL
counterpart.
All of the above is of course moot if we don't move the needle past 1.1.1 in
v20..
--
Daniel Gustafsson
(*) Yes. The irony of me proposing to add a new TLS library implementation to
postgres is *not* lost on me.
Re: LibreSSL and OpenSSL separation in libpq to support 1.1.1 deprecation
От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 12 Aug 2026, at 11:51, Peter Eisentraut wrote: > > On 09.07.26 23:14, Daniel Gustafsson wrote: >> The attached implements LibreSSL as a separate TLS library implementation (*) >> in libpq with fe-secure-libressl.c and be-secure-libressl.c along with build >> and test infrastructure. > > I'm skeptical about this approach. What has been presented so far doesn't convince me that the differences between the openssl and the libressl variants will be larger than their commonalities. That assumes that future changes are done within the 1.1.1 API, which is already not the case since 1f3b9bb109b8b1a7b (granted, it's in src/common but similar patches against be-secure-openssl.c are already on the list). Personally I'd be much more interested in deprecating 1.1.1 and moving us onto supported APIs. Until we do there is of course no point in a patch like this (which I tried to say upthread). > As an example, my recent patch [0] works just the same on both (AFAICT). I didn't have to worry about the differences at all. While not introduced in this patch, merely moved, it also use a since 3.0 deprecated API which is not available in LibreSSL. Reading the implementation they seem quite similar apart from ibreSSL not supporting increased keysize when using SSL_CTX_set_security_level. While we don't use the security level API, it's an example of difference behind the API which *I* constantly worry about when poking at this code. > Under the proposed system, I would have to make the same code changes twice, test everything twice (including obtaining libressl in the first place and set up a separate build for it). Doesn't sound appealing. Testing everything twice isn't new, we already need to test all libpq TLS related changes on both OpenSSL and LibreSSL since they are supported. Trusting that one works because the other one does is a brittle assumption and I've had to revert commits because of precisely that reason. Applying code twice is a real pain though, but navigating an increased level of ifdefs won't be pleasant either (assuming it happens of course). Again, all of this is moot if we don't deprecate 1.1.1 support, but I don't think we are doing our users a service by allowing them to use an TLS library which when v20 goes EOL has been out of security updates for 8+ years. -- Daniel Gustafsson
Re: LibreSSL and OpenSSL separation in libpq to support 1.1.1 deprecation
От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Wed, Aug 12, 2026 at 8:14 AM Daniel Gustafsson wrote: > > Under the proposed system, I would have to make the same code changes twice, test everything twice (including obtaining libressl in the first place and set up a separate build for it). Doesn't sound appealing. > > Testing everything twice isn't new, we already need to test all libpq TLS > related changes on both OpenSSL and LibreSSL since they are supported. > Trusting that one works because the other one does is a brittle assumption and > I've had to revert commits because of precisely that reason. Applying code > twice is a real pain though, but navigating an increased level of ifdefs won't > be pleasant either (assuming it happens of course). +1 -- this is where I kind of raised an eyebrow at your argument, Peter. We're already doing that, and we *must* do it, whether it's obvious or not that said work is being done. I'm very much in favor of splitting that apart and making the invisible pain visible (at least conceptually -- I haven't had a chance yet to sit down and look at this particular patch, and I'm very sorry for that; maybe a hybrid such as Alvaro's suggestion would work too). In my opinion, keeping the two same-in-name-but-not-in-practice implementations together is keeping things more brittle, not less, most recently when I look at the SNI work. If we split the two, then in addition to not risking 1.1.1-based destabilization as we move to 4.0 APIs, we can investigate porting LibreSSL code on top of their libtls API instead. > Again, all of this is moot if we don't deprecate 1.1.1 support, but I don't > think we are doing our users a service by allowing them to use an TLS library > which when v20 goes EOL has been out of security updates for 8+ years. We should do that for PG20. I'm continuing to push for that in other threads [1]. No one has said "no" yet, I think, so IMNSHO we should just do it. Thanks, --Jacob [1] https://postgr.es/m/CAOYmi%2B%3DVJJ%3D1a-wHwWd2mTgQ3bkHzAUHCFssosF7h1y8TEN%2Biw%40mail.gmail.com