在结构链代码级别限制成员的调用访问

Restrict invoke access for members at fabric chaincode level

我试图在链代码级别动态限制成员的调用访问,并且在 tutorial 中找到了这个方法 "stub.GetCallerCertificate" 但出现错误。

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

你能告诉我我在代码中犯了什么错误吗?如果可能的话,请提供一些在链代码级别限制对成员访问的工作示例(仅用于调用事务,就像在 solidity 中检查 msg.sender 一样) ?

链码语言:Go

代码:

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

GetCallerCertificate 可能是 hyperledger fabric 0.6 的 api。在 Hyperledger fabric V1 中,您可以在存根上使用 GetCreator 调用或使用在 hyperledger fabric 文档的 this section 中引用的 ClientIdentity 库。

基于属性的访问控制只是您可以执行访问控制的一种方式。您可以通过其他方式做到这一点,包括使用 cid 库允许您访问的证书信息。

这是我从 node.js 那里得到的示例,可能会对您有所帮助。

async function getInvokerID(stub) {
    let cid=new ClientIdentity(stub)
    let id = cid.getID(); // X509 Certificate invoker is in CN form
    console.log(id)
    let attributeValue=cid.getAttributeValue("attributeName")
    console.log(attributeValue)
    let CN = id.substring(id.indexOf("CN=") + 3, id.lastIndexOf("::"));
    return attributeValue;
}