Privacy multitenancy cli option (#264)

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
pull/269/head
Jason Frame 5 years ago committed by GitHub
parent ebb76dfdb6
commit f33fe8f63d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  2. 40
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  3. 1
      besu/src/test/resources/everything_config.toml
  4. 26
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/PrivacyParameters.java

@ -657,6 +657,12 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
description = "Enable private transactions (default: ${DEFAULT-VALUE})") description = "Enable private transactions (default: ${DEFAULT-VALUE})")
private final Boolean isPrivacyEnabled = false; private final Boolean isPrivacyEnabled = false;
@Option(
names = {"--privacy-multi-tenancy-enabled"},
description = "Enable multi-tenant private transactions (default: ${DEFAULT-VALUE})",
hidden = true)
private final Boolean isPrivacyMultiTenancyEnabled = false;
@Option( @Option(
names = {"--revert-reason-enabled"}, names = {"--revert-reason-enabled"},
description = description =
@ -1359,7 +1365,11 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
commandLine, commandLine,
"--privacy-enabled", "--privacy-enabled",
!isPrivacyEnabled, !isPrivacyEnabled,
asList("--privacy-url", "--privacy-public-key-file", "--privacy-precompiled-address")); asList(
"--privacy-url",
"--privacy-public-key-file",
"--privacy-precompiled-address",
"--privacy-multi-tenancy-enabled"));
final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder(); final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder();
if (isPrivacyEnabled) { if (isPrivacyEnabled) {
@ -1371,8 +1381,17 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
throw new ParameterException(commandLine, String.format("%s %s", "Pruning", errorSuffix)); throw new ParameterException(commandLine, String.format("%s %s", "Pruning", errorSuffix));
} }
if (isPrivacyMultiTenancyEnabled
&& !jsonRpcConfiguration.isAuthenticationEnabled()
&& !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.setEnabled(true);
privacyParametersBuilder.setEnclaveUrl(privacyUrl); privacyParametersBuilder.setEnclaveUrl(privacyUrl);
privacyParametersBuilder.setMultiTenancyEnabled(isPrivacyMultiTenancyEnabled);
if (privacyPublicKeyFile() != null) { if (privacyPublicKeyFile() != null) {
try { try {
privacyParametersBuilder.setEnclavePublicKeyUsingFile(privacyPublicKeyFile()); privacyParametersBuilder.setEnclavePublicKeyUsingFile(privacyPublicKeyFile());

@ -113,6 +113,8 @@ public class BesuCommandTest extends CommandTestAbstract {
.put("config", (new JsonObject()).put("chainId", GENESIS_CONFIG_TEST_CHAINID)); .put("config", (new JsonObject()).put("chainId", GENESIS_CONFIG_TEST_CHAINID));
private static final JsonObject GENESIS_INVALID_DATA = private static final JsonObject GENESIS_INVALID_DATA =
(new JsonObject()).put("config", new JsonObject()); (new JsonObject()).put("config", new JsonObject());
private static final String ENCLAVE_PUBLIC_KEY_PATH =
BesuCommand.class.getResource("/orion_publickey.pub").getPath();
private final String[] validENodeStrings = { private final String[] validENodeStrings = {
"enode://" + VALID_NODE_ID + "@192.168.0.1:4567", "enode://" + VALID_NODE_ID + "@192.168.0.1:4567",
@ -2680,6 +2682,44 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(enclaveArg.getValue().isEnabled()).isEqualTo(false); assertThat(enclaveArg.getValue().isEnabled()).isEqualTo(false);
} }
@Test
public void privacyMultiTenancyIsConfiguredWhenConfiguredWithNecessaryOptions() {
when(storageService.getByName("rocksdb-privacy"))
.thenReturn(Optional.of(rocksDBSPrivacyStorageFactory));
parseCommand(
"--privacy-enabled",
"--rpc-http-authentication-enabled",
"--privacy-multi-tenancy-enabled",
"--rpc-http-authentication-jwt-public-key-file",
"/non/existent/file",
"--privacy-public-key-file",
ENCLAVE_PUBLIC_KEY_PATH);
final ArgumentCaptor<PrivacyParameters> privacyParametersArgumentCaptor =
ArgumentCaptor.forClass(PrivacyParameters.class);
verify(mockControllerBuilder).privacyParameters(privacyParametersArgumentCaptor.capture());
verify(mockControllerBuilder).build();
assertThat(privacyParametersArgumentCaptor.getValue().isMultiTenancyEnabled()).isTrue();
}
@Test
public void privacyMultiTenancyWithoutAuthenticationFails() {
parseCommand(
"--privacy-enabled",
"--privacy-multi-tenancy-enabled",
"--rpc-http-authentication-jwt-public-key-file",
"/non/existent/file",
"--privacy-public-key-file",
ENCLAVE_PUBLIC_KEY_PATH);
assertThat(commandErrorOutput.toString())
.startsWith(
"Privacy multi-tenancy requires either http authentication to be enabled or WebSocket authentication to be enabled");
}
private Path createFakeGenesisFile(final JsonObject jsonGenesis) throws IOException { private Path createFakeGenesisFile(final JsonObject jsonGenesis) throws IOException {
final Path genesisFile = Files.createTempFile("genesisFile", ""); final Path genesisFile = Files.createTempFile("genesisFile", "");
Files.write(genesisFile, encodeJsonGenesis(jsonGenesis).getBytes(UTF_8)); Files.write(genesisFile, encodeJsonGenesis(jsonGenesis).getBytes(UTF_8));

@ -105,6 +105,7 @@ permissions-accounts-contract-address="0x000000000000000000000000000000000000678
privacy-url="http://127.0.0.1:8888" privacy-url="http://127.0.0.1:8888"
privacy-public-key-file="./pubKey.pub" privacy-public-key-file="./pubKey.pub"
privacy-enabled=false privacy-enabled=false
privacy-multi-tenancy-enabled=true
privacy-precompiled-address=9 privacy-precompiled-address=9
privacy-marker-transaction-signing-key-file="./signerKey" privacy-marker-transaction-signing-key-file="./signerKey"

@ -51,6 +51,7 @@ public class PrivacyParameters {
private PrivacyStorageProvider privateStorageProvider; private PrivacyStorageProvider privateStorageProvider;
private WorldStateArchive privateWorldStateArchive; private WorldStateArchive privateWorldStateArchive;
private PrivateStateStorage privateStateStorage; private PrivateStateStorage privateStateStorage;
private boolean multiTenancyEnabled;
public Integer getPrivacyAddress() { public Integer getPrivacyAddress() {
return privacyAddress; return privacyAddress;
@ -132,9 +133,25 @@ public class PrivacyParameters {
this.enclave = enclave; this.enclave = enclave;
} }
private void setMultiTenancyEnabled(final boolean multiTenancyEnabled) {
this.multiTenancyEnabled = multiTenancyEnabled;
}
public boolean isMultiTenancyEnabled() {
return multiTenancyEnabled;
}
@Override @Override
public String toString() { public String toString() {
return "PrivacyParameters{" + "enabled=" + enabled + ", enclaveUri='" + enclaveUri + '\'' + '}'; return "PrivacyParameters{"
+ "enabled="
+ enabled
+ ", multiTenancyEnabled = "
+ multiTenancyEnabled
+ ", enclaveUri='"
+ enclaveUri
+ '\''
+ '}';
} }
public static class Builder { public static class Builder {
@ -147,6 +164,7 @@ public class PrivacyParameters {
private Path privateKeyPath; private Path privateKeyPath;
private PrivacyStorageProvider storageProvider; private PrivacyStorageProvider storageProvider;
private EnclaveFactory enclaveFactory; private EnclaveFactory enclaveFactory;
private boolean multiTenancyEnabled;
public Builder setPrivacyAddress(final Integer privacyAddress) { public Builder setPrivacyAddress(final Integer privacyAddress) {
this.privacyAddress = privacyAddress; this.privacyAddress = privacyAddress;
@ -178,6 +196,11 @@ public class PrivacyParameters {
return this; return this;
} }
public Builder setMultiTenancyEnabled(final boolean multiTenancyEnabled) {
this.multiTenancyEnabled = multiTenancyEnabled;
return this;
}
public PrivacyParameters build() throws IOException { public PrivacyParameters build() throws IOException {
final PrivacyParameters config = new PrivacyParameters(); final PrivacyParameters config = new PrivacyParameters();
if (enabled) { if (enabled) {
@ -204,6 +227,7 @@ public class PrivacyParameters {
config.setEnabled(enabled); config.setEnabled(enabled);
config.setEnclaveUri(enclaveUrl); config.setEnclaveUri(enclaveUrl);
config.setPrivacyAddress(privacyAddress); config.setPrivacyAddress(privacyAddress);
config.setMultiTenancyEnabled(multiTenancyEnabled);
return config; return config;
} }

Loading…
Cancel
Save