Centralize ssl tests' check for whether we're using LibreSSL.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 9 May 2025 15:50:33 +0000 (11:50 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 9 May 2025 15:50:33 +0000 (11:50 -0400)
Right now there's only one caller, so that this is merely
an exercise in shoving code from one module to another,
but there will shortly be another one.  It seems better to
avoid having two copies of this highly-subject-to-change test.

Back-patch to v15, where we first introduced some tests that
don't work with LibreSSL.

Reported-by: Thomas Munro <thomas.munro@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CA+hUKG+fLqyweHqFSBcErueUVT0vDuSNWui-ySz3+d_APmq7dw@mail.gmail.com
Backpatch-through: 15

src/test/ssl/t/001_ssltests.pl
src/test/ssl/t/SSL/Backend/OpenSSL.pm
src/test/ssl/t/SSL/Server.pm

index 8b0de2d8e7e70b02a1a87077de872393cb63658b..60b5c3630b0c06d24195706af68ad287ddd067ae 100644 (file)
@@ -35,9 +35,8 @@ sub switch_server_cert
    $ssl_server->switch_server_cert(@_);
 }
 
-# Determine whether this build uses OpenSSL or LibreSSL. As a heuristic, the
-# HAVE_SSL_CTX_SET_CERT_CB macro isn't defined for LibreSSL.
-my $libressl = not check_pg_config("#define HAVE_SSL_CTX_SET_CERT_CB 1");
+# Determine whether this build uses OpenSSL or LibreSSL.
+my $libressl = $ssl_server->is_libressl;
 
 #### Some configuration
 
index e044318531f2e92ec19273c44488dd13e76fb734..4159addb700c1676d81b19986e9024af0e8264de 100644 (file)
@@ -26,6 +26,7 @@ package SSL::Backend::OpenSSL;
 
 use strict;
 use warnings FATAL => 'all';
+use PostgreSQL::Test::Utils;
 use File::Basename;
 use File::Copy;
 
@@ -205,6 +206,23 @@ sub get_library
    return $self->{_library};
 }
 
+=pod
+
+=item $backend->library_is_libressl()
+
+Detect whether the SSL library is LibreSSL.
+
+=cut
+
+sub library_is_libressl
+{
+   my ($self) = @_;
+
+   # The HAVE_SSL_CTX_SET_CERT_CB macro isn't defined for LibreSSL.
+   # We may eventually need a less-bogus heuristic.
+   return not check_pg_config("#define HAVE_SSL_CTX_SET_CERT_CB 1");
+}
+
 # Internal method for copying a set of files, taking into account wildcards
 sub _copy_files
 {
index 14277418419322d8a42c6d054b2df280004d9d9f..33975b28e8ced98c6826d5f848bf6f150711597f 100644 (file)
@@ -244,6 +244,23 @@ sub ssl_library
 
 =pod
 
+=item $server->is_libressl()
+
+Detect whether the currently used SSL backend is LibreSSL.
+(Ideally we'd not need this hack, but presently we do.)
+
+=cut
+
+sub is_libressl
+{
+   my $self = shift;
+   my $backend = $self->{backend};
+
+   return $backend->library_is_libressl();
+}
+
+=pod
+
 =item switch_server_cert(params)
 
 Change the configuration to use the given set of certificate, key, ca and