diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
index 494bd0b96c..501849a752 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
@@ -165,6 +165,9 @@
Microsoft\Data\SqlClient\AlwaysEncryptedEnclaveProviderUtils.cs
+
+ Microsoft\Data\SqlClient\AlwaysEncryptedHelperClasses.cs
+
Microsoft\Data\SqlClient\AlwaysEncryptedKeyConverter.cs
@@ -591,6 +594,9 @@
Microsoft\Data\SqlClient\TdsParser.cs
+
+ Microsoft\Data\SqlClient\TdsParserHelperClasses.cs
+
Microsoft\Data\SqlClient\TdsParserStateObject.cs
@@ -638,7 +644,6 @@
-
@@ -683,7 +688,6 @@
-
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
index 2a15e3245a..53f2aa04a9 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
@@ -30,14 +30,14 @@
full
-
+
$([System.IO.Path]::Combine('$(IntermediateOutputPath)\$(TargetFramework)','$(GeneratedSourceFileName)'))
-
+
True
@@ -213,6 +213,9 @@
Microsoft\Data\SqlClient\AlwaysEncryptedEnclaveProviderUtils.cs
+
+ Microsoft\Data\SqlClient\AlwaysEncryptedHelperClasses.cs
+
Microsoft\Data\SqlClient\AlwaysEncryptedKeyConverter.cs
@@ -624,6 +627,9 @@
Microsoft\Data\SqlClient\TdsRecordBufferSetter.cs
+
+ Microsoft\Data\SqlClient\TdsParserHelperClasses.cs
+
Microsoft\Data\SqlClient\TdsParserSessionPool.cs
@@ -712,7 +718,6 @@
-
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs
index 617e1a3b57..69605d85eb 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs
@@ -1676,15 +1676,15 @@ override public DataTable GetSchemaTable()
try
{
statistics = SqlStatistics.StartTimer(Statistics);
- if (_metaData == null || _metaData._schemaTable == null)
+ if (_metaData == null || _metaData.schemaTable == null)
{
if (this.MetaData != null)
{
- _metaData._schemaTable = BuildSchemaTable();
- Debug.Assert(_metaData._schemaTable != null, "No schema information yet!");
+ _metaData.schemaTable = BuildSchemaTable();
+ Debug.Assert(_metaData.schemaTable != null, "No schema information yet!");
}
}
- return _metaData?._schemaTable;
+ return _metaData?.schemaTable;
}
finally
{
@@ -4823,7 +4823,7 @@ internal TdsOperationStatus TrySetMetaData(_SqlMetaDataSet metaData, bool moreIn
_tableNames = null;
if (_metaData != null)
{
- _metaData._schemaTable = null;
+ _metaData.schemaTable = null;
_data = SqlBuffer.CreateBufferArray(metaData.Length);
}
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs
index fb0884bb36..758499f55f 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs
@@ -1300,7 +1300,7 @@ private void EnableSsl(uint info, SqlConnectionEncryptOption encrypt, bool integ
ThrowExceptionAndWarning(_physicalStateObj);
}
- string warningMessage = SslProtocolsHelper.GetProtocolWarning(protocolVersion);
+ string warningMessage = ((System.Security.Authentication.SslProtocols)protocolVersion).GetProtocolWarning();
if (!string.IsNullOrEmpty(warningMessage))
{
if (!encrypt && LocalAppContextSwitches.SuppressInsecureTLSWarning)
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
deleted file mode 100644
index 6a834da984..0000000000
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
+++ /dev/null
@@ -1,1392 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Data.SqlTypes;
-using System.Diagnostics;
-using System.Globalization;
-using System.Security;
-using System.Text;
-using Microsoft.Data.Common;
-using Microsoft.Data.SqlClient.Server;
-using Microsoft.Data.SqlTypes;
-
-namespace Microsoft.Data.SqlClient
-{
- internal enum CallbackType
- {
- Read = 0,
- Write = 1
- }
-
- internal enum EncryptionOptions
- {
- OFF,
- ON,
- NOT_SUP,
- REQ,
- LOGIN,
- OPTIONS_MASK = 0x3f,
- CTAIP = 0x40,
- CLIENT_CERT = 0x80,
- }
-
- internal enum PreLoginHandshakeStatus
- {
- Successful,
- InstanceFailure
- }
-
- internal enum PreLoginOptions
- {
- VERSION,
- ENCRYPT,
- INSTANCE,
- THREADID,
- MARS,
- TRACEID,
- FEDAUTHREQUIRED,
- NUMOPT,
- LASTOPT = 255
- }
-
- internal enum RunBehavior
- {
- UntilDone = 1, // 0001 binary
- ReturnImmediately = 2, // 0010 binary
- Clean = 5, // 0101 binary - Clean AND UntilDone
- Attention = 13 // 1101 binary - Clean AND UntilDone AND Attention
- }
-
- internal enum TdsParserState
- {
- Closed,
- OpenNotLoggedIn,
- OpenLoggedIn,
- Broken,
- }
-
- ///
- /// Class encapsulating the data to be sent to the server as part of Federated Authentication Feature Extension.
- ///
- internal class FederatedAuthenticationFeatureExtensionData
- {
- internal TdsEnums.FedAuthLibrary libraryType;
- internal bool fedAuthRequiredPreLoginResponse;
- internal SqlAuthenticationMethod authentication;
- internal byte[] accessToken;
- }
-
- ///
- /// Represents a single encrypted value for a CEK. It contains the encrypted CEK,
- /// the store type, name,the key path and encryption algorithm.
- ///
- internal class SqlEncryptionKeyInfo
- {
- internal byte[] encryptedKey; // the encrypted "column encryption key"
- internal int databaseId;
- internal int cekId;
- internal int cekVersion;
- internal byte[] cekMdVersion;
- internal string keyPath;
- internal string keyStoreName;
- internal string algorithmName;
- internal byte normalizationRuleVersion;
- }
-
- ///
- /// Encapsulates one entry in the CipherInfo table sent as part of Colmetadata.
- /// The same CEK is encrypted multiple times with different master keys (for master key
- /// rotation scenario) We need to keep all these around until we can resolve the CEK
- /// using the correct master key.
- ///
- internal class SqlTceCipherInfoEntry
- {
-
- ///
- /// List of Column Encryption Key Information.
- ///
- private readonly List _columnEncryptionKeyValues;
-
- ///
- /// Key Ordinal.
- ///
- private readonly int _ordinal;
-
- ///
- /// Database ID
- ///
- private int _databaseId;
-
- ///
- /// Cek ID
- ///
- private int _cekId;
-
- ///
- /// Cek Version
- ///
- private int _cekVersion;
-
- ///
- /// Cek MD Version
- ///
- private byte[] _cekMdVersion;
-
- ///
- /// Return the ordinal.
- ///
- internal int Ordinal
- {
- get
- {
- return _ordinal;
- }
- }
-
- ///
- /// Return the DatabaseID.
- ///
- internal int DatabaseId
- {
- get
- {
- return _databaseId;
- }
- }
-
- ///
- /// Return the CEK ID.
- ///
- internal int CekId
- {
- get
- {
- return _cekId;
- }
- }
-
- ///
- /// Return the CEK Version.
- ///
- internal int CekVersion
- {
- get
- {
- return _cekVersion;
- }
- }
-
- ///
- /// Return the CEK MD Version.
- ///
- internal byte[] CekMdVersion
- {
- get
- {
- return _cekMdVersion;
- }
- }
-
- ///
- /// Return the list of Column Encryption Key Values.
- ///
- internal List ColumnEncryptionKeyValues
- {
- get
- {
- return _columnEncryptionKeyValues;
- }
- }
-
- ///
- /// Add an entry to the list of ColumnEncryptionKeyValues.
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- internal void Add(byte[] encryptedKey, int databaseId, int cekId, int cekVersion, byte[] cekMdVersion, string keyPath, string keyStoreName, string algorithmName)
- {
-
- Debug.Assert(_columnEncryptionKeyValues != null, "_columnEncryptionKeyValues should already be initialized.");
-
- SqlEncryptionKeyInfo encryptionKey = new SqlEncryptionKeyInfo();
- encryptionKey.encryptedKey = encryptedKey;
- encryptionKey.databaseId = databaseId;
- encryptionKey.cekId = cekId;
- encryptionKey.cekVersion = cekVersion;
- encryptionKey.cekMdVersion = cekMdVersion;
- encryptionKey.keyPath = keyPath;
- encryptionKey.keyStoreName = keyStoreName;
- encryptionKey.algorithmName = algorithmName;
- _columnEncryptionKeyValues.Add(encryptionKey);
-
- if (0 == _databaseId)
- {
- _databaseId = databaseId;
- _cekId = cekId;
- _cekVersion = cekVersion;
- _cekMdVersion = cekMdVersion;
- }
- else
- {
- Debug.Assert(_databaseId == databaseId);
- Debug.Assert(_cekId == cekId);
- Debug.Assert(_cekVersion == cekVersion);
- Debug.Assert(_cekMdVersion != null && cekMdVersion != null && _cekMdVersion.Length == _cekMdVersion.Length);
- }
- }
-
- ///
- /// Constructor.
- ///
- ///
- internal SqlTceCipherInfoEntry(int ordinal = 0)
- {
- _ordinal = ordinal;
- _databaseId = 0;
- _cekId = 0;
- _cekVersion = 0;
- _cekMdVersion = null;
- _columnEncryptionKeyValues = new List();
- }
- }
-
- ///
- /// Represents a table with various CEKs used in a resultset. Each entry corresponds to one (unique) CEK. The CEK
- /// may have been encrypted using multiple master keys (giving us multiple CEK values). All these values form one single
- /// entry in this table.
- ///
- internal class SqlTceCipherInfoTable
- {
- private readonly SqlTceCipherInfoEntry[] keyList;
-
- internal SqlTceCipherInfoTable(int tabSize)
- {
- Debug.Assert(0 < tabSize, "Invalid Table Size");
- keyList = new SqlTceCipherInfoEntry[tabSize];
- }
-
- internal SqlTceCipherInfoEntry this[int index]
- {
- get
- {
- Debug.Assert(index < keyList.Length, "Invalid index specified.");
- return keyList[index];
- }
- set
- {
- Debug.Assert(index < keyList.Length, "Invalid index specified.");
- keyList[index] = value;
- }
- }
-
- internal int Size
- {
- get
- {
- return keyList.Length;
- }
- }
- }
-
- internal class RoutingInfo
- {
- internal byte Protocol { get; private set; }
- internal UInt16 Port { get; private set; }
- internal string ServerName { get; private set; }
-
- internal RoutingInfo(byte protocol, UInt16 port, string servername)
- {
- Protocol = protocol;
- Port = port;
- ServerName = servername;
- }
- }
-
- sealed internal class SqlLogin
- {
- internal SqlAuthenticationMethod authentication = SqlAuthenticationMethod.NotSpecified; // Authentication type
- internal int timeout; // login timeout
- internal bool userInstance = false; // user instance
- internal string hostName = ""; // client machine name
- internal string userName = ""; // user id
- internal string password = ""; // password
- internal string applicationName = ""; // application name
- internal string serverName = ""; // server name
- internal string language = ""; // initial language
- internal string database = ""; // initial database
- internal string attachDBFilename = ""; // DB filename to be attached
- internal string newPassword = ""; // new password for reset password
- internal bool useReplication = false; // user login for replication
- internal bool useSSPI = false; // use integrated security
- internal int packetSize = SqlConnectionString.DEFAULT.Packet_Size; // packet size
- internal bool readOnlyIntent = false; // read-only intent
- internal SqlCredential credential; // user id and password in SecureString
- internal SecureString newSecurePassword; // new password in SecureString for resetting pasword
- }
-
- sealed internal class SqlLoginAck
- {
- internal string programName;
- internal byte majorVersion;
- internal byte minorVersion;
- internal short buildNum;
- internal bool isVersion8;
- internal UInt32 tdsVersion;
- }
-
- sealed internal class SqlFedAuthInfo
- {
- internal string spn;
- internal string stsurl;
- public override string ToString()
- {
- return String.Format(CultureInfo.InvariantCulture, "STSURL: {0}, SPN: {1}", stsurl ?? String.Empty, spn ?? String.Empty);
- }
- }
-
- sealed internal class SqlFedAuthToken
- {
- internal UInt32 dataLen;
- internal byte[] accessToken;
- internal long expirationFileTime;
- }
-
- sealed internal class _SqlMetaData : SqlMetaDataPriv, ICloneable
- {
- [Flags]
- private enum _SqlMetadataFlags : int
- {
- None = 0,
-
- Updatable = 1 << 0,
- UpdateableUnknown = 1 << 1,
- IsDifferentName = 1 << 2,
- IsKey = 1 << 3,
- IsHidden = 1 << 4,
- IsExpression = 1 << 5,
- IsIdentity = 1 << 6,
- IsColumnSet = 1 << 7,
-
- IsUpdatableMask = (Updatable | UpdateableUnknown) // two bit field (0 is read only, 1 is updatable, 2 is updatability unknown)
- }
-
- internal string column;
- internal string baseColumn;
- internal MultiPartTableName multiPartTableName;
- internal readonly int ordinal;
- internal byte tableNum;
- internal byte op; // for altrow-columns only
- internal ushort operand; // for altrow-columns only
- private _SqlMetadataFlags flags;
-
- internal _SqlMetaData(int ordinal) : base()
- {
- this.ordinal = ordinal;
- }
-
- private bool HasFlag(_SqlMetadataFlags flag)
- {
- return (flags & flag) != 0;
- }
-
- internal string serverName
- {
- get
- {
- return multiPartTableName.ServerName;
- }
- }
- internal string catalogName
- {
- get
- {
- return multiPartTableName.CatalogName;
- }
- }
- internal string schemaName
- {
- get
- {
- return multiPartTableName.SchemaName;
- }
- }
- internal string tableName
- {
- get
- {
- return multiPartTableName.TableName;
- }
- }
-
- public byte Updatability
- {
- get => (byte)(flags & _SqlMetadataFlags.IsUpdatableMask);
- set => flags = (_SqlMetadataFlags)((value & (byte)_SqlMetadataFlags.IsUpdatableMask) | ((int)flags & ~(byte)_SqlMetadataFlags.IsUpdatableMask));
- }
-
- public bool IsReadOnly
- {
- get => !HasFlag(_SqlMetadataFlags.IsUpdatableMask);
- }
-
- public bool IsDifferentName
- {
- get => HasFlag(_SqlMetadataFlags.IsDifferentName);
- set => Set(_SqlMetadataFlags.IsDifferentName, value);
- }
-
- public bool IsKey
- {
- get => HasFlag(_SqlMetadataFlags.IsKey);
- set => Set(_SqlMetadataFlags.IsKey, value);
- }
-
- public bool IsHidden
- {
- get => HasFlag(_SqlMetadataFlags.IsHidden);
- set => Set(_SqlMetadataFlags.IsHidden, value);
- }
-
- public bool IsExpression
- {
- get => HasFlag(_SqlMetadataFlags.IsExpression);
- set => Set(_SqlMetadataFlags.IsExpression, value);
- }
-
- public bool IsIdentity
- {
- get => HasFlag(_SqlMetadataFlags.IsIdentity);
- set => Set(_SqlMetadataFlags.IsIdentity, value);
- }
-
- public bool IsColumnSet
- {
- get => HasFlag(_SqlMetadataFlags.IsColumnSet);
- set => Set(_SqlMetadataFlags.IsColumnSet, value);
- }
-
- private void Set(_SqlMetadataFlags flag, bool value)
- {
- flags = value ? flags | flag : flags & ~flag;
- }
-
- internal bool Is2008DateTimeType
- {
- get
- {
- return SqlDbType.Date == type || SqlDbType.Time == type || SqlDbType.DateTime2 == type || SqlDbType.DateTimeOffset == type;
- }
- }
-
- internal bool IsLargeUdt
- {
- get
- {
- return type == SqlDbType.Udt && length == Int32.MaxValue;
- }
- }
-
- public object Clone()
- {
- _SqlMetaData result = new _SqlMetaData(ordinal);
- result.CopyFrom(this);
- result.column = column;
- result.baseColumn = baseColumn;
- result.multiPartTableName = multiPartTableName;
- result.tableNum = tableNum;
- result.flags = flags;
- result.op = op;
- result.operand = operand;
- return result;
- }
- }
-
- sealed internal class _SqlMetaDataSet
- {
- internal ushort id; // for altrow-columns only
- internal DataTable _schemaTable;
- internal readonly SqlTceCipherInfoTable cekTable; // table of "column encryption keys" used for this metadataset
- internal readonly _SqlMetaData[] _metaDataArray;
- private int _hiddenColumnCount;
- private int[] _visibleColumnMap;
-
- internal _SqlMetaDataSet(int count, SqlTceCipherInfoTable cipherTable)
- {
- _hiddenColumnCount = -1;
- cekTable = cipherTable;
- _metaDataArray = new _SqlMetaData[count];
- for (int i = 0; i < _metaDataArray.Length; ++i)
- {
- _metaDataArray[i] = new _SqlMetaData(i);
- }
- }
-
- private _SqlMetaDataSet(_SqlMetaDataSet original)
- {
- id = original.id;
- _hiddenColumnCount = original._hiddenColumnCount;
- _visibleColumnMap = original._visibleColumnMap;
- _schemaTable = original._schemaTable;
- if (original._metaDataArray == null)
- {
- _metaDataArray = null;
- }
- else
- {
- _metaDataArray = new _SqlMetaData[original._metaDataArray.Length];
- for (int idx = 0; idx < _metaDataArray.Length; idx++)
- {
- _metaDataArray[idx] = (_SqlMetaData)original._metaDataArray[idx].Clone();
- }
- }
- }
-
- internal int VisibleColumnCount
- {
- get
- {
- if (_hiddenColumnCount == -1)
- {
- SetupHiddenColumns();
- }
- return Length - _hiddenColumnCount;
- }
- }
-
- internal int Length
- {
- get
- {
- return _metaDataArray.Length;
- }
- }
-
- internal _SqlMetaData this[int index]
- {
- get
- {
- return _metaDataArray[index];
- }
- set
- {
- Debug.Assert(value == null, "used only by SqlBulkCopy");
- _metaDataArray[index] = value;
- }
- }
-
- public int GetVisibleColumnIndex(int index)
- {
- if (_hiddenColumnCount == -1)
- {
- SetupHiddenColumns();
- }
- if (_visibleColumnMap is null)
- {
- return index;
- }
- else
- {
- return _visibleColumnMap[index];
- }
- }
-
- public _SqlMetaDataSet Clone()
- {
- return new _SqlMetaDataSet(this);
- }
-
- private void SetupHiddenColumns()
- {
- int hiddenColumnCount = 0;
- for (int index = 0; index < Length; index++)
- {
- if (_metaDataArray[index].IsHidden)
- {
- hiddenColumnCount += 1;
- }
- }
-
- if (hiddenColumnCount > 0)
- {
- int[] visibleColumnMap = new int[Length - hiddenColumnCount];
- int mapIndex = 0;
- for (int metaDataIndex = 0; metaDataIndex < Length; metaDataIndex++)
- {
- if (!_metaDataArray[metaDataIndex].IsHidden)
- {
- visibleColumnMap[mapIndex] = metaDataIndex;
- mapIndex += 1;
- }
- }
- _visibleColumnMap = visibleColumnMap;
- }
- _hiddenColumnCount = hiddenColumnCount;
- }
- }
-
-
- sealed internal class _SqlMetaDataSetCollection : ICloneable
- {
- private readonly List<_SqlMetaDataSet> altMetaDataSetArray;
- internal _SqlMetaDataSet metaDataSet;
-
- internal _SqlMetaDataSetCollection()
- {
- altMetaDataSetArray = new List<_SqlMetaDataSet>();
- }
-
- internal void SetAltMetaData(_SqlMetaDataSet altMetaDataSet)
- {
- // VSTFDEVDIV 479675: if altmetadata with same id is found, override it rather than adding a new one
- int newId = altMetaDataSet.id;
- for (int i = 0; i < altMetaDataSetArray.Count; i++)
- {
- if (altMetaDataSetArray[i].id == newId)
- {
- // override the existing metadata with the same id
- altMetaDataSetArray[i] = altMetaDataSet;
- return;
- }
- }
-
- // if we did not find metadata to override, add as new
- altMetaDataSetArray.Add(altMetaDataSet);
- }
-
- internal _SqlMetaDataSet GetAltMetaData(int id)
- {
- foreach (_SqlMetaDataSet altMetaDataSet in altMetaDataSetArray)
- {
- if (altMetaDataSet.id == id)
- {
- return altMetaDataSet;
- }
- }
- Debug.Fail("Can't match up altMetaDataSet with given id");
- return null;
- }
-
- public object Clone()
- {
- _SqlMetaDataSetCollection result = new _SqlMetaDataSetCollection();
- result.metaDataSet = metaDataSet == null ? null : metaDataSet.Clone();
- foreach (_SqlMetaDataSet set in altMetaDataSetArray)
- {
- result.altMetaDataSetArray.Add(set.Clone());
- }
- return result;
- }
- }
-
- ///
- /// Represents Encryption related information of the cipher data.
- ///
- internal class SqlCipherMetadata
- {
-
- ///
- /// Cipher Info Entry.
- ///
- private SqlTceCipherInfoEntry _sqlTceCipherInfoEntry;
-
- ///
- /// Encryption Algorithm Id.
- ///
- private readonly byte _cipherAlgorithmId;
-
- ///
- /// Encryption Algorithm Name.
- ///
- private readonly string _cipherAlgorithmName;
-
- ///
- /// Encryption Type.
- ///
- private readonly byte _encryptionType;
-
- ///
- /// Normalization Rule Version.
- ///
- private readonly byte _normalizationRuleVersion;
-
- ///
- /// Encryption Algorithm Handle.
- ///
- private SqlClientEncryptionAlgorithm _sqlClientEncryptionAlgorithm;
-
- ///
- /// Sql Encryption Key Info.
- ///
- private SqlEncryptionKeyInfo _sqlEncryptionKeyInfo;
-
- ///
- /// Ordinal (into the Cek Table).
- ///
- private readonly ushort _ordinal;
-
- ///
- /// Return the Encryption Info Entry.
- ///
- internal SqlTceCipherInfoEntry EncryptionInfo
- {
- get
- {
- return _sqlTceCipherInfoEntry;
- }
- set
- {
- Debug.Assert(_sqlTceCipherInfoEntry == null, "We can only set the EncryptionInfo once.");
- _sqlTceCipherInfoEntry = value;
- }
- }
-
- ///
- /// Return the cipher's encryption algorithm id.
- ///
- internal byte CipherAlgorithmId
- {
- get
- {
- return _cipherAlgorithmId;
- }
- }
-
- ///
- /// Return the cipher's encryption algorithm name (could be null).
- ///
- internal string CipherAlgorithmName
- {
- get
- {
- return _cipherAlgorithmName;
- }
- }
-
- ///
- /// Return EncryptionType (Deterministic, Randomized, etc.)
- ///
- internal byte EncryptionType
- {
- get
- {
- return _encryptionType;
- }
- }
-
- ///
- /// Return normalization rule version.
- ///
- internal byte NormalizationRuleVersion
- {
- get
- {
- return _normalizationRuleVersion;
- }
- }
-
- ///
- /// Return the cipher encyrption algorithm handle.
- ///
- internal SqlClientEncryptionAlgorithm CipherAlgorithm
- {
- get
- {
- return _sqlClientEncryptionAlgorithm;
- }
- set
- {
- Debug.Assert(_sqlClientEncryptionAlgorithm == null, "_sqlClientEncryptionAlgorithm should not be set more than once.");
- _sqlClientEncryptionAlgorithm = value;
- }
- }
-
- ///
- /// Return Encryption Key Info.
- ///
- internal SqlEncryptionKeyInfo EncryptionKeyInfo
- {
- get
- {
- return _sqlEncryptionKeyInfo;
- }
-
- set
- {
- Debug.Assert(_sqlEncryptionKeyInfo == null, "_sqlEncryptionKeyInfo should not be set more than once.");
- _sqlEncryptionKeyInfo = value;
- }
- }
-
- ///
- /// Return Ordinal into Cek Table.
- ///
- internal ushort CekTableOrdinal
- {
- get
- {
- return _ordinal;
- }
- }
-
- ///
- /// Constructor.
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- internal SqlCipherMetadata(SqlTceCipherInfoEntry sqlTceCipherInfoEntry,
- ushort ordinal,
- byte cipherAlgorithmId,
- string cipherAlgorithmName,
- byte encryptionType,
- byte normalizationRuleVersion)
- {
- Debug.Assert(!sqlTceCipherInfoEntry.Equals(default(SqlTceCipherInfoEntry)), "sqlTceCipherInfoEntry should not be un-initialized.");
-
- _sqlTceCipherInfoEntry = sqlTceCipherInfoEntry;
- _ordinal = ordinal;
- _cipherAlgorithmId = cipherAlgorithmId;
- _cipherAlgorithmName = cipherAlgorithmName;
- _encryptionType = encryptionType;
- _normalizationRuleVersion = normalizationRuleVersion;
- _sqlEncryptionKeyInfo = null;
- }
-
- ///
- /// Do we have an handle to the cipher encryption algorithm already ?
- ///
- ///
- internal bool IsAlgorithmInitialized()
- {
- return _sqlClientEncryptionAlgorithm != null ? true : false;
- }
- }
-
- internal class SqlMetaDataPriv
- {
- [Flags]
- private enum SqlMetaDataPrivFlags : byte
- {
- None = 0,
- IsNullable = 1 << 1,
- IsMultiValued = 1 << 2
- }
-
- internal SqlDbType type; // SqlDbType enum value
- internal byte tdsType; // underlying tds type
- internal byte precision = TdsEnums.UNKNOWN_PRECISION_SCALE; // give default of unknown (-1)
- internal byte scale = TdsEnums.UNKNOWN_PRECISION_SCALE; // give default of unknown (-1)
- private SqlMetaDataPrivFlags flags;
- internal int length;
- internal SqlCollation collation;
- internal int codePage;
- internal Encoding encoding;
- internal MetaType metaType; // cached metaType
- public SqlMetaDataUdt udt;
- public SqlMetaDataXmlSchemaCollection xmlSchemaCollection;
-
- internal bool isEncrypted; // TCE encrypted?
- internal SqlMetaDataPriv baseTI; // for encrypted columns, represents the TYPE_INFO for plaintext value
- internal SqlCipherMetadata cipherMD; // Cipher related metadata for encrypted columns.
-
- internal SqlMetaDataPriv()
- {
- }
-
- public bool IsNullable
- {
- get => HasFlag(SqlMetaDataPrivFlags.IsNullable);
- set => Set(SqlMetaDataPrivFlags.IsNullable, value);
- }
-
- public bool IsMultiValued
- {
- get => HasFlag(SqlMetaDataPrivFlags.IsMultiValued);
- set => Set(SqlMetaDataPrivFlags.IsMultiValued, value);
- }
-
- private bool HasFlag(SqlMetaDataPrivFlags flag)
- {
- return (flags & flag) != 0;
- }
-
- private void Set(SqlMetaDataPrivFlags flag, bool value)
- {
- flags = value ? flags | flag : flags & ~flag;
- }
-
- internal virtual void CopyFrom(SqlMetaDataPriv original)
- {
- this.type = original.type;
- this.tdsType = original.tdsType;
- this.precision = original.precision;
- this.scale = original.scale;
- this.length = original.length;
- this.collation = original.collation;
- this.codePage = original.codePage;
- this.encoding = original.encoding;
- this.metaType = original.metaType;
- this.flags = original.flags;
-
- if (original.udt != null)
- {
- udt = new SqlMetaDataUdt();
- udt.CopyFrom(original.udt);
- }
-
- if (original.xmlSchemaCollection != null)
- {
- xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection();
- xmlSchemaCollection.CopyFrom(original.xmlSchemaCollection);
- }
- }
-
- ///
- /// Is the algorithm handle for the cipher encryption initialized ?
- ///
- ///
- internal bool IsAlgorithmInitialized()
- {
- if (cipherMD != null)
- {
- return cipherMD.IsAlgorithmInitialized();
- }
-
- return false;
- }
-
- ///
- /// Returns the normalization rule version byte.
- ///
- ///
- internal byte NormalizationRuleVersion
- {
- get
- {
- if (cipherMD != null)
- {
- return cipherMD.NormalizationRuleVersion;
- }
-
- return 0x00;
- }
- }
- }
-
- sealed internal class SqlMetaDataXmlSchemaCollection
- {
- internal string Database;
- internal string OwningSchema;
- internal string Name;
-
- public void CopyFrom(SqlMetaDataXmlSchemaCollection original)
- {
- if (original != null)
- {
- Database = original.Database;
- OwningSchema = original.OwningSchema;
- Name = original.Name;
- }
- }
- }
-
- sealed internal class SqlMetaDataUdt
- {
- internal Type Type;
- internal string DatabaseName;
- internal string SchemaName;
- internal string TypeName;
- internal string AssemblyQualifiedName;
-
- public void CopyFrom(SqlMetaDataUdt original)
- {
- if (original != null)
- {
- Type = original.Type;
- DatabaseName = original.DatabaseName;
- SchemaName = original.SchemaName;
- TypeName = original.TypeName;
- AssemblyQualifiedName = original.AssemblyQualifiedName;
- }
- }
- }
-
- ///
- /// Class encapsulating additional information when sending encrypted input parameters.
- ///
- sealed internal class SqlColumnEncryptionInputParameterInfo
- {
- ///
- /// Metadata of the parameter to write the TYPE_INFO of the unencrypted column data type.
- ///
- private readonly SmiParameterMetaData _smiParameterMetadata;
-
- ///
- /// Column encryption related metadata.
- ///
- private readonly SqlCipherMetadata _cipherMetadata;
-
- ///
- /// Serialized format for a subset of members.
- /// Does not include _smiParameterMetadata's serialization.
- ///
- private readonly byte[] _serializedWireFormat;
-
- ///
- /// Return the SMI Parameter Metadata.
- ///
- internal SmiParameterMetaData ParameterMetadata
- {
- get
- {
- return _smiParameterMetadata;
- }
- }
-
- ///
- /// Return the serialized format for some members.
- /// This is pre-calculated and cached since members are immutable.
- /// Does not include _smiParameterMetadata's serialization.
- ///
- internal byte[] SerializedWireFormat
- {
- get
- {
- return _serializedWireFormat;
- }
- }
-
- ///
- /// Constructor.
- ///
- ///
- ///
- internal SqlColumnEncryptionInputParameterInfo(SmiParameterMetaData smiParameterMetadata, SqlCipherMetadata cipherMetadata)
- {
- Debug.Assert(smiParameterMetadata != null, "smiParameterMetadata should not be null.");
- Debug.Assert(cipherMetadata != null, "cipherMetadata should not be null");
- Debug.Assert(cipherMetadata.EncryptionKeyInfo != null, "cipherMetadata.EncryptionKeyInfo.HasValue should be true.");
-
- _smiParameterMetadata = smiParameterMetadata;
- _cipherMetadata = cipherMetadata;
- _serializedWireFormat = SerializeToWriteFormat();
- }
-
- ///
- /// Serializes some data members to wire format.
- ///
- private byte[] SerializeToWriteFormat()
- {
- int totalLength = 0;
-
- // CipherAlgorithmId.
- totalLength += sizeof(byte);
-
- // Encryption Type.
- totalLength += sizeof(byte);
-
- // Database id of the encryption key.
- totalLength += sizeof(int);
-
- // Id of the encryption key.
- totalLength += sizeof(int);
-
- // Version of the encryption key.
- totalLength += sizeof(int);
-
- // Metadata version of the encryption key.
- totalLength += _cipherMetadata.EncryptionKeyInfo.cekMdVersion.Length;
-
- // Normalization Rule Version.
- totalLength += sizeof(byte);
-
- byte[] serializedWireFormat = new byte[totalLength];
-
- // No:of bytes consumed till now. Running variable.
- int consumedBytes = 0;
-
- // 1 - Write Cipher Algorithm Id.
- serializedWireFormat[consumedBytes++] = _cipherMetadata.CipherAlgorithmId;
-
- // 2 - Write Encryption Type.
- serializedWireFormat[consumedBytes++] = _cipherMetadata.EncryptionType;
-
- // 3 - Write the database id of the encryption key.
- SerializeIntIntoBuffer(_cipherMetadata.EncryptionKeyInfo.databaseId, serializedWireFormat, ref consumedBytes);
-
- // 4 - Write the id of the encryption key.
- SerializeIntIntoBuffer(_cipherMetadata.EncryptionKeyInfo.cekId, serializedWireFormat, ref consumedBytes);
-
- // 5 - Write the version of the encryption key.
- SerializeIntIntoBuffer(_cipherMetadata.EncryptionKeyInfo.cekVersion, serializedWireFormat, ref consumedBytes);
-
- // 6 - Write the metadata version of the encryption key.
- Buffer.BlockCopy(_cipherMetadata.EncryptionKeyInfo.cekMdVersion, 0, serializedWireFormat, consumedBytes, _cipherMetadata.EncryptionKeyInfo.cekMdVersion.Length);
- consumedBytes += _cipherMetadata.EncryptionKeyInfo.cekMdVersion.Length;
-
- // 7 - Write Normalization Rule Version.
- serializedWireFormat[consumedBytes++] = _cipherMetadata.NormalizationRuleVersion;
-
- return serializedWireFormat;
- }
-
- ///
- /// Serializes an int into the provided buffer and offset.
- ///
- private void SerializeIntIntoBuffer(int value, byte[] buffer, ref int offset)
- {
- buffer[offset++] = (byte)(value & 0xff);
- buffer[offset++] = (byte)((value >> 8) & 0xff);
- buffer[offset++] = (byte)((value >> 16) & 0xff);
- buffer[offset++] = (byte)((value >> 24) & 0xff);
- }
- }
-
- sealed internal class _SqlRPC
- {
- internal string rpcName;
- internal ushort ProcID; // Used instead of name
- internal ushort options;
-
- internal SqlParameter[] systemParams;
- internal byte[] systemParamOptions;
- internal int systemParamCount;
-
- internal SqlParameterCollection userParams;
- internal long[] userParamMap;
- internal int userParamCount;
-
- internal int? recordsAffected;
- internal int cumulativeRecordsAffected;
-
- internal int errorsIndexStart;
- internal int errorsIndexEnd;
- internal SqlErrorCollection errors;
-
- internal int warningsIndexStart;
- internal int warningsIndexEnd;
- internal SqlErrorCollection warnings;
- internal bool needsFetchParameterEncryptionMetadata;
-
- internal SqlBatchCommand batchCommand;
-
- internal string GetCommandTextOrRpcName()
- {
- if (TdsEnums.RPC_PROCID_EXECUTESQL == ProcID)
- {
- // Param 0 is the actual sql executing
- return (string)systemParams[0].Value;
- }
- else
- {
- return rpcName;
- }
- }
-
- internal SqlParameter GetParameterByIndex(int index, out byte options)
- {
- SqlParameter retval;
- if (index < systemParamCount)
- {
- retval = systemParams[index];
- options = systemParamOptions[index];
- }
- else
- {
- long data = userParamMap[index - systemParamCount];
- int paramIndex = (int)(data & int.MaxValue);
- options = (byte)((data >> 32) & 0xFF);
- retval = userParams[paramIndex];
- }
- return retval;
- }
- }
-
- sealed internal class SqlReturnValue : SqlMetaDataPriv
- {
-
- internal ushort parmIndex; //2005 or later only
- internal string parameter;
- internal readonly SqlBuffer value;
-
- internal SqlReturnValue() : base()
- {
- value = new SqlBuffer();
- }
- }
-
- internal struct MultiPartTableName
- {
- private string _multipartName;
- private string _serverName;
- private string _catalogName;
- private string _schemaName;
- private string _tableName;
-
- internal MultiPartTableName(string[] parts)
- {
- _multipartName = null;
- _serverName = parts[0];
- _catalogName = parts[1];
- _schemaName = parts[2];
- _tableName = parts[3];
- }
-
- internal MultiPartTableName(string multipartName)
- {
- _multipartName = multipartName;
- _serverName = null;
- _catalogName = null;
- _schemaName = null;
- _tableName = null;
- }
-
- internal string ServerName
- {
- get
- {
- ParseMultipartName();
- return _serverName;
- }
- set { _serverName = value; }
- }
- internal string CatalogName
- {
- get
- {
- ParseMultipartName();
- return _catalogName;
- }
- set { _catalogName = value; }
- }
- internal string SchemaName
- {
- get
- {
- ParseMultipartName();
- return _schemaName;
- }
- set { _schemaName = value; }
- }
- internal string TableName
- {
- get
- {
- ParseMultipartName();
- return _tableName;
- }
- set { _tableName = value; }
- }
-
- private void ParseMultipartName()
- {
- if (_multipartName != null)
- {
- string[] parts = MultipartIdentifier.ParseMultipartIdentifier(_multipartName, "[\"", "]\"", Strings.SQL_TDSParserTableName, false);
- _serverName = parts[0];
- _catalogName = parts[1];
- _schemaName = parts[2];
- _tableName = parts[3];
- _multipartName = null;
- }
- }
-
- internal static readonly MultiPartTableName Null = new MultiPartTableName(new string[] { null, null, null, null });
- }
-
- internal static class SslProtocolsHelper
- {
- // protocol versions from native sni
- [Flags]
- private enum NativeProtocols
- {
- SP_PROT_SSL2_SERVER = 0x00000004,
- SP_PROT_SSL2_CLIENT = 0x00000008,
- SP_PROT_SSL3_SERVER = 0x00000010,
- SP_PROT_SSL3_CLIENT = 0x00000020,
- SP_PROT_TLS1_0_SERVER = 0x00000040,
- SP_PROT_TLS1_0_CLIENT = 0x00000080,
- SP_PROT_TLS1_1_SERVER = 0x00000100,
- SP_PROT_TLS1_1_CLIENT = 0x00000200,
- SP_PROT_TLS1_2_SERVER = 0x00000400,
- SP_PROT_TLS1_2_CLIENT = 0x00000800,
- SP_PROT_TLS1_3_SERVER = 0x00001000,
- SP_PROT_TLS1_3_CLIENT = 0x00002000,
- SP_PROT_SSL2 = SP_PROT_SSL2_SERVER | SP_PROT_SSL2_CLIENT,
- SP_PROT_SSL3 = SP_PROT_SSL3_SERVER | SP_PROT_SSL3_CLIENT,
- SP_PROT_TLS1_0 = SP_PROT_TLS1_0_SERVER | SP_PROT_TLS1_0_CLIENT,
- SP_PROT_TLS1_1 = SP_PROT_TLS1_1_SERVER | SP_PROT_TLS1_1_CLIENT,
- SP_PROT_TLS1_2 = SP_PROT_TLS1_2_SERVER | SP_PROT_TLS1_2_CLIENT,
- SP_PROT_TLS1_3 = SP_PROT_TLS1_3_SERVER | SP_PROT_TLS1_3_CLIENT,
- SP_PROT_NONE = 0x0
- }
-
- private static string ToFriendlyName(this NativeProtocols protocol)
- {
- string name;
-
- if (protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_CLIENT) || protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_SERVER))
- {
- name = "TLS 1.3";
- }
- else if (protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_CLIENT) || protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_2_SERVER))
- {
- name = "TLS 1.2";
- }
- else if (protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_1_CLIENT) || protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_1_SERVER))
- {
- name = "TLS 1.1";
- }
- else if (protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_0_CLIENT) || protocol.HasFlag(NativeProtocols.SP_PROT_TLS1_0_SERVER))
- {
- name = "TLS 1.0";
- }
- else if (protocol.HasFlag(NativeProtocols.SP_PROT_SSL3_CLIENT) || protocol.HasFlag(NativeProtocols.SP_PROT_SSL3_SERVER))
- {
- name = "SSL 3.0";
- }
- else if (protocol.HasFlag(NativeProtocols.SP_PROT_SSL2_CLIENT) || protocol.HasFlag(NativeProtocols.SP_PROT_SSL2_SERVER))
- {
- name = "SSL 2.0";
- }
- else if (protocol.HasFlag(NativeProtocols.SP_PROT_NONE))
- {
- name = "None";
- }
- else
- {
- throw new ArgumentException(StringsHelper.GetString(StringsHelper.net_invalid_enum, nameof(NativeProtocols)), nameof(NativeProtocols));
- }
- return name;
- }
-
- ///
- /// check the negotiated secure protocol if it's under TLS 1.2
- ///
- ///
- /// Localized warning message
- public static string GetProtocolWarning(uint protocol)
- {
- var nativeProtocol = (NativeProtocols)protocol;
- string message = string.Empty;
- if ((nativeProtocol & (NativeProtocols.SP_PROT_SSL2 | NativeProtocols.SP_PROT_SSL3 | NativeProtocols.SP_PROT_TLS1_1)) != NativeProtocols.SP_PROT_NONE)
- {
- message = StringsHelper.GetString(Strings.SEC_ProtocolWarning, nativeProtocol.ToFriendlyName());
- }
- return message;
- }
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs
similarity index 97%
rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs
rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs
index 6c09532f6b..a574e6c366 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/AlwaysEncryptedHelperClasses.cs
@@ -11,8 +11,8 @@ namespace Microsoft.Data.SqlClient
{
///
- /// Represents a single encrypted value for a CEK. It contains the encrypted CEK,
- /// the store type, name,the key path and encryption algorithm.
+ /// Represents a single encrypted value for a CEK. It contains the encrypted CEK,
+ /// the store type, name,the key path and encryption algorithm.
///
internal class SqlEncryptionKeyInfo
{
@@ -27,10 +27,10 @@ internal class SqlEncryptionKeyInfo
}
///
- /// Encapsulates one entry in the CipherInfo table sent as part of Colmetadata.
+ /// Encapsulates one entry in the CipherInfo table sent as part of Colmetadata.
/// The same CEK is encrypted multiple times with different master keys (for master key
/// rotation scenario) We need to keep all these around until we can resolve the CEK
- /// using the correct master key.
+ /// using the correct master key.
///
internal class SqlTceCipherInfoEntry
{
@@ -192,9 +192,9 @@ internal SqlTceCipherInfoEntry(int ordinal = 0)
}
///
- /// Represents a table with various CEKs used in a resultset. Each entry corresponds to one (unique) CEK. The CEK
+ /// Represents a table with various CEKs used in a resultset. Each entry corresponds to one (unique) CEK. The CEK
/// may have been encrypted using multiple master keys (giving us multiple CEK values). All these values form one single
- /// entry in this table.
+ /// entry in this table.
///
internal class SqlTceCipherInfoTable
{
@@ -229,7 +229,7 @@ internal int Size
}
}
- sealed internal partial class _SqlMetaDataSet
+ internal sealed partial class _SqlMetaDataSet
{
internal readonly SqlTceCipherInfoTable cekTable; // table of "column encryption keys" used for this metadataset
@@ -468,7 +468,7 @@ internal byte NormalizationRuleVersion
///
/// Class encapsulating additional information when sending encrypted input parameters.
///
- sealed internal class SqlColumnEncryptionInputParameterInfo
+ internal sealed class SqlColumnEncryptionInputParameterInfo
{
///
/// Metadata of the parameter to write the TYPE_INFO of the unencrypted column data type.
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
similarity index 92%
rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
index 9dcdc70afa..a5355905d3 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
@@ -3,12 +3,10 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Buffers;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.Common;
-using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
@@ -16,7 +14,6 @@
using System.Security.Authentication;
using System.Text;
using Microsoft.Data.Common;
-using Microsoft.Data.SqlTypes;
namespace Microsoft.Data.SqlClient
{
@@ -32,7 +29,12 @@ internal enum EncryptionOptions
ON,
NOT_SUP,
REQ,
- LOGIN
+ LOGIN,
+#if NETFRAMEWORK
+ OPTIONS_MASK = 0x3f,
+ CTAIP = 0x40,
+ CLIENT_CERT = 0x80,
+#endif
}
internal enum PreLoginHandshakeStatus
@@ -123,6 +125,11 @@ internal sealed class SqlLoginAck
internal byte minorVersion;
internal short buildNum;
internal uint tdsVersion;
+#if NETFRAMEWORK
+ internal string programName;
+
+ internal bool isVersion8;
+#endif
}
internal sealed class SqlFedAuthInfo
@@ -131,13 +138,13 @@ internal sealed class SqlFedAuthInfo
internal string stsurl;
public override string ToString()
{
- return String.Format(CultureInfo.InvariantCulture, "STSURL: {0}, SPN: {1}", stsurl ?? String.Empty, spn ?? String.Empty);
+ return $"STSURL: {stsurl}, SPN: {spn}";
}
}
internal sealed class SqlFedAuthToken
{
- internal UInt32 dataLen;
+ internal uint dataLen;
internal byte[] accessToken;
internal long expirationFileTime;
}
@@ -298,7 +305,9 @@ internal sealed partial class _SqlMetaDataSet
internal DataTable schemaTable;
private readonly _SqlMetaData[] _metaDataArray;
+#if !NETFRAMEWORK
internal ReadOnlyCollection dbColumnSchema;
+#endif
private int _hiddenColumnCount;
private int[] _visibleColumnMap;
@@ -318,7 +327,11 @@ private _SqlMetaDataSet(_SqlMetaDataSet original)
id = original.id;
_hiddenColumnCount = original._hiddenColumnCount;
_visibleColumnMap = original._visibleColumnMap;
+#if !NETFRAMEWORK
dbColumnSchema = original.dbColumnSchema;
+#else
+ schemaTable = original.schemaTable;
+#endif
if (original._metaDataArray == null)
{
_metaDataArray = null;
@@ -459,8 +472,8 @@ internal _SqlMetaDataSet GetAltMetaData(int id)
public object Clone()
{
- _SqlMetaDataSetCollection result = new _SqlMetaDataSetCollection();
- result.metaDataSet = metaDataSet == null ? null : metaDataSet.Clone();
+ _SqlMetaDataSetCollection result = new _SqlMetaDataSetCollection() { metaDataSet = metaDataSet?.Clone() };
+
foreach (_SqlMetaDataSet set in _altMetaDataSetArray)
{
result._altMetaDataSetArray.Add(set.Clone());
@@ -546,7 +559,7 @@ internal virtual void CopyFrom(SqlMetaDataPriv original)
}
}
- sealed internal class SqlMetaDataXmlSchemaCollection
+ internal sealed class SqlMetaDataXmlSchemaCollection
{
internal string Database;
internal string OwningSchema;
@@ -563,7 +576,7 @@ public void CopyFrom(SqlMetaDataXmlSchemaCollection original)
}
}
- sealed internal class SqlMetaDataUdt
+ internal sealed class SqlMetaDataUdt
{
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
@@ -631,8 +644,8 @@ internal string GetCommandTextOrRpcName()
internal SqlParameter GetParameterByIndex(int index, out byte options)
{
- options = 0;
- SqlParameter retval = null;
+ SqlParameter retval;
+
if (index < systemParamCount)
{
retval = systemParams[index];
@@ -647,13 +660,15 @@ internal SqlParameter GetParameterByIndex(int index, out byte options)
}
return retval;
}
-
}
internal sealed class SqlReturnValue : SqlMetaDataPriv
{
internal string parameter;
internal readonly SqlBuffer value;
+#if NETFRAMEWORK
+ internal ushort parmIndex; //2005 or later only
+#endif
internal SqlReturnValue() : base()
{
@@ -752,10 +767,13 @@ private static string ToFriendlyName(this SslProtocols protocol)
{
name = "TLS 1.3";
}*/
- if((protocol & SslProtocols.Tls12) == SslProtocols.Tls12)
+ if ((protocol & SslProtocols.Tls12) == SslProtocols.Tls12)
{
name = "TLS 1.2";
}
+#if NET8_0_OR_GREATER
+#pragma warning disable SYSLIB0039 // Type or member is obsolete: TLS 1.0 & 1.1 are deprecated
+#endif
else if ((protocol & SslProtocols.Tls11) == SslProtocols.Tls11)
{
name = "TLS 1.1";
@@ -764,20 +782,26 @@ private static string ToFriendlyName(this SslProtocols protocol)
{
name = "TLS 1.0";
}
-// SSL 2.0 and 3.0 are only referenced to log a warning, not explicitly used for connections
-#pragma warning disable CS0618, CA5397
+#if NET8_0_OR_GREATER
+#pragma warning restore SYSLIB0039 // Type or member is obsolete: SSL and TLS 1.0 & 1.1 is deprecated
+#endif
+#pragma warning disable CS0618 // Type or member is obsolete: SSL is deprecated
else if ((protocol & SslProtocols.Ssl3) == SslProtocols.Ssl3)
{
name = "SSL 3.0";
}
else if ((protocol & SslProtocols.Ssl2) == SslProtocols.Ssl2)
-#pragma warning restore CS0618, CA5397
+#pragma warning restore CS0618 // Type or member is obsolete: SSL and TLS 1.0 & 1.1 is deprecated
{
name = "SSL 2.0";
}
else
{
+#if !NETFRAMEWORK
name = protocol.ToString();
+#else
+ throw new ArgumentException(StringsHelper.GetString(StringsHelper.net_invalid_enum, "NativeProtocols"), "NativeProtocols");
+#endif
}
return name;
@@ -791,12 +815,21 @@ private static string ToFriendlyName(this SslProtocols protocol)
public static string GetProtocolWarning(this SslProtocols protocol)
{
string message = string.Empty;
-// SSL 2.0 and 3.0 are only referenced to log a warning, not explicitly used for connections
-#pragma warning disable CS0618, CA5397
+#if NET8_0_OR_GREATER
+#pragma warning disable SYSLIB0039 // Type or member is obsolete: TLS 1.0 & 1.1 are deprecated
+#endif
+#pragma warning disable CS0618 // Type or member is obsolete : SSL is depricated
if ((protocol & (SslProtocols.Ssl2 | SslProtocols.Ssl3 | SslProtocols.Tls | SslProtocols.Tls11)) != SslProtocols.None)
-#pragma warning restore CS0618, CA5397
+#pragma warning restore CS0618 // Type or member is obsolete : SSL is depricated
+#if NET8_0_OR_GREATER
+#pragma warning restore SYSLIB0039 // Type or member is obsolete: SSL and TLS 1.0 & 1.1 is deprecated
+#endif
{
+#if !NETFRAMEWORK
message = StringsHelper.Format(Strings.SEC_ProtocolWarning, protocol.ToFriendlyName());
+#else
+ message = StringsHelper.GetString(Strings.SEC_ProtocolWarning, protocol.ToFriendlyName());
+#endif
}
return message;
}