新聞中心
這篇文章給大家分享的是有關(guān)Fabric CA創(chuàng)建用戶(hù)機(jī)制的示例分析的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
創(chuàng)新互聯(lián)公司的客戶(hù)來(lái)自各行各業(yè),為了共同目標(biāo),我們?cè)诠ぷ魃厦芮信浜希瑥膭?chuàng)業(yè)型小企業(yè)到企事業(yè)單位,感謝他們對(duì)我們的要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶(hù)帶來(lái)驚喜。專(zhuān)業(yè)領(lǐng)域包括網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、電商網(wǎng)站開(kāi)發(fā)、微信營(yíng)銷(xiāo)、系統(tǒng)平臺(tái)開(kāi)發(fā)。
在研究Fabric CA 創(chuàng)建用戶(hù),的時(shí)候發(fā)現(xiàn)很多隱含規(guī)則
通過(guò)官方文檔,我們知道 fabric-ca 可以帶有如下幾個(gè)以hf.
開(kāi)頭的屬性,我們暫且稱(chēng)之為系統(tǒng)屬性
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 |
現(xiàn)象一:Boolean類(lèi)型系統(tǒng)屬性
首先,我們用admin創(chuàng)建賬戶(hù)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
即,設(shè)置test_a用戶(hù)hf.GenCRL=false
,結(jié)果如下:
然后我們嘗試用test_a
賬戶(hù)分別創(chuàng)建以下幾個(gè)賬戶(hù)(注意是用test_a
賬戶(hù),而不是admin
賬戶(hù))
test_a_a,設(shè)置test_a_a用戶(hù)
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
結(jié)果創(chuàng)建失敗,會(huì)報(bào)權(quán)限錯(cuò)誤,如下所示:
test_a_b,設(shè)置test_a_b用戶(hù)
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
結(jié)果同上:
test_a_c,不設(shè)置test_a_c用戶(hù)
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
結(jié)果創(chuàng)建成功,如下:
其他幾個(gè)布爾類(lèi)型屬性,hf.Revoker
,hf.AffiliationMgr
,hf.IntermediateCA
,都有類(lèi)似現(xiàn)象,即,上級(jí)id這些布爾屬性如果設(shè)置為false(或者不設(shè)置),則所創(chuàng)建是下級(jí)id都不能帶有對(duì)應(yīng)的這個(gè)幾個(gè)布爾類(lèi)型的系統(tǒng)屬性
現(xiàn)象二:hf.Registrar.Roles
的約束
剛才創(chuàng)建的test_a身份,id.type=client
,hf.Registrar.Roles=client,user
, 如果我們用test_a注冊(cè)一個(gè)id.type=peer
或者id.type=orderer
的身份 結(jié)果會(huì)怎樣呢?大家應(yīng)該都想得到,肯定是失敗,這里我就不做測(cè)試了
備注:fabric-ca 1.1 版本 hf.Registrar.Roles
屬性只支持client,user,peer,orderer
四種,1.2版本即將支持自定義角色,詳見(jiàn):https://jira.hyperledger.org/browse/FAB-7882
相關(guān)資料截圖:
用 test_a 用戶(hù)創(chuàng)建一個(gè) test_a_d身份,設(shè)置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
結(jié)果創(chuàng)建失敗,如下:
可以繼續(xù)往下測(cè)試,可以發(fā)現(xiàn),當(dāng)test_a身份的屬性hf.Registrar.Roles=client,user
,往下用test_a身份創(chuàng)建的子身份的f.Registrar.Roles
屬性值都不能超過(guò)client,user
的范圍
再用 test_a 用戶(hù)創(chuàng)建一個(gè) test_a_e身份,設(shè)置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
結(jié)果創(chuàng)建失敗,錯(cuò)誤信息如下:
子 id 的id.type
屬性值也受到上級(jí)id的hf.Registrar.Roles
屬性值的約束
現(xiàn)象三:hf.Registrar.Attributes
屬性的約束
嘗試用 admin 身份 創(chuàng)建 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=*
,還是創(chuàng)建失敗,結(jié)果如圖
再?lài)L試用 admin 身份 創(chuàng)建 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
創(chuàng)建成功,結(jié)果如圖
總結(jié)下來(lái),有以下幾點(diǎn)規(guī)律:
上級(jí)id的
hf.Registrar.Attributes
值可以約束它所創(chuàng)建的子級(jí)id能添加的屬性,但是帶hf.
的除外,帶hf.
開(kāi)頭的會(huì)被當(dāng)做系統(tǒng)屬性,區(qū)別對(duì)待從上級(jí)往下,所帶的屬性約束只能是逐漸收斂的,不能發(fā)散
相關(guān)代碼
感興趣可以詳細(xì)研究一下源代碼 相關(guān)部分代碼可以參見(jiàn):https://github.com/hyperledger/fabric-ca/blob/release-1.1/lib/attr/attribute.go
感謝各位的閱讀!關(guān)于“Fabric CA創(chuàng)建用戶(hù)機(jī)制的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
分享文章:FabricCA創(chuàng)建用戶(hù)機(jī)制的示例分析
文章源于:http://www.ef60e0e.cn/article/gdgggs.html