Search in sources :

Example 1 with JsonWebKeyType

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;
    }
}
Also used : JsonWebKeyType(com.microsoft.azure.keyvault.webkey.JsonWebKeyType) KeyAttributes(com.microsoft.azure.keyvault.models.KeyAttributes) CreateKeyRequest(com.microsoft.azure.keyvault.requests.CreateKeyRequest) KeyAttributes(com.microsoft.azure.keyvault.models.KeyAttributes) Attributes(com.microsoft.azure.keyvault.models.Attributes) DateTime(org.joda.time.DateTime)

Aggregations

Attributes (com.microsoft.azure.keyvault.models.Attributes)1 KeyAttributes (com.microsoft.azure.keyvault.models.KeyAttributes)1 CreateKeyRequest (com.microsoft.azure.keyvault.requests.CreateKeyRequest)1 JsonWebKeyType (com.microsoft.azure.keyvault.webkey.JsonWebKeyType)1 DateTime (org.joda.time.DateTime)1