主题
fabric-ca · 架构
顶层组件
| 组件 | 文件 | 行号 | 职责 |
|---|---|---|---|
Server struct | lib/server.go | 67-95 | 主服务器对象;含 CA、mux(gorilla/mux)、dbMetrics、Metrics、Operations |
CA struct | lib/ca.go | 73-104 | CA 实例;含 db(FabricCADB)、csp(BCCSP)、enrollSigner、issuer(Idemix)、registry、attrMgr |
Client struct | lib/client.go | 46 | 客户端 SDK |
serverEndpoint struct | lib/serverendpoint.go | 19-30 | REST 端点:Path、Methods、Handler、successRC |
CA 启动
| 函数 | 文件 | 行号 |
|---|---|---|
newCA() | lib/ca.go | 112-124 |
initCA() | lib/ca.go | 127-148 |
initCA()(lib/ca.go:141-146)会创建 Idemix issuer:idemix.NewIssuer() + issuer.Init(renew, db, levels)。
端点注册
所有 REST 端点在 lib/server.go:549-564 的 registerHandlers() 中注册,调用 registerHandler()(lib/server.go:567-570),同时映射到 /{Path} 与 /api/v1/{Path} 两个路径。
端点完整列表见 05-core-flows 与 06-api。
数据库适配
| 项 | 文件 | 行号 |
|---|---|---|
DB struct(包 sqlx.DB) | lib/server/db/db.go | 77-83 |
DB 工厂 New(dbType, ...) | lib/server/db/factory/factory.go | 29-47 |
| SQLite 驱动 | lib/server/db/sqlite/ | — |
| PostgreSQL 驱动 | lib/server/db/postgres/ | — |
| MySQL 驱动 | lib/server/db/mysql/ | — |
| 迁移机制 | lib/server/db/migrator.go | 16-86 |
SQLite 注释中标注其不适合集群(lib/caconfig.go:58-61)。SQLite 固定单连接(lib/server/db/sqlite/sqlite.go:99)。PostgreSQL / MySQL 的连接池参数 [未核]。
表 schema(SQLite)
来源:lib/server/db/sqlite/sqlite.go:136-197。
| 表 | CREATE 行号 | 用途 |
|---|---|---|
users | 138 | 用户身份:id、token、type、affiliation、attributes、state、max_enrollments、level、incorrect_password_attempts |
certificates | 154 | 证书:serial_number、authority_key_identifier、ca_label、status、reason、expiry、revoked_at、pem、level |
affiliations | 146 | 组织树:name(UNIQUE)、prekey、level |
credentials | 162 | Idemix 凭证:revocation_handle(PK)、cred、ca_label、status、reason、expiry、revoked_at、level |
revocation_authority_info | 170 | Idemix RA 信息:epoch(PK)、next_handle、lasthandle_in_pool、level |
nonces | 178 | nonce:val(UNIQUE PK)、expiry、level |
properties | 186-190 | 系统属性表(各对象的 level) |
配置结构
| 配置 | 定义文件 | 行号 |
|---|---|---|
ServerConfig | lib/serverconfig.go | 29-61 |
CAConfig | lib/caconfig.go | 81-98 |
CAConfigDB | lib/caconfig.go | 127-131 |
ClientConfig | lib/clientconfig.go | 33-50 |
字段细节见 07-config。
BCCSP
| 项 | 文件 | 出处 |
|---|---|---|
| CSP 实现 | util/csp.go | README.md:63 |
| PKCS#11 keyrequest 支持 | lib/keyrequest.go(build tag pkcs11)/ lib/keyrequestnopkcs11.go(!pkcs11),均实现 GetKeyRequest(cfg *CAConfig) | 文件存在 |
TLS
| 项 | 文件 | 行号 |
|---|---|---|
| TLS 子目录 | lib/tls/ | 目录存在 |
| TLS 版本设置 | lib/server.go | 673-680(配置 TLS 1.2-1.3 与 stls.DefaultCipherSuites) |
具体加密套件清单 [未核]。
Idemix 子系统
lib/server/idemix/ 下文件:
idemixlib.goissuer.goconfig.gocri.goenroll.gorevocationkey.gorevocationauthority.goissuercredential.gocreddbaccessor.gononce.goidemix_roles.go
Idemix 加密协议细节由外部依赖 github.com/IBM/idemix 提供,本仓库源码不含算法实现。