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;
}
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);
}
}
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();
}
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;
}
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;
}
Aggregations