Search in sources :

Example 1 with PkiQbftExtraDataCodec

use of org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec in project besu by hyperledger.

the class ProposalPayloadValidator method validateCms.

private boolean validateCms(final Block block, final BftBlockInterface bftBlockInterface, final CmsValidator cmsValidator) {
    final PkiQbftExtraData pkiExtraData = (PkiQbftExtraData) bftBlockInterface.getExtraData(block.getHeader());
    final Hash hashWithoutCms = PkiQbftBlockHeaderFunctions.forCmsSignature((PkiQbftExtraDataCodec) bftExtraDataCodec).hash(block.getHeader());
    LOG.debug("Validating CMS with signed hash {} in block {}", hashWithoutCms, block.getHash());
    if (!cmsValidator.validate(pkiExtraData.getCms(), hashWithoutCms)) {
        LOG.info("{}: invalid CMS in block {}", ERROR_PREFIX, block.getHash());
        return false;
    } else {
        LOG.trace("Valid CMS in block {}", block.getHash());
        return true;
    }
}
Also used : Hash(org.hyperledger.besu.datatypes.Hash) PkiQbftExtraData(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData) PkiQbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec)

Example 2 with PkiQbftExtraDataCodec

use of org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec in project besu by hyperledger.

the class ProposalPayloadValidatorTest method validationForCmsFailsWhenCmsFailsValidation.

@Test
public void validationForCmsFailsWhenCmsFailsValidation() {
    final PkiQbftExtraDataCodec pkiQbftExtraDataCodec = new PkiQbftExtraDataCodec();
    final QbftContext qbftContext = setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec);
    final Bytes cms = Bytes.fromHexStringLenient("0x1");
    final ProtocolContext protocolContext = new ProtocolContext(blockChain, worldStateArchive, qbftContext);
    final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator(expectedProposer, roundIdentifier, blockValidator, protocolContext, pkiQbftExtraDataCodec, Optional.of(cmsValidator));
    final Block block = createPkiProposalBlock(emptyList(), roundIdentifier, pkiQbftExtraDataCodec, cms);
    final Proposal proposal = messageFactory.createProposal(roundIdentifier, block, emptyList(), emptyList());
    final Hash hashWithoutCms = PkiQbftBlockHeaderFunctions.forCmsSignature(pkiQbftExtraDataCodec).hash(block.getHeader());
    when(blockValidator.validateAndProcessBlock(eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), eq(HeaderValidationMode.FULL))).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
    when(cmsValidator.validate(eq(cms), eq(hashWithoutCms))).thenReturn(false);
    assertThat(payloadValidator.validate(proposal.getSignedPayload())).isFalse();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) QbftContext(org.hyperledger.besu.consensus.qbft.QbftContext) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) Hash(org.hyperledger.besu.datatypes.Hash) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) PkiQbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Example 3 with PkiQbftExtraDataCodec

use of org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec in project besu by hyperledger.

the class ProposalPayloadValidatorTest method validationForCmsPassesWhenCmsIsValid.

@Test
public void validationForCmsPassesWhenCmsIsValid() {
    final PkiQbftExtraDataCodec pkiQbftExtraDataCodec = new PkiQbftExtraDataCodec();
    final QbftContext qbftContext = setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec);
    final Bytes cms = Bytes.fromHexStringLenient("0x1");
    final ProtocolContext protocolContext = new ProtocolContext(blockChain, worldStateArchive, qbftContext);
    final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator(expectedProposer, roundIdentifier, blockValidator, protocolContext, pkiQbftExtraDataCodec, Optional.of(cmsValidator));
    final Block block = createPkiProposalBlock(emptyList(), roundIdentifier, pkiQbftExtraDataCodec, cms);
    final Proposal proposal = messageFactory.createProposal(roundIdentifier, block, emptyList(), emptyList());
    final Hash hashWithoutCms = PkiQbftBlockHeaderFunctions.forCmsSignature(pkiQbftExtraDataCodec).hash(block.getHeader());
    when(blockValidator.validateAndProcessBlock(eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), eq(HeaderValidationMode.FULL))).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
    when(cmsValidator.validate(eq(cms), eq(hashWithoutCms))).thenReturn(true);
    assertThat(payloadValidator.validate(proposal.getSignedPayload())).isTrue();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) QbftContext(org.hyperledger.besu.consensus.qbft.QbftContext) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) Hash(org.hyperledger.besu.datatypes.Hash) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) PkiQbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Aggregations

PkiQbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec)3 Hash (org.hyperledger.besu.datatypes.Hash)3 Bytes (org.apache.tuweni.bytes.Bytes)2 QbftContext (org.hyperledger.besu.consensus.qbft.QbftContext)2 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)2 BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)2 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)2 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)2 Block (org.hyperledger.besu.ethereum.core.Block)2 Test (org.junit.Test)2 PkiQbftExtraData (org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData)1