Search in sources :

Example 6 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class PrivacyGroupManagerProviderTest method provider.

@Test
public void provider() {
    try (var enclaveMockedStatic = mockStatic(Enclave.class);
        var privacyGroupDAOMockStatic = mockStatic(PrivacyGroupDAO.class);
        var batchPrivacyGroupPublisherMockedStatic = mockStatic(BatchPrivacyGroupPublisher.class)) {
        enclaveMockedStatic.when(Enclave::create).thenReturn(mock(Enclave.class));
        privacyGroupDAOMockStatic.when(PrivacyGroupDAO::create).thenReturn(mock(PrivacyGroupDAO.class));
        batchPrivacyGroupPublisherMockedStatic.when(BatchPrivacyGroupPublisher::create).thenReturn(mock(BatchPrivacyGroupPublisher.class));
        PrivacyGroupManager result = PrivacyGroupManagerProvider.provider();
        assertThat(result).isNotNull();
        enclaveMockedStatic.verify(Enclave::create);
        enclaveMockedStatic.verifyNoMoreInteractions();
        privacyGroupDAOMockStatic.verify(PrivacyGroupDAO::create);
        privacyGroupDAOMockStatic.verifyNoMoreInteractions();
        batchPrivacyGroupPublisherMockedStatic.verify(BatchPrivacyGroupPublisher::create);
        batchPrivacyGroupPublisherMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : PrivacyGroupManager(com.quorum.tessera.privacygroup.PrivacyGroupManager) Enclave(com.quorum.tessera.enclave.Enclave) BatchPrivacyGroupPublisher(com.quorum.tessera.privacygroup.publish.BatchPrivacyGroupPublisher) PrivacyGroupDAO(com.quorum.tessera.data.PrivacyGroupDAO) Test(org.junit.Test)

Example 7 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class TransactionManagerProvider method provider.

public static TransactionManager provider() {
    final TransactionManagerHolder transactionManagerHolder = TransactionManagerHolder.INSTANCE;
    if (transactionManagerHolder.getTransactionManager().isPresent()) {
        return transactionManagerHolder.getTransactionManager().get();
    }
    final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
    final Enclave enclave = Enclave.create();
    final EncryptedRawTransactionDAO encryptedRawTransactionDAO = EncryptedRawTransactionDAO.create();
    LOGGER.debug("Creating ResendManager");
    final ResendManager resendManager = ResendManager.create();
    LOGGER.debug("Created ResendManager {}", resendManager);
    LOGGER.debug("Creating payload publisher");
    final PayloadPublisher payloadPublisher = PayloadPublisher.create();
    LOGGER.debug("Created payload publisher {}", payloadPublisher);
    LOGGER.debug("Creating batchPayloadPublisher");
    final BatchPayloadPublisher batchPayloadPublisher = BatchPayloadPublisher.create();
    LOGGER.debug("Created batchPayloadPublisher {}", batchPayloadPublisher);
    LOGGER.debug("Creating PrivacyHelper");
    final PrivacyHelper privacyHelper = PrivacyHelper.create();
    LOGGER.debug("Created PrivacyHelper {}", privacyHelper);
    int resendBatchSize = 100;
    LOGGER.debug("Creating PayloadDigest");
    final PayloadDigest messageHashFactory = PayloadDigest.create();
    LOGGER.debug("Created PayloadDigest {}", messageHashFactory);
    return transactionManagerHolder.store(new TransactionManagerImpl(enclave, encryptedTransactionDAO, encryptedRawTransactionDAO, resendManager, batchPayloadPublisher, privacyHelper, messageHashFactory));
}
Also used : ResendManager(com.quorum.tessera.transaction.resend.ResendManager) PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) Enclave(com.quorum.tessera.enclave.Enclave) EncryptedRawTransactionDAO(com.quorum.tessera.data.EncryptedRawTransactionDAO) PayloadDigest(com.quorum.tessera.enclave.PayloadDigest) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper)

Example 8 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class BatchWorkflowFactoryImpl method create.

@Override
public BatchWorkflow create(long transactionCount) {
    ValidateEnclaveStatus validateEnclaveStatus = new ValidateEnclaveStatus(enclave);
    PreparePayloadForRecipient preparePayloadForRecipient = new PreparePayloadForRecipient();
    FindRecipientFromPartyInfo findRecipientFromPartyInfo = new FindRecipientFromPartyInfo(discovery);
    FilterPayload filterPayload = new FilterPayload(enclave);
    SearchRecipientKeyForPayload searchRecipientKeyForPayload = new SearchRecipientKeyForPayload(enclave);
    SenderIsNotRecipient senderIsNotRecipient = new SenderIsNotRecipient(enclave);
    EncodedPayloadPublisher encodedPayloadPublisher = new EncodedPayloadPublisher(resendBatchPublisher);
    List<BatchWorkflowAction> handlers = List.of(validateEnclaveStatus, filterPayload, preparePayloadForRecipient, searchRecipientKeyForPayload, findRecipientFromPartyInfo, senderIsNotRecipient, encodedPayloadPublisher);
    return new BatchWorkflow() {

        private final AtomicLong filteredMessageCount = new AtomicLong(transactionCount);

        @Override
        public boolean execute(BatchWorkflowContext context) {
            context.setExpectedTotal(filteredMessageCount.get());
            boolean outcome = handlers.stream().filter(Predicate.not(h -> h.execute(context))).findFirst().isEmpty();
            if (!outcome) {
                context.setExpectedTotal(filteredMessageCount.decrementAndGet());
                encodedPayloadPublisher.checkOutstandingPayloads(context);
            }
            return outcome;
        }

        @Override
        public long getPublishedMessageCount() {
            return encodedPayloadPublisher.getPublishedCount();
        }
    };
}
Also used : Objects(java.util.Objects) AtomicLong(java.util.concurrent.atomic.AtomicLong) Discovery(com.quorum.tessera.discovery.Discovery) List(java.util.List) Predicate(java.util.function.Predicate) Enclave(com.quorum.tessera.enclave.Enclave) ResendBatchPublisher(com.quorum.tessera.recovery.resend.ResendBatchPublisher) com.quorum.tessera.recovery.workflow(com.quorum.tessera.recovery.workflow) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 9 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class BatchWorkflowFactoryProvider method provider.

public static BatchWorkflowFactory provider() {
    Enclave enclave = Enclave.create();
    Discovery discovery = Discovery.create();
    ResendBatchPublisher resendBatchPublisher = ResendBatchPublisher.create();
    return new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) ResendBatchPublisher(com.quorum.tessera.recovery.resend.ResendBatchPublisher)

Example 10 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class LegacyResendManagerImpl method resendIndividual.

protected ResendResponse resendIndividual(final PublicKey targetResendKey, final MessageHash messageHash) {
    final EncryptedTransaction encryptedTransaction = encryptedTransactionDAO.retrieveByHash(messageHash).orElseThrow(() -> new TransactionNotFoundException("Message with hash " + messageHash + " was not found"));
    final EncodedPayload payload = encryptedTransaction.getPayload();
    if (payload.getPrivacyMode() != PrivacyMode.STANDARD_PRIVATE) {
        throw new EnhancedPrivacyNotSupportedException("Cannot resend enhanced privacy transaction in legacy resend");
    }
    if (!Objects.equals(payload.getSenderKey(), targetResendKey)) {
        final EncodedPayload formattedPayload = EncodedPayload.Builder.forRecipient(payload, targetResendKey).build();
        return ResendResponse.Builder.create().withPayload(formattedPayload).build();
    }
    // split all the boxes out into their own payload
    final Set<EncodedPayload> allTxns = payload.getRecipientBoxes().stream().map(box -> EncodedPayload.Builder.from(payload).withNewRecipientKeys(Collections.emptyList()).withRecipientBoxes(List.of(box.getData())).build()).collect(Collectors.toSet());
    final BatchWorkflowContext context = new BatchWorkflowContext();
    context.setPayloadsToPublish(allTxns);
    context.setEncryptedTransaction(encryptedTransaction);
    new SearchRecipientKeyForPayload(enclave).execute(context);
    final EncodedPayload.Builder builder = EncodedPayload.Builder.from(payload).withNewRecipientKeys(new ArrayList<>()).withRecipientBoxes(new ArrayList<>());
    context.getPayloadsToPublish().forEach(formattedPayload -> {
        builder.withRecipientKey(formattedPayload.getRecipientKeys().get(0));
        builder.withRecipientBox(formattedPayload.getRecipientBoxes().get(0).getData());
    });
    return ResendResponse.Builder.create().withPayload(builder.build()).build();
}
Also used : IntStream(java.util.stream.IntStream) PublicKey(com.quorum.tessera.encryption.PublicKey) ResendResponse(com.quorum.tessera.recovery.resend.ResendResponse) java.util(java.util) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Collectors(java.util.stream.Collectors) com.quorum.tessera.recovery.workflow(com.quorum.tessera.recovery.workflow) Discovery(com.quorum.tessera.discovery.Discovery) ResendRequest(com.quorum.tessera.recovery.resend.ResendRequest) PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) TransactionNotFoundException(com.quorum.tessera.transaction.exception.TransactionNotFoundException) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) Enclave(com.quorum.tessera.enclave.Enclave) MessageHash(com.quorum.tessera.data.MessageHash) TransactionNotFoundException(com.quorum.tessera.transaction.exception.TransactionNotFoundException) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException)

Aggregations

Enclave (com.quorum.tessera.enclave.Enclave)29 Test (org.junit.Test)11 Discovery (com.quorum.tessera.discovery.Discovery)9 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)7 PayloadDigest (com.quorum.tessera.enclave.PayloadDigest)6 RuntimeContext (com.quorum.tessera.context.RuntimeContext)5 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)5 NetworkStore (com.quorum.tessera.discovery.NetworkStore)4 PrivacyHelper (com.quorum.tessera.transaction.PrivacyHelper)4 TransactionManager (com.quorum.tessera.transaction.TransactionManager)4 Config (com.quorum.tessera.config.Config)3 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)3 LegacyResendManager (com.quorum.tessera.recovery.workflow.LegacyResendManager)3 Client (jakarta.ws.rs.client.Client)3 CliResult (com.quorum.tessera.cli.CliResult)2 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)2 RestClientFactory (com.quorum.tessera.context.RestClientFactory)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 ResendBatchPublisher (com.quorum.tessera.recovery.resend.ResendBatchPublisher)2