Search in sources :

Example 1 with EnclaveFactory

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();
}
Also used : Path(java.nio.file.Path) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) Enclave(org.hyperledger.besu.enclave.Enclave) RestrictedDefaultPrivacyController(org.hyperledger.besu.ethereum.privacy.RestrictedDefaultPrivacyController) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) InMemoryKeyValueStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Before(org.junit.Before)

Example 2 with EnclaveFactory

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();
}
Also used : Path(java.nio.file.Path) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) BesuController(org.hyperledger.besu.controller.BesuController) PrivacyKeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) InMemoryKeyValueStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) URI(java.net.URI)

Example 3 with EnclaveFactory

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());
}
Also used : EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) InMemoryPrivacyStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider)

Example 4 with EnclaveFactory

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;
            }
        });
    }
}
Also used : EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) KeyPairUtil(org.hyperledger.besu.crypto.KeyPairUtil) PrivacyKeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder) Arrays(java.util.Arrays) RocksDBKeyValueStorageFactory(org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValueStorageFactory) EnclaveServerException(org.hyperledger.besu.enclave.EnclaveServerException) EnclaveIOException(org.hyperledger.besu.enclave.EnclaveIOException) NoopEnclaveTestHarness(org.hyperledger.enclave.testutil.NoopEnclaveTestHarness) LoggerFactory(org.slf4j.LoggerFactory) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Address(org.hyperledger.besu.datatypes.Address) BesuNode(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode) Network(org.testcontainers.containers.Network) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) Transaction(org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction) TesseraTestHarnessFactory(org.hyperledger.enclave.testutil.TesseraTestHarnessFactory) Enclave(org.hyperledger.besu.enclave.Enclave) PrivateCondition(org.hyperledger.besu.tests.acceptance.dsl.privacy.condition.PrivateCondition) EnclaveTestHarness(org.hyperledger.enclave.testutil.EnclaveTestHarness) URI(java.net.URI) PrivacyStorageProvider(org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider) Path(java.nio.file.Path) RocksDBFactoryConfiguration(org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBFactoryConfiguration) Logger(org.slf4j.Logger) BesuNodeConfiguration(org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfiguration) Files(java.nio.file.Files) EnclaveType(org.hyperledger.enclave.testutil.EnclaveType) KeyValueSegmentIdentifier(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier) Vertx(io.vertx.core.Vertx) NodeConfiguration(org.hyperledger.besu.tests.acceptance.dsl.node.configuration.NodeConfiguration) IOException(java.io.IOException) RocksDBKeyValuePrivacyStorageFactory(org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValuePrivacyStorageFactory) DATABASE_PATH(org.hyperledger.besu.controller.BesuController.DATABASE_PATH) Collectors(java.util.stream.Collectors) BesuConfigurationImpl(org.hyperledger.besu.services.BesuConfigurationImpl) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException) BesuNodeRunner(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNodeRunner) List(java.util.List) RocksDBMetricsFactory(org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactory) Optional(java.util.Optional) PrivacyNodeConfiguration(org.hyperledger.besu.tests.acceptance.dsl.node.configuration.privacy.PrivacyNodeConfiguration) Collections(java.util.Collections) Awaitility(org.awaitility.Awaitility) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) Condition(org.hyperledger.besu.tests.acceptance.dsl.condition.Condition) EnclaveServerException(org.hyperledger.besu.enclave.EnclaveServerException) Enclave(org.hyperledger.besu.enclave.Enclave) EnclaveIOException(org.hyperledger.besu.enclave.EnclaveIOException) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException)

Example 5 with EnclaveFactory

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);
}
Also used : Path(java.nio.file.Path) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) PrivacyKeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder) EnclaveIOException(org.hyperledger.besu.enclave.EnclaveIOException) IOException(java.io.IOException) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters)

Aggregations

EnclaveFactory (org.hyperledger.besu.enclave.EnclaveFactory)8 PrivacyParameters (org.hyperledger.besu.ethereum.core.PrivacyParameters)5 Path (java.nio.file.Path)4 PrivacyKeyValueStorageProviderBuilder (org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder)4 IOException (java.io.IOException)3 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)3 URI (java.net.URI)2 Enclave (org.hyperledger.besu.enclave.Enclave)2 EnclaveIOException (org.hyperledger.besu.enclave.EnclaveIOException)2 InMemoryKeyValueStorageProvider (org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider)2 RestrictedDefaultPrivacyController (org.hyperledger.besu.ethereum.privacy.RestrictedDefaultPrivacyController)2 EnclaveKeyConfiguration (org.hyperledger.enclave.testutil.EnclaveKeyConfiguration)2 Vertx (io.vertx.core.Vertx)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1