use of com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider in project mssql-jdbc by microsoft.
the class JDBCEncryptionDecryptionTest method testAkvName.
/*
* Test getting/setting AKV name
*/
@ParameterizedTest
@MethodSource("enclaveParams")
@Tag(Constants.reqExternalSetup)
public void testAkvName(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey);
String keystoreName = "keystoreName";
akv.setName(keystoreName);
assertTrue(akv.getName().equals(keystoreName));
}
use of com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider in project mssql-jdbc by microsoft.
the class JDBCEncryptionDecryptionTest method testBadAkvTokenCredential.
/*
* Test bad Azure Key Vault using TokenCredential
*/
@SuppressWarnings("unused")
@ParameterizedTest
@MethodSource("enclaveParams")
public void testBadAkvTokenCredential(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
try {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider((TokenCredential) null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullValue")));
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider in project mssql-jdbc by microsoft.
the class JDBCEncryptionDecryptionTest method testBadAkvCallback.
/*
* Test bad Azure Key Vault using SQLServerKeyVaultAuthenticationCallback
*/
@SuppressWarnings("unused")
@ParameterizedTest
@MethodSource("enclaveParams")
public void testBadAkvCallback(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
try {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider((SQLServerKeyVaultAuthenticationCallback) null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullValue")));
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider in project mssql-jdbc by microsoft.
the class JDBCEncryptionDecryptionTest method testAkvDecryptColumnEncryptionKey.
/*
* Test decryptColumnEncryptionKey for AKV
*/
@ParameterizedTest
@MethodSource("enclaveParams")
@Tag(Constants.reqExternalSetup)
public void testAkvDecryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
SQLServerColumnEncryptionAzureKeyVaultProvider akv = null;
akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey);
// null akvpath
try {
akv.decryptColumnEncryptionKey(null, "", null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVPathNull")));
}
// invalid akvpath
try {
akv.decryptColumnEncryptionKey("keypath", "", null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVMasterKeyPathInvalid")));
}
// invalid akvpath url
try {
akv.decryptColumnEncryptionKey("http:///^[!#$&-;=?-[]_a-", "", null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVURLInvalid")));
}
// null encryptedColumnEncryptionKey
try {
akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullEncryptedColumnEncryptionKey")));
}
// empty encryptedColumnEncryptionKey
try {
byte[] emptyCek = new byte[0];
akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, emptyCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyEncryptedColumnEncryptionKey")));
}
// invalid algorithm
try {
byte[] badCek = new byte[1];
akv.decryptColumnEncryptionKey(keyIDs[0], "invalidAlgo", badCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidKeyEncryptionAlgorithm")));
}
// bad encryptedColumnEncryptionKey
try {
byte[] badCek = new byte[1];
akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, badCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidEcryptionAlgorithmVersion")));
}
}
Aggregations