@@ -209,7 +209,7 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, bool, error)
209
209
}
210
210
if mc .cfg .tls != nil || mc .cfg .Net == "unix" {
211
211
// write cleartext auth packet
212
- return []byte (mc .cfg .Passwd ), true , nil // TODO: nul-terminate
212
+ return []byte (mc .cfg .Passwd ), true , nil
213
213
}
214
214
// request public key
215
215
// TODO: allow to specify a local file with the pub key via the DSN
@@ -234,6 +234,9 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
234
234
// sent and we have to keep using the cipher sent in the init packet.
235
235
if authData == nil {
236
236
authData = oldAuthData
237
+ } else {
238
+ // copy data from read buffer to owned slice
239
+ copy (oldAuthData , authData )
237
240
}
238
241
239
242
plugin = newPlugin
@@ -316,18 +319,23 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
316
319
}
317
320
318
321
case "sha256_password" :
319
- block , _ := pem .Decode (authData )
320
- pub , err := x509 .ParsePKIXPublicKey (block .Bytes )
321
- if err != nil {
322
- return err
323
- }
322
+ switch len (authData ) {
323
+ case 0 :
324
+ return nil // auth successful
325
+ default :
326
+ block , _ := pem .Decode (authData )
327
+ pub , err := x509 .ParsePKIXPublicKey (block .Bytes )
328
+ if err != nil {
329
+ return err
330
+ }
324
331
325
- // send encrypted password
326
- err = mc .sendEncryptedPassword (oldAuthData , pub .(* rsa.PublicKey ))
327
- if err != nil {
328
- return err
332
+ // send encrypted password
333
+ err = mc .sendEncryptedPassword (oldAuthData , pub .(* rsa.PublicKey ))
334
+ if err != nil {
335
+ return err
336
+ }
337
+ return mc .readResultOK ()
329
338
}
330
- return mc .readResultOK ()
331
339
332
340
default :
333
341
return nil // auth successful
0 commit comments