新西兰服务器

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


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

发布时间:2021-12-25 12:28:57 来源:高防服务器网 阅读:86 作者:小新 栏目:互联网科技

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

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

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

Name Type Description
hf.Registrar.Roles List List of roles that the registrar is allowed to manage
hf.Registrar.DelegateRoles List List of roles that the registrar is allowed to give to a registree for its ‘hf.Registrar.Roles’ attribute
hf.Registrar.Attributes List List of attributes that registrar is allowed to register
hf.GenCRL Boolean Identity is able to generate CRL if attribute value is true
hf.Revoker Boolean Identity is able to revoke a user and/or certificates if attribute value is true
hf.AffiliationMgr Boolean Identity is able to manage affiliations if attribute value is true
hf.IntermediateCA Boolean Identity 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/browse/FAB-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

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

[微信提示:高防服务器能助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

[图文来源于网络,不代表本站立场,如有侵权,请联系高防服务器网删除]
[