Search in sources :

Example 1 with SlashingProtectionContext

use of tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext in project web3signer by ConsenSys.

the class Eth2Runner method registerEth2Routes.

private void registerEth2Routes(final RouterBuilder routerBuilder, final ArtifactSignerProvider blsSignerProvider, final LogErrorHandler errorHandler, final MetricsSystem metricsSystem, final Optional<SlashingProtectionContext> slashingProtectionContext) {
    final ObjectMapper objectMapper = SigningObjectMapperFactory.createObjectMapper();
    // security handler for keymanager endpoints
    routerBuilder.securityHandler("bearerAuth", context -> {
        // TODO Auth token security logic
        final boolean authorized = true;
        if (authorized) {
            context.next();
        } else {
            context.response().setStatusCode(401).end("{ message: \"permission denied\" }");
        }
    });
    addPublicKeysListHandler(routerBuilder, blsSignerProvider, ETH2_LIST.name(), errorHandler);
    final SignerForIdentifier<BlsArtifactSignature> blsSigner = new SignerForIdentifier<>(blsSignerProvider, this::formatBlsSignature, BLS);
    routerBuilder.operation(ETH2_SIGN.name()).handler(new BlockingHandlerDecorator(new Eth2SignForIdentifierHandler(blsSigner, new HttpApiMetrics(metricsSystem, BLS), new SlashingProtectionMetrics(metricsSystem), slashingProtectionContext.map(SlashingProtectionContext::getSlashingProtection), objectMapper, eth2Spec), false)).failureHandler(errorHandler);
    addReloadHandler(routerBuilder, blsSignerProvider, RELOAD.name(), errorHandler);
    if (isKeyManagerApiEnabled) {
        routerBuilder.operation(KEYMANAGER_LIST.name()).handler(new BlockingHandlerDecorator(new ListKeystoresHandler(blsSignerProvider, objectMapper), false)).failureHandler(errorHandler);
        final ValidatorManager validatorManager = createValidatorManager(blsSignerProvider, objectMapper);
        routerBuilder.operation(KEYMANAGER_IMPORT.name()).handler(new BlockingHandlerDecorator(new ImportKeystoresHandler(objectMapper, config.getKeyConfigPath(), slashingProtectionContext.map(SlashingProtectionContext::getSlashingProtection), blsSignerProvider, validatorManager), false)).failureHandler(errorHandler);
        routerBuilder.operation(KEYMANAGER_DELETE.name()).handler(new BlockingHandlerDecorator(new DeleteKeystoresHandler(objectMapper, slashingProtectionContext.map(SlashingProtectionContext::getSlashingProtection), blsSignerProvider, validatorManager), false)).failureHandler(errorHandler);
    }
}
Also used : FileValidatorManager(tech.pegasys.web3signer.signing.FileValidatorManager) DbValidatorManager(tech.pegasys.web3signer.slashingprotection.DbValidatorManager) ValidatorManager(tech.pegasys.web3signer.signing.ValidatorManager) ListKeystoresHandler(tech.pegasys.web3signer.core.service.http.handlers.keymanager.list.ListKeystoresHandler) DeleteKeystoresHandler(tech.pegasys.web3signer.core.service.http.handlers.keymanager.delete.DeleteKeystoresHandler) SlashingProtectionMetrics(tech.pegasys.web3signer.core.metrics.SlashingProtectionMetrics) SignerForIdentifier(tech.pegasys.web3signer.core.service.http.handlers.signing.SignerForIdentifier) BlockingHandlerDecorator(io.vertx.ext.web.impl.BlockingHandlerDecorator) BlsArtifactSignature(tech.pegasys.web3signer.signing.BlsArtifactSignature) SlashingProtectionContext(tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext) ImportKeystoresHandler(tech.pegasys.web3signer.core.service.http.handlers.keymanager.imports.ImportKeystoresHandler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Eth2SignForIdentifierHandler(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SignForIdentifierHandler) HttpApiMetrics(tech.pegasys.web3signer.core.service.http.metrics.HttpApiMetrics)

Example 2 with SlashingProtectionContext

use of tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext in project web3signer by ConsenSys.

the class Eth2ExportSubCommand method run.

@Override
public void run() {
    if (output == null) {
        throw new MissingParameterException(spec.commandLine(), spec.findOption("--to"), "--to has not been specified");
    } else if (StringUtils.isEmpty(eth2Config.getSlashingProtectionParameters().getDbUrl())) {
        throw new MissingParameterException(spec.parent().commandLine(), spec.findOption("--slashing-protection-db-url"), "--slashing-protection-db-url has not been specified");
    }
    try (final OutputStream outStream = new FileOutputStream(output)) {
        final SlashingProtectionContext slashingProtectionContext = SlashingProtectionContextFactory.create(eth2Config.getSlashingProtectionParameters());
        slashingProtectionContext.getSlashingProtection().exportData(outStream);
    } catch (final IOException e) {
        throw new UncheckedIOException("Unable to find output target file", e);
    } catch (final IllegalStateException e) {
        throw new InitializationException(e.getMessage(), e);
    } catch (final RuntimeException e) {
        throw new InitializationException("Failed to initialise Slashing Protection: " + e.getMessage(), e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) MissingParameterException(picocli.CommandLine.MissingParameterException) UncheckedIOException(java.io.UncheckedIOException) SlashingProtectionContext(tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) InitializationException(tech.pegasys.web3signer.core.InitializationException)

Example 3 with SlashingProtectionContext

use of tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext in project web3signer by ConsenSys.

the class Eth2ImportSubCommand method run.

@Override
public void run() {
    if (from == null) {
        throw new MissingParameterException(spec.commandLine(), spec.findOption("--from"), "--from has not been specified");
    } else if (StringUtils.isEmpty(eth2Config.getSlashingProtectionParameters().getDbUrl())) {
        throw new MissingParameterException(spec.parent().commandLine(), spec.findOption("--slashing-protection-db-url"), "--slashing-protection-db-url has not been specified");
    }
    try (final InputStream inStream = new FileInputStream(from)) {
        final SlashingProtectionContext slashingProtectionContext = SlashingProtectionContextFactory.create(eth2Config.getSlashingProtectionParameters());
        slashingProtectionContext.getSlashingProtection().importData(inStream);
    } catch (final IOException e) {
        throw new UncheckedIOException("Unable to find input file", e);
    } catch (final IllegalStateException e) {
        throw new InitializationException(e.getMessage(), e);
    } catch (final RuntimeException e) {
        throw new InitializationException("Failed to initialise Slashing Protection: " + e.getMessage(), e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MissingParameterException(picocli.CommandLine.MissingParameterException) UncheckedIOException(java.io.UncheckedIOException) SlashingProtectionContext(tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) InitializationException(tech.pegasys.web3signer.core.InitializationException) FileInputStream(java.io.FileInputStream)

Aggregations

SlashingProtectionContext (tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 MissingParameterException (picocli.CommandLine.MissingParameterException)2 InitializationException (tech.pegasys.web3signer.core.InitializationException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BlockingHandlerDecorator (io.vertx.ext.web.impl.BlockingHandlerDecorator)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 SlashingProtectionMetrics (tech.pegasys.web3signer.core.metrics.SlashingProtectionMetrics)1 DeleteKeystoresHandler (tech.pegasys.web3signer.core.service.http.handlers.keymanager.delete.DeleteKeystoresHandler)1 ImportKeystoresHandler (tech.pegasys.web3signer.core.service.http.handlers.keymanager.imports.ImportKeystoresHandler)1 ListKeystoresHandler (tech.pegasys.web3signer.core.service.http.handlers.keymanager.list.ListKeystoresHandler)1 SignerForIdentifier (tech.pegasys.web3signer.core.service.http.handlers.signing.SignerForIdentifier)1 Eth2SignForIdentifierHandler (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SignForIdentifierHandler)1 HttpApiMetrics (tech.pegasys.web3signer.core.service.http.metrics.HttpApiMetrics)1 BlsArtifactSignature (tech.pegasys.web3signer.signing.BlsArtifactSignature)1 FileValidatorManager (tech.pegasys.web3signer.signing.FileValidatorManager)1