use of com.quorum.tessera.config.KeyData in project tessera by ConsenSys.
the class KeyDataUtil method marshal.
public static KeyData marshal(final ConfigKeyPair keyPair) {
final KeyData keyData = new KeyData();
if (DirectKeyPair.class.isInstance(keyPair)) {
DirectKeyPair kp = DirectKeyPair.class.cast(keyPair);
keyData.setPublicKey(kp.getPublicKey());
keyData.setPrivateKey(kp.getPrivateKey());
return keyData;
}
if (InlineKeypair.class.isInstance(keyPair)) {
InlineKeypair kp = InlineKeypair.class.cast(keyPair);
keyData.setPublicKey(kp.getPublicKey());
keyData.setConfig(kp.getPrivateKeyConfig());
return keyData;
}
if (AzureVaultKeyPair.class.isInstance(keyPair)) {
AzureVaultKeyPair kp = AzureVaultKeyPair.class.cast(keyPair);
keyData.setAzureVaultPublicKeyId(kp.getPublicKeyId());
keyData.setAzureVaultPrivateKeyId(kp.getPrivateKeyId());
keyData.setAzureVaultPublicKeyVersion(kp.getPublicKeyVersion());
keyData.setAzureVaultPrivateKeyVersion(kp.getPrivateKeyVersion());
return keyData;
}
if (HashicorpVaultKeyPair.class.isInstance(keyPair)) {
HashicorpVaultKeyPair kp = HashicorpVaultKeyPair.class.cast(keyPair);
keyData.setHashicorpVaultPublicKeyId(kp.getPublicKeyId());
keyData.setHashicorpVaultPrivateKeyId(kp.getPrivateKeyId());
keyData.setHashicorpVaultSecretEngineName(kp.getSecretEngineName());
keyData.setHashicorpVaultSecretName(kp.getSecretName());
keyData.setHashicorpVaultSecretVersion(Objects.toString(kp.getSecretVersion(), null));
return keyData;
}
if (AWSKeyPair.class.isInstance(keyPair)) {
AWSKeyPair kp = AWSKeyPair.class.cast(keyPair);
keyData.setAwsSecretsManagerPublicKeyId(kp.getPublicKeyId());
keyData.setAwsSecretsManagerPrivateKeyId(kp.getPrivateKeyId());
return keyData;
}
if (FilesystemKeyPair.class.isInstance(keyPair)) {
FilesystemKeyPair kp = FilesystemKeyPair.class.cast(keyPair);
keyData.setPublicKeyPath(kp.getPublicKeyPath());
keyData.setPrivateKeyPath(kp.getPrivateKeyPath());
return keyData;
}
if (UnsupportedKeyPair.class.isInstance(keyPair)) {
UnsupportedKeyPair kp = UnsupportedKeyPair.class.cast(keyPair);
return new KeyData(kp.getConfig(), kp.getPrivateKey(), kp.getPublicKey(), kp.getPrivateKeyPath(), kp.getPublicKeyPath(), kp.getAzureVaultPrivateKeyId(), kp.getAzureVaultPublicKeyId(), kp.getAzureVaultPublicKeyVersion(), kp.getAzureVaultPrivateKeyVersion(), kp.getHashicorpVaultPrivateKeyId(), kp.getHashicorpVaultPublicKeyId(), kp.getHashicorpVaultSecretEngineName(), kp.getHashicorpVaultSecretName(), kp.getHashicorpVaultSecretVersion(), kp.getAwsSecretsManagerPublicKeyId(), kp.getAwsSecretsManagerPrivateKeyId());
}
throw new UnsupportedOperationException("The keypair type " + keyPair.getClass() + " is not allowed");
}
use of com.quorum.tessera.config.KeyData in project tessera by ConsenSys.
the class KeyDataUtilTest method getKeyPairTypeForHashicorpVaultKeyPair.
@Test
public void getKeyPairTypeForHashicorpVaultKeyPair() {
KeyData keyData = new KeyData();
keyData.setHashicorpVaultSecretName("HASHICORP_SECRET_NAME");
keyData.setHashicorpVaultSecretEngineName("HASHICORP_VAULT_ENGINE");
keyData.setHashicorpVaultPrivateKeyId("HASHICORP_PRIVATE_ID");
keyData.setHashicorpVaultPublicKeyId("HASHICORP_PUBLIC_ID");
Class<? extends ConfigKeyPair> result = KeyDataUtil.getKeyPairTypeFor(keyData);
assertThat(result).isEqualTo(HashicorpVaultKeyPair.class);
}
use of com.quorum.tessera.config.KeyData in project tessera by ConsenSys.
the class KeyDataUtilTest method marshalAwsKeypair.
@Test
public void marshalAwsKeypair() {
AWSKeyPair keyPair = new AWSKeyPair("AwsSecretsManagerPublicKeyId", "AwsSecretsManagerPrivateKeyId");
KeyData result = KeyDataUtil.marshal(keyPair);
assertThat(result.getAwsSecretsManagerPublicKeyId()).isEqualTo("AwsSecretsManagerPublicKeyId");
assertThat(result.getAwsSecretsManagerPrivateKeyId()).isEqualTo("AwsSecretsManagerPrivateKeyId");
}
use of com.quorum.tessera.config.KeyData in project tessera by ConsenSys.
the class KeyDataUtilTest method unmarshalAzureVaultKeyPair.
@Test
public void unmarshalAzureVaultKeyPair() {
KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
KeyData keyData = new KeyData();
keyData.setAzureVaultPrivateKeyId("AzureVaultPrivateKeyId");
keyData.setAzureVaultPublicKeyId("AzureVaultPublicKeyId");
KeyDataConfig config = mock(KeyDataConfig.class);
keyData.setConfig(config);
AzureVaultKeyPair result = (AzureVaultKeyPair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
assertThat(result).isNotNull();
assertThat(result.getPrivateKeyId()).isEqualTo("AzureVaultPrivateKeyId");
assertThat(result.getPublicKeyId()).isEqualTo("AzureVaultPublicKeyId");
verifyZeroInteractions(keyEncryptor);
}
use of com.quorum.tessera.config.KeyData in project tessera by ConsenSys.
the class KeyDataUtilTest method isLockedFromFileSystem.
@Test
public void isLockedFromFileSystem() throws URISyntaxException {
KeyData keyData = new KeyData();
keyData.setPublicKeyPath(mock(Path.class));
final Path privUnlockedFile = Paths.get(getClass().getResource("/unlockedprivatekey.json").toURI());
keyData.setPrivateKeyPath(privUnlockedFile);
assertThat(KeyDataUtil.isLocked(keyData)).isFalse();
final Path privLockedFile = Paths.get(getClass().getResource("/lockedprivatekey.json").toURI());
keyData.setPrivateKeyPath(privLockedFile);
assertThat(KeyDataUtil.isLocked(keyData)).isTrue();
}
Aggregations