Search in sources :

Example 1 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalHashicorpVaultKeyPair.

@Test
public void unmarshalHashicorpVaultKeyPair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    keyData.setHashicorpVaultPrivateKeyId("HashicorpVaultPrivateKeyId");
    keyData.setHashicorpVaultPublicKeyId("HashicorpVaultPublicKeyId");
    keyData.setHashicorpVaultSecretVersion("99");
    keyData.setHashicorpVaultSecretName("HashicorpSecretName");
    keyData.setHashicorpVaultSecretEngineName("HashicorpVaultSecretEngineName");
    HashicorpVaultKeyPair result = (HashicorpVaultKeyPair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull();
    assertThat(result.getPrivateKeyId()).isEqualTo("HashicorpVaultPrivateKeyId");
    assertThat(result.getPublicKeyId()).isEqualTo("HashicorpVaultPublicKeyId");
    assertThat(result.getSecretVersion()).isEqualTo(99);
    assertThat(result.getSecretEngineName()).isEqualTo("HashicorpVaultSecretEngineName");
    assertThat(result.getSecretName()).isEqualTo("HashicorpSecretName");
    verifyZeroInteractions(keyEncryptor);
}
Also used : KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 2 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalUnknownKeyPair.

@Test
public void unmarshalUnknownKeyPair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    UnsupportedKeyPair result = (UnsupportedKeyPair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull();
    verifyZeroInteractions(keyEncryptor);
}
Also used : KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 3 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalHashicorpVaultKeyPairNoSecretVersionDefined.

@Test
public void unmarshalHashicorpVaultKeyPairNoSecretVersionDefined() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    keyData.setHashicorpVaultPrivateKeyId("HashicorpVaultPrivateKeyId");
    keyData.setHashicorpVaultPublicKeyId("HashicorpVaultPublicKeyId");
    keyData.setHashicorpVaultSecretName("HashicorpSecretName");
    keyData.setHashicorpVaultSecretEngineName("HashicorpVaultSecretEngineName");
    HashicorpVaultKeyPair result = (HashicorpVaultKeyPair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull();
    assertThat(result.getPrivateKeyId()).isEqualTo("HashicorpVaultPrivateKeyId");
    assertThat(result.getPublicKeyId()).isEqualTo("HashicorpVaultPublicKeyId");
    assertThat(result.getSecretVersion()).isZero();
    assertThat(result.getSecretEngineName()).isEqualTo("HashicorpVaultSecretEngineName");
    assertThat(result.getSecretName()).isEqualTo("HashicorpSecretName");
    verifyZeroInteractions(keyEncryptor);
}
Also used : KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 4 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalFilesystemKeyPair.

@Test
public void unmarshalFilesystemKeyPair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    Path privateKeyPath = mock(Path.class);
    Path publicKeyPath = mock(Path.class);
    keyData.setPrivateKeyPath(privateKeyPath);
    keyData.setPublicKeyPath(publicKeyPath);
    FilesystemKeyPair result = (FilesystemKeyPair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull();
    assertThat(result.getPrivateKeyPath()).isSameAs(privateKeyPath);
    assertThat(result.getPublicKeyPath()).isSameAs(publicKeyPath);
    verifyZeroInteractions(keyEncryptor);
}
Also used : Path(java.nio.file.Path) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 5 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method marshalInlineKeypair.

@Test
public void marshalInlineKeypair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyDataConfig keyDataConfig = mock(KeyDataConfig.class);
    InlineKeypair keyPair = new InlineKeypair("PUBLIC_KEY", keyDataConfig, keyEncryptor);
    KeyData result = KeyDataUtil.marshal(keyPair);
    assertThat(result.getPublicKey()).isEqualTo("PUBLIC_KEY");
    assertThat(result.getConfig()).isSameAs(keyDataConfig);
}
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)

Aggregations

KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)20 Test (org.junit.Test)15 KeyData (com.quorum.tessera.config.KeyData)10 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)10 Path (java.nio.file.Path)5 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)4 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)4 CliResult (com.quorum.tessera.cli.CliResult)3 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)3 ConstraintViolationException (jakarta.validation.ConstraintViolationException)3 HashMap (java.util.HashMap)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 CliException (com.quorum.tessera.cli.CliException)2 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)2 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 EnvironmentVariableProvider (com.quorum.tessera.config.util.EnvironmentVariableProvider)2 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)2 Encryptor (com.quorum.tessera.encryption.Encryptor)2 PublicKey (com.quorum.tessera.encryption.PublicKey)2 Client (jakarta.ws.rs.client.Client)2