Search in sources :

Example 61 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class NodeInfoTest method createWithEverything.

@Test
public void createWithEverything() {
    String url = "someurl";
    final Recipient recipient = mock(Recipient.class);
    PublicKey publicKey = mock(PublicKey.class);
    when(recipient.getUrl()).thenReturn("http://someurl.com/");
    when(recipient.getKey()).thenReturn(publicKey);
    Collection<Recipient> recipients = List.of(recipient);
    Collection<String> supportedVersions = List.of("ONE", "TWO");
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(recipients).withSupportedApiVersions(supportedVersions).build();
    assertThat(nodeInfo.getUrl()).isEqualTo(url);
    assertThat(nodeInfo.getRecipients()).isEqualTo(Set.copyOf(recipients));
    assertThat(nodeInfo.getRecipientsAsMap()).containsKey(publicKey).containsValue("http://someurl.com/");
    assertThat(nodeInfo.supportedApiVersions()).isEqualTo(Set.copyOf(supportedVersions));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 62 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class TransactionManagerTest method sendSignedTransaction.

@Test
public void sendSignedTransaction() {
    EncodedPayload payload = mock(EncodedPayload.class);
    MessageHash hash = new MessageHash("HASH".getBytes());
    EncryptedRawTransaction encryptedRawTransaction = mock(EncryptedRawTransaction.class);
    when(encryptedRawTransaction.getHash()).thenReturn(hash);
    when(encryptedRawTransaction.toRawTransaction()).thenReturn(mock((RawTransaction.class)));
    when(encryptedRawTransactionDAO.retrieveByHash(hash)).thenReturn(Optional.of(encryptedRawTransaction));
    when(payload.getCipherText()).thenReturn("ENCRYPTED_PAYLOAD".getBytes());
    when(enclave.encryptPayload(any(RawTransaction.class), any(), any())).thenReturn(payload);
    PublicKey receiver = PublicKey.from("RECEIVER".getBytes());
    when(enclave.getPublicKeys()).thenReturn(Set.of(receiver));
    SendSignedRequest sendSignedRequest = mock(SendSignedRequest.class);
    when(sendSignedRequest.getRecipients()).thenReturn(List.of(receiver));
    when(sendSignedRequest.getSignedData()).thenReturn("HASH".getBytes());
    when(sendSignedRequest.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    SendResponse result = transactionManager.sendSignedTransaction(sendSignedRequest);
    assertThat(result).isNotNull();
    assertThat(result.getTransactionHash()).isEqualTo(new MessageHash("HASH".getBytes()));
    assertThat(result.getManagedParties()).containsExactly(receiver);
    ArgumentCaptor<PrivacyMetadata> data = ArgumentCaptor.forClass(PrivacyMetadata.class);
    verify(enclave).encryptPayload(any(RawTransaction.class), any(), data.capture());
    verify(encryptedTransactionDAO).save(any(EncryptedTransaction.class), any(Callable.class));
    verify(encryptedRawTransactionDAO).retrieveByHash(any(MessageHash.class));
    verify(enclave).getForwardingKeys();
    verify(enclave).getPublicKeys();
    final PrivacyMetadata passingData = data.getValue();
    assertThat(passingData.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
    assertThat(passingData.getPrivacyGroupId()).isNotPresent();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 63 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class TransactionManagerTest method getParticipantsReturnsAllRecipients.

@Test
public void getParticipantsReturnsAllRecipients() {
    MessageHash transactionHash = mock(MessageHash.class);
    final PublicKey senderKey = mock(PublicKey.class);
    final PublicKey recipientKey = mock(PublicKey.class);
    final EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
    final EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(senderKey, recipientKey));
    when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
    when(encryptedTransactionDAO.retrieveByHash(transactionHash)).thenReturn(Optional.of(encryptedTransaction));
    final List<PublicKey> participants = transactionManager.getParticipants(transactionHash);
    assertThat(participants).containsExactlyInAnyOrder(senderKey, recipientKey);
    verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 64 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class TransactionManagerTest method receiveWithAffectedContractTransactions.

@Test
public void receiveWithAffectedContractTransactions() {
    PublicKey sender = PublicKey.from("sender".getBytes());
    PublicKey recipient = PublicKey.from("recipient".getBytes());
    MessageHash messageHash = mock(MessageHash.class);
    ReceiveRequest receiveRequest = mock(ReceiveRequest.class);
    when(receiveRequest.getRecipient()).thenReturn(Optional.of(recipient));
    when(receiveRequest.getTransactionHash()).thenReturn(messageHash);
    final String b64AffectedTxHash = "bfMIqWJ/QGQhkK4USxMBxduzfgo/SIGoCros5bWYfPKUBinlAUCqLVOUAP9q+BgLlsWni1M6rnzfmaqSw2J5hQ==";
    final Map<TxHash, SecurityHash> affectedTxs = Map.of(new TxHash(b64AffectedTxHash), SecurityHash.from("encoded".getBytes()));
    EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getExecHash()).thenReturn("execHash".getBytes());
    when(payload.getPrivacyMode()).thenReturn(PrivacyMode.PRIVATE_STATE_VALIDATION);
    when(payload.getAffectedContractTransactions()).thenReturn(affectedTxs);
    when(payload.getSenderKey()).thenReturn(sender);
    final EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
    when(encryptedTransaction.getHash()).thenReturn(messageHash);
    when(encryptedTransaction.getPayload()).thenReturn(payload);
    when(encryptedTransactionDAO.retrieveByHash(eq(messageHash))).thenReturn(Optional.of(encryptedTransaction));
    byte[] expectedOutcome = "Encrypted payload".getBytes();
    when(enclave.unencryptTransaction(eq(payload), any(PublicKey.class))).thenReturn(expectedOutcome);
    PublicKey publicKey = mock(PublicKey.class);
    when(enclave.getPublicKeys()).thenReturn(Collections.singleton(publicKey));
    ReceiveResponse receiveResponse = transactionManager.receive(receiveRequest);
    assertThat(receiveResponse).isNotNull();
    assertThat(receiveResponse.getUnencryptedTransactionData()).isEqualTo(expectedOutcome);
    assertThat(receiveResponse.getExecHash()).isEqualTo("execHash".getBytes());
    assertThat(receiveResponse.getAffectedTransactions()).hasSize(1);
    assertThat(receiveResponse.sender()).isEqualTo(sender);
    verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
    verify(enclave, times(2)).unencryptTransaction(any(EncodedPayload.class), any(PublicKey.class));
    verify(enclave).getPublicKeys();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 65 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class TransactionManagerTest method getMandatoryRecipients.

@Test
public void getMandatoryRecipients() {
    MessageHash transactionHash = mock(MessageHash.class);
    final PublicKey senderKey = mock(PublicKey.class);
    final PublicKey recipientKey = mock(PublicKey.class);
    final EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
    final EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(senderKey, recipientKey));
    when(encodedPayload.getPrivacyMode()).thenReturn(PrivacyMode.MANDATORY_RECIPIENTS);
    when(encodedPayload.getMandatoryRecipients()).thenReturn(Set.of(recipientKey));
    when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
    when(encryptedTransactionDAO.retrieveByHash(transactionHash)).thenReturn(Optional.of(encryptedTransaction));
    final Set<PublicKey> participants = transactionManager.getMandatoryRecipients(transactionHash);
    assertThat(participants).containsExactly(recipientKey);
    verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Aggregations

PublicKey (com.quorum.tessera.encryption.PublicKey)281 Test (org.junit.Test)213 Response (jakarta.ws.rs.core.Response)59 MessageHash (com.quorum.tessera.data.MessageHash)57 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)48 Collectors (java.util.stream.Collectors)32 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)28 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)25 java.util (java.util)23 SendResponse (com.quorum.tessera.api.SendResponse)21 Nonce (com.quorum.tessera.encryption.Nonce)20 Recipient (com.quorum.tessera.partyinfo.node.Recipient)20 Operation (io.swagger.v3.oas.annotations.Operation)20 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)20 Stream (java.util.stream.Stream)19 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)18 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)17 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)17 URI (java.net.URI)17 SendRequest (com.quorum.tessera.api.SendRequest)15