Search in sources :

Example 1 with MessageHash

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

the class RawTransactionResourceTest method store.

@Test
public void store() {
    com.quorum.tessera.transaction.StoreRawResponse response = mock(com.quorum.tessera.transaction.StoreRawResponse.class);
    MessageHash transactionHash = mock(MessageHash.class);
    when(transactionHash.getHashBytes()).thenReturn("TXN".getBytes());
    when(response.getHash()).thenReturn(transactionHash);
    when(transactionManager.store(any())).thenReturn(response);
    final StoreRawRequest storeRawRequest = new StoreRawRequest();
    storeRawRequest.setPayload("PAYLOAD".getBytes());
    storeRawRequest.setFrom("Sender".getBytes());
    final Response result = transactionResource.store(storeRawRequest);
    assertThat(result.getStatus()).isEqualTo(200);
    verify(transactionManager).store(any());
}
Also used : Response(jakarta.ws.rs.core.Response) StoreRawRequest(com.quorum.tessera.api.StoreRawRequest) MessageHash(com.quorum.tessera.data.MessageHash) Test(org.junit.Test)

Example 2 with MessageHash

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

the class RawTransactionResourceTest method storeVersion21.

@Test
public void storeVersion21() {
    com.quorum.tessera.transaction.StoreRawResponse response = mock(com.quorum.tessera.transaction.StoreRawResponse.class);
    MessageHash transactionHash = mock(MessageHash.class);
    when(transactionHash.getHashBytes()).thenReturn("TXN".getBytes());
    when(response.getHash()).thenReturn(transactionHash);
    when(transactionManager.store(any())).thenReturn(response);
    final StoreRawRequest storeRawRequest = new StoreRawRequest();
    storeRawRequest.setPayload("PAYLOAD".getBytes());
    storeRawRequest.setFrom("Sender".getBytes());
    final Response result = transactionResource.storeVersion21(storeRawRequest);
    assertThat(result.getStatus()).isEqualTo(200);
    verify(transactionManager).store(any());
}
Also used : Response(jakarta.ws.rs.core.Response) StoreRawRequest(com.quorum.tessera.api.StoreRawRequest) MessageHash(com.quorum.tessera.data.MessageHash) Test(org.junit.Test)

Example 3 with MessageHash

use of com.quorum.tessera.data.MessageHash 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 4 with MessageHash

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

the class BesuTransactionResource method receive.

@Operation(summary = "/receive", operationId = "getDecryptedPayloadJson", description = "get payload from database, decrypt, and return. This endpoint is only to be used by Besu")
@ApiResponse(responseCode = "200", description = "decrypted payload", content = { @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = BesuReceiveResponse.class)), @Content(mediaType = ORION, schema = @Schema(implementation = BesuReceiveResponse.class)) })
@POST
@Path("/receive")
@Consumes({ APPLICATION_JSON, ORION })
@Produces(APPLICATION_JSON)
public Response receive(@Valid final ReceiveRequest request) {
    LOGGER.debug("Received receive request");
    MessageHash transactionHash = Optional.of(request).map(ReceiveRequest::getKey).map(base64Decoder::decode).map(MessageHash::new).get();
    PublicKey recipient = Optional.of(request).map(ReceiveRequest::getTo).filter(Predicate.not(String::isEmpty)).filter(Objects::nonNull).map(base64Decoder::decode).map(PublicKey::from).orElse(null);
    com.quorum.tessera.transaction.ReceiveRequest receiveRequest = com.quorum.tessera.transaction.ReceiveRequest.Builder.create().withTransactionHash(transactionHash).withRecipient(recipient).withRaw(request.isRaw()).build();
    com.quorum.tessera.transaction.ReceiveResponse response = transactionManager.receive(receiveRequest);
    BesuReceiveResponse receiveResponse = new BesuReceiveResponse();
    receiveResponse.setPayload(response.getUnencryptedTransactionData());
    receiveResponse.setSenderKey(response.sender().encodeToBase64());
    response.getPrivacyGroupId().map(PrivacyGroup.Id::getBase64).ifPresent(receiveResponse::setPrivacyGroupId);
    return Response.status(Response.Status.OK).type(APPLICATION_JSON).entity(receiveResponse).build();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) MessageHash(com.quorum.tessera.data.MessageHash) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 5 with MessageHash

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

the class EncodedPayloadResource method createEncodedPayload.

// hide this operation from swagger generation; the /encodedpayload/create operation is overloaded
// and must be documented in a single place
@Hidden
@POST
@Path("create")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response createEncodedPayload(@NotNull @Valid final SendRequest sendRequest) {
    LOGGER.info("Received request for custom payload encryption");
    final PublicKey sender = Optional.ofNullable(sendRequest.getFrom()).map(base64Decoder::decode).map(PublicKey::from).orElseGet(transactionManager::defaultPublicKey);
    final List<PublicKey> recipientList = Stream.of(sendRequest).filter(sr -> Objects.nonNull(sr.getTo())).flatMap(s -> Stream.of(s.getTo())).map(base64Decoder::decode).map(PublicKey::from).collect(Collectors.toList());
    final Set<MessageHash> affectedTransactions = Stream.ofNullable(sendRequest.getAffectedContractTransactions()).flatMap(Arrays::stream).map(Base64.getDecoder()::decode).map(MessageHash::new).collect(Collectors.toSet());
    final byte[] execHash = Optional.ofNullable(sendRequest.getExecHash()).map(String::getBytes).orElse(new byte[0]);
    final com.quorum.tessera.transaction.SendRequest request = com.quorum.tessera.transaction.SendRequest.Builder.create().withRecipients(recipientList).withSender(sender).withPayload(sendRequest.getPayload()).withExecHash(execHash).withPrivacyMode(PrivacyMode.fromFlag(sendRequest.getPrivacyFlag())).withAffectedContractTransactions(affectedTransactions).build();
    final EncodedPayload encodedPayload = encodedPayloadManager.create(request);
    final Map<String, String> affectedContractTransactionMap = encodedPayload.getAffectedContractTransactions().entrySet().stream().collect(Collectors.toMap(e -> e.getKey().encodeToBase64(), e -> Base64.getEncoder().encodeToString(e.getValue().getData())));
    final PayloadEncryptResponse response = new PayloadEncryptResponse();
    response.setSenderKey(encodedPayload.getSenderKey().getKeyBytes());
    response.setCipherText(encodedPayload.getCipherText());
    response.setCipherTextNonce(encodedPayload.getCipherTextNonce().getNonceBytes());
    response.setRecipientBoxes(encodedPayload.getRecipientBoxes().stream().map(RecipientBox::getData).collect(Collectors.toList()));
    response.setRecipientNonce(encodedPayload.getRecipientNonce().getNonceBytes());
    response.setRecipientKeys(encodedPayload.getRecipientKeys().stream().map(PublicKey::getKeyBytes).collect(Collectors.toList()));
    response.setPrivacyMode(encodedPayload.getPrivacyMode().getPrivacyFlag());
    response.setAffectedContractTransactions(affectedContractTransactionMap);
    response.setExecHash(encodedPayload.getExecHash());
    return Response.ok(response).type(APPLICATION_JSON).build();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) LoggerFactory(org.slf4j.LoggerFactory) Valid(jakarta.validation.Valid) NotNull(jakarta.validation.constraints.NotNull) RecipientBox(com.quorum.tessera.enclave.RecipientBox) Path(jakarta.ws.rs.Path) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) MIME_TYPE_JSON_2_1(com.quorum.tessera.version.MultiTenancyVersion.MIME_TYPE_JSON_2_1) Produces(jakarta.ws.rs.Produces) MessageHash(com.quorum.tessera.data.MessageHash) Schema(io.swagger.v3.oas.annotations.media.Schema) Consumes(jakarta.ws.rs.Consumes) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Logger(org.slf4j.Logger) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) Hidden(io.swagger.v3.oas.annotations.Hidden) POST(jakarta.ws.rs.POST) TransactionManager(com.quorum.tessera.transaction.TransactionManager) Collectors(java.util.stream.Collectors) PayloadDecryptRequest(com.quorum.tessera.api.PayloadDecryptRequest) SendRequest(com.quorum.tessera.api.SendRequest) EncodedPayloadManager(com.quorum.tessera.transaction.EncodedPayloadManager) Stream(java.util.stream.Stream) Tag(io.swagger.v3.oas.annotations.tags.Tag) APPLICATION_JSON(jakarta.ws.rs.core.MediaType.APPLICATION_JSON) TxHash(com.quorum.tessera.enclave.TxHash) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) RecipientBox(com.quorum.tessera.enclave.RecipientBox) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Hidden(io.swagger.v3.oas.annotations.Hidden)

Aggregations

MessageHash (com.quorum.tessera.data.MessageHash)81 PublicKey (com.quorum.tessera.encryption.PublicKey)56 Test (org.junit.Test)51 Response (jakarta.ws.rs.core.Response)44 Operation (io.swagger.v3.oas.annotations.Operation)21 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)21 SendResponse (com.quorum.tessera.api.SendResponse)17 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)16 SendRequest (com.quorum.tessera.api.SendRequest)15 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)15 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)15 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)13 java.util (java.util)13 Collectors (java.util.stream.Collectors)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)12 TransactionManager (com.quorum.tessera.transaction.TransactionManager)12 Tag (io.swagger.v3.oas.annotations.tags.Tag)11 Valid (jakarta.validation.Valid)11