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);
}
}
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();
}
}
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);
}
}
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());
}
}
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);
}
}
Aggregations