use of com.quorum.tessera.config.keypairs.ConfigKeyPair in project tessera by ConsenSys.
the class KeyGenCommandTest method updateNoOutputFileDefined.
@Test
public void updateNoOutputFileDefined() {
String filename = "";
ConfigKeyPair configKeyPair = mock(ConfigKeyPair.class);
when(keyGenerator.generate(filename, null, null)).thenReturn(configKeyPair);
when(keyGeneratorFactory.create(refEq(null), any(EncryptorConfig.class))).thenReturn(keyGenerator);
Config config = mock(Config.class);
KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
KeyData keyData = mock(KeyData.class);
when(keyDataMarshaller.marshal(configKeyPair)).thenReturn(keyData);
when(config.getKeys()).thenReturn(keyConfiguration);
commandLine.registerConverter(Config.class, value -> config);
int exitCode = commandLine.execute("--configfile=".concat(filename), "--vault.type=".concat(KeyVaultType.AZURE.name()));
assertThat(exitCode).isZero();
verify(keyGeneratorFactory).create(refEq(null), any(EncryptorConfig.class));
verify(keyGenerator).generate(filename, null, null);
verify(configFileUpdaterWriter).updateAndWriteToCLI(List.of(keyData), null, config);
verify(keyDataMarshaller).marshal(configKeyPair);
}
use of com.quorum.tessera.config.keypairs.ConfigKeyPair in project tessera by ConsenSys.
the class KeyGenCommandTest method onlyMulipleOutputFilesProvided.
@Test
public void onlyMulipleOutputFilesProvided() throws Exception {
List<String> optionVariations = List.of("--keyout", "-filename");
List<String> valueVariations = List.of("myfile", "myotherfile", "yetanother");
ConfigKeyPair configKeyPair = mock(ConfigKeyPair.class);
valueVariations.forEach(filename -> {
when(keyGenerator.generate(filename, null, null)).thenReturn(configKeyPair);
});
when(keyGeneratorFactory.create(refEq(null), any(EncryptorConfig.class))).thenReturn(keyGenerator);
for (String option : optionVariations) {
String arg = option.concat("=").concat(String.join(",", valueVariations));
int exitCode = commandLine.execute(arg);
assertThat(exitCode).isZero();
CommandLine.ParseResult parseResult = commandLine.getParseResult();
assertThat(parseResult).isNotNull();
assertThat(parseResult.matchedArgs()).hasSize(1);
assertThat(parseResult.hasMatchedOption(option));
assertThat(parseResult.unmatched()).isEmpty();
CliResult result = commandLine.getExecutionResult();
assertThat(result).isNotNull();
assertThat(result.isSuppressStartup()).isTrue();
assertThat(result.getConfig()).isNotPresent();
}
verify(keyDataMarshaller, times(optionVariations.size() * valueVariations.size())).marshal(configKeyPair);
verify(keyGeneratorFactory, times(optionVariations.size())).create(refEq(null), any(EncryptorConfig.class));
valueVariations.forEach(filename -> {
verify(keyGenerator, times(optionVariations.size())).generate(filename, null, null);
});
}
use of com.quorum.tessera.config.keypairs.ConfigKeyPair in project tessera by ConsenSys.
the class KeyGenCommandTest method vaultUrlProvidedOnCommandLine.
@Test
public void vaultUrlProvidedOnCommandLine() {
ConfigKeyPair configKeyPair = mock(ConfigKeyPair.class);
when(keyGenerator.generate("", null, null)).thenReturn(configKeyPair);
when(keyGeneratorFactory.create(any(AzureKeyVaultConfig.class), any(EncryptorConfig.class))).thenReturn(keyGenerator);
int outcome = commandLine.execute("--vault.type=AZURE", "--vault.url=someurl");
assertThat(outcome).isZero();
executionExceptionHandler.getExceptions().forEach(Throwable::printStackTrace);
assertThat(executionExceptionHandler.getExceptions()).isEmpty();
verify(keyGenerator).generate("", null, null);
verify(keyGeneratorFactory).create(any(AzureKeyVaultConfig.class), any(EncryptorConfig.class));
verify(keyDataMarshaller).marshal(configKeyPair);
}
use of com.quorum.tessera.config.keypairs.ConfigKeyPair in project tessera by ConsenSys.
the class CliKeyPasswordResolver method getSingleKeyPassword.
protected void getSingleKeyPassword(final int keyNumber, final KeyData keyPair, final KeyEncryptor keyEncryptor) {
final boolean isInline = KeyDataUtil.isInline(keyPair);
final boolean isFilesystem = KeyDataUtil.isFileSystem(keyPair);
if (!isInline && !isFilesystem) {
// some other key type that doesn't use passwords, skip
return;
}
final boolean isLocked = KeyDataUtil.isLocked(keyPair);
if (isLocked) {
ConfigKeyPair configKeyPair = KeyDataUtil.unmarshal(keyPair, keyEncryptor);
int currentAttemptNumber = MAX_PASSWORD_ATTEMPTS;
while (currentAttemptNumber > 0) {
if (Objects.isNull(configKeyPair.getPassword()) || configKeyPair.getPassword().length == 0 || Optional.ofNullable(configKeyPair.getPrivateKey()).filter(s -> s.contains("NACL_FAILURE")).isPresent()) {
final String attemptOutput = "Attempt " + (MAX_PASSWORD_ATTEMPTS - currentAttemptNumber + 1) + " of " + MAX_PASSWORD_ATTEMPTS + ".";
System.out.printf("Password for key[%s] missing or invalid.", keyNumber);
System.out.println();
System.out.printf("%s Enter a password for the key", attemptOutput);
System.out.println();
final char[] pass = passwordReader.readPasswordFromConsole();
configKeyPair.withPassword(pass);
keyPair.setPassword(pass);
}
currentAttemptNumber--;
}
}
}
use of com.quorum.tessera.config.keypairs.ConfigKeyPair in project tessera by ConsenSys.
the class SendIT method senderAndRecipientOnSameNode.
@Test
public void senderAndRecipientOnSameNode() throws UnsupportedEncodingException {
// Node C has 2 keys, use them both
final String[] recipientPublicKeys = ExecutionContext.currentContext().getConfigs().stream().filter(c -> c.getAlias() == NodeAlias.C).findFirst().map(ConfigDescriptor::getAllKeys).get().stream().map(ConfigKeyPair::getPublicKey).toArray(String[]::new);
final Party party = partyHelper.findByAlias(NodeAlias.C);
final byte[] transactionData = utils.createTransactionData();
final SendRequest sendRequest = new SendRequest();
sendRequest.setFrom(recipientPublicKeys[0]);
sendRequest.setTo(recipientPublicKeys[1]);
sendRequest.setPayload(transactionData);
final Response response = party.getRestClient().target(party.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
final SendResponse result = response.readEntity(SendResponse.class);
assertThat(result.getKey()).isNotNull().isNotBlank();
assertThat(result.getManagedParties()).containsExactlyInAnyOrder(recipientPublicKeys);
assertThat(result.getSenderKey()).isEqualTo(recipientPublicKeys[0]);
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(201);
URI location = response.getLocation();
{
final Response checkPersistedTxnResponse = party.getRestClient().target(location).request().accept(MIME_TYPE_JSON_2_1).get();
assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
assertThat(receiveResponse.getManagedParties()).containsExactlyInAnyOrder(recipientPublicKeys);
}
{
String encodedId = URLEncoder.encode(result.getKey(), StandardCharsets.UTF_8.toString());
Stream.of(party).map(Party::getRestClientWebTarget).map(target -> target.path("transaction")).map(target -> target.path(encodedId)).map(target -> target.request().accept(MIME_TYPE_JSON_2_1).get()).forEach(r -> {
assertThat(r.getStatus()).isEqualTo(200);
ReceiveResponse receiveResponse = r.readEntity(ReceiveResponse.class);
assertThat(receiveResponse.getManagedParties()).containsExactlyInAnyOrder(recipientPublicKeys);
assertThat(receiveResponse.getSenderKey()).isEqualTo(recipientPublicKeys[0]);
});
}
}
Aggregations