Search in sources :

Example 16 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalAwsVaultKeyPair.

@Test
public void unmarshalAwsVaultKeyPair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    keyData.setAwsSecretsManagerPrivateKeyId("AwsSecretsManagerPrivateKeyId");
    keyData.setAwsSecretsManagerPublicKeyId("AwsSecretsManagerPublicKeyId");
    AWSKeyPair result = (AWSKeyPair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull();
    assertThat(result.getPrivateKeyId()).isEqualTo("AwsSecretsManagerPrivateKeyId");
    assertThat(result.getPublicKeyId()).isEqualTo("AwsSecretsManagerPublicKeyId");
    verifyZeroInteractions(keyEncryptor);
}
Also used : KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 17 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalInlineKeypair.

@Test
public void unmarshalInlineKeypair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    keyData.setPublicKey("PUBLICKEY");
    KeyDataConfig config = mock(KeyDataConfig.class);
    keyData.setConfig(config);
    InlineKeypair result = (InlineKeypair) KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull();
    assertThat(result.getPublicKey()).isEqualTo("PUBLICKEY");
    assertThat(result.getPrivateKeyConfig()).isSameAs(config);
    verifyZeroInteractions(keyEncryptor);
}
Also used : KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 18 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method unmarshalDirectKeyPair.

@Test
public void unmarshalDirectKeyPair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    KeyData keyData = new KeyData();
    keyData.setPublicKey("PUBLICKEY");
    keyData.setPrivateKey("PRIVATEKEY");
    ConfigKeyPair result = KeyDataUtil.unmarshal(keyData, keyEncryptor);
    assertThat(result).isNotNull().isExactlyInstanceOf(DirectKeyPair.class);
    assertThat(result.getPublicKey()).isEqualTo("PUBLICKEY");
    assertThat(result.getPrivateKey()).isEqualTo("PRIVATEKEY");
    verifyZeroInteractions(keyEncryptor);
}
Also used : KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 19 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class KeyDataUtilTest method marshalFilesystemKeyPair.

@Test
public void marshalFilesystemKeyPair() {
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    Path pubicKeyPath = mock(Path.class);
    Path privateKeyPath = mock(Path.class);
    FilesystemKeyPair keyPair = new FilesystemKeyPair(pubicKeyPath, privateKeyPath, keyEncryptor);
    KeyData result = KeyDataUtil.marshal(keyPair);
    assertThat(result.getPublicKeyPath()).isSameAs(pubicKeyPath);
    assertThat(result.getPrivateKeyPath()).isSameAs(privateKeyPath);
}
Also used : Path(java.nio.file.Path) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) KeyData(com.quorum.tessera.config.KeyData) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 20 with KeyEncryptor

use of com.quorum.tessera.config.keys.KeyEncryptor in project tessera by ConsenSys.

the class PeerToPeerIT method validatePartyInfoContentsOnNodeA.

/*
  Assume that not of the tests should have managed to change the initial party info
   */
private void validatePartyInfoContentsOnNodeA() {
    Party someParty = partyHelper.getParties().filter(p -> !p.getAlias().equals("A")).findAny().get();
    ServerConfig serverContext = someParty.getConfig().getP2PServerConfig();
    Client client = clientFactory.buildFrom(serverContext);
    Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().get();
    assertThat(response.getStatus()).isEqualTo(200);
    JsonObject result = response.readEntity(JsonObject.class);
    Map<String, String> actual = result.getJsonArray("keys").stream().map(o -> o.asJsonObject()).collect(Collectors.toMap(o -> o.getString("key"), o -> removeTrailingSlash(o.getString("url"))));
    EncryptorConfig encryptorConfig = partyHelper.getParties().findFirst().map(Party::getConfig).map(Config::getEncryptor).get();
    KeyEncryptor keyEncryptor = KeyEncryptorFactory.newFactory().create(encryptorConfig);
    List<String> keyz = partyHelper.getParties().map(Party::getConfig).map(Config::getKeys).flatMap(k -> k.getKeyData().stream()).map(kd -> KeyDataUtil.unmarshal(kd, keyEncryptor)).map(ConfigKeyPair::getPublicKey).collect(Collectors.toList());
    List<String> urls = partyHelper.getParties().map(Party::getConfig).map(Config::getP2PServerConfig).map(ServerConfig::getServerAddress).map(s -> removeTrailingSlash(s)).collect(Collectors.toList());
    assertThat(actual).containsKeys(keyz.toArray(new String[0]));
    assertThat(actual).containsValues(urls.toArray(new String[0]));
}
Also used : Response(jakarta.ws.rs.core.Response) 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) ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Config(com.quorum.tessera.config.Config) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) JsonObject(jakarta.json.JsonObject) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Client(jakarta.ws.rs.client.Client)

Aggregations

KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)20 Test (org.junit.Test)15 KeyData (com.quorum.tessera.config.KeyData)10 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)10 Path (java.nio.file.Path)5 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)4 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)4 CliResult (com.quorum.tessera.cli.CliResult)3 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)3 ConstraintViolationException (jakarta.validation.ConstraintViolationException)3 HashMap (java.util.HashMap)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 CliException (com.quorum.tessera.cli.CliException)2 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)2 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 EnvironmentVariableProvider (com.quorum.tessera.config.util.EnvironmentVariableProvider)2 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)2 Encryptor (com.quorum.tessera.encryption.Encryptor)2 PublicKey (com.quorum.tessera.encryption.PublicKey)2 Client (jakarta.ws.rs.client.Client)2