Search in sources :

Example 1 with KeyStoreValidationException

use of tech.pegasys.signers.bls.keystore.KeyStoreValidationException in project web3signer by ConsenSys.

the class BlsArtifactSignerFactory method createKeystoreArtifact.

private ArtifactSigner createKeystoreArtifact(final FileKeyStoreMetadata fileKeyStoreMetadata) {
    final Path keystoreFile = makeRelativePathAbsolute(fileKeyStoreMetadata.getKeystoreFile());
    final Path keystorePasswordFile = makeRelativePathAbsolute(fileKeyStoreMetadata.getKeystorePasswordFile());
    try {
        final KeyStoreData keyStoreData = KeyStoreLoader.loadFromFile(keystoreFile);
        final String password = loadPassword(keystorePasswordFile);
        final Bytes privateKey = KeyStore.decrypt(password, keyStoreData);
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKey)));
        return signerFactory.apply(new BlsArtifactSignerArgs(keyPair, SignerOrigin.FILE_KEYSTORE, Optional.ofNullable(keyStoreData.getPath())));
    } catch (final KeyStoreValidationException e) {
        throw new SigningMetadataException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) Bytes(org.apache.tuweni.bytes.Bytes) KeyStoreValidationException(tech.pegasys.signers.bls.keystore.KeyStoreValidationException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Example 2 with KeyStoreValidationException

use of tech.pegasys.signers.bls.keystore.KeyStoreValidationException in project web3signer by ConsenSys.

the class BlsKeystoreBulkLoader method createSignerForKeystore.

private Optional<? extends ArtifactSigner> createSignerForKeystore(final Path keystoreFile, final PasswordRetriever passwordRetriever) {
    try {
        LOG.debug("Loading keystore {}", keystoreFile);
        final KeyStoreData keyStoreData = KeyStoreLoader.loadFromFile(keystoreFile);
        final String key = FilenameUtils.removeExtension(keystoreFile.getFileName().toString());
        final String password = passwordRetriever.retrievePassword(key);
        final Bytes privateKey = KeyStore.decrypt(password, keyStoreData);
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKey)));
        final BlsArtifactSigner artifactSigner = new BlsArtifactSigner(keyPair, SignerOrigin.FILE_KEYSTORE);
        return Optional.of(artifactSigner);
    } catch (final KeyStoreValidationException | IOException e) {
        LOG.error("Keystore could not be loaded {}", keystoreFile, e);
        return Optional.empty();
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) KeyStoreValidationException(tech.pegasys.signers.bls.keystore.KeyStoreValidationException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Example 3 with KeyStoreValidationException

use of tech.pegasys.signers.bls.keystore.KeyStoreValidationException in project web3signer by ConsenSys.

the class BlsArtifactSignerFactory method createKeystoreArtifact.

private ArtifactSigner createKeystoreArtifact(final FileKeyStoreMetadata fileKeyStoreMetadata) {
    final Path keystoreFile = makeRelativePathAbsolute(fileKeyStoreMetadata.getKeystoreFile());
    final Path keystorePasswordFile = makeRelativePathAbsolute(fileKeyStoreMetadata.getKeystorePasswordFile());
    try {
        final KeyStoreData keyStoreData = KeyStoreLoader.loadFromFile(keystoreFile);
        final String password = loadPassword(keystorePasswordFile);
        final Bytes privateKey = KeyStore.decrypt(password, keyStoreData);
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKey)));
        return signerFactory.apply(new BlsArtifactSignerArgs(keyPair, SignerOrigin.FILE_KEYSTORE, Optional.ofNullable(keyStoreData.getPath())));
    } catch (final KeyStoreValidationException e) {
        throw new SigningMetadataException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) Bytes(org.apache.tuweni.bytes.Bytes) KeyStoreValidationException(tech.pegasys.signers.bls.keystore.KeyStoreValidationException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Example 4 with KeyStoreValidationException

use of tech.pegasys.signers.bls.keystore.KeyStoreValidationException in project teku by ConsenSys.

the class SendDepositsCommand method getValidatorKey.

private BLSKeyPair getValidatorKey() {
    if (validatorKeyOptions.getValidatorKey() != null) {
        return privateKeyToKeyPair(validatorKeyOptions.getValidatorKey());
    }
    try {
        final String keystorePassword = readPassword();
        final KeyStoreData keyStoreData = KeyStoreLoader.loadFromFile(validatorKeyOptions.getValidatorKeyStoreOptions().getValidatorKeystoreFile().toPath());
        final Bytes privateKey = KeyStore.decrypt(keystorePassword, keyStoreData);
        return privateKeyToKeyPair(Bytes32.wrap(privateKey));
    } catch (final KeyStoreValidationException e) {
        throw new ParameterException(spec.commandLine(), e.getMessage());
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) KeyStoreValidationException(tech.pegasys.signers.bls.keystore.KeyStoreValidationException) ParameterException(picocli.CommandLine.ParameterException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData)

Example 5 with KeyStoreValidationException

use of tech.pegasys.signers.bls.keystore.KeyStoreValidationException in project teku by ConsenSys.

the class LocalValidatorSource method createValidatorProvider.

private ValidatorProvider createValidatorProvider(final Pair<Path, Path> keystorePasswordFilePair) {
    final Path keystorePath = keystorePasswordFilePair.getLeft();
    final Path passwordPath = keystorePasswordFilePair.getRight();
    try {
        final KeyStoreData keyStoreData = KeyStoreLoader.loadFromFile(keystorePath);
        final BLSPublicKey publicKey = BLSPublicKey.fromBytesCompressedValidate(Bytes48.wrap(keyStoreData.getPubkey()));
        final String password = loadPassword(passwordPath);
        localValidatorSourceMap.put(publicKey, new ActiveLocalValidatorSource(keystorePath, passwordPath));
        return new LocalValidatorProvider(spec, keyStoreData, keystorePath, publicKey, password, readOnly);
    } catch (final KeyStoreValidationException e) {
        if (Throwables.getRootCause(e) instanceof FileNotFoundException) {
            throw new InvalidConfigurationException(e.getMessage(), e);
        }
        throw new InvalidConfigurationException("Invalid keystore: " + keystorePath, e);
    }
}
Also used : Path(java.nio.file.Path) KeyStoreValidationException(tech.pegasys.signers.bls.keystore.KeyStoreValidationException) FileNotFoundException(java.io.FileNotFoundException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)

Aggregations

KeyStoreValidationException (tech.pegasys.signers.bls.keystore.KeyStoreValidationException)5 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)5 Bytes (org.apache.tuweni.bytes.Bytes)4 Path (java.nio.file.Path)3 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ParameterException (picocli.CommandLine.ParameterException)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1 InvalidConfigurationException (tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)1