From e8ea91e7a1c360644bd44f6da0a60d1ac115d12b Mon Sep 17 00:00:00 2001 From: lance6716 <lance6716@gmail.com> Date: Sat, 7 Sep 2024 13:37:59 +0800 Subject: [PATCH 1/4] Fix can't connect to MySQL 8.0 with long password Signed-off-by: lance6716 <lance6716@gmail.com> --- client/auth.go | 6 +++--- client/client_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/auth.go b/client/auth.go index cb479f3ba..006f71e11 100644 --- a/client/auth.go +++ b/client/auth.go @@ -115,11 +115,11 @@ func (c *Conn) readInitialHandshake() error { // the first packet *must* have at least 20 bytes of a scramble. // if a plugin provided less, we pad it to 20 with zeros rest := int(authPluginDataLen) - 8 - if max := 12 + 1; rest < max { - rest = max + if rest < 13 { + rest = 13 } - authPluginDataPart2 := data[pos : pos+rest] + authPluginDataPart2 := data[pos : pos+rest-1] pos += rest c.salt = append(c.salt, authPluginDataPart2...) diff --git a/client/client_test.go b/client/client_test.go index 3917db3f5..9dbf0a3f5 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -526,3 +526,16 @@ INSERT INTO field_value_test VALUES ( require.Equal(s.T(), expected[i], v.String()) } } + +func (s *clientTestSuite) TestLongPassword() { + _, err := s.c.Execute("DROP USER IF EXISTS 'test_long_password'@'localhost'") + require.NoError(s.T(), err) + _, err = s.c.Execute("CREATE USER 'test_long_password'@'localhost' IDENTIFIED BY '12345678901234567890'") + require.NoError(s.T(), err) + + addr := fmt.Sprintf("%s:%s", *test_util.MysqlHost, s.port) + c, err := Connect(addr, "test_long_password", "12345678901234567890", "") + require.NoError(s.T(), err) + err = c.Close() + require.NoError(s.T(), err) +} From 6a0645bfc9a68ecb90bf40d98ad5bd59c4ff5021 Mon Sep 17 00:00:00 2001 From: lance6716 <lance6716@gmail.com> Date: Sat, 7 Sep 2024 13:45:01 +0800 Subject: [PATCH 2/4] tmp revert Signed-off-by: lance6716 <lance6716@gmail.com> --- client/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/auth.go b/client/auth.go index 006f71e11..2d348d210 100644 --- a/client/auth.go +++ b/client/auth.go @@ -119,7 +119,7 @@ func (c *Conn) readInitialHandshake() error { rest = 13 } - authPluginDataPart2 := data[pos : pos+rest-1] + authPluginDataPart2 := data[pos : pos+rest] pos += rest c.salt = append(c.salt, authPluginDataPart2...) From 99e38f61dc76b838ff67805e355f927993d1f5f5 Mon Sep 17 00:00:00 2001 From: lance6716 <lance6716@gmail.com> Date: Sat, 7 Sep 2024 13:48:13 +0800 Subject: [PATCH 3/4] revert Signed-off-by: lance6716 <lance6716@gmail.com> --- client/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/auth.go b/client/auth.go index 2d348d210..006f71e11 100644 --- a/client/auth.go +++ b/client/auth.go @@ -119,7 +119,7 @@ func (c *Conn) readInitialHandshake() error { rest = 13 } - authPluginDataPart2 := data[pos : pos+rest] + authPluginDataPart2 := data[pos : pos+rest-1] pos += rest c.salt = append(c.salt, authPluginDataPart2...) From 3adfed454abc1d96c9486cf3328860678dd46f03 Mon Sep 17 00:00:00 2001 From: lance6716 <lance6716@gmail.com> Date: Sat, 7 Sep 2024 13:53:30 +0800 Subject: [PATCH 4/4] fix wrong UT Signed-off-by: lance6716 <lance6716@gmail.com> --- client/client_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 9dbf0a3f5..1008a101b 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -528,9 +528,9 @@ INSERT INTO field_value_test VALUES ( } func (s *clientTestSuite) TestLongPassword() { - _, err := s.c.Execute("DROP USER IF EXISTS 'test_long_password'@'localhost'") + _, err := s.c.Execute("DROP USER IF EXISTS 'test_long_password'@'%'") require.NoError(s.T(), err) - _, err = s.c.Execute("CREATE USER 'test_long_password'@'localhost' IDENTIFIED BY '12345678901234567890'") + _, err = s.c.Execute("CREATE USER 'test_long_password'@'%' IDENTIFIED BY '12345678901234567890'") require.NoError(s.T(), err) addr := fmt.Sprintf("%s:%s", *test_util.MysqlHost, s.port)