Commit e6e9c4da authored by Heikki Linnakangas's avatar Heikki Linnakangas

Misc cleanup of SCRAM code.

* Remove is_scram_verifier() function. It was unused.
* Fix sanitize_char() function, used in error messages on protocol
  violations, to print bytes >= 0x7F correctly.
* Change spelling of scram_MockSalt() function to be more consistent with
  the surroundings.
* Change a few more references to "server proof" to "server signature" that
  I missed in commit d981074c.
parent 344a1130
...@@ -153,7 +153,7 @@ static void mock_scram_verifier(const char *username, int *iterations, ...@@ -153,7 +153,7 @@ static void mock_scram_verifier(const char *username, int *iterations,
char **salt, uint8 *stored_key, uint8 *server_key); char **salt, uint8 *stored_key, uint8 *server_key);
static bool is_scram_printable(char *p); static bool is_scram_printable(char *p);
static char *sanitize_char(char c); static char *sanitize_char(char c);
static char *scram_MockSalt(const char *username); static char *scram_mock_salt(const char *username);
/* /*
* pg_be_scram_init * pg_be_scram_init
...@@ -480,28 +480,6 @@ scram_verify_plain_password(const char *username, const char *password, ...@@ -480,28 +480,6 @@ scram_verify_plain_password(const char *username, const char *password,
return memcmp(computed_key, server_key, SCRAM_KEY_LEN) == 0; return memcmp(computed_key, server_key, SCRAM_KEY_LEN) == 0;
} }
/*
* Check if given verifier can be used for SCRAM authentication.
*
* Returns true if it is a SCRAM verifier, and false otherwise.
*/
bool
is_scram_verifier(const char *verifier)
{
int iterations;
char *salt = NULL;
uint8 stored_key[SCRAM_KEY_LEN];
uint8 server_key[SCRAM_KEY_LEN];
bool result;
result = parse_scram_verifier(verifier, &iterations, &salt,
stored_key, server_key);
if (salt)
pfree(salt);
return result;
}
/* /*
* Parse and validate format of given SCRAM verifier. * Parse and validate format of given SCRAM verifier.
...@@ -592,7 +570,7 @@ mock_scram_verifier(const char *username, int *iterations, char **salt, ...@@ -592,7 +570,7 @@ mock_scram_verifier(const char *username, int *iterations, char **salt,
int encoded_len; int encoded_len;
/* Generate deterministic salt */ /* Generate deterministic salt */
raw_salt = scram_MockSalt(username); raw_salt = scram_mock_salt(username);
encoded_salt = (char *) palloc(pg_b64_enc_len(SCRAM_DEFAULT_SALT_LEN) + 1); encoded_salt = (char *) palloc(pg_b64_enc_len(SCRAM_DEFAULT_SALT_LEN) + 1);
encoded_len = pg_b64_encode(raw_salt, SCRAM_DEFAULT_SALT_LEN, encoded_salt); encoded_len = pg_b64_encode(raw_salt, SCRAM_DEFAULT_SALT_LEN, encoded_salt);
...@@ -679,7 +657,7 @@ sanitize_char(char c) ...@@ -679,7 +657,7 @@ sanitize_char(char c)
if (c >= 0x21 && c <= 0x7E) if (c >= 0x21 && c <= 0x7E)
snprintf(buf, sizeof(buf), "'%c'", c); snprintf(buf, sizeof(buf), "'%c'", c);
else else
snprintf(buf, sizeof(buf), "0x%02x", c); snprintf(buf, sizeof(buf), "0x%02x", (unsigned char) c);
return buf; return buf;
} }
...@@ -1146,7 +1124,7 @@ build_server_final_message(scram_state *state) ...@@ -1146,7 +1124,7 @@ build_server_final_message(scram_state *state)
* pointer to a static buffer of size SCRAM_DEFAULT_SALT_LEN. * pointer to a static buffer of size SCRAM_DEFAULT_SALT_LEN.
*/ */
static char * static char *
scram_MockSalt(const char *username) scram_mock_salt(const char *username)
{ {
pg_sha256_ctx ctx; pg_sha256_ctx ctx;
static uint8 sha_digest[PG_SHA256_DIGEST_LENGTH]; static uint8 sha_digest[PG_SHA256_DIGEST_LENGTH];
......
...@@ -28,7 +28,6 @@ extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen, ...@@ -28,7 +28,6 @@ extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen,
/* Routines to handle and check SCRAM-SHA-256 verifier */ /* Routines to handle and check SCRAM-SHA-256 verifier */
extern char *pg_be_scram_build_verifier(const char *password); extern char *pg_be_scram_build_verifier(const char *password);
extern bool is_scram_verifier(const char *verifier);
extern bool scram_verify_plain_password(const char *username, extern bool scram_verify_plain_password(const char *username,
const char *password, const char *verifier); const char *password, const char *verifier);
......
...@@ -212,7 +212,7 @@ pg_fe_scram_exchange(void *opaq, char *input, int inputlen, ...@@ -212,7 +212,7 @@ pg_fe_scram_exchange(void *opaq, char *input, int inputlen,
break; break;
case FE_SCRAM_PROOF_SENT: case FE_SCRAM_PROOF_SENT:
/* Receive server proof */ /* Receive server signature */
if (!read_server_final_message(state, input, errorMessage)) if (!read_server_final_message(state, input, errorMessage))
goto error; goto error;
...@@ -228,7 +228,7 @@ pg_fe_scram_exchange(void *opaq, char *input, int inputlen, ...@@ -228,7 +228,7 @@ pg_fe_scram_exchange(void *opaq, char *input, int inputlen,
{ {
*success = false; *success = false;
printfPQExpBuffer(errorMessage, printfPQExpBuffer(errorMessage,
libpq_gettext("invalid server proof\n")); libpq_gettext("invalid server signature\n"));
} }
*done = true; *done = true;
state->state = FE_SCRAM_FINISHED; state->state = FE_SCRAM_FINISHED;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment