Fabric CA创建用户机制的示例分析

这篇文章给大家分享的是有关Fabric CA创建用户机制的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

在研究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创建用户机制的示例分析  fabric 第1张

命令如下:

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,结果如下:

Fabric CA创建用户机制的示例分析  fabric 第2张

然后我们尝试用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

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

Fabric CA创建用户机制的示例分析  fabric 第3张

  • 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

结果同上:

Fabric CA创建用户机制的示例分析  fabric 第4张

  • 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

结果创建成功,如下:

Fabric CA创建用户机制的示例分析  fabric 第5张

其他几个布尔类型属性,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/browse/FAB-7882

相关资料截图:

Fabric CA创建用户机制的示例分析  fabric 第6张

Fabric CA创建用户机制的示例分析  fabric 第7张

Fabric CA创建用户机制的示例分析  fabric 第8张

Fabric CA创建用户机制的示例分析  fabric 第9张

Fabric CA创建用户机制的示例分析  fabric 第10张

用 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

结果创建失败,如下:

Fabric CA创建用户机制的示例分析  fabric 第11张

可以继续往下测试,可以发现,当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

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

Fabric CA创建用户机制的示例分析  fabric 第12张

子 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=*,还是创建失败,结果如图

Fabric CA创建用户机制的示例分析  fabric 第13张

再尝试用 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

创建成功,结果如图

Fabric CA创建用户机制的示例分析  fabric 第14张

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

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

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

相关代码

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

Fabric CA创建用户机制的示例分析  fabric 第15张Fabric CA创建用户机制的示例分析  fabric 第16张

感谢各位的阅读!关于“Fabric CA创建用户机制的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接