简体   繁体   English

识别Hyperledger Fabric V1.0链码中的调用同级/组织

[英]Identify invoking peer/organisation inside Hyperledger Fabric V1.0 chaincode

有什么方法可以知道Hyperledger Fabric V1.0的 golang 代码中的调用方和组织吗?

Currently all API's available for chaincode is described in interface.go file. 当前,在interface.go文件中描述了可用于链码的所有API。 At the moment there is no API which will allow you to identify invoking peer and organization inside the chaincode. 目前尚无API可让您识别链码中的调用方和组织。 I think the main reason for that is that chaincode has to be agnostic to that type of information, since all ACL's managed by the peer and chaincode should stay agnostic to it, preserve deterministic behavior regardless of whoever invoking it and be stateless. 我认为这样做的主要原因是链码必须与该类型的信息无关,因为由对等方和链码管理的所有ACL均应与之无关,无论谁调用它且无状态,都应保持确定性行为。

If need you probably could try to leverage the identity of the client who created transaction proposal request, by using GetCreator API: 如果需要,您可以尝试使用GetCreator API来利用创建交易建议请求的客户的身份:

    // GetCreator returns `SignatureHeader.Creator` (e.g. an identity)
    // of the `SignedProposal`. This is the identity of the agent (or user)
    // submitting the transaction.
    GetCreator() ([]byte, error)

And then to parse client certificate to learn about the client, also you can also consider to use transient fields to make client to put there relevant information which could be read by chaincode later: 然后要解析客户端证书以了解客户端,也可以考虑使用瞬态字段使客户端将相关信息放置在那里,稍后链码可以读取这些信息:

// GetTransient returns the `ChaincodeProposalPayload.Transient` field.
// It is a map that contains data (e.g. cryptographic material)
// that might be used to implement some form of application-level
// confidentiality. The contents of this field, as prescribed by
// `ChaincodeProposalPayload`, are supposed to always
// be omitted from the transaction and excluded from the ledger.
GetTransient() (map[string][]byte, error)

In fabric 1.1, there seems a new lib cid can reach to your requirements. 在结构1.1中,似乎有一个新的lib cid可以满足您的要求。

Getting the client's ID 获取客户的ID

// GetID returns the ID associated with the invoking identity.  This ID
// is guaranteed to be unique within the MSP.
func GetID(stub ChaincodeStubInterface) (string, error) 

Getting the MSP ID 获取MSP ID

// GetMSPID returns the ID of the MSP associated with the identity that
// submitted the transaction
func GetMSPID(stub ChaincodeStubInterface) (string, error)

For full information your can refer Client Identity Chaincode Library 有关完整的信息,您可以参考客户端身份链代码库

The client identity chaincode library enables developers to write chaincode which makes access control decisions based on the identity of the client (ie the invoker of the chaincode). 客户端身份链码库使开发人员能够编写链码,该链码基于客户端(即链码的调用者)的身份来做出访问控制决策。

You can get the id of the calling client by using GetID function available in the cid package. 您可以使用cid包中提供的GetID函数来获取调用客户端的ID。

Few other functions available that you may find useful in the above-mentioned package are: 在上述软件包中,您几乎找不到有用的其他功能:

  • GetX509Certificate It can be used to get the X509 certificate of the client. GetX509Certificate可以用来获取客户端的X509证书。
  • GetAttributeValue to get the attributes that were associated with the client during the time of his registration. GetAttributeValue获取在客户端注册期间与客户端关联的属性。

Other than the functions available in cid package, you may find these functions helpful too. 除了cid软件包中可用的功能外,您可能还会发现这些功能也很有帮助。

  • GetSignedProposal It returns the signed proposal object, which contains all data elements part of a transaction proposal. GetSignedProposal它返回签名的投标对象,该对象包含交易投标的所有数据元素。
  • GetCreator It returns SignatureHeader.Creator (eg an identity) of the SignedProposal . GetCreator它返回SignatureHeader.Creator的(例如身份) SignedProposal This is the identity of the agent (or user) submitting the transaction. 这是提交事务的代理(或用户)的身份。

I ended up on this question by looking for a way to restrict non-members of private data collections to query private data from a peer. 最后,我通过寻找一种方法来限制非私有数据集合的成员来从对等方查询私有数据来解决这个问题。 I was considering adding a verifier in the chaincode to see if the client belonged to the same organization as the peer. 我正在考虑在链码中添加一个验证器,以查看客户端是否与对等方属于同一组织。

If you are looking to do the same, use the memberOnlyRead attribute when creating the private data collection. 如果要执行相同的操作,请在创建私有数据集合时使用memberOnlyRead属性。 You might be able to build more advanced restrictions using this technique. 您可能可以使用此技术建立更高级的限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM