Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oe1Xu-0005y8-QJ for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Sep 2022 21:58:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oe1Xs-0001aM-Fj for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Sep 2022 21:58:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oe1Xs-0001aD-6k for pgsql-bugs@lists.postgresql.org; Thu, 29 Sep 2022 21:58:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oe1Xp-00081r-Rr for pgsql-bugs@lists.postgresql.org; Thu, 29 Sep 2022 21:58:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 28TLwBwp467715; Thu, 29 Sep 2022 17:58:11 -0400 From: Tom Lane To: Daniel Gustafsson cc: Jacob Champion , heath.lord@crunchydata.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17625: In PG15 PQsslAttribute returns different values than PG14 when SSL is not in use for the connection In-reply-to: <8F5DD45F-8A0D-4CBE-93B9-844C55886B85@yesql.se> References: <17625-fc47c78b7d71b534@postgresql.org> <346263.1664480998@sss.pgh.pa.us> <360379.1664482591@sss.pgh.pa.us> <395956.1664484332@sss.pgh.pa.us> <398499.1664485687@sss.pgh.pa.us> <8F5DD45F-8A0D-4CBE-93B9-844C55886B85@yesql.se> Comments: In-reply-to Daniel Gustafsson message dated "Thu, 29 Sep 2022 23:37:15 +0200" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <467582.1664488678.0@sss.pgh.pa.us> Date: Thu, 29 Sep 2022 17:58:11 -0400 Message-ID: <467714.1664488691@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <467582.1664488678.1@sss.pgh.pa.us> Daniel Gustafsson writes: >> On 29 Sep 2022, at 23:08, Tom Lane wrote: >> A definition that'd be consistent with what we just agreed to for >> PQsslAttribute is: >> PQsslAttributeNames(NULL): the attributes for the default SSL library, >> or an empty list if there is none. >> PQsslAttributeNames(conn): the attributes for the SSL library in use >> on this connection, or an empty list if not encrypted. > I think that makes sense, it keeps the API consistent. So more or less as attached, then. Since this is mostly about future-proofing, I'd personally be content to put it in HEAD. Is there a case for shoehorning this into v15 at this late date? Consistency with PQsslAttribute would be good, but I'm not sure we want to make this kind of change post-RC1. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="clean-up-PQsslAttributeNames.patch"; charset="us-ascii" Content-ID: <467582.1664488678.2@sss.pgh.pa.us> Content-Description: clean-up-PQsslAttributeNames.patch Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 8908f775df..41864c6cf1 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -2592,12 +2592,22 @@ const char *PQsslAttribute(const PGconn *conn, con= st char *attribute_name); PQsslAttributeNamesPQ= sslAttributeNames - Returns an array of SSL attribute names available. + Returns an array of SSL attribute names that can be used + in PQsslAttribute(). The array is terminated by a NULL pointer. const char * const * PQsslAttributeNames(const PGconn *conn); + + + If conn is NULL, the attributes available for t= he + default SSL library are returned, or an empty list + if libpq was compiled without any SSL + support. If conn is not NULL, the attributes + available for the SSL library in use for the connection are return= ed, + or an empty list if the connection is not encrypted. + = diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/lib= pq/fe-secure-openssl.c index 74b5c5987a..b42a908733 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -1730,7 +1730,7 @@ PQsslStruct(PGconn *conn, const char *struct_name) const char *const * PQsslAttributeNames(PGconn *conn) { - static const char *const result[] =3D { + static const char *const openssl_attrs[] =3D { "library", "key_bits", "cipher", @@ -1738,8 +1738,19 @@ PQsslAttributeNames(PGconn *conn) "protocol", NULL }; + static const char *const empty_attrs[] =3D {NULL}; = - return result; + if (!conn) + { + /* Return attributes of default SSL library */ + return openssl_attrs; + } + + /* No attrs for unencrypted connection */ + if (conn->ssl =3D=3D NULL) + return empty_attrs; + + return openssl_attrs; } = const char * ------- =_aaaaaaaaaa0--