Search in sources :

Example 1 with SQLServerColumnEncryptionAzureKeyVaultProvider

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")));
    }
}
Also used : SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with SQLServerColumnEncryptionAzureKeyVaultProvider

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")));
    }
}
Also used : SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with SQLServerColumnEncryptionAzureKeyVaultProvider

use of com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider in project mssql-jdbc by Microsoft.

the class JDBCEncryptionDecryptionTest method testAkvNameWithTokenCredential.

@ParameterizedTest
@MethodSource("enclaveParams")
@Tag(Constants.reqExternalSetup)
public void testAkvNameWithTokenCredential(String serverName, String url, String protocol) throws Exception {
    setAEConnectionString(serverName, url, protocol);
    ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId(tenantID).clientId(applicationClientID).clientSecret(applicationKey).build();
    try {
        SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(credential);
        String keystoreName = "keystoreName";
        akv.setName(keystoreName);
        assertTrue(akv.getName().equals(keystoreName));
    } catch (SQLServerException e) {
        fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
    }
}
Also used : ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) ClientSecretCredential(com.azure.identity.ClientSecretCredential) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Tag(org.junit.jupiter.api.Tag)

Example 4 with SQLServerColumnEncryptionAzureKeyVaultProvider

use of com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider in project mssql-jdbc by microsoft.

the class JDBCEncryptionDecryptionTest method testAkvBadEncryptColumnEncryptionKey.

/*
     * Test bad encryptColumnEncryptionKey for AKV
     */
@ParameterizedTest
@MethodSource("enclaveParams")
@Tag(Constants.reqExternalSetup)
public void testAkvBadEncryptColumnEncryptionKey(String serverName, String url, String protocol) throws Exception {
    setAEConnectionString(serverName, url, protocol);
    SQLServerColumnEncryptionAzureKeyVaultProvider akv = null;
    akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey);
    // null encryptedColumnEncryptionKey
    try {
        akv.encryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, null);
        fail(TestResource.getResource("R_expectedExceptionNotThrown"));
    } catch (SQLServerException e) {
        assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullColumnEncryptionKey")));
    }
    // empty encryptedColumnEncryptionKey
    try {
        byte[] emptyCek = new byte[0];
        akv.encryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, emptyCek);
        fail(TestResource.getResource("R_expectedExceptionNotThrown"));
    } catch (SQLServerException e) {
        assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyCEK")));
    }
}
Also used : SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Tag(org.junit.jupiter.api.Tag)

Example 5 with SQLServerColumnEncryptionAzureKeyVaultProvider

use of com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider in project mssql-jdbc by microsoft.

the class JDBCEncryptionDecryptionTest method testAkvNameWithAuthCallback_ADAL.

/**
 * This tests callback implemented using ADAL lib
 */
@ParameterizedTest
@MethodSource("enclaveParams")
@Tag(Constants.reqExternalSetup)
public void testAkvNameWithAuthCallback_ADAL(String serverName, String url, String protocol) throws Exception {
    setAEConnectionString(serverName, url, protocol);
    try {
        SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback_ADAL);
        String keystoreName = "keystoreName";
        akv.setName(keystoreName);
        assertTrue(akv.getName().equals(keystoreName));
    } catch (SQLServerException e) {
        fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
    }
}
Also used : SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Tag(org.junit.jupiter.api.Tag)

Aggregations

SQLServerColumnEncryptionAzureKeyVaultProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider)24 SQLServerException (com.microsoft.sqlserver.jdbc.SQLServerException)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Tag (org.junit.jupiter.api.Tag)14 SQLServerColumnEncryptionJavaKeyStoreProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider)4 SQLException (java.sql.SQLException)4 ClientSecretCredential (com.azure.identity.ClientSecretCredential)2 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)2 AuthenticationContext (com.microsoft.aad.adal4j.AuthenticationContext)2 AuthenticationResult (com.microsoft.aad.adal4j.AuthenticationResult)2 ClientCredential (com.microsoft.aad.adal4j.ClientCredential)2 ISQLServerDataSource (com.microsoft.sqlserver.jdbc.ISQLServerDataSource)2 SQLServerColumnEncryptionKeyStoreProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionKeyStoreProvider)2 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)2 SQLServerConnectionPoolDataSource (com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource)2 SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)2 SQLServerKeyVaultAuthenticationCallback (com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback)2 SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)2 SQLServerXADataSource (com.microsoft.sqlserver.jdbc.SQLServerXADataSource)2