Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
c6305a9c
Commit
c6305a9c
authored
Mar 17, 2017
by
Heikki Linnakangas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow plaintext 'password' authentication when user has a SCRAM verifier.
Oversight in the main SCRAM patch.
parent
ff30aec7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
22 deletions
+87
-22
src/backend/libpq/auth-scram.c
src/backend/libpq/auth-scram.c
+46
-0
src/backend/libpq/crypt.c
src/backend/libpq/crypt.c
+39
-22
src/include/libpq/scram.h
src/include/libpq/scram.h
+2
-0
No files found.
src/backend/libpq/auth-scram.c
View file @
c6305a9c
...
...
@@ -364,6 +364,52 @@ scram_build_verifier(const char *username, const char *password,
return
psprintf
(
"scram-sha-256:%s:%d:%s:%s"
,
encoded_salt
,
iterations
,
storedkey_hex
,
serverkey_hex
);
}
/*
* Verify a plaintext password against a SCRAM verifier. This is used when
* performing plaintext password authentication for a user that has a SCRAM
* verifier stored in pg_authid.
*/
bool
scram_verify_plain_password
(
const
char
*
username
,
const
char
*
password
,
const
char
*
verifier
)
{
char
*
encoded_salt
;
char
*
salt
;
int
saltlen
;
int
iterations
;
uint8
stored_key
[
SCRAM_KEY_LEN
];
uint8
server_key
[
SCRAM_KEY_LEN
];
uint8
computed_key
[
SCRAM_KEY_LEN
];
if
(
!
parse_scram_verifier
(
verifier
,
&
encoded_salt
,
&
iterations
,
stored_key
,
server_key
))
{
/*
* The password looked like a SCRAM verifier, but could not be
* parsed.
*/
elog
(
LOG
,
"invalid SCRAM verifier for user
\"
%s
\"
"
,
username
);
return
false
;
}
salt
=
palloc
(
pg_b64_dec_len
(
strlen
(
encoded_salt
)));
saltlen
=
pg_b64_decode
(
encoded_salt
,
strlen
(
encoded_salt
),
salt
);
if
(
saltlen
==
-
1
)
{
elog
(
LOG
,
"invalid SCRAM verifier for user
\"
%s
\"
"
,
username
);
return
false
;
}
/* Compute Server key based on the user-supplied plaintext password */
scram_ClientOrServerKey
(
password
,
salt
,
saltlen
,
iterations
,
SCRAM_SERVER_KEY_NAME
,
computed_key
);
/*
* Compare the verifier's Server Key with the one computed from the
* user-supplied password.
*/
return
memcmp
(
computed_key
,
server_key
,
SCRAM_KEY_LEN
)
==
0
;
}
/*
* Check if given verifier can be used for SCRAM authentication.
...
...
src/backend/libpq/crypt.c
View file @
c6305a9c
...
...
@@ -283,7 +283,6 @@ plain_crypt_verify(const char *role, const char *shadow_pass,
const
char
*
client_pass
,
char
**
logdetail
)
{
int
retval
;
char
crypt_client_pass
[
MD5_PASSWD_LEN
+
1
];
/*
...
...
@@ -293,6 +292,21 @@ plain_crypt_verify(const char *role, const char *shadow_pass,
*/
switch
(
get_password_type
(
shadow_pass
))
{
case
PASSWORD_TYPE_SCRAM
:
if
(
scram_verify_plain_password
(
role
,
client_pass
,
shadow_pass
))
{
return
STATUS_OK
;
}
else
{
*
logdetail
=
psprintf
(
_
(
"Password does not match for user
\"
%s
\"
."
),
role
);
return
STATUS_ERROR
;
}
break
;
case
PASSWORD_TYPE_MD5
:
if
(
!
pg_md5_encrypt
(
client_pass
,
role
,
...
...
@@ -307,30 +321,33 @@ plain_crypt_verify(const char *role, const char *shadow_pass,
*/
return
STATUS_ERROR
;
}
client_pass
=
crypt_client_pass
;
break
;
case
PASSWORD_TYPE_PLAINTEXT
:
break
;
default:
/*
* This shouldn't happen. Plain "password" authentication should
* be possible with any kind of stored password hash.
*/
*
logdetail
=
psprintf
(
_
(
"Password of user
\"
%s
\"
is in unrecognized format."
),
if
(
strcmp
(
crypt_client_pass
,
shadow_pass
)
==
0
)
return
STATUS_OK
;
else
{
*
logdetail
=
psprintf
(
_
(
"Password does not match for user
\"
%s
\"
."
),
role
);
return
STATUS_ERROR
;
}
break
;
case
PASSWORD_TYPE_PLAINTEXT
:
if
(
strcmp
(
client_pass
,
shadow_pass
)
==
0
)
retval
=
STATUS_OK
;
return
STATUS_OK
;
else
{
*
logdetail
=
psprintf
(
_
(
"Password does not match for user
\"
%s
\"
."
),
role
);
retval
=
STATUS_ERROR
;
return
STATUS_ERROR
;
}
break
;
}
return
retval
;
/*
* This shouldn't happen. Plain "password" authentication is possible
* with any kind of stored password hash.
*/
*
logdetail
=
psprintf
(
_
(
"Password of user
\"
%s
\"
is in unrecognized format."
),
role
);
return
STATUS_ERROR
;
}
src/include/libpq/scram.h
View file @
c6305a9c
...
...
@@ -31,5 +31,7 @@ extern char *scram_build_verifier(const char *username,
const
char
*
password
,
int
iterations
);
extern
bool
is_scram_verifier
(
const
char
*
verifier
);
extern
bool
scram_verify_plain_password
(
const
char
*
username
,
const
char
*
password
,
const
char
*
verifier
);
#endif
/* PG_SCRAM_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment