diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2017-04-07 14:56:05 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2017-04-07 14:56:05 +0300 |
commit | 60f11b87a2349985230c08616fa8a34ffde934c8 (patch) | |
tree | fe3eaa86daee5df071c4dfbc1072d89fd86ff37d /src/common/scram-common.c | |
parent | 32e33a7979a10e9fcf2c9b32703838cec1daf674 (diff) | |
download | postgresql-60f11b87a2349985230c08616fa8a34ffde934c8.tar.gz postgresql-60f11b87a2349985230c08616fa8a34ffde934c8.zip |
Use SASLprep to normalize passwords for SCRAM authentication.
An important step of SASLprep normalization, is to convert the string to
Unicode normalization form NFKC. 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.
No documentation changes included, because there is no details on the
SCRAM mechanism in the docs anyway. An overview on that in the protocol
specification would probably be good, even though SCRAM is documented in
detail in RFC5802. I'll write that as a separate patch. An important thing
to mention there is that we apply SASLprep even on invalid UTF-8 strings,
to support other encodings.
Patch by Michael Paquier and me.
Discussion: https://www.postgresql.org/message-id/CAB7nPqSByyEmAVLtEf1KxTRh=PWNKiWKEKQR=e1yGehz=wbymQ@mail.gmail.com
Diffstat (limited to 'src/common/scram-common.c')
-rw-r--r-- | src/common/scram-common.c | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/src/common/scram-common.c b/src/common/scram-common.c index e44f38f6520..df9f0eaa90d 100644 --- a/src/common/scram-common.c +++ b/src/common/scram-common.c @@ -148,28 +148,9 @@ scram_H(const uint8 *input, int len, uint8 *result) } /* - * Encrypt password for SCRAM authentication. This basically applies the - * normalization of the password and a hash calculation using the salt - * value given by caller. - */ -static void -scram_SaltedPassword(const char *password, const char *salt, int saltlen, int iterations, - uint8 *result) -{ - /* - * XXX: Here SASLprep should be applied on password. However, per RFC5802, - * it is required that the password is encoded in UTF-8, something that is - * not guaranteed in this protocol. We may want to revisit this - * normalization function once encoding functions are available as well in - * the frontend in order to be able to encode properly this string, and - * then apply SASLprep on it. - */ - - scram_Hi(password, salt, saltlen, iterations, result); -} - -/* * Calculate ClientKey or ServerKey. + * + * The password should already be normalized by SASLprep. */ void scram_ClientOrServerKey(const char *password, @@ -179,7 +160,7 @@ scram_ClientOrServerKey(const char *password, uint8 keybuf[SCRAM_KEY_LEN]; scram_HMAC_ctx ctx; - scram_SaltedPassword(password, salt, saltlen, iterations, keybuf); + scram_Hi(password, salt, saltlen, iterations, keybuf); scram_HMAC_init(&ctx, keybuf, SCRAM_KEY_LEN); scram_HMAC_update(&ctx, keystr, strlen(keystr)); scram_HMAC_final(result, &ctx); |