Skip to content

Commit bbe8410

Browse files
committed
Initial removal of CertificateUtility.CreateCertificate
One test implied that DataTestUtility.AKVUrl would point to an RSA key which aligned with the certificate's private key. Switching this to dynamically generate the key in places.
1 parent 986cdb9 commit bbe8410

File tree

12 files changed

+132
-169
lines changed

12 files changed

+132
-169
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/AKVTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ public void ForcedColumnDecryptErrorTestShouldFail()
133133
[PlatformSpecific(TestPlatforms.Windows)]
134134
public void TestRoundTripWithAKVAndCertStoreProvider()
135135
{
136-
using SQLSetupStrategyCertStoreProvider certStoreFixture = new();
136+
SqlColumnEncryptionCertificateStoreProvider certStoreProvider = new SqlColumnEncryptionCertificateStoreProvider();
137137
byte[] plainTextColumnEncryptionKey = ColumnEncryptionKey.GenerateRandomBytes(ColumnEncryptionKey.KeySizeInBytes);
138-
byte[] encryptedColumnEncryptionKeyUsingAKV = _fixture.AkvStoreProvider.EncryptColumnEncryptionKey(DataTestUtility.AKVUrl, @"RSA_OAEP", plainTextColumnEncryptionKey);
139-
byte[] columnEncryptionKeyReturnedAKV2Cert = certStoreFixture.CertStoreProvider.DecryptColumnEncryptionKey(certStoreFixture.CspColumnMasterKey.KeyPath, @"RSA_OAEP", encryptedColumnEncryptionKeyUsingAKV);
138+
byte[] encryptedColumnEncryptionKeyUsingAKV = _fixture.AkvStoreProvider.EncryptColumnEncryptionKey(_fixture.AkvKeyUrl, @"RSA_OAEP", plainTextColumnEncryptionKey);
139+
byte[] columnEncryptionKeyReturnedAKV2Cert = certStoreProvider.DecryptColumnEncryptionKey(_fixture.ColumnMasterKeyPath, @"RSA_OAEP", encryptedColumnEncryptionKeyUsingAKV);
140140
Assert.True(plainTextColumnEncryptionKey.SequenceEqual(columnEncryptionKeyReturnedAKV2Cert), @"Roundtrip failed");
141141

142142
// Try the opposite.
143-
byte[] encryptedColumnEncryptionKeyUsingCert = certStoreFixture.CertStoreProvider.EncryptColumnEncryptionKey(certStoreFixture.CspColumnMasterKey.KeyPath, @"RSA_OAEP", plainTextColumnEncryptionKey);
144-
byte[] columnEncryptionKeyReturnedCert2AKV = _fixture.AkvStoreProvider.DecryptColumnEncryptionKey(DataTestUtility.AKVUrl, @"RSA_OAEP", encryptedColumnEncryptionKeyUsingCert);
143+
byte[] encryptedColumnEncryptionKeyUsingCert = certStoreProvider.EncryptColumnEncryptionKey(_fixture.ColumnMasterKeyPath, @"RSA_OAEP", plainTextColumnEncryptionKey);
144+
byte[] columnEncryptionKeyReturnedCert2AKV = _fixture.AkvStoreProvider.DecryptColumnEncryptionKey(_fixture.AkvKeyUrl, @"RSA_OAEP", encryptedColumnEncryptionKeyUsingCert);
145145
Assert.True(plainTextColumnEncryptionKey.SequenceEqual(columnEncryptionKeyReturnedCert2AKV), @"Roundtrip failed");
146146
}
147147

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ConversionTests.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
using System.Security.Cryptography.X509Certificates;
1515
using Xunit;
1616
using Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup;
17+
using Microsoft.Data.SqlClient.TestUtilities.Fixtures;
1718

1819
namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
1920
{
2021
[PlatformSpecific(TestPlatforms.Windows)]
21-
public sealed class ConversionTests : IDisposable
22+
public sealed class ConversionTests : IDisposable, IClassFixture<ColumnMasterKeyCertificateFixture>
2223
{
2324

2425
private const string IdentityColumnName = "IdentityColumn";
@@ -29,7 +30,7 @@ public sealed class ConversionTests : IDisposable
2930
private const decimal SmallMoneyMinValue = -214748.3648M;
3031
private const int MaxLength = 10000;
3132
private int NumberOfRows = DataTestUtility.EnclaveEnabled ? 10 : 100;
32-
private static X509Certificate2 certificate;
33+
private X509Certificate2 certificate;
3334
private ColumnMasterKey columnMasterKey;
3435
private ColumnEncryptionKey columnEncryptionKey;
3536
private SqlColumnEncryptionCertificateStoreProvider certStoreProvider = new SqlColumnEncryptionCertificateStoreProvider();
@@ -54,12 +55,9 @@ public ColumnMetaData(SqlDbType columnType, int columnSize, int precision, int s
5455
public bool UseMax { get; set; }
5556
}
5657

57-
public ConversionTests()
58+
public ConversionTests(ColumnMasterKeyCertificateFixture fixture)
5859
{
59-
if (certificate == null)
60-
{
61-
certificate = CertificateUtility.CreateCertificate();
62-
}
60+
certificate = fixture.ColumnMasterKeyCertificate;
6361
columnMasterKey = new CspColumnMasterKey(DatabaseHelper.GenerateUniqueName("CMK"), certificate.Thumbprint, certStoreProvider, DataTestUtility.EnclaveEnabled);
6462
_databaseObjects.Add(columnMasterKey);
6563

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ public void TestEncryptDecryptWithCSP(string connectionString)
188188
using SqlCommand sqlCommand = new(@$"SELECT CustomerId, FirstName, LastName FROM [{tableName}] WHERE FirstName = @firstName",
189189
sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled);
190190
SqlParameter customerFirstParam = sqlCommand.Parameters.AddWithValue(@"firstName", @"Microsoft");
191-
Console.WriteLine(@"Exception: {0}");
192191
customerFirstParam.Direction = System.Data.ParameterDirection.Input;
193192

194193
using SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

0 commit comments

Comments
 (0)