diff options
author | Michael Paquier <michael@paquier.xyz> | 2019-01-01 20:05:51 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2019-01-01 20:05:51 +0900 |
commit | 1707a0d2aa6b2bcfe78f63836c769943a1a6b9e0 (patch) | |
tree | 2e4acf6889358493cfda78582d54b8b751c3fbe5 /src/interfaces/libpq/fe-auth-scram.c | |
parent | d880b208e5fcf55e3ae396d5fc5fa6639f58205f (diff) | |
download | postgresql-1707a0d2aa6b2bcfe78f63836c769943a1a6b9e0.tar.gz postgresql-1707a0d2aa6b2bcfe78f63836c769943a1a6b9e0.zip |
Remove configure switch --disable-strong-random
This removes a portion of infrastructure introduced by fe0a0b5 to allow
compilation of Postgres in environments where no strong random source is
available, meaning that there is no linking to OpenSSL and no
/dev/urandom (Windows having its own CryptoAPI). No systems shipped
this century lack /dev/urandom, and the buildfarm is actually not
testing this switch at all, so just remove it. This simplifies
particularly some backend code which included a fallback implementation
using shared memory, and removes a set of alternate regression output
files from pgcrypto.
Author: Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/20181230063219.GG608@paquier.xyz
Diffstat (limited to 'src/interfaces/libpq/fe-auth-scram.c')
-rw-r--r-- | src/interfaces/libpq/fe-auth-scram.c | 62 |
1 files changed, 2 insertions, 60 deletions
diff --git a/src/interfaces/libpq/fe-auth-scram.c b/src/interfaces/libpq/fe-auth-scram.c index 603ef4c0020..6f9e6789d56 100644 --- a/src/interfaces/libpq/fe-auth-scram.c +++ b/src/interfaces/libpq/fe-auth-scram.c @@ -19,11 +19,6 @@ #include "common/scram-common.h" #include "fe-auth.h" -/* These are needed for getpid(), in the fallback implementation */ -#ifndef HAVE_STRONG_RANDOM -#include <sys/types.h> -#include <unistd.h> -#endif /* * Status of exchange messages used for SCRAM authentication via the @@ -72,7 +67,6 @@ static bool verify_server_signature(fe_scram_state *state); static void calculate_client_proof(fe_scram_state *state, const char *client_final_message_without_proof, uint8 *result); -static bool pg_frontend_random(char *dst, int len); /* * Initialize SCRAM exchange status. @@ -320,7 +314,7 @@ build_client_first_message(fe_scram_state *state) * Generate a "raw" nonce. This is converted to ASCII-printable form by * base64-encoding it. */ - if (!pg_frontend_random(raw_nonce, SCRAM_RAW_NONCE_LEN)) + if (!pg_strong_random(raw_nonce, SCRAM_RAW_NONCE_LEN)) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not generate nonce\n")); @@ -764,7 +758,7 @@ pg_fe_scram_build_verifier(const char *password) password = (const char *) prep_password; /* Generate a random salt */ - if (!pg_frontend_random(saltbuf, SCRAM_DEFAULT_SALT_LEN)) + if (!pg_strong_random(saltbuf, SCRAM_DEFAULT_SALT_LEN)) { if (prep_password) free(prep_password); @@ -779,55 +773,3 @@ pg_fe_scram_build_verifier(const char *password) return result; } - -/* - * Random number generator. - */ -static bool -pg_frontend_random(char *dst, int len) -{ -#ifdef HAVE_STRONG_RANDOM - return pg_strong_random(dst, len); -#else - int i; - char *end = dst + len; - - static unsigned short seed[3]; - static int mypid = 0; - - pglock_thread(); - - if (mypid != getpid()) - { - struct timeval now; - - gettimeofday(&now, NULL); - - seed[0] = now.tv_sec ^ getpid(); - seed[1] = (unsigned short) (now.tv_usec); - seed[2] = (unsigned short) (now.tv_usec >> 16); - } - - for (i = 0; dst < end; i++) - { - uint32 r; - int j; - - /* - * pg_jrand48 returns a 32-bit integer. Fill the next 4 bytes from - * it. - */ - r = (uint32) pg_jrand48(seed); - - for (j = 0; j < 4 && dst < end; j++) - { - *(dst++) = (char) (r & 0xFF); - r >>= 8; - } - } - - pgunlock_thread(); - - return true; -#endif -} |