postgresql/src/common
Michael Paquier 3d10ece612 Make implementation of SASLprep compliant for ASCII characters
This commit makes our implementation of SASLprep() compliant with RFC
3454 (Stringprep) and RFC 4013 (SASLprep).  Originally, as introduced in
60f11b87a2, the operation considered a password made of only ASCII
characters as valid, performing an optimization for this case to skip
the internal NFKC transformation.

However, the RFCs listed above use a different definition, with the
following characters being prohibited:
- 0x00~0x1F (0~31), control characters.
- 0x7F (127, DEL).

In its SCRAM protocol, Postgres has the idea to apply a password as-is
if SASLprep() is not a success, so this change is safe on
backward-compatibility grounds:
- A libpq client with the compliant SASLprep can connect to a server
with a non-compliant SASLprep.
- A libpq client with the non-compliant SASLprep can connect to a server
with a compliant SASLprep.

This commit removes the all-ASCII optimization used in pg_saslprep() and
applies SASLprep even if a password is made only of ASCII characters,
making the operation compatible with the RFC.  All the in-core callers
of pg_saslprep() do that:
- pg_be_scram_build_secret() in auth-scram.c, when generating a
SCRAM verifier for rolpassword in the backend.
- scram_init() in fe-auth-scram.c, when starting the SASL exchange.
- pg_fe_scram_build_secret() in fe-auth-scram.c, when generating a SCRAM
verifier for the frontend with libpq, to generate it for a ALTER/CREATE
ROLE command for example.

The test module test_saslprep shows the difference this change is
leading to.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Discussion: https://postgr.es/m/aaEJ-El2seZHeFcG@paquier.xyz
2026-03-24 08:29:23 +09:00
..
unicode Update Unicode data to Unicode 17.0.0 2026-03-20 08:42:50 +01:00
.gitignore Replace the data structure used for keyword lookup. 2019-01-06 17:02:57 -05:00
archive.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
base64.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
binaryheap.c Remove #include <math.h> where not needed 2026-01-15 19:09:47 +01:00
blkreftable.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
checksum_helper.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
compression.c Move tar detection and compression logic to common. 2026-03-20 15:31:35 -04:00
config_info.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
controldata_utils.c Don't include wait_event.h in pgstat.h 2026-03-06 16:24:58 +01:00
cryptohash.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
cryptohash_openssl.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
d2s.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
d2s_full_table.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
d2s_intrinsics.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
digit_table.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
encnames.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
exec.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
f2s.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
fe_memutils.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
file_perm.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
file_utils.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
hashfn.c Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00
hmac.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
hmac_openssl.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
ip.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
jsonapi.c Fix some -Wcast-qual warnings 2026-02-27 21:57:33 +01:00
keywords.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
kwlookup.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
link-canary.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
logging.c Revert "Replace pg_restrict by standard restrict" 2026-01-14 15:12:25 +01:00
Makefile Don't put library-supplied -L/-I switches before user-supplied ones. 2025-07-29 15:17:40 -04:00
md5.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
md5_common.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
md5_int.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
meson.build meson: allow disabling building/installation of static libraries. 2026-02-23 16:45:40 +01:00
parse_manifest.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
percentrepl.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_get_line.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_lzcompress.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_prng.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgfnames.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
psprintf.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
relpath.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
restricted_token.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
rmtree.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
ryu_common.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
saslprep.c Make implementation of SASLprep compliant for ASCII characters 2026-03-24 08:29:23 +09:00
scram-common.c Fix accidentally cast away qualifiers 2026-01-26 16:02:31 +01:00
sha1.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
sha1_int.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
sha2.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
sha2_int.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
sprompt.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
string.c Revert "Replace pg_restrict by standard restrict" 2026-01-14 15:12:25 +01:00
stringinfo.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
unicode_case.c Fix accidentally cast away qualifiers 2026-01-26 16:02:31 +01:00
unicode_category.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
unicode_norm.c Fix misc typos, mostly in comments 2026-01-08 18:10:08 +02:00
username.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
wait_error.c Update copyright for 2026 2026-01-01 13:24:10 -05:00
wchar.c Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00