use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class EncodedPayloadManagerProvider method provider.
public static EncodedPayloadManager provider() {
EncodedPayloadManagerHolder encodedPayloadManagerHolder = EncodedPayloadManagerHolder.INSTANCE;
if (encodedPayloadManagerHolder.getEncodedPayloadManager().isPresent()) {
return encodedPayloadManagerHolder.getEncodedPayloadManager().get();
}
Enclave enclave = Enclave.create();
PrivacyHelper privacyHelper = PrivacyHelper.create();
PayloadDigest payloadDigest = PayloadDigest.create();
EncodedPayloadManager encodedPayloadManager = new EncodedPayloadManagerImpl(enclave, privacyHelper, payloadDigest);
encodedPayloadManagerHolder.storeInstance(encodedPayloadManager);
return encodedPayloadManager;
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class RuntimeContextProviderTest method provides.
@Test
public void provides() {
Config confg = createMockConfig();
try (var mockedStaticConfigFactory = mockStatic(ConfigFactory.class);
var mockStaticRestClientFactory = mockStatic(RestClientFactory.class);
var mockStaticKeyDataUtil = mockStatic(KeyDataUtil.class);
var mockStaticEnclave = mockStatic(Enclave.class)) {
Enclave enclave = mock(Enclave.class);
mockStaticEnclave.when(Enclave::create).thenReturn(enclave);
ConfigKeyPair configKeyPair = mock(ConfigKeyPair.class);
when(configKeyPair.getPublicKey()).thenReturn(Base64.getEncoder().encodeToString("PublicKey".getBytes()));
when(configKeyPair.getPrivateKey()).thenReturn(Base64.getEncoder().encodeToString("PrivateKey".getBytes()));
mockStaticKeyDataUtil.when(() -> KeyDataUtil.unmarshal(any(KeyData.class), any(KeyEncryptor.class))).thenReturn(configKeyPair);
RestClientFactory restClientFactory = mock(RestClientFactory.class);
when(restClientFactory.buildFrom(any(ServerConfig.class))).thenReturn(mock(Client.class));
mockStaticRestClientFactory.when(RestClientFactory::create).thenReturn(restClientFactory);
ConfigFactory configFactory = mock(ConfigFactory.class);
when(configFactory.getConfig()).thenReturn(confg);
mockedStaticConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
RuntimeContext runtimeContext = RuntimeContextProvider.provider();
assertThat(runtimeContext).isNotNull().isSameAs(RuntimeContextProvider.provider());
mockedStaticConfigFactory.verify(ConfigFactory::create);
mockedStaticConfigFactory.verifyNoMoreInteractions();
mockStaticRestClientFactory.verify(RestClientFactory::create);
mockedStaticConfigFactory.verifyNoMoreInteractions();
mockStaticKeyDataUtil.verify(() -> KeyDataUtil.unmarshal(any(KeyData.class), any(KeyEncryptor.class)));
mockStaticKeyDataUtil.verifyNoMoreInteractions();
mockStaticEnclave.verify(Enclave::create);
mockStaticEnclave.verifyNoMoreInteractions();
verify(enclave).getPublicKeys();
verifyNoMoreInteractions(enclave);
}
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class RuntimeContextProvider method provider.
public static RuntimeContext provider() {
LOGGER.debug("Providing RuntimeContext");
RuntimeContextHolder contextHolder = RuntimeContextHolder.INSTANCE;
if (contextHolder.getContext().isPresent()) {
LOGGER.debug("Found stored RuntimeContext instance");
return contextHolder.getContext().get();
}
Config config = ConfigFactory.create().getConfig();
EncryptorConfig encryptorConfig = Optional.ofNullable(config.getEncryptor()).orElse(new EncryptorConfig() {
{
setType(EncryptorType.NACL);
}
});
KeyEncryptor keyEncryptor = KeyEncryptorFactory.newFactory().create(encryptorConfig);
final KeyVaultConfigValidations vaultConfigValidation = KeyVaultConfigValidations.create();
final RuntimeContextBuilder runtimeContextBuilder = RuntimeContextBuilder.create();
if (Objects.nonNull(config.getKeys())) {
List<ConfigKeyPair> configKeyPairs = config.getKeys().getKeyData().stream().map(o -> KeyDataUtil.unmarshal(o, keyEncryptor)).collect(Collectors.toList());
Set<ConstraintViolation<?>> violations = vaultConfigValidation.validate(config.getKeys(), configKeyPairs);
if (!violations.isEmpty()) {
LOGGER.debug("Constraint violations {}", violations);
throw new ConstraintViolationException(violations);
}
final Enclave enclave = Enclave.create();
runtimeContextBuilder.withKeys(enclave.getPublicKeys());
}
List<ServerConfig> servers = config.getServerConfigs();
ServerConfig p2pServerContext = servers.stream().filter(s -> s.getApp() == AppType.P2P).findFirst().orElseThrow(() -> new IllegalStateException("No P2P server configured"));
Client p2pClient = RestClientFactory.create().buildFrom(p2pServerContext);
List<PublicKey> alwaysSendTo = Stream.of(config).map(Config::getAlwaysSendTo).filter(Objects::nonNull).flatMap(List::stream).map(Base64.getDecoder()::decode).map(PublicKey::from).collect(Collectors.toList());
RuntimeContext context = runtimeContextBuilder.withP2pServerUri(config.getP2PServerConfig().getServerUri()).withP2pClient(p2pClient).withKeyEncryptor(keyEncryptor).withDisablePeerDiscovery(config.isDisablePeerDiscovery()).withRemoteKeyValidation(config.getFeatures().isEnableRemoteKeyValidation()).withEnhancedPrivacy(config.getFeatures().isEnablePrivacyEnhancements()).withPeers(config.getPeers().stream().map(Peer::getUrl).map(URI::create).collect(Collectors.toList())).withAlwaysSendTo(alwaysSendTo).withUseWhiteList(config.isUseWhiteList()).withRecoveryMode(config.isRecoveryMode()).withMultiplePrivateStates(config.getFeatures().isEnableMultiplePrivateStates()).withClientMode(config.getClientMode()).build();
contextHolder.setContext(context);
return context;
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class PrivacyGroupManagerProvider method provider.
public static PrivacyGroupManager provider() {
Enclave enclave = Enclave.create();
PrivacyGroupDAO privacyGroupDAO = PrivacyGroupDAO.create();
BatchPrivacyGroupPublisher publisher = BatchPrivacyGroupPublisher.create();
return new PrivacyGroupManagerImpl(enclave, privacyGroupDAO, publisher);
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class ResendManagerProvider method provider.
public static ResendManager provider() {
LOGGER.debug("Creating EncryptedTransactionDAO");
final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
LOGGER.debug("Created EncryptedTransactionDAO {}", encryptedTransactionDAO);
LOGGER.debug("Creating Enclave");
final Enclave enclave = Enclave.create();
LOGGER.debug("Created Enclave {}", enclave);
PayloadDigest payloadDigest = PayloadDigest.create();
return new ResendManagerImpl(encryptedTransactionDAO, enclave, payloadDigest);
}
Aggregations