Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 218b024

Browse files
committed
Accept SCRAM channel binding enabled clients
Add support to the SCRAM exchange for clients that support channel binding, such as PostgreSQL version 11 and beyond. If such a client encounters a PostgreSQL 10 server that does not support channel binding, it will send a channel binding flag 'y', meaning the client supports channel binding but thinks the server does not. But PostgreSQL 10 erroneously did not accept that flag. This would cause connections to fail if a version 11 client connects to a version 10 server with SCRAM authentication over SSL. Author: Michael Paquier <michael.paquier@gmail.com>
1 parent ee5b595 commit 218b024

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/libpq/auth-scram.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ typedef struct
112112

113113
const char *username; /* username from startup packet */
114114

115+
char cbind_flag;
116+
115117
int iterations;
116118
char *salt; /* base64-encoded */
117119
uint8 StoredKey[SCRAM_KEY_LEN];
@@ -774,6 +776,7 @@ read_client_first_message(scram_state *state, char *input)
774776
*/
775777

776778
/* read gs2-cbind-flag */
779+
state->cbind_flag = *input;
777780
switch (*input)
778781
{
779782
case 'n':
@@ -1033,10 +1036,13 @@ read_client_final_message(scram_state *state, char *input)
10331036

10341037
/*
10351038
* Read channel-binding. We don't support channel binding, so it's
1036-
* expected to always be "biws", which is "n,,", base64-encoded.
1039+
* expected to always be "biws", which is "n,,", base64-encoded, or
1040+
* "eSws", which is "y,,". We also have to check whether the flag is
1041+
* the same one that the client originally sent.
10371042
*/
10381043
channel_binding = read_attr_value(&p, 'c');
1039-
if (strcmp(channel_binding, "biws") != 0)
1044+
if (!(strcmp(channel_binding, "biws") == 0 && state->cbind_flag == 'n') &&
1045+
!(strcmp(channel_binding, "eSws") == 0 && state->cbind_flag == 'y'))
10401046
ereport(ERROR,
10411047
(errcode(ERRCODE_PROTOCOL_VIOLATION),
10421048
(errmsg("unexpected SCRAM channel-binding attribute in client-final-message"))));

0 commit comments

Comments
 (0)