@@ -82,7 +82,7 @@ public void TestInvalidCipherText()
8282 [ PlatformSpecific ( TestPlatforms . Windows ) ]
8383 public void TestInvalidAlgorithmVersion ( )
8484 {
85- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_InvalidAlgorithmVersion ,
85+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_InvalidAlgorithmVersion ,
8686 40 , "01" ) ;
8787 byte [ ] plainText = Encoding . Unicode . GetBytes ( "Hello World" ) ;
8888 byte [ ] cipherText = EncryptDataUsingAED ( plainText , CertFixture . cek , CColumnEncryptionType . Deterministic ) ;
@@ -112,7 +112,7 @@ public void TestInvalidAuthenticationTag()
112112 [ PlatformSpecific ( TestPlatforms . Windows ) ]
113113 public void TestNullColumnEncryptionAlgorithm ( )
114114 {
115- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_NullColumnEncryptionAlgorithm ,
115+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_NullColumnEncryptionAlgorithm ,
116116 "'AEAD_AES_256_CBC_HMAC_SHA256'" ) ;
117117 Object cipherMD = GetSqlCipherMetadata ( 0 , 0 , null , 1 , 0x01 ) ;
118118 AddEncryptionKeyToCipherMD ( cipherMD , CertFixture . encryptedCek , 0 , 0 , 0 , new byte [ ] { 0x01 , 0x02 , 0x03 } , CertFixture . certificatePath , "MSSQL_CERTIFICATE_STORE" , "RSA_OAEP" ) ;
@@ -148,32 +148,35 @@ public void TestUnknownEncryptionAlgorithmId()
148148 [ PlatformSpecific ( TestPlatforms . Windows ) ]
149149 public void TestUnknownCustomKeyStoreProvider ( )
150150 {
151- // Clear out the existing providers (to ensure test reliability)
152- ClearSqlConnectionGlobalProviders ( ) ;
153-
154- const string invalidProviderName = "Dummy_Provider" ;
155- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_UnrecognizedKeyStoreProviderName ,
156- invalidProviderName , "'MSSQL_CERTIFICATE_STORE', 'MSSQL_CNG_STORE', 'MSSQL_CSP_PROVIDER'" , "" ) ;
157- Object cipherMD = GetSqlCipherMetadata ( 0 , 1 , null , 1 , 0x03 ) ;
158- AddEncryptionKeyToCipherMD ( cipherMD , CertFixture . encryptedCek , 0 , 0 , 0 , new byte [ ] { 0x01 , 0x02 , 0x03 } , CertFixture . certificatePath , invalidProviderName , "RSA_OAEP" ) ;
159- byte [ ] plainText = Encoding . Unicode . GetBytes ( "HelloWorld" ) ;
160- byte [ ] cipherText = EncryptDataUsingAED ( plainText , CertFixture . cek , CColumnEncryptionType . Deterministic ) ;
151+ lock ( Utility . ClearSqlConnectionGlobalProvidersLock )
152+ {
153+ // Clear out the existing providers (to ensure test reliability)
154+ ClearSqlConnectionGlobalProviders ( ) ;
161155
162- Exception decryptEx = Assert . Throws < TargetInvocationException > ( ( ) => DecryptWithKey ( plainText , cipherMD ) ) ;
163- Assert . Contains ( expectedMessage , decryptEx . InnerException . Message ) ;
156+ const string invalidProviderName = "Dummy_Provider" ;
157+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_UnrecognizedKeyStoreProviderName ,
158+ invalidProviderName , "'MSSQL_CERTIFICATE_STORE', 'MSSQL_CNG_STORE', 'MSSQL_CSP_PROVIDER'" , "" ) ;
159+ Object cipherMD = GetSqlCipherMetadata ( 0 , 1 , null , 1 , 0x03 ) ;
160+ AddEncryptionKeyToCipherMD ( cipherMD , CertFixture . encryptedCek , 0 , 0 , 0 , new byte [ ] { 0x01 , 0x02 , 0x03 } , CertFixture . certificatePath , invalidProviderName , "RSA_OAEP" ) ;
161+ byte [ ] plainText = Encoding . Unicode . GetBytes ( "HelloWorld" ) ;
162+ byte [ ] cipherText = EncryptDataUsingAED ( plainText , CertFixture . cek , CColumnEncryptionType . Deterministic ) ;
164163
165- Exception encryptEx = Assert . Throws < TargetInvocationException > ( ( ) => EncryptWithKey ( plainText , cipherMD ) ) ;
166- Assert . Contains ( expectedMessage , encryptEx . InnerException . Message ) ;
164+ Exception decryptEx = Assert . Throws < TargetInvocationException > ( ( ) => DecryptWithKey ( plainText , cipherMD ) ) ;
165+ Assert . Contains ( expectedMessage , decryptEx . InnerException . Message ) ;
166+
167+ Exception encryptEx = Assert . Throws < TargetInvocationException > ( ( ) => EncryptWithKey ( plainText , cipherMD ) ) ;
168+ Assert . Contains ( expectedMessage , encryptEx . InnerException . Message ) ;
167169
168- ClearSqlConnectionGlobalProviders ( ) ;
170+ ClearSqlConnectionGlobalProviders ( ) ;
171+ }
169172 }
170173
171174 [ Fact ]
172175 [ PlatformSpecific ( TestPlatforms . Windows ) ]
173176 public void TestTceUnknownEncryptionAlgorithm ( )
174177 {
175178 const string unknownEncryptionAlgorithm = "Dummy" ;
176- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_UnknownColumnEncryptionAlgorithm ,
179+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_UnknownColumnEncryptionAlgorithm ,
177180 unknownEncryptionAlgorithm , "'AEAD_AES_256_CBC_HMAC_SHA256'" ) ;
178181 Object cipherMD = GetSqlCipherMetadata ( 0 , 0 , "Dummy" , 1 , 0x01 ) ;
179182 AddEncryptionKeyToCipherMD ( cipherMD , CertFixture . encryptedCek , 0 , 0 , 0 , new byte [ ] { 0x01 , 0x02 , 0x03 } , CertFixture . certificatePath , "MSSQL_CERTIFICATE_STORE" , "RSA_OAEP" ) ;
@@ -193,7 +196,7 @@ public void TestExceptionsFromCertStore()
193196 {
194197 byte [ ] corruptedCek = GenerateInvalidEncryptedCek ( CertFixture . cek , ECEKCorruption . SIGNATURE ) ;
195198
196- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_KeyDecryptionFailedCertStore ,
199+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_KeyDecryptionFailedCertStore ,
197200 "MSSQL_CERTIFICATE_STORE" , BitConverter . ToString ( corruptedCek , corruptedCek . Length - 10 , 10 ) ) ;
198201
199202 Object cipherMD = GetSqlCipherMetadata ( 0 , 1 , null , 1 , 0x01 ) ;
@@ -209,27 +212,30 @@ public void TestExceptionsFromCertStore()
209212 [ PlatformSpecific ( TestPlatforms . Windows ) ]
210213 public void TestExceptionsFromCustomKeyStore ( )
211214 {
212- string expectedMessage = "Failed to decrypt a column encryption key" ;
215+ lock ( Utility . ClearSqlConnectionGlobalProvidersLock )
216+ {
217+ string expectedMessage = "Failed to decrypt a column encryption key" ;
213218
214- // Clear out the existing providers (to ensure test reliability)
215- ClearSqlConnectionGlobalProviders ( ) ;
219+ // Clear out the existing providers (to ensure test reliability)
220+ ClearSqlConnectionGlobalProviders ( ) ;
216221
217- IDictionary < string , SqlColumnEncryptionKeyStoreProvider > customProviders = new Dictionary < string , SqlColumnEncryptionKeyStoreProvider > ( ) ;
218- customProviders . Add ( DummyKeyStoreProvider . Name , new DummyKeyStoreProvider ( ) ) ;
219- SqlConnection . RegisterColumnEncryptionKeyStoreProviders ( customProviders ) ;
222+ IDictionary < string , SqlColumnEncryptionKeyStoreProvider > customProviders = new Dictionary < string , SqlColumnEncryptionKeyStoreProvider > ( ) ;
223+ customProviders . Add ( DummyKeyStoreProvider . Name , new DummyKeyStoreProvider ( ) ) ;
224+ SqlConnection . RegisterColumnEncryptionKeyStoreProviders ( customProviders ) ;
220225
221- object cipherMD = GetSqlCipherMetadata ( 0 , 1 , null , 1 , 0x01 ) ;
222- AddEncryptionKeyToCipherMD ( cipherMD , CertFixture . encryptedCek , 0 , 0 , 0 , new byte [ ] { 0x01 , 0x02 , 0x03 } , CertFixture . certificatePath , "DummyProvider" , "DummyAlgo" ) ;
223- byte [ ] plainText = Encoding . Unicode . GetBytes ( "HelloWorld" ) ;
224- byte [ ] cipherText = EncryptDataUsingAED ( plainText , CertFixture . cek , CColumnEncryptionType . Deterministic ) ;
226+ object cipherMD = GetSqlCipherMetadata ( 0 , 1 , null , 1 , 0x01 ) ;
227+ AddEncryptionKeyToCipherMD ( cipherMD , CertFixture . encryptedCek , 0 , 0 , 0 , new byte [ ] { 0x01 , 0x02 , 0x03 } , CertFixture . certificatePath , "DummyProvider" , "DummyAlgo" ) ;
228+ byte [ ] plainText = Encoding . Unicode . GetBytes ( "HelloWorld" ) ;
229+ byte [ ] cipherText = EncryptDataUsingAED ( plainText , CertFixture . cek , CColumnEncryptionType . Deterministic ) ;
225230
226- Exception decryptEx = Assert . Throws < TargetInvocationException > ( ( ) => DecryptWithKey ( cipherText , cipherMD ) ) ;
227- Assert . Contains ( expectedMessage , decryptEx . InnerException . Message ) ;
231+ Exception decryptEx = Assert . Throws < TargetInvocationException > ( ( ) => DecryptWithKey ( cipherText , cipherMD ) ) ;
232+ Assert . Contains ( expectedMessage , decryptEx . InnerException . Message ) ;
228233
229- Exception encryptEx = Assert . Throws < TargetInvocationException > ( ( ) => EncryptWithKey ( cipherText , cipherMD ) ) ;
230- Assert . Contains ( expectedMessage , encryptEx . InnerException . Message ) ;
234+ Exception encryptEx = Assert . Throws < TargetInvocationException > ( ( ) => EncryptWithKey ( cipherText , cipherMD ) ) ;
235+ Assert . Contains ( expectedMessage , encryptEx . InnerException . Message ) ;
231236
232- ClearSqlConnectionGlobalProviders ( ) ;
237+ ClearSqlConnectionGlobalProviders ( ) ;
238+ }
233239 }
234240 }
235241
0 commit comments