|
6 | 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
7 | 7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
|
8 | 8 |
|
| 9 | +// +build go1.8 |
| 10 | + |
9 | 11 | package mysql
|
10 | 12 |
|
11 | 13 | import (
|
@@ -67,20 +69,31 @@ func (c *Config) Connect(ctx context.Context) (driver.Conn, error) {
|
67 | 69 | mc.writeTimeout = mc.cfg.WriteTimeout
|
68 | 70 |
|
69 | 71 | // Reading Handshake Initialization Packet
|
70 |
| - cipher, err := mc.readInitPacket() |
| 72 | + authData, plugin, err := mc.readHandshakePacket() |
71 | 73 | if err != nil {
|
72 | 74 | mc.cleanup()
|
73 | 75 | return nil, err
|
74 | 76 | }
|
75 | 77 |
|
76 | 78 | // Send Client Authentication Packet
|
77 |
| - if err = mc.writeAuthPacket(cipher); err != nil { |
| 79 | + authResp, addNUL, err := mc.auth(authData, plugin) |
| 80 | + if err != nil { |
| 81 | + // try the default auth plugin, if using the requested plugin failed |
| 82 | + errLog.Print("could not use requested auth plugin '"+plugin+"': ", err.Error()) |
| 83 | + plugin = defaultAuthPlugin |
| 84 | + authResp, addNUL, err = mc.auth(authData, plugin) |
| 85 | + if err != nil { |
| 86 | + mc.cleanup() |
| 87 | + return nil, err |
| 88 | + } |
| 89 | + } |
| 90 | + if err = mc.writeHandshakeResponsePacket(authResp, addNUL, plugin); err != nil { |
78 | 91 | mc.cleanup()
|
79 | 92 | return nil, err
|
80 | 93 | }
|
81 | 94 |
|
82 | 95 | // Handle response to auth packet, switch methods if possible
|
83 |
| - if err = handleAuthResult(mc, cipher); err != nil { |
| 96 | + if err = mc.handleAuthResult(authData, plugin); err != nil { |
84 | 97 | // Authentication failed and MySQL has already closed the connection
|
85 | 98 | // (https://dev.mysql.com/doc/internals/en/authentication-fails.html).
|
86 | 99 | // Do not send COM_QUIT, just cleanup and return the error.
|
|
0 commit comments