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();
}
}
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);
}
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;
}
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();
}
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();
}
Aggregations