Search in sources :

Example 1 with TimingContext

use of org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext in project web3signer by ConsenSys.

the class BlsArtifactSignerFactory method create.

@Override
public ArtifactSigner create(final AwsKeySigningMetadata awsKeySigningMetadata) {
    try (final TimingContext ignored = privateKeyRetrievalTimer.labels("aws").startTimer()) {
        final Bytes32 keyBytes = Bytes32.wrap(extractBytesFromSecretsManager(awsKeySigningMetadata));
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(keyBytes));
        return signerFactory.apply(new BlsArtifactSignerArgs(keyPair, SignerOrigin.AWS));
    }
}
Also used : Bytes32(org.apache.tuweni.bytes.Bytes32) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) TimingContext(org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)

Example 2 with TimingContext

use of org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext in project web3signer by ConsenSys.

the class BlsArtifactSignerFactory method create.

@Override
public ArtifactSigner create(final HashicorpSigningMetadata hashicorpMetadata) {
    try (final TimingContext ignored = privateKeyRetrievalTimer.labels("hashicorp").startTimer()) {
        final Bytes privateKeyBytes = extractBytesFromVault(hashicorpMetadata);
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKeyBytes)));
        return signerFactory.apply(new BlsArtifactSignerArgs(keyPair, SignerOrigin.HASHICORP));
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) TimingContext(org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)

Example 3 with TimingContext

use of org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext in project web3signer by ConsenSys.

the class Eth1SignForIdentifierHandler method handle.

@Override
public void handle(final RoutingContext routingContext) {
    try (final TimingContext ignored = metrics.getSigningTimer().startTimer()) {
        final RequestParameters params = routingContext.get(ValidationHandler.REQUEST_CONTEXT_KEY);
        final String identifier = params.pathParameter("identifier").toString();
        final Bytes data;
        try {
            data = getDataToSign(params);
        } catch (final IllegalArgumentException e) {
            metrics.getMalformedRequestCounter().inc();
            LOG.debug("Invalid signing request", e);
            routingContext.fail(400);
            return;
        }
        signerForIdentifier.sign(normaliseIdentifier(identifier), data).ifPresentOrElse(signature -> {
            respondWithSignature(routingContext, signature);
        }, () -> {
            LOG.trace("Identifier not found {}", identifier);
            metrics.getMissingSignerCounter().inc();
            routingContext.fail(404);
        });
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SignerForIdentifier.toBytes(tech.pegasys.web3signer.core.service.http.handlers.signing.SignerForIdentifier.toBytes) TimingContext(org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext) RequestParameters(io.vertx.ext.web.validation.RequestParameters)

Example 4 with TimingContext

use of org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext in project web3signer by ConsenSys.

the class Eth2SignForIdentifierHandler method handle.

@Override
public void handle(final RoutingContext routingContext) {
    try (final TimingContext ignored = httpMetrics.getSigningTimer().startTimer()) {
        LOG.trace("{} || {}", routingContext.normalizedPath(), routingContext.getBody());
        final RequestParameters params = routingContext.get(ValidationHandler.REQUEST_CONTEXT_KEY);
        final String identifier = params.pathParameter("identifier").toString();
        final Eth2SigningRequestBody eth2SigningRequestBody;
        try {
            eth2SigningRequestBody = getSigningRequest(params);
        } catch (final IllegalArgumentException | JsonProcessingException e) {
            handleInvalidRequest(routingContext, e);
            return;
        }
        final Bytes signingRoot = computeSigningRoot(eth2SigningRequestBody);
        if (eth2SigningRequestBody.getSigningRoot() != null) {
            checkArgument(eth2SigningRequestBody.getSigningRoot().equals(signingRoot), "Signing root %s must match signing computed signing root %s from data", eth2SigningRequestBody.getSigningRoot(), signingRoot);
        }
        final String normalisedIdentifier = normaliseIdentifier(identifier);
        if (slashingProtection.isPresent()) {
            handleSigning(routingContext, signingRoot, normalisedIdentifier, signature -> signWithSlashingProtection(routingContext, identifier, eth2SigningRequestBody, signingRoot, signature));
        } else {
            handleSigning(routingContext, signingRoot, normalisedIdentifier, signature -> respondWithSignature(routingContext, signature));
        }
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TimingContext(org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext) RequestParameters(io.vertx.ext.web.validation.RequestParameters)

Example 5 with TimingContext

use of org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext in project web3signer by ConsenSys.

the class BlsArtifactSignerFactory method create.

@Override
public ArtifactSigner create(final InterlockSigningMetadata interlockSigningMetadata) {
    try (final TimingContext ignored = privateKeyRetrievalTimer.labels("interlock").startTimer()) {
        final Bytes32 keyBytes = Bytes32.wrap(extractBytesFromInterlock(interlockSigningMetadata));
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(keyBytes));
        return signerFactory.apply(new BlsArtifactSignerArgs(keyPair, SignerOrigin.INTERLOCK));
    }
}
Also used : Bytes32(org.apache.tuweni.bytes.Bytes32) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) TimingContext(org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)

Aggregations

TimingContext (org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)12 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)10 Bytes (org.apache.tuweni.bytes.Bytes)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 RequestParameters (io.vertx.ext.web.validation.RequestParameters)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SignerForIdentifier.toBytes (tech.pegasys.web3signer.core.service.http.handlers.signing.SignerForIdentifier.toBytes)1