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

Add encalve enabled always encrypted feature #293

Merged
merged 83 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
fa3575d
Add Attestation Protocol in connection string
karinazhou Oct 7, 2019
a3b20c7
Files for Enclave Provider
Oct 7, 2019
0fdc42d
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient
Oct 7, 2019
478d3d8
resolve conflict
karinazhou Oct 8, 2019
6bd96a8
Remove build info
karinazhou Oct 8, 2019
02e00dc
Merge branch 'master' of https://github.com/dotnet/SqlClient
Oct 9, 2019
daab578
Removing References to SqlColumnEncryptionManager
Oct 9, 2019
f5e5f61
Add attestation protocol to EnclaveDelegate
karinazhou Oct 9, 2019
ff3d0b0
merge after conflicts
karinazhou Oct 9, 2019
fdf728f
include attestation protocol info in exception
karinazhou Oct 9, 2019
a3d46a5
Adding packages to NetFx csproj
Oct 10, 2019
6f1003c
removing extra reference
Oct 10, 2019
ec0b9f5
Update Microsoft.Data.SqlClient.csproj
Oct 10, 2019
256ca73
netcore changes
Oct 11, 2019
61cb439
Adding Enclave files to NetCore
Oct 11, 2019
228afc7
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
Oct 11, 2019
6dbc68d
Add dependencies
karinazhou Oct 11, 2019
fe4001f
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 11, 2019
c640569
Add enclave provider files in netcoreapp only
karinazhou Oct 11, 2019
579c5f2
make attestation stuff internal
karinazhou Oct 11, 2019
a343aa4
make attestation stuff internal (#259)
karinazhou Oct 11, 2019
4a10209
Taking public API documentation out
Oct 15, 2019
5630fc3
Removes the xml file from public API documentation
Oct 15, 2019
a414c3f
removing SqlColumnEncryptionEnclaveProviderConfigurationManager refer…
Oct 15, 2019
41970f5
code clean up for netCore, SqlConnection class
Oct 15, 2019
b20fb1b
Add AE enclave support in netcore
karinazhou Oct 15, 2019
d629c25
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 15, 2019
335e6f0
setting up the test for Attestation Protocol in SqlConnection
Oct 16, 2019
f3f1759
Fix error message and add dependencies
karinazhou Oct 16, 2019
0a4f334
Add enclave support in .NET Core (#270)
karinazhou Oct 17, 2019
0e7d693
testing sqlconnection
Oct 17, 2019
d6b52ba
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
Oct 17, 2019
fcc62be
continue testing connectionstring
Oct 17, 2019
4da88e6
Port fix for AAS claim comparison
karinazhou Oct 17, 2019
3a10fdc
Add Enclave setup check
karinazhou Oct 17, 2019
7ec9304
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 17, 2019
11c896f
Add enclave setup check (#272)
karinazhou Oct 17, 2019
6129bf7
Test SqlConnectionStringBuilder Tests updated for Attestation Protoco…
Oct 18, 2019
4333840
adding more test for AE v2
Oct 18, 2019
767c330
Merge branch 'master' of https://github.com/dotnet/SqlClient into AE-…
Oct 22, 2019
987afab
ConnectionString for AEV2
Oct 23, 2019
608ba56
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 25, 2019
2637744
AEV2 Tests
Oct 25, 2019
ffdb701
Fixing some of the tests
Oct 25, 2019
af1361f
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 28, 2019
80222d5
Adding ClassData for testing AEV2
Oct 28, 2019
54fd399
config file updated
Oct 28, 2019
7fca4be
update config
karinazhou Oct 28, 2019
bbfc61e
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 28, 2019
a6929fa
Add more connection string for enclave testing
karinazhou Oct 28, 2019
360237f
Adjusting APIShoould and BulkCopyAE to wwork with AEV2
Oct 29, 2019
ebfa831
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
Oct 29, 2019
c88ea66
code clean up
Oct 29, 2019
e7f2fb6
Improve the enclave support in tests (ApiShould / BulkCopyAE / CspPro…
karinazhou Oct 30, 2019
d7d0859
Merge branch 'master' of https://github.com/dotnet/SqlClient into AE-…
karinazhou Oct 30, 2019
657e508
Fix named argument error and bring change from master
karinazhou Oct 30, 2019
1674894
Comments resolved on AEV2 PR
Oct 31, 2019
7cde996
Fix according to comments and modify conversion tests
karinazhou Oct 31, 2019
09bae48
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 31, 2019
557e335
Update src/Microsoft.Data.SqlClient/netcore/src/Resources/SR.resx
karinazhou Oct 31, 2019
571762c
Resolve partial comments
karinazhou Oct 31, 2019
f151006
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 31, 2019
8269438
revert docs directory
karinazhou Oct 31, 2019
1b8bcac
Reverting some comment doc changes
Oct 31, 2019
a2888c2
Reverting version change
David-Engel Oct 31, 2019
8b86dae
Minor formatting edits
David-Engel Oct 31, 2019
ba619ca
Resolve comments part2 and update conversion tests
karinazhou Oct 31, 2019
93533ac
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Oct 31, 2019
fa29fbd
Fixing Functional Tests.
Oct 31, 2019
76f15b0
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
Oct 31, 2019
c68c12e
Fix comments
Oct 31, 2019
25c8865
Fixing/Editing more Functional Tests comments
Nov 1, 2019
8078b39
RetriableEnclaveQueryExecutionException -> RetryableEnclaveQueryExecu…
David-Engel Nov 1, 2019
70e9d54
Fix test hunging for ExceptionGenericError
karinazhou Nov 4, 2019
d3fcd81
Fixing MasterKeyPath Test with AEV2
Nov 4, 2019
45b11b2
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
Nov 4, 2019
9689f76
Add Documentation Include tag
Nov 4, 2019
6f98035
minor changes
yukiwongky Nov 4, 2019
b5304bc
Minor fix for TestTrustedMasterKeyPaths
karinazhou Nov 4, 2019
dea1550
Merge branch 'AE-with-enclave' of https://github.com/dotnet/SqlClient…
karinazhou Nov 4, 2019
938720e
fix config
karinazhou Nov 4, 2019
d41a284
Add missing docs
karinazhou Nov 4, 2019
a37a3bd
Get and set expected value for DdType.Date and DbType.Time (#269)
ErikEJ Nov 4, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/snippets/Microsoft.Data.SqlClient/EnclavePublicKey.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<docs>
<members name="EnclavePublicKey">
<EnclavePublicKey>
<summary>Class to hold the enclave's RSA public key</summary>
</EnclavePublicKey>
<PublicKey>
<summary>To be added.</summary>
</PublicKey>
<ctor name="payload">
<summary>Instantiates the Class with assigning received payload value to PublicKey</summary>
<param name="payload"></param>
</ctor>
</members>
</docs>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<docs>
<members name="SqlConnectionAttestationProtocol">
<SqlConnectionAttestationProtocol>
<summary>
Specifies a value for Attestation Protocol.
</summary>
</SqlConnectionAttestationProtocol>
<NotSpecified>
<summary>If the attestation protocol is not specified. Use this as default value.</summary>
<value>0</value>
</NotSpecified>
<AAS>
<summary>Attestation portocol for Azure Attestation Service</summary>
<value>1</value>
</AAS>
<HGS>
<summary>Attestation protocol for Host Guardian Service</summary>
<value>3</value>
</HGS>
</members>
</docs>
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ public enum SqlConnectionColumnEncryptionSetting
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionColumnEncryptionSetting.xml' path='docs/members[@name="SqlConnectionColumnEncryptionSetting"]/Enabled/*'/>
Enabled = 1,
}

/// <include file='..\..\..\..\doc\snippets\Microsoft.Data.SqlClient\SqlConnectionAttestationProtocol.xml' path='docs/members[@name="SqlConnectionAttestationProtocol"]/SqlConnectionAttestationProtocol/*' />
public enum SqlConnectionAttestationProtocol
{
/// <include file='..\..\..\..\doc\snippets\Microsoft.Data.SqlClient\SqlConnectionAttestationProtocol.xml' path='docs/members[@name="SqlConnectionAttestationProtocol"]/NotSpecified/*' />
NotSpecified = 0,

/// <include file='..\..\..\..\doc\snippets\Microsoft.Data.SqlClient\SqlConnectionAttestationProtocol.xml' path='docs/members[@name="SqlConnectionAttestationProtocol"]/AAS/*' />
AAS = 1,

/// <include file='..\..\..\..\doc\snippets\Microsoft.Data.SqlClient\SqlConnectionAttestationProtocol.xml' path='docs/members[@name="SqlConnectionAttestationProtocol"]/HGS/*' />
HGS = 3
}

/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml' path='docs/members[@name="SqlColumnEncryptionCertificateStoreProvider"]/SqlColumnEncryptionCertificateStoreProvider/*'/>
public partial class SqlColumnEncryptionCertificateStoreProvider : Microsoft.Data.SqlClient.SqlColumnEncryptionKeyStoreProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
<Compile Include="Microsoft\Data\SqlClient\SqlDelegatedTransaction.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParser.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIPacket.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\AzureAttestationBasedEnclaveProvider.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProvider.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\VirtualSecureModeEnclaveProviderBase.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\AlwaysEncryptedAttestationException.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\AlwaysEncryptedEnclaveProviderUtils.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\EnclaveProviderBase.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\EnclaveSessionCache.NetCoreApp.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' AND '$(OSGroup)' != 'AnyOS' AND '$(TargetGroup)' == 'netstandard'">
<Compile Include="Microsoft\Data\SqlClient\SqlDelegatedTransaction.NetStandard.cs" />
Expand Down Expand Up @@ -270,7 +277,6 @@
<Compile Include="Microsoft\Data\SqlClient\SqlQueryMetadataCache.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionEnclaveProvider.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlEnclaveAttestationParameters.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionEnclaveProviderConfigurationManager.cs" />
<Compile Include="Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs" />
<Compile Include="Microsoft\Data\SqlClient\EnclaveDelegate.cs" />
<Compile Include="Microsoft\Data\SqlClient\DataClassification\SensitivityClassification.cs" />
Expand Down Expand Up @@ -587,6 +593,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="5.5.0" />
<PackageReference Condition="'$(TargetsWindows)' == 'true' And '$(IsPartialFacadeAssembly)' != 'true' and '$(IsUAPAssembly)' != 'true'" Include="Microsoft.Win32.Registry" Version="4.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,127 @@ internal static string ColumnEncryptionSettingToString(SqlConnectionColumnEncryp
}
}

#region <<AttestationProtocol Utility>>

/// <summary>
/// Attestation Protocol.
/// </summary>
const string AttestationProtocolHGS = "HGS";
const string AttestationProtocolAAS = "AAS";

/// <summary>
/// Convert a string value to the corresponding SqlConnectionAttestationProtocol
/// </summary>
/// <param name="value"></param>
/// <param name="result"></param>
/// <returns></returns>
internal static bool TryConvertToAttestationProtocol(string value, out SqlConnectionAttestationProtocol result)
{
if (StringComparer.InvariantCultureIgnoreCase.Equals(value, AttestationProtocolHGS))
{
result = SqlConnectionAttestationProtocol.HGS;
return true;
}
else if (StringComparer.InvariantCultureIgnoreCase.Equals(value, AttestationProtocolAAS))
{
result = SqlConnectionAttestationProtocol.AAS;
return true;
}
else

result = DbConnectionStringDefaults.AttestationProtocol;
return false;
}

internal static bool IsValidAttestationProtocol(SqlConnectionAttestationProtocol value)
{
Debug.Assert(Enum.GetNames(typeof(SqlConnectionAttestationProtocol)).Length == 3, "SqlConnectionAttestationProtocol enum has changed, update needed");
return value == SqlConnectionAttestationProtocol.NotSpecified
|| value == SqlConnectionAttestationProtocol.HGS
|| value == SqlConnectionAttestationProtocol.AAS;

}

internal static string AttestationProtocolToString(SqlConnectionAttestationProtocol value)
{
Debug.Assert(IsValidAttestationProtocol(value), "value is not a valid attestation protocol");

switch (value)
{
case SqlConnectionAttestationProtocol.HGS:
return AttestationProtocolHGS;
case SqlConnectionAttestationProtocol.AAS:
return AttestationProtocolAAS;
default:
return null;
}
}

internal static SqlConnectionAttestationProtocol ConvertToAttestationProtocol(string keyword, object value)
{
if (null == value)
{
return DbConnectionStringDefaults.AttestationProtocol;
}

string sValue = (value as string);
SqlConnectionAttestationProtocol result;

if (null != sValue)
{
// try again after remove leading & trailing whitespaces.
sValue = sValue.Trim();
if (TryConvertToAttestationProtocol(sValue, out result))
{
return result;
}

// string values must be valid
throw ADP.InvalidConnectionOptionValue(keyword);
}
else
{
// the value is not string, try other options
SqlConnectionAttestationProtocol eValue;

if (value is SqlConnectionAttestationProtocol)
{
eValue = (SqlConnectionAttestationProtocol)value;
}
else if (value.GetType().IsEnum)
{
// explicitly block scenarios in which user tries to use wrong enum types, like:
// builder["SqlConnectionAttestationProtocol"] = EnvironmentVariableTarget.Process;
// workaround: explicitly cast non-SqlConnectionAttestationProtocol enums to int
throw ADP.ConvertFailed(value.GetType(), typeof(SqlConnectionAttestationProtocol), null);
}
else
{
try
{
// Enum.ToObject allows only integral and enum values (enums are blocked above), rasing ArgumentException for the rest
eValue = (SqlConnectionAttestationProtocol)Enum.ToObject(typeof(SqlConnectionAttestationProtocol), value);
}
catch (ArgumentException e)
{
// to be consistent with the messages we send in case of wrong type usage, replace
// the error with our exception, and keep the original one as inner one for troubleshooting
throw ADP.ConvertFailed(value.GetType(), typeof(SqlConnectionAttestationProtocol), e);
}
}

if (IsValidAttestationProtocol(eValue))
{
return eValue;
}
else
{
throw ADP.InvalidEnumerationValue(typeof(SqlConnectionAttestationProtocol), (int)eValue);
}
}
}

#endregion

internal static bool IsValidApplicationIntentValue(ApplicationIntent value)
{
Expand Down Expand Up @@ -524,6 +645,7 @@ internal static partial class DbConnectionStringDefaults
internal static readonly SqlAuthenticationMethod Authentication = SqlAuthenticationMethod.NotSpecified;
internal const SqlConnectionColumnEncryptionSetting ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Disabled;
internal const string EnclaveAttestationUrl = "";
internal const SqlConnectionAttestationProtocol AttestationProtocol = SqlConnectionAttestationProtocol.NotSpecified;
}


Expand Down Expand Up @@ -559,6 +681,7 @@ internal static partial class DbConnectionStringKeywords
internal const string Authentication = "Authentication";
internal const string ColumnEncryptionSetting = "Column Encryption Setting";
internal const string EnclaveAttestationUrl = "Enclave Attestation Url";
internal const string AttestationProtocol = "Attestation Protocol";

// common keywords (OleDb, OracleClient, SqlClient)
internal const string DataSource = "Data Source";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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;

namespace Microsoft.Data.SqlClient
{
internal class AlwaysEncryptedAttestationException : Exception
{
public AlwaysEncryptedAttestationException(string message, Exception innerException) : base(message, innerException) { }

public AlwaysEncryptedAttestationException(string message) : base(message) { }

public AlwaysEncryptedAttestationException() : base() { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.Linq;

namespace Microsoft.Data.SqlClient
{
internal class EnclavePublicKey
{
public byte[] PublicKey { get; set; }

public EnclavePublicKey(byte[] payload)
{
PublicKey = payload;
}
}

internal class EnclaveDiffieHellmanInfo
{
public int Size { get; private set; }

public byte[] PublicKey { get; private set; }

public byte[] PublicKeySignature { get; private set; }

public EnclaveDiffieHellmanInfo(byte[] payload)
{
Size = payload.Length;

int offset = 0;
int publicKeySize = BitConverter.ToInt32(payload, offset);
offset += sizeof(int);

int publicKeySignatureSize = BitConverter.ToInt32(payload, offset);
offset += sizeof(int);

PublicKey = payload.Skip(offset).Take(publicKeySize).ToArray();
offset += publicKeySize;

PublicKeySignature = payload.Skip(offset).Take(publicKeySignatureSize).ToArray();
offset += publicKeySignatureSize;
}
}

internal enum EnclaveType
{
None = 0,

Vbs = 1,

Sgx = 2
}
}
Loading