Search in sources :

Example 1 with JsonWebKeyOperation

use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation 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 2 with JsonWebKeyOperation

use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation 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 3 with JsonWebKeyOperation

use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation in project azure-sdk-for-java by Azure.

the class RsaValidationTests method validateRsaKey.

private static void validateRsaKey(KeyPair keyPair, JsonWebKey key) throws Exception {
    JsonWebKey jsonWebKey = JsonWebKey.fromRSA(keyPair);
    boolean includePrivateKey = keyPair.getPrivate() != null;
    KeyPair keyPair2 = jsonWebKey.toRSA(includePrivateKey);
    Assert.assertTrue(includePrivateKey == jsonWebKey.hasPrivateKey());
    PublicKey publicKey = keyPair2.getPublic();
    PrivateKey privateKey = keyPair2.getPrivate();
    if (includePrivateKey) {
        Assert.assertNotNull(privateKey);
        // set the missing properties to compare the keys
        jsonWebKey.withKeyOps(new ArrayList<JsonWebKeyOperation>(key.keyOps()));
        jsonWebKey.withKid(new String(key.kid()));
        Assert.assertEquals(jsonWebKey, key);
        Assert.assertEquals(key.hashCode(), jsonWebKey.hashCode());
    }
    encryptDecrypt(publicKey, privateKey);
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) JsonWebKeyOperation(com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation) PublicKey(java.security.PublicKey) JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey)

Example 4 with JsonWebKeyOperation

use of com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation in project azure-sdk-for-java by Azure.

the class AesValidationTests method invalidKeyOps.

@Test
public void invalidKeyOps() throws Exception {
    JsonWebKey key = getAes();
    key.withKeyOps(Arrays.asList(JsonWebKeyOperation.ENCRYPT, new JsonWebKeyOperation("foo")));
    Assert.assertFalse(key.isValid());
}
Also used : JsonWebKeyOperation(com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation) JsonWebKey(com.microsoft.azure.keyvault.webkey.JsonWebKey) Test(org.junit.Test)

Aggregations

JsonWebKeyOperation (com.microsoft.azure.keyvault.webkey.JsonWebKeyOperation)4 KeyAttributes (com.microsoft.azure.keyvault.models.KeyAttributes)2 KeyBundle (com.microsoft.azure.keyvault.models.KeyBundle)2 JsonWebKey (com.microsoft.azure.keyvault.webkey.JsonWebKey)2 ServiceResponse (com.microsoft.rest.ServiceResponse)2 ResponseBody (okhttp3.ResponseBody)2 Response (retrofit2.Response)2 Observable (rx.Observable)2 KeyCreateParameters (com.microsoft.azure.keyvault.models.KeyCreateParameters)1 KeyUpdateParameters (com.microsoft.azure.keyvault.models.KeyUpdateParameters)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 Test (org.junit.Test)1