Fabric CA源码和镜像编译
原文网址:https://blog.csdn.net/zhayujie5200/article/details/80221361
前言
之前使用CA服务一直是在
docker
容器中运行下载好的CA镜像,在应用程序中通过Node SDK中集成的接口来访问CA服务器,这次尝试手动部署CA服务;Fabric CA由服务端和客户端组件组成,CA服务端(
fabric-ca-server
)可以看作一个web服务,执行了Go代码编译生成的二进制文件后,会监听一个端口,处理收到的请求;CA客户端(
fabric-ca-client
)其实就是一个向CA服务端发送请求的程序,执行编译成的二进制文件并带上不同参数,可以向CA服务器发送相应的http请求,完成一系列操作。
准备工作
安装Go语言并配置好
GOPATH
环境变量,下载并配置docker
安装
libtool
和libtdhl-dev
sudo apt install libtool libltdl-dev
通过命令行安装和启动CA
直接从github下载并编译
go get -u github.com/hyperledger/fabric-ca/cmd/fabric-ca-server go get -u github.com/hyperledger/fabric-ca/cmd/fabric-ca-client
go get
命令会自动获取源码并编译至$GOPATH/bin
,我的目录是~/go/bin
,目录下出现编译好的二进制可执行文件fabric-ca-server
和fabric-ca-client
接着初始化和启动
fabric-ca-server
,需要设置一个管理员用户的名称和密码fabric-ca-server init -b admin:adminpw fabric-ca-server start -b admin:adminpw
在这里报错了
panic: Version is not set for fabric-ca library
,可能与下载的v1.1版本的fabric-ca
有关系。
手动编译生成
既然直接从github下载的版本出现错误,可以选择自己去编译生成指定版本的
fabric-ca-server
。
首先下载fabric-ca
源码并切换至相应版本:git clone https://github.com/hyperledger/fabric-ca.git
然后在
fabric-ca
目录下进行编译make fabric-ca-server make fabric-ca-client
cd /home/admin/gocode/src/github.com/hyperledger/fabric-ca/bin
会在.../fabric-ca/bin
目录下生成fabric-ca-server
和fabric-ca-client
。
接着进入bin
目录对CA服务端进行初始化:
fabric-ca-server init -b admin:adminpw
初始化后在目录下生成
msp
:包含keystore,CA服务器的私钥ca-cert.pem
:CA服务端的证书fabric-ca-server.db
:CA默认使用的嵌入型数据库 SQLitefabric-ca-server-config.yaml
:CA服务端的配置文件
接着启动CA服务器
fabric-ca-server start -b admin:adminpw
CA server开始监听,默认监听地址为http://0.0.0.0:7054
。如果直接执行start
命令则会自动先进行初始化init
然后启动服务开始监听。
通过docker镜像安装和启动CA
docker
镜像中同时包含了fabric-ca-server
和fabric-ca-client
直接下载fabric-ca镜像
首先可以选择从Docker Hub
直接下载fabric-ca
镜像:docker pull hyperledger/fabric-ca:x86_64-1.1.0
利用
docker-compose.yml
文件来启动镜像,配置文件在.../fabric-ca/docker/server
中,进入该目录后启动:docker-compose up
即可启动ca容器,如果镜像不存在还会主动拉取镜像,在
.../server/fabric-ca-server
目录中会生成上述的配置文件(这是利用docker-compose.yml
文件设置的映射),证书私钥,数据库文件等,并且开始监听一个端口。手动编译docker镜像
除了直接从Docker Hub
拉取fabric-ca
镜像,还可以通过源码编译生成镜像。
在fabric-ca
目录下执行:make docker
会生成四个镜像
fabric-ca
,fabric-ca-tool
,fabric-ca-peer
,fabric-ca-orderer
,镜像保存在.../fabric-ca/build/image
中,之后和上面的方法相同根据docker-compose.yml
文件启动ca节点。
Fabric CA的使用
访问Fabric CA服务端的方法有两种:通过客户端工具(fabric-ca-client
)和RESTful
接口。本质上,客户端工具也是调用服务端的RESTful
接口实现的。这里采用客户端工具的方法来进行访问。
首先按照上述步骤初始化和启动CA服务器(执行fabric-ca-server
或启动CA容器),如果已经下载fabric-ca-client
,那移动到相应目录下即可开始操作(若已添加至环境变量则不用)。
如果是以docker
容器方式运行CA服务器且未下载客户端工具,可以进入容器内部进行测试(ca镜像集成了服务端和客户端组件),二进制文件放在/usr/local/bin
且已经添加环境变量,进入方法为:
docker exec -it fabric-ca-server bash
这里选择运行编译好的可执行文件的方法,首先在一个终端下启动CA服务器:
fabric-ca-server start -b admin:adminpw
在另一个终端操作CA客户端。首先需要注册(enroll)启动时设置的管理员用户, 注册前需要设置证书存储目录的环境变量:
export FABRIC_CA_CLIENT_HOME=$HOME/ca
fabric-ca-client enroll -u http://admin:adminpw@localhost:7054
可以发现~/ca
目录下生成了一个fabric-ca-client-config.yaml
配置文件,以及msp
目录,包含管理员的证书和私钥。
有了已经enroll成功的admin用户,接下来将admin作为登记员(Registrar)来登记(register)一个新用户:
fabric-ca-client register --id.name Jim --id.type user --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar'
[root@localhost admin]# fabric-ca-client register --id.name Jim --id.type user --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar' 2018/06/14 07:24:45 [INFO] Configuration file location: /root/ca/fabric-ca-client-config.yaml Password: iQEoXaLRWmNL
客户端可以接收到一个密码,用这个注册密码来注册(enroll)用户:
fabric-ca-client enroll -u http://Jim:
iQEoXaLRWmNL@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/Jim
这样一个新用户就注册成功了,获取了属于自己的证书和私钥。
总结
总结一下,手动部署CA服务可以分为两类方法:
一种方法是在命令行直接运行编译过后的可执行文件,可以通过
go get
命令自动获取并编译(最新版本有报错),也可以手动获取源码,切换版本后再进行编译; 然后在命令行中初始化和启动CA服务器;另一种方法是在容器中运行
docker
镜像,镜像中包含编译好的可执行文件,镜像可以从Docker Hub
直接下载,也可以在fabric-ca
目录下利用make docker
手动编译,然后利用docker-compose
启动CA容器。
最后查看相关文件内容或者树结构
cd /home/admin/gocode/src/github.com/hyperledger/fabric-ca/bin
1 [root@localhost bin]# tree -F 2 . 3 ├── ca-cert.pem 4 ├── fabric-ca-client* 5 ├── fabric-ca-server* 6 ├── fabric-ca-server-config.yaml 7 ├── fabric-ca-server.db 8 └── msp/ 9 └── keystore/ 10 └── 73c8509d3f8b33d60ba9825a0ddeb10dc6a12fb22fc8912c7661e7a639baac0c_sk* 11 12 2 directories, 6 files
gedit fabric-ca-server-config.yaml
# Version of config file version: 1.1.1-snapshot-e656889 # Server's listening port (default: 7054) port: 7054 # Enables debug logging (default: false) debug: false # Size limit of an acceptable CRL in bytes (default: 512000) crlsizelimit: 512000 tls:# Enable TLS (default: false)enabled: false# TLS for the server's listening portcertfile:keyfile:clientauth:type: noclientcertcertfiles: ca:# Name of this CAname:# Key file (is only used to import a private key into BCCSP)keyfile:# Certificate file (default: ca-cert.pem)certfile:# Chain filechainfile: crl:# Specifies expiration for the generated CRL. The number of hours# specified by this property is added to the UTC time, the resulting time# is used to set the 'Next Update' date of the CRL.expiry: 24h registry:# Maximum number of times a password/secret can be reused for enrollment# (default: -1, which means there is no limit)maxenrollments: -1# Contains identity information which is used when LDAP is disabledidentities:- name: adminpass: adminpwtype: clientaffiliation: ""attrs:hf.Registrar.Roles: "peer,orderer,client,user"hf.Registrar.DelegateRoles: "peer,orderer,client,user"hf.Revoker: truehf.IntermediateCA: truehf.GenCRL: truehf.Registrar.Attributes: "*"hf.AffiliationMgr: true db:type: sqlite3datasource: fabric-ca-server.dbtls:enabled: falsecertfiles:client:certfile:keyfile: ldap:# Enables or disables the LDAP client (default: false)# If this is set to true, the "registry" section is ignored.enabled: false# The URL of the LDAP serverurl: ldap://<adminDN>:<adminPassword>@<host>:<port>/<base># TLS configuration for the client connection to the LDAP servertls:certfiles:client:certfile:keyfile:# Attribute related configuration for mapping from LDAP entries to Fabric CA attributesattribute:# 'names' is an array of strings containing the LDAP attribute names which are# requested from the LDAP server for an LDAP identity's entrynames: ['uid','member']converters:- name:value:maps:groups:- name:value: affiliations:org1:- department1- department2org2:- department1 signing:default:usage:- digital signatureexpiry: 8760hprofiles:ca:usage:- cert sign- crl signexpiry: 43800hcaconstraint:isca: truemaxpathlen: 0tls:usage:- signing- key encipherment- server auth- client auth- key agreementexpiry: 8760h csr:cn: fabric-ca-servernames:- C: USST: "North Carolina"L:O: HyperledgerOU: Fabrichosts:- localhost.localdomain- localhostca:expiry: 131400hpathlength: 1 bccsp:default: SWsw:hash: SHA2security: 256filekeystore:# The directory used for the software file-based keystorekeystore: msp/keystore cacount: cafiles: intermediate:parentserver:url:caname:enrollment:hosts:profile:label:tls:certfiles:client:certfile:keyfile:
tree -L 1 fabric-ca
1 ├── api 2 ├── bin 3 ├── CHANGELOG.md 4 ├── ci.properties 5 ├── cmd 6 ├── CODE_OF_CONDUCT.md 7 ├── CONTRIBUTING.md 8 ├── docker 9 ├── docker-env.mk 10 ├── docs 11 ├── images 12 ├── lib 13 ├── LICENSE 14 ├── MAINTAINERS.md 15 ├── Makefile 16 ├── README.md 17 ├── release_notes 18 ├── scripts 19 ├── swagger 20 ├── test 21 ├── testdata 22 ├── util 23 └── vendor
fabric-ca-server-config.yaml
1 # Version of config file2 version: 1.1.1-snapshot-e6568893 4 # Server's listening port (default: 7054)5 port: 70546 7 # Enables debug logging (default: false)8 debug: false 9 10 # Size limit of an acceptable CRL in bytes (default: 512000) 11 crlsizelimit: 512000 12 13 tls: 14 # Enable TLS (default: false) 15 enabled: false 16 # TLS for the server's listening port 17 certfile: 18 keyfile: 19 clientauth: 20 type: noclientcert 21 certfiles: 22 23 ca: 24 # Name of this CA 25 name: 26 # Key file (is only used to import a private key into BCCSP) 27 keyfile: 28 # Certificate file (default: ca-cert.pem) 29 certfile: 30 # Chain file 31 chainfile: 32 33 34 crl: 35 expiry: 24h 36 37 38 registry: 39 # Maximum number of times a password/secret can be reused for enrollment 40 # (default: -1, which means there is no limit) 41 maxenrollments: -1 42 43 # Contains identity information which is used when LDAP is disabled 44 identities: 45 - name: admin 46 pass: adminpw 47 type: client 48 affiliation: "" 49 attrs: 50 hf.Registrar.Roles: "peer,orderer,client,user" 51 hf.Registrar.DelegateRoles: "peer,orderer,client,user" 52 hf.Revoker: true 53 hf.IntermediateCA: true 54 hf.GenCRL: true 55 hf.Registrar.Attributes: "*" 56 hf.AffiliationMgr: true 57 58 59 db: 60 type: sqlite3 61 datasource: fabric-ca-server.db 62 tls: 63 enabled: false 64 certfiles: 65 client: 66 certfile: 67 keyfile: 68 69 70 ldap: 71 # Enables or disables the LDAP client (default: false) 72 # If this is set to true, the "registry" section is ignored. 73 enabled: false 74 # The URL of the LDAP server 75 url: ldap://<adminDN>:<adminPassword>@<host>:<port>/<base> 76 # TLS configuration for the client connection to the LDAP server 77 tls: 78 certfiles: 79 client: 80 certfile: 81 keyfile: 82 # Attribute related configuration for mapping from LDAP entries to Fabric CA attributes 83 attribute: 84 names: ['uid','member'] 85 converters: 86 - name: 87 value: 88 maps: 89 groups: 90 - name: 91 value: 92 affiliations: 93 org1: 94 - department1 95 - department2 96 org2: 97 - department1 98 signing: 99 default: 100 usage: 101 - digital signature 102 expiry: 8760h 103 profiles: 104 ca: 105 usage: 106 - cert sign 107 - crl sign 108 expiry: 43800h 109 caconstraint: 110 isca: true 111 maxpathlen: 0 112 tls: 113 usage: 114 - signing 115 - key encipherment 116 - server auth 117 - client auth 118 - key agreement 119 expiry: 8760h 120 csr: 121 cn: fabric-ca-server 122 names: 123 - C: US 124 ST: "North Carolina" 125 L: 126 O: Hyperledger 127 OU: Fabric 128 hosts: 129 - localhost.localdomain 130 - localhost 131 ca: 132 expiry: 131400h 133 pathlength: 1 134 bccsp: 135 default: SW 136 sw: 137 hash: SHA2 138 security: 256 139 filekeystore: 140 # The directory used for the software file-based keystore 141 keystore: msp/keystore 142 cacount: 143 cafiles: 144 145 intermediate: 146 parentserver: 147 url: 148 caname: 149 150 enrollment: 151 hosts: 152 profile: 153 label: 154 tls: 155 certfiles: 156 client: 157 certfile: 158 keyfile:
转载于:https://www.cnblogs.com/ycx95/p/9180625.html
Fabric CA源码和镜像编译相关推荐
- Android Gradle Plugin 源码阅读与编译
前言 为了解一些Andorid的构建流程,有时候需要阅读Android Gradle Plugin的相关源码的.自己阅读Android Gradle Plugin源码主要经历了三个时期: 1.AOSP ...
- 关于谷歌webrtc源码国内镜像的使用问题,以及Kurento媒体服务器
关于谷歌webrtc源码国内镜像的使用问题,以及Kurento媒体服务器 我周末搞了两天没搞出来码在国内有个镜像:https://source.codeaurora.org/quic/lc 但是 ...
- WebRTC源码下载与编译
WebRTC源码编译 1 几种源码下载方案对比 1.1 拉别人下好的代码 1.2云服务器 1.3 国内镜像 1.4 挂代理(推荐) 2 源码编译环境准备 2.1 环境要求 2.2 代理服务器配置 2. ...
- Android12 源码下载、编译、刷机、单编调试Framework
文章目录 说明 1. 代码下载 1.1 下载Repo工具 1.2 安装和配置Git 1.3 创建工程目录 1.4 初始化Repo仓库 1.5 同步代码 2. 驱动下载 2.1 下载对应机型的驱动 2. ...
- 《深入理解Android内核设计思想(第2版)(上下册)》之Android源码下载及编译
本文摘自人民邮电出版社异步社区<深入理解Android内核设计思想(第2版)(上下册)> 购书地址:http://item.jd.com/12212640.html 试读地址:http:/ ...
- linux下下载openwrt源码,OpenWrt下载编译
不想啰嗦直接肝,依次执行: git clone git://github.com/openwrt/openwrt.git cd openwrt ./scripts/feeds update -a ./ ...
- 《深入理解Android内核设计思想(第2版)(上下册)》之Android源码下载及编译...
本文摘自人民邮电出版社异步社区<深入理解Android内核设计思想(第2版)(上下册)> 购书地址:item.jd.com/12212640.ht- 试读地址:www.epubit.com ...
- 开发板与虚拟机组网、uboot源码makefile分析、uboot安全启动与非安全启动方式、uboot源码配置与编译流程、制作TF启动盘
开发板与虚拟机组网. 局面:开发板.PC(Ubuntu系统).网线直连PC:设置Ubuntu系统:1.设置桥接模式,桥接到PC的有线网卡上:2.手动配置IP V4的地址信息,注意和开发板保持在同一网段 ...
- dll 源码_重新编译mono——Android动态更新dll
环境: 操作系统:Mac OSX10.12.6 mono版本:unity2017.1.3p4 NDK版本:android-ndk-r10e 一.指导步骤: 1.修改mono源码,重新编译,替换打包机的 ...
- 探索比特币源码0-bitcoin的编译
探索比特币源码0-bitcoin的编译 前言 区块链领域作为一个新兴的热点,迭代的实在是太快了,刚刚入门,必须要抓紧追赶. 在阅读了一些优秀的文档之后,已经对比特币及其背后的实现技术--区块链有了一定 ...
最新文章
- ecshop入门第一步,替换ecshop模板的显示图片
- PS2 KBC will hang
- java中创建两种线程的方式_java中创建线程的两种方式有什么区别?
- linux 文件时间详解
- abb变频器acs880说明书_常见品牌变频器修改功率方法大全
- java构造方法重载_Java 重载、重写、构造函数的实例详解
- 用友老是显示服务器错误,客户端连服务器出现这样的错误框
- pku 2418 Hardwood Species 字典树
- python自然语言的背景_PYTHON 自然语言处理
- repo-关于URL编码
- 前后端分离使用 Token 登录解决方案
- delphi datasnap断线后再次连接_电脑连接WiFi后经常出现断线断开连接问题的解决方法...
- Linux系统编程:pipe匿名管道的使用,实现linux命令下管道命令
- Python基础闯关失败总结
- JAVA 设计模式 职责链模式
- nginx发布静态目录备忘
- 虚拟机安装centos7.2系统
- html5 橡皮擦效果,javascript – HTML5 Canvas:globalCompositeOperation(橡皮擦)
- Learn Git Branching 学习笔记(Git远程仓库篇)
- 麦吉尔大学计算机科学申请,三大权威榜单为你诠释:加拿大计算机科学哪家强?...
热门文章
- 12星座的出生年月日性格_十二星座出生日期
- mysql同时满足升序和降序_mysql中的升序和降序以及一个字段升序和一个字段降序...
- Rockcip Android多媒体框架 Codec2
- win7共享文件提示输入网络密码
- Spring boot2.0 JpaRepository findOne的使用
- Linux中rm -rf 文件夹,删不掉
- html中的embed标签属性,html中Embed标签的语法和属性设置
- vs下inl中的函数提示C2084 已有主体的解决方案
- IPone 接口压力测试
- 这些好玩的 GitHub 项目,你知道几个?