Search in sources :

Example 1 with KeyAttributes

use of com.microsoft.azure.keyvault.models.KeyAttributes in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method importKeyWithServiceResponseAsync.

/**
     * Imports an externally created key, stores it, and returns key parameters and attributes to the client. The import key operation may be used to import any key type into an Azure Key Vault. If the named key already exists, Azure Key Vault creates a new version of the key. Authorization: requires the keys/import permission.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param keyName Name for the imported key.
     * @param key The Json web key
     * @return the observable to the KeyBundle object
     */
public Observable<ServiceResponse<KeyBundle>> importKeyWithServiceResponseAsync(String vaultBaseUrl, String keyName, JsonWebKey key) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (keyName == null) {
        throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (key == null) {
        throw new IllegalArgumentException("Parameter key is required and cannot be null.");
    }
    Validator.validate(key);
    final Boolean hsm = null;
    final KeyAttributes keyAttributes = null;
    final Map<String, String> tags = null;
    KeyImportParameters parameters = new KeyImportParameters();
    parameters.withHsm(null);
    parameters.withKey(key);
    parameters.withKeyAttributes(null);
    parameters.withTags(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.importKey(keyName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyBundle>>>() {

        @Override
        public Observable<ServiceResponse<KeyBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<KeyBundle> clientResponse = importKeyDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : KeyAttributes(com.microsoft.azure.keyvault.models.KeyAttributes) KeyImportParameters(com.microsoft.azure.keyvault.models.KeyImportParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) KeyBundle(com.microsoft.azure.keyvault.models.KeyBundle)

Example 2 with KeyAttributes

use of com.microsoft.azure.keyvault.models.KeyAttributes in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method createKeyWithServiceResponseAsync.

/**
     * Creates a new key, stores it, then returns key parameters and attributes to the client. The create key operation can be used to create any key type in Azure Key Vault. If the named key already exists, Azure Key Vault creates a new version of the key. Authorization: Requires the keys/create permission.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param keyName The name for the new key. The system will generate the version name for the new key.
     * @param kty The type of key to create. For valid key types, see JsonWebKeyType. Supported JsonWebKey key types (kty) for Elliptic Curve, RSA, HSM, Octet. Possible values include: 'EC', 'RSA', 'RSA-HSM', 'oct'
     * @return the observable to the KeyBundle object
     */
public Observable<ServiceResponse<KeyBundle>> createKeyWithServiceResponseAsync(String vaultBaseUrl, String keyName, JsonWebKeyType kty) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (keyName == null) {
        throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (kty == null) {
        throw new IllegalArgumentException("Parameter kty is required and cannot be null.");
    }
    final Integer keySize = null;
    final List<JsonWebKeyOperation> keyOps = null;
    final KeyAttributes keyAttributes = null;
    final Map<String, String> tags = null;
    KeyCreateParameters parameters = new KeyCreateParameters();
    parameters.withKty(kty);
    parameters.withKeySize(null);
    parameters.withKeyOps(null);
    parameters.withKeyAttributes(null);
    parameters.withTags(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.createKey(keyName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyBundle>>>() {

        @Override
        public Observable<ServiceResponse<KeyBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<KeyBundle> clientResponse = createKeyDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : KeyAttributes(com.microsoft.azure.keyvault.models.KeyAttributes) KeyCreateParameters(com.microsoft.azure.keyvault.models.KeyCreateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) JsonWebKeyOperation(com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation) KeyBundle(com.microsoft.azure.keyvault.models.KeyBundle)

Example 3 with KeyAttributes

use of com.microsoft.azure.keyvault.models.KeyAttributes in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method updateKeyWithServiceResponseAsync.

/**
     * The update key operation changes specified attributes of a stored key and can be applied to any key type and key version stored in Azure Key Vault. The cryptographic material of a key itself cannot be changed. In order to perform this operation, the key must already exist in the Key Vault. Authorization: requires the keys/update permission.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param keyName The name of key to update.
     * @param keyVersion The version of the key to update.
     * @return the observable to the KeyBundle object
     */
public Observable<ServiceResponse<KeyBundle>> updateKeyWithServiceResponseAsync(String vaultBaseUrl, String keyName, String keyVersion) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (keyName == null) {
        throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
    }
    if (keyVersion == null) {
        throw new IllegalArgumentException("Parameter keyVersion is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    final List<JsonWebKeyOperation> keyOps = null;
    final KeyAttributes keyAttributes = null;
    final Map<String, String> tags = null;
    KeyUpdateParameters parameters = new KeyUpdateParameters();
    parameters.withKeyOps(null);
    parameters.withKeyAttributes(null);
    parameters.withTags(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.updateKey(keyName, keyVersion, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyBundle>>>() {

        @Override
        public Observable<ServiceResponse<KeyBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<KeyBundle> clientResponse = updateKeyDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : KeyAttributes(com.microsoft.azure.keyvault.models.KeyAttributes) KeyUpdateParameters(com.microsoft.azure.keyvault.models.KeyUpdateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) JsonWebKeyOperation(com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation) KeyBundle(com.microsoft.azure.keyvault.models.KeyBundle)

Example 4 with KeyAttributes

use of com.microsoft.azure.keyvault.models.KeyAttributes in project azure-sdk-for-java by Azure.

the class KeyOperationsTest method checkImportOperation.

private void checkImportOperation(KeyBundle keyBundle, boolean importToHardware) throws Exception {
    Attributes attribute = new KeyAttributes().withEnabled(true).withExpires(new DateTime().withYear(2050).withMonthOfYear(1)).withNotBefore(new DateTime().withYear(2000).withMonthOfYear(1));
    Map<String, String> tags = new HashMap<String, String>();
    tags.put("foo", "baz");
    JsonWebKey importedJwk = keyBundle.key();
    KeyBundle importResultBundle = keyVaultClient.importKey(new ImportKeyRequest.Builder(getVaultUri(), KEY_NAME, keyBundle.key()).withHsm(importToHardware).withAttributes(attribute).withTags(tags).build());
    validateRsaKeyBundle(importResultBundle, getVaultUri(), KEY_NAME, importToHardware ? JsonWebKeyType.RSA_HSM : JsonWebKeyType.RSA, importedJwk.keyOps(), attribute);
    checkEncryptDecryptSequence(importedJwk, importResultBundle);
    Assert.assertTrue(importResultBundle.key().isValid());
}
Also used : HashMap(java.util.HashMap) KeyAttributes(com.microsoft.azure.keyvault.models.KeyAttributes) ImportKeyRequest(com.microsoft.azure.keyvault.requests.ImportKeyRequest) Attributes(com.microsoft.azure.keyvault.models.Attributes) KeyAttributes(com.microsoft.azure.keyvault.models.KeyAttributes) JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) KeyBundle(com.microsoft.azure.keyvault.models.KeyBundle) DateTime(org.joda.time.DateTime)

Example 5 with KeyAttributes

use of com.microsoft.azure.keyvault.models.KeyAttributes 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

KeyAttributes (com.microsoft.azure.keyvault.models.KeyAttributes)5 KeyBundle (com.microsoft.azure.keyvault.models.KeyBundle)4 ServiceResponse (com.microsoft.rest.ServiceResponse)3 ResponseBody (okhttp3.ResponseBody)3 Response (retrofit2.Response)3 Observable (rx.Observable)3 Attributes (com.microsoft.azure.keyvault.models.Attributes)2 JsonWebKeyOperation (com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation)2 DateTime (org.joda.time.DateTime)2 KeyCreateParameters (com.microsoft.azure.keyvault.models.KeyCreateParameters)1 KeyImportParameters (com.microsoft.azure.keyvault.models.KeyImportParameters)1 KeyUpdateParameters (com.microsoft.azure.keyvault.models.KeyUpdateParameters)1 CreateKeyRequest (com.microsoft.azure.keyvault.requests.CreateKeyRequest)1 ImportKeyRequest (com.microsoft.azure.keyvault.requests.ImportKeyRequest)1 JsonWebKey (com.microsoft.azure.keyvault.webkey.JsonWebKey)1 JsonWebKeyType (com.microsoft.azure.keyvault.webkey.JsonWebKeyType)1 HashMap (java.util.HashMap)1