Search in sources :

Example 1 with FileKeyStoreMetadata

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);
}
Also used : Path(java.nio.file.Path) SigningMetadataException(tech.pegasys.web3signer.core.multikey.metadata.SigningMetadataException) FileKeyStoreMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata) Test(org.junit.jupiter.api.Test)

Example 2 with FileKeyStoreMetadata

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.");
}
Also used : Path(java.nio.file.Path) SigningMetadataException(tech.pegasys.web3signer.core.multikey.metadata.SigningMetadataException) FileKeyStoreMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata) Test(org.junit.jupiter.api.Test)

Example 3 with FileKeyStoreMetadata

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);
}
Also used : Path(java.nio.file.Path) SigningMetadataException(tech.pegasys.web3signer.core.multikey.metadata.SigningMetadataException) FileKeyStoreMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata) Test(org.junit.jupiter.api.Test)

Example 4 with FileKeyStoreMetadata

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));
    }
}
Also used : Path(java.nio.file.Path) FileKeyStoreMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata) KeyStoreLoader(tech.pegasys.signers.bls.keystore.KeyStoreLoader) Files(java.nio.file.Files) IOException(java.io.IOException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) Collectors(java.util.stream.Collectors) YamlSignerParser(tech.pegasys.web3signer.core.multikey.metadata.parser.YamlSignerParser) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) SigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.SigningMetadata) AbstractMap(java.util.AbstractMap) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) IdentifierUtils(tech.pegasys.web3signer.core.util.IdentifierUtils) Map(java.util.Map) Optional(java.util.Optional) KeyType(tech.pegasys.web3signer.core.signing.KeyType) Path(java.nio.file.Path) LogManager(org.apache.logging.log4j.LogManager) FilenameUtils(org.apache.commons.io.FilenameUtils) SigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.SigningMetadata) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) IOException(java.io.IOException) List(java.util.List) AbstractMap(java.util.AbstractMap) Map(java.util.Map) FileKeyStoreMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata)

Example 5 with FileKeyStoreMetadata

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);
}
Also used : Path(java.nio.file.Path) FileKeyStoreMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata)

Aggregations

FileKeyStoreMetadata (tech.pegasys.web3signer.core.multikey.metadata.FileKeyStoreMetadata)8 Path (java.nio.file.Path)7 Test (org.junit.jupiter.api.Test)6 SigningMetadataException (tech.pegasys.web3signer.core.multikey.metadata.SigningMetadataException)4 ArtifactSigner (tech.pegasys.web3signer.core.signing.ArtifactSigner)2 BlsArtifactSigner (tech.pegasys.web3signer.core.signing.BlsArtifactSigner)2 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 AbstractMap (java.util.AbstractMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 KeyStoreLoader (tech.pegasys.signers.bls.keystore.KeyStoreLoader)1