区块链教程Fabric1.0源代码分析MSP成员关系服务提供者一
  PsFdlfMAlaXs 2023年11月02日 54 0

Fabric 1.0源代码笔记 之 MSP(成员关系服务提供者)

1、MSP概述

MSP,全称Membership Service Provider,即成员关系服务提供者,作用为管理Fabric中的众多参与者。

成员服务提供者(MSP)是一个提供抽象化成员操作框架的组件。 MSP将颁发与校验证书,以及用户认证背后的所有密码学机制与协议都抽象了出来。一个MSP可以自己定义身份,以及身份的管理(身份验证)与认证(生成与验证签名)规则。 一个Hyperledger Fabric区块链网络可以被一个或多个MSP管理。

MSP的核心代码在msp目录下,其他相关代码分布在common/config/msp、protos/msp下。目录结构如下:

  • msp目录     * msp.go,定义接口MSP、MSPManager、Identity、SigningIdentity、IdentityDeserializer。     * mspimpl.go,实现MSP接口,即bccspmsp。     * mspmgrimpl.go,实现MSPManager接口,即mspManagerImpl。     * identities.go,实现Identity、SigningIdentity接口,即identity和signingidentity。     * configbuilder.go,提供读取证书文件并将其组装成MSP等接口所需的数据结构,以及转换配置结构体(FactoryOpts->MSPConfig)等工具函数。     * cert.go,证书相关结构体及方法。     * mgmt目录         * mgmt.go,msp相关管理方法实现。         * principal.go,MSPPrincipalGetter接口及其实现,即localMSPPrincipalGetter。         * deserializer.go,DeserializersManager接口及其实现,即mspDeserializersManager。
  • common/config/msp目录     * config.go,定义了MSPConfigHandler及其方法,用于配置MSP和configtx工具。
  • protos/msp目录,msp相关Protocol Buffer原型文件。

2、核心接口定义

IdentityDeserializer为身份反序列化接口,同时被MSP和MSPManger的接口嵌入。定义如下:

type IdentityDeserializer interface {
    DeserializeIdentity(serializedIdentity []byte) (Identity, error)
}
//代码在msp/msp.go

MSP接口定义:

type MSP interface {
    IdentityDeserializer //需要实现IdentityDeserializer接口
    Setup(config *msp.MSPConfig) error //根据MSPConfig设置MSP实例
    GetType() ProviderType //获取MSP类型,即FABRIC
    GetIdentifier() (string, error) //获取MSP名字
    GetDefaultSigningIdentity() (SigningIdentity, error) //获取默认的签名身份
    GetTLSRootCerts() [][]byte //获取TLS根CA证书
    Validate(id Identity) error //校验身份是否有效
    SatisfiesPrincipal(id Identity, principal *msp.MSPPrincipal) error //验证给定的身份与principal中所描述的类型是否相匹配
}
//代码在msp/msp.go

MSPManager接口定义:

type MSPManager interface {
    IdentityDeserializer //需要实现IdentityDeserializer接口
    Setup(msps []MSP) error //用给定的msps填充实例中的mspsMap
    GetMSPs() (map[string]MSP, error) //获取MSP列表,即mspsMap
}
//代码在msp/msp.go

Identity接口定义(身份):

type Identity interface {
    GetIdentifier() *IdentityIdentifier //获取身份ID
    GetMSPIdentifier() string //获取MSP ID,即id.Mspid
    Validate() error //校验身份是否有效,即调取msp.Validate(id)
    GetOrganizationalUnits() []*OUIdentifier //获取组织单元
    Verify(msg []byte, sig []byte) error //用这个身份校验消息签名
    Serialize() ([]byte, error) //身份序列化
    SatisfiesPrincipal(principal *msp.MSPPrincipal) error //调用msp的SatisfiesPrincipal检查身份与principal中所描述的类型是否匹配
}
//代码在msp/msp.go

SigningIdentity接口定义(签名身份):

type SigningIdentity interface {
    Identity //需要实现Identity接口
    Sign(msg []byte) ([]byte, error) //签名msg
}
//代码在msp/msp.go

未完待续感谢关注!

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
PsFdlfMAlaXs