@@ -52,19 +52,19 @@ public class Sha256AuthenticationPlugin : MySqlAuthenticationPlugin
5252 protected override byte [ ] MoreData ( byte [ ] data )
5353 {
5454 rawPubkey = data ;
55- byte [ ] buffer = GetPassword ( ) as byte [ ] ;
55+ byte [ ] buffer = GetNonLengthEncodedPassword ( ) as byte [ ] ;
5656 return buffer ;
5757 }
5858
5959 public override object GetPassword ( )
6060 {
6161 if ( Settings . SslMode != MySqlSslMode . None )
6262 {
63- // send as clear text, since the channel is already encrypted
6463 byte [ ] passBytes = Encoding . GetBytes ( Settings . Password ) ;
65- byte [ ] buffer = new byte [ passBytes . Length + 1 ] ;
66- Array . Copy ( passBytes , 0 , buffer , 0 , passBytes . Length ) ;
67- buffer [ passBytes . Length ] = 0 ;
64+ byte [ ] buffer = new byte [ passBytes . Length + 2 ] ;
65+ Array . Copy ( passBytes , 0 , buffer , 1 , passBytes . Length ) ;
66+ buffer [ 0 ] = ( byte ) ( passBytes . Length + 1 ) ;
67+ buffer [ buffer . Length - 1 ] = 0x00 ;
6868 return buffer ;
6969 }
7070 else
@@ -83,6 +83,21 @@ public override object GetPassword()
8383 }
8484 }
8585
86+ private byte [ ] GetNonLengthEncodedPassword ( )
87+ {
88+ // Required for AuthChange requests.
89+ if ( Settings . SslMode != MySqlSslMode . None )
90+ {
91+ // Send as clear text, since the channel is already encrypted.
92+ byte [ ] passBytes = Encoding . GetBytes ( Settings . Password ) ;
93+ byte [ ] buffer = new byte [ passBytes . Length + 1 ] ;
94+ Array . Copy ( passBytes , 0 , buffer , 0 , passBytes . Length ) ;
95+ buffer [ passBytes . Length ] = 0 ;
96+ return buffer ;
97+ }
98+ else return GetPassword ( ) as byte [ ] ;
99+ }
100+
86101 private byte [ ] GetRsaPassword ( string password , byte [ ] seedBytes , byte [ ] rawPublicKey )
87102 {
88103 if ( password . Length == 0 ) return new byte [ 1 ] ;
@@ -100,7 +115,7 @@ private byte[] GetRsaPassword(string password, byte[] seedBytes, byte[] rawPubli
100115 throw new MySqlException ( "RSA2" ) ;
101116 return rsa . Encrypt ( obfuscated , RSAEncryptionPadding . OaepSHA1 ) ;
102117#else
103- RSACryptoServiceProvider rsa = MySqlPemReader . ConvertPemToRSAProvider ( rawPublicKey ) ;
118+ RSACryptoServiceProvider rsa = MySqlPemReader . ConvertPemToRSAProvider ( rawPublicKey ) ;
104119 if ( rsa == null )
105120 //throw new MySqlException(Resources.UnableToReadRSAKey);
106121 throw new MySqlException ( "RSA2" ) ;
0 commit comments