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