use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.
the class VerifyIsHSMMasterkeyCorrect method getHSMMasterkey.
public void getHSMMasterkey(String hsmType, String partitionName) {
char[] partitionPassword = null;
try {
partitionPassword = ConsoleUtil.getPasswordFromConsole("Enter Password for the Partition " + partitionName + " : ");
Configuration conf = RangerKeyStoreProvider.getDBKSConf();
conf.set(HSM_TYPE, hsmType);
conf.set(PARTITION_NAME, partitionName);
conf.set(PARTITION_PASSWORD, String.valueOf(partitionPassword));
String password = conf.get(ENCRYPTION_KEY);
RangerKMSDB rangerkmsDb = new RangerKMSDB(conf);
DaoManager daoManager = rangerkmsDb.getDaoManager();
RangerKeyStore dbStore = new RangerKeyStore(daoManager);
// Get Master Key from HSM
RangerHSM rangerHSM = new RangerHSM(conf);
String hsmMasterKey = rangerHSM.getMasterKey(password);
if (hsmMasterKey == null) {
// Master Key does not exists
throw new IOException("Ranger MasterKey does not exists in HSM!!!");
}
dbStore.engineLoad(null, hsmMasterKey.toCharArray());
System.out.println("KMS keystore engine loaded successfully.");
} catch (Throwable t) {
throw new RuntimeException("Unable to load keystore engine with given password or Masterkey was tampered.", t);
}
}
use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.
the class TestRangerKeyStore method testInvalidKey1.
@Test(expected = IOException.class)
public void testInvalidKey1() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
DaoManager daoManager = Mockito.mock(DaoManager.class);
RangerKeyStore rangerKeyStore = new RangerKeyStore(daoManager);
String keyValue = "enckey:1";
InputStream inputStream = generateKeyStoreFile(keyValue);
rangerKeyStore.engineLoadKeyStoreFile(inputStream, storePass, keyPass, masterKey, fileFormat);
inputStream.close();
}
use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.
the class TestRangerKeyStore method testInvalidKey2.
@Test(expected = IOException.class)
public void testInvalidKey2() 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();
}
use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.
the class TestRangerKeyStore method testValidKey2.
@Test
public void testValidKey2() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
DaoManager daoManager = Mockito.mock(DaoManager.class);
RangerKeyStore rangerKeyStore = new RangerKeyStore(daoManager);
String keyValue = "1-enckey_test";
InputStream inputStream = generateKeyStoreFile(keyValue);
rangerKeyStore.engineLoadKeyStoreFile(inputStream, storePass, keyPass, masterKey, fileFormat);
inputStream.close();
}
use of org.apache.ranger.kms.dao.DaoManager in project ranger by apache.
the class DB2HSMMKUtil method doExportMKToHSM.
private boolean doExportMKToHSM(String hsmType, String partitionName) {
char[] partitionPassword = null;
try {
partitionPassword = ConsoleUtil.getPasswordFromConsole("Enter Password for the Partition " + partitionName + " : ");
Configuration conf = RangerKeyStoreProvider.getDBKSConf();
conf.set(HSM_TYPE, hsmType);
conf.set(PARTITION_NAME, partitionName);
conf.set(PARTITION_PASSWORD, String.valueOf(partitionPassword));
RangerKMSDB rangerkmsDb = new RangerKMSDB(conf);
DaoManager daoManager = rangerkmsDb.getDaoManager();
String password = conf.get(ENCRYPTION_KEY);
// Get Master Key from Ranger DB
RangerMasterKey rangerMasterKey = new RangerMasterKey(daoManager);
String mkey = rangerMasterKey.getMasterKey(password);
byte[] key = Base64.decode(mkey);
// Put Master Key in HSM
RangerHSM rangerHSM = new RangerHSM(conf);
return rangerHSM.setMasterKey(password, key);
} catch (Throwable t) {
throw new RuntimeException("Unable to import Master key from Ranger DB to HSM ", t);
} finally {
Arrays.fill(partitionPassword, ' ');
}
}
Aggregations