github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/msp/msp.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package msp 18 19 import ( 20 "github.com/hyperledger/fabric/protos/msp" 21 ) 22 23 // FIXME: we need better comments on the interfaces!! 24 // FIXME: we need better comments on the interfaces!! 25 // FIXME: we need better comments on the interfaces!! 26 27 // IdentityDeserializer is implemented by both MSPManger and MSP 28 type IdentityDeserializer interface { 29 // DeserializeIdentity deserializes an identity. 30 // Deserialization will fail if the identity is associated to 31 // an msp that is different from this one that is performing 32 // the deserialization. 33 DeserializeIdentity(serializedIdentity []byte) (Identity, error) 34 } 35 36 // Membership service provider APIs for Hyperledger Fabric: 37 // 38 // By "membership service provider" we refer to an abstract component of the 39 // system that would provide (anonymous) credentials to clients, and peers for 40 // them to participate in Hyperledger/fabric network. Clients use these 41 // credentials to authenticate their transactions, and peers use these credentials 42 // to authenticate transaction processing results (endorsements). While 43 // strongly connected to the transaction processing components of the systems, 44 // this interface aims to have membership services components defined, in such 45 // a way such that alternate implementations of this can be smoothly plugged in 46 // without modifying the core of transaction processing components of the system. 47 // 48 // This file includes Membership service provider interface that covers the 49 // needs of a peer membership service provider interface. 50 51 // MSPManager is an interface defining a manager of one or more MSPs. This 52 // essentially acts as a mediator to MSP calls and routes MSP related calls 53 // to the appropriate MSP. 54 // This object is immutable, it is initialized once and never changed. 55 type MSPManager interface { 56 57 // IdentityDeserializer interface needs to be implemented by MSPManager 58 IdentityDeserializer 59 60 // Setup the MSP manager instance according to configuration information 61 Setup(msps []MSP) error 62 63 // GetMSPs Provides a list of Membership Service providers 64 GetMSPs() (map[string]MSP, error) 65 } 66 67 // MSP is the minimal Membership Service Provider Interface to be implemented 68 // to accommodate peer functionality 69 type MSP interface { 70 71 // IdentityDeserializer interface needs to be implemented by MSP 72 IdentityDeserializer 73 74 // Setup the MSP instance according to configuration information 75 Setup(config *msp.MSPConfig) error 76 77 // GetType returns the provider type 78 GetType() ProviderType 79 80 // GetIdentifier returns the provider identifier 81 GetIdentifier() (string, error) 82 83 // GetSigningIdentity returns a signing identity corresponding to the provided identifier 84 GetSigningIdentity(identifier *IdentityIdentifier) (SigningIdentity, error) 85 86 // GetDefaultSigningIdentity returns the default signing identity 87 GetDefaultSigningIdentity() (SigningIdentity, error) 88 89 // GetRootCerts returns the root certificates for this MSP 90 GetRootCerts() []Identity 91 92 // GetIntermediateCerts returns the intermediate root certificates for this MSP 93 GetIntermediateCerts() []Identity 94 95 // Validate checks whether the supplied identity is valid 96 Validate(id Identity) error 97 98 // SatisfiesPrincipal checks whether the identity matches 99 // the description supplied in MSPPrincipal. The check may 100 // involve a byte-by-byte comparison (if the principal is 101 // a serialized identity) or may require MSP validation 102 SatisfiesPrincipal(id Identity, principal *msp.MSPPrincipal) error 103 } 104 105 // OUIdentifier represents an organizational unit and 106 // its related chain of trust identifier. 107 type OUIdentifier struct { 108 // CertifiersIdentifier is the hash of certificates chain of trust 109 // related to this organizational unit 110 CertifiersIdentifier []byte 111 // OrganizationUnitIdentifier defines the organizational unit under the 112 // MSP identified with MSPIdentifier 113 OrganizationalUnitIdentifier string 114 } 115 116 // From this point on, there are interfaces that are shared within the peer and client API 117 // of the membership service provider. 118 119 // Identity interface defining operations associated to a "certificate". 120 // That is, the public part of the identity could be thought to be a certificate, 121 // and offers solely signature verification capabilities. This is to be used 122 // at the peer side when verifying certificates that transactions are signed 123 // with, and verifying signatures that correspond to these certificates./// 124 type Identity interface { 125 126 // GetIdentifier returns the identifier of that identity 127 GetIdentifier() *IdentityIdentifier 128 129 // GetMSPIdentifier returns the MSP Id for this instance 130 GetMSPIdentifier() string 131 132 // Validate uses the rules that govern this identity to validate it. 133 // E.g., if it is a fabric TCert implemented as identity, validate 134 // will check the TCert signature against the assumed root certificate 135 // authority. 136 Validate() error 137 138 // GetOrganizationalUnits returns zero or more organization units or 139 // divisions this identity is related to as long as this is public 140 // information. Certain MSP implementations may use attributes 141 // that are publicly associated to this identity, or the identifier of 142 // the root certificate authority that has provided signatures on this 143 // certificate. 144 // Examples: 145 // - if the identity is an x.509 certificate, this function returns one 146 // or more string which is encoded in the Subject's Distinguished Name 147 // of the type OU 148 // TODO: For X.509 based identities, check if we need a dedicated type 149 // for OU where the Certificate OU is properly namespaced by the 150 // signer's identity 151 GetOrganizationalUnits() []*OUIdentifier 152 153 // Verify a signature over some message using this identity as reference 154 Verify(msg []byte, sig []byte) error 155 156 // Serialize converts an identity to bytes 157 Serialize() ([]byte, error) 158 159 // SatisfiesPrincipal checks whether this instance matches 160 // the description supplied in MSPPrincipal. The check may 161 // involve a byte-by-byte comparison (if the principal is 162 // a serialized identity) or may require MSP validation 163 SatisfiesPrincipal(principal *msp.MSPPrincipal) error 164 } 165 166 // SigningIdentity is an extension of Identity to cover signing capabilities. 167 // E.g., signing identity should be requested in the case of a client who wishes 168 // to sign transactions, or fabric endorser who wishes to sign proposal 169 // processing outcomes. 170 type SigningIdentity interface { 171 172 // Extends Identity 173 Identity 174 175 // Sign the message 176 Sign(msg []byte) ([]byte, error) 177 178 // GetPublicVersion returns the public parts of this identity 179 GetPublicVersion() Identity 180 } 181 182 // IdentityIdentifier is a holder for the identifier of a specific 183 // identity, naturally namespaced, by its provider identifier. 184 type IdentityIdentifier struct { 185 186 // The identifier of the associated membership service provider 187 Mspid string 188 189 // The identifier for an identity within a provider 190 Id string 191 } 192 193 // ProviderType indicates the type of an identity provider 194 type ProviderType int 195 196 // The ProviderType of a member relative to the member API 197 const ( 198 FABRIC ProviderType = iota // MSP is of FABRIC type 199 OTHER // MSP is of OTHER TYPE 200 )