Search code examples
hyperledger-fabrichyperledgerhyperledger-chaincode

Restrict invoke access for members at fabric chaincode level


I am trying to restrict invoke access for members dynamically in chaincode level and had found this method in a tutorial "stub.GetCallerCertificate" but getting an error.

Error:stub.GetCallerCertificate undefined (type shim.ChaincodeStubInterface has no field or method GetCallerCertificate)

Could you please tell what mistake I made in the code and if possible please provide some working example for restricting access to members in chaincode level (only for invoking transactions, Just like checking for msg.sender in solidity)?

Chaincode language : Go

Code:

 xx, err1 := stub.GetCallerCertificate()
   if err1 != nil {
       matchLogger.Info(err1)
   }
   matchLogger.Info("Cert ----")
   matchLogger.Info(string(xx))

Solution

  • GetCallerCertificate was probably the api for hyperledger fabric 0.6. In Hyperledger fabric V1 you can use the GetCreator call on the stub or use the ClientIdentity library which is referenced in this section of the hyperledger fabric docs.

    Attribute-based access control is just one way you can perform access control. You can do it in other ways including making use of the certificate information which the cid library allows you to access.