Skip to content

Commit a425a4f

Browse files
Revert "Port Fix for EnclaveSessionCache Issue (dotnet#686)"
This reverts commit 5a46e3d.
1 parent 2be1298 commit a425a4f

27 files changed

+190
-412
lines changed

doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ the enclave attestation protocol as well as the logic for creating and caching e
1919
<CreateEnclaveSession>
2020
<param name="enclaveAttestationInfo">The information the provider uses to attest the enclave and generate a symmetric key for the session. The format of this information is specific to the enclave attestation protocol.</param>
2121
<param name="clientDiffieHellmanKey">A Diffie-Hellman algorithm object that encapsulates a client-side key pair.</param>
22-
<param name="enclaveSessionParameters">The set of parameters required for an enclave session.</param>
22+
<param name="attestationUrl">The endpoint of an attestation service for attesting the enclave.</param>
23+
<param name="servername">The name of the SQL Server instance containing the enclave.</param>
2324
<param name="customData">The set of extra data needed for attestating the enclave.</param>
2425
<param name="customDataLength">The length of the extra data needed for attestating the enclave.</param>
2526
<param name="sqlEnclaveSession">The requested enclave session or <see langword="null" /> if the provider doesn't implement session caching.</param>
@@ -36,7 +37,8 @@ the enclave attestation protocol as well as the logic for creating and caching e
3637
<remarks>To be added.</remarks>
3738
</GetAttestationParameters>
3839
<GetEnclaveSession>
39-
<param name="enclaveSessionParameters">The set of parameters required for enclave session.</param>
40+
<param name="serverName">The name of the SQL Server instance containing the enclave.</param>
41+
<param name="attestationUrl">The endpoint of an attestation service, SqlClient contacts to attest the enclave.</param>
4042
<param name="generateCustomData"><see langword="true" /> to indicate that a set of extra data needs to be generated for attestation; otherwise, <see langword="false" />.</param>
4143
<param name="sqlEnclaveSession">When this method returns, the requested enclave session or <see langword="null" /> if the provider doesn't implement session caching. This parameter is treated as uninitialized.</param>
4244
<param name="counter">A counter that the enclave provider is expected to increment each time SqlClient retrieves the session from the cache. The purpose of this field is to prevent replay attacks.</param>
@@ -47,7 +49,8 @@ the enclave attestation protocol as well as the logic for creating and caching e
4749
<remarks>To be added.</remarks>
4850
</GetEnclaveSession>
4951
<InvalidateEnclaveSession>
50-
<param name="enclaveSessionParameters">The set of parameters required for enclave session.</param>
52+
<param name="serverName">The name of the SQL Server instance containing the enclave.</param>
53+
<param name="enclaveAttestationUrl">The endpoint of an attestation service, SqlClient contacts to attest the enclave.</param>
5154
<param name="enclaveSession">The session to be invalidated.</param>
5255
<summary>When overridden in a derived class, looks up and evicts an enclave session from the enclave session cache, if the provider implements session caching.</summary>
5356
<remarks>To be added.</remarks>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/AzureAttestationBasedEnclaveProvider.NetCoreApp.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ internal class AzureAttestationEnclaveProvider : EnclaveProviderBase
6565
#region Internal methods
6666
// When overridden in a derived class, looks up an existing enclave session information in the enclave session cache.
6767
// If the enclave provider doesn't implement enclave session caching, this method is expected to return null in the sqlEnclaveSession parameter.
68-
internal override void GetEnclaveSession(EnclaveSessionParameters enclaveSessionParameters, bool generateCustomData, out SqlEnclaveSession sqlEnclaveSession, out long counter, out byte[] customData, out int customDataLength)
68+
internal override void GetEnclaveSession(string servername, string attestationUrl, bool generateCustomData, out SqlEnclaveSession sqlEnclaveSession, out long counter, out byte[] customData, out int customDataLength)
6969
{
70-
GetEnclaveSessionHelper(enclaveSessionParameters, generateCustomData, out sqlEnclaveSession, out counter, out customData, out customDataLength);
70+
GetEnclaveSessionHelper(servername, attestationUrl, generateCustomData, out sqlEnclaveSession, out counter, out customData, out customDataLength);
7171
}
7272

7373
// Gets the information that SqlClient subsequently uses to initiate the process of attesting the enclave and to establish a secure session with the enclave.
@@ -81,17 +81,17 @@ internal override SqlEnclaveAttestationParameters GetAttestationParameters(strin
8181
}
8282

8383
// When overridden in a derived class, performs enclave attestation, generates a symmetric key for the session, creates a an enclave session and stores the session information in the cache.
84-
internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHellmanCng clientDHKey, EnclaveSessionParameters enclaveSessionParameters, byte[] customData, int customDataLength, out SqlEnclaveSession sqlEnclaveSession, out long counter)
84+
internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHellmanCng clientDHKey, string attestationUrl, string servername, byte[] customData, int customDataLength, out SqlEnclaveSession sqlEnclaveSession, out long counter)
8585
{
8686
sqlEnclaveSession = null;
8787
counter = 0;
8888
try
8989
{
9090
ThreadRetryCache.Remove(Thread.CurrentThread.ManagedThreadId.ToString());
91-
sqlEnclaveSession = GetEnclaveSessionFromCache(enclaveSessionParameters, out counter);
91+
sqlEnclaveSession = GetEnclaveSessionFromCache(servername, attestationUrl, out counter);
9292
if (sqlEnclaveSession == null)
9393
{
94-
if (!string.IsNullOrEmpty(enclaveSessionParameters.AttestationUrl) && customData != null && customDataLength > 0)
94+
if (!string.IsNullOrEmpty(attestationUrl) && customData != null && customDataLength > 0)
9595
{
9696
byte[] nonce = customData;
9797

@@ -101,13 +101,13 @@ internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHell
101101
AzureAttestationInfo attestInfo = new AzureAttestationInfo(attestationInfo);
102102

103103
// Validate the attestation info
104-
VerifyAzureAttestationInfo(enclaveSessionParameters.AttestationUrl, attestInfo.EnclaveType, attestInfo.AttestationToken.AttestationToken, attestInfo.Identity, nonce);
104+
VerifyAzureAttestationInfo(attestationUrl, attestInfo.EnclaveType, attestInfo.AttestationToken.AttestationToken, attestInfo.Identity, nonce);
105105

106106
// Set up shared secret and validate signature
107107
byte[] sharedSecret = GetSharedSecret(attestInfo.Identity, nonce, attestInfo.EnclaveType, attestInfo.EnclaveDHInfo, clientDHKey);
108108

109109
// add session to cache
110-
sqlEnclaveSession = AddEnclaveSessionToCache(enclaveSessionParameters, sharedSecret, attestInfo.SessionId, out counter);
110+
sqlEnclaveSession = AddEnclaveSessionToCache(attestationUrl, servername, sharedSecret, attestInfo.SessionId, out counter);
111111
}
112112
else
113113
{
@@ -126,9 +126,9 @@ internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHell
126126
}
127127

128128
// When overridden in a derived class, looks up and evicts an enclave session from the enclave session cache, if the provider implements session caching.
129-
internal override void InvalidateEnclaveSession(EnclaveSessionParameters enclaveSessionParameters, SqlEnclaveSession enclaveSessionToInvalidate)
129+
internal override void InvalidateEnclaveSession(string serverName, string enclaveAttestationUrl, SqlEnclaveSession enclaveSessionToInvalidate)
130130
{
131-
InvalidateEnclaveSessionHelper(enclaveSessionParameters, enclaveSessionToInvalidate);
131+
InvalidateEnclaveSessionHelper(serverName, enclaveAttestationUrl, enclaveSessionToInvalidate);
132132
}
133133
#endregion
134134

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/EnclaveDelegate.NetCoreApp.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ internal byte[] GetSerializedAttestationParameters(SqlEnclaveAttestationParamete
6262
/// </summary>
6363
/// <param name="attestationProtocol">attestation protocol</param>
6464
/// <param name="enclaveType">enclave type</param>
65-
/// <param name="enclaveSessionParameters">The set of parameters required for enclave session.</param>
65+
/// <param name="serverName">servername</param>
66+
/// <param name="attestationUrl">attestation url for attestation service endpoint</param>
6667
/// <param name="attestationInfo">attestation info from SQL Server</param>
6768
/// <param name="attestationParameters">attestation parameters</param>
6869
/// <param name="customData">A set of extra data needed for attestating the enclave.</param>
6970
/// <param name="customDataLength">The length of the extra data needed for attestating the enclave.</param>
70-
internal void CreateEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, EnclaveSessionParameters enclaveSessionParameters,
71+
internal void CreateEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, string serverName, string attestationUrl,
7172
byte[] attestationInfo, SqlEnclaveAttestationParameters attestationParameters, byte[] customData, int customDataLength)
7273
{
7374

@@ -79,18 +80,18 @@ internal void CreateEnclaveSession(SqlConnectionAttestationProtocol attestationP
7980
byte[] dummyCustomData = null;
8081
int dummyCustomDataLength;
8182

82-
sqlColumnEncryptionEnclaveProvider.GetEnclaveSession(enclaveSessionParameters, false, out sqlEnclaveSession, out counter, out dummyCustomData, out dummyCustomDataLength);
83+
sqlColumnEncryptionEnclaveProvider.GetEnclaveSession(serverName, attestationUrl, false, out sqlEnclaveSession, out counter, out dummyCustomData, out dummyCustomDataLength);
8384

8485
if (sqlEnclaveSession != null)
8586
{
8687
return;
8788
}
8889

89-
sqlColumnEncryptionEnclaveProvider.CreateEnclaveSession(attestationInfo, attestationParameters.ClientDiffieHellmanKey, enclaveSessionParameters, customData, customDataLength, out sqlEnclaveSession, out counter);
90+
sqlColumnEncryptionEnclaveProvider.CreateEnclaveSession(attestationInfo, attestationParameters.ClientDiffieHellmanKey, attestationUrl, serverName, customData, customDataLength, out sqlEnclaveSession, out counter);
9091

9192
if (sqlEnclaveSession == null)
9293
{
93-
throw SQL.NullEnclaveSessionReturnedFromProvider(enclaveType, enclaveSessionParameters.AttestationUrl);
94+
throw SQL.NullEnclaveSessionReturnedFromProvider(enclaveType, attestationUrl);
9495
}
9596
}
9697
}
@@ -102,9 +103,10 @@ internal void CreateEnclaveSession(SqlConnectionAttestationProtocol attestationP
102103
/// <param name="keysToBeSentToEnclave">Keys to be sent to enclave</param>
103104
/// <param name="queryText"></param>
104105
/// <param name="enclaveType">enclave type</param>
105-
/// <param name="enclaveSessionParameters">The set of parameters required for enclave session.</param>
106+
/// <param name="serverName">server name</param>
107+
/// <param name="enclaveAttestationUrl">url for attestation endpoint</param>
106108
/// <returns></returns>
107-
internal EnclavePackage GenerateEnclavePackage(SqlConnectionAttestationProtocol attestationProtocol, Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave, string queryText, string enclaveType, EnclaveSessionParameters enclaveSessionParameters)
109+
internal EnclavePackage GenerateEnclavePackage(SqlConnectionAttestationProtocol attestationProtocol, Dictionary<int, SqlTceCipherInfoEntry> keysToBeSentToEnclave, string queryText, string enclaveType, string serverName, string enclaveAttestationUrl)
108110
{
109111

110112
SqlEnclaveSession sqlEnclaveSession = null;
@@ -114,27 +116,27 @@ internal EnclavePackage GenerateEnclavePackage(SqlConnectionAttestationProtocol
114116

115117
try
116118
{
117-
GetEnclaveSession(attestationProtocol, enclaveType, enclaveSessionParameters, false, out sqlEnclaveSession, out counter, out dummyCustomData, out dummyCustomDataLength, throwIfNull: true);
119+
GetEnclaveSession(attestationProtocol, enclaveType, serverName, enclaveAttestationUrl, false, out sqlEnclaveSession, out counter, out dummyCustomData, out dummyCustomDataLength, throwIfNull: true);
118120
}
119121
catch (Exception e)
120122
{
121123
throw new RetryableEnclaveQueryExecutionException(e.Message, e);
122124
}
123125

124-
List<ColumnEncryptionKeyInfo> decryptedKeysToBeSentToEnclave = GetDecryptedKeysToBeSentToEnclave(keysToBeSentToEnclave, enclaveSessionParameters.ServerName);
126+
List<ColumnEncryptionKeyInfo> decryptedKeysToBeSentToEnclave = GetDecryptedKeysToBeSentToEnclave(keysToBeSentToEnclave, serverName);
125127
byte[] queryStringHashBytes = ComputeQueryStringHash(queryText);
126128
byte[] keyBytePackage = GenerateBytePackageForKeys(counter, queryStringHashBytes, decryptedKeysToBeSentToEnclave);
127129
byte[] sessionKey = sqlEnclaveSession.GetSessionKey();
128-
byte[] encryptedBytePackage = EncryptBytePackage(keyBytePackage, sessionKey, enclaveSessionParameters.ServerName);
130+
byte[] encryptedBytePackage = EncryptBytePackage(keyBytePackage, sessionKey, serverName);
129131
byte[] enclaveSessionHandle = BitConverter.GetBytes(sqlEnclaveSession.SessionId);
130132
byte[] byteArrayToBeSentToEnclave = CombineByteArrays(new[] { enclaveSessionHandle, encryptedBytePackage });
131133
return new EnclavePackage(byteArrayToBeSentToEnclave, sqlEnclaveSession);
132134
}
133135

134-
internal void InvalidateEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, EnclaveSessionParameters enclaveSessionParameters, SqlEnclaveSession enclaveSession)
136+
internal void InvalidateEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, string serverName, string EnclaveAttestationUrl, SqlEnclaveSession enclaveSession)
135137
{
136138
SqlColumnEncryptionEnclaveProvider sqlColumnEncryptionEnclaveProvider = GetEnclaveProvider(attestationProtocol, enclaveType);
137-
sqlColumnEncryptionEnclaveProvider.InvalidateEnclaveSession(enclaveSessionParameters, enclaveSession);
139+
sqlColumnEncryptionEnclaveProvider.InvalidateEnclaveSession(serverName, EnclaveAttestationUrl, enclaveSession);
138140
}
139141

140142

@@ -205,20 +207,20 @@ private string ConvertAttestationProtocolToString(SqlConnectionAttestationProtoc
205207
}
206208
}
207209

208-
internal void GetEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, EnclaveSessionParameters enclaveSessionParameters, bool generateCustomData, out SqlEnclaveSession sqlEnclaveSession, out byte[] customData, out int customDataLength)
210+
internal void GetEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, string serverName, string enclaveAttestationUrl, bool generateCustomData, out SqlEnclaveSession sqlEnclaveSession, out byte[] customData, out int customDataLength)
209211
{
210212
long counter;
211-
GetEnclaveSession(attestationProtocol, enclaveType, enclaveSessionParameters, generateCustomData, out sqlEnclaveSession, out counter, out customData, out customDataLength, throwIfNull: false);
213+
GetEnclaveSession(attestationProtocol, enclaveType, serverName, enclaveAttestationUrl, generateCustomData, out sqlEnclaveSession, out counter, out customData, out customDataLength, throwIfNull: false);
212214
}
213215

214-
private void GetEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, EnclaveSessionParameters enclaveSessionParameters, bool generateCustomData, out SqlEnclaveSession sqlEnclaveSession, out long counter, out byte[] customData, out int customDataLength, bool throwIfNull)
216+
private void GetEnclaveSession(SqlConnectionAttestationProtocol attestationProtocol, string enclaveType, string serverName, string enclaveAttestationUrl, bool generateCustomData, out SqlEnclaveSession sqlEnclaveSession, out long counter, out byte[] customData, out int customDataLength, bool throwIfNull)
215217
{
216218
SqlColumnEncryptionEnclaveProvider sqlColumnEncryptionEnclaveProvider = GetEnclaveProvider(attestationProtocol, enclaveType);
217-
sqlColumnEncryptionEnclaveProvider.GetEnclaveSession(enclaveSessionParameters, generateCustomData, out sqlEnclaveSession, out counter, out customData, out customDataLength);
219+
sqlColumnEncryptionEnclaveProvider.GetEnclaveSession(serverName, enclaveAttestationUrl, generateCustomData, out sqlEnclaveSession, out counter, out customData, out customDataLength);
218220

219221
if (throwIfNull && sqlEnclaveSession == null)
220222
{
221-
throw SQL.NullEnclaveSessionDuringQueryExecution(enclaveType, enclaveSessionParameters.AttestationUrl);
223+
throw SQL.NullEnclaveSessionDuringQueryExecution(enclaveType, enclaveAttestationUrl);
222224
}
223225
}
224226
}

0 commit comments

Comments
 (0)