26 const char *sasl_mechanism);
90 const char *client_final_message_without_proof,
99 const char *sasl_mechanism)
117 if (!
state->sasl_mechanism)
192 free(
state->client_final_message_without_proof);
238 switch (
state->state)
286 state->conn->client_finished_auth =
true;
310 char *begin = *
input;
316 "malformed SCRAM message (attribute \"%c\" expected)",
325 "malformed SCRAM message (expected character \"=\" for attribute \"%c\")",
332 while (*end && *end !=
',')
435 if (!
state->client_first_message_bare)
525 "could not encode cbind data for channel binding\n");
540 "channel binding not supported by this build\n");
560 if (
state->client_final_message_without_proof ==
NULL)
565 state->client_final_message_without_proof,
664 if (
state->saltlen < 0)
677 if (*endptr !=
'\0' ||
state->iterations < 1)
701 if (!
state->server_final_message)
767 const char *client_final_message_without_proof,
783 if (
state->conn->scram_client_key_binary)
822 (
const uint8 *) client_final_message_without_proof,
823 strlen(client_final_message_without_proof)) < 0 ||
831 for (
i = 0;
i <
state->key_length;
i++)
860 if (
state->conn->scram_server_key_binary)
886 (
uint8 *)
state->client_final_message_without_proof,
887 strlen(
state->client_final_message_without_proof)) < 0 ||
889 state->key_length) < 0)
900 state->key_length) != 0)
int pg_b64_enc_len(int srclen)
int pg_b64_encode(const uint8 *src, int len, char *dst, int dstlen)
int pg_b64_dec_len(int srclen)
int pg_b64_decode(const char *src, int len, uint8 *dst, int dstlen)
#define Assert(condition)
int errmsg(const char *fmt,...)
static char * build_client_first_message(fe_scram_state *state)
const pg_fe_sasl_mech pg_scram_mech
static bool verify_server_signature(fe_scram_state *state, bool *match, const char **errstr)
static void * scram_init(PGconn *conn, const char *password, const char *sasl_mechanism)
static char * read_attr_value(char **input, char attr, PQExpBuffer errorMessage)
static void scram_free(void *opaq)
static bool read_server_first_message(fe_scram_state *state, char *input)
static bool scram_channel_bound(void *opaq)
char * pg_fe_scram_build_secret(const char *password, int iterations, const char **errstr)
static bool calculate_client_proof(fe_scram_state *state, const char *client_final_message_without_proof, uint8 *result, const char **errstr)
static SASLStatus scram_exchange(void *opaq, bool final, char *input, int inputlen, char **output, int *outputlen)
static char * build_client_final_message(fe_scram_state *state)
static bool read_server_final_message(fe_scram_state *state, char *input)
void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...)
char * pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)
pg_hmac_ctx * pg_hmac_create(pg_cryptohash_type type)
void pg_hmac_free(pg_hmac_ctx *ctx)
const char * pg_hmac_error(pg_hmac_ctx *ctx)
int pg_hmac_update(pg_hmac_ctx *ctx, const uint8 *data, size_t len)
int pg_hmac_init(pg_hmac_ctx *ctx, const uint8 *key, size_t len)
int pg_hmac_final(pg_hmac_ctx *ctx, uint8 *dest, size_t len)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
static char buf[DEFAULT_XLOG_SEG_SIZE]
bool pg_strong_random(void *buf, size_t len)
void initPQExpBuffer(PQExpBuffer str)
int enlargePQExpBuffer(PQExpBuffer str, size_t needed)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferDataBroken(buf)
pg_saslprep_rc pg_saslprep(const char *input, char **output)
int scram_ServerKey(const uint8 *salted_password, pg_cryptohash_type hash_type, int key_length, uint8 *result, const char **errstr)
int scram_SaltedPassword(const char *password, pg_cryptohash_type hash_type, int key_length, const uint8 *salt, int saltlen, int iterations, uint8 *result, const char **errstr)
char * scram_build_secret(pg_cryptohash_type hash_type, int key_length, const uint8 *salt, int saltlen, int iterations, const char *password, const char **errstr)
int scram_ClientKey(const uint8 *salted_password, pg_cryptohash_type hash_type, int key_length, uint8 *result, const char **errstr)
int scram_H(const uint8 *input, pg_cryptohash_type hash_type, int key_length, uint8 *result, const char **errstr)
#define SCRAM_SHA_256_PLUS_NAME
#define SCRAM_RAW_NONCE_LEN
#define SCRAM_DEFAULT_SALT_LEN
#define SCRAM_MAX_KEY_LEN
#define SCRAM_SHA_256_KEY_LEN
char * client_final_message_without_proof
fe_scram_state_enum state
char * client_first_message_bare
char * server_final_message
char * server_first_message
pg_cryptohash_type hash_type
PQExpBufferData errorMessage