How to test endorsement policy for the business network in multiple organizations

0 votes

I have following this tutorial to setup multiple organizations. According to step 13 before committing transaction requires both organizations should sign off. How can I test that both organizations are endorsing transaction?

Jul 6, 2018 in Blockchain by charlie_brown
• 7,720 points
590 views

1 answer to this question.

0 votes

Give the proposal responses you are receiving from endorsing peer you can iterate to check validity of the signatures. Here for example code from Java SDK which handles this:

/*
 * Verifies that a Proposal response is properly signed. The payload is the
 * concatenation of the response payload byte string and the endorsement The
 * certificate (public key) is gotten from the Endorsement.Endorser.IdBytes
 * field
 *
 * @param crypto the CryptoPrimitives instance to be used for signing and
 * verification
 *
 * @return true/false depending on result of signature verification
 */
public boolean verify(CryptoSuite crypto) {

    if (isVerified()) { // check if this proposalResponse was already verified   by client code
        return isVerified();
    }

    if (isInvalid()) {
        this.isVerified = false;
    }

    FabricProposalResponse.Endorsement endorsement = this.proposalResponse.getEndorsement();
    ByteString sig = endorsement.getSignature();

    try {
        Identities.SerializedIdentity endorser = Identities.SerializedIdentity
                .parseFrom(endorsement.getEndorser());
        ByteString plainText = proposalResponse.getPayload().concat(endorsement.getEndorser());

        if (config.extraLogLevel(10)) {

            if (null != diagnosticFileDumper) {
                StringBuilder sb = new StringBuilder(10000);
                sb.append("payload TransactionBuilderbytes in hex: " + DatatypeConverter.printHexBinary(proposalResponse.getPayload().toByteArray()));
                sb.append("\n");
                sb.append("endorser bytes in hex: "
                        + DatatypeConverter.printHexBinary(endorsement.getEndorser().toByteArray()));
                sb.append("\n");
                sb.append("plainText bytes in hex: " + DatatypeConverter.printHexBinary(plainText.toByteArray()));

                logger.trace("payload TransactionBuilderbytes:  " +
                        diagnosticFileDumper.createDiagnosticFile(sb.toString()));
            }

        }

        this.isVerified = crypto.verify(endorser.getIdBytes().toByteArray(), config.getSignatureAlgorithm(),
                sig.toByteArray(), plainText.toByteArray()
        );
    } catch (InvalidProtocolBufferException | CryptoException e) {
        logger.error("verify: Cannot retrieve peer identity from ProposalResponse. Error is: " + e.getMessage(), e);
        this.isVerified = false;
    }

    return this.isVerified;
} // verify

Of course you can achive same results with other SDK in pretty similar way.

answered Jul 6, 2018 by aryya
• 7,450 points

Related Questions In Blockchain

+1 vote
2 answers

How to configure Endorsement policy in Hyperledger?

The Hyperledger Fabric Endorsement policy is configured ...READ MORE

answered Jul 25, 2018 in Blockchain by slayer
• 29,350 points
2,920 views
0 votes
1 answer
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,237 views
+1 vote
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
732 views
0 votes
1 answer

How to prevent the smart contract from being modified and deployed in the blockchain network?

To expand on Matthew's answer, each state ...READ MORE

answered Jul 6, 2018 in Blockchain by aryya
• 7,450 points
646 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP