Search in sources :

Example 1 with EncryptorConfig

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

the class EnclaveFactoryImpl method createServer.

static Enclave createServer(Config config) {
    LOGGER.info("Creating enclave server");
    EncryptorConfig encryptorConfig = config.getEncryptor();
    EncryptorFactory encryptorFactory = EncryptorFactory.newFactory(encryptorConfig.getType().name());
    Encryptor encryptor = encryptorFactory.create(encryptorConfig.getProperties());
    KeyEncryptor keyEncryptor = KeyEncryptorFactory.newFactory().create(encryptorConfig);
    final KeyPairConverter keyPairConverter = new KeyPairConverter(config, new EnvironmentVariableProvider());
    final Collection<KeyPair> keys = keyPairConverter.convert(config.getKeys().getKeyData().stream().map(kd -> KeyDataUtil.unmarshal(kd, keyEncryptor)).collect(Collectors.toList()));
    final Collection<PublicKey> forwardKeys = keyPairConverter.convert(config.getAlwaysSendTo());
    LOGGER.debug("Creating enclave");
    Enclave enclave = new EnclaveImpl(encryptor, new KeyManagerImpl(keys, forwardKeys));
    LOGGER.debug("Created enclave {}", enclave);
    return enclave;
}
Also used : EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) EnvironmentVariableProvider(com.quorum.tessera.config.util.EnvironmentVariableProvider) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory)

Example 2 with EncryptorConfig

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

the class KeyGeneratorFactoryTest method awsVaultKeyGeneratorWhenAwsConfigProvided.

@Test
public void awsVaultKeyGeneratorWhenAwsConfigProvided() {
    final DefaultKeyVaultConfig keyVaultConfig = new DefaultKeyVaultConfig();
    keyVaultConfig.setKeyVaultType(KeyVaultType.AWS);
    EncryptorConfig encryptorConfig = mock(EncryptorConfig.class);
    when(encryptorConfig.getType()).thenReturn(EncryptorType.NACL);
    when(encryptorConfig.getProperties()).thenReturn(Collections.EMPTY_MAP);
    KeyGeneratorFactory keyGeneratorFactory = KeyGeneratorFactory.create();
    try (MockedStatic<KeyVaultServiceFactory> mockedKeyVaultServiceFactory = mockStatic(KeyVaultServiceFactory.class)) {
        KeyVaultService keyVaultService = mock(KeyVaultService.class);
        KeyVaultServiceFactory keyVaultServiceFactory = mock(KeyVaultServiceFactory.class);
        when(keyVaultServiceFactory.create(any(), any())).thenReturn(keyVaultService);
        mockedKeyVaultServiceFactory.when(() -> KeyVaultServiceFactory.getInstance(KeyVaultType.AWS)).thenReturn(keyVaultServiceFactory);
        final KeyGenerator keyGenerator = keyGeneratorFactory.create(keyVaultConfig, encryptorConfig);
        assertThat(keyGenerator).isNotNull();
        assertThat(keyGenerator).isExactlyInstanceOf(AWSSecretManagerKeyGenerator.class);
    }
}
Also used : DefaultKeyVaultConfig(com.quorum.tessera.config.DefaultKeyVaultConfig) KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyVaultServiceFactory(com.quorum.tessera.key.vault.KeyVaultServiceFactory) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Test(org.junit.Test)

Example 3 with EncryptorConfig

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

the class EncryptorOptionsTest method ellipticalCurveNoPropertiesDefined.

@Test
public void ellipticalCurveNoPropertiesDefined() {
    EncryptorOptions encryptorOptions = new EncryptorOptions();
    String[] args = new String[] { "--encryptor.type=EC" };
    new CommandLine(encryptorOptions).parseArgs(args);
    EncryptorConfig result = encryptorOptions.parseEncryptorConfig();
    assertThat(result).isNotNull();
    assertThat(result.getType()).isEqualTo(EncryptorType.EC);
    assertThat(result.getProperties()).isEmpty();
}
Also used : CommandLine(picocli.CommandLine) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Test(org.junit.Test)

Example 4 with EncryptorConfig

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

the class EncryptorOptions method parseEncryptorConfig.

EncryptorConfig parseEncryptorConfig() {
    final EncryptorConfig encryptorConfig = new EncryptorConfig();
    // annotations
    if (Objects.isNull(type)) {
        type = EncryptorType.NACL;
    }
    Map<String, String> properties = new HashMap<>();
    if (type == EncryptorType.EC) {
        Optional.ofNullable(symmetricCipher).ifPresent(v -> properties.put("symmetricCipher", v));
        Optional.ofNullable(ellipticCurve).ifPresent(v -> properties.put("ellipticCurve", v));
        Optional.ofNullable(nonceLength).ifPresent(v -> properties.put("nonceLength", v));
        Optional.ofNullable(sharedKeyLength).ifPresent(v -> properties.put("sharedKeyLength", v));
    }
    encryptorConfig.setType(type);
    encryptorConfig.setProperties(properties);
    return encryptorConfig;
}
Also used : HashMap(java.util.HashMap) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig)

Example 5 with EncryptorConfig

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

the class JaxbConfigFactory method create.

@Override
public Config create(final InputStream configData) {
    byte[] originalData = Stream.of(configData).map(InputStreamReader::new).map(BufferedReader::new).flatMap(BufferedReader::lines).collect(Collectors.joining(System.lineSeparator())).getBytes();
    final Config initialConfig = JaxbUtil.unmarshal(new ByteArrayInputStream(originalData), Config.class);
    EncryptorConfig encryptorConfig = Optional.ofNullable(initialConfig.getEncryptor()).orElse(DEFAULT_ENCRYPTOR_CONFIG);
    // Initialise the key encrypter it will store into holder object.
    keyEncryptorFactory.create(encryptorConfig);
    final Config config = JaxbUtil.unmarshal(new ByteArrayInputStream(originalData), Config.class);
    config.setEncryptor(encryptorConfig);
    return config;
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Config(com.quorum.tessera.config.Config) BufferedReader(java.io.BufferedReader) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig)

Aggregations

EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)12 Test (org.junit.Test)9 Config (com.quorum.tessera.config.Config)3 CommandLine (picocli.CommandLine)3 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)2 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)2 EnvironmentVariableProvider (com.quorum.tessera.config.util.EnvironmentVariableProvider)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DefaultKeyVaultConfig (com.quorum.tessera.config.DefaultKeyVaultConfig)1 ServerConfig (com.quorum.tessera.config.ServerConfig)1 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)1 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)1 PublicKey (com.quorum.tessera.encryption.PublicKey)1 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)1 KeyVaultService (com.quorum.tessera.key.vault.KeyVaultService)1 KeyVaultServiceFactory (com.quorum.tessera.key.vault.KeyVaultServiceFactory)1 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)1 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)1 Recipient (com.quorum.tessera.partyinfo.model.Recipient)1 JsonObject (jakarta.json.JsonObject)1