Search in sources :

Example 1 with Encryptor

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

the class AzureVaultKeyGeneratorTest method setUp.

@Before
public void setUp() {
    this.encryptor = mock(Encryptor.class);
    this.keyVaultService = mock(KeyVaultService.class);
    final KeyPair keyPair = new KeyPair(pub, priv);
    when(encryptor.generateNewKeys()).thenReturn(keyPair);
    azureVaultKeyGenerator = new AzureVaultKeyGenerator(encryptor, keyVaultService);
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyPair(com.quorum.tessera.encryption.KeyPair) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Encryptor(com.quorum.tessera.encryption.Encryptor) Before(org.junit.Before)

Example 2 with Encryptor

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

the class HashicorpVaultKeyGeneratorTest method setUp.

@Before
public void setUp() {
    this.encryptor = mock(Encryptor.class);
    this.keyVaultService = mock(KeyVaultService.class);
    final KeyPair keyPair = new KeyPair(pub, priv);
    when(encryptor.generateNewKeys()).thenReturn(keyPair);
    this.hashicorpVaultKeyGenerator = new HashicorpVaultKeyGenerator(encryptor, keyVaultService);
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyPair(com.quorum.tessera.encryption.KeyPair) HashicorpVaultKeyPair(com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair) Encryptor(com.quorum.tessera.encryption.Encryptor) Before(org.junit.Before)

Example 3 with Encryptor

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

the class EllipticalCurveEncryptorFactoryTest method createInstance.

@Test
public void createInstance() {
    final Encryptor result = encryptorFactory.create();
    assertThat(encryptorFactory.getType()).isEqualTo("EC");
    assertThat(result).isNotNull().isExactlyInstanceOf(EllipticalCurveEncryptor.class);
}
Also used : Encryptor(com.quorum.tessera.encryption.Encryptor) Test(org.junit.Test)

Example 4 with Encryptor

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

the class DefaultKeyGeneratorFactory method create.

@Override
public KeyGenerator create(KeyVaultConfig keyVaultConfig, EncryptorConfig encryptorConfig) {
    Objects.requireNonNull(encryptorConfig, "No encryptor config defined. ");
    final EncryptorFactory encryptorFactory = EncryptorFactory.newFactory(encryptorConfig.getType().name());
    final Encryptor encryptor = encryptorFactory.create(encryptorConfig.getProperties());
    if (keyVaultConfig != null) {
        final KeyVaultServiceFactory keyVaultServiceFactory = KeyVaultServiceFactory.getInstance(keyVaultConfig.getKeyVaultType());
        final Config config = new Config();
        final KeyConfiguration keyConfiguration = new KeyConfiguration();
        if (keyVaultConfig.getKeyVaultType().equals(KeyVaultType.AZURE)) {
            keyConfiguration.addKeyVaultConfig(keyVaultConfig);
            config.setKeys(keyConfiguration);
            final KeyVaultService keyVaultService = keyVaultServiceFactory.create(config, new EnvironmentVariableProvider());
            return new AzureVaultKeyGenerator(encryptor, keyVaultService);
        } else if (keyVaultConfig.getKeyVaultType().equals(KeyVaultType.AWS)) {
            if (!(keyVaultConfig instanceof DefaultKeyVaultConfig)) {
                throw new IllegalArgumentException("AWS key vault config not instance of DefaultKeyVaultConfig");
            }
            keyConfiguration.addKeyVaultConfig(keyVaultConfig);
            config.setKeys(keyConfiguration);
            final KeyVaultService keyVaultService = keyVaultServiceFactory.create(config, new EnvironmentVariableProvider());
            return new AWSSecretManagerKeyGenerator(encryptor, keyVaultService);
        } else {
            keyConfiguration.addKeyVaultConfig(keyVaultConfig);
            config.setKeys(keyConfiguration);
            final KeyVaultService keyVaultService = keyVaultServiceFactory.create(config, new EnvironmentVariableProvider());
            return new HashicorpVaultKeyGenerator(encryptor, keyVaultService);
        }
    }
    KeyEncryptor keyEncyptor = KeyEncryptorFactory.newFactory().create(encryptorConfig);
    return new FileKeyGenerator(encryptor, keyEncyptor, PasswordReaderFactory.create());
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) Encryptor(com.quorum.tessera.encryption.Encryptor) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) EnvironmentVariableProvider(com.quorum.tessera.config.util.EnvironmentVariableProvider) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyVaultServiceFactory(com.quorum.tessera.key.vault.KeyVaultServiceFactory) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) EncryptorFactory(com.quorum.tessera.encryption.EncryptorFactory)

Example 5 with Encryptor

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

the class JnaclFactoryTest method createInstance.

@Test
public void createInstance() {
    final Encryptor result = jnaclFactory.create();
    assertThat(jnaclFactory.getType()).isEqualTo("NACL");
    assertThat(result).isNotNull().isExactlyInstanceOf(Jnacl.class);
}
Also used : Encryptor(com.quorum.tessera.encryption.Encryptor) Test(org.junit.Test)

Aggregations

Encryptor (com.quorum.tessera.encryption.Encryptor)9 KeyPair (com.quorum.tessera.encryption.KeyPair)5 KeyVaultService (com.quorum.tessera.key.vault.KeyVaultService)4 Before (org.junit.Before)4 Test (org.junit.Test)3 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)2 AWSKeyPair (com.quorum.tessera.config.keypairs.AWSKeyPair)1 AzureVaultKeyPair (com.quorum.tessera.config.keypairs.AzureVaultKeyPair)1 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)1 HashicorpVaultKeyPair (com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair)1 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)1 EnvironmentVariableProvider (com.quorum.tessera.config.util.EnvironmentVariableProvider)1 EncryptorFactory (com.quorum.tessera.encryption.EncryptorFactory)1 KeyVaultServiceFactory (com.quorum.tessera.key.vault.KeyVaultServiceFactory)1 PasswordReader (com.quorum.tessera.passwords.PasswordReader)1