Skip to content

Commit

Permalink
Rename SimulatorEnclaveProvider - "None" attestation protocol, phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
DavoudEshtehari committed Jan 27, 2022
1 parent a7023be commit 2d74c19
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs">
<Link>Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs">
<Link>Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProviderBase.cs">
<Link>Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProviderBase.cs</Link>
</Compile>
Expand All @@ -507,9 +510,6 @@
<Compile Include="Microsoft\Data\SqlClient\SqlDependencyUtils.AssemblyLoadContext.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIStreams.ValueTask.cs" />
</ItemGroup>
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetFramework)' != 'netstandard2.0' AND '$(BuildSimulator)' == 'true'">
<Compile Include="Microsoft\Data\SqlClient\SimulatorEnclaveProvider.NetCoreApp.cs" />
</ItemGroup>
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS'">
<Compile Include="Resources\StringsHelper.cs">
<Link>Resources\StringsHelper.NetCore.cs</Link>
Expand Down Expand Up @@ -558,7 +558,6 @@
<Link>Microsoft\Data\SqlClient\SqlSequentialStream.cs</Link>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlAuthenticationProviderManager.cs" />

<Compile Include="Microsoft\Data\SqlClient\Server\SqlSer.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\AzureAttestationBasedEnclaveProvider.cs">
<Link>Microsoft\Data\SqlClient\AzureAttestationBasedEnclaveProvider.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs">
<Link>Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\EnclaveDelegate.cs">
<Link>Microsoft\Data\SqlClient\EnclaveDelegate.cs</Link>
</Compile>
Expand Down Expand Up @@ -629,9 +632,6 @@
<Compile Include="Microsoft\Data\SqlClient\Server\sqlser.cs" />
<Compile Include="Microsoft\Data\Sql\SqlGenericUtil.cs" />
</ItemGroup>
<ItemGroup Condition="'$(BuildSimulator)' == 'true'">
<Compile Include="Microsoft\Data\SqlClient\SimulatorEnclaveProvider.cs" />
</ItemGroup>
<!-- Resources -->
<ItemGroup>
<Compile Include="Resources\Strings.Designer.cs">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class AzureAttestationEnclaveProvider : EnclaveProviderBase
{
#region Constants
private const int DiffieHellmanKeySize = 384;
private const int AzureBasedAttestationProtocolId = 1;
private const int AzureBasedAttestationProtocolId = (int)SqlConnectionAttestationProtocol.AAS;
private const int SigningKeyRetryInSec = 3;
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private SqlColumnEncryptionEnclaveProvider GetEnclaveProvider(SqlConnectionAttes

#if ENCLAVE_SIMULATOR
case SqlConnectionAttestationProtocol.SIM:
SimulatorEnclaveProvider simulatorEnclaveProvider = new SimulatorEnclaveProvider();
s_enclaveProviders[attestationProtocol] = (SqlColumnEncryptionEnclaveProvider)simulatorEnclaveProvider;
NoneAttestationEnclaveProvider noneAttestationEnclaveProvider = new NoneAttestationEnclaveProvider();
s_enclaveProviders[attestationProtocol] = (SqlColumnEncryptionEnclaveProvider)noneAttestationEnclaveProvider;
sqlColumnEncryptionEnclaveProvider = s_enclaveProviders[attestationProtocol];
break;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Caching;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Concurrent;

namespace Microsoft.Data.SqlClient
{
internal class SimulatorEnclaveProvider : EnclaveProviderBase
internal class NoneAttestationEnclaveProvider : EnclaveProviderBase
{
private static readonly int EnclaveSessionHandleSize = 8;
private const int DiffieHellmanKeySize = 384;
private const int NoneAttestationProtocolId = 2;

// When overridden in a derived class, looks up an existing enclave session information in the enclave session cache.
// If the enclave provider doesn't implement enclave session caching, this method is expected to return null in the sqlEnclaveSession parameter.
Expand All @@ -29,18 +25,15 @@ internal override void GetEnclaveSession(EnclaveSessionParameters enclaveSession
// Gets the information that SqlClient subsequently uses to initiate the process of attesting the enclave and to establish a secure session with the enclave.
internal override SqlEnclaveAttestationParameters GetAttestationParameters(string attestationUrl, byte[] customData, int customDataLength)
{
// The key derivation function and hash algorithm name are specified when key derivation is performed
ECDiffieHellman clientDHKey = ECDiffieHellman.Create();
clientDHKey.KeySize = 384;

return new SqlEnclaveAttestationParameters(2, new byte[] { }, clientDHKey);
ECDiffieHellman clientDHKey = KeyConverter.CreateECDiffieHellman(DiffieHellmanKeySize);
return new SqlEnclaveAttestationParameters(NoneAttestationProtocolId, Array.Empty<byte>(), clientDHKey);
}

// 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.
// 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.
internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHellman clientDHKey, EnclaveSessionParameters enclaveSessionParameters, byte[] customData, int customDataLength, out SqlEnclaveSession sqlEnclaveSession, out long counter)
{
////for simulator: enclave does not send public key, and sends an empty attestation info
//// The only non-trivial content it sends is the session setup info (DH pubkey of enclave)
// for None attestation: enclave does not send public key, and sends an empty attestation info
// The only non-trivial content it sends is the session setup info (DH pubkey of enclave)

sqlEnclaveSession = null;
counter = 0;
Expand All @@ -53,14 +46,14 @@ internal override void CreateEnclaveSession(byte[] attestationInfo, ECDiffieHell
{
if (!string.IsNullOrEmpty(enclaveSessionParameters.AttestationUrl))
{
////Read AttestationInfo
// Read AttestationInfo
int attestationInfoOffset = 0;
uint sizeOfTrustedModuleAttestationInfoBuffer = BitConverter.ToUInt32(attestationInfo, attestationInfoOffset);
attestationInfoOffset += sizeof(UInt32);
int sizeOfTrustedModuleAttestationInfoBufferInt = checked((int)sizeOfTrustedModuleAttestationInfoBuffer);
Debug.Assert(sizeOfTrustedModuleAttestationInfoBuffer == 0);

////read secure session info
// read secure session info
uint sizeOfSecureSessionInfoResponse = BitConverter.ToUInt32(attestationInfo, attestationInfoOffset);
attestationInfoOffset += sizeof(UInt32);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal abstract class VirtualizationBasedSecurityEnclaveProviderBase : Enclave
#region Constants

private const int DiffieHellmanKeySize = 384;
private const int VsmHGSProtocolId = 3;
private const int VsmHGSProtocolId = (int)SqlConnectionAttestationProtocol.HGS;

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

// 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.
Expand Down

0 comments on commit 2d74c19

Please sign in to comment.