Skip to content

Commit b84aab9

Browse files
author
Johnny Pham
authored
Rename SimulatorEnclaveProvider - "None" attestation protocol, phase 1 (#1419)
* rename simulator enclave provider * Update EnclaveDelegate.Crypto.cs * use Array.Empty<byte>() * use enum for protocol id fields
1 parent 41b57bb commit b84aab9

File tree

7 files changed

+21
-143
lines changed

7 files changed

+21
-143
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@
488488
<Compile Include="..\..\src\Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs">
489489
<Link>Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs</Link>
490490
</Compile>
491+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs">
492+
<Link>Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs</Link>
493+
</Compile>
491494
<Compile Include="..\..\src\Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProviderBase.cs">
492495
<Link>Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProviderBase.cs</Link>
493496
</Compile>
@@ -507,9 +510,6 @@
507510
<Compile Include="Microsoft\Data\SqlClient\SqlDependencyUtils.AssemblyLoadContext.cs" />
508511
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIStreams.ValueTask.cs" />
509512
</ItemGroup>
510-
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetFramework)' != 'netstandard2.0' AND '$(BuildSimulator)' == 'true'">
511-
<Compile Include="Microsoft\Data\SqlClient\SimulatorEnclaveProvider.NetCoreApp.cs" />
512-
</ItemGroup>
513513
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS'">
514514
<Compile Include="Resources\StringsHelper.cs">
515515
<Link>Resources\StringsHelper.NetCore.cs</Link>
@@ -558,7 +558,6 @@
558558
<Link>Microsoft\Data\SqlClient\SqlSequentialStream.cs</Link>
559559
</Compile>
560560
<Compile Include="Microsoft\Data\SqlClient\SqlAuthenticationProviderManager.cs" />
561-
562561
<Compile Include="Microsoft\Data\SqlClient\Server\SqlSer.cs" />
563562
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
564563
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@
165165
<Compile Include="..\..\src\Microsoft\Data\SqlClient\AzureAttestationBasedEnclaveProvider.cs">
166166
<Link>Microsoft\Data\SqlClient\AzureAttestationBasedEnclaveProvider.cs</Link>
167167
</Compile>
168+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs">
169+
<Link>Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs</Link>
170+
</Compile>
168171
<Compile Include="..\..\src\Microsoft\Data\SqlClient\EnclaveDelegate.cs">
169172
<Link>Microsoft\Data\SqlClient\EnclaveDelegate.cs</Link>
170173
</Compile>
@@ -629,9 +632,6 @@
629632
<Compile Include="Microsoft\Data\SqlClient\Server\sqlser.cs" />
630633
<Compile Include="Microsoft\Data\Sql\SqlGenericUtil.cs" />
631634
</ItemGroup>
632-
<ItemGroup Condition="'$(BuildSimulator)' == 'true'">
633-
<Compile Include="Microsoft\Data\SqlClient\SimulatorEnclaveProvider.cs" />
634-
</ItemGroup>
635635
<!-- Resources -->
636636
<ItemGroup>
637637
<Compile Include="Resources\Strings.Designer.cs">

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SimulatorEnclaveProvider.cs

Lines changed: 0 additions & 114 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal class AzureAttestationEnclaveProvider : EnclaveProviderBase
4949
{
5050
#region Constants
5151
private const int DiffieHellmanKeySize = 384;
52-
private const int AzureBasedAttestationProtocolId = 1;
52+
private const int AzureBasedAttestationProtocolId = (int)SqlConnectionAttestationProtocol.AAS;
5353
private const int SigningKeyRetryInSec = 3;
5454
#endregion
5555

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/EnclaveDelegate.Crypto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ private SqlColumnEncryptionEnclaveProvider GetEnclaveProvider(SqlConnectionAttes
103103

104104
#if ENCLAVE_SIMULATOR
105105
case SqlConnectionAttestationProtocol.SIM:
106-
SimulatorEnclaveProvider simulatorEnclaveProvider = new SimulatorEnclaveProvider();
107-
s_enclaveProviders[attestationProtocol] = (SqlColumnEncryptionEnclaveProvider)simulatorEnclaveProvider;
106+
NoneAttestationEnclaveProvider noneAttestationEnclaveProvider = new NoneAttestationEnclaveProvider();
107+
s_enclaveProviders[attestationProtocol] = (SqlColumnEncryptionEnclaveProvider)noneAttestationEnclaveProvider;
108108
sqlColumnEncryptionEnclaveProvider = s_enclaveProviders[attestationProtocol];
109109
break;
110110
#endif
Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections.Generic;
76
using System.Diagnostics;
8-
using System.Linq;
9-
using System.Runtime.Caching;
107
using System.Security.Cryptography;
11-
using System.Text;
128
using System.Threading;
13-
using System.Threading.Tasks;
14-
using System.Collections.Concurrent;
159

1610
namespace Microsoft.Data.SqlClient
1711
{
18-
internal class SimulatorEnclaveProvider : EnclaveProviderBase
12+
internal class NoneAttestationEnclaveProvider : EnclaveProviderBase
1913
{
2014
private static readonly int EnclaveSessionHandleSize = 8;
15+
private const int DiffieHellmanKeySize = 384;
16+
private const int NoneAttestationProtocolId = 2;
2117

2218
// When overridden in a derived class, looks up an existing enclave session information in the enclave session cache.
2319
// If the enclave provider doesn't implement enclave session caching, this method is expected to return null in the sqlEnclaveSession parameter.
@@ -29,18 +25,15 @@ internal override void GetEnclaveSession(EnclaveSessionParameters enclaveSession
2925
// Gets the information that SqlClient subsequently uses to initiate the process of attesting the enclave and to establish a secure session with the enclave.
3026
internal override SqlEnclaveAttestationParameters GetAttestationParameters(string attestationUrl, byte[] customData, int customDataLength)
3127
{
32-
// The key derivation function and hash algorithm name are specified when key derivation is performed
33-
ECDiffieHellman clientDHKey = ECDiffieHellman.Create();
34-
clientDHKey.KeySize = 384;
35-
36-
return new SqlEnclaveAttestationParameters(2, new byte[] { }, clientDHKey);
28+
ECDiffieHellman clientDHKey = KeyConverter.CreateECDiffieHellman(DiffieHellmanKeySize);
29+
return new SqlEnclaveAttestationParameters(NoneAttestationProtocolId, Array.Empty<byte>(), clientDHKey);
3730
}
3831

39-
// 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.
32+
// When overridden in a derived class, performs enclave attestation, generates a symmetric key for the session, creates an enclave session and stores the session information in the cache.
4033
internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHellman clientDHKey, EnclaveSessionParameters enclaveSessionParameters, byte[] customData, int customDataLength, out SqlEnclaveSession sqlEnclaveSession, out long counter)
4134
{
42-
////for simulator: enclave does not send public key, and sends an empty attestation info
43-
//// The only non-trivial content it sends is the session setup info (DH pubkey of enclave)
35+
// for None attestation: enclave does not send public key, and sends an empty attestation info
36+
// The only non-trivial content it sends is the session setup info (DH pubkey of enclave)
4437

4538
sqlEnclaveSession = null;
4639
counter = 0;
@@ -53,14 +46,14 @@ internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHell
5346
{
5447
if (!string.IsNullOrEmpty(enclaveSessionParameters.AttestationUrl))
5548
{
56-
////Read AttestationInfo
49+
// Read AttestationInfo
5750
int attestationInfoOffset = 0;
5851
uint sizeOfTrustedModuleAttestationInfoBuffer = BitConverter.ToUInt32(attestationInfo, attestationInfoOffset);
5952
attestationInfoOffset += sizeof(UInt32);
6053
int sizeOfTrustedModuleAttestationInfoBufferInt = checked((int)sizeOfTrustedModuleAttestationInfoBuffer);
6154
Debug.Assert(sizeOfTrustedModuleAttestationInfoBuffer == 0);
6255

63-
////read secure session info
56+
// read secure session info
6457
uint sizeOfSecureSessionInfoResponse = BitConverter.ToUInt32(attestationInfo, attestationInfoOffset);
6558
attestationInfoOffset += sizeof(UInt32);
6659

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/VirtualSecureModeEnclaveProviderBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal abstract class VirtualizationBasedSecurityEnclaveProviderBase : Enclave
2222
#region Constants
2323

2424
private const int DiffieHellmanKeySize = 384;
25-
private const int VsmHGSProtocolId = 3;
25+
private const int VsmHGSProtocolId = (int)SqlConnectionAttestationProtocol.HGS;
2626

2727
// ENCLAVE_IDENTITY related constants
2828
private static readonly EnclaveIdentity ExpectedPolicy = new EnclaveIdentity()
@@ -95,7 +95,7 @@ internal override void GetEnclaveSession(EnclaveSessionParameters enclaveSession
9595
internal override SqlEnclaveAttestationParameters GetAttestationParameters(string attestationUrl, byte[] customData, int customDataLength)
9696
{
9797
ECDiffieHellman clientDHKey = KeyConverter.CreateECDiffieHellman(DiffieHellmanKeySize);
98-
return new SqlEnclaveAttestationParameters(VsmHGSProtocolId, new byte[] { }, clientDHKey);
98+
return new SqlEnclaveAttestationParameters(VsmHGSProtocolId, Array.Empty<byte>(), clientDHKey);
9999
}
100100

101101
// 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.

0 commit comments

Comments
 (0)