diff options
| author | Daniel Gustafsson | 2023-03-27 07:46:29 +0000 |
|---|---|---|
| committer | Daniel Gustafsson | 2023-03-27 07:46:29 +0000 |
| commit | b577743000cd0974052af3a71770a23760423102 (patch) | |
| tree | 29ae4bb91ea49a0b6671df31caebb8bec47186a7 /src/include | |
| parent | c15631f0f596b2e6c4b03f24c03289d06d008783 (diff) | |
Make SCRAM iteration count configurable
Replace the hardcoded value with a GUC such that the iteration
count can be raised in order to increase protection against
brute-force attacks. The hardcoded value for SCRAM iteration
count was defined to be 4096, which is taken from RFC 7677, so
set the default for the GUC to 4096 to match. In RFC 7677 the
recommendation is at least 15000 iterations but 4096 is listed
as a SHOULD requirement given that it's estimated to yield a
0.5s processing time on a mobile handset of the time of RFC
writing (late 2015).
Raising the iteration count of SCRAM will make stored passwords
more resilient to brute-force attacks at a higher computational
cost during connection establishment. Lowering the count will
reduce computational overhead during connections at the tradeoff
of reducing strength against brute-force attacks.
There are however platforms where even a modest iteration count
yields a too high computational overhead, with weaker password
encryption schemes chosen as a result. In these situations,
SCRAM with a very low iteration count still gives benefits over
weaker schemes like md5, so we allow the iteration count to be
set to one at the low end.
The new GUC is intentionally generically named such that it can
be made to support future SCRAM standards should they emerge.
At that point the value can be made into key:value pairs with
an undefined key as a default which will be backwards compatible
with this.
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Jonathan S. Katz <jkatz@postgresql.org>
Discussion: https://postgr.es/m/F72E7BC7-189F-4B17-BF47-9735EB72C364@yesql.se
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/common/scram-common.h | 2 | ||||
| -rw-r--r-- | src/include/libpq/scram.h | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/include/common/scram-common.h b/src/include/common/scram-common.h index 0c75df5559..5ccff96ece 100644 --- a/src/include/common/scram-common.h +++ b/src/include/common/scram-common.h @@ -47,7 +47,7 @@ * Default number of iterations when generating secret. Should be at least * 4096 per RFC 7677. */ -#define SCRAM_DEFAULT_ITERATIONS 4096 +#define SCRAM_SHA_256_DEFAULT_ITERATIONS 4096 extern int scram_SaltedPassword(const char *password, pg_cryptohash_type hash_type, int key_length, diff --git a/src/include/libpq/scram.h b/src/include/libpq/scram.h index b275e1e87e..310bc36517 100644 --- a/src/include/libpq/scram.h +++ b/src/include/libpq/scram.h @@ -18,6 +18,9 @@ #include "libpq/libpq-be.h" #include "libpq/sasl.h" +/* Number of iterations when generating new secrets */ +extern PGDLLIMPORT int scram_sha_256_iterations; + /* SASL implementation callbacks */ extern PGDLLIMPORT const pg_be_sasl_mech pg_be_scram_mech; |
