Skip to content

Commit a708ae3

Browse files
Update NetCore
1 parent ab564ce commit a708ae3

2 files changed

Lines changed: 67 additions & 63 deletions

File tree

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -923,44 +923,48 @@ internal static class SslProtocolsHelper
923923
{
924924
private static string ToFriendlyName(this SslProtocols protocol)
925925
{
926-
string name ;
926+
string name;
927927

928-
switch (protocol)
928+
/* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later
929+
* This driver does not support this version yet!
930+
if ((protocol & SslProtocols.Tls13) == SslProtocols.Tls13)
929931
{
932+
name = "TLS 1.3";
933+
}*/
934+
if((protocol & SslProtocols.Tls12) == SslProtocols.Tls12)
935+
{
936+
name = "TLS 1.2";
937+
}
938+
else if ((protocol & SslProtocols.Tls11) == SslProtocols.Tls11)
939+
{
940+
name = "TLS 1.1";
941+
}
942+
else if ((protocol & SslProtocols.Tls) == SslProtocols.Tls)
943+
{
944+
name = "TLS 1.0";
945+
}
930946
#pragma warning disable CS0618 // Type or member is obsolete: SSL is depricated
931-
case SslProtocols.Ssl2:
932-
name = "SSL 2";
933-
break;
934-
case SslProtocols.Ssl3:
935-
name = "SSL 3";
936-
break;
937-
#pragma warning restore CS0618 // Type or member is obsolete: SSL is depricated
938-
/* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later
939-
* This driver does not support this version yet!
940-
case SslProtocols.Tls13:
941-
name = "TLS 1.3";
942-
break;
943-
*/
944-
case SslProtocols.Tls:
945-
name = "TLS 1.0";
946-
break;
947-
case SslProtocols.Tls11:
948-
name = "TLS 1.1";
949-
break;
950-
case SslProtocols.Tls12:
951-
name = "TLS 1.2";
952-
break;
953-
default:
954-
name = protocol.ToString();
955-
break;
956-
};
947+
else if ((protocol & SslProtocols.Ssl3) == SslProtocols.Ssl3)
948+
{
949+
name = "SSL 3.0";
950+
}
951+
else if ((protocol & SslProtocols.Ssl2) == SslProtocols.Ssl2)
952+
#pragma warning disable CS0618 // Type or member is obsolete: SSL is depricated
953+
{
954+
name = "SSL 2.0";
955+
}
956+
else
957+
{
958+
name = protocol.ToString();
959+
}
960+
957961
return name;
958962
}
959963
public static string GetProtocolWarning(this SslProtocols protocol)
960964
{
961965
string message = string.Empty;
962966
#pragma warning disable CS0618 // Type or member is obsolete : SSL is depricated
963-
if ((protocol & (SslProtocols.Ssl2 | SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11)) == protocol)
967+
if ((protocol & (SslProtocols.Ssl2 | SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11)) != SslProtocols.None)
964968
#pragma warning restore CS0618 // Type or member is obsolete : SSL is depricated
965969
{
966970
message = SRHelper.Format(SR.SEC_ProtocolWarning, protocol.ToFriendlyName());

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -333,43 +333,43 @@ internal override uint GenerateSspiClientContext(byte[] receivedBuff, uint recei
333333
internal override uint WaitForSSLHandShakeToComplete(out int protocolVersion)
334334
{
335335
uint returnValue = SNINativeMethodWrapper.SNIWaitForSSLHandshakeToComplete(Handle, GetTimeoutRemaining(), out uint nativeProtocolVersion);
336-
337-
switch ((NativeProtocols)nativeProtocolVersion)
336+
var nativeProtocol = (NativeProtocols)nativeProtocolVersion;
337+
338+
/* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later
339+
* This driver does not support this version yet!
340+
if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_SERVER))
341+
{
342+
protocolVersion = (int)SslProtocols.Tls13;
343+
}*/
344+
if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_SERVER))
345+
{
346+
protocolVersion = (int)SslProtocols.Tls12;
347+
}
348+
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_1_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_1_SERVER))
349+
{
350+
protocolVersion = (int)SslProtocols.Tls11;
351+
}
352+
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_0_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_0_SERVER))
353+
{
354+
protocolVersion = (int)SslProtocols.Tls;
355+
}
356+
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_SSL3_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_SSL3_SERVER))
338357
{
339-
case NativeProtocols.SP_PROT_SSL2_SERVER:
340-
case NativeProtocols.SP_PROT_SSL2_CLIENT:
341358
#pragma warning disable CS0618 // Type or member is obsolete : SSL is depricated
342-
protocolVersion = (int)SslProtocols.Ssl2;
343-
break;
344-
case NativeProtocols.SP_PROT_SSL3_SERVER:
345-
case NativeProtocols.SP_PROT_SSL3_CLIENT:
346-
protocolVersion = (int)SslProtocols.Ssl3;
359+
protocolVersion = (int)SslProtocols.Ssl3;
360+
}
361+
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_SSL2_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_SSL2_SERVER))
362+
{
363+
protocolVersion = (int)SslProtocols.Ssl2;
347364
#pragma warning restore CS0618 // Type or member is obsolete : SSL is depricated
348-
break;
349-
case NativeProtocols.SP_PROT_TLS1_0_SERVER:
350-
case NativeProtocols.SP_PROT_TLS1_0_CLIENT:
351-
protocolVersion = (int)SslProtocols.Tls;
352-
break;
353-
case NativeProtocols.SP_PROT_TLS1_1_SERVER:
354-
case NativeProtocols.SP_PROT_TLS1_1_CLIENT:
355-
protocolVersion = (int)SslProtocols.Tls11;
356-
break;
357-
case NativeProtocols.SP_PROT_TLS1_2_SERVER:
358-
case NativeProtocols.SP_PROT_TLS1_2_CLIENT:
359-
protocolVersion = (int)SslProtocols.Tls12;
360-
break;
361-
/* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later
362-
* This driver does not support this version yet!
363-
case NativeProtocols.SP_PROT_TLS1_3_SERVER:
364-
case NativeProtocols.SP_PROT_TLS1_3_CLIENT:
365-
protocolVersion = (int)SslProtocols.Tls13;
366-
break;
367-
*/
368-
case NativeProtocols.SP_PROT_NONE:
369-
protocolVersion = (int)SslProtocols.None;
370-
break;
371-
default:
372-
throw new InvalidOperationException("Unknown protocol.");
365+
}
366+
else if(nativeProtocol.HasFlag(NativeProtocols.SP_PROT_NONE))
367+
{
368+
protocolVersion = (int)SslProtocols.None;
369+
}
370+
else
371+
{
372+
throw new ArgumentException(SRHelper.Format(SRHelper.net_invalid_enum, nameof(NativeProtocols)), nameof(NativeProtocols));
373373
}
374374
return returnValue;
375375
}

0 commit comments

Comments
 (0)