Search in sources :

Example 1 with KeyNotFoundException

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

the class KeyNotFoundExceptionMapperTest method toResponse.

@Test
public void toResponse() {
    final KeyNotFoundException keyNotFoundException = new KeyNotFoundException("OUCH");
    final Response result = instance.toResponse(keyNotFoundException);
    assertThat(result).isNotNull();
    final String message = (String) result.getEntity();
    assertThat(message).isEqualTo("OUCH");
    assertThat(result.getStatus()).isEqualTo(404);
}
Also used : Response(jakarta.ws.rs.core.Response) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) Test(org.junit.Test)

Example 2 with KeyNotFoundException

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

the class DiscoveryHelperImpl method buildRemoteNodeInfo.

@Override
public NodeInfo buildRemoteNodeInfo(PublicKey recipientKey) {
    final ActiveNode activeNode = networkStore.getActiveNodes().filter(node -> node.getKeys().contains(recipientKey)).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
    final String nodeUrl = activeNode.getUri().asString();
    final Set<Recipient> recipients = activeNode.getKeys().stream().map(k -> Recipient.of(k, nodeUrl)).collect(Collectors.toSet());
    final NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(nodeUrl).withRecipients(recipients).withSupportedApiVersions(activeNode.getSupportedVersions()).build();
    return nodeInfo;
}
Also used : KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) Logger(org.slf4j.Logger) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ApiVersion(com.quorum.tessera.version.ApiVersion) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) Optional(java.util.Optional) URI(java.net.URI) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException)

Example 3 with KeyNotFoundException

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

the class FindRecipientFromPartyInfoTest method executeKeyNotFound.

@Test
public void executeKeyNotFound() {
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    PublicKey publicKey = mock(PublicKey.class);
    batchWorkflowContext.setRecipientKey(publicKey);
    NodeInfo nodeInfo = mock(NodeInfo.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getKey()).thenReturn(mock(PublicKey.class));
    when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    try {
        findRecipientFromPartyInfo.execute(batchWorkflowContext);
        failBecauseExceptionWasNotThrown(KeyNotFoundException.class);
    } catch (KeyNotFoundException ex) {
        verify(discovery).getCurrent();
        assertThat(batchWorkflowContext.getRecipient()).isNull();
        assertThat(batchWorkflowContext.getRecipientKey()).isSameAs(publicKey);
    }
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) Test(org.junit.Test)

Example 4 with KeyNotFoundException

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

the class FindRecipientFromPartyInfo method execute.

@Override
public boolean execute(BatchWorkflowContext event) {
    PublicKey recipientKey = event.getRecipientKey();
    final Recipient retrievedRecipientFromStore = discovery.getCurrent().getRecipients().stream().filter(recipient -> recipientKey.equals(recipient.getKey())).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
    event.setRecipient(retrievedRecipientFromStore);
    return true;
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.node.Recipient) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException)

Aggregations

KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)4 PublicKey (com.quorum.tessera.encryption.PublicKey)3 Recipient (com.quorum.tessera.partyinfo.node.Recipient)3 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)2 Test (org.junit.Test)2 RuntimeContext (com.quorum.tessera.context.RuntimeContext)1 ActiveNode (com.quorum.tessera.discovery.ActiveNode)1 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)1 NetworkStore (com.quorum.tessera.discovery.NetworkStore)1 NodeUri (com.quorum.tessera.discovery.NodeUri)1 Enclave (com.quorum.tessera.enclave.Enclave)1 ApiVersion (com.quorum.tessera.version.ApiVersion)1 Response (jakarta.ws.rs.core.Response)1 URI (java.net.URI)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1