Search in sources :

Example 1 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class PayloadPublisherProvider method provider.

public static PayloadPublisher provider() {
    Config config = ConfigFactory.create().getConfig();
    Discovery partyInfoService = Discovery.create();
    ClientFactory clientFactory = new ClientFactory();
    Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    return new RestPayloadPublisher(client, partyInfoService);
}
Also used : Config(com.quorum.tessera.config.Config) Discovery(com.quorum.tessera.discovery.Discovery) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Client(jakarta.ws.rs.client.Client)

Example 2 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class PrivacyGroupPublisherProvider method provider.

public static PrivacyGroupPublisher provider() {
    Discovery discovery = Discovery.create();
    Config config = ConfigFactory.create().getConfig();
    Client client = new ClientFactory().buildFrom(config.getP2PServerConfig());
    return new RestPrivacyGroupPublisher(discovery, client);
}
Also used : Config(com.quorum.tessera.config.Config) Discovery(com.quorum.tessera.discovery.Discovery) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Client(jakarta.ws.rs.client.Client)

Example 3 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class PeerToPeerIT method benevolentNodeBecomesPossessedAndSendsInvalidKeyInRecipientList.

/*
  A good node with valid key has a bad recipient in its party info
   */
@Test
public void benevolentNodeBecomesPossessedAndSendsInvalidKeyInRecipientList() throws Exception {
    Party partyB = partyHelper.findByAlias(NodeAlias.B);
    ServerConfig serverConfig = partyB.getConfig().getP2PServerConfig();
    PublicKey publicKey = Optional.of(partyB).map(Party::getPublicKey).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    Recipient itself = Recipient.of(publicKey, serverConfig.getServerUri().toString());
    String validButIncorrectUrl = partyHelper.findByAlias(NodeAlias.C).getConfig().getP2PServerConfig().getServerAddress();
    Recipient badRecipient = Recipient.of(PublicKey.from("OUCH".getBytes()), validButIncorrectUrl);
    Set<Recipient> recipients = Stream.of(itself, badRecipient).collect(Collectors.toSet());
    assertThat(recipients).containsExactlyInAnyOrder(itself, badRecipient);
    PartyInfo partyInfo = new PartyInfo(serverConfig.getServerUri().toString(), recipients, Collections.emptySet());
    Client client = new ClientFactory().buildFrom(serverConfig);
    PartyInfoParser partyInfoParser = PartyInfoParser.create();
    byte[] data = partyInfoParser.to(partyInfo);
    StreamingOutput output = out -> out.write(data);
    Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().post(Entity.entity(output, MediaType.APPLICATION_OCTET_STREAM));
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) PublicKey(com.quorum.tessera.encryption.PublicKey) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Example 4 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class PeerToPeerIT method benevolentNodeBecomesPosessedAndSendsInvalidUrlInRecipientList.

/*
  A good node with valid key has a bad recipient in its party info.
  The key is valid (node C's key) but there is a validation failure as
  the url cannot be called.
   */
@Test
public void benevolentNodeBecomesPosessedAndSendsInvalidUrlInRecipientList() throws Exception {
    Party partyB = partyHelper.findByAlias(NodeAlias.B);
    ServerConfig serverConfig = Optional.of(partyB.getConfig()).map(Config::getP2PServerConfig).get();
    PublicKey publicKey = Optional.of(partyB).map(Party::getPublicKey).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    Recipient itself = Recipient.of(publicKey, serverConfig.getServerUri().toString());
    String validKeyFromOtherNode = partyHelper.findByAlias(NodeAlias.C).getPublicKey();
    PublicKey validButIncorrectKey = Optional.of(validKeyFromOtherNode).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    Recipient badRecipient = Recipient.of(validButIncorrectKey, "http://bogus.supersnide.com:8829");
    Set<Recipient> recipients = Stream.of(itself, badRecipient).collect(Collectors.toSet());
    assertThat(recipients).containsExactlyInAnyOrder(itself, badRecipient);
    PartyInfo partyInfo = new PartyInfo(serverConfig.getServerUri().toString(), recipients, Collections.emptySet());
    Client client = new ClientFactory().buildFrom(serverConfig);
    PartyInfoParser partyInfoParser = PartyInfoParser.create();
    byte[] data = partyInfoParser.to(partyInfo);
    StreamingOutput output = out -> out.write(data);
    Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().post(Entity.entity(output, MediaType.APPLICATION_OCTET_STREAM));
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) PublicKey(com.quorum.tessera.encryption.PublicKey) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Example 5 with ClientFactory

use of com.quorum.tessera.jaxrs.client.ClientFactory in project tessera by ConsenSys.

the class EnclaveClientProvider method provider.

public static EnclaveClient provider() {
    Config config = ConfigFactory.create().getConfig();
    LOGGER.debug("Creating RestfulEnclaveClient with {}", config);
    Optional<ServerConfig> enclaveServerConfig = config.getServerConfigs().stream().filter(sc -> sc.getApp() == AppType.ENCLAVE).findAny();
    final ClientFactory clientFactory = new ClientFactory();
    LOGGER.debug("Creating server context from config");
    ServerConfig serverConfig = enclaveServerConfig.get();
    LOGGER.debug("Created server context from config");
    Client client = clientFactory.buildFrom(serverConfig);
    LOGGER.info("Creating remoted enclave for {}", serverConfig.getServerUri());
    return new RestfulEnclaveClient(client, serverConfig.getServerUri());
}
Also used : EnclaveClient(com.quorum.tessera.enclave.EnclaveClient) Client(jakarta.ws.rs.client.Client) Logger(org.slf4j.Logger) com.quorum.tessera.config(com.quorum.tessera.config) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) EnclaveClient(com.quorum.tessera.enclave.EnclaveClient) Client(jakarta.ws.rs.client.Client)

Aggregations

ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)10 Client (jakarta.ws.rs.client.Client)10 Config (com.quorum.tessera.config.Config)9 ServerConfig (com.quorum.tessera.config.ServerConfig)6 Response (jakarta.ws.rs.core.Response)4 Test (org.junit.Test)4 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)3 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)3 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)3 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)3 PublicKey (com.quorum.tessera.encryption.PublicKey)3 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)3 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)3 Recipient (com.quorum.tessera.partyinfo.model.Recipient)3 ClientSSLContextFactory (com.quorum.tessera.ssl.context.ClientSSLContextFactory)3 SSLContextFactory (com.quorum.tessera.ssl.context.SSLContextFactory)3 JsonObject (jakarta.json.JsonObject)3 Entity (jakarta.ws.rs.client.Entity)3 MediaType (jakarta.ws.rs.core.MediaType)3