Commit 85f4d639 authored by Peter Eisentraut's avatar Peter Eisentraut

Tweak some SCRAM error messages and code comments

Clarify/correct some error messages, fix up some code comments that
confused SASL and SCRAM, and other minor fixes.  No changes in
functionality.
parent 580ddcec
...@@ -1405,13 +1405,13 @@ ErrorMessage. ...@@ -1405,13 +1405,13 @@ ErrorMessage.
</para> </para>
<para> <para>
When SCRAM-SHA-256 is used in PostgreSQL, the server will ignore the username When SCRAM-SHA-256 is used in PostgreSQL, the server will ignore the user name
that the client sends in the <structname>client-first-message</>. The username that the client sends in the <structname>client-first-message</>. The user name
that was already sent in the startup message is used instead. that was already sent in the startup message is used instead.
<productname>PostgreSQL</> supports multiple character encodings, while SCRAM <productname>PostgreSQL</> supports multiple character encodings, while SCRAM
dictates UTF-8 to be used for the username, so it might be impossible to dictates UTF-8 to be used for the user name, so it might be impossible to
represent the PostgreSQL username in UTF-8. To avoid confusion, the client represent the PostgreSQL user name in UTF-8. To avoid confusion, the client
should use <literal>pg_same_as_startup_message</literal> as the username in the should use <literal>pg_same_as_startup_message</literal> as the user name in the
<structname>client-first-message</>. <structname>client-first-message</>.
</para> </para>
...@@ -5274,7 +5274,7 @@ RowDescription (B) ...@@ -5274,7 +5274,7 @@ RowDescription (B)
<varlistentry> <varlistentry>
<term> <term>
SASLInitialresponse (F) SASLInitialResponse (F)
</term> </term>
<listitem> <listitem>
<para> <para>
......
...@@ -573,7 +573,7 @@ mock_scram_verifier(const char *username, int *iterations, char **salt, ...@@ -573,7 +573,7 @@ mock_scram_verifier(const char *username, int *iterations, char **salt,
} }
/* /*
* Read the value in a given SASL exchange message for given attribute. * Read the value in a given SCRAM exchange message for given attribute.
*/ */
static char * static char *
read_attr_value(char **input, char attr) read_attr_value(char **input, char attr)
...@@ -585,7 +585,7 @@ read_attr_value(char **input, char attr) ...@@ -585,7 +585,7 @@ read_attr_value(char **input, char attr)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("malformed SCRAM message"), errmsg("malformed SCRAM message"),
errdetail("Expected attribute '%c' but found %s.", errdetail("Expected attribute \"%c\" but found \"%s\".",
attr, sanitize_char(*begin)))); attr, sanitize_char(*begin))));
begin++; begin++;
...@@ -593,7 +593,7 @@ read_attr_value(char **input, char attr) ...@@ -593,7 +593,7 @@ read_attr_value(char **input, char attr)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("malformed SCRAM message"), errmsg("malformed SCRAM message"),
errdetail("Expected character = for attribute %c.", attr))); errdetail("Expected character \"=\" for attribute \"%c\".", attr)));
begin++; begin++;
end = begin; end = begin;
...@@ -652,7 +652,7 @@ sanitize_char(char c) ...@@ -652,7 +652,7 @@ sanitize_char(char c)
} }
/* /*
* Read the next attribute and value in a SASL exchange message. * Read the next attribute and value in a SCRAM exchange message.
* *
* Returns NULL if there is attribute. * Returns NULL if there is attribute.
*/ */
...@@ -674,7 +674,7 @@ read_any_attr(char **input, char *attr_p) ...@@ -674,7 +674,7 @@ read_any_attr(char **input, char *attr_p)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("malformed SCRAM message"), errmsg("malformed SCRAM message"),
errdetail("Attribute expected, but found invalid character %s.", errdetail("Attribute expected, but found invalid character \"%s\".",
sanitize_char(attr)))); sanitize_char(attr))));
if (attr_p) if (attr_p)
*attr_p = attr; *attr_p = attr;
...@@ -684,7 +684,7 @@ read_any_attr(char **input, char *attr_p) ...@@ -684,7 +684,7 @@ read_any_attr(char **input, char *attr_p)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("malformed SCRAM message"), errmsg("malformed SCRAM message"),
errdetail("Expected character = for attribute %c.", attr))); errdetail("Expected character \"=\" for attribute \"%c\".", attr)));
begin++; begin++;
end = begin; end = begin;
...@@ -703,7 +703,7 @@ read_any_attr(char **input, char *attr_p) ...@@ -703,7 +703,7 @@ read_any_attr(char **input, char *attr_p)
} }
/* /*
* Read and parse the first message from client in the context of a SASL * Read and parse the first message from client in the context of a SCRAM
* authentication exchange message. * authentication exchange message.
* *
* At this stage, any errors will be reported directly with ereport(ERROR). * At this stage, any errors will be reported directly with ereport(ERROR).
...@@ -802,14 +802,14 @@ read_client_first_message(scram_state *state, char *input) ...@@ -802,14 +802,14 @@ read_client_first_message(scram_state *state, char *input)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("malformed SCRAM message"), errmsg("malformed SCRAM message"),
errdetail("Unexpected channel-binding flag %s.", errdetail("Unexpected channel-binding flag \"%s\".",
sanitize_char(*input)))); sanitize_char(*input))));
} }
if (*input != ',') if (*input != ',')
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("malformed SCRAM message"), errmsg("malformed SCRAM message"),
errdetail("Comma expected, but found character %s.", errdetail("Comma expected, but found character \"%s\".",
sanitize_char(*input)))); sanitize_char(*input))));
input++; input++;
...@@ -824,7 +824,7 @@ read_client_first_message(scram_state *state, char *input) ...@@ -824,7 +824,7 @@ read_client_first_message(scram_state *state, char *input)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION), (errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("malformed SCRAM message"), errmsg("malformed SCRAM message"),
errdetail("Unexpected attribute %s in client-first-message.", errdetail("Unexpected attribute \"%s\" in client-first-message.",
sanitize_char(*input)))); sanitize_char(*input))));
input++; input++;
...@@ -929,7 +929,7 @@ verify_client_proof(scram_state *state) ...@@ -929,7 +929,7 @@ verify_client_proof(scram_state *state)
} }
/* /*
* Build the first server-side message sent to the client in a SASL * Build the first server-side message sent to the client in a SCRAM
* communication exchange. * communication exchange.
*/ */
static char * static char *
......
...@@ -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 signature\n")); libpq_gettext("incorrect server signature\n"));
} }
*done = true; *done = true;
state->state = FE_SCRAM_FINISHED; state->state = FE_SCRAM_FINISHED;
...@@ -249,7 +249,7 @@ error: ...@@ -249,7 +249,7 @@ error:
} }
/* /*
* Read value for an attribute part of a SASL message. * Read value for an attribute part of a SCRAM message.
*/ */
static char * static char *
read_attr_value(char **input, char attr, PQExpBuffer errorMessage) read_attr_value(char **input, char attr, PQExpBuffer errorMessage)
...@@ -260,7 +260,7 @@ read_attr_value(char **input, char attr, PQExpBuffer errorMessage) ...@@ -260,7 +260,7 @@ read_attr_value(char **input, char attr, PQExpBuffer errorMessage)
if (*begin != attr) if (*begin != attr)
{ {
printfPQExpBuffer(errorMessage, printfPQExpBuffer(errorMessage,
libpq_gettext("malformed SCRAM message (%c expected)\n"), libpq_gettext("malformed SCRAM message (attribute \"%c\" expected)\n"),
attr); attr);
return NULL; return NULL;
} }
...@@ -269,7 +269,7 @@ read_attr_value(char **input, char attr, PQExpBuffer errorMessage) ...@@ -269,7 +269,7 @@ read_attr_value(char **input, char attr, PQExpBuffer errorMessage)
if (*begin != '=') if (*begin != '=')
{ {
printfPQExpBuffer(errorMessage, printfPQExpBuffer(errorMessage,
libpq_gettext("malformed SCRAM message (expected = in attr '%c')\n"), libpq_gettext("malformed SCRAM message (expected character \"=\" for attribute \"%c\")\n"),
attr); attr);
return NULL; return NULL;
} }
...@@ -508,7 +508,7 @@ read_server_final_message(fe_scram_state *state, char *input, ...@@ -508,7 +508,7 @@ read_server_final_message(fe_scram_state *state, char *input,
char *errmsg = read_attr_value(&input, 'e', errormessage); char *errmsg = read_attr_value(&input, 'e', errormessage);
printfPQExpBuffer(errormessage, printfPQExpBuffer(errormessage,
libpq_gettext("error received from server in SASL exchange: %s\n"), libpq_gettext("error received from server in SCRAM exchange: %s\n"),
errmsg); errmsg);
return false; return false;
} }
......
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