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

Adding TDS8 version for TDSLogin #1657

Merged
merged 12 commits into from
Jul 23, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ private void CompleteLogin(bool enlistOK)
_parser._physicalStateObj.SniContext = SniContext.Snix_Login;
}

private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword, SecureString newSecurePassword)
private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword, SecureString newSecurePassword, SqlConnectionEncryptOption encrypt)
{
// create a new login record
SqlLogin login = new SqlLogin();
Expand Down Expand Up @@ -1351,7 +1351,7 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,
// The SQLDNSCaching feature is implicitly set
requestedFeatures |= TdsEnums.FeatureExtension.SQLDNSCaching;

_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData);
_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData, encrypt);
}

private void LoginFailure()
Expand Down Expand Up @@ -1917,7 +1917,7 @@ private void AttemptOneLogin(
_timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.LoginBegin);

_parser._physicalStateObj.SniContext = SniContext.Snix_Login;
this.Login(serverInfo, timeout, newPassword, newSecurePassword);
this.Login(serverInfo, timeout, newPassword, newSecurePassword, ConnectionOptions.Encrypt);

_timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth);
_timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.PostLogin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ internal sealed partial class TdsParser

private bool _is2012 = false;

private bool _is2022 = false;

private byte[][] _sniSpnBuffer = null;

// SqlStatistics
Expand Down Expand Up @@ -438,7 +440,7 @@ internal void Connect(

// AD Integrated behaves like Windows integrated when connecting to a non-fedAuth server
_physicalStateObj.CreatePhysicalSNIHandle(serverInfo.ExtendedServerName, ignoreSniOpenTimeout, timerExpire, out instanceName, ref _sniSpnBuffer,
false, true, fParallel, _connHandler.ConnectionOptions.IPAddressPreference, FQDNforDNSCache, ref _connHandler.pendingSQLDNSObject, serverInfo.ServerSPN ,
false, true, fParallel, _connHandler.ConnectionOptions.IPAddressPreference, FQDNforDNSCache, ref _connHandler.pendingSQLDNSObject, serverInfo.ServerSPN,
integratedSecurity || authType == SqlAuthenticationMethod.ActiveDirectoryIntegrated, encrypt == SqlConnectionEncryptOption.Strict,
hostNameInCertificate);

Expand Down Expand Up @@ -499,7 +501,7 @@ internal void Connect(
}

SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Sending prelogin handshake");
SendPreLoginHandshake(instanceName, encrypt,integratedSecurity);
SendPreLoginHandshake(instanceName, encrypt, integratedSecurity);

_connHandler.TimeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake);
_connHandler.TimeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake);
Expand Down Expand Up @@ -3639,10 +3641,17 @@ private bool TryProcessLoginAck(TdsParserStateObject stateObj, out SqlLoginAck s
}
_is2012 = true;
break;
case TdsEnums.TDS8_MAJOR << 24 | TdsEnums.TDS8_MINOR:
if (increment != TdsEnums.TDS8_INCREMENT)
{
throw SQL.InvalidTDSVersion();
}
_is2022 = true;
break;
default:
throw SQL.InvalidTDSVersion();
}

_is2012 |= _is2022;
_is2008 |= _is2012;
_is2005 |= _is2008;

Expand Down Expand Up @@ -7942,7 +7951,7 @@ internal int WriteFedAuthFeatureRequest(FederatedAuthenticationFeatureExtensionD
return len;
}

internal void TdsLogin(SqlLogin rec, TdsEnums.FeatureExtension requestedFeatures, SessionData recoverySessionData, FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData)
internal void TdsLogin(SqlLogin rec, TdsEnums.FeatureExtension requestedFeatures, SessionData recoverySessionData, FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData, SqlConnectionEncryptOption encrypt)
{
_physicalStateObj.SetTimeoutSeconds(rec.timeout);

Expand Down Expand Up @@ -8112,7 +8121,14 @@ internal void TdsLogin(SqlLogin rec, TdsEnums.FeatureExtension requestedFeatures
WriteInt(length, _physicalStateObj);
if (recoverySessionData == null)
{
WriteInt((TdsEnums.SQL2012_MAJOR << 24) | (TdsEnums.SQL2012_INCREMENT << 16) | TdsEnums.SQL2012_MINOR, _physicalStateObj);
if (encrypt == SqlConnectionEncryptOption.Strict)
{
WriteInt((TdsEnums.TDS8_MAJOR << 24) | (TdsEnums.TDS8_INCREMENT << 16) | TdsEnums.TDS8_MINOR, _physicalStateObj);
}
else
{
WriteInt((TdsEnums.SQL2012_MAJOR << 24) | (TdsEnums.SQL2012_INCREMENT << 16) | TdsEnums.SQL2012_MINOR, _physicalStateObj);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ private void CompleteLogin(bool enlistOK)
_parser._physicalStateObj.SniContext = SniContext.Snix_Login;
}

private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword, SecureString newSecurePassword)
private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword, SecureString newSecurePassword, SqlConnectionEncryptOption encrypt)
{
// create a new login record
SqlLogin login = new SqlLogin();
Expand Down Expand Up @@ -1630,7 +1630,7 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,
// The SQLDNSCaching feature is implicitly set
requestedFeatures |= TdsEnums.FeatureExtension.SQLDNSCaching;

_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData, _originalNetworkAddressInfo);
_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData, _originalNetworkAddressInfo, encrypt);
}

private void LoginFailure()
Expand Down Expand Up @@ -2310,7 +2310,7 @@ private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, SecureSt
timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.LoginBegin);

_parser._physicalStateObj.SniContext = SniContext.Snix_Login;
this.Login(serverInfo, timeout, newPassword, newSecurePassword);
this.Login(serverInfo, timeout, newPassword, newSecurePassword, ConnectionOptions.Encrypt);

timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth);
timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.PostLogin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ internal static void Assert(string message)

private bool _is2012 = false;

private bool _is2022 = false;

private byte[] _sniSpnBuffer = null;

// UNDONE - need to have some for both instances - both command and default???
Expand Down Expand Up @@ -4125,10 +4127,16 @@ private bool TryProcessLoginAck(TdsParserStateObject stateObj, out SqlLoginAck s
{ throw SQL.InvalidTDSVersion(); }
_is2012 = true;
break;
case (uint)TdsEnums.TDS8_MAJOR << 24 | TdsEnums.TDS8_MINOR:
if (increment != TdsEnums.TDS8_INCREMENT)
{ throw SQL.InvalidTDSVersion(); }
_is2022 = true;
break;
default:
throw SQL.InvalidTDSVersion();
}

_is2012 |= _is2022;
_is2008 |= _is2012;
_is2005 |= _is2008;
_is2000SP1 |= _is2005; // includes all lower versions
Expand Down Expand Up @@ -8791,7 +8799,8 @@ internal void TdsLogin(SqlLogin rec,
TdsEnums.FeatureExtension requestedFeatures,
SessionData recoverySessionData,
FederatedAuthenticationFeatureExtensionData fedAuthFeatureExtensionData,
SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo)
SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo,
SqlConnectionEncryptOption encrypt)
{
_physicalStateObj.SetTimeoutSeconds(rec.timeout);

Expand Down Expand Up @@ -8989,7 +8998,14 @@ internal void TdsLogin(SqlLogin rec,
WriteInt(length, _physicalStateObj);
if (recoverySessionData == null)
{
WriteInt((TdsEnums.SQL2012_MAJOR << 24) | (TdsEnums.SQL2012_INCREMENT << 16) | TdsEnums.SQL2012_MINOR, _physicalStateObj);
if (encrypt == SqlConnectionEncryptOption.Strict)
{
WriteInt((TdsEnums.TDS8_MAJOR << 24) | (TdsEnums.TDS8_INCREMENT << 16) | TdsEnums.TDS8_MINOR, _physicalStateObj);
}
else
{
WriteInt((TdsEnums.SQL2012_MAJOR << 24) | (TdsEnums.SQL2012_INCREMENT << 16) | TdsEnums.SQL2012_MINOR, _physicalStateObj);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,22 @@ public enum ActiveDirectoryWorkflow : byte
public const int SQL2005_MAJOR = 0x72; // the high-byte is sufficient to distinguish later versions
public const int SQL2008_MAJOR = 0x73;
public const int SQL2012_MAJOR = 0x74;
public const int TDS8_MAJOR = 0x08; // TDS8 version to be used at login7
public const string TDS8_Protocol = "tds/8.0"; //TDS8

// Increments:
public const int SQL2000SP1_INCREMENT = 0x00;
public const int SQL2005_INCREMENT = 0x09;
public const int SQL2008_INCREMENT = 0x0b;
public const int SQL2012_INCREMENT = 0x00;
public const int TDS8_INCREMENT = 0x00;

// Minors:
public const int SQL2000SP1_MINOR = 0x0001;
public const int SQL2005_RTM_MINOR = 0x0002;
public const int SQL2008_MINOR = 0x0003;
public const int SQL2012_MINOR = 0x0004;
public const int TDS8_MINOR = 0x00;

public const int ORDER_68000 = 1;
public const int USE_DB_ON = 1;
Expand Down