Multi-Tenancy: Do not specify a public key anymore when requesting a … (#185)

* Multi-Tenancy: Do not specify a public key anymore when requesting a payload from Orion, so all private keys are tried to decrypt the encrypted payload.

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
pull/182/head
pinges 5 years ago committed by Usman Saleem
parent a6b2ec7460
commit 3c1768eef7
  1. 2
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/EnclaveErrorAcceptanceTest.java
  2. 4
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/EthSignerAcceptanceTest.java
  3. 8
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/web3j/privacy/PrivacyGroupAcceptanceTest.java
  4. 4
      enclave/src/main/java/org/hyperledger/besu/enclave/types/ReceiveRequest.java
  5. 4
      enclave/src/main/java/org/hyperledger/besu/enclave/types/ReceiveResponse.java
  6. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java
  7. 6
      ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractIntegrationTest.java
  8. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java
  9. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionHandler.java
  10. 3
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java
  11. 2
      ethereum/referencetests/src/test/resources
  12. 2
      gradle/versions.gradle
  13. 4
      testutil/src/main/java/org/hyperledger/orion/testutil/OrionTestHarnessFactory.java

@ -152,7 +152,7 @@ public class EnclaveErrorAcceptanceTest extends PrivacyAcceptanceTestBase {
alice.getEnclaveKey(), alice.getEnclaveKey(),
bob.getEnclaveKey()))); bob.getEnclaveKey())));
assertThat(throwable).hasMessageContaining("NodePushingToPeer"); assertThat(throwable).hasMessageContaining("NodePropagatingToAllPeers");
} }
@Test @Test

@ -107,8 +107,8 @@ public class EthSignerAcceptanceTest extends PrivacyAcceptanceTestBase {
new PrivacyGroup( new PrivacyGroup(
privacyGroupId, privacyGroupId,
PrivacyGroup.Type.PANTHEON, PrivacyGroup.Type.PANTHEON,
"Default Name", "",
"Default Description", "",
Base64String.wrapList(minerNode.getEnclaveKey())))); Base64String.wrapList(minerNode.getEnclaveKey()))));
final String transactionHash = final String transactionHash =

@ -76,7 +76,7 @@ public class PrivacyGroupAcceptanceTest extends PrivacyAcceptanceTestBase {
new PrivacyGroup( new PrivacyGroup(
privacyGroupId, privacyGroupId,
PrivacyGroup.Type.PANTHEON, PrivacyGroup.Type.PANTHEON,
"Default Name", "",
"my group description", "my group description",
Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey())); Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey()));
@ -97,7 +97,7 @@ public class PrivacyGroupAcceptanceTest extends PrivacyAcceptanceTestBase {
privacyGroupId, privacyGroupId,
PrivacyGroup.Type.PANTHEON, PrivacyGroup.Type.PANTHEON,
"myGroupName", "myGroupName",
"Default Description", "",
Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey())); Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey()));
alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected)); alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));
@ -116,8 +116,8 @@ public class PrivacyGroupAcceptanceTest extends PrivacyAcceptanceTestBase {
new PrivacyGroup( new PrivacyGroup(
privacyGroupId, privacyGroupId,
PrivacyGroup.Type.PANTHEON, PrivacyGroup.Type.PANTHEON,
"Default Name", "",
"Default Description", "",
Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey())); Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey()));
alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected)); alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));

@ -28,6 +28,10 @@ public class ReceiveRequest {
this.to = to; this.to = to;
} }
public ReceiveRequest(final String key) {
this(key, null);
}
public String getKey() { public String getKey() {
return key; return key;
} }

@ -21,8 +21,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonPropertyOrder({"payload", "privacyGroupId"}) @JsonPropertyOrder({"payload", "privacyGroupId"})
public class ReceiveResponse { public class ReceiveResponse {
private byte[] payload; private final byte[] payload;
private String privacyGroupId; private final String privacyGroupId;
@JsonCreator @JsonCreator
public ReceiveResponse( public ReceiveResponse(

@ -36,7 +36,7 @@ public class PrivCreatePrivacyGroup implements JsonRpcMethod {
private static final Logger LOG = getLogger(); private static final Logger LOG = getLogger();
private final Enclave enclave; private final Enclave enclave;
private PrivacyParameters privacyParameters; private final PrivacyParameters privacyParameters;
private final JsonRpcParameter parameters; private final JsonRpcParameter parameters;
public PrivCreatePrivacyGroup( public PrivCreatePrivacyGroup(

@ -160,11 +160,7 @@ public class PrivacyPrecompiledContractIntegrationTest {
final PrivacyPrecompiledContract privacyPrecompiledContract = final PrivacyPrecompiledContract privacyPrecompiledContract =
new PrivacyPrecompiledContract( new PrivacyPrecompiledContract(
new SpuriousDragonGasCalculator(), new SpuriousDragonGasCalculator(), enclave, worldStateArchive, privateStateStorage);
publicKeys.get(0),
enclave,
worldStateArchive,
privateStateStorage);
privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor()); privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor());

@ -46,7 +46,6 @@ import org.apache.logging.log4j.Logger;
public class PrivacyPrecompiledContract extends AbstractPrecompiledContract { public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
private final Enclave enclave; private final Enclave enclave;
private final String enclavePublicKey;
private final WorldStateArchive privateWorldStateArchive; private final WorldStateArchive privateWorldStateArchive;
private final PrivateStateStorage privateStateStorage; private final PrivateStateStorage privateStateStorage;
private PrivateTransactionProcessor privateTransactionProcessor; private PrivateTransactionProcessor privateTransactionProcessor;
@ -58,7 +57,6 @@ public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
final GasCalculator gasCalculator, final PrivacyParameters privacyParameters) { final GasCalculator gasCalculator, final PrivacyParameters privacyParameters) {
this( this(
gasCalculator, gasCalculator,
privacyParameters.getEnclavePublicKey(),
new Enclave(privacyParameters.getEnclaveUri()), new Enclave(privacyParameters.getEnclaveUri()),
privacyParameters.getPrivateWorldStateArchive(), privacyParameters.getPrivateWorldStateArchive(),
privacyParameters.getPrivateStateStorage()); privacyParameters.getPrivateStateStorage());
@ -66,13 +64,11 @@ public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
PrivacyPrecompiledContract( PrivacyPrecompiledContract(
final GasCalculator gasCalculator, final GasCalculator gasCalculator,
final String publicKey,
final Enclave enclave, final Enclave enclave,
final WorldStateArchive worldStateArchive, final WorldStateArchive worldStateArchive,
final PrivateStateStorage privateStateStorage) { final PrivateStateStorage privateStateStorage) {
super("Privacy", gasCalculator); super("Privacy", gasCalculator);
this.enclave = enclave; this.enclave = enclave;
this.enclavePublicKey = publicKey;
this.privateWorldStateArchive = worldStateArchive; this.privateWorldStateArchive = worldStateArchive;
this.privateStateStorage = privateStateStorage; this.privateStateStorage = privateStateStorage;
} }
@ -90,12 +86,12 @@ public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
@Override @Override
public BytesValue compute(final BytesValue input, final MessageFrame messageFrame) { public BytesValue compute(final BytesValue input, final MessageFrame messageFrame) {
final String key = BytesValues.asBase64String(input); final String key = BytesValues.asBase64String(input);
final ReceiveRequest receiveRequest = new ReceiveRequest(key, enclavePublicKey); final ReceiveRequest receiveRequest = new ReceiveRequest(key);
final ReceiveResponse receiveResponse; final ReceiveResponse receiveResponse;
try { try {
receiveResponse = enclave.receive(receiveRequest); receiveResponse = enclave.receive(receiveRequest);
} catch (Exception e) { } catch (final Exception e) {
LOG.error("Enclave probably does not have private transaction with key {}.", key, e); LOG.error("Enclave probably does not have private transaction with key {}.", key, e);
return BytesValue.EMPTY; return BytesValue.EMPTY;
} }

@ -94,8 +94,7 @@ public class PrivateTransactionHandler {
} }
} }
public String getPrivacyGroup(final String key, final PrivateTransaction privateTransaction) public String getPrivacyGroup(final String key, final PrivateTransaction privateTransaction) {
throws Exception {
if (privateTransaction.getPrivacyGroupId().isPresent()) { if (privateTransaction.getPrivacyGroupId().isPresent()) {
return BytesValues.asBase64String(privateTransaction.getPrivacyGroupId().get()); return BytesValues.asBase64String(privateTransaction.getPrivacyGroupId().get());
} }
@ -108,7 +107,7 @@ public class PrivateTransactionHandler {
try { try {
receiveResponse = enclave.receive(receiveRequest); receiveResponse = enclave.receive(receiveRequest);
return receiveResponse.getPrivacyGroupId(); return receiveResponse.getPrivacyGroupId();
} catch (Exception e) { } catch (final RuntimeException e) {
LOG.error("Failed to retrieve private transaction in enclave", e); LOG.error("Failed to retrieve private transaction in enclave", e);
throw e; throw e;
} }

@ -54,7 +54,6 @@ public class PrivacyPrecompiledContractTest {
@Rule public final TemporaryFolder temp = new TemporaryFolder(); @Rule public final TemporaryFolder temp = new TemporaryFolder();
private final String actual = "Test String"; private final String actual = "Test String";
private final String publicKey = "public key";
private final BytesValue key = BytesValue.wrap(actual.getBytes(UTF_8)); private final BytesValue key = BytesValue.wrap(actual.getBytes(UTF_8));
private PrivacyPrecompiledContract privacyPrecompiledContract; private PrivacyPrecompiledContract privacyPrecompiledContract;
private PrivacyPrecompiledContract brokenPrivateTransactionHandler; private PrivacyPrecompiledContract brokenPrivateTransactionHandler;
@ -134,7 +133,6 @@ public class PrivacyPrecompiledContractTest {
privacyPrecompiledContract = privacyPrecompiledContract =
new PrivacyPrecompiledContract( new PrivacyPrecompiledContract(
new SpuriousDragonGasCalculator(), new SpuriousDragonGasCalculator(),
publicKey,
mockEnclave(), mockEnclave(),
worldStateArchive, worldStateArchive,
privateStateStorage); privateStateStorage);
@ -142,7 +140,6 @@ public class PrivacyPrecompiledContractTest {
brokenPrivateTransactionHandler = brokenPrivateTransactionHandler =
new PrivacyPrecompiledContract( new PrivacyPrecompiledContract(
new SpuriousDragonGasCalculator(), new SpuriousDragonGasCalculator(),
publicKey,
brokenMockEnclave(), brokenMockEnclave(),
worldStateArchive, worldStateArchive,
privateStateStorage); privateStateStorage);

@ -1 +1 @@
Subproject commit cfbcd15f91d4d6e1785d9cae5c5c37f47e8bad46 Subproject commit 0327d9f76ce2a292a99e7a9dfc93627368ce589e

@ -61,7 +61,7 @@ dependencyManagement {
dependency 'org.apache.tuweni:tuweni-crypto:0.9.0' dependency 'org.apache.tuweni:tuweni-crypto:0.9.0'
dependency 'org.apache.tuweni:tuweni-toml:0.9.0' dependency 'org.apache.tuweni:tuweni-toml:0.9.0'
dependency 'net.consensys:orion:1.3.2' dependency 'net.consensys:orion:1.5.0-SNAPSHOT'
dependency 'org.apache.commons:commons-text:1.8' dependency 'org.apache.commons:commons-text:1.8'

@ -38,8 +38,8 @@ public class OrionTestHarnessFactory {
final String privKeyPath, final String privKeyPath,
final List<String> othernodes) final List<String> othernodes)
throws IOException { throws IOException {
Path key1pub = copyResource(pubKeyPath, tempDir.resolve(pubKeyPath)); final Path key1pub = copyResource(pubKeyPath, tempDir.resolve(pubKeyPath));
Path key1key = copyResource(privKeyPath, tempDir.resolve(privKeyPath)); final Path key1key = copyResource(privKeyPath, tempDir.resolve(privKeyPath));
return create(tempDir, key1pub, key1key, othernodes); return create(tempDir, key1pub, key1key, othernodes);
} }

Loading…
Cancel
Save