Search in sources :

Example 1 with RangerMasterKey

use of org.apache.hadoop.crypto.key.RangerMasterKey in project testcases by coheigea.

the class RangerMasterKeyTest method testRangerMasterKey.

@org.junit.Test
public void testRangerMasterKey() throws Throwable {
    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 (Throwable t) {
    // expected
    }
    Assert.assertNotNull(rangerMasterKey.getMasterSecretKey(masterKeyPassword));
    try {
        rangerMasterKey.getMasterSecretKey("badpass");
        Assert.fail("Failure expected on retrieving a key with the wrong password");
    } catch (Throwable t) {
    // 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)

Example 2 with RangerMasterKey

use of org.apache.hadoop.crypto.key.RangerMasterKey in project ranger by apache.

the class RangerKMSStartUp method initRangerMasterKey.

@PostConstruct
public void initRangerMasterKey() {
    LOG.info("Ranger KMSStartUp");
    RangerMasterKey rangerMasterKey = new RangerMasterKey();
    try {
        Configuration conf = RangerKeyStoreProvider.getDBKSConf();
        String password = conf.get(ENCRYPTION_KEY);
        boolean check = rangerMasterKey.generateMasterKey(password);
        if (check) {
            LOG.info("MasterKey Generated..");
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) RangerMasterKey(org.apache.hadoop.crypto.key.RangerMasterKey) PostConstruct(javax.annotation.PostConstruct)

Example 3 with RangerMasterKey

use of org.apache.hadoop.crypto.key.RangerMasterKey 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

RangerMasterKey (org.apache.hadoop.crypto.key.RangerMasterKey)3 Path (java.nio.file.Path)2 RangerKMSDB (org.apache.hadoop.crypto.key.RangerKMSDB)2 DaoManager (org.apache.ranger.kms.dao.DaoManager)2 PostConstruct (javax.annotation.PostConstruct)1 Configuration (org.apache.hadoop.conf.Configuration)1 Test (org.junit.Test)1