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