Search in sources :

Example 1 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class ValidationTest method azureKeyPairOnlyPublicKeyVersionSetCreatesViolation.

@Test
public void azureKeyPairOnlyPublicKeyVersionSetCreatesViolation() {
    String is32Chars = "12345678901234567890123456789012";
    AzureVaultKeyPair azureVaultKeyPair = new AzureVaultKeyPair("pubId", "privId", is32Chars, null);
    Set<ConstraintViolation<AzureVaultKeyPair>> violations = validator.validate(azureVaultKeyPair);
    assertThat(violations).hasSize(1);
    assertThat(violations.iterator().next().getMessage()).isEqualTo("Only one key version was provided for the Azure vault key pair.  Either set the version for both the public and private key, or leave both unset");
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Example 2 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class ValidationTest method azureKeyPairOnlyPrivateKeyVersionSetCreatesViolation.

@Test
public void azureKeyPairOnlyPrivateKeyVersionSetCreatesViolation() {
    String is32Chars = "12345678901234567890123456789012";
    AzureVaultKeyPair azureVaultKeyPair = new AzureVaultKeyPair("pubId", "privId", null, is32Chars);
    Set<ConstraintViolation<AzureVaultKeyPair>> violations = validator.validate(azureVaultKeyPair);
    assertThat(violations).hasSize(1);
    assertThat(violations.iterator().next().getMessage()).isEqualTo("Only one key version was provided for the Azure vault key pair.  Either set the version for both the public and private key, or leave both unset");
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Example 3 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class ValidationTest method azureKeyPairKeyVersionShorterThan32CharsCreatesViolation.

@Test
public void azureKeyPairKeyVersionShorterThan32CharsCreatesViolation() {
    String is31Chars = "1234567890123456789012345678901";
    AzureVaultKeyPair keyPair = new AzureVaultKeyPair("id", "id", is31Chars, is31Chars);
    Set<ConstraintViolation<AzureVaultKeyPair>> violations = validator.validate(keyPair);
    assertThat(violations).hasSize(2);
    assertThat(violations).extracting("messageTemplate").containsExactly("length must be 32 characters", "length must be 32 characters");
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Example 4 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class KeyPairConverter method convert.

private KeyPair convert(ConfigKeyPair configKeyPair) {
    final String base64PublicKey;
    final String base64PrivateKey;
    if (configKeyPair instanceof AzureVaultKeyPair) {
        KeyVaultServiceFactory keyVaultServiceFactory = KeyVaultServiceFactory.getInstance(KeyVaultType.AZURE);
        KeyVaultService keyVaultService = keyVaultServiceFactory.create(config, envProvider);
        AzureVaultKeyPair akp = (AzureVaultKeyPair) configKeyPair;
        Map<String, String> getPublicKeyData = new HashMap<>(Map.of("secretName", akp.getPublicKeyId()));
        getPublicKeyData.put("secretVersion", akp.getPublicKeyVersion());
        Map<String, String> getPrivateKeyData = new HashMap<>(Map.of("secretName", akp.getPrivateKeyId()));
        getPrivateKeyData.put("secretVersion", akp.getPrivateKeyVersion());
        base64PublicKey = keyVaultService.getSecret(getPublicKeyData);
        base64PrivateKey = keyVaultService.getSecret(getPrivateKeyData);
    } else if (configKeyPair instanceof HashicorpVaultKeyPair) {
        KeyVaultServiceFactory keyVaultServiceFactory = KeyVaultServiceFactory.getInstance(KeyVaultType.HASHICORP);
        KeyVaultService keyVaultService = keyVaultServiceFactory.create(config, envProvider);
        HashicorpVaultKeyPair hkp = (HashicorpVaultKeyPair) configKeyPair;
        Map<String, String> getPublicKeyData = Map.of("secretEngineName", hkp.getSecretEngineName(), "secretName", hkp.getSecretName(), "secretId", hkp.getPublicKeyId(), "secretVersion", Objects.toString(hkp.getSecretVersion()));
        Map<String, String> getPrivateKeyData = Map.of("secretEngineName", hkp.getSecretEngineName(), "secretName", hkp.getSecretName(), "secretId", hkp.getPrivateKeyId(), "secretVersion", Objects.toString(hkp.getSecretVersion()));
        base64PublicKey = keyVaultService.getSecret(getPublicKeyData);
        base64PrivateKey = keyVaultService.getSecret(getPrivateKeyData);
    } else if (configKeyPair instanceof AWSKeyPair) {
        KeyVaultServiceFactory keyVaultServiceFactory = KeyVaultServiceFactory.getInstance(KeyVaultType.AWS);
        KeyVaultService keyVaultService = keyVaultServiceFactory.create(config, envProvider);
        AWSKeyPair akp = (AWSKeyPair) configKeyPair;
        Map<String, String> getPublicKeyData = Map.of("secretName", akp.getPublicKeyId());
        Map<String, String> getPrivateKeyData = Map.of("secretName", akp.getPrivateKeyId());
        base64PublicKey = keyVaultService.getSecret(getPublicKeyData);
        base64PrivateKey = keyVaultService.getSecret(getPrivateKeyData);
    } else {
        base64PublicKey = configKeyPair.getPublicKey();
        base64PrivateKey = configKeyPair.getPrivateKey();
    }
    return new KeyPair(PublicKey.from(Base64.getDecoder().decode(base64PublicKey.trim())), PrivateKey.from(Base64.getDecoder().decode(base64PrivateKey.trim())));
}
Also used : HashicorpVaultKeyPair(com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair) KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) KeyPair(com.quorum.tessera.encryption.KeyPair) AWSKeyPair(com.quorum.tessera.config.keypairs.AWSKeyPair) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) HashicorpVaultKeyPair(com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair) AWSKeyPair(com.quorum.tessera.config.keypairs.AWSKeyPair) KeyVaultServiceFactory(com.quorum.tessera.key.vault.KeyVaultServiceFactory) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair)

Example 5 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class DefaultKeyVaultConfigValidationsTest method validCase.

@Test
public void validCase() {
    KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    // Not ideal. Having to use config object in tests to apply validation rules.
    KeyVaultConfig keyVaultConfig = new DefaultKeyVaultConfig() {

        {
            setKeyVaultType(KeyVaultType.AZURE);
        }
    };
    List<KeyVaultConfig> keyVaultConfigList = Arrays.asList(mock(KeyVaultConfig.class));
    when(keyConfiguration.getKeyVaultConfigs()).thenReturn(keyVaultConfigList);
    ConfigKeyPair keyPair = new AzureVaultKeyPair("publicKeyId", "privateKeyId", null, null);
    List<ConfigKeyPair> keyPairs = Arrays.asList(keyPair);
    Set<ConstraintViolation<?>> results = validator.validate(keyConfiguration, keyPairs);
    assertThat(results).isEmpty();
}
Also used : KeyVaultConfig(com.quorum.tessera.config.KeyVaultConfig) DefaultKeyVaultConfig(com.quorum.tessera.config.DefaultKeyVaultConfig) DefaultKeyVaultConfig(com.quorum.tessera.config.DefaultKeyVaultConfig) KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) ConstraintViolation(jakarta.validation.ConstraintViolation) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Aggregations

AzureVaultKeyPair (com.quorum.tessera.config.keypairs.AzureVaultKeyPair)11 Test (org.junit.Test)9 ConstraintViolation (jakarta.validation.ConstraintViolation)8 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 KeyPair (com.quorum.tessera.encryption.KeyPair)2 DefaultKeyVaultConfig (com.quorum.tessera.config.DefaultKeyVaultConfig)1 KeyConfiguration (com.quorum.tessera.config.KeyConfiguration)1 KeyVaultConfig (com.quorum.tessera.config.KeyVaultConfig)1 AWSKeyPair (com.quorum.tessera.config.keypairs.AWSKeyPair)1 HashicorpVaultKeyPair (com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair)1 KeyVaultService (com.quorum.tessera.key.vault.KeyVaultService)1 KeyVaultServiceFactory (com.quorum.tessera.key.vault.KeyVaultServiceFactory)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1