Search in sources :

Example 96 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.

the class ProposalResponse method verify.

/*
     * 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;
}
Also used : ByteString(com.google.protobuf.ByteString) FabricProposalResponse(org.hyperledger.fabric.protos.peer.FabricProposalResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Identities(org.hyperledger.fabric.protos.msp.Identities) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException)

Example 97 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.

the class ProposalResponse method getChaincodeActionResponsePayload.

/**
 * ChaincodeActionResponsePayload is the result of the executing chaincode.
 *
 * @return the result of the executing chaincode.
 * @throws InvalidArgumentException
 */
public byte[] getChaincodeActionResponsePayload() throws InvalidArgumentException {
    if (isInvalid()) {
        throw new InvalidArgumentException("Proposal response is invalid.");
    }
    try {
        final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer();
        ByteString ret = proposalResponsePayloadDeserializer.getExtension().getChaincodeAction().getResponse().getPayload();
        if (null == ret) {
            return null;
        }
        return ret.toByteArray();
    } catch (InvalidArgumentException e) {
        throw e;
    } catch (Exception e) {
        throw new InvalidArgumentException(e);
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException)

Example 98 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.

the class ChaincodeActionDeserializer method getEvent.

ChaincodeEvent getEvent() {
    ChaincodeAction ca = getChaincodeAction();
    ByteString eventsBytes = ca.getEvents();
    if (eventsBytes == null || eventsBytes.isEmpty()) {
        return null;
    }
    return new ChaincodeEvent(eventsBytes);
}
Also used : ChaincodeAction(org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeAction) ByteString(com.google.protobuf.ByteString)

Example 99 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.

the class ChannelTest method testProposalBuilderWithOutMetaInf.

@Test
public void testProposalBuilderWithOutMetaInf() throws Exception {
    InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
    installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
    installProposalBuilder.chaincodePath("github.com/example_cc");
    installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
    installProposalBuilder.chaincodeName("example_cc.go");
    installProposalBuilder.chaincodeVersion("1");
    Channel channel = hfclient.newChannel("testProposalBuilderWithOutMetaInf");
    TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
    installProposalBuilder.context(transactionContext);
    // Build it get the proposal. Then unpack it to see if it's what we expect.
    FabricProposal.Proposal proposal = installProposalBuilder.build();
    FabricProposal.ChaincodeProposalPayload chaincodeProposalPayload = FabricProposal.ChaincodeProposalPayload.parseFrom(proposal.getPayload());
    Chaincode.ChaincodeInvocationSpec chaincodeInvocationSpec = Chaincode.ChaincodeInvocationSpec.parseFrom(chaincodeProposalPayload.getInput());
    Chaincode.ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.getChaincodeSpec();
    Chaincode.ChaincodeInput input = chaincodeSpec.getInput();
    Chaincode.ChaincodeDeploymentSpec chaincodeDeploymentSpec = Chaincode.ChaincodeDeploymentSpec.parseFrom(input.getArgs(1));
    ByteString codePackage = chaincodeDeploymentSpec.getCodePackage();
    ArrayList tarBytesToEntryArrayList = tarBytesToEntryArrayList(codePackage.toByteArray());
    ArrayList<String> expect = new ArrayList(Arrays.asList(new String[] { "src/github.com/example_cc/example_cc.go" }));
    assertArrayListEquals("Tar in Install Proposal's codePackage does not have expected entries. ", expect, tarBytesToEntryArrayList);
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) ByteString(com.google.protobuf.ByteString) Chaincode(org.hyperledger.fabric.protos.peer.Chaincode) ArrayList(java.util.ArrayList) TestUtils.tarBytesToEntryArrayList(org.hyperledger.fabric.sdk.testutils.TestUtils.tarBytesToEntryArrayList) ByteString(com.google.protobuf.ByteString) FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Example 100 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.

the class ChannelTest method testProposalBuilderWithMetaInf.

@Test
public void testProposalBuilderWithMetaInf() throws Exception {
    InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
    installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
    installProposalBuilder.chaincodePath("github.com/example_cc");
    installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
    installProposalBuilder.chaincodeName("example_cc.go");
    installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/test1"));
    installProposalBuilder.chaincodeVersion("1");
    Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInf");
    TestUtils.MockUser mockUser = getMockUser("rick", "rickORG");
    TransactionContext transactionContext = new TransactionContext(channel, mockUser, CryptoSuite.Factory.getCryptoSuite());
    installProposalBuilder.context(transactionContext);
    // Build it get the proposal. Then unpack it to see if it's what we expect.
    FabricProposal.Proposal proposal = installProposalBuilder.build();
    FabricProposal.ChaincodeProposalPayload chaincodeProposalPayload = FabricProposal.ChaincodeProposalPayload.parseFrom(proposal.getPayload());
    Chaincode.ChaincodeInvocationSpec chaincodeInvocationSpec = Chaincode.ChaincodeInvocationSpec.parseFrom(chaincodeProposalPayload.getInput());
    Chaincode.ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.getChaincodeSpec();
    Chaincode.ChaincodeInput input = chaincodeSpec.getInput();
    Chaincode.ChaincodeDeploymentSpec chaincodeDeploymentSpec = Chaincode.ChaincodeDeploymentSpec.parseFrom(input.getArgs(1));
    ByteString codePackage = chaincodeDeploymentSpec.getCodePackage();
    ArrayList tarBytesToEntryArrayList = tarBytesToEntryArrayList(codePackage.toByteArray());
    ArrayList<String> expect = new ArrayList(Arrays.asList(new String[] { "META-INF/statedb/couchdb/indexes/MockFakeIndex.json", "src/github.com/example_cc/example_cc.go" }));
    assertArrayListEquals("Tar in Install Proposal's codePackage does not have expected entries. ", expect, tarBytesToEntryArrayList);
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) ByteString(com.google.protobuf.ByteString) Chaincode(org.hyperledger.fabric.protos.peer.Chaincode) ArrayList(java.util.ArrayList) TestUtils.tarBytesToEntryArrayList(org.hyperledger.fabric.sdk.testutils.TestUtils.tarBytesToEntryArrayList) ByteString(com.google.protobuf.ByteString) TestUtils(org.hyperledger.fabric.sdk.testutils.TestUtils) FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Aggregations

ByteString (com.google.protobuf.ByteString)406 Test (org.junit.Test)143 ArrayList (java.util.ArrayList)65 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)63 HashMap (java.util.HashMap)41 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)40 IOException (java.io.IOException)37 List (java.util.List)33 Map (java.util.Map)33 ServerRequest (com.pokegoapi.main.ServerRequest)17 ExecutionException (java.util.concurrent.ExecutionException)16 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)14 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)14 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)14 Feature (com.google.cloud.vision.v1.Feature)14 Image (com.google.cloud.vision.v1.Image)14 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)14 FileInputStream (java.io.FileInputStream)13 ByteBuffer (java.nio.ByteBuffer)13 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)12