Skip to content

Commit 0dee607

Browse files
author
Jose Ramirez
committed
WL-11618 Change caching_sha2_password padding
Updated the caching_sha2_password RSA encryption padding to RSA_PKCS1_OAEP_PADDING for server versions 8.0.5+.
1 parent ad059fe commit 0dee607

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
6.9.12
2+
- Updated the RSA key encryption padding to RSA_PKCS1_OAEP_PADDING for the caching_sha2_password authentication plugin when connecting to server 8.0.5 (or later) (WL11618).
23
- Added support for the caching_sha2_password authentication plugin introduced in server 8.0.3.
34
Added support for RSA key encription in the sha256_password authentication plugin (WL11285).
45
- Added support for MySQL 8 server features (WL11325).

Source/MySql.Data/Authentication/CachingSha2AuthenticationPlugin.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,34 @@ private byte[] GetRsaPassword(string password, byte[] seedBytes, byte[] rawPubli
120120
byte[] obfuscated = GetXor(AliasText.Encoding.Default.GetBytes(password), seedBytes);
121121

122122
// Encrypt the password and send it to the server.
123+
if (this.ServerVersion >= new Version("8.0.5"))
124+
{
123125
#if NETSTANDARD1_3
124-
RSA rsa = MySqlPemReader.ConvertPemToRSAProvider(rawPublicKey);
125-
if (rsa == null) throw new MySqlException(Resources.UnableToReadRSAKey);
126+
RSA rsa = MySqlPemReader.ConvertPemToRSAProvider(rawPublicKey);
127+
if (rsa == null) throw new MySqlException(Resources.UnableToReadRSAKey);
126128

127-
// TODO in MySQL 8.0.3 the RSA_PKCS1_PADDING is used in caching_sha2_password full auth stage but in 8.0.4 it should be changed to RSA_PKCS1_OAEP_PADDING, the same as in sha256_password.
128-
return rsa.Encrypt(obfuscated, RSAEncryptionPadding.Pkcs1);
129+
return rsa.Encrypt(obfuscated, RSAEncryptionPadding.OaepSHA1);
129130
#else
130-
RSACryptoServiceProvider rsa = MySqlPemReader.ConvertPemToRSAProvider(rawPublicKey);
131-
if (rsa == null) throw new MySqlException(Resources.UnableToReadRSAKey);
132-
return rsa.Encrypt(obfuscated, false);
131+
RSACryptoServiceProvider rsa = MySqlPemReader.ConvertPemToRSAProvider(rawPublicKey);
132+
if (rsa == null) throw new MySqlException(Resources.UnableToReadRSAKey);
133+
134+
return rsa.Encrypt(obfuscated, true);
133135
#endif
136+
}
137+
else
138+
{
139+
#if NETSTANDARD1_3
140+
RSA rsa = MySqlPemReader.ConvertPemToRSAProvider(rawPublicKey);
141+
if (rsa == null) throw new MySqlException(Resources.UnableToReadRSAKey);
142+
143+
return rsa.Encrypt(obfuscated, RSAEncryptionPadding.Pkcs1);
144+
#else
145+
RSACryptoServiceProvider rsa = MySqlPemReader.ConvertPemToRSAProvider(rawPublicKey);
146+
if (rsa == null) throw new MySqlException(Resources.UnableToReadRSAKey);
147+
148+
return rsa.Encrypt(obfuscated, false);
149+
#endif
150+
}
134151
}
135152

136153
public override object GetPassword()

0 commit comments

Comments
 (0)