Use SASLprep to normalize passwords for SCRAM authentication. saslprep
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 7 Apr 2017 11:27:02 +0000 (14:27 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 7 Apr 2017 11:27:02 +0000 (14:27 +0300)
commit5ba20866e593bb03c7915997188b0d12f4614873
treefe3eaa86daee5df071c4dfbc1072d89fd86ff37d
parent32e33a7979a10e9fcf2c9b32703838cec1daf674
Use SASLprep to normalize passwords for SCRAM authentication.

SASLprep works on UTF-8, but we try to apply the SASLprep normalization
even when the password is not in UTF-8 encoding. That may seem odd, but
the encoding used during authentication isn't well-defined, so by always
applying the normalization, we don't rely on client locale settings, which
might well be wrong. If the input cannot be processed as UTF-8, we skip
the normalization. (That is contrary to the spec, but we need to somehow
deal with other encodings, while the spec just dictates UTF-8.)

An important step of SASLprep normalization, is to convert the string to
Unicode normalization form NFKC. The Unicode normalization requires a
fairly large table of character decompositions, which is generated from
data published by the Unicode consortium. The script to generate the table
is put in src/common/unicode, as well test code for the normalization.
A pre-generated version of the tables is included in src/include/common,
so you don't need the code in src/common/unicode to build PostgreSQL, only
if you wish to modify the normalization tables.

The SASLprep implementation depends on the UTF-8 functions from
src/backend/utils/mb/wchar.c. So to use it, you must also compile and link
that. That doesn't change anything for the current users of these
functions, the backend and libpq, as they both already link with wchar.o.
It would be good to move those functions into a separate file in
src/commmon, but I'll leave that for another day.

Patch by Michael Paquier and me.

Discussion: https://www.postgresql.org/message-id/CAB7nPqSByyEmAVLtEf1KxTRh=PWNKiWKEKQR=e1yGehz=wbymQ@mail.gmail.com
19 files changed:
src/backend/libpq/auth-scram.c
src/common/Makefile
src/common/saslprep.c [new file with mode: 0644]
src/common/scram-common.c
src/common/unicode/.gitignore [new file with mode: 0644]
src/common/unicode/Makefile [new file with mode: 0644]
src/common/unicode/README [new file with mode: 0644]
src/common/unicode/generate-norm_test_table.pl [new file with mode: 0644]
src/common/unicode/generate-unicode_norm_table.pl [new file with mode: 0644]
src/common/unicode/norm_test.c [new file with mode: 0644]
src/common/unicode_norm.c [new file with mode: 0644]
src/include/common/saslprep.h [new file with mode: 0644]
src/include/common/unicode_norm.h [new file with mode: 0644]
src/include/common/unicode_norm_table.h [new file with mode: 0644]
src/interfaces/libpq/.gitignore
src/interfaces/libpq/Makefile
src/interfaces/libpq/fe-auth-scram.c
src/test/authentication/t/002_saslprep.pl [new file with mode: 0644]
src/tools/msvc/Mkvcbuild.pm