-
Notifications
You must be signed in to change notification settings - Fork 331
AE with enclaves - multi-platform and .NET Standard 2.1 support #676
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
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
13857f2
Merge pull request #2 from dotnet/master
b807d0b
Merge remote-tracking branch 'upstream/master'
johnnypham 26b0f35
Set up CI with Azure Pipelines
3da84f8
Delete azure-pipelines.yml
9b49213
Merge remote-tracking branch 'upstream/master'
johnnypham d02b69c
Set up CI with Azure Pipelines
896caa1
Delete azure-pipelines.yml
0c04741
Merge branch 'master' of https://github.com/johnnypham/SqlClient
johnnypham 035ef3d
Merge remote-tracking branch 'upstream/master'
johnnypham d1dc8bb
Merge remote-tracking branch 'upstream/master'
johnnypham acbb0a5
Merge remote-tracking branch 'upstream/master'
johnnypham 0d8b82f
aev2
johnnypham a98f2a0
azure attestation, vbs
johnnypham 0d5c11e
Update EnclaveProviderBase.NetCoreApp.cs
johnnypham 6eeaf13
Update EnclaveProviderBase.NetCoreApp.cs
johnnypham 7bec0ea
replace tobytearray
johnnypham 1831ef0
move new methods to utils
johnnypham b79a97e
minor changes
johnnypham 0c898c3
ae apishould tests for linux
johnnypham 361505a
test akv fixture
johnnypham c9785ea
Update SQLSetupStrategy.cs
johnnypham 50c5b12
bulkcopyae akv test
johnnypham d1da600
apishould cross platform
johnnypham 2a93a2e
test fixture changes
johnnypham 743d6ce
Update BulkCopyAE.cs
johnnypham 81654cc
Update BulkCopyAE.cs
johnnypham 9ab0eac
test platform specific fixtures
johnnypham 170ddc9
test platform specific fixtures
johnnypham ba1b31a
update ae tests for linux
johnnypham 1cad3ff
minor changes
johnnypham daa2b13
netstandard
johnnypham c12121f
netstandard changes
johnnypham f264806
change targetframework property to targetframeworks
johnnypham 0448362
Update SqlColumnEncryptionCertificateStoreProvider.Windows.cs
johnnypham 9ba0fc9
Address feedback
johnnypham bcc7e6c
Merge branch 'aev2' of https://github.com/johnnypham/SqlClient into aev2
johnnypham 4780d48
Merge remote-tracking branch 'upstream/master' into aev2
johnnypham 104e0d6
fix culture exceptions in functional tests for ubuntu 18.04
johnnypham 5575f1c
revert test changes
johnnypham 7a1e9fb
test against .net standard 2.1
johnnypham 5285c26
add dispose to new fixture class
johnnypham ec12750
Update AlwaysEncryptedEnclaveProviderUtils.cs
johnnypham dca6da8
Update AlwaysEncryptedEnclaveProviderUtils.cs
johnnypham e575519
Update AlwaysEncryptedEnclaveProviderUtils.cs
johnnypham 50e2ee3
Merge remote-tracking branch 'upstream/master' into aev2
johnnypham 58235f7
casing
johnnypham 5d0fde8
Address comments
johnnypham a552100
Address comments
johnnypham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
55 changes: 0 additions & 55 deletions
55
...nt/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedEnclaveProviderUtils.NetCoreApp.cs
This file was deleted.
Oops, something went wrong.
153 changes: 153 additions & 0 deletions
153
...ata.SqlClient/netcore/src/Microsoft/Data/SqlClient/AlwaysEncryptedEnclaveProviderUtils.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| // 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.Diagnostics; | ||
| using System.Linq; | ||
| using System.Security.Cryptography; | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
| // Contains methods to convert cryptography keys between different formats. | ||
| internal sealed class KeyConverter | ||
| { | ||
| // The RSA public key blob is structured as follows: | ||
| // BCRYPT_RSAKEY_BLOB header | ||
| // byte[ExponentSize] publicExponent | ||
| // byte[ModulusSize] modulus | ||
| private readonly struct RSAPublicKeyBlob | ||
| { | ||
| // Size of an RSA public key blob | ||
| internal static readonly int Size = 539; | ||
| // Size of the BCRYPT_RSAKEY_BLOB header | ||
| internal static readonly int HeaderSize = 27; | ||
| // Size of the exponent (final 3 bytes of the header) | ||
| internal static readonly int ExponentSize = 3; | ||
| // Size of the modulus (remaining bytes after the header) | ||
| internal static readonly int ModulusSize = Size - HeaderSize; | ||
| internal static readonly int ExponentOffset = HeaderSize - ExponentSize; | ||
| internal static readonly int ModulusOffset = HeaderSize; | ||
| } | ||
|
|
||
| // Extracts the public key's modulus and exponent from an RSA public key blob | ||
| // and returns an RSAParameters object | ||
| internal static RSAParameters RSAPublicKeyBlobToParams(byte[] keyBlob) | ||
| { | ||
| Debug.Assert(keyBlob.Length == RSAPublicKeyBlob.Size, | ||
| $"RSA public key blob was not the expected length. Actual: {keyBlob.Length}. Expected: {RSAPublicKeyBlob.Size}"); | ||
| return new RSAParameters() | ||
| { | ||
| Exponent = keyBlob.Skip(RSAPublicKeyBlob.ExponentOffset).Take(RSAPublicKeyBlob.ExponentSize).ToArray(), | ||
| Modulus = keyBlob.Skip(RSAPublicKeyBlob.ModulusOffset).Take(RSAPublicKeyBlob.ModulusSize).ToArray() | ||
| }; | ||
| } | ||
|
|
||
| // The ECC public key blob is structured as follows: | ||
| // BCRYPT_ECCKEY_BLOB header | ||
| // byte[KeySize] X | ||
| // byte[KeySize] Y | ||
| private readonly struct ECCPublicKeyBlob | ||
| { | ||
| // Size of an ECC public key blob | ||
| internal static readonly int Size = 104; | ||
| // Size of the BCRYPT_ECCKEY_BLOB header | ||
| internal static readonly int HeaderSize = 8; | ||
| // Size of each coordinate | ||
| internal static readonly int KeySize = (Size - HeaderSize) / 2; | ||
| } | ||
|
|
||
| // Magic numbers identifying blob types | ||
| // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-wcce/cba27df5-4880-4f95-a879-783f8657e53b | ||
| private readonly struct KeyBlobMagicNumber | ||
| { | ||
| internal static readonly byte[] ECDHPublicP384 = new byte[] { 0x45, 0x43, 0x4b, 0x33 }; | ||
| } | ||
|
|
||
| // Extracts the public key's X and Y coordinates from an ECC public key blob | ||
| // and returns an ECParameters object | ||
| internal static ECParameters ECCPublicKeyBlobToParams(byte[] keyBlob) | ||
| { | ||
| Debug.Assert(keyBlob.Length == ECCPublicKeyBlob.Size, | ||
| $"ECC public key blob was not the expected length. Actual: {keyBlob.Length}. Expected: {ECCPublicKeyBlob.Size}"); | ||
| return new ECParameters | ||
| { | ||
| Curve = ECCurve.NamedCurves.nistP384, | ||
| Q = new ECPoint | ||
| { | ||
| X = keyBlob.Skip(ECCPublicKeyBlob.HeaderSize).Take(ECCPublicKeyBlob.KeySize).ToArray(), | ||
| Y = keyBlob.Skip(ECCPublicKeyBlob.HeaderSize + ECCPublicKeyBlob.KeySize).Take(ECCPublicKeyBlob.KeySize).ToArray() | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| // Serializes an ECDiffieHellmanPublicKey to an ECC public key blob | ||
| // "ECDiffieHellmanPublicKey.ToByteArray() doesn't have a (standards-)defined export | ||
| // format. The version used by ECDiffieHellmanPublicKeyCng is Windows-specific" | ||
| // from https://github.com/dotnet/runtime/issues/27276 | ||
| // => ECDiffieHellmanPublicKey.ToByteArray() is not supported in Unix | ||
| internal static byte[] ECDHPublicKeyToECCKeyBlob(ECDiffieHellmanPublicKey publicKey) | ||
| { | ||
| byte[] keyBlob = new byte[ECCPublicKeyBlob.Size]; | ||
|
|
||
| // Set magic number | ||
| Array.Copy(KeyBlobMagicNumber.ECDHPublicP384, 0, keyBlob, 0, 4); | ||
| // Set key size | ||
| keyBlob[4] = (byte)ECCPublicKeyBlob.KeySize; | ||
|
|
||
| ECPoint ecPoint = publicKey.ExportParameters().Q; | ||
| Debug.Assert(ecPoint.X.Length == ECCPublicKeyBlob.KeySize && ecPoint.Y.Length == ECCPublicKeyBlob.KeySize, | ||
| $"ECDH public key was not the expected length. Actual (X): {ecPoint.X.Length}. Actual (Y): {ecPoint.Y.Length} Expected: {ECCPublicKeyBlob.Size}"); | ||
| // Copy x and y coordinates to key blob | ||
| Array.Copy(ecPoint.X, 0, keyBlob, ECCPublicKeyBlob.HeaderSize, ECCPublicKeyBlob.KeySize); | ||
| Array.Copy(ecPoint.Y, 0, keyBlob, ECCPublicKeyBlob.HeaderSize + ECCPublicKeyBlob.KeySize, ECCPublicKeyBlob.KeySize); | ||
| return keyBlob; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.