Search in sources :

Example 56 with PublicKey

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

the class KeyResourceTest method testGetPublicKeys.

@Test
public void testGetPublicKeys() {
    try (var mockedStaticRuntimeContext = mockStatic(RuntimeContext.class)) {
        mockedStaticRuntimeContext.when(RuntimeContext::getInstance).thenReturn(runtimeContext);
        Base64.Decoder base64Decoder = Base64.getDecoder();
        final String keyJsonString = "{\"keys\": [{\"key\": \"QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=\"}]}";
        String key = "QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=";
        Set<PublicKey> publicKeys = new HashSet<>();
        publicKeys.add(PublicKey.from(base64Decoder.decode(key)));
        when(runtimeContext.getPublicKeys()).thenReturn(publicKeys);
        Response response = keyResource.getPublicKeys();
        assertThat(response).isNotNull();
        assertThat(response.getStatus()).isEqualTo(200);
        final String output = response.getEntity().toString();
        final JsonReader expected = Json.createReader(new StringReader(keyJsonString));
        final JsonReader actual = Json.createReader(new StringReader(output));
        assertThat(expected.readObject()).isEqualTo(actual.readObject());
        verify(runtimeContext).getPublicKeys();
        mockedStaticRuntimeContext.verify(RuntimeContext::getInstance);
        mockedStaticRuntimeContext.verifyNoMoreInteractions();
    }
}
Also used : Response(jakarta.ws.rs.core.Response) Base64(java.util.Base64) PublicKey(com.quorum.tessera.encryption.PublicKey) StringReader(java.io.StringReader) JsonReader(jakarta.json.JsonReader) RuntimeContext(com.quorum.tessera.context.RuntimeContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with PublicKey

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

the class AutoDiscovery method onUpdate.

@Override
public void onUpdate(final NodeInfo nodeInfo) {
    LOGGER.debug("Processing node info {}", nodeInfo);
    final NodeUri callerNodeUri = NodeUri.create(nodeInfo.getUrl());
    LOGGER.debug("Update node {}", callerNodeUri);
    final Set<PublicKey> keys = nodeInfo.getRecipients().stream().filter(r -> NodeUri.create(r.getUrl()).equals(callerNodeUri)).map(Recipient::getKey).collect(Collectors.toSet());
    final ActiveNode activeNode = ActiveNode.Builder.create().withUri(callerNodeUri).withKeys(keys).withSupportedVersions(nodeInfo.supportedApiVersions()).build();
    networkStore.store(activeNode);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode)

Example 58 with PublicKey

use of com.quorum.tessera.encryption.PublicKey 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 59 with PublicKey

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

the class PartyInfoServiceUtilTest method validateSameRecipientListsAsValid.

@Test
public void validateSameRecipientListsAsValid() {
    final String url = "http://somedomain.com";
    final PublicKey key = PublicKey.from("ONE".getBytes());
    final Set<Recipient> existingRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
    final NodeInfo existingPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(existingRecipients).build();
    final Set<Recipient> newRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
    final NodeInfo newPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(newRecipients).build();
    assertThat(PartyInfoServiceUtil.validateKeysToUrls(existingPartyInfo, newPartyInfo)).isTrue();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Example 60 with PublicKey

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

the class PartyInfoServiceUtilTest method validateAttemptToChangeUrlAsInvalid.

@Test
public void validateAttemptToChangeUrlAsInvalid() {
    final String url = "http://somedomain.com";
    final PublicKey key = PublicKey.from("ONE".getBytes());
    final Set<Recipient> existingRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
    final NodeInfo existingPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(existingRecipients).build();
    final Set<Recipient> newRecipients = Collections.singleton(Recipient.of(key, "http://two.com"));
    final NodeInfo newPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(newRecipients).build();
    assertThat(PartyInfoServiceUtil.validateKeysToUrls(existingPartyInfo, newPartyInfo)).isFalse();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) 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