Skip to content

Commit 4a012bf

Browse files
committed
Added log messages in access control and proof verification
Signed-off-by: sandeep.nishad1 <[email protected]>
1 parent 0819572 commit 4a012bf

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

core/network/fabric-interop-cc/contracts/interop/access_control_cc.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,27 @@ func verifyAccessToCC(s *SmartContract, ctx contractapi.TransactionContextInterf
137137
// TODO: Check if these will be the same format (Or convert to matching formats at some point)
138138
// TODO: Need to use principalType and perform different validation for type "certificate" and "ca".
139139
// Code below assumes that requestor's membership has already been authenticated earlier if the type is "ca"
140-
if (rule.PrincipalType == "certificate" && query.Certificate == rule.Principal) ||
141-
(rule.PrincipalType == "ca" && query.RequestingOrg == rule.Principal) {
140+
if (rule.PrincipalType == "certificate" && query.Certificate == rule.Principal) {
142141
// Break loop as cert is valid.
142+
log.Infof("Access Control Policy PERMITS the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.Certificate)
143+
return nil
144+
}
145+
if (rule.PrincipalType == "ca" && query.RequestingOrg == rule.Principal) {
146+
// Break loop as cert is valid.
147+
log.Infof("Access Control Policy PERMITS the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.RequestingOrg)
143148
return nil
144149
}
145150
}
146151

147152
}
148-
errorMessage := fmt.Sprintf("Access Control Policy DOES NOT PERMIT the following request: %s", viewAddressString)
153+
var errorMessage string
154+
if (query.Certificate != "") {
155+
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.Certificate)
156+
} else if (query.RequestingOrg != "") {
157+
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from '%s:%s'", viewAddressString, query.RequestingNetwork, query.RequestingOrg)
158+
} else {
159+
errorMessage = fmt.Sprintf("Access Control Policy DOES NOT PERMIT the request '%s' from a foreign entity", viewAddressString)
160+
}
149161
log.Error(errorMessage)
150162
return errors.New(errorMessage)
151163

core/network/fabric-interop-cc/contracts/interop/write_external_state.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (s *SmartContract) ParseAndValidateView(ctx contractapi.TransactionContextI
7070
// 1. Verify proof
7171
err = s.VerifyView(ctx, b64ViewProto, address)
7272
if err != nil {
73+
log.Errorf("Proof obtained from foreign network for query '%s' is INVALID", address)
7374
return nil, fmt.Errorf("VerifyView error: %s", err)
7475
}
7576

@@ -149,7 +150,7 @@ func (s *SmartContract) VerifyView(ctx contractapi.TransactionContextInterface,
149150
case common.Meta_CORDA:
150151
switch view.Meta.ProofType {
151152
case "Notarization":
152-
return verifyCordaNotarization(s, ctx, view.Data, verificationPolicy, addressStruct.LedgerSegment)
153+
return verifyCordaNotarization(s, ctx, view.Data, verificationPolicy, addressStruct.LedgerSegment, address)
153154
default:
154155
return fmt.Errorf("Proof type not supported: %s", view.Meta.ProofType)
155156
}
@@ -180,7 +181,7 @@ func (s *SmartContract) VerifyView(ctx contractapi.TransactionContextInterface,
180181
// 3. Verify each of the signatures in the Notarization array according to the data bytes and certificate.
181182
// 4. Check the certificates are valid according to the Membership.
182183
// 5. Check the notarizations fulfill the verification policy of the request.
183-
func verifyCordaNotarization(s *SmartContract, ctx contractapi.TransactionContextInterface, data []byte, verificationPolicy *common.Policy, securityDomain string) error {
184+
func verifyCordaNotarization(s *SmartContract, ctx contractapi.TransactionContextInterface, data []byte, verificationPolicy *common.Policy, securityDomain, address string) error {
184185
var cordaViewData corda.ViewData
185186
err := protoV2.Unmarshal(data, &cordaViewData)
186187
if err != nil {
@@ -222,6 +223,7 @@ func verifyCordaNotarization(s *SmartContract, ctx contractapi.TransactionContex
222223
return fmt.Errorf("Notarizations missing signer: %s", signer)
223224
}
224225
}
226+
log.Infof("Proof associated with response '%s' from Corda network for query '%s' is VALID", string(cordaViewData.Payload), address)
225227
return nil
226228
}
227229

@@ -294,5 +296,6 @@ func verifyFabricNotarization(s *SmartContract, ctx contractapi.TransactionConte
294296
return fmt.Errorf("Notarizations missing signer: %s", signer)
295297
}
296298
}
299+
log.Infof("Proof associated with response '%s' from Fabric network for query '%s' is VALID", string(fabricViewData.Response.Payload), address)
297300
return nil
298301
}

0 commit comments

Comments
 (0)