postgresql/src/include/libpq
Michael Paquier 864f80fead Fix handling of SCRAM-SHA-256's channel binding with RSA-PSS certificates
OpenSSL 1.1.1 and newer versions have added support for RSA-PSS
certificates, which requires the use of a specific routine in OpenSSL to
determine which hash function to use when compiling it when using
channel binding in SCRAM-SHA-256.  X509_get_signature_nid(), that is the
original routine the channel binding code has relied on, is not able to
determine which hash algorithm to use for such certificates.  However,
X509_get_signature_info(), new to OpenSSL 1.1.1, is able to do it.  This
commit switches the channel binding logic to rely on
X509_get_signature_info() over X509_get_signature_nid(), which would be
the choice when building with 1.1.1 or newer.

The error could have been triggered on the client or the server, hence
libpq and the backend need to have their related code paths patched.
Note that attempting to load an RSA-PSS certificate with OpenSSL 1.1.0
or older leads to a failure due to an unsupported algorithm.

The discovery of relying on X509_get_signature_info() comes from Jacob,
the tests have been written by Heikki (with few tweaks from me), while I
have bundled the whole together while adding the bits needed for MSVC
and meson.

This issue exists since channel binding exists, so backpatch all the way
down.  Some tests are added in 15~, triggered if compiling with OpenSSL
1.1.1 or newer, where the certificate and key files can easily be
generated for RSA-PSS.

Reported-by: Gunnar "Nick" Bluth
Author: Jacob Champion, Heikki Linnakangas
Discussion: https://postgr.es/m/17760-b6c61e752ec07060@postgresql.org
Backpatch-through: 11
2023-02-15 10:12:33 +09:00
..
auth.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
be-fsstubs.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
be-gssapi-common.h Harden be-gssapi-common.h for headerscheck 2021-11-26 17:00:29 -03:00
crypt.h Revert error handling improvements for cryptohashes 2022-01-14 11:25:39 +09:00
hba.h Make check_usermap() parameter names consistent. 2022-09-17 16:54:14 -07:00
ifaddr.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
libpq-be.h Fix handling of SCRAM-SHA-256's channel binding with RSA-PSS certificates 2023-02-15 10:12:33 +09:00
libpq-fs.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
libpq.h Reject extraneous data after SSL or GSS encryption handshake. 2021-11-08 11:01:43 -05:00
pqcomm.h Remove server and libpq support for old FE/BE protocol version 2. 2021-03-04 10:45:55 +02:00
pqformat.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pqmq.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pqsignal.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
scram.h Revert error handling improvements for cryptohashes 2022-01-14 11:25:39 +09:00