use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.
the class PrivacyReorgTest method setUp.
@Before
public void setUp() throws IOException {
mockEnclave = mock(Enclave.class);
final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
PRIVATE_TRANSACTION.writeTo(rlpOutput);
when(mockEnclave.receive(any())).thenReturn(new ReceiveResponse(rlpOutput.encoded().toBase64String().getBytes(StandardCharsets.UTF_8), PRIVACY_GROUP_BYTES32.toBase64String(), ENCLAVE_PUBLIC_KEY.toBase64String()));
privacyMarkerTransaction = Transaction.builder().type(TransactionType.FRONTIER).chainId(BigInteger.valueOf(1337)).gasLimit(60000).gasPrice(Wei.of(1000)).nonce(0).payload(PRIVACY_TRANSACTION_PAYLOAD).to(DEFAULT_PRIVACY).value(Wei.ZERO).signAndBuild(KEY_PAIR);
// Create Storage
final Path dataDir = folder.newFolder().toPath();
// Configure Privacy
EnclaveFactory enclaveFactory = mock(EnclaveFactory.class);
when(enclaveFactory.createVertxEnclave(any())).thenReturn(mockEnclave);
privacyParameters = new PrivacyParameters.Builder().setEnabled(true).setStorageProvider(createKeyValueStorageProvider()).setEnclaveUrl(URI.create("http//1.1.1.1:1234")).setEnclaveFactory(enclaveFactory).build();
privacyParameters.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
privacyController = mock(RestrictedDefaultPrivacyController.class);
when(privacyController.findPrivacyGroupByGroupId(any(), any())).thenReturn(Optional.of(new PrivacyGroup()));
privateStateRootResolver = new PrivateStateRootResolver(privacyParameters.getPrivateStateStorage());
besuController = new BesuController.Builder().fromGenesisConfig(GenesisConfigFile.development()).synchronizerConfiguration(SynchronizerConfiguration.builder().build()).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).storageProvider(new InMemoryKeyValueStorageProvider()).networkId(BigInteger.ONE).miningParameters(new MiningParameters.Builder().minTransactionGasPrice(Wei.of(1000)).miningEnabled(false).build()).nodeKey(NodeKeyUtils.generate()).metricsSystem(new NoOpMetricsSystem()).dataDirectory(dataDir).clock(TestClock.fixed()).privacyParameters(privacyParameters).transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT).gasLimitCalculator(GasLimitCalculator.constant()).evmConfiguration(EvmConfiguration.DEFAULT).build();
}
use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.
the class PrivacyTest method setUpControllerWithPrivacyEnabled.
private BesuController setUpControllerWithPrivacyEnabled(final boolean flexibleEnabled) throws IOException, URISyntaxException {
final Path dataDir = folder.newFolder().toPath();
final Path dbDir = dataDir.resolve("database");
final PrivacyParameters privacyParameters = new PrivacyParameters.Builder().setEnabled(true).setEnclaveUrl(new URI("http://127.0.0.1:8000")).setStorageProvider(createKeyValueStorageProvider(dataDir, dbDir)).setEnclaveFactory(new EnclaveFactory(vertx)).setFlexiblePrivacyGroupsEnabled(flexibleEnabled).build();
return new BesuController.Builder().fromGenesisConfig(GenesisConfigFile.mainnet()).synchronizerConfiguration(SynchronizerConfiguration.builder().build()).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).storageProvider(new InMemoryKeyValueStorageProvider()).networkId(BigInteger.ONE).miningParameters(new MiningParameters.Builder().miningEnabled(false).build()).nodeKey(NodeKeyUtils.generate()).metricsSystem(new NoOpMetricsSystem()).dataDirectory(dataDir).clock(TestClock.fixed()).privacyParameters(privacyParameters).transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT).gasLimitCalculator(GasLimitCalculator.constant()).evmConfiguration(EvmConfiguration.DEFAULT).build();
}
use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.
the class BesuNodeFactory method createNodeWithMultiTenantedPrivacy.
public BesuNode createNodeWithMultiTenantedPrivacy(final String name, final String enclaveUrl, final String authFile, final String privTransactionSigningKey, final boolean enableFlexiblePrivacy) throws IOException, URISyntaxException {
final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder();
final PrivacyParameters privacyParameters = privacyParametersBuilder.setMultiTenancyEnabled(true).setEnabled(true).setFlexiblePrivacyGroupsEnabled(enableFlexiblePrivacy).setStorageProvider(new InMemoryPrivacyStorageProvider()).setEnclaveFactory(new EnclaveFactory(Vertx.vertx())).setEnclaveUrl(URI.create(enclaveUrl)).setPrivateKeyPath(Paths.get(ClassLoader.getSystemResource(privTransactionSigningKey).toURI())).build();
final MiningParameters miningParameters = new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).coinbase(AddressHelpers.ofValue(1)).miningEnabled(true).build();
return create(new BesuNodeConfigurationBuilder().name(name).jsonRpcEnabled().jsonRpcAuthenticationConfiguration(authFile).enablePrivateTransactions().privacyParameters(privacyParameters).miningConfiguration(miningParameters).build());
}
use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.
the class PrivacyNode method testEnclaveConnection.
public void testEnclaveConnection(final List<PrivacyNode> otherNodes) {
if (this.isPrivacyPluginEnabled) {
LOG.info("Skipping test as node has no enclave (isPrivacyPluginEnabled=true)");
return;
}
if (!otherNodes.isEmpty()) {
LOG.debug(String.format("Testing Enclave connectivity between %s (%s) and %s (%s)", besu.getName(), enclave.nodeUrl(), Arrays.toString(otherNodes.stream().map(node -> node.besu.getName()).toArray()), Arrays.toString(otherNodes.stream().map(node -> node.enclave.nodeUrl()).toArray())));
final EnclaveFactory factory = new EnclaveFactory(vertx);
final Enclave enclaveClient = factory.createVertxEnclave(enclave.clientUrl());
final String payload = "SGVsbG8sIFdvcmxkIQ==";
final List<String> to = otherNodes.stream().map(node -> node.enclave.getDefaultPublicKey()).collect(Collectors.toList());
Awaitility.await().until(() -> {
try {
enclaveClient.send(payload, enclave.getDefaultPublicKey(), to);
return true;
} catch (final EnclaveClientException | EnclaveIOException | EnclaveServerException e) {
LOG.warn("Waiting for enclave connectivity between {} and {}: " + e.getMessage(), enclave.getDefaultPublicKey(), to.get(0));
return false;
}
});
}
}
use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.
the class PrivacyNode method start.
public void start(final BesuNodeRunner runner) {
enclave.start();
final PrivacyParameters privacyParameters;
try {
final Path dataDir = Files.createTempDirectory("acctest-privacy");
final Path dbDir = dataDir.resolve(DATABASE_PATH);
var builder = new PrivacyParameters.Builder().setEnabled(true).setEnclaveUrl(enclave.clientUrl()).setStorageProvider(createKeyValueStorageProvider(dataDir, dbDir)).setPrivateKeyPath(KeyPairUtil.getDefaultKeyFile(besu.homeDirectory()).toPath()).setEnclaveFactory(new EnclaveFactory(vertx)).setFlexiblePrivacyGroupsEnabled(isFlexiblePrivacyEnabled).setMultiTenancyEnabled(isMultitenancyEnabled).setPrivacyPluginEnabled(isPrivacyPluginEnabled);
if (enclave.getPublicKeyPaths().size() > 0) {
builder.setPrivacyUserIdUsingFile(enclave.getPublicKeyPaths().get(0).toFile());
}
privacyParameters = builder.build();
} catch (final IOException e) {
throw new RuntimeException(e);
}
besu.setPrivacyParameters(privacyParameters);
besu.start(runner);
}
Aggregations