Skip to content

Commit 103a32f

Browse files
committed
ed25519: better error message for an incorrect password hash
1 parent c94ec9f commit 103a32f

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

mysql-test/suite/plugins/r/auth_ed25519.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ show grants for test1@localhost;
3939
Grants for test1@localhost
4040
GRANT USAGE ON *.* TO 'test1'@'localhost' IDENTIFIED VIA ed25519 USING 'ZIgUREUg5PVgQ6LskhXmO+eZLS0nC8be6HPjYWR4YJY'
4141
drop user test1@localhost;
42+
create user test1@localhost identified via ed25519 using 'foo';
43+
ERROR HY000: Password hash should be 43 characters long
44+
create user test1@localhost identified via ed25519 using '>>>1234567890123456789012345678901234567890';
45+
ERROR HY000: Password hash should be base64 encoded
4246
create user test1@localhost identified via ed25519 using password('foo');
4347
show grants for test1@localhost;
4448
Grants for test1@localhost

mysql-test/suite/plugins/t/auth_ed25519.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ let $pwd=`select ed25519_password("secret")`;
2929
eval create user test1@localhost identified via ed25519 using '$pwd';
3030
show grants for test1@localhost;
3131
drop user test1@localhost;
32+
--error ER_PASSWD_LENGTH
33+
create user test1@localhost identified via ed25519 using 'foo';
34+
--error ER_PASSWD_LENGTH
35+
create user test1@localhost identified via ed25519 using '>>>1234567890123456789012345678901234567890';
3236
create user test1@localhost identified via ed25519 using password('foo');
3337
show grants for test1@localhost;
3438
select ed25519_password('foo');

plugin/auth_ed25519/server_ed25519.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
1616

1717
#include <mysql/plugin_auth.h>
18+
#include <mysqld_error.h>
1819
#include "common.h"
1920

2021
#if !defined(__attribute__) && !defined(__GNUC__)
@@ -77,12 +78,18 @@ static int digest_to_binary(const char *d, size_t dlen,
7778
char pw[PASSWORD_LEN_BUF];
7879

7980
if (*blen < CRYPTO_PUBLICKEYBYTES || dlen != PASSWORD_LEN)
81+
{
82+
my_printf_error(ER_PASSWD_LENGTH, "Password hash should be %d characters long", 0, PASSWORD_LEN);
8083
return 1;
84+
}
8185

8286
*blen= CRYPTO_PUBLICKEYBYTES;
8387
memcpy(pw, d, PASSWORD_LEN);
8488
pw[PASSWORD_LEN]= '=';
85-
return my_base64_decode(pw, PASSWORD_LEN_BUF, b, 0, 0) != CRYPTO_PUBLICKEYBYTES;
89+
if (my_base64_decode(pw, PASSWORD_LEN_BUF, b, 0, 0) == CRYPTO_PUBLICKEYBYTES)
90+
return 0;
91+
my_printf_error(ER_PASSWD_LENGTH, "Password hash should be base64 encoded", 0);
92+
return 1;
8693
}
8794

8895
static struct st_mysql_auth info =

sql/sql_acl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ static int set_user_salt(ACL_USER *acl_user, plugin_ref plugin)
17921792
size_t len= sizeof(buf);
17931793
if (auth->preprocess_hash(acl_user->auth_string.str,
17941794
acl_user->auth_string.length, buf, &len))
1795-
return 1; // ER_PASSWD_LENGTH?
1795+
return 1;
17961796
acl_user->salt.str= (char*)memdup_root(&acl_memroot, buf, len);
17971797
acl_user->salt.length= len;
17981798
}

0 commit comments

Comments
 (0)