Skip to content

Support caching sha2 password #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2018

Conversation

nakagami
Copy link
Contributor

@nakagami nakagami commented May 15, 2018

Description

Support chaching_sha2_password authentication plugin. It's MySQL 8.0 default plugin.

Related Issue #785

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

@methane
Copy link
Member

methane commented May 15, 2018

Thanks for your contribution.

There is #552 which implements auth plugin support (without caching_sha2 implementation).
But author of the pull request is not active and there are some unfixed review comments.

@julienschmidt How do you think about next version? MySQL 8.0 is GA already.

  1. Don't merge this and add support for authentication plugins. #552 until next version is released.
  2. Merge this before next version. And add auth plugin support after next version is released.
  3. Fix add support for authentication plugins. #552 and implement caching_sha2 based on it, before releasing next version.

@julienschmidt julienschmidt added this to the v1.4.0 milestone May 15, 2018
@julienschmidt
Copy link
Member

Thank you for this pull-request!

@methane I changed the scheduled release date for v1.4.0 to 1 week from now. We should get it out ASAP. My preference would be option 3. I'll look into it later today, to see how feasible that is. Otherwise we'll fall back to option 2. Making a release without MySQL 8 support would be a bad joke.

@@ -1842,7 +1842,7 @@ func TestSQLInjection(t *testing.T) {

dsns := []string{
dsn,
dsn + "&sql_mode='NO_BACKSLASH_ESCAPES,NO_AUTO_CREATE_USER'",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a required change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO_AUTO_CREATE_USER SQL mode seems removed at MySQL 8.0
https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html

My linux box show that message

--- FAIL: TestSQLInjection (0.92s)
        driver_test.go:161: error on exec CREATE TABLE test (v INTEGER): Error 1231: Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

@julienschmidt julienschmidt self-assigned this May 15, 2018
Copy link
Member

@julienschmidt julienschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@methane let's do it the other way round. As we will merge this PR anyway in some form, let's merge it as it is first and then implement the general auth plugin support. The benefit would be that we hopefully already get some feedback if this breaks something before we make the release.

packets.go Outdated
plain := make([]byte, 20)
for k, v := range []byte(mc.cfg.Passwd) {
plain[k] = byte(v)
}
Copy link
Member

@methane methane May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When len(mc.cfg.Passwd) > 20, this code may overflow.
Could we just use copy(plain, mc.cfg.Passwd) here?

packets.go Outdated
plain[k] = byte(v)
}
for i := range plain {
plain[i] ^= cipher[i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(plain) == 20, but how about len(cipher)?
Shouldn't we do cipher[i % len(cipher)]?

Copy link
Contributor Author

@nakagami nakagami May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Please fix only above. (len(mc.cfg.Passwd) > 20 case).

Copy link
Contributor Author

@nakagami nakagami May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, There is no limitation about password length (< 20) when caching_sha2_password.
Now fix it 84f6018

@methane
Copy link
Member

methane commented May 17, 2018

@nakagami Would you add MySQL 8.0 test to .travis.yml?
It may be very similar to MySQL 5.7 test.

@nakagami
Copy link
Contributor Author

Would you add MySQL 8.0 test to .travis.yml?

Sorry, it is difficult for me.

@julienschmidt
Copy link
Member

@nakagami
Copy link
Contributor Author

Sorry, gofmt & push now

@julienschmidt
Copy link
Member

@methane any other requested changes or is this PR ready for merge now?

@methane
Copy link
Member

methane commented May 19, 2018

I want to add MySQL 8 test on Travis, using caching_sha2 auth.

@julienschmidt
Copy link
Member

See https://github.com/go-sql-driver/mysql/tree/travis-mysql8 / https://travis-ci.org/go-sql-driver/mysql/jobs/381084434. I'll submit a separate PR which also fixes the LOAD DATA LOCAL INFILE test.

@julienschmidt julienschmidt merged commit f557730 into go-sql-driver:master May 19, 2018
@julienschmidt
Copy link
Member

Thanks a lot @nakagami!

@doug-ess

This comment has been minimized.

@methane

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants