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