Search in sources :

Example 31 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class FlexiblePrivacyController method sendRequest.

private SendResponse sendRequest(final PrivateTransaction privateTransaction, final Optional<PrivacyGroup> maybePrivacyGroup) {
    final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
    final PrivacyGroup privacyGroup = maybePrivacyGroup.orElseThrow();
    final Optional<TransactionProcessingResult> version = privateTransactionSimulator.process(privateTransaction.getPrivacyGroupId().orElseThrow().toBase64String(), buildCallParams(GET_VERSION_METHOD_SIGNATURE));
    new VersionedPrivateTransaction(privateTransaction, version).writeTo(rlpOutput);
    final List<String> flexiblePrivateFor = privacyGroup.getMembers();
    return enclave.send(rlpOutput.encoded().toBase64String(), privateTransaction.getPrivateFrom().toBase64String(), flexiblePrivateFor);
}
Also used : BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)

Example 32 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class FlexiblePrivacyController method findPrivacyGroupByMembers.

@Override
public PrivacyGroup[] findPrivacyGroupByMembers(final List<String> addresses, final String privacyUserId) {
    final ArrayList<PrivacyGroup> privacyGroups = new ArrayList<>();
    final PrivacyGroupHeadBlockMap privacyGroupHeadBlockMap = privateStateStorage.getPrivacyGroupHeadBlockMap(blockchain.getChainHeadHash()).orElse(PrivacyGroupHeadBlockMap.empty());
    privacyGroupHeadBlockMap.keySet().forEach(c -> {
        final Optional<PrivacyGroup> maybePrivacyGroup = findPrivacyGroupByGroupId(c.toBase64String(), privacyUserId);
        if (maybePrivacyGroup.isPresent() && maybePrivacyGroup.get().getMembers().containsAll(addresses)) {
            privacyGroups.add(maybePrivacyGroup.get());
        }
    });
    return privacyGroups.toArray(new PrivacyGroup[0]);
}
Also used : ArrayList(java.util.ArrayList) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)

Example 33 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class PrivacyPrecompiledContractTest method testInvalidPrivateTransaction.

@Test
public void testInvalidPrivateTransaction() {
    final Enclave enclave = mock(Enclave.class);
    when(enclave.retrievePrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID)).thenReturn(new PrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", Arrays.asList(VALID_BASE64_ENCLAVE_KEY.toBase64String())));
    final PrivacyPrecompiledContract contract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, privateStateRootResolver, privateStateGenesisAllocator, "RestrictedPrivacyTest");
    contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.invalid(ValidationResult.invalid(TransactionInvalidReason.INCORRECT_NONCE))));
    final PrivateTransaction privateTransaction = privateTransactionBesu();
    final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
    final String privateFrom = privateTransaction.getPrivateFrom().toBase64String();
    final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
    when(enclave.receive(any(String.class))).thenReturn(response);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.EMPTY);
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) Enclave(org.hyperledger.besu.enclave.Enclave) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Example 34 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class MultiTenancyPrivacyControllerTest method sendsBesuTransactionWithPrivacyUserIdInPrivacyGroupAndProducesSuccessfulResponse.

@Test
public void sendsBesuTransactionWithPrivacyUserIdInPrivacyGroupAndProducesSuccessfulResponse() {
    final PrivateTransaction transaction = PrivateTransaction.builder().privateFrom(Bytes.fromBase64String(ENCLAVE_PUBLIC_KEY1)).privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)).build();
    final PrivacyGroup privacyGroupWithPrivacyUserId = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2));
    when(privacyController.createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithPrivacyUserId))).thenReturn(ENCLAVE_KEY);
    final String response = multiTenancyPrivacyController.createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithPrivacyUserId));
    assertThat(response).isEqualTo(ENCLAVE_KEY);
    verify(privacyController).createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithPrivacyUserId));
}
Also used : PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Example 35 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class MultiTenancyPrivacyControllerTest method findsPrivacyGroupWhenPrivacyUserIdInAddresses.

@Test
public void findsPrivacyGroupWhenPrivacyUserIdInAddresses() {
    final List<String> addresses = List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2);
    final PrivacyGroup privacyGroup = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2));
    when(privacyController.findPrivacyGroupByMembers(addresses, ENCLAVE_PUBLIC_KEY1)).thenReturn(new PrivacyGroup[] { privacyGroup });
    final PrivacyGroup[] privacyGroups = multiTenancyPrivacyController.findPrivacyGroupByMembers(addresses, ENCLAVE_PUBLIC_KEY1);
    assertThat(privacyGroups).hasSize(1);
    assertThat(privacyGroups[0]).usingRecursiveComparison().isEqualTo(privacyGroup);
    verify(privacyController).findPrivacyGroupByMembers(addresses, ENCLAVE_PUBLIC_KEY1);
}
Also used : PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Aggregations

PrivacyGroup (org.hyperledger.besu.enclave.types.PrivacyGroup)35 Test (org.junit.Test)19 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)13 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)8 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)7 JsonObject (io.vertx.core.json.JsonObject)5 Bytes (org.apache.tuweni.bytes.Bytes)5 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)5 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)5 Enclave (org.hyperledger.besu.enclave.Enclave)4 MultiTenancyValidationException (org.hyperledger.besu.ethereum.privacy.MultiTenancyValidationException)4 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)4 Test (org.junit.jupiter.api.Test)4 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)3 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)3 PrecompiledContract (org.hyperledger.besu.evm.precompile.PrecompiledContract)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CreatePrivacyGroupParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter)2