Search in sources :

Example 61 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class CustomPayloadEncryptionIT method payloadDecryptionFailsWithoutProperKeyAvailable.

@Test
public void payloadDecryptionFailsWithoutProperKeyAvailable() {
    final Party sender = partyHelper.findByAlias(NodeAlias.A);
    final Party recipient = partyHelper.findByAlias(NodeAlias.B);
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(Base64.getEncoder().encode("Test Payload".getBytes()));
    sendRequest.setTo(recipient.getPublicKey());
    final Response encryptResult = sender.getRestClientWebTarget().path("/encodedpayload/create").request().post(Entity.entity(sendRequest, mediaType));
    assertThat(encryptResult.getStatus()).isEqualTo(200);
    final PayloadEncryptResponse payloadEncryptResponse = encryptResult.readEntity(PayloadEncryptResponse.class);
    // purposefully remove the wrong box so it can't be decrypted
    // since the key that corresponds to the remaining box isn't on that node
    final String firstRecipientInList = Base64.getEncoder().encodeToString(payloadEncryptResponse.getRecipientKeys().get(0));
    if (Objects.equals(firstRecipientInList, sender.getPublicKey())) {
        payloadEncryptResponse.getRecipientBoxes().remove(1);
    } else {
        payloadEncryptResponse.getRecipientBoxes().remove(0);
    }
    payloadEncryptResponse.setRecipientKeys(Collections.emptyList());
    final Response decryptResultForRecipient = recipient.getRestClientWebTarget().path("/encodedpayload/decrypt").request().post(Entity.entity(payloadEncryptResponse, mediaType));
    assertThat(decryptResultForRecipient.getStatus()).isEqualTo(500);
}
Also used : PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Test(org.junit.Test)

Example 62 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class CustomPayloadEncryptionIT method createPayload.

@Test
public void createPayload() {
    final Party sender = partyHelper.findByAlias(NodeAlias.A);
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(Base64.getEncoder().encode("Test Payload".getBytes()));
    sendRequest.setTo(partyHelper.getParties().map(Party::getPublicKey).toArray(String[]::new));
    Response result = sender.getRestClientWebTarget().path("/encodedpayload/create").request().post(Entity.entity(sendRequest, mediaType));
    assertThat(result.getStatus()).isEqualTo(200);
    final PayloadEncryptResponse payloadEncryptResponse = result.readEntity(PayloadEncryptResponse.class);
    assertThat(Base64.getEncoder().encodeToString(payloadEncryptResponse.getSenderKey())).isEqualTo(sender.getPublicKey());
    assertThat(payloadEncryptResponse.getCipherText()).isNotEmpty();
    assertThat(payloadEncryptResponse.getCipherTextNonce()).isNotEmpty();
    assertThat(payloadEncryptResponse.getRecipientBoxes()).hasSize(4);
    assertThat(payloadEncryptResponse.getRecipientNonce()).isNotEmpty();
    assertThat(payloadEncryptResponse.getRecipientKeys()).hasSize(4).containsExactlyInAnyOrder(partyHelper.getParties().map(Party::getPublicKey).map(Base64.getDecoder()::decode).toArray(byte[][]::new));
    assertThat(payloadEncryptResponse.getPrivacyMode()).isEqualTo(0);
    assertThat(payloadEncryptResponse.getAffectedContractTransactions()).isEmpty();
    assertThat(payloadEncryptResponse.getExecHash()).isEmpty();
}
Also used : PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Test(org.junit.Test)

Example 63 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class ResendIndividualIT method resendTransactionForIncorrectKey.

@Test
public void resendTransactionForIncorrectKey() {
    final ResendRequest request = new ResendRequest();
    request.setType(RESEND_INDIVIDUAL_VALUE);
    request.setKey(this.hash);
    Party anyOtherParty = partyHelper.getParties().filter(p -> !p.equals(sender)).filter(p -> !p.equals(recipient)).findAny().get();
    request.setPublicKey(anyOtherParty.getPublicKey());
    final Response response = vanillaHttpOnlyClient.target(recipient.getP2PUri()).path(RESEND_PATH).request().post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE));
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(500);
    assertThat(response.readEntity(String.class)).contains("Recipient " + anyOtherParty.getPublicKey() + " is not a recipient of transaction");
}
Also used : Client(jakarta.ws.rs.client.Client) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PayloadEncoderImpl(com.quorum.tessera.enclave.PayloadEncoderImpl) Test(org.junit.Test) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) PartyHelper(com.quorum.tessera.test.PartyHelper) Entity(jakarta.ws.rs.client.Entity) Response(jakarta.ws.rs.core.Response) MediaType(jakarta.ws.rs.core.MediaType) Party(com.quorum.tessera.test.Party) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) Before(org.junit.Before) Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Aggregations

Party (com.quorum.tessera.test.Party)63 Response (jakarta.ws.rs.core.Response)60 Test (org.junit.Test)46 SendResponse (com.quorum.tessera.api.SendResponse)45 SendRequest (com.quorum.tessera.api.SendRequest)43 ReceiveResponse (com.quorum.tessera.api.ReceiveResponse)32 URI (java.net.URI)16 RestUtils (com.quorum.tessera.test.rest.RestUtils)11 JsonObject (jakarta.json.JsonObject)7 PartyHelper (com.quorum.tessera.test.PartyHelper)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 PayloadEncryptResponse (com.quorum.tessera.api.PayloadEncryptResponse)4 Entity (jakarta.ws.rs.client.Entity)4 StringReader (java.io.StringReader)4 ExecutionContext (suite.ExecutionContext)4 ServerConfig (com.quorum.tessera.config.ServerConfig)3 ConfigDescriptor (config.ConfigDescriptor)3 Json (jakarta.json.Json)3 Client (jakarta.ws.rs.client.Client)3 Before (org.junit.Before)3