Fabric CA 创建用户机制研究


声明:本文转载自https://my.oschina.net/sumier/blog/1820680,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

近期在研究Fabric CA 创建用户,的时候发现很多隐含规则

通过官方文档,我们知道 fabric-ca 可以带有如下几个以hf.开头的属性,我们暂且称之为系统属性

NameTypeDescription
hf.Registrar.RolesListList of roles that the registrar is allowed to manage
hf.Registrar.DelegateRolesListList of roles that the registrar is allowed to give to a registree for its ‘hf.Registrar.Roles’ attribute
hf.Registrar.AttributesListList of attributes that registrar is allowed to register
hf.GenCRLBooleanIdentity is able to generate CRL if attribute value is true
hf.RevokerBooleanIdentity is able to revoke a user and/or certificates if attribute value is true
hf.AffiliationMgrBooleanIdentity is able to manage affiliations if attribute value is true
hf.IntermediateCABooleanIdentity is able to enroll as an intermediate CA if attribute value is true

现象一:Boolean类型系统属性

首先,我们用admin创建账户test_a,

输入图片说明

命令如下:

fabric-ca-client register -d \ --id.name test_a \ --id.secret test_a_pw \ --id.type client \ --id.affiliation easypay.fabric \ --id.attrs '"hf.Registrar.Roles=client,user"' \ --id.attrs '"hf.Registrar.DelegateRoles=client,user"' \ --id.attrs '"hf.Registrar.Attributes=*"' \ --id.attrs hf.Revoker=true \ --id.attrs hf.AffiliationMgr=true \ --id.attrs hf.IntermediateCA=true \ --id.attrs hf.GenCRL=false 

即,设置test_a用户hf.GenCRL=false,结果如下:

输入图片说明

然后我们尝试用test_a账户分别创建以下几个账户(注意是用test_a账户,而不是admin账户)

  • test_a_a,设置test_a_a用户hf.GenCRL=true:
fabric-ca-client register -d \ --id.name test_a_a \ --id.secret test_a_a_pw \ --id.type client \ --id.affiliation easypay.fabric \ --id.attrs '"hf.Registrar.Roles=client,user"' \ --id.attrs '"hf.Registrar.DelegateRoles=client,user"' \ --id.attrs '"hf.Registrar.Attributes=*"' \ --id.attrs hf.Revoker=true \ --id.attrs hf.AffiliationMgr=true \ --id.attrs hf.IntermediateCA=true \ --id.attrs hf.GenCRL=true  

结果创建失败,会报权限错误,如下所示:

输入图片说明

  • test_a_b,设置test_a_b用户hf.GenCRL=false:
fabric-ca-client register -d \ --id.name test_a_b \ --id.secret test_a_b_pw \ --id.type client \ --id.affiliation easypay.fabric \ --id.attrs '"hf.Registrar.Roles=client,user"' \ --id.attrs '"hf.Registrar.DelegateRoles=client,user"' \ --id.attrs '"hf.Registrar.Attributes=*"' \ --id.attrs hf.Revoker=true \ --id.attrs hf.AffiliationMgr=true \ --id.attrs hf.IntermediateCA=true \ --id.attrs hf.GenCRL=false 

结果同上:

输入图片说明

  • test_a_c,不设置test_a_c用户hf.GenCRL属性:
fabric-ca-client register -d \ --id.name test_a_c \ --id.secret test_a_c_pw \ --id.type client \ --id.affiliation easypay.fabric \ --id.attrs '"hf.Registrar.Roles=client,user"' \ --id.attrs '"hf.Registrar.DelegateRoles=client,user"' \ --id.attrs '"hf.Registrar.Attributes=*"' \ --id.attrs hf.Revoker=true \ --id.attrs hf.AffiliationMgr=true \ --id.attrs hf.IntermediateCA=true  

结果创建成功,如下:

输入图片说明

其他几个布尔类型属性,hf.Revoker,hf.AffiliationMgr,hf.IntermediateCA,都有类似现象,即,上级id这些布尔属性如果设置为false(或者不设置),则所创建是下级id都不能带有对应的这个几个布尔类型的系统属性

现象二:hf.Registrar.Roles的约束

刚才创建的test_a身份,id.type=client,hf.Registrar.Roles=client,user, 如果我们用test_a注册一个id.type=peer或者id.type=orderer的身份 结果会怎样呢?大家应该都想得到,肯定是失败,这里我就不做测试了

备注:fabric-ca 1.1 版本 hf.Registrar.Roles 属性只支持client,user,peer,orderer四种,1.2版本即将支持自定义角色,详见:https:/jira.hyperledger.org/browseFAB-7882

相关资料截图:

输入图片说明

输入图片说明

输入图片说明

输入图片说明

输入图片说明

用 test_a 用户创建一个 test_a_d身份,设置test_a_d属性hf.Registrar.Roles=client,user,peer ,如下:

fabric-ca-client register -d \ --id.name test_a_d \ --id.secret test_a_d_pw \ --id.type client \ --id.affiliation easypay.fabric \ --id.attrs '"hf.Registrar.Roles=client,user,peer"' \ --id.attrs '"hf.Registrar.DelegateRoles=client,user,peer"' \ --id.attrs '"hf.Registrar.Attributes=*"' \ --id.attrs hf.Revoker=true \ --id.attrs hf.AffiliationMgr=true \ --id.attrs hf.IntermediateCA=true 

结果创建失败,如下:

输入图片说明

可以继续往下测试,可以发现,当test_a身份的属性hf.Registrar.Roles=client,user ,往下用test_a身份创建的子身份的f.Registrar.Roles属性值都不能超过client,user的范围

再用 test_a 用户创建一个 test_a_e身份,设置test_a_e 属性id.type=peer ,如下:

fabric-ca-client register -d \ --id.name test_a_e \ --id.secret test_a_e_pw \ --id.type peer \ --id.affiliation easypay.fabric \ --id.attrs '"hf.Registrar.Roles=client,user"' \ --id.attrs '"hf.Registrar.DelegateRoles=client,user"' \ --id.attrs '"hf.Registrar.Attributes=*"' \ --id.attrs hf.Revoker=true \ --id.attrs hf.AffiliationMgr=true \ --id.attrs hf.IntermediateCA=true 

结果创建失败,错误信息如下:

输入图片说明

子 id 的id.type属性值也受到上级id的hf.Registrar.Roles属性值的约束

现象三:hf.Registrar.Attributes 属性的约束

尝试用 admin 身份 创建 test_b ,添加hf.key=value

fabric-ca-client register -d \ --id.name test_b \ --id.secret test_b_pw \ --id.type client \ --id.attrs hf.key=value 

即使admin身份hf.Registrar.Attributes=*,还是创建失败,结果如图

输入图片说明

再尝试用 admin 身份 创建 test_c,添加hf=value

fabric-ca-client register -d \ --id.name test_c \ --id.secret test_c_pw \ --id.type client \ --id.attrs hf=value 

创建成功,结果如图

输入图片说明

总结下来,有以下几点规律:

  1. 上级id的hf.Registrar.Attributes值可以约束它所创建的子级id能添加的属性,但是带hf.的除外,带hf.开头的会被当做系统属性,区别对待

  2. 从上级往下,所带的属性约束只能是逐渐收敛的,不能发散

相关代码

感兴趣可以详细研究一下源代码 相关部分代码可以参见:https://github.com/hyperledger/fabric-ca/blob/release-1.1/lib/attr/attribute.go

输入图片说明 输入图片说明

本文发表于2018年05月29日 20:00
(c)注:本文转载自https://my.oschina.net/sumier/blog/1820680,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 1983 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1