Search in sources :

Example 16 with DaoManager

use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.

the class TestRangerKeyStore method testInvalidKey3.

@Test(expected = IOException.class)
public void testInvalidKey3() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
    DaoManager daoManager = Mockito.mock(DaoManager.class);
    RangerKeyStore rangerKeyStore = new RangerKeyStore(daoManager);
    String keyValue = "1 enckey";
    InputStream inputStream = generateKeyStoreFile(keyValue);
    rangerKeyStore.engineLoadKeyStoreFile(inputStream, storePass, keyPass, masterKey, fileFormat);
    inputStream.close();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RangerKeyStore(org.apache.hadoop.crypto.key.RangerKeyStore) DaoManager(org.apache.ranger.kms.dao.DaoManager) Test(org.junit.Test)

Example 17 with DaoManager

use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.

the class TestRangerKeyStore method testInvalidKey4.

@Test(expected = IOException.class)
public void testInvalidKey4() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
    DaoManager daoManager = Mockito.mock(DaoManager.class);
    RangerKeyStore rangerKeyStore = new RangerKeyStore(daoManager);
    String keyValue = "_1-enckey";
    InputStream inputStream = generateKeyStoreFile(keyValue);
    rangerKeyStore.engineLoadKeyStoreFile(inputStream, storePass, keyPass, masterKey, fileFormat);
    inputStream.close();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RangerKeyStore(org.apache.hadoop.crypto.key.RangerKeyStore) DaoManager(org.apache.ranger.kms.dao.DaoManager) Test(org.junit.Test)

Example 18 with DaoManager

use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.

the class RangerMasterKeyTest method testRangerMasterKey.

@Test
public void testRangerMasterKey() throws Throwable {
    if (!UNRESTRICTED_POLICIES_INSTALLED) {
        return;
    }
    Path configDir = Paths.get("src/test/resources/kms");
    System.setProperty(KMSConfiguration.KMS_CONFIG_DIR, configDir.toFile().getAbsolutePath());
    RangerKMSDB rangerkmsDb = new RangerKMSDB(RangerKeyStoreProvider.getDBKSConf());
    DaoManager daoManager = rangerkmsDb.getDaoManager();
    String masterKeyPassword = "password0password0password0password0password0password0password0password0" + "password0password0password0password0password0password0password0password0password0password0" + "password0password0password0password0password0password0password0password0password0password0";
    RangerMasterKey rangerMasterKey = new RangerMasterKey(daoManager);
    Assert.assertTrue(rangerMasterKey.generateMasterKey(masterKeyPassword));
    Assert.assertNotNull(rangerMasterKey.getMasterKey(masterKeyPassword));
    try {
        rangerMasterKey.getMasterKey("badpass");
        Assert.fail("Failure expected on retrieving a key with the wrong password");
    } catch (Exception ex) {
    // expected
    }
    Assert.assertNotNull(rangerMasterKey.getMasterSecretKey(masterKeyPassword));
    try {
        rangerMasterKey.getMasterSecretKey("badpass");
        Assert.fail("Failure expected on retrieving a key with the wrong password");
    } catch (Exception ex) {
    // expected
    }
}
Also used : Path(java.nio.file.Path) RangerKMSDB(org.apache.hadoop.crypto.key.RangerKMSDB) RangerMasterKey(org.apache.hadoop.crypto.key.RangerMasterKey) DaoManager(org.apache.ranger.kms.dao.DaoManager) Test(org.junit.Test)

Aggregations

DaoManager (org.apache.ranger.kms.dao.DaoManager)18 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 Test (org.junit.Test)7 Configuration (org.apache.hadoop.conf.Configuration)6 RangerKeyStore (org.apache.hadoop.crypto.key.RangerKeyStore)6 IOException (java.io.IOException)5 KeyVaultClient (com.microsoft.azure.keyvault.KeyVaultClient)3 File (java.io.File)2 Path (java.nio.file.Path)2 Key (java.security.Key)2 KeyStoreException (java.security.KeyStoreException)2 ArrayList (java.util.ArrayList)2 RangerKMSDB (org.apache.hadoop.crypto.key.RangerKMSDB)2 RangerMasterKey (org.apache.hadoop.crypto.key.RangerMasterKey)2 XXRangerKeyStore (org.apache.ranger.entity.XXRangerKeyStore)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1