Search in sources :

Example 1 with PartyInfoParser

use of com.quorum.tessera.p2p.partyinfo.PartyInfoParser 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 2 with PartyInfoParser

use of com.quorum.tessera.p2p.partyinfo.PartyInfoParser in project tessera by ConsenSys.

the class PeerToPeerIT method maliciousNodeHasInvalidKey.

/*
  If the sending node has an invalid key, we 200 as the secondary key
  should not be validated.
   */
@Test
public void maliciousNodeHasInvalidKey() throws Exception {
    Party highjackedParty = partyHelper.findByAlias(NodeAlias.B);
    PublicKey bogusKey = PublicKey.from("BADKEY".getBytes());
    ServerConfig serverConfig = highjackedParty.getConfig().getP2PServerConfig();
    Recipient recipient = Recipient.of(bogusKey, serverConfig.getServerUri().toString());
    PartyInfo partyInfo = new PartyInfo(serverConfig.getServerUri().toString(), Collections.singleton(recipient), Collections.emptySet());
    Client client = 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(500);
}
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) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Client(jakarta.ws.rs.client.Client) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Test(org.junit.Test)

Example 3 with PartyInfoParser

use of com.quorum.tessera.p2p.partyinfo.PartyInfoParser 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 4 with PartyInfoParser

use of com.quorum.tessera.p2p.partyinfo.PartyInfoParser in project tessera by ConsenSys.

the class SyncPollerTest method init.

@Before
public void init() {
    this.executorService = mock(ExecutorService.class);
    this.resendPartyStore = mock(ResendPartyStore.class);
    this.transactionRequester = mock(TransactionRequester.class);
    this.partyInfoService = mock(Discovery.class);
    this.partyInfoParser = mock(PartyInfoParser.class);
    this.p2pClient = mock(P2pClient.class);
    doReturn(true).when(p2pClient).sendPartyInfo(anyString(), any());
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("myurl").build();
    when(partyInfoService.getCurrent()).thenReturn(nodeInfo);
    this.syncPoller = new SyncPoller(executorService, resendPartyStore, transactionRequester, partyInfoService, partyInfoParser, p2pClient);
}
Also used : P2pClient(com.quorum.tessera.partyinfo.P2pClient) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ExecutorService(java.util.concurrent.ExecutorService) Discovery(com.quorum.tessera.discovery.Discovery) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) Before(org.junit.Before)

Example 5 with PartyInfoParser

use of com.quorum.tessera.p2p.partyinfo.PartyInfoParser in project tessera by ConsenSys.

the class P2PRestApp method getSingletons.

@Override
public Set<Object> getSingletons() {
    RuntimeContext runtimeContext = RuntimeContext.getInstance();
    List<URI> peers = runtimeContext.getPeers();
    LOGGER.debug("Found configured peers {}", peers);
    peers.stream().map(NodeUri::create).map(NodeUri::asURI).peek(u -> LOGGER.debug("Adding {} to party store", u)).forEach(partyStore::store);
    final PartyInfoResource partyInfoResource = new PartyInfoResource(discovery, partyInfoParser, runtimeContext.getP2pClient(), enclave, runtimeContext.isRemoteKeyValidation());
    final IPWhitelistFilter iPWhitelistFilter = new IPWhitelistFilter();
    final TransactionResource transactionResource = new TransactionResource(transactionManager, batchResendManager, legacyResendManager);
    final UpCheckResource upCheckResource = new UpCheckResource();
    final PrivacyGroupResource privacyGroupResource = new PrivacyGroupResource(privacyGroupManager);
    if (runtimeContext.isRecoveryMode()) {
        final RecoveryResource recoveryResource = new RecoveryResource(transactionManager, batchResendManager);
        return Set.of(partyInfoResource, iPWhitelistFilter, recoveryResource, upCheckResource);
    }
    return Set.of(partyInfoResource, iPWhitelistFilter, transactionResource, privacyGroupResource, upCheckResource);
}
Also used : PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) AppType(com.quorum.tessera.config.AppType) Logger(org.slf4j.Logger) TransactionManager(com.quorum.tessera.transaction.TransactionManager) LoggerFactory(org.slf4j.LoggerFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) Set(java.util.Set) PrivacyGroupManager(com.quorum.tessera.privacygroup.PrivacyGroupManager) NodeUri(com.quorum.tessera.discovery.NodeUri) PartyStore(com.quorum.tessera.p2p.partyinfo.PartyStore) Objects(java.util.Objects) Discovery(com.quorum.tessera.discovery.Discovery) ApplicationPath(jakarta.ws.rs.ApplicationPath) List(java.util.List) Stream(java.util.stream.Stream) UpCheckResource(com.quorum.tessera.api.common.UpCheckResource) GlobalFilter(com.quorum.tessera.api.filter.GlobalFilter) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) LegacyResendManager(com.quorum.tessera.recovery.workflow.LegacyResendManager) Collectors.toSet(java.util.stream.Collectors.toSet) IPWhitelistFilter(com.quorum.tessera.api.filter.IPWhitelistFilter) TesseraRestApplication(com.quorum.tessera.app.TesseraRestApplication) UpCheckResource(com.quorum.tessera.api.common.UpCheckResource) IPWhitelistFilter(com.quorum.tessera.api.filter.IPWhitelistFilter) NodeUri(com.quorum.tessera.discovery.NodeUri) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI)

Aggregations

PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)7 Stream (java.util.stream.Stream)6 Before (org.junit.Before)6 Config (com.quorum.tessera.config.Config)5 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)5 ServerConfig (com.quorum.tessera.config.ServerConfig)5 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)5 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)5 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)5 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)5 PublicKey (com.quorum.tessera.encryption.PublicKey)5 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)5 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)5 Recipient (com.quorum.tessera.partyinfo.model.Recipient)5 JsonObject (jakarta.json.JsonObject)5 Client (jakarta.ws.rs.client.Client)5 Entity (jakarta.ws.rs.client.Entity)5 MediaType (jakarta.ws.rs.core.MediaType)5 Response (jakarta.ws.rs.core.Response)5 StreamingOutput (jakarta.ws.rs.core.StreamingOutput)5