Search in sources :

Example 16 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig in project tessera by ConsenSys.

the class InlineKeypairTest method incorrectPasswordGetsCorrectFailureToken.

@Test
public void incorrectPasswordGetsCorrectFailureToken() {
    PrivateKeyData privateKeyData = mock(PrivateKeyData.class);
    final KeyDataConfig privKeyDataConfig = mock(KeyDataConfig.class);
    when(privKeyDataConfig.getPrivateKeyData()).thenReturn(privateKeyData);
    when(privKeyDataConfig.getType()).thenReturn(PrivateKeyType.LOCKED);
    when(keyEncryptor.decryptPrivateKey(privateKeyData, "wrong-password".toCharArray())).thenThrow(new EncryptorException("WHAT YOU TALKING ABOUT WILLIS"));
    final InlineKeypair inlineKeypair = new InlineKeypair("public", privKeyDataConfig, keyEncryptor);
    inlineKeypair.withPassword("wrong-password".toCharArray());
    String result = inlineKeypair.getPrivateKey();
    assertThat(String.valueOf(inlineKeypair.getPassword())).isEqualTo("wrong-password");
    assertThat(result).isEqualTo("NACL_FAILURE");
}
Also used : KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) EncryptorException(com.quorum.tessera.encryption.EncryptorException) Test(org.junit.Test)

Example 17 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig 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 18 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalInlineKeypair.

@Test
public void unmarshalInlineKeypair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    keyData.setPublicKey("PUBLICKEY");
    KeyDataConfig config = mock(KeyDataConfig.class);
    keyData.setConfig(config);
    InlineKeypair result = (InlineKeypair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull();
    assertThat(result.getPublicKey()).isEqualTo("PUBLICKEY");
    assertThat(result.getPrivateKeyConfig()).isSameAs(config);
    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)

Aggregations

KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)18 Test (org.junit.Test)17 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)13 Path (java.nio.file.Path)7 KeyData (com.quorum.tessera.config.KeyData)6 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 PrivateKey (com.quorum.tessera.encryption.PrivateKey)3 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)2 EncryptorException (com.quorum.tessera.encryption.EncryptorException)2 CliResult (com.quorum.tessera.cli.CliResult)1 ArgonOptions (com.quorum.tessera.config.ArgonOptions)1 KeyPair (com.quorum.tessera.encryption.KeyPair)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1