use of com.quorum.tessera.config.ServerConfig 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);
}
use of com.quorum.tessera.config.ServerConfig 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);
}
use of com.quorum.tessera.config.ServerConfig 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);
}
use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class Main method main.
public static void main(String... args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
final CommandLine commandLine = new CommandLine(new EnclaveCliAdapter());
commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
commandLine.execute(args);
final CliResult cliResult = commandLine.getExecutionResult();
if (cliResult == null) {
System.exit(1);
}
if (!cliResult.getConfig().isPresent()) {
System.exit(cliResult.getStatus());
}
final TesseraServerFactory restServerFactory = TesseraServerFactory.create(CommunicationType.REST);
final Config config = cliResult.getConfig().get();
ConfigFactory.create().store(config);
final ServerConfig serverConfig = config.getServerConfigs().stream().findFirst().get();
Enclave enclave = EnclaveServer.create();
LOGGER.debug("Created enclave {}", enclave);
final TesseraServer server = restServerFactory.createServer(serverConfig, Set.of(new EnclaveApplication(enclave)));
server.start();
CountDownLatch latch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
server.stop();
} catch (Exception ex) {
LOGGER.error(null, ex);
} finally {
}
}));
latch.await();
}
use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class EnclaveClientProviderTest method beforeTest.
@Before
public void beforeTest() {
configFactory = mock(ConfigFactory.class);
Config config = mock(Config.class);
ServerConfig serverConfig = mock(ServerConfig.class);
when(serverConfig.getApp()).thenReturn(appType);
when(serverConfig.getServerUri()).thenReturn(URI.create("someEnclaveServerUri"));
when(config.getServerConfigs()).thenReturn(List.of(serverConfig));
when(configFactory.getConfig()).thenReturn(config);
}
Aggregations