@@ -82,7 +82,7 @@ public void TestInvalidCipherText()
82
82
[ PlatformSpecific ( TestPlatforms . Windows ) ]
83
83
public void TestInvalidAlgorithmVersion ( )
84
84
{
85
- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_InvalidAlgorithmVersion ,
85
+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_InvalidAlgorithmVersion ,
86
86
40 , "01" ) ;
87
87
byte [ ] plainText = Encoding . Unicode . GetBytes ( "Hello World" ) ;
88
88
byte [ ] cipherText = EncryptDataUsingAED ( plainText , CertFixture . cek , CColumnEncryptionType . Deterministic ) ;
@@ -112,7 +112,7 @@ public void TestInvalidAuthenticationTag()
112
112
[ PlatformSpecific ( TestPlatforms . Windows ) ]
113
113
public void TestNullColumnEncryptionAlgorithm ( )
114
114
{
115
- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_NullColumnEncryptionAlgorithm ,
115
+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_NullColumnEncryptionAlgorithm ,
116
116
"'AEAD_AES_256_CBC_HMAC_SHA256'" ) ;
117
117
Object cipherMD = GetSqlCipherMetadata ( 0 , 0 , null , 1 , 0x01 ) ;
118
118
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()
148
148
[ PlatformSpecific ( TestPlatforms . Windows ) ]
149
149
public void TestUnknownCustomKeyStoreProvider ( )
150
150
{
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 ( ) ;
161
155
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 ) ;
164
163
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 ) ;
167
169
168
- ClearSqlConnectionGlobalProviders ( ) ;
170
+ ClearSqlConnectionGlobalProviders ( ) ;
171
+ }
169
172
}
170
173
171
174
[ Fact ]
172
175
[ PlatformSpecific ( TestPlatforms . Windows ) ]
173
176
public void TestTceUnknownEncryptionAlgorithm ( )
174
177
{
175
178
const string unknownEncryptionAlgorithm = "Dummy" ;
176
- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_UnknownColumnEncryptionAlgorithm ,
179
+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_UnknownColumnEncryptionAlgorithm ,
177
180
unknownEncryptionAlgorithm , "'AEAD_AES_256_CBC_HMAC_SHA256'" ) ;
178
181
Object cipherMD = GetSqlCipherMetadata ( 0 , 0 , "Dummy" , 1 , 0x01 ) ;
179
182
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()
193
196
{
194
197
byte [ ] corruptedCek = GenerateInvalidEncryptedCek ( CertFixture . cek , ECEKCorruption . SIGNATURE ) ;
195
198
196
- string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_KeyDecryptionFailedCertStore ,
199
+ string expectedMessage = string . Format ( SystemDataResourceManager . Instance . TCE_KeyDecryptionFailedCertStore ,
197
200
"MSSQL_CERTIFICATE_STORE" , BitConverter . ToString ( corruptedCek , corruptedCek . Length - 10 , 10 ) ) ;
198
201
199
202
Object cipherMD = GetSqlCipherMetadata ( 0 , 1 , null , 1 , 0x01 ) ;
@@ -209,27 +212,30 @@ public void TestExceptionsFromCertStore()
209
212
[ PlatformSpecific ( TestPlatforms . Windows ) ]
210
213
public void TestExceptionsFromCustomKeyStore ( )
211
214
{
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" ;
213
218
214
- // Clear out the existing providers (to ensure test reliability)
215
- ClearSqlConnectionGlobalProviders ( ) ;
219
+ // Clear out the existing providers (to ensure test reliability)
220
+ ClearSqlConnectionGlobalProviders ( ) ;
216
221
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 ) ;
220
225
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 ) ;
225
230
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 ) ;
228
233
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 ) ;
231
236
232
- ClearSqlConnectionGlobalProviders ( ) ;
237
+ ClearSqlConnectionGlobalProviders ( ) ;
238
+ }
233
239
}
234
240
}
235
241
0 commit comments