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");
}
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");
}
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");
}
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())));
}
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();
}
Aggregations