Search in sources :

Example 16 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class KeyPairConverterTest method convertMultipleKeyPairs.

@Test
public void convertMultipleKeyPairs() {
    final String pubA = "publicA";
    final String privA = "privateA";
    final String pubB = "publicB";
    final String privB = "privateB";
    final DirectKeyPair keyPairA = new DirectKeyPair(pubA, privA);
    final DirectKeyPair keyPairB = new DirectKeyPair(pubB, privB);
    final Collection<KeyPair> result = converter.convert(Arrays.asList(keyPairA, keyPairB));
    assertThat(result).hasSize(2);
    final KeyPair expectedA = new KeyPair(PublicKey.from(decodeBase64(pubA)), PrivateKey.from(decodeBase64(privA)));
    final KeyPair expectedB = new KeyPair(PublicKey.from(decodeBase64(pubB)), PrivateKey.from(decodeBase64(privB)));
    final Iterator<KeyPair> it = result.iterator();
    final KeyPair resultA = it.next();
    assertThat(resultA).isEqualToComparingFieldByField(expectedA);
    final KeyPair resultB = it.next();
    assertThat(resultB).isEqualToComparingFieldByField(expectedB);
}
Also used : KeyPair(com.quorum.tessera.encryption.KeyPair) Test(org.junit.Test)

Example 17 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class KeyPairConverterTest method convertSingleAzureVaultKeyPair.

@Test
public void convertSingleAzureVaultKeyPair() {
    try (var staticKeyVaultServiceFactory = mockStatic(KeyVaultServiceFactory.class)) {
        KeyVaultServiceFactory keyVaultServiceFactory = mock(KeyVaultServiceFactory.class);
        KeyVaultService keyVaultService = mock(KeyVaultService.class);
        when(keyVaultService.getSecret(any(Map.class))).thenReturn("publicSecret").thenReturn("privSecret");
        when(keyVaultServiceFactory.create(any(Config.class), any(EnvironmentVariableProvider.class))).thenReturn(keyVaultService);
        staticKeyVaultServiceFactory.when(() -> KeyVaultServiceFactory.getInstance(KeyVaultType.AZURE)).thenReturn(keyVaultServiceFactory);
        final AzureVaultKeyPair keyPair = new AzureVaultKeyPair("pub", "priv", null, null);
        Collection<KeyPair> result = converter.convert(List.of(keyPair));
        assertThat(result).hasSize(1);
        KeyPair resultKeyPair = result.iterator().next();
        KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("publicSecret")), PrivateKey.from(decodeBase64("privSecret")));
        assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
        verify(keyVaultService, times(2)).getSecret(any(Map.class));
        verify(keyVaultServiceFactory).create(any(Config.class), any(EnvironmentVariableProvider.class));
        staticKeyVaultServiceFactory.verify(() -> KeyVaultServiceFactory.getInstance(KeyVaultType.AZURE));
        staticKeyVaultServiceFactory.verifyNoMoreInteractions();
        verifyNoMoreInteractions(keyVaultService);
        verifyNoMoreInteractions(keyVaultServiceFactory);
    }
}
Also used : EnvironmentVariableProvider(com.quorum.tessera.config.util.EnvironmentVariableProvider) KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyPair(com.quorum.tessera.encryption.KeyPair) Config(com.quorum.tessera.config.Config) KeyVaultServiceFactory(com.quorum.tessera.key.vault.KeyVaultServiceFactory) Test(org.junit.Test)

Example 18 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class KeyPairConverterTest method convertSingleFilesystemKeyPair.

@Test
public void convertSingleFilesystemKeyPair() {
    final FilesystemKeyPair keyPair = mock(FilesystemKeyPair.class);
    when(keyPair.getPublicKey()).thenReturn("public");
    when(keyPair.getPrivateKey()).thenReturn("private");
    Collection<KeyPair> result = converter.convert(Collections.singletonList(keyPair));
    assertThat(result).hasSize(1);
    KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("public")), PrivateKey.from(decodeBase64("private")));
    KeyPair resultKeyPair = result.iterator().next();
    assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
}
Also used : KeyPair(com.quorum.tessera.encryption.KeyPair) Test(org.junit.Test)

Example 19 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class KeyPairConverterTest method convertSingleDirectKeyPair.

@Test
public void convertSingleDirectKeyPair() {
    final DirectKeyPair keyPair = new DirectKeyPair("public", "private");
    Collection<KeyPair> result = converter.convert(Collections.singletonList(keyPair));
    assertThat(result).hasSize(1);
    KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("public")), PrivateKey.from(decodeBase64("private")));
    KeyPair resultKeyPair = result.iterator().next();
    assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
}
Also used : KeyPair(com.quorum.tessera.encryption.KeyPair) Test(org.junit.Test)

Example 20 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class KeyPairConverterTest method convertSingleInlineKeyPair.

@Test
public void convertSingleInlineKeyPair() {
    final InlineKeypair keyPair = mock(InlineKeypair.class);
    when(keyPair.getPublicKey()).thenReturn("public");
    when(keyPair.getPrivateKey()).thenReturn("private");
    Collection<KeyPair> result = converter.convert(Collections.singletonList(keyPair));
    assertThat(result).hasSize(1);
    KeyPair expected = new KeyPair(PublicKey.from(decodeBase64("public")), PrivateKey.from(decodeBase64("private")));
    KeyPair resultKeyPair = result.iterator().next();
    assertThat(resultKeyPair).isEqualToComparingFieldByField(expected);
}
Also used : KeyPair(com.quorum.tessera.encryption.KeyPair) Test(org.junit.Test)

Aggregations

KeyPair (com.quorum.tessera.encryption.KeyPair)21 Test (org.junit.Test)11 KeyVaultService (com.quorum.tessera.key.vault.KeyVaultService)7 Encryptor (com.quorum.tessera.encryption.Encryptor)5 KeyVaultServiceFactory (com.quorum.tessera.key.vault.KeyVaultServiceFactory)4 Before (org.junit.Before)4 Config (com.quorum.tessera.config.Config)3 AWSKeyPair (com.quorum.tessera.config.keypairs.AWSKeyPair)3 AzureVaultKeyPair (com.quorum.tessera.config.keypairs.AzureVaultKeyPair)3 HashicorpVaultKeyPair (com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair)3 EnvironmentVariableProvider (com.quorum.tessera.config.util.EnvironmentVariableProvider)3 Path (java.nio.file.Path)3 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)2 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)2 KeyData (com.quorum.tessera.config.KeyData)1 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)1 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)1 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)1 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)1 SharedKey (com.quorum.tessera.encryption.SharedKey)1