Skip to content

Commit b695554

Browse files
author
Jose Ramirez
committed
Bug #27571593 CONN FAILS FOR USER CREATED USING MYSQL_PASSWD(SERV STRD WITH SHA256)-WL#11618
Fixed the way the password is generated for ssl based connections with the sha256_password which was missing an initial byte with the password's length.
1 parent 70d0daf commit b695554

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Source/MySql.Data/Authentication/Sha256AuthenticationPlugin.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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");

Tests/MySql.Data.Tests/MySqlConnectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void SetFixture(SetUpClass data)
4545
{
4646
st = data;
4747
if (st.conn.State != ConnectionState.Open && !st.conn.SoftClosed)
48-
st.conn.Open();
48+
st.conn.Open();
4949
}
5050

5151
[Fact]

0 commit comments

Comments
 (0)