Skip to content

Commit 3a69455

Browse files
Merge pull request #16 from eByte23/bugifx/6.9_netstandard_fix_ssl_auth_error
Bugifx/6.9 netstandard fix ssl auth error
2 parents b6f7592 + d03089e commit 3a69455

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

Diff for: Source/MySql.Data/Authentication/AuthenticationManager.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ static AuthenticationPluginManager()
3636
{
3737
plugins["mysql_native_password"] = new PluginInfo("MySql.Data.MySqlClient.Authentication.MySqlNativePasswordPlugin");
3838
plugins["sha256_password"] = new PluginInfo("MySql.Data.MySqlClient.Authentication.Sha256AuthenticationPlugin");
39-
#if !CF && !RT && !NETSTANDARD1_3
39+
#if !CF && !RT
4040
plugins["authentication_windows_client"] = new PluginInfo("MySql.Data.MySqlClient.Authentication.MySqlWindowsAuthenticationPlugin");
41+
#if !NETSTANDARD1_3
4142
if (MySqlConfiguration.Settings != null && MySqlConfiguration.Settings.AuthenticationPlugins != null)
4243
{
4344
foreach (AuthenticationPluginConfigurationElement e in MySqlConfiguration.Settings.AuthenticationPlugins)
4445
plugins[e.Name] = new PluginInfo(e.Type);
4546
}
4647
#endif
47-
}
48+
#endif
49+
}
4850

49-
public static MySqlAuthenticationPlugin GetPlugin(string method)
51+
public static MySqlAuthenticationPlugin GetPlugin(string method)
5052
{
5153
if (!plugins.ContainsKey(method))
5254
throw new MySqlException(String.Format(Resources.AuthenticationMethodNotSupported, method));

Diff for: Source/MySql.Data/Authentication/WindowsAuthenticationPlugin.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ internal class MySqlWindowsAuthenticationPlugin : MySqlAuthenticationPlugin
4747
protected override void CheckConstraints()
4848
{
4949
string platform = String.Empty;
50-
#if !RT && !NETSTANDARD1_3
51-
int p = (int)Environment.OSVersion.Platform;
52-
if ((p == 4) || (p == 128))
50+
#if !RT
51+
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
5352
platform = "Unix";
54-
else if (Environment.OSVersion.Platform == PlatformID.MacOSX)
53+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
5554
platform = "Mac OS/X";
5655

5756
if (!String.IsNullOrEmpty(platform))

Diff for: Source/MySql.Data/NativeDriver.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
using MySql.Data.MySqlClient.Authentication;
3232
using System.Reflection;
3333
using System.ComponentModel;
34+
using System.Security.Cryptography.X509Certificates;
35+
using System.Net.Security;
36+
using System.Security.Authentication;
3437
#if RT || NETSTANDARD1_3
3538
using System.Linq;
3639
#endif
@@ -195,16 +198,16 @@ public async void Open()
195198
try
196199
{
197200
#if NETSTANDARD1_3
198-
baseStream = StreamCreator.GetStream(Settings).Result;
201+
baseStream = StreamCreator.GetStream(Settings).Result;
199202
#else
200-
baseStream = await StreamCreator.GetStream(Settings);
203+
baseStream = await StreamCreator.GetStream(Settings);
201204
#endif
202205
#if !CF && !RT && !NETSTANDARD1_3
203206
if (Settings.IncludeSecurityAsserts)
204207
MySqlSecurityPermission.CreatePermissionSet(false).Assert();
205208
#endif
206-
}
207-
catch (System.Security.SecurityException)
209+
}
210+
catch (System.Security.SecurityException)
208211
{
209212
throw;
210213
}
@@ -277,7 +280,7 @@ public async void Open()
277280
packet.WriteByte(33); //character set utf-8
278281
packet.Write(new byte[23]);
279282

280-
#if !CF && !RT && !NETSTANDARD1_3
283+
#if !CF && !RT
281284
if ((serverCaps & ClientFlags.SSL) == 0)
282285
{
283286
if ((Settings.SslMode != MySqlSslMode.None)
@@ -322,7 +325,7 @@ public async void Open()
322325
stream.MaxBlockSize = maxSinglePacket;
323326
}
324327

325-
#if !CF && !RT && !NETSTANDARD1_3
328+
#if !CF && !RT
326329

327330
#region SSL
328331

Diff for: Source/MySql.Data/extensions/RT/ExtensionMethods.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
using System.Collections.Generic;
2525
using System.IO;
2626
using System.Linq;
27+
using System.Net.Security;
2728
using System.Reflection;
29+
using System.Security.Authentication;
30+
using System.Security.Cryptography.X509Certificates;
2831
using System.Text;
2932
using System.Threading;
3033
using System.Threading.Tasks;
@@ -81,5 +84,13 @@ public static PropertyInfo[] GetProperties(this Type type)
8184
{
8285
return type.GetRuntimeProperties().ToArray();
8386
}
84-
}
87+
88+
#if NETSTANDARD1_3
89+
public static void AuthenticateAsClient(this SslStream ss, string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
90+
{
91+
ss.AuthenticateAsClientAsync(targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation).Wait();
92+
}
93+
94+
#endif
95+
}
8596
}

Diff for: Source/MySql.Data/project.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"dependencies": {
2525
"Microsoft.CSharp": "4.0.1-rc2-24027",
26+
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-final",
2627
"System.Collections": "4.0.11-rc2-24027",
2728
"System.Collections.Specialized": "4.0.1-rc2-24027",
2829
"System.Console": "4.0.0-rc2-24027",
@@ -49,7 +50,9 @@
4950
"System.Net.Sockets": "4.1.0-rc2-24027",
5051
"System.Security.Cryptography.Algorithms": "4.1.0-rc2-24027",
5152
"System.Collections.NonGeneric": "4.0.1-rc2-24027",
52-
"System.Reflection.TypeExtensions": "4.1.0-rc2-24027"
53+
"System.Reflection.TypeExtensions": "4.1.0-rc2-24027",
54+
"System.Security.Cryptography.X509Certificates": "4.1.0-rc2-24027",
55+
"System.Net.Security": "4.0.0-rc2-24027"
5356
},
5457
"frameworks": {
5558
"netstandard1.3": {

0 commit comments

Comments
 (0)