Search in sources :

Example 21 with KeyData

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");
}
Also used : KeyData(com.quorum.tessera.config.KeyData)

Example 22 with KeyData

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);
}
Also used : KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 23 with KeyData

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");
}
Also used : KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 24 with KeyData

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);
}
Also used : KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 25 with KeyData

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();
}
Also used : Path(java.nio.file.Path) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Aggregations

KeyData (com.quorum.tessera.config.KeyData)34 Test (org.junit.Test)32 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)31 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)10 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)7 Path (java.nio.file.Path)7 Config (com.quorum.tessera.config.Config)1 KeyConfiguration (com.quorum.tessera.config.KeyConfiguration)1 DirectKeyPair (com.quorum.tessera.config.keypairs.DirectKeyPair)1 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)1 KeyPair (com.quorum.tessera.encryption.KeyPair)1 ArrayList (java.util.ArrayList)1