资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

FabricCA创建用户机制的示例分析

这篇文章给大家分享的是有关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-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创建用户机制的示例分析

然后我们尝试用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创建用户机制的示例分析

  • 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创建用户机制的示例分析

  • 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创建用户机制的示例分析

其他几个布尔类型属性,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 CA创建用户机制的示例分析

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

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

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

用 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创建用户机制的示例分析

可以继续往下测试,可以发现,当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创建用户机制的示例分析

子 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创建用户机制的示例分析

再尝试用 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创建用户机制的示例分析

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

  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 CA创建用户机制的示例分析

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


当前名称:FabricCA创建用户机制的示例分析
分享路径:http://cdkjz.cn/article/gdgggs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220