Search in sources :

Example 1 with BlockRequest

use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest in project web3signer by ConsenSys.

the class DeleteKeystoresAcceptanceTest method deletingDisablesSigningForAllWeb3Signers.

@Test
public void deletingDisablesSigningForAllWeb3Signers() throws URISyntaxException, JsonProcessingException {
    final String firstPubkey = createBlsKey("eth2/bls_keystore.json", "somepassword");
    final String secondPubKey = createBlsKey("eth2/bls_keystore_2.json", "otherpassword");
    setupSignerWithKeyManagerApi(WITH_SLASHING_PROTECTION_DATA);
    final SignerConfiguration signer2Configuration = new SignerConfigurationBuilder().withKeyStoreDirectory(testDirectory).withMode("eth2").withNetwork("minimal").withAltairForkEpoch(MINIMAL_ALTAIR_FORK).withSlashingEnabled(true).withSlashingProtectionDbUrl(signer.getSlashingDbUrl()).withSlashingProtectionDbUsername(DB_USERNAME).withSlashingProtectionDbPassword(DB_PASSWORD).withKeyManagerApiEnabled(true).build();
    final Signer signer2 = new Signer(signer2Configuration, null);
    signer2.start();
    signer2.awaitStartupCompletion();
    callDeleteKeystores(composeRequestBody()).then().contentType(ContentType.JSON).assertThat().statusCode(200).body("data[0].status", is("deleted")).and().body("slashing_protection", is(singleEntrySlashingData));
    callListKeys().then().statusCode(200).contentType(ContentType.JSON).body("data.size()", is(1)).and().body("data[0].validating_pubkey", is(secondPubKey));
    callListKeys(signer2).then().statusCode(200).contentType(ContentType.JSON).body("data.size()", is(2)).and().body("data[0].validating_pubkey", is(firstPubkey)).body("data[1].validating_pubkey", is(secondPubKey));
    final Eth2SigningRequestBody attestationRequest = Eth2RequestUtils.createCannedRequest(ArtifactType.ATTESTATION);
    signer.eth2Sign(firstPubkey, attestationRequest, ContentType.TEXT).then().statusCode(404);
    signer2.eth2Sign(firstPubkey, attestationRequest, ContentType.TEXT).then().statusCode(412);
    final Eth2SigningRequestBody blockRequest = Eth2RequestUtils.createCannedRequest(ArtifactType.BLOCK_V2);
    signer.eth2Sign(firstPubkey, blockRequest, ContentType.TEXT).then().statusCode(404);
    signer2.eth2Sign(firstPubkey, blockRequest, ContentType.TEXT).then().statusCode(412);
}
Also used : Signer(tech.pegasys.web3signer.dsl.signer.Signer) SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with BlockRequest

use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest in project web3signer by ConsenSys.

the class BlockRequestDeserializer method deserialize.

@Override
public BlockRequest deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
    final ObjectCodec codec = p.getCodec();
    final JsonNode node = codec.readTree(p);
    final SpecMilestone specMilestone = SpecMilestone.valueOf(node.findValue("version").asText());
    final BeaconBlock beaconBlock;
    final BeaconBlockHeader beaconBlockHeader;
    final BlockRequest blockRequest;
    switch(specMilestone) {
        case PHASE0:
            beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlock.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlock);
            break;
        case ALTAIR:
            beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlockAltair.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlock);
            break;
        case BELLATRIX:
            // for BELLATRIX we only need block_header instead of complete block
            beaconBlockHeader = codec.treeToValue(node.findValue("block_header"), BeaconBlockHeader.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlockHeader);
            break;
        default:
            throw new IllegalStateException("Fork version not yet supported: " + specMilestone);
    }
    return blockRequest;
}
Also used : BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) BeaconBlockHeader(tech.pegasys.teku.api.schema.BeaconBlockHeader) BlockRequest(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) BeaconBlockAltair(tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)

Example 3 with BlockRequest

use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest in project web3signer by ConsenSys.

the class Eth2BlockSigningAcceptanceTest method emptyBlockRequestReturnsBadRequestStatus.

@Test
void emptyBlockRequestReturnsBadRequestStatus() throws JsonProcessingException {
    final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(SpecMilestone.BELLATRIX);
    setupEth2Signer(Eth2Network.MINIMAL, SpecMilestone.BELLATRIX);
    final Eth2SigningRequestBody request = util.createBlockV2Request(new BlockRequest(SpecMilestone.BELLATRIX));
    final Response response = signer.eth2Sign(keyPair.getPublicKey().toString(), request, ContentType.JSON);
    response.then().statusCode(400);
}
Also used : Response(io.restassured.response.Response) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Eth2BlockSigningRequestUtil(tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil) BlockRequest(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BlockRequest

use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest in project web3signer by ConsenSys.

the class KeyLoadAndSignAcceptanceTest method unusedFieldsInRequestDoesNotAffectSigning.

@Test
public void unusedFieldsInRequestDoesNotAffectSigning() throws JsonProcessingException {
    final String configFilename = BLS_KEY_PAIR.getPublicKey().toString().substring(2);
    final Path keyConfigFile = testDirectory.resolve(configFilename + ".yaml");
    METADATA_FILE_HELPERS.createUnencryptedYamlFileAt(keyConfigFile, PRIVATE_KEY, KeyType.BLS);
    setupEth2Signer(Eth2Network.MINIMAL, SpecMilestone.PHASE0);
    final Eth2SigningRequestBody blockRequest = Eth2RequestUtils.createBlockRequest();
    final JsonObject jsonObject = new JsonObject(ETH_2_INTERFACE_OBJECT_MAPPER.writeValueAsString(blockRequest));
    final String body = jsonObject.put("unknownField", "someValue").toString();
    final String expectedSignature = BLS.sign(BLS_KEY_PAIR.getSecretKey(), blockRequest.getSigningRoot()).toString();
    given().baseUri(signer.getUrl()).contentType(ContentType.JSON).pathParam("identifier", BLS_KEY_PAIR.getPublicKey().toString()).body(body).when().post(Signer.signPath(KeyType.BLS)).then().statusCode(200).contentType(ContentType.JSON).body("signature", equalToIgnoringCase(expectedSignature));
}
Also used : Path(java.nio.file.Path) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)3 Eth2SigningRequestBody (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 BlockRequest (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest)2 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Response (io.restassured.response.Response)1 JsonObject (io.vertx.core.json.JsonObject)1 Path (java.nio.file.Path)1 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)1 BeaconBlockHeader (tech.pegasys.teku.api.schema.BeaconBlockHeader)1 BeaconBlockAltair (tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)1 SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)1 Signer (tech.pegasys.web3signer.dsl.signer.Signer)1 SignerConfiguration (tech.pegasys.web3signer.dsl.signer.SignerConfiguration)1 SignerConfigurationBuilder (tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder)1 Eth2BlockSigningRequestUtil (tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil)1