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