当前位置:网站首页>实战:fabric 用户证书吊销操作流程
实战:fabric 用户证书吊销操作流程
2022-07-04 12:37:00 【InfoQ】

1. 使用fabric-ca 生成 user4的证书
##进入fabric-ca
> kubectl exec -it -n hll004 ca-shenzhen-6888d45db-vdhwp bash
## 注册user3新身份
bash-5.1# fabric-ca-client register --id.name user4 --id.type client --id.secret user4pw --id.attrs "hf.Registrar.Roles=client,hf.Registrar.Attributes=*" --tls.certfiles /certs/root-ca/shenzhen/tls-cert.pem
## 登记user4身份
bash-5.1# fabric-ca-client enroll -u https://user4:[email protected]:7054 -M /certs/peerOrganizations/shenzhen.hll004.bsnbase.com/users/[email protected]/msp --tls.certfiles /certs/root-ca/shenzhen/tls-cert.pem
## 将user4证书重命名为u[email protected]
bash-5.1# cp /certs/peerOrganizations/shenzhen.hll004.bsnbase.com/users/[email protected]/msp/signcerts/cert.pem /certs/peerOrganizations/shenzhen.hll004.bsnbase.com/users/[email protected]/msp/signcerts/[email protected]
## 将 config.yaml文件赋值到user4的msp下
bash-5.1# cp /certs/peerOrganizations/shenzhen.hll004.bsnbase.com/users/[email protected]/msp/config.yaml /certs/peerOrganizations/shenzhen.hll004.bsnbase.com/users/[email protected]/msp/config.yaml
2. 注销前调用链码
> kubectl exec -it -n hll004 peer1-shenzhen-ffd89f897-b7hkj -c peer1-shenzhen-cli bash
## 切换用户user4
bash-5.1# export CORE_PEER_MSPCONFIGPATH=/certs/peerOrganizations/shenzhen.hll004.bsnbase.com/users/[email protected]/msp
## 调用链码
bash-5.1# peer chaincode invoke -o orderer1.orderer.hll004.bsnbase.com:7050 -C bsnchannel -n sacc -c '{"Args":["set","d","4"]}' --tls --cafile /certs/ordererOrganizations/orderer.hll004.bsnbase.com/orderers/orderer1.orderer.hll004.bsnbase.com/tls/server.crt
## 查询链码
bash-5.1# peer chaincode query -C bsnchannel -n sacc -c '{"Args":["get","b"]}'

3.吊销用户user4 并生成CRL
##进入fabric-ca
> kubectl exec -it -n hll004 ca-shenzhen-6888d45db-vdhwp bash
## 吊销证书并生成CRL 会在当前home下生成crl: /certs/peerOrganizations/shenzhen.hll004.bsnbase.com/msp/crls/crl.pem
bash-5.1# fabric-ca-client revoke -e user4 -r unspecified --gencrl --tls.certfiles /certs/root-ca/shenzhen/tls-cert.pem
cat /certs/peerOrganizations/shenzhen.hll004.bsnbase.com/msp/crls/crl.pem
-----BEGIN X509 CRL-----
MIIBZTCCAQwCAQEwCgYIKoZIzj0EAwIwaDELMAkGA1UEBhMCVVMxFzAVBgNVBAgT
Dk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMG
RmFicmljMRkwFwYDVQQDExBmYWJyaWMtY2Etc2VydmVyFw0yMjA2MTExNDM5MDha
Fw0yMjA2MTIxNDM5MDhaME4wJQIUYC7Dg4/6Ewn9mOh0Pus2bsMB0qIXDTIyMDYx
MTA2MDA0NlowJQIUYareqlvuL/vtyLnktwD94fbhNtwXDTIyMDYxMTE0MzkwN1qg
IzAhMB8GA1UdIwQYMBaAFO9fRc1RAhuTAzZQ+NF11GWVcoVRMAoGCCqGSM49BAMC
A0cAMEQCIASpL269XJF1nIk2KBHu0jzuImtbARaNYUe0n7SaojzWAiBuvJUmuXfe
KmT0dT5BKQtq7ZXJP6/ZXob7uTBtiLV0Xw==
-----END X509 CRL-----
##对上面进行base编码 (后面会用到): LS0tLS1CRUdJTiBYNTA5IENSTC0tLS0tCk1JSUJaVENDQVF3Q0FRRXdDZ1lJS29aSXpqMEVBd0l3YURFTE1Ba0dBMVVFQmhNQ1ZWTXhGekFWQmdOVkJBZ1QKRGs1dmNuUm9JRU5oY205c2FXNWhNUlF3RWdZRFZRUUtFd3RJZVhCbGNteGxaR2RsY2pFUE1BMEdBMVVFQ3hNRwpSbUZpY21sak1Sa3dGd1lEVlFRREV4Qm1ZV0p5YVdNdFkyRXRjMlZ5ZG1WeUZ3MHlNakEyTVRFeE5ETTVNRGhhCkZ3MHlNakEyTVRJeE5ETTVNRGhhTUU0d0pRSVVZQzdEZzQvNkV3bjltT2gwUHVzMmJzTUIwcUlYRFRJeU1EWXgKTVRBMk1EQTBObG93SlFJVVlhcmVxbHZ1TC92dHlMbmt0d0Q5NGZiaE50d1hEVEl5TURZeE1URTBNemt3TjFxZwpJekFoTUI4R0ExVWRJd1FZTUJhQUZPOWZSYzFSQWh1VEF6WlErTkYxMUdXVmNvVlJNQW9HQ0NxR1NNNDlCQU1DCkEwY0FNRVFDSUFTcEwyNjlYSkYxbklrMktCSHUwanp1SW10YkFSYU5ZVWUwbjdTYW9qeldBaUJ1dkpVbXVYZmUKS21UMGRUNUJLUXRxN1pYSlA2L1pYb2I3dVRCdGlMVjBYdz09Ci0tLS0tRU5EIFg1MDkgQ1JMLS0tLS0=
4 . 修改bsnchannel通道文件
## 登录组织shenzhen的peer1节点cli
> kubectl exec -it -n hll004 peer1-shenzhen-gs3465-ds bash
bash-5.1# export ORDERER_CA=/certs/ordererOrganizations/orderer.hll004.bsnbase.com/orderers/orderer1.orderer.hll004.bsnbase.com/tls/ca.crt
bash-5.1# export CHANNEL_NAME=bsnchannel
## 使用peer channel fetch命令获取应用通道的信息
bash-5.1# peer channel fetch config config_block.pb -o orderer1.orderer.hll004.bsnbase.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
2022-06-11 14:57:23.127 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-06-11 14:57:23.145 UTC [cli.common] readBlock -> INFO 002 Received block: 11
2022-06-11 14:57:23.145 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 7
2022-06-11 14:57:23.155 UTC [cli.common] readBlock -> INFO 004 Received block: 7
## 将通道文件中的内容转换成JSON并对其进行修剪
bash-5.1# configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > sys_config.json
bash-5.1# cp sys_config.json sys_config_new.json
## 将sys_config_new.json中的 channel_group.groups.Application.groups.ShenzhenMSP下的revocation_list字段值改为CRL的base64编码字符串
bash-5.1# vi sys_config_new.json
## 将上面两步产生的 JSON文件 重新编码成PB文件
bash-5.1# configtxlator proto_encode --input sys_config.json --type common.Config --output sys_config.pb
bash-5.1# configtxlator proto_encode --input sys_config_new.json --type common.Config --output sys_modified_config.pb
## 计算两个PB文件差异 输出新的PB文件
bash-5.1# configtxlator compute_update --channel_id $CHANNEL_NAME --original sys_config.pb --updated sys_modified_config.pb --output sys_crl_update.pb
## 把上一步PB转JSON 为了封装信封使用
bash-5.1# configtxlator proto_decode --input sys_crl_update.pb --type common.ConfigUpdate | jq . > sys_crl_update.json
## 封装信封
bash-5.1# echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL_NAME'", "type":2}},"data":{"config_update":'$(cat sys_crl_update.json)'}}}' | jq . > sys_crl_update_in_envelope.json
## JSON 转PB 最后生成准备提交文件
bash-5.1# configtxlator proto_encode --input sys_crl_update_in_envelope.json --type common.Envelope --output sys_crl_update_in_envelope.pb
## 完成最后签名的组织可执行交易提案至order
bash-5.1# peer channel update -f sys_crl_update_in_envelope.pb -c $CHANNEL_NAME -o orderer1.orderer.hll004.bsnbase.com:7050 --tls --cafile $ORDERER_CA
2022-06-11 15:03:11.600 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-06-11 15:03:11.648 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update


5. 注销后调用链码
## 登录peer-cli
[[email protected] ~]# kubectl exec -it -n hll004 peer1-shenzhen-ffd89f897-b7hkj -c peer1-shenzhen-cli bash
## 先使用Admin用户调用链码
bash-5.1# peer chaincode invoke -o orderer1.orderer.hll004.bsnbase.com:7050 -C bsnchannel -n sacc -c '{"Args":["set","e","4"]}' --tls --cafile /certs/ordererOrganizations/orderer.hll004.bsnbase.com/orderers/orderer1.orderer.hll004.bsnbase.com/tls/server.crt
2022-06-11 15:05:05.500 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 payload:"4"
## ## 先使用Admin用户查询链码
bash-5.1# peer chaincode query -C bsnchannel -n sacc -c '{"Args":["get","e"]}'
4
## 切换user4用户
bash-5.1# export CORE_PEER_MSPCONFIGPATH=/certs/peerOrganizations/shenzhen.hll004.bsnbase.com/users/[email protected]/msp
## 先使用user4用户查询链码
bash-5.1# peer chaincode query -C bsnchannel -n sacc -c '{"Args":["get","e"]}'
Error: error endorsing query: rpc error: code = Unknown desc = error validating proposal: access denied: channel [bsnchannel] creator org [ShenzhenMSP] - proposal response: <nil>
## ## 先使用user4用户调用链码
bash-5.1# peer chaincode invoke -o orderer1.orderer.hll004.bsnbase.com:7050 -C bsnchannel -n sacc -c '{"Args":["set","f","4"]}' --tls --cafile /certs/ordererOrganizations/orderer.hll004.bsnbase.com/orderers/orderer1.orderer.hll004.bsnbase.com/tls/server.crt
Error: error endorsing invoke: rpc error: code = Unknown desc = error validating proposal: access denied: channel [bsnchannel] creator org [ShenzhenMSP] - proposal response: <nil>

边栏推荐
- mysql三级分销代理关系存储
- 读《认知觉醒》
- Show recent errors only command /bin/sh failed with exit code 1
- WPF double slider control and forced capture of mouse event focus
- Play Sanzi chess easily
- Simple understanding of binary search
- Definition of cognition
- When to use pointers in go?
- Is the main thread the same as the UI thread- Is main thread the same as UI thread?
- PostgreSQL 9.1 飞升之路
猜你喜欢
Show recent errors only command /bin/sh failed with exit code 1
Introduction to the button control elevatedbutton of the fleet tutorial (the tutorial includes the source code)
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
A taste of node JS (V), detailed explanation of express module
C语言函数
16. Memory usage and segmentation
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
[data clustering] section 3 of Chapter 4: DBSCAN performance analysis, advantages and disadvantages, and parameter selection methods
Transformer principle and code elaboration (tensorflow)
After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil
随机推荐
16.内存使用与分段
Global and Chinese markets for soluble suture 2022-2028: Research Report on technology, participants, trends, market size and share
Full arrangement (medium difficulty)
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
Communication tutorial | overview of the first, second and third generation can bus
Definition of cognition
敏捷开发/敏捷测试感受
C language: find the length of string
asp. Core is compatible with both JWT authentication and cookies authentication
美团·阿里关于多模态召回的应用实践
After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil
[data clustering] section 3 of Chapter 4: DBSCAN performance analysis, advantages and disadvantages, and parameter selection methods
游戏启动后提示安装HMS Core,点击取消,未再次提示安装HMS Core(初始化失败返回907135003)
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Detailed explanation of mt4api documentary and foreign exchange API documentary interfaces
用fail2ban阻止密码尝试攻
mm_ Cognition of struct structure
数据库锁表?别慌,本文教你如何解决
一文掌握数仓中auto analyze的使用