pgsql: Fix detection of passwords hashed with MD5 or SCRAM-SHA-256 - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Fix detection of passwords hashed with MD5 or SCRAM-SHA-256
Date
Msg-id E1hIpD6-0002uW-TL@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix detection of passwords hashed with MD5 or SCRAM-SHA-256

This commit fixes a couple of issues related to the way password
verifiers hashed with MD5 or SCRAM-SHA-256 are detected, leading to
being able to store in catalogs passwords which do not follow the
supported hash formats:
- A MD5-hashed entry was checked based on if its header uses "md5" and
if the string length matches what is expected.  Unfortunately the code
never checked if the hash only used hexadecimal characters, as reported
by Tom Lane.
- A SCRAM-hashed entry was checked based on only its header, which
should be "SCRAM-SHA-256$", but it never checked for any fields
afterwards, as reported by Jonathan Katz.

Backpatch down to v10, which is where SCRAM has been introduced, and
where password verifiers in plain format have been removed.

Author: Jonathan Katz
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/016deb6b-1f0a-8e9f-1833-a8675b170aa9@postgresql.org
Backpatch-through: 10

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/15fe91e70ec69ecffad9f250f8e96f3823147195

Modified Files
--------------
src/backend/libpq/auth-scram.c         |  4 +---
src/backend/libpq/crypt.c              | 13 +++++++++++--
src/include/common/md5.h               |  1 +
src/include/libpq/scram.h              |  2 ++
src/test/regress/expected/password.out | 17 ++++++++++++++++-
src/test/regress/sql/password.sql      | 13 +++++++++++++
6 files changed, 44 insertions(+), 6 deletions(-)


pgsql-committers by date:

Previous
From: Andres Freund
Date:
Subject: pgsql: Convert gist to compute page level xid horizon on primary.
Next
From: Laurenz Albe
Date:
Subject: Re: pgsql: Allow insert and update tuple routing and COPY forforeign table