Blockchain 如何在多个组织中测试业务网络的背书策略

Blockchain 如何在多个组织中测试业务网络的背书策略,blockchain,hyperledger-fabric,hyperledger,hyperledger-composer,Blockchain,Hyperledger Fabric,Hyperledger,Hyperledger Composer,我有以下教程来设置多个组织。根据第13步,在提交事务之前,要求两个组织都应签字。如何测试这两个组织是否都在签署交易?给出您从签署对等方收到的提案响应,您可以反复检查签名的有效性。下面是Java SDK中处理此问题的示例代码: /* * Verifies that a Proposal response is properly signed. The payload is the * concatenation of the response payload byte string and t

我有以下教程来设置多个组织。根据第13步,在提交事务之前,要求两个组织都应签字。如何测试这两个组织是否都在签署交易?

给出您从签署对等方收到的提案响应,您可以反复检查签名的有效性。下面是Java SDK中处理此问题的示例代码:

/*
 * 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

当然,您可以通过非常类似的方式使用其他SDK获得相同的结果。

您想在哪里测试它?作为客户,它负责将背书交易发送给两个组织的对等方,然后收集签名。一旦对等方获得带有事务的块,它将执行VSCC,以确保满足背书策略,例如,根据策略,事务具有足够的有效签名。您能详细说明一下您希望在哪里进行此检查吗?@Artemberger我想使用API或其他方式检查事务是否由组织签名Fabric中的此背书模式是否只留给客户正确实施背书?我的问题是,在对等方的vscc验证期间,当您验证从订购方收到的事务时,您是否同时验证R/W集和签名?[否则,我可以通过绕过验证检查并发送在每个响应(来自每个对等方)中可能只是不同的R/W集来复制Fabric。Rite?]是的,有MVCC验证和VSCC,一个检查密钥版本以进行并发修改,另一个确保事务符合认可策略。