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 5, 2018 in Blockchain by charlie_brown
• 7,710 points
63 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 5, 2018 by ariaholic
• 7,320 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,040 points
589 views
0 votes
1 answer
0 votes
1 answer
+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
• 27,620 points
51 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 5, 2018 in Blockchain by ariaholic
• 7,320 points
35 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.