Search in sources :

Example 1 with EncryptedTransaction

use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.

the class MigrationTest method generateEncryptedTransaction.

static EncryptedTransaction generateEncryptedTransaction() {
    EncryptedTransaction encryptedTransaction = new EncryptedTransaction();
    encryptedTransaction.setHash(new MessageHash(UUID.randomUUID().toString().getBytes()));
    encryptedTransaction.setPayload(generateEncodedPayload());
    encryptedTransaction.setEncodedPayloadCodec(EncodedPayloadCodec.LEGACY);
    return encryptedTransaction;
}
Also used : MessageHash(com.quorum.tessera.data.MessageHash) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction)

Example 2 with EncryptedTransaction

use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.

the class ResendManagerImplTest method storePayloadAsSenderWhenTxIsPresentAndRecipientExisted.

@Test
public void storePayloadAsSenderWhenTxIsPresentAndRecipientExisted() {
    final EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getSenderKey()).thenReturn(senderKey);
    when(encodedPayload.getCipherText()).thenReturn(cipherText);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey1));
    when(encodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox1));
    when(enclave.getPublicKeys()).thenReturn(singleton(senderKey));
    final EncryptedTransaction et = mock(EncryptedTransaction.class);
    when(et.getPayload()).thenReturn(encodedPayload);
    when(encryptedTransactionDAO.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(et));
    resendManager.acceptOwnMessage(encodedPayload);
    assertThat(encodedPayload.getRecipientKeys()).containsExactly(recipientKey1);
    assertThat(encodedPayload.getRecipientBoxes()).containsExactly(recipientBox1);
    verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
    verify(enclave).getPublicKeys();
    verify(enclave).unencryptTransaction(encodedPayload, senderKey);
}
Also used : MessageHash(com.quorum.tessera.data.MessageHash) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 3 with EncryptedTransaction

use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.

the class ResendManagerImplTest method storePayloadAsSenderWhenTxIsPresentAndRecipientAlreadyExists.

@Test
public void storePayloadAsSenderWhenTxIsPresentAndRecipientAlreadyExists() {
    final EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getCipherText()).thenReturn("CIPHERTEXT".getBytes());
    when(encodedPayload.getSenderKey()).thenReturn(senderKey);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey2));
    when(encodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox2));
    final EncodedPayload existingEncodedPayload = mock(EncodedPayload.class);
    when(existingEncodedPayload.getCipherText()).thenReturn("CIPHERTEXT".getBytes());
    when(existingEncodedPayload.getSenderKey()).thenReturn(senderKey);
    when(existingEncodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey1, recipientKey2));
    when(existingEncodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox1, recipientBox2));
    final EncryptedTransaction et = mock(EncryptedTransaction.class);
    when(et.getPayload()).thenReturn(existingEncodedPayload);
    when(enclave.getPublicKeys()).thenReturn(Set.of(senderKey));
    when(encryptedTransactionDAO.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(et));
    resendManager.acceptOwnMessage(encodedPayload);
    assertThat(encodedPayload.getRecipientKeys()).containsExactly(recipientKey2);
    assertThat(encodedPayload.getRecipientBoxes()).containsExactly(recipientBox2);
    verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
    verify(enclave).getPublicKeys();
    verify(enclave).unencryptTransaction(encodedPayload, senderKey);
}
Also used : MessageHash(com.quorum.tessera.data.MessageHash) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 4 with EncryptedTransaction

use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.

the class ResendManagerImplTest method invalidPayloadFromMaliciousRecipient.

@Test
public void invalidPayloadFromMaliciousRecipient() {
    final EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getSenderKey()).thenReturn(senderKey);
    when(encodedPayload.getCipherText()).thenReturn(cipherText);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey1));
    when(encodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox1));
    final EncodedPayload existingEncodedPayload = mock(EncodedPayload.class);
    when(existingEncodedPayload.getCipherText()).thenReturn("CIPHERTEXT".getBytes());
    when(existingEncodedPayload.getSenderKey()).thenReturn(senderKey);
    when(existingEncodedPayload.getRecipientKeys()).thenReturn(List.of());
    when(existingEncodedPayload.getRecipientBoxes()).thenReturn(List.of());
    final EncryptedTransaction et = mock(EncryptedTransaction.class);
    when(et.getPayload()).thenReturn(existingEncodedPayload);
    when(enclave.getPublicKeys()).thenReturn(singleton(senderKey));
    when(encryptedTransactionDAO.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(et));
    when(enclave.unencryptTransaction(existingEncodedPayload, senderKey)).thenReturn("payload1".getBytes());
    final Throwable throwable = catchThrowable(() -> resendManager.acceptOwnMessage(encodedPayload));
    assertThat(throwable).isInstanceOf(IllegalArgumentException.class).hasMessage("Invalid payload provided");
    verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
    verify(enclave).getPublicKeys();
    verify(enclave).unencryptTransaction(encodedPayload, senderKey);
    verify(enclave).unencryptTransaction(existingEncodedPayload, senderKey);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) MessageHash(com.quorum.tessera.data.MessageHash) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 5 with EncryptedTransaction

use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.

the class PrivacyHelperTest method findAffectedContractTransactionsFromSendRequestFound.

@Test
public void findAffectedContractTransactionsFromSendRequestFound() {
    final MessageHash hash1 = mock(MessageHash.class);
    final MessageHash hash2 = mock(MessageHash.class);
    EncryptedTransaction et1 = mock(EncryptedTransaction.class);
    when(et1.getEncodedPayload()).thenReturn("payload1".getBytes());
    when(et1.getHash()).thenReturn(hash1);
    when(et1.getPayload()).thenReturn(mock(EncodedPayload.class));
    EncryptedTransaction et2 = mock(EncryptedTransaction.class);
    when(et2.getEncodedPayload()).thenReturn("payload2".getBytes());
    when(et2.getHash()).thenReturn(hash2);
    when(et2.getPayload()).thenReturn(mock(EncodedPayload.class));
    when(encryptedTransactionDAO.findByHashes(anyCollection())).thenReturn(List.of(et1, et2));
    List<AffectedTransaction> affectedTransactions = privacyHelper.findAffectedContractTransactionsFromSendRequest(Set.of(hash1, hash2));
    assertThat(affectedTransactions).isNotNull();
    assertThat(affectedTransactions.size()).isEqualTo(2);
    verify(encryptedTransactionDAO).findByHashes(any());
}
Also used : MessageHash(com.quorum.tessera.data.MessageHash) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Aggregations

EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)32 Test (org.junit.Test)24 PublicKey (com.quorum.tessera.encryption.PublicKey)21 MessageHash (com.quorum.tessera.data.MessageHash)19 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)13 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 ResendRequest (com.quorum.tessera.recovery.resend.ResendRequest)5 BatchWorkflow (com.quorum.tessera.recovery.workflow.BatchWorkflow)5 BatchWorkflowContext (com.quorum.tessera.recovery.workflow.BatchWorkflowContext)5 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)4 ResendResponse (com.quorum.tessera.recovery.resend.ResendResponse)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 After (org.junit.After)4 Before (org.junit.Before)4 Base64Codec (com.quorum.tessera.base64.Base64Codec)3 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)3 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)3 com.quorum.tessera.enclave (com.quorum.tessera.enclave)3 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)3