Skip to content

Commit 7a3af1d

Browse files
committed
Expose the signed proposal to chaincodes
This change-set does the following: 1. It allows a chaincode to get the SignedProposal object from the chaincode shim. This is propaedeutic to the enforcement of access control in chaincodes. This change-set comes in the context of 1. https://jira.hyperledger.org/browse/FAB-2968 2. https://jira.hyperledger.org/browse/FAB-2969 Change-Id: I6f1af65c6959591af314e110d569558b3ab32ce5 Signed-off-by: Angelo De Caro <[email protected]>
1 parent 9428140 commit 7a3af1d

File tree

7 files changed

+86
-67
lines changed

7 files changed

+86
-67
lines changed

core/chaincode/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ func (handler *Handler) setChaincodeProposal(signedProp *pb.SignedProposal, prop
14151415
return fmt.Errorf("Failed getting proposal context. Signed proposal is nil.")
14161416
}
14171417

1418-
msg.Proposal = prop
1418+
msg.Proposal = signedProp
14191419
}
14201420
return nil
14211421
}

core/chaincode/shim/chaincode.go

+23-13
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ type ChaincodeStub struct {
6060
chaincodeEvent *pb.ChaincodeEvent
6161
args [][]byte
6262
handler *Handler
63+
signedProposal *pb.SignedProposal
6364
proposal *pb.Proposal
6465

65-
// Additional fields extracted from the proposal
66+
// Additional fields extracted from the signedProposal
6667
creator []byte
6768
transient map[string][]byte
6869
binding []byte
@@ -286,28 +287,32 @@ func chatWithPeer(chaincodename string, stream PeerChaincodeStream, cc Chaincode
286287
// -- init stub ---
287288
// ChaincodeInvocation functionality
288289

289-
func (stub *ChaincodeStub) init(handler *Handler, txid string, input *pb.ChaincodeInput, proposal *pb.Proposal) error {
290+
func (stub *ChaincodeStub) init(handler *Handler, txid string, input *pb.ChaincodeInput, signedProposal *pb.SignedProposal) error {
290291
stub.TxID = txid
291292
stub.args = input.Args
292293
stub.handler = handler
293-
stub.proposal = proposal
294+
stub.signedProposal = signedProposal
294295

295296
// TODO: sanity check: verify that every call to init with a nil
296-
// proposal is a legitimate one, meaning it is an internal call
297+
// signedProposal is a legitimate one, meaning it is an internal call
297298
// to system chaincodes.
298-
if proposal != nil {
299-
// Extract creator, transient, binding...
299+
if signedProposal != nil {
300300
var err error
301-
stub.creator, stub.transient, err = utils.GetChaincodeProposalContext(proposal)
301+
302+
stub.proposal, err = utils.GetProposal(signedProposal.ProposalBytes)
303+
if err != nil {
304+
return fmt.Errorf("Failed extracting signedProposal from signed signedProposal. [%s]", err)
305+
}
306+
307+
// Extract creator, transient, binding...
308+
stub.creator, stub.transient, err = utils.GetChaincodeProposalContext(stub.proposal)
302309
if err != nil {
303-
return fmt.Errorf("Failed extracting proposal fields. [%s]", err)
310+
return fmt.Errorf("Failed extracting signedProposal fields. [%s]", err)
304311
}
305312

306-
// TODO: txid must uniquely identity the transaction.
307-
// Remove this comment once replay attack protection will be in place
308-
stub.binding, err = utils.ComputeProposalBinding(proposal)
313+
stub.binding, err = utils.ComputeProposalBinding(stub.proposal)
309314
if err != nil {
310-
return fmt.Errorf("Failed computing binding from proposal. [%s]", err)
315+
return fmt.Errorf("Failed computing binding from signedProposal. [%s]", err)
311316
}
312317
}
313318

@@ -590,7 +595,7 @@ func (stub *ChaincodeStub) GetFunctionAndParameters() (function string, params [
590595
return
591596
}
592597

593-
// GetCreator returns SignatureHeader.Creator of the proposal
598+
// GetCreator returns SignatureHeader.Creator of the signedProposal
594599
// this Stub refers to.
595600
func (stub *ChaincodeStub) GetCreator() ([]byte, error) {
596601
return stub.creator, nil
@@ -610,6 +615,11 @@ func (stub *ChaincodeStub) GetBinding() ([]byte, error) {
610615
return stub.binding, nil
611616
}
612617

618+
// GetSignedProposal return the signed signedProposal this stub refers to.
619+
func (stub *ChaincodeStub) GetSignedProposal() (*pb.SignedProposal, error) {
620+
return stub.signedProposal, nil
621+
}
622+
613623
// GetArgsSlice returns the arguments to the stub call as a byte array
614624
func (stub *ChaincodeStub) GetArgsSlice() ([]byte, error) {
615625
args := stub.GetArgs()

core/chaincode/shim/interfaces.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type ChaincodeStubInterface interface {
102102
// key values across time. GetHistoryForKey is intended to be used for read-only queries.
103103
GetHistoryForKey(key string) (HistoryQueryIteratorInterface, error)
104104

105-
// GetCreator returns SignatureHeader.Creator of the proposal
105+
// GetCreator returns SignatureHeader.Creator of the signedProposal
106106
// this Stub refers to.
107107
GetCreator() ([]byte, error)
108108

@@ -116,6 +116,9 @@ type ChaincodeStubInterface interface {
116116
// GetBinding returns the transaction binding
117117
GetBinding() ([]byte, error)
118118

119+
// GetSignedProposal return the signed signedProposal this stub refers to.
120+
GetSignedProposal() (*pb.SignedProposal, error)
121+
119122
// GetArgsSlice returns the arguments to the stub call as a byte array
120123
GetArgsSlice() ([]byte, error)
121124

core/chaincode/shim/mockstub.go

+5
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ func (stub *MockStub) GetBinding() ([]byte, error) {
270270
return nil, nil
271271
}
272272

273+
// Not implemented
274+
func (stub *MockStub) GetSignedProposal() (*pb.SignedProposal, error) {
275+
return nil, nil
276+
}
277+
273278
// Not implemented
274279
func (stub *MockStub) GetArgsSlice() ([]byte, error) {
275280
return nil, nil

protos/peer/admin.pb.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/peer/chaincode_shim.pb.go

+50-49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/peer/chaincode_shim.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ message ChaincodeMessage {
5353
bytes payload = 3;
5454
string txid = 4;
5555

56-
Proposal proposal = 5;
56+
SignedProposal proposal = 5;
5757

5858
//event emmited by chaincode. Used only with Init or Invoke.
5959
// This event is then stored (currently)

0 commit comments

Comments
 (0)