@@ -161,9 +161,9 @@ func (handler *Handler) deleteRangeQueryIterator(txContext *transactionContext,
161
161
delete (txContext .rangeQueryIteratorMap , txid )
162
162
}
163
163
164
- //THIS CAN BE REMOVED ONCE WE SUPPORT CONFIDENTIALITY WITH CC-CALLING-CC
165
- //we dissallow chaincode-chaincode interactions till confidentiality implications are understood
166
- func (handler * Handler ) canCallChaincode (txid string ) * pb.ChaincodeMessage {
164
+ //THIS CAN BE REMOVED ONCE WE FULL SUPPORT (Invoke and Query) CONFIDENTIALITY WITH CC-CALLING-CC
165
+ //Only invocation are allowed, not queries
166
+ func (handler * Handler ) canCallChaincode (txid string , isQuery bool ) * pb.ChaincodeMessage {
167
167
secHelper := handler .chaincodeSupport .getSecHelper ()
168
168
if secHelper == nil {
169
169
return nil
@@ -176,7 +176,9 @@ func (handler *Handler) canCallChaincode(txid string) *pb.ChaincodeMessage {
176
176
} else if txctx .transactionSecContext == nil {
177
177
errMsg = fmt .Sprintf ("[%s]Error transaction context is nil while checking for confidentiality. Sending %s" , shorttxid (txid ), pb .ChaincodeMessage_ERROR )
178
178
} else if txctx .transactionSecContext .ConfidentialityLevel != pb .ConfidentialityLevel_PUBLIC {
179
- errMsg = fmt .Sprintf ("[%s]Error chaincode-chaincode interactions not supported for with privacy enabled. Sending %s" , shorttxid (txid ), pb .ChaincodeMessage_ERROR )
179
+ if isQuery {
180
+ errMsg = fmt .Sprintf ("[%s]Error chaincode-chaincode interactions not supported for with privacy enabled. Sending %s" , shorttxid (txid ), pb .ChaincodeMessage_ERROR )
181
+ }
180
182
}
181
183
182
184
if errMsg != "" {
@@ -209,10 +211,12 @@ func (handler *Handler) encryptOrDecrypt(encrypt bool, txid string, payload []by
209
211
var err error
210
212
if txctx .transactionSecContext .Type == pb .Transaction_CHAINCODE_DEPLOY {
211
213
if enc , err = secHelper .GetStateEncryptor (handler .deployTXSecContext , handler .deployTXSecContext ); err != nil {
214
+ chaincodeLogger .Errorf ("error getting crypto encryptor for deploy tx :%s" , err )
212
215
return nil , fmt .Errorf ("error getting crypto encryptor for deploy tx :%s" , err )
213
216
}
214
217
} else if txctx .transactionSecContext .Type == pb .Transaction_CHAINCODE_INVOKE || txctx .transactionSecContext .Type == pb .Transaction_CHAINCODE_QUERY {
215
218
if enc , err = secHelper .GetStateEncryptor (handler .deployTXSecContext , txctx .transactionSecContext ); err != nil {
219
+ chaincodeLogger .Errorf ("error getting crypto encryptor %s" , err )
216
220
return nil , fmt .Errorf ("error getting crypto encryptor %s" , err )
217
221
}
218
222
} else {
@@ -1046,7 +1050,9 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
1046
1050
err = ledgerObj .DeleteState (chaincodeID , key )
1047
1051
} else if msg .Type .String () == pb .ChaincodeMessage_INVOKE_CHAINCODE .String () {
1048
1052
//check and prohibit C-call-C for CONFIDENTIAL txs
1049
- if triggerNextStateMsg = handler .canCallChaincode (msg .Txid ); triggerNextStateMsg != nil {
1053
+ chaincodeLogger .Debugf ("[%s] C-call-C" , shorttxid (msg .Txid ))
1054
+
1055
+ if triggerNextStateMsg = handler .canCallChaincode (msg .Txid , false ); triggerNextStateMsg != nil {
1050
1056
return
1051
1057
}
1052
1058
chaincodeSpec := & pb.ChaincodeSpec {}
@@ -1060,12 +1066,21 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
1060
1066
1061
1067
// Get the chaincodeID to invoke
1062
1068
newChaincodeID := chaincodeSpec .ChaincodeID .Name
1069
+ chaincodeLogger .Debugf ("[%s] C-call-C %s" , shorttxid (msg .Txid ), newChaincodeID )
1063
1070
1064
1071
// Create the transaction object
1065
1072
chaincodeInvocationSpec := & pb.ChaincodeInvocationSpec {ChaincodeSpec : chaincodeSpec }
1066
1073
transaction , _ := pb .NewChaincodeExecute (chaincodeInvocationSpec , msg .Txid , pb .Transaction_CHAINCODE_INVOKE )
1067
1074
1068
- // Launch the new chaincode if not already running
1075
+ tsc := handler .getTxContext (msg .Txid ).transactionSecContext
1076
+
1077
+ transaction .Nonce = tsc .Nonce
1078
+ transaction .ConfidentialityLevel = tsc .ConfidentialityLevel
1079
+ transaction .ConfidentialityProtocolVersion = tsc .ConfidentialityProtocolVersion
1080
+ transaction .Metadata = tsc .Metadata
1081
+ transaction .Cert = tsc .Cert
1082
+
1083
+ // cd the new chaincode if not already running
1069
1084
_ , chaincodeInput , launchErr := handler .chaincodeSupport .Launch (context .Background (), transaction )
1070
1085
if launchErr != nil {
1071
1086
payload := []byte (launchErr .Error ())
@@ -1217,7 +1232,7 @@ func (handler *Handler) initializeSecContext(tx, depTx *pb.Transaction) error {
1217
1232
return nil
1218
1233
}
1219
1234
1220
- func (handler * Handler ) setChaincodeSecurityContext (tx * pb.Transaction , msg * pb.ChaincodeMessage ) error {
1235
+ func (handler * Handler ) setChaincodeSecurityContext (tx , depTx * pb.Transaction , msg * pb.ChaincodeMessage ) error {
1221
1236
chaincodeLogger .Debug ("setting chaincode security context..." )
1222
1237
if msg .SecurityContext == nil {
1223
1238
msg .SecurityContext = & pb.ChaincodeSecurityContext {}
@@ -1248,6 +1263,13 @@ func (handler *Handler) setChaincodeSecurityContext(tx *pb.Transaction, msg *pb.
1248
1263
return err
1249
1264
}
1250
1265
1266
+ msg .SecurityContext .Payload = ctorMsgRaw
1267
+ // TODO: add deploy metadata
1268
+ if depTx != nil {
1269
+ msg .SecurityContext .ParentMetadata = depTx .Metadata
1270
+ } else {
1271
+ msg .SecurityContext .ParentMetadata = handler .deployTXSecContext .Metadata
1272
+ }
1251
1273
msg .SecurityContext .Payload = ctorMsgRaw
1252
1274
msg .SecurityContext .TxTimestamp = tx .Timestamp
1253
1275
}
@@ -1289,7 +1311,7 @@ func (handler *Handler) initOrReady(txid string, initArgs [][]byte, tx *pb.Trans
1289
1311
}
1290
1312
1291
1313
//if security is disabled the context elements will just be nil
1292
- if err := handler .setChaincodeSecurityContext (tx , ccMsg ); err != nil {
1314
+ if err := handler .setChaincodeSecurityContext (tx , depTx , ccMsg ); err != nil {
1293
1315
return nil , err
1294
1316
}
1295
1317
@@ -1317,7 +1339,7 @@ func (handler *Handler) handleQueryChaincode(msg *pb.ChaincodeMessage) {
1317
1339
}()
1318
1340
1319
1341
//check and prohibit C-call-C for CONFIDENTIAL txs
1320
- if serialSendMsg = handler .canCallChaincode (msg .Txid ); serialSendMsg != nil {
1342
+ if serialSendMsg = handler .canCallChaincode (msg .Txid , true ); serialSendMsg != nil {
1321
1343
return
1322
1344
}
1323
1345
@@ -1337,6 +1359,16 @@ func (handler *Handler) handleQueryChaincode(msg *pb.ChaincodeMessage) {
1337
1359
chaincodeInvocationSpec := & pb.ChaincodeInvocationSpec {ChaincodeSpec : chaincodeSpec }
1338
1360
transaction , _ := pb .NewChaincodeExecute (chaincodeInvocationSpec , msg .Txid , pb .Transaction_CHAINCODE_QUERY )
1339
1361
1362
+ tsc := handler .getTxContext (msg .Txid ).transactionSecContext
1363
+
1364
+ transaction .Nonce = tsc .Nonce
1365
+ transaction .ConfidentialityLevel = tsc .ConfidentialityLevel
1366
+ transaction .ConfidentialityProtocolVersion = tsc .ConfidentialityProtocolVersion
1367
+ transaction .Metadata = tsc .Metadata
1368
+ transaction .Cert = tsc .Cert
1369
+
1370
+ chaincodeLogger .Debugf ("[%s]Invoking another chaincode" , shorttxid (msg .Txid ))
1371
+
1340
1372
// Launch the new chaincode if not already running
1341
1373
_ , chaincodeInput , launchErr := handler .chaincodeSupport .Launch (context .Background (), transaction )
1342
1374
if launchErr != nil {
@@ -1466,7 +1498,7 @@ func (handler *Handler) sendExecuteMessage(msg *pb.ChaincodeMessage, tx *pb.Tran
1466
1498
}
1467
1499
1468
1500
//if security is disabled the context elements will just be nil
1469
- if err := handler .setChaincodeSecurityContext (tx , msg ); err != nil {
1501
+ if err := handler .setChaincodeSecurityContext (tx , nil , msg ); err != nil {
1470
1502
return nil , err
1471
1503
}
1472
1504
0 commit comments