pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve error handling of HMAC computations
Date: Thu, 13 Jan 2022 07:18:58 +0000
Message-ID: <E1n7uNu-0007vO-Vy@gemulon.postgresql.org> (raw)

Improve error handling of HMAC computations

This is similar to b69aba7, except that this completes the work for
HMAC with a new routine called pg_hmac_error() that would provide more
context about the type of error that happened during a HMAC computation:
- The fallback HMAC implementation in hmac.c relies on cryptohashes, so
in some code paths it is necessary to return back the error generated by
cryptohashes.
- For the OpenSSL implementation (hmac_openssl.c), the logic is very
similar to cryptohash_openssl.c, where the error context comes from
OpenSSL if one of its internal routines failed, with different error
codes if something internal to hmac_openssl.c failed or was incorrect.

Any in-core code paths that use the centralized HMAC interface are
related to SCRAM, for errors that are unlikely going to happen, with
only SHA-256.  It would be possible to see errors when computing some
HMACs with MD5 for example and OpenSSL FIPS enabled, and this commit
would help in reporting the correct errors but nothing in core uses
that.  So, at the end, no backpatch to v14 is done, at least for now.

Errors in SCRAM related to the computation of the server key, stored
key, etc. need to pass down the potential error context string across
more layers of their respective call stacks for the frontend and the
backend, so each surrounding routine is adapted for this purpose.

Reviewed-by: Sergey Shinderuk
Discussion: https://postgr.es/m/Yd0N9tSAIIkFd+qi@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5513dc6a304d8bda114004a3b906cc6fde5d6274

Modified Files
--------------
src/backend/libpq/auth-scram.c       | 22 +++++----
src/common/hmac.c                    | 64 +++++++++++++++++++++++++
src/common/hmac_openssl.c            | 90 ++++++++++++++++++++++++++++++++++++
src/common/scram-common.c            | 68 ++++++++++++++++++++-------
src/include/common/hmac.h            |  1 +
src/include/common/scram-common.h    | 14 ++++--
src/interfaces/libpq/fe-auth-scram.c | 76 ++++++++++++++++++++++--------
src/interfaces/libpq/fe-auth.c       | 10 ++--
src/interfaces/libpq/fe-auth.h       |  3 +-
src/tools/pgindent/typedefs.list     |  1 +
10 files changed, 294 insertions(+), 55 deletions(-)



Message-ID: <E1n7uNu-0007vO-Vy@gemulon.postgresql.org>
Permalink:  ../E1n7uNu-0007vO-Vy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1n7uNu-0007vO-Vy@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Improve error handling of HMAC computations
  In-Reply-To: <E1n7uNu-0007vO-Vy@gemulon.postgresql.org>
  References: <E1n7uNu-0007vO-Vy@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox