Search in sources :

Example 51 with PublicKey

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

the class DisabledAutoDiscoveryTest method onUpdateNodeSendsNewKey.

@Test
public void onUpdateNodeSendsNewKey() {
    String url = knownPeers.iterator().next().asString();
    PublicKey key = mock(PublicKey.class);
    List<Recipient> recipients = List.of(Recipient.of(key, url));
    List<ActiveNode> storedNodes = new ArrayList<>();
    doAnswer(invocation -> {
        storedNodes.add(invocation.getArgument(0));
        return null;
    }).when(networkStore).store(any(ActiveNode.class));
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(recipients).build();
    discovery.onUpdate(nodeInfo);
    assertThat(storedNodes).hasSize(1);
    ActiveNode savedNode = storedNodes.get(0);
    assertThat(savedNode.getKeys()).containsExactly(key);
    assertThat(savedNode.getUri()).isEqualTo(NodeUri.create(url));
    verify(networkStore).store(any(ActiveNode.class));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 52 with PublicKey

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

the class DiscoveryHelperTest method onCreate.

@Test
public void onCreate() {
    URI uri = URI.create("http://somedomain.com/");
    when(runtimeContext.getPeers()).thenReturn(List.of(uri));
    when(runtimeContext.getP2pServerUri()).thenReturn(uri);
    PublicKey publicKey = mock(PublicKey.class);
    when(enclave.getPublicKeys()).thenReturn(Set.of(publicKey));
    discoveryHelper.onCreate();
    verify(networkStore).store(any(ActiveNode.class));
    verify(runtimeContext).getP2pServerUri();
    verify(enclave).getPublicKeys();
    mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 53 with PublicKey

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

the class DiscoveryHelperTest method buildCurrent.

@Test
public void buildCurrent() {
    final URI uri = URI.create("http://somedomain.com");
    when(runtimeContext.getP2pServerUri()).thenReturn(uri);
    final List<PublicKey> keys = IntStream.range(0, 5).mapToObj(i -> mock(PublicKey.class)).collect(Collectors.toList());
    final ActiveNode activeNode = ActiveNode.Builder.create().withUri(NodeUri.create(uri)).withKeys(keys).build();
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
    NodeInfo result = discoveryHelper.buildCurrent();
    assertThat(result).isNotNull();
    assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
    assertThat(result.getRecipients()).hasSize(5);
    List<Recipient> recipients = List.copyOf(result.getRecipients());
    assertThat(recipients.stream().map(Recipient::getKey).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(keys);
    verify(networkStore).getActiveNodes();
    verify(runtimeContext).getP2pServerUri();
    mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Mockito(org.mockito.Mockito) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Stream(java.util.stream.Stream) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) After(org.junit.After) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) Before(org.junit.Before) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 54 with PublicKey

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

the class DiscoveryHelperTest method buildRemoteNodeInfo.

@Test
public void buildRemoteNodeInfo() {
    String url = "http://nodeurl.com/";
    final PublicKey key = PublicKey.from("key".getBytes());
    final PublicKey anotherKey = PublicKey.from("anotherKey".getBytes());
    final Recipient recipient = Recipient.of(key, url);
    final Recipient sameNodeDifferentKey = Recipient.of(anotherKey, url);
    ActiveNode activeNode = mock(ActiveNode.class);
    when(activeNode.getUri()).thenReturn(NodeUri.create(url));
    when(activeNode.getKeys()).thenReturn(Set.of(key, anotherKey));
    when(activeNode.getSupportedVersions()).thenReturn(Set.of("v1", "v2"));
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
    final NodeInfo result = discoveryHelper.buildRemoteNodeInfo(key);
    assertThat(result).isNotNull();
    assertThat(result.getUrl()).isEqualTo(url);
    assertThat(result.getRecipients()).containsExactlyInAnyOrder(recipient, sameNodeDifferentKey);
    assertThat(result.supportedApiVersions()).containsExactlyInAnyOrder("v1", "v2");
    verify(networkStore).getActiveNodes();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 55 with PublicKey

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

the class KeyResource method getPublicKeys.

@GET
@Operation(summary = "/keys", description = "get all public keys managed by the server's enclave")
@ApiResponse(responseCode = "200", description = "server's public keys", content = @Content(schema = @Schema(implementation = GetPublicKeysResponse.class)))
public Response getPublicKeys() {
    RuntimeContext runtimeContext = RuntimeContext.getInstance();
    Set<PublicKey> publicKeys = runtimeContext.getPublicKeys();
    final JsonArrayBuilder keyBuilder = Json.createArrayBuilder();
    publicKeys.stream().map(key -> Json.createObjectBuilder().add("key", key.encodeToBase64()).build()).forEach(keyBuilder::add);
    final String output = Json.createObjectBuilder().add("keys", keyBuilder.build()).build().toString();
    return Response.status(Response.Status.OK).entity(output).build();
}
Also used : Schema(io.swagger.v3.oas.annotations.media.Schema) Consumes(jakarta.ws.rs.Consumes) PublicKey(com.quorum.tessera.encryption.PublicKey) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) Set(java.util.Set) GET(jakarta.ws.rs.GET) Json(jakarta.json.Json) 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) MediaType(jakarta.ws.rs.core.MediaType) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Tag(io.swagger.v3.oas.annotations.tags.Tag) RuntimeContext(com.quorum.tessera.context.RuntimeContext) GetPublicKeysResponse(com.quorum.tessera.thirdparty.model.GetPublicKeysResponse) Produces(jakarta.ws.rs.Produces) PublicKey(com.quorum.tessera.encryption.PublicKey) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) RuntimeContext(com.quorum.tessera.context.RuntimeContext) GET(jakarta.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

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