Search in sources :

Example 6 with EnclaveFactory

use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.

the class BesuCommand method privacyParameters.

private PrivacyParameters privacyParameters(final KeyValueStorageProvider storageProvider) {
    CommandLineUtils.checkOptionDependencies(logger, commandLine, "--privacy-enabled", !privacyOptionGroup.isPrivacyEnabled, asList("--privacy-multi-tenancy-enabled", "--privacy-tls-enabled"));
    CommandLineUtils.checkMultiOptionDependencies(logger, commandLine, "--privacy-url and/or --privacy-public-key-file ignored because none of --privacy-enabled or isQuorum (in genesis file) was defined.", List.of(!privacyOptionGroup.isPrivacyEnabled, !isGoQuorumCompatibilityMode), List.of("--privacy-url", "--privacy-public-key-file"));
    checkPrivacyTlsOptionsDependencies();
    final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder();
    if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyEnabled)) {
        final String errorSuffix = "cannot be enabled with privacy.";
        if (syncMode == SyncMode.FAST) {
            throw new ParameterException(commandLine, String.format("%s %s", "Fast sync", errorSuffix));
        }
        if (isPruningEnabled()) {
            throw new ParameterException(commandLine, String.format("%s %s", "Pruning", errorSuffix));
        }
        if (isGoQuorumCompatibilityMode) {
            throw new ParameterException(commandLine, String.format("%s %s", "GoQuorum mode", errorSuffix));
        }
        if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyMultiTenancyEnabled) && Boolean.FALSE.equals(jsonRpcConfiguration.isAuthenticationEnabled()) && Boolean.FALSE.equals(webSocketConfiguration.isAuthenticationEnabled())) {
            throw new ParameterException(commandLine, "Privacy multi-tenancy requires either http authentication to be enabled or WebSocket authentication to be enabled");
        }
        privacyParametersBuilder.setEnabled(true);
        privacyParametersBuilder.setEnclaveUrl(privacyOptionGroup.privacyUrl);
        privacyParametersBuilder.setMultiTenancyEnabled(privacyOptionGroup.isPrivacyMultiTenancyEnabled);
        privacyParametersBuilder.setFlexiblePrivacyGroupsEnabled(privacyOptionGroup.isFlexiblePrivacyGroupsEnabled || privacyOptionGroup.isOnchainPrivacyGroupsEnabled);
        privacyParametersBuilder.setPrivacyPluginEnabled(unstablePrivacyPluginOptions.isPrivacyPluginEnabled());
        final boolean hasPrivacyPublicKey = privacyOptionGroup.privacyPublicKeyFile != null;
        if (hasPrivacyPublicKey && Boolean.TRUE.equals(privacyOptionGroup.isPrivacyMultiTenancyEnabled)) {
            throw new ParameterException(commandLine, "Privacy multi-tenancy and privacy public key cannot be used together");
        }
        if (!hasPrivacyPublicKey && !privacyOptionGroup.isPrivacyMultiTenancyEnabled && !unstablePrivacyPluginOptions.isPrivacyPluginEnabled()) {
            throw new ParameterException(commandLine, "Please specify Enclave public key file path to enable privacy");
        }
        if (hasPrivacyPublicKey && Boolean.FALSE.equals(privacyOptionGroup.isPrivacyMultiTenancyEnabled)) {
            try {
                privacyParametersBuilder.setPrivacyUserIdUsingFile(privacyOptionGroup.privacyPublicKeyFile);
            } catch (final IOException e) {
                throw new ParameterException(commandLine, "Problem with privacy-public-key-file: " + e.getMessage(), e);
            } catch (final IllegalArgumentException e) {
                throw new ParameterException(commandLine, "Contents of privacy-public-key-file invalid: " + e.getMessage(), e);
            }
        }
        privacyParametersBuilder.setPrivateKeyPath(privacyOptionGroup.privateMarkerTransactionSigningKeyPath);
        privacyParametersBuilder.setStorageProvider(privacyKeyStorageProvider(keyValueStorageName + "-privacy"));
        if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyTlsEnabled)) {
            privacyParametersBuilder.setPrivacyKeyStoreFile(privacyOptionGroup.privacyKeyStoreFile);
            privacyParametersBuilder.setPrivacyKeyStorePasswordFile(privacyOptionGroup.privacyKeyStorePasswordFile);
            privacyParametersBuilder.setPrivacyTlsKnownEnclaveFile(privacyOptionGroup.privacyTlsKnownEnclaveFile);
        }
        privacyParametersBuilder.setEnclaveFactory(new EnclaveFactory(vertx));
    } else if (isGoQuorumCompatibilityMode) {
        privacyParametersBuilder.setGoQuorumPrivacyParameters(Optional.of(configureGoQuorumPrivacy(storageProvider)));
    }
    if (Boolean.FALSE.equals(privacyOptionGroup.isPrivacyEnabled) && anyPrivacyApiEnabled()) {
        logger.warn("Privacy is disabled. Cannot use EEA/PRIV API methods when not using Privacy.");
    }
    if (!isGoQuorumCompatibilityMode && (jsonRPCHttpOptionGroup.rpcHttpApis.contains(RpcApis.GOQUORUM.name()) || jsonRPCWebsocketOptionGroup.rpcWsApis.contains(RpcApis.GOQUORUM.name()))) {
        logger.warn("Cannot use GOQUORUM API methods when not in GoQuorum mode.");
    }
    privacyParametersBuilder.setPrivacyService(privacyPluginService);
    final PrivacyParameters privacyParameters = privacyParametersBuilder.build();
    if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyEnabled)) {
        preSynchronizationTaskRunner.addTask(new PrivateDatabaseMigrationPreSyncTask(privacyParameters, privacyOptionGroup.migratePrivateDatabase));
    }
    return privacyParameters;
}
Also used : EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) KeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder) PermissioningConfigurationBuilder(org.hyperledger.besu.ethereum.permissioning.PermissioningConfigurationBuilder) PrivacyKeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder) BesuControllerBuilder(org.hyperledger.besu.controller.BesuControllerBuilder) RunnerBuilder(org.hyperledger.besu.RunnerBuilder) ParameterException(picocli.CommandLine.ParameterException) IOException(java.io.IOException) PrivateDatabaseMigrationPreSyncTask(org.hyperledger.besu.cli.presynctasks.PrivateDatabaseMigrationPreSyncTask) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) GoQuorumPrivacyParameters(org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters)

Example 7 with EnclaveFactory

use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.

the class PrivacyPrecompiledContractIntegrationTest method setUpOnce.

@BeforeAll
public static void setUpOnce() throws Exception {
    testHarness = TesseraTestHarnessFactory.create("enclave", Files.createTempDirectory(folder, "enclave"), new EnclaveKeyConfiguration("enclave_key_0.pub", "enclave_key_1.key"), Optional.empty());
    testHarness.start();
    final EnclaveFactory factory = new EnclaveFactory(vertx);
    enclave = factory.createVertxEnclave(testHarness.clientUrl());
    messageFrame = mock(MessageFrame.class);
    final BlockDataGenerator blockGenerator = new BlockDataGenerator();
    final Block genesis = blockGenerator.genesisBlock();
    final Block block = blockGenerator.block(new BlockDataGenerator.BlockOptions().setParentHash(genesis.getHeader().getHash()));
    when(messageFrame.getBlockValues()).thenReturn(block.getHeader());
    final PrivateMetadataUpdater privateMetadataUpdater = mock(PrivateMetadataUpdater.class);
    when(privateMetadataUpdater.getPrivateBlockMetadata(any())).thenReturn(null);
    when(privateMetadataUpdater.getPrivacyGroupHeadBlockMap()).thenReturn(PrivacyGroupHeadBlockMap.empty());
    when(messageFrame.getContextVariable(eq(PrivateStateUtils.KEY_IS_PERSISTING_PRIVATE_STATE), anyBoolean())).thenReturn(false);
    when(messageFrame.getContextVariable(eq(PrivateStateUtils.KEY_PRIVATE_METADATA_UPDATER))).thenReturn(privateMetadataUpdater);
    when(messageFrame.hasContextVariable(eq(PrivateStateUtils.KEY_PRIVATE_METADATA_UPDATER))).thenReturn(true);
    worldStateArchive = mock(WorldStateArchive.class);
    final MutableWorldState mutableWorldState = mock(MutableWorldState.class);
    when(mutableWorldState.updater()).thenReturn(mock(WorldUpdater.class));
    when(worldStateArchive.getMutable()).thenReturn(mutableWorldState);
    when(worldStateArchive.getMutable(any(), any())).thenReturn(Optional.of(mutableWorldState));
    privateStateStorage = mock(PrivateStateStorage.class);
    final PrivateStateStorage.Updater storageUpdater = mock(PrivateStateStorage.Updater.class);
    when(privateStateStorage.getPrivacyGroupHeadBlockMap(any())).thenReturn(Optional.of(PrivacyGroupHeadBlockMap.empty()));
    when(storageUpdater.putPrivateBlockMetadata(nullable(Bytes32.class), nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(storageUpdater.putTransactionReceipt(nullable(Bytes32.class), nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(privateStateStorage.updater()).thenReturn(storageUpdater);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) Bytes32(org.apache.tuweni.bytes.Bytes32) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) EnclaveKeyConfiguration(org.hyperledger.enclave.testutil.EnclaveKeyConfiguration) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Block(org.hyperledger.besu.ethereum.core.Block) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 8 with EnclaveFactory

use of org.hyperledger.besu.enclave.EnclaveFactory in project besu by hyperledger.

the class PrivGetPrivateTransactionIntegrationTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    vertx = Vertx.vertx();
    testHarness = TesseraTestHarnessFactory.create("enclave", Files.createTempDirectory(folder, "enclave"), new EnclaveKeyConfiguration("enclave_key_0.pub", "enclave_key_0.key"), Optional.empty());
    testHarness.start();
    final EnclaveFactory factory = new EnclaveFactory(vertx);
    enclave = factory.createVertxEnclave(testHarness.clientUrl());
    privacyController = new RestrictedDefaultPrivacyController(blockchain, privateStateStorage, enclave, null, null, null, null, null);
}
Also used : EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) EnclaveKeyConfiguration(org.hyperledger.enclave.testutil.EnclaveKeyConfiguration) RestrictedDefaultPrivacyController(org.hyperledger.besu.ethereum.privacy.RestrictedDefaultPrivacyController) BeforeEach(org.junit.jupiter.api.BeforeEach)

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