@@ -20,6 +20,7 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
23
+ "github.com/hyperledger/fabric/common/cauthdsl"
23
24
"github.com/hyperledger/fabric/core/chaincode/shim"
24
25
"github.com/hyperledger/fabric/core/peer/msp"
25
26
"github.com/hyperledger/fabric/protos/common"
@@ -48,20 +49,26 @@ func (vscc *ValidatorOneValidSignature) Init(stub shim.ChaincodeStubInterface) (
48
49
// policy specification to be coded as a transaction of the chaincode and the client
49
50
// selecting which policy to use for validation using parameter function
50
51
// @return serialized Block of valid and invalid transactions indentified
51
- // Note that Peer calls this function with 2 arguments, where args[0] is the
52
- // function name and args[1] is the Envelope
52
+ // Note that Peer calls this function with 3 arguments, where args[0] is the
53
+ // function name, args[1] is the Envelope and args[2] is the validation policy
53
54
func (vscc * ValidatorOneValidSignature ) Invoke (stub shim.ChaincodeStubInterface ) ([]byte , error ) {
55
+ // TODO: document the argument in some white paper or design document
54
56
// args[0] - function name (not used now)
55
57
// args[1] - serialized Envelope
58
+ // args[2] - serialized policy
56
59
args := stub .GetArgs ()
57
- if len (args ) < 2 {
60
+ if len (args ) < 3 {
58
61
return nil , errors .New ("Incorrect number of arguments" )
59
62
}
60
63
61
64
if args [1 ] == nil {
62
65
return nil , errors .New ("No block to validate" )
63
66
}
64
67
68
+ if args [2 ] == nil {
69
+ return nil , errors .New ("No policy supplied" )
70
+ }
71
+
65
72
logger .Infof ("VSCC invoked" )
66
73
67
74
// get the envelope...
@@ -78,6 +85,15 @@ func (vscc *ValidatorOneValidSignature) Invoke(stub shim.ChaincodeStubInterface)
78
85
return nil , err
79
86
}
80
87
88
+ // get the policy
89
+ mgr := mspmgmt .GetManagerForChain (payl .Header .ChainHeader .ChainID )
90
+ pProvider := cauthdsl .NewPolicyProvider (mgr )
91
+ policy , err := pProvider .NewPolicy (args [2 ])
92
+ if err != nil {
93
+ logger .Errorf ("VSCC error: pProvider.NewPolicy failed, err %s" , err )
94
+ return nil , err
95
+ }
96
+
81
97
// validate the payload type
82
98
if common .HeaderType (payl .Header .ChainHeader .Type ) != common .HeaderType_ENDORSER_TRANSACTION {
83
99
logger .Errorf ("Only Endorser Transactions are supported, provided type %d" , payl .Header .ChainHeader .Type )
@@ -99,29 +115,29 @@ func (vscc *ValidatorOneValidSignature) Invoke(stub shim.ChaincodeStubInterface)
99
115
return nil , err
100
116
}
101
117
102
- // this is what is being signed
118
+ // this is the first part of the signed message
103
119
prespBytes := cap .Action .ProposalResponsePayload
104
120
105
- // loop through each of the endorsements
106
- for _ , endorsement := range cap .Action .Endorsements {
107
- // extract the identity of the signer
108
- end , err := mspmgmt .GetManagerForChain (payl .Header .ChainHeader .ChainID ).DeserializeIdentity (endorsement .Endorser )
109
- if err != nil {
110
- logger .Errorf ("VSCC error: DeserializeIdentity failed, err %s" , err )
111
- return nil , err
112
- }
113
-
114
- // validate it
115
- err = end .Validate ()
116
- if err != nil {
117
- return nil , fmt .Errorf ("Invalid endorser identity, err %s" , err )
121
+ // build the signature set for the evaluation
122
+ signatureSet := make ([]* common.SignedData , len (cap .Action .Endorsements ))
123
+
124
+ // loop through each of the endorsements and build the signature set
125
+ for i , endorsement := range cap .Action .Endorsements {
126
+ signatureSet [i ] = & common.SignedData {
127
+ // set the data that is signed; concatenation of proposal response bytes and endorser ID
128
+ Data : append (prespBytes , endorsement .Endorser ... ),
129
+ // set the identity that signs the message: it's the endorser
130
+ Identity : endorsement .Endorser ,
131
+ // set the signature
132
+ Signature : endorsement .Signature ,
118
133
}
134
+ }
119
135
120
- // verify the signature
121
- err = end . Verify ( append ( prespBytes , endorsement . Endorser ... ), endorsement . Signature )
122
- if err != nil {
123
- return nil , fmt .Errorf ("Invalid signature , err %s" , err )
124
- }
136
+ // evaluate the signature set against the policy
137
+ err = policy . Evaluate ( signatureSet )
138
+ if err != nil {
139
+ logger .Errorf ("VSCC error: policy evaluation failed , err %s" , err )
140
+ return nil , err
125
141
}
126
142
}
127
143
0 commit comments