use of com.microsoft.azure.keyvault.webkey.JsonWebKeyType in project ranger by apache.
the class RangerAzureKeyVaultKeyGenerator method generateMasterKey.
@Override
public boolean generateMasterKey(String password) throws Exception {
if (keyVaultClient == null) {
throw new Exception("Key Vault Client is null. Please check the azure related configuration.");
}
try {
masterKeyBundle = keyVaultClient.getKey(keyVaultURL, azureMasterKey);
} catch (Exception ex) {
throw new Exception("Error while getting existing master key from Azure. Master Key Name : " + azureMasterKey + " . Key Vault URL : " + keyVaultURL + " . Error : " + ex.getMessage());
}
if (masterKeyBundle == null) {
try {
JsonWebKeyType keyType;
switch(azureMasterKeyType) {
case "RSA":
keyType = JsonWebKeyType.RSA;
break;
case "RSA_HSM":
keyType = JsonWebKeyType.RSA_HSM;
break;
case "EC":
keyType = JsonWebKeyType.EC;
break;
case "EC_HSM":
keyType = JsonWebKeyType.EC_HSM;
break;
case "OCT":
keyType = JsonWebKeyType.OCT;
break;
default:
keyType = JsonWebKeyType.RSA;
}
Attributes masterKeyattribute = new KeyAttributes().withEnabled(true).withNotBefore(new DateTime());
CreateKeyRequest createKeyRequest = new CreateKeyRequest.Builder(keyVaultURL, azureMasterKey, keyType).withAttributes(masterKeyattribute).build();
masterKeyBundle = keyVaultClient.createKeyAsync(createKeyRequest, null).get();
return true;
} catch (Exception ex) {
throw new Exception("Error while creating master key : " + ex.getMessage());
}
} else {
logger.info("Azure Master key exist with name :" + azureMasterKey + " with key identifier " + masterKeyBundle.key().kid());
return true;
}
}
Aggregations