use of com.quorum.tessera.config.keypairs.AWSKeyPair 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.AWSKeyPair in project tessera by ConsenSys.
the class AWSSecretManagerKeyGenerator method generate.
@Override
public AWSKeyPair generate(String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) {
final KeyPair keys = this.encryptor.generateNewKeys();
final StringBuilder publicId = new StringBuilder();
final StringBuilder privateId = new StringBuilder();
if (filename != null) {
final Path path = Paths.get(filename);
final String secretId = path.getFileName().toString();
if (!secretId.matches("^[0-9a-zA-Z\\-/_+=.@]*$")) {
throw new UnsupportedCharsetException("Generated key ID for AWS Secret Manager can contain only 0-9, a-z, A-Z and /_+=.@- characters");
}
publicId.append(secretId);
privateId.append(secretId);
}
publicId.append("Pub");
privateId.append("Key");
saveKeyInSecretManager(publicId.toString(), keys.getPublicKey());
saveKeyInSecretManager(privateId.toString(), keys.getPrivateKey());
return new AWSKeyPair(publicId.toString(), privateId.toString());
}
use of com.quorum.tessera.config.keypairs.AWSKeyPair in project tessera by ConsenSys.
the class AWSSecretManagerKeyGeneratorTest method keysSavedInVaultWithProvidedVaultIdAndCorrectSuffix.
@Test
public void keysSavedInVaultWithProvidedVaultIdAndCorrectSuffix() {
final String vaultId = "vaultId";
final String pubVaultId = vaultId + "Pub";
final String privVaultId = vaultId + "Key";
final AWSKeyPair result = awsSecretManagerKeyGenerator.generate(vaultId, null, null);
final ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
verify(keyVaultService, times(2)).setSecret(captor.capture());
List<Map> capturedArgs = captor.getAllValues();
assertThat(capturedArgs).hasSize(2);
Map<String, String> expectedDataPub = Map.of("secretName", pubVaultId, "secret", pub.encodeToBase64());
Map<String, String> expectedDataPriv = Map.of("secretName", privVaultId, "secret", priv.encodeToBase64());
assertThat(capturedArgs).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder(expectedDataPub, expectedDataPriv);
verifyNoMoreInteractions(keyVaultService);
final AWSKeyPair expected = new AWSKeyPair(pubVaultId, privVaultId);
assertThat(result).isExactlyInstanceOf(AWSKeyPair.class);
assertThat(result).isEqualToComparingFieldByField(expected);
}
Aggregations