Skip to content

Commit af9889e

Browse files
committed
Merge branch 'master' into connector-interface-support
2 parents 255f988 + 1b9eda2 commit af9889e

File tree

11 files changed

+237
-147
lines changed

11 files changed

+237
-147
lines changed

AUTHORS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Jacek Szwec <szwec.jacek at gmail.com>
4141
James Harr <james.harr at gmail.com>
4242
Jeff Hodges <jeff at somethingsimilar.com>
4343
Jeffrey Charles <jeffreycharles at gmail.com>
44+
Jerome Meyer <jxmeyer at gmail.com>
4445
Jian Zhen <zhenjl at gmail.com>
4546
Joshua Prunier <joshua.prunier at gmail.com>
4647
Julien Lefevre <julien.lefevr at gmail.com>
@@ -73,7 +74,9 @@ Shuode Li <elemount at qq.com>
7374
Soroush Pour <me at soroushjp.com>
7475
Stan Putrya <root.vagner at gmail.com>
7576
Stanley Gunawan <gunawan.stanley at gmail.com>
77+
Steven Hartland <steven.hartland at multiplay.co.uk>
7678
Thomas Wodarek <wodarekwebpage at gmail.com>
79+
Tom Jenkinson <tom at tjenkinson.me>
7780
Xiangyu Hu <xiangyu.hu at outlook.com>
7881
Xiaobing Jiang <s7v7nislands at gmail.com>
7982
Xiuming Chen <cc at cxm.cc>
@@ -89,3 +92,4 @@ Keybase Inc.
8992
Percona LLC
9093
Pivotal Inc.
9194
Stripe Inc.
95+
Multiplay Ltd.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ Timeout for establishing connections, aka dial timeout. The value must be a deci
328328

329329
```
330330
Type: bool / string
331-
Valid Values: true, false, skip-verify, <name>
331+
Valid Values: true, false, skip-verify, preferred, <name>
332332
Default: false
333333
```
334334

335-
`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side). Use a custom value registered with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
335+
`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side) or use `preferred` to use TLS only when advertised by the server. This is similar to `skip-verify`, but additionally allows a fallback to a connection which is not encrypted. Neither `skip-verify` nor `preferred` add any reliable security. You can use a custom TLS config after registering it with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
336336

337337

338338
##### `writeTimeout`

auth.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -234,64 +234,64 @@ func (mc *mysqlConn) sendEncryptedPassword(seed []byte, pub *rsa.PublicKey) erro
234234
if err != nil {
235235
return err
236236
}
237-
return mc.writeAuthSwitchPacket(enc, false)
237+
return mc.writeAuthSwitchPacket(enc)
238238
}
239239

240-
func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, bool, error) {
240+
func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
241241
switch plugin {
242242
case "caching_sha2_password":
243243
authResp := scrambleSHA256Password(authData, mc.cfg.Passwd)
244-
return authResp, false, nil
244+
return authResp, nil
245245

246246
case "mysql_old_password":
247247
if !mc.cfg.AllowOldPasswords {
248-
return nil, false, ErrOldPassword
248+
return nil, ErrOldPassword
249249
}
250250
// Note: there are edge cases where this should work but doesn't;
251251
// this is currently "wontfix":
252252
// https://github.com/go-sql-driver/mysql/issues/184
253-
authResp := scrambleOldPassword(authData[:8], mc.cfg.Passwd)
254-
return authResp, true, nil
253+
authResp := append(scrambleOldPassword(authData[:8], mc.cfg.Passwd), 0)
254+
return authResp, nil
255255

256256
case "mysql_clear_password":
257257
if !mc.cfg.AllowCleartextPasswords {
258-
return nil, false, ErrCleartextPassword
258+
return nil, ErrCleartextPassword
259259
}
260260
// http://dev.mysql.com/doc/refman/5.7/en/cleartext-authentication-plugin.html
261261
// http://dev.mysql.com/doc/refman/5.7/en/pam-authentication-plugin.html
262-
return []byte(mc.cfg.Passwd), true, nil
262+
return append([]byte(mc.cfg.Passwd), 0), nil
263263

264264
case "mysql_native_password":
265265
if !mc.cfg.AllowNativePasswords {
266-
return nil, false, ErrNativePassword
266+
return nil, ErrNativePassword
267267
}
268268
// https://dev.mysql.com/doc/internals/en/secure-password-authentication.html
269269
// Native password authentication only need and will need 20-byte challenge.
270270
authResp := scramblePassword(authData[:20], mc.cfg.Passwd)
271-
return authResp, false, nil
271+
return authResp, nil
272272

273273
case "sha256_password":
274274
if len(mc.cfg.Passwd) == 0 {
275-
return nil, true, nil
275+
return []byte{0}, nil
276276
}
277277
if mc.cfg.tls != nil || mc.cfg.Net == "unix" {
278278
// write cleartext auth packet
279-
return []byte(mc.cfg.Passwd), true, nil
279+
return append([]byte(mc.cfg.Passwd), 0), nil
280280
}
281281

282282
pubKey := mc.cfg.pubKey
283283
if pubKey == nil {
284284
// request public key from server
285-
return []byte{1}, false, nil
285+
return []byte{1}, nil
286286
}
287287

288288
// encrypted password
289289
enc, err := encryptPassword(mc.cfg.Passwd, authData, pubKey)
290-
return enc, false, err
290+
return enc, err
291291

292292
default:
293293
errLog.Print("unknown auth plugin:", plugin)
294-
return nil, false, ErrUnknownPlugin
294+
return nil, ErrUnknownPlugin
295295
}
296296
}
297297

@@ -315,11 +315,11 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
315315

316316
plugin = newPlugin
317317

318-
authResp, addNUL, err := mc.auth(authData, plugin)
318+
authResp, err := mc.auth(authData, plugin)
319319
if err != nil {
320320
return err
321321
}
322-
if err = mc.writeAuthSwitchPacket(authResp, addNUL); err != nil {
322+
if err = mc.writeAuthSwitchPacket(authResp); err != nil {
323323
return err
324324
}
325325

@@ -352,21 +352,23 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
352352
case cachingSha2PasswordPerformFullAuthentication:
353353
if mc.cfg.tls != nil || mc.cfg.Net == "unix" {
354354
// write cleartext auth packet
355-
err = mc.writeAuthSwitchPacket([]byte(mc.cfg.Passwd), true)
355+
err = mc.writeAuthSwitchPacket(append([]byte(mc.cfg.Passwd), 0))
356356
if err != nil {
357357
return err
358358
}
359359
} else {
360360
pubKey := mc.cfg.pubKey
361361
if pubKey == nil {
362362
// request public key from server
363-
data := mc.buf.takeSmallBuffer(4 + 1)
363+
data, err := mc.buf.takeSmallBuffer(4 + 1)
364+
if err != nil {
365+
return err
366+
}
364367
data[4] = cachingSha2PasswordRequestPublicKey
365368
mc.writePacket(data)
366369

367370
// parse public key
368-
data, err := mc.readPacket()
369-
if err != nil {
371+
if data, err = mc.readPacket(); err != nil {
370372
return err
371373
}
372374

0 commit comments

Comments
 (0)