Commit 7ac955b3 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Allow SCRAM authentication, when pg_hba.conf says 'md5'.

If a user has a SCRAM verifier in pg_authid.rolpassword, there's no reason
we cannot attempt to perform SCRAM authentication instead of MD5. The worst
that can happen is that the client doesn't support SCRAM, and the
authentication will fail. But previously, it would fail for sure, because
we would not even try. SCRAM is strictly more secure than MD5, so there's
no harm in trying it. This allows for a more graceful transition from MD5
passwords to SCRAM, as user passwords can be changed to SCRAM verifiers
incrementally, without changing pg_hba.conf.

Refactor the code in auth.c to support that better. Notably, we now have to
look up the user's pg_authid entry before sending the password challenge,
also when performing MD5 authentication. Also simplify the concept of a
"doomed" authentication. Previously, if a user had a password, but it had
expired, we still performed SCRAM authentication (but always returned error
at the end) using the salt and iteration count from the expired password.
Now we construct a fake salt, like we do when the user doesn't have a
password or doesn't exist at all. That simplifies get_role_password(), and
we can don't need to distinguish the  "user has expired password", and
"user does not exist" cases in auth.c.

On second thoughts, also rename uaSASL to uaSCRAM. It refers to the
mechanism specified in pg_hba.conf, and while we use SASL for SCRAM
authentication at the protocol level, the mechanism should be called SCRAM,
not SASL. As a comparison, we have uaLDAP, even though it looks like the
plain 'password' authentication at the protocol level.

Discussion: https://www.postgresql.org/message-id/6425.1489506016@sss.pgh.pa.us
Reviewed-by: Michael Paquier
parent 78874531
...@@ -412,23 +412,22 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> ...@@ -412,23 +412,22 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>md5</></term> <term><literal>scram</></term>
<listitem> <listitem>
<para> <para>
Require the client to supply a double-MD5-hashed password for Perform SCRAM-SHA-256 authentication to verify the user's
authentication. password. See <xref linkend="auth-password"> for details.
See <xref linkend="auth-password"> for details.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>scram</></term> <term><literal>md5</></term>
<listitem> <listitem>
<para> <para>
Perform SCRAM-SHA-256 authentication to verify the user's Perform SCRAM-SHA-256 or MD5 authentication to verify the
password. user's password. See <xref linkend="auth-password">
See <xref linkend="auth-password"> for details. for details.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -689,13 +688,12 @@ host postgres all 192.168.12.10/32 scram ...@@ -689,13 +688,12 @@ host postgres all 192.168.12.10/32 scram
# Allow any user from hosts in the example.com domain to connect to # Allow any user from hosts in the example.com domain to connect to
# any database if the user's password is correctly supplied. # any database if the user's password is correctly supplied.
# #
# Most users use SCRAM authentication, but some users use older clients # Require SCRAM authentication for most users, but make an exception
# that don't support SCRAM authentication, and need to be able to log # for user 'mike', who uses an older client that doesn't support SCRAM
# in using MD5 authentication. Such users are put in the @md5users # authentication.
# group, everyone else must use SCRAM.
# #
# TYPE DATABASE USER ADDRESS METHOD # TYPE DATABASE USER ADDRESS METHOD
host all @md5users .example.com md5 host all mike .example.com md5
host all all .example.com scram host all all .example.com scram
# In the absence of preceding "host" lines, these two lines will # In the absence of preceding "host" lines, these two lines will
...@@ -949,12 +947,13 @@ omicron bryanh guest1 ...@@ -949,12 +947,13 @@ omicron bryanh guest1
</para> </para>
<para> <para>
In <literal>md5</>, the client sends a hash of a random challenge, <literal>md5</> allows falling back to a less secure challenge-response
generated by the server, and the password. It prevents password sniffing, mechanism for those users with an MD5 hashed password.
but is less secure than <literal>scram</>, and provides no protection The fallback mechanism also prevents password sniffing, but provides no
if an attacker manages to steal the password hash from the server. protection if an attacker manages to steal the password hash from the
<literal>md5</> cannot be used with the <xref server, and it cannot be used with the <xref
linkend="guc-db-user-namespace"> feature. linkend="guc-db-user-namespace"> feature. For all other users,
<literal>md5</> works the same as <literal>scram</>.
</para> </para>
<para> <para>
......
...@@ -130,79 +130,91 @@ static char *scram_MockSalt(const char *username); ...@@ -130,79 +130,91 @@ static char *scram_MockSalt(const char *username);
* after the beginning of the exchange with verifier data. * after the beginning of the exchange with verifier data.
* *
* 'username' is the provided by the client. 'shadow_pass' is the role's * 'username' is the provided by the client. 'shadow_pass' is the role's
* password verifier, from pg_authid.rolpassword. If 'doomed' is true, the * password verifier, from pg_authid.rolpassword. If 'shadow_pass' is NULL, we
* authentication must fail, as if an incorrect password was given. * still perform an authentication exchange, but it will fail, as if an
* 'shadow_pass' may be NULL, when 'doomed' is set. * incorrect password was given.
*/ */
void * void *
pg_be_scram_init(const char *username, const char *shadow_pass, bool doomed) pg_be_scram_init(const char *username, const char *shadow_pass)
{ {
scram_state *state; scram_state *state;
int password_type; bool got_verifier;
state = (scram_state *) palloc0(sizeof(scram_state)); state = (scram_state *) palloc0(sizeof(scram_state));
state->state = SCRAM_AUTH_INIT; state->state = SCRAM_AUTH_INIT;
state->username = username; state->username = username;
/* /*
* Perform sanity checks on the provided password after catalog lookup. * Parse the stored password verifier.
* The authentication is bound to fail if the lookup itself failed or if
* the password stored is MD5-encrypted. Authentication is possible for
* users with a valid plain password though.
*/ */
if (shadow_pass)
{
int password_type = get_password_type(shadow_pass);
if (shadow_pass == NULL || doomed) if (password_type == PASSWORD_TYPE_SCRAM)
password_type = -1; {
else if (parse_scram_verifier(shadow_pass, &state->salt, &state->iterations,
password_type = get_password_type(shadow_pass); state->StoredKey, state->ServerKey))
got_verifier = true;
else
{
/*
* The password looked like a SCRAM verifier, but could not be
* parsed.
*/
elog(LOG, "invalid SCRAM verifier for user \"%s\"", username);
got_verifier = false;
}
}
else if (password_type == PASSWORD_TYPE_PLAINTEXT)
{
/*
* The stored password is in plain format. Generate a fresh SCRAM
* verifier from it, and proceed with that.
*/
char *verifier;
if (password_type == PASSWORD_TYPE_SCRAM) verifier = scram_build_verifier(username, shadow_pass, 0);
{
if (!parse_scram_verifier(shadow_pass, &state->salt, &state->iterations, (void) parse_scram_verifier(verifier, &state->salt, &state->iterations,
state->StoredKey, state->ServerKey)) state->StoredKey, state->ServerKey);
pfree(verifier);
got_verifier = true;
}
else
{ {
/* /*
* The password looked like a SCRAM verifier, but could not be * The user doesn't have SCRAM verifier, nor could we generate
* parsed. * one. (You cannot do SCRAM authentication with an MD5 hash.)
*/ */
elog(LOG, "invalid SCRAM verifier for user \"%s\"", username); state->logdetail = psprintf(_("User \"%s\" does not have a valid SCRAM verifier."),
doomed = true; state->username);
got_verifier = false;
} }
} }
else if (password_type == PASSWORD_TYPE_PLAINTEXT) else
{ {
char *verifier;
/* /*
* The password provided is in plain format, in which case a fresh * The caller requested us to perform a dummy authentication. This is
* SCRAM verifier can be generated and used for the rest of the * considered normal, since the caller requested it, so don't set log
* processing. * detail.
*/ */
verifier = scram_build_verifier(username, shadow_pass, 0); got_verifier = false;
(void) parse_scram_verifier(verifier, &state->salt, &state->iterations,
state->StoredKey, state->ServerKey);
pfree(verifier);
} }
else
doomed = true;
if (doomed) /*
* If the user did not have a valid SCRAM verifier, we still go through
* the motions with a mock one, and fail as if the client supplied an
* incorrect password. This is to avoid revealing information to an
* attacker.
*/
if (!got_verifier)
{ {
/*
* We don't have a valid SCRAM verifier, nor could we generate one, or
* the caller requested us to perform a dummy authentication.
*
* The authentication is bound to fail, but to avoid revealing
* information to the attacker, go through the motions with a fake
* SCRAM verifier, and fail as if the password was incorrect.
*/
state->logdetail = psprintf(_("User \"%s\" does not have a valid SCRAM verifier."),
state->username);
mock_scram_verifier(username, &state->salt, &state->iterations, mock_scram_verifier(username, &state->salt, &state->iterations,
state->StoredKey, state->ServerKey); state->StoredKey, state->ServerKey);
state->doomed = true;
} }
state->doomed = doomed;
return state; return state;
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#include "commands/user.h"
#include "common/ip.h" #include "common/ip.h"
#include "common/md5.h" #include "common/md5.h"
#include "libpq/auth.h" #include "libpq/auth.h"
...@@ -49,17 +50,15 @@ static char *recv_password_packet(Port *port); ...@@ -49,17 +50,15 @@ static char *recv_password_packet(Port *port);
/*---------------------------------------------------------------- /*----------------------------------------------------------------
* MD5 authentication * Password-based authentication methods (password, md5, and scram)
*---------------------------------------------------------------- *----------------------------------------------------------------
*/ */
static int CheckMD5Auth(Port *port, char **logdetail); static int CheckPasswordAuth(Port *port, char **logdetail);
static int CheckPWChallengeAuth(Port *port, char **logdetail);
/*---------------------------------------------------------------- static int CheckMD5Auth(Port *port, char *shadow_pass, char **logdetail);
* Plaintext password authentication static int CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail);
*----------------------------------------------------------------
*/
static int CheckPasswordAuth(Port *port, char **logdetail);
/*---------------------------------------------------------------- /*----------------------------------------------------------------
* Ident authentication * Ident authentication
...@@ -200,12 +199,6 @@ static int CheckRADIUSAuth(Port *port); ...@@ -200,12 +199,6 @@ static int CheckRADIUSAuth(Port *port);
static int PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identifier, char *user_name, char *passwd); static int PerformRadiusTransaction(char *server, char *secret, char *portstr, char *identifier, char *user_name, char *passwd);
/*----------------------------------------------------------------
* SASL authentication
*----------------------------------------------------------------
*/
static int CheckSASLAuth(Port *port, char **logdetail);
/* /*
* Maximum accepted size of GSS and SSPI authentication tokens. * Maximum accepted size of GSS and SSPI authentication tokens.
* *
...@@ -291,7 +284,7 @@ auth_failed(Port *port, int status, char *logdetail) ...@@ -291,7 +284,7 @@ auth_failed(Port *port, int status, char *logdetail)
break; break;
case uaPassword: case uaPassword:
case uaMD5: case uaMD5:
case uaSASL: case uaSCRAM:
errstr = gettext_noop("password authentication failed for user \"%s\""); errstr = gettext_noop("password authentication failed for user \"%s\"");
/* We use it to indicate if a .pgpass password failed. */ /* We use it to indicate if a .pgpass password failed. */
errcode_return = ERRCODE_INVALID_PASSWORD; errcode_return = ERRCODE_INVALID_PASSWORD;
...@@ -552,17 +545,14 @@ ClientAuthentication(Port *port) ...@@ -552,17 +545,14 @@ ClientAuthentication(Port *port)
break; break;
case uaMD5: case uaMD5:
status = CheckMD5Auth(port, &logdetail); case uaSCRAM:
status = CheckPWChallengeAuth(port, &logdetail);
break; break;
case uaPassword: case uaPassword:
status = CheckPasswordAuth(port, &logdetail); status = CheckPasswordAuth(port, &logdetail);
break; break;
case uaSASL:
status = CheckSASLAuth(port, &logdetail);
break;
case uaPAM: case uaPAM:
#ifdef USE_PAM #ifdef USE_PAM
status = CheckPAMAuth(port, port->user_name, ""); status = CheckPAMAuth(port, port->user_name, "");
...@@ -710,41 +700,34 @@ recv_password_packet(Port *port) ...@@ -710,41 +700,34 @@ recv_password_packet(Port *port)
/*---------------------------------------------------------------- /*----------------------------------------------------------------
* MD5 authentication * Password-based authentication mechanisms
*---------------------------------------------------------------- *----------------------------------------------------------------
*/ */
/*
* Plaintext password authentication.
*/
static int static int
CheckMD5Auth(Port *port, char **logdetail) CheckPasswordAuth(Port *port, char **logdetail)
{ {
char md5Salt[4]; /* Password salt */
char *passwd; char *passwd;
char *shadow_pass;
int result; int result;
char *shadow_pass;
if (Db_user_namespace) sendAuthRequest(port, AUTH_REQ_PASSWORD, NULL, 0);
ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("MD5 authentication is not supported when \"db_user_namespace\" is enabled")));
/* include the salt to use for computing the response */
if (!pg_backend_random(md5Salt, 4))
{
ereport(LOG,
(errmsg("could not generate random MD5 salt")));
return STATUS_ERROR;
}
sendAuthRequest(port, AUTH_REQ_MD5, md5Salt, 4);
passwd = recv_password_packet(port); passwd = recv_password_packet(port);
if (passwd == NULL) if (passwd == NULL)
return STATUS_EOF; /* client wouldn't send password */ return STATUS_EOF; /* client wouldn't send password */
result = get_role_password(port->user_name, &shadow_pass, logdetail); shadow_pass = get_role_password(port->user_name, logdetail);
if (result == STATUS_OK) if (shadow_pass)
result = md5_crypt_verify(port->user_name, shadow_pass, passwd, {
md5Salt, 4, logdetail); result = plain_crypt_verify(port->user_name, shadow_pass, passwd,
logdetail);
}
else
result = STATUS_ERROR;
if (shadow_pass) if (shadow_pass)
pfree(shadow_pass); pfree(shadow_pass);
...@@ -753,42 +736,114 @@ CheckMD5Auth(Port *port, char **logdetail) ...@@ -753,42 +736,114 @@ CheckMD5Auth(Port *port, char **logdetail)
return result; return result;
} }
/*---------------------------------------------------------------- /*
* Plaintext password authentication * MD5 and SCRAM authentication.
*----------------------------------------------------------------
*/ */
static int
CheckPWChallengeAuth(Port *port, char **logdetail)
{
int auth_result;
char *shadow_pass;
PasswordType pwtype;
Assert(port->hba->auth_method == uaSCRAM ||
port->hba->auth_method == uaMD5);
/* First look up the user's password. */
shadow_pass = get_role_password(port->user_name, logdetail);
/*
* If the user does not exist, or has no password, we still go through the
* motions of authentication, to avoid revealing to the client that the
* user didn't exist. If 'md5' is allowed, we choose whether to use 'md5'
* or 'scram' authentication based on current password_encryption setting.
* The idea is that most genuine users probably have a password of that
* type, if we pretend that this user had a password of that type, too, it
* "blends in" best.
*
* If the user had a password, but it was expired, we'll use the details
* of the expired password for the authentication, but report it as
* failure to the client even if correct password was given.
*/
if (!shadow_pass)
pwtype = Password_encryption;
else
pwtype = get_password_type(shadow_pass);
/*
* If 'md5' authentication is allowed, decide whether to perform 'md5' or
* 'scram' authentication based on the type of password the user has. If
* it's an MD5 hash, we must do MD5 authentication, and if it's a SCRAM
* verifier, we must do SCRAM authentication. If it's stored in
* plaintext, we could do either one, so we opt for the more secure
* mechanism, SCRAM.
*
* If MD5 authentication is not allowed, always use SCRAM. If the user
* had an MD5 password, CheckSCRAMAuth() will fail.
*/
if (port->hba->auth_method == uaMD5 && pwtype == PASSWORD_TYPE_MD5)
{
auth_result = CheckMD5Auth(port, shadow_pass, logdetail);
}
else
{
auth_result = CheckSCRAMAuth(port, shadow_pass, logdetail);
}
if (shadow_pass)
pfree(shadow_pass);
/*
* If get_role_password() returned error, return error, even if the
* authentication succeeded.
*/
if (!shadow_pass)
{
Assert(auth_result != STATUS_OK);
return STATUS_ERROR;
}
return auth_result;
}
static int static int
CheckPasswordAuth(Port *port, char **logdetail) CheckMD5Auth(Port *port, char *shadow_pass, char **logdetail)
{ {
char md5Salt[4]; /* Password salt */
char *passwd; char *passwd;
int result; int result;
char *shadow_pass;
sendAuthRequest(port, AUTH_REQ_PASSWORD, NULL, 0); if (Db_user_namespace)
ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("MD5 authentication is not supported when \"db_user_namespace\" is enabled")));
/* include the salt to use for computing the response */
if (!pg_backend_random(md5Salt, 4))
{
ereport(LOG,
(errmsg("could not generate random MD5 salt")));
return STATUS_ERROR;
}
sendAuthRequest(port, AUTH_REQ_MD5, md5Salt, 4);
passwd = recv_password_packet(port); passwd = recv_password_packet(port);
if (passwd == NULL) if (passwd == NULL)
return STATUS_EOF; /* client wouldn't send password */ return STATUS_EOF; /* client wouldn't send password */
result = get_role_password(port->user_name, &shadow_pass, logdetail);
if (result == STATUS_OK)
result = plain_crypt_verify(port->user_name, shadow_pass, passwd,
logdetail);
if (shadow_pass) if (shadow_pass)
pfree(shadow_pass); result = md5_crypt_verify(port->user_name, shadow_pass, passwd,
md5Salt, 4, logdetail);
else
result = STATUS_ERROR;
pfree(passwd); pfree(passwd);
return result; return result;
} }
/*----------------------------------------------------------------
* SASL authentication system
*----------------------------------------------------------------
*/
static int static int
CheckSASLAuth(Port *port, char **logdetail) CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
{ {
int mtype; int mtype;
StringInfoData buf; StringInfoData buf;
...@@ -796,8 +851,6 @@ CheckSASLAuth(Port *port, char **logdetail) ...@@ -796,8 +851,6 @@ CheckSASLAuth(Port *port, char **logdetail)
char *output = NULL; char *output = NULL;
int outputlen = 0; int outputlen = 0;
int result; int result;
char *shadow_pass;
bool doomed = false;
/* /*
* SASL auth is not supported for protocol versions before 3, because it * SASL auth is not supported for protocol versions before 3, because it
...@@ -827,11 +880,9 @@ CheckSASLAuth(Port *port, char **logdetail) ...@@ -827,11 +880,9 @@ CheckSASLAuth(Port *port, char **logdetail)
* This is because we don't want to reveal to an attacker what usernames * This is because we don't want to reveal to an attacker what usernames
* are valid, nor which users have a valid password. * are valid, nor which users have a valid password.
*/ */
if (get_role_password(port->user_name, &shadow_pass, logdetail) != STATUS_OK)
doomed = true;
/* Initialize the status tracker for message exchanges */ /* Initialize the status tracker for message exchanges */
scram_opaq = pg_be_scram_init(port->user_name, shadow_pass, doomed); scram_opaq = pg_be_scram_init(port->user_name, shadow_pass);
/* /*
* Loop through SASL message exchange. This exchange can consist of * Loop through SASL message exchange. This exchange can consist of
...@@ -875,7 +926,7 @@ CheckSASLAuth(Port *port, char **logdetail) ...@@ -875,7 +926,7 @@ CheckSASLAuth(Port *port, char **logdetail)
*/ */
result = pg_be_scram_exchange(scram_opaq, buf.data, buf.len, result = pg_be_scram_exchange(scram_opaq, buf.data, buf.len,
&output, &outputlen, &output, &outputlen,
doomed ? NULL : logdetail); logdetail);
/* input buffer no longer used */ /* input buffer no longer used */
pfree(buf.data); pfree(buf.data);
......
...@@ -31,25 +31,18 @@ ...@@ -31,25 +31,18 @@
/* /*
* Fetch stored password for a user, for authentication. * Fetch stored password for a user, for authentication.
* *
* Returns STATUS_OK on success. On error, returns STATUS_ERROR, and stores * On error, returns NULL, and stores a palloc'd string describing the reason,
* a palloc'd string describing the reason, for the postmaster log, in * for the postmaster log, in *logdetail. The error reason should *not* be
* *logdetail. The error reason should *not* be sent to the client, to avoid * sent to the client, to avoid giving away user information!
* giving away user information!
*
* If the password is expired, it is still returned in *shadow_pass, but the
* return code is STATUS_ERROR. On other errors, *shadow_pass is set to
* NULL.
*/ */
int char *
get_role_password(const char *role, char **shadow_pass, char **logdetail) get_role_password(const char *role, char **logdetail)
{ {
int retval = STATUS_ERROR;
TimestampTz vuntil = 0; TimestampTz vuntil = 0;
HeapTuple roleTup; HeapTuple roleTup;
Datum datum; Datum datum;
bool isnull; bool isnull;
char *shadow_pass;
*shadow_pass = NULL;
/* Get role info from pg_authid */ /* Get role info from pg_authid */
roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(role)); roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(role));
...@@ -57,7 +50,7 @@ get_role_password(const char *role, char **shadow_pass, char **logdetail) ...@@ -57,7 +50,7 @@ get_role_password(const char *role, char **shadow_pass, char **logdetail)
{ {
*logdetail = psprintf(_("Role \"%s\" does not exist."), *logdetail = psprintf(_("Role \"%s\" does not exist."),
role); role);
return STATUS_ERROR; /* no such user */ return NULL; /* no such user */
} }
datum = SysCacheGetAttr(AUTHNAME, roleTup, datum = SysCacheGetAttr(AUTHNAME, roleTup,
...@@ -67,9 +60,9 @@ get_role_password(const char *role, char **shadow_pass, char **logdetail) ...@@ -67,9 +60,9 @@ get_role_password(const char *role, char **shadow_pass, char **logdetail)
ReleaseSysCache(roleTup); ReleaseSysCache(roleTup);
*logdetail = psprintf(_("User \"%s\" has no password assigned."), *logdetail = psprintf(_("User \"%s\" has no password assigned."),
role); role);
return STATUS_ERROR; /* user has no password */ return NULL; /* user has no password */
} }
*shadow_pass = TextDatumGetCString(datum); shadow_pass = TextDatumGetCString(datum);
datum = SysCacheGetAttr(AUTHNAME, roleTup, datum = SysCacheGetAttr(AUTHNAME, roleTup,
Anum_pg_authid_rolvaliduntil, &isnull); Anum_pg_authid_rolvaliduntil, &isnull);
...@@ -78,30 +71,25 @@ get_role_password(const char *role, char **shadow_pass, char **logdetail) ...@@ -78,30 +71,25 @@ get_role_password(const char *role, char **shadow_pass, char **logdetail)
ReleaseSysCache(roleTup); ReleaseSysCache(roleTup);
if (**shadow_pass == '\0') if (*shadow_pass == '\0')
{ {
*logdetail = psprintf(_("User \"%s\" has an empty password."), *logdetail = psprintf(_("User \"%s\" has an empty password."),
role); role);
pfree(*shadow_pass); pfree(shadow_pass);
*shadow_pass = NULL; return NULL; /* empty password */
return STATUS_ERROR; /* empty password */
} }
/* /*
* Password OK, now check to be sure we are not past rolvaliduntil * Password OK, but check to be sure we are not past rolvaliduntil
*/ */
if (isnull) if (!isnull && vuntil < GetCurrentTimestamp())
retval = STATUS_OK;
else if (vuntil < GetCurrentTimestamp())
{ {
*logdetail = psprintf(_("User \"%s\" has an expired password."), *logdetail = psprintf(_("User \"%s\" has an expired password."),
role); role);
retval = STATUS_ERROR; return NULL;
} }
else
retval = STATUS_OK;
return retval; return shadow_pass;
} }
/* /*
......
...@@ -1328,7 +1328,7 @@ parse_hba_line(TokenizedLine *tok_line, int elevel) ...@@ -1328,7 +1328,7 @@ parse_hba_line(TokenizedLine *tok_line, int elevel)
parsedline->auth_method = uaMD5; parsedline->auth_method = uaMD5;
} }
else if (strcmp(token->string, "scram") == 0) else if (strcmp(token->string, "scram") == 0)
parsedline->auth_method = uaSASL; parsedline->auth_method = uaSCRAM;
else if (strcmp(token->string, "pam") == 0) else if (strcmp(token->string, "pam") == 0)
#ifdef USE_PAM #ifdef USE_PAM
parsedline->auth_method = uaPAM; parsedline->auth_method = uaPAM;
......
...@@ -32,8 +32,7 @@ extern PasswordType get_password_type(const char *shadow_pass); ...@@ -32,8 +32,7 @@ extern PasswordType get_password_type(const char *shadow_pass);
extern char *encrypt_password(PasswordType target_type, const char *role, extern char *encrypt_password(PasswordType target_type, const char *role,
const char *password); const char *password);
extern int get_role_password(const char *role, char **shadow_pass, extern char *get_role_password(const char *role, char **logdetail);
char **logdetail);
extern int md5_crypt_verify(const char *role, const char *shadow_pass, extern int md5_crypt_verify(const char *role, const char *shadow_pass,
const char *client_pass, const char *md5_salt, const char *client_pass, const char *md5_salt,
......
...@@ -30,7 +30,7 @@ typedef enum UserAuth ...@@ -30,7 +30,7 @@ typedef enum UserAuth
uaIdent, uaIdent,
uaPassword, uaPassword,
uaMD5, uaMD5,
uaSASL, uaSCRAM,
uaGSS, uaGSS,
uaSSPI, uaSSPI,
uaPAM, uaPAM,
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#define SASL_EXCHANGE_FAILURE 2 #define SASL_EXCHANGE_FAILURE 2
/* Routines dedicated to authentication */ /* Routines dedicated to authentication */
extern void *pg_be_scram_init(const char *username, const char *shadow_pass, bool doomed); extern void *pg_be_scram_init(const char *username, const char *shadow_pass);
extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen, extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen,
char **output, int *outputlen, char **logdetail); char **output, int *outputlen, char **logdetail);
......
...@@ -75,10 +75,10 @@ SKIP: ...@@ -75,10 +75,10 @@ SKIP:
test_role($node, 'md5_role', 'scram', 2); test_role($node, 'md5_role', 'scram', 2);
test_role($node, 'plain_role', 'scram', 0); test_role($node, 'plain_role', 'scram', 0);
# For "md5" method, users "plain_role" and "md5_role" should be able to # For "md5" method, all users should be able to connect (SCRAM
# connect. # authentication will be performed for the user with a scram verifier.)
reset_pg_hba($node, 'md5'); reset_pg_hba($node, 'md5');
test_role($node, 'scram_role', 'md5', 2); test_role($node, 'scram_role', 'md5', 0);
test_role($node, 'md5_role', 'md5', 0); test_role($node, 'md5_role', 'md5', 0);
test_role($node, 'plain_role', 'md5', 0); test_role($node, 'plain_role', 'md5', 0);
} }
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