Skip to content

Commit e6e9c4d

Browse files
committed
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 d981074.
1 parent 344a113 commit e6e9c4d

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

src/backend/libpq/auth-scram.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static void mock_scram_verifier(const char *username, int *iterations,
153153
char **salt, uint8 *stored_key, uint8 *server_key);
154154
static bool is_scram_printable(char *p);
155155
static char *sanitize_char(char c);
156-
static char *scram_MockSalt(const char *username);
156+
static char *scram_mock_salt(const char *username);
157157

158158
/*
159159
* pg_be_scram_init
@@ -480,28 +480,6 @@ scram_verify_plain_password(const char *username, const char *password,
480480
return memcmp(computed_key, server_key, SCRAM_KEY_LEN) == 0;
481481
}
482482

483-
/*
484-
* Check if given verifier can be used for SCRAM authentication.
485-
*
486-
* Returns true if it is a SCRAM verifier, and false otherwise.
487-
*/
488-
bool
489-
is_scram_verifier(const char *verifier)
490-
{
491-
int iterations;
492-
char *salt = NULL;
493-
uint8 stored_key[SCRAM_KEY_LEN];
494-
uint8 server_key[SCRAM_KEY_LEN];
495-
bool result;
496-
497-
result = parse_scram_verifier(verifier, &iterations, &salt,
498-
stored_key, server_key);
499-
if (salt)
500-
pfree(salt);
501-
502-
return result;
503-
}
504-
505483

506484
/*
507485
* Parse and validate format of given SCRAM verifier.
@@ -592,7 +570,7 @@ mock_scram_verifier(const char *username, int *iterations, char **salt,
592570
int encoded_len;
593571

594572
/* Generate deterministic salt */
595-
raw_salt = scram_MockSalt(username);
573+
raw_salt = scram_mock_salt(username);
596574

597575
encoded_salt = (char *) palloc(pg_b64_enc_len(SCRAM_DEFAULT_SALT_LEN) + 1);
598576
encoded_len = pg_b64_encode(raw_salt, SCRAM_DEFAULT_SALT_LEN, encoded_salt);
@@ -679,7 +657,7 @@ sanitize_char(char c)
679657
if (c >= 0x21 && c <= 0x7E)
680658
snprintf(buf, sizeof(buf), "'%c'", c);
681659
else
682-
snprintf(buf, sizeof(buf), "0x%02x", c);
660+
snprintf(buf, sizeof(buf), "0x%02x", (unsigned char) c);
683661
return buf;
684662
}
685663

@@ -1146,7 +1124,7 @@ build_server_final_message(scram_state *state)
11461124
* pointer to a static buffer of size SCRAM_DEFAULT_SALT_LEN.
11471125
*/
11481126
static char *
1149-
scram_MockSalt(const char *username)
1127+
scram_mock_salt(const char *username)
11501128
{
11511129
pg_sha256_ctx ctx;
11521130
static uint8 sha_digest[PG_SHA256_DIGEST_LENGTH];

src/include/libpq/scram.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen,
2828

2929
/* Routines to handle and check SCRAM-SHA-256 verifier */
3030
extern char *pg_be_scram_build_verifier(const char *password);
31-
extern bool is_scram_verifier(const char *verifier);
3231
extern bool scram_verify_plain_password(const char *username,
3332
const char *password, const char *verifier);
3433

src/interfaces/libpq/fe-auth-scram.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pg_fe_scram_exchange(void *opaq, char *input, int inputlen,
212212
break;
213213

214214
case FE_SCRAM_PROOF_SENT:
215-
/* Receive server proof */
215+
/* Receive server signature */
216216
if (!read_server_final_message(state, input, errorMessage))
217217
goto error;
218218

@@ -228,7 +228,7 @@ pg_fe_scram_exchange(void *opaq, char *input, int inputlen,
228228
{
229229
*success = false;
230230
printfPQExpBuffer(errorMessage,
231-
libpq_gettext("invalid server proof\n"));
231+
libpq_gettext("invalid server signature\n"));
232232
}
233233
*done = true;
234234
state->state = FE_SCRAM_FINISHED;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy