Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TDS8 - Enable retrieval of TLS 1.3 SSL Protocol from SNI on .NET Core #1821

Merged
merged 3 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enable tls1.3 ssl protocol on netcore
  • Loading branch information
lcheunglci committed Oct 31, 2022
commit 35d3721aadf46859d28e76f0c66e2a10e6a7890c
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,20 @@ internal void Connect(
// On Instance failure re-connect and flush SNI named instance cache.
_physicalStateObj.SniContext = SniContext.Snix_Connect;

_physicalStateObj.CreatePhysicalSNIHandle(serverInfo.ExtendedServerName, ignoreSniOpenTimeout, timerExpire, out instanceName, ref _sniSpnBuffer, true, true, fParallel,
_connHandler.ConnectionOptions.IPAddressPreference, FQDNforDNSCache, ref _connHandler.pendingSQLDNSObject, serverInfo.ServerSPN, integratedSecurity);
_physicalStateObj.CreatePhysicalSNIHandle(serverInfo.ExtendedServerName,
ignoreSniOpenTimeout,
timerExpire,
out instanceName,
ref _sniSpnBuffer,
true,
true, fParallel,
_connHandler.ConnectionOptions.IPAddressPreference,
FQDNforDNSCache,
ref _connHandler.pendingSQLDNSObject,
serverInfo.ServerSPN,
integratedSecurity,
encrypt == SqlConnectionEncryptOption.Strict,
hostNameInCertificate);

if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
{
Expand Down Expand Up @@ -552,6 +564,7 @@ internal void Connect(
throw SQL.InstanceFailure();
}
}
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Prelogin handshake successful");

if (_fMARS && marsCapable)
{
Expand Down Expand Up @@ -1010,7 +1023,8 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(
uint info = (shouldValidateServerCert ? TdsEnums.SNI_SSL_VALIDATE_CERTIFICATE : 0)
| (is2005OrLater ? TdsEnums.SNI_SSL_USE_SCHANNEL_CACHE : 0);

EnableSsl(info, encrypt, integratedSecurity);

EnableSsl(info, encrypt == SqlConnectionEncryptOption.Mandatory, integratedSecurity);
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,16 @@ internal override uint WaitForSSLHandShakeToComplete(out int protocolVersion)
var nativeProtocol = (NativeProtocols)nativeProtocolVersion;

/* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later
* This driver does not support this version yet!
* This driver does not support this version yet! */
#if NETCOREAPP3_1_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are not supporting netcoreapp3.1 it should suffice if we just want to check for NETCOREAPP and omit the version.

Suggested change
#if NETCOREAPP3_1_OR_GREATER
#if NETCOREAPP

if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_SERVER))
{
protocolVersion = (int)SslProtocols.Tls13;
}*/
}
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_SERVER))
#else
if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_SERVER))
#endif
Copy link
Contributor

@DavoudEshtehari DavoudEshtehari Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not required to be the first statement in the chain of if-else statements. This additional condition can be added as a else if just for simplification.
Also, the related inline comments won't be valid anymore.

{
protocolVersion = (int)SslProtocols.Tls12;
}
Expand Down