use of tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata in project web3signer by ConsenSys.
the class BlsArtifactSignerFactoryTest method emptyKeystorePasswordThrowsError.
@Test
void emptyKeystorePasswordThrowsError() throws IOException {
final Path emptyPasswordFile = configDir.resolve("emptyPassword");
Files.createFile(emptyPasswordFile);
final FileKeyStoreMetadata fileKeyStoreMetadata = new FileKeyStoreMetadata(keystoreFile, emptyPasswordFile, KeyType.BLS);
assertThatThrownBy(() -> artifactSignerFactory.create(fileKeyStoreMetadata)).isInstanceOf(SigningMetadataException.class).hasMessage("Keystore password cannot be empty: " + emptyPasswordFile);
}
use of tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata in project web3signer by ConsenSys.
the class BlsArtifactSignerFactoryTest method invalidKeystorePasswordThrowsError.
@Test
void invalidKeystorePasswordThrowsError() throws IOException {
final Path invalidPasswordFile = configDir.resolve("invalidPassword");
Files.writeString(invalidPasswordFile, "invalid_password");
final FileKeyStoreMetadata fileKeyStoreMetadata = new FileKeyStoreMetadata(keystoreFile, invalidPasswordFile, KeyType.BLS);
assertThatThrownBy(() -> artifactSignerFactory.create(fileKeyStoreMetadata)).isInstanceOf(SigningMetadataException.class).hasMessage("Failed to decrypt KeyStore, checksum validation failed.");
}
use of tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata in project web3signer by ConsenSys.
the class BlsArtifactSignerFactoryTest method nonExistentKeyStoreThrowsError.
@Test
void nonExistentKeyStoreThrowsError() {
final Path nonExistingKeystoreFile = configDir.resolve("someNonExistingKeystore");
final FileKeyStoreMetadata fileKeyStoreMetadata = new FileKeyStoreMetadata(nonExistingKeystoreFile, passwordFile, KeyType.BLS);
assertThatThrownBy(() -> artifactSignerFactory.create(fileKeyStoreMetadata)).isInstanceOf(SigningMetadataException.class).hasMessage("KeyStore file not found: " + nonExistingKeystoreFile);
}
use of tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata in project web3signer by ConsenSys.
the class KeystoreFileManager method findKeystoreConfigFiles.
private Optional<List<Path>> findKeystoreConfigFiles(final String pubkey) throws IOException {
// find keystore files and map them to their pubkeys
try (final Stream<Path> fileStream = Files.list(keystorePath)) {
Map<String, List<Path>> map = fileStream.filter(path -> FilenameUtils.getExtension(path.toString()).toLowerCase().endsWith("yaml")).map(path -> {
try {
final String fileContent = Files.readString(path, StandardCharsets.UTF_8);
final SigningMetadata metaDataInfo = YamlSignerParser.YAML_MAPPER.readValue(fileContent, SigningMetadata.class);
if (metaDataInfo.getKeyType() == KeyType.BLS && metaDataInfo instanceof FileKeyStoreMetadata) {
final FileKeyStoreMetadata info = ((FileKeyStoreMetadata) metaDataInfo);
final Path keystoreFile = info.getKeystoreFile();
final Path passwordFile = info.getKeystorePasswordFile();
final KeyStoreData keyStoreData = KeyStoreLoader.loadFromFile(keystoreFile);
final String decodedPubKey = IdentifierUtils.normaliseIdentifier(keyStoreData.getPubkey().appendHexTo(new StringBuilder()).toString());
return new AbstractMap.SimpleEntry<>(decodedPubKey, List.of(path, keystoreFile, passwordFile));
} else {
return null;
}
} catch (final Exception e) {
LOG.error("Error reading config file: {}", path, e);
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// return the matching file
return Optional.ofNullable(map.get(pubkey));
}
}
use of tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata in project web3signer by ConsenSys.
the class ImportKeystoresHandler method createKeyStoreYamlFileAt.
public void createKeyStoreYamlFileAt(final String fileName, final String jsonKeystoreData, final String password) throws IOException {
final Path yamlFile = keystorePath.resolve(fileName + ".yaml");
final String keystoreFileName = fileName + ".json";
final Path keystoreFile = yamlFile.getParent().resolve(keystoreFileName);
createTextFile(keystoreFile, jsonKeystoreData);
final String passwordFilename = fileName + ".password";
final Path passwordFile = yamlFile.getParent().resolve(passwordFilename);
createTextFile(passwordFile, password);
final FileKeyStoreMetadata data = new FileKeyStoreMetadata(keystoreFile, passwordFile, KeyType.BLS);
createYamlFile(yamlFile, data);
}
Aggregations