From 8139bb47ed568e9826f7c2691c0d3f7d2faec65d Mon Sep 17 00:00:00 2001 From: Alessandro Sorniotti Date: Mon, 16 Oct 2017 14:22:48 +0200 Subject: [PATCH] [FAB-6367] create genesis tx/block with other MSPs This change set introduces an 'MSPType' field to configtx.yaml, so that the type of MSP can be specified. This permits credentials for other MSP types, most notably the idemix MSP, to be included in genesis tx/blocks so that they can be used as well. If no MSPType is specified, the standard one is automatically assumed. Change-Id: I5a609b57cfe85ae030f7a8fbecf8cfd71d3074ae Signed-off-by: Alessandro Sorniotti --- common/tools/configtxgen/encoder/encoder.go | 4 ++-- common/tools/configtxgen/localconfig/config.go | 7 +++++++ common/tools/cryptogen/msp/msp_test.go | 2 +- msp/configbuilder.go | 12 ++++++++++-- msp/msp.go | 14 ++++++++++++++ msp/msp_test.go | 2 +- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/common/tools/configtxgen/encoder/encoder.go b/common/tools/configtxgen/encoder/encoder.go index f301ea27632..a93c675f12d 100644 --- a/common/tools/configtxgen/encoder/encoder.go +++ b/common/tools/configtxgen/encoder/encoder.go @@ -178,7 +178,7 @@ func NewOrdererGroup(conf *genesisconfig.Orderer) (*cb.ConfigGroup, error) { // NewOrdererOrgGroup returns an orderer org component of the channel configuration. It defines the crypto material for the // organization (its MSP). It sets the mod_policy of all elements to "Admins". func NewOrdererOrgGroup(conf *genesisconfig.Organization) (*cb.ConfigGroup, error) { - mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID) + mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID, conf.MSPType) if err != nil { return nil, errors.Wrapf(err, "1 - Error loading MSP configuration for org: %s", conf.Name) } @@ -216,7 +216,7 @@ func NewApplicationGroup(conf *genesisconfig.Application) (*cb.ConfigGroup, erro // NewApplicationOrgGroup returns an application org component of the channel configuration. It defines the crypto material for the organization // (its MSP) as well as its anchor peers for use by the gossip network. It sets the mod_policy of all elements to "Admins". func NewApplicationOrgGroup(conf *genesisconfig.Organization) (*cb.ConfigGroup, error) { - mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID) + mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID, conf.MSPType) if err != nil { return nil, errors.Wrapf(err, "1 - Error loading MSP configuration for org %s: %s", conf.Name) } diff --git a/common/tools/configtxgen/localconfig/config.go b/common/tools/configtxgen/localconfig/config.go index df81bceadf4..4defceb988c 100644 --- a/common/tools/configtxgen/localconfig/config.go +++ b/common/tools/configtxgen/localconfig/config.go @@ -21,6 +21,7 @@ import ( "path/filepath" cf "github.com/hyperledger/fabric/core/config" + "github.com/hyperledger/fabric/msp" ) const ( @@ -113,6 +114,7 @@ type Organization struct { Name string `yaml:"Name"` ID string `yaml:"ID"` MSPDir string `yaml:"MSPDir"` + MSPType string `yaml:"MSPType"` AdminPrincipal string `yaml:"AdminPrincipal"` // Note: Viper deserialization does not seem to care for @@ -277,6 +279,11 @@ func (p *Profile) completeInitialization(configDir string) { } func (org *Organization) completeInitialization(configDir string) { + // set the MSP type; if none is specified we assume BCCSP + if org.MSPType == "" { + org.MSPType = msp.ProviderTypeToString(msp.FABRIC) + } + if org.AdminPrincipal == "" { org.AdminPrincipal = AdminRoleAdminPrincipal } diff --git a/common/tools/cryptogen/msp/msp_test.go b/common/tools/cryptogen/msp/msp_test.go index a66dabe3058..a2922046abf 100644 --- a/common/tools/cryptogen/msp/msp_test.go +++ b/common/tools/cryptogen/msp/msp_test.go @@ -135,7 +135,7 @@ func TestGenerateVerifyingMSP(t *testing.T) { "Expected to find file "+file) } // finally check to see if we can load this as a verifying MSP config - testMSPConfig, err := fabricmsp.GetVerifyingMspConfig(mspDir, testName) + testMSPConfig, err := fabricmsp.GetVerifyingMspConfig(mspDir, testName, fabricmsp.ProviderTypeToString(fabricmsp.FABRIC)) assert.NoError(t, err, "Error parsing verifying MSP config") testMSP, err := fabricmsp.New(&fabricmsp.BCCSPNewOpts{NewBaseOpts: fabricmsp.NewBaseOpts{Version: fabricmsp.MSPv1_0}}) assert.NoError(t, err, "Error creating new BCCSP MSP") diff --git a/msp/configbuilder.go b/msp/configbuilder.go index 0316bc573c6..b2b5a07c95e 100644 --- a/msp/configbuilder.go +++ b/msp/configbuilder.go @@ -146,8 +146,16 @@ func GetLocalMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string) return getMspConfig(dir, ID, sigid) } -func GetVerifyingMspConfig(dir string, ID string) (*msp.MSPConfig, error) { - return getMspConfig(dir, ID, nil) +// GetVerifyingMspConfig returns an MSP config given directory, ID and type +func GetVerifyingMspConfig(dir, ID, mspType string) (*msp.MSPConfig, error) { + switch mspType { + case ProviderTypeToString(FABRIC): + return getMspConfig(dir, ID, nil) + case ProviderTypeToString(IDEMIX): + return GetIdemixMspConfig(dir, ID) + default: + return nil, errors.Errorf("unknown MSP type '%s'", mspType) + } } func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.MSPConfig, error) { diff --git a/msp/msp.go b/msp/msp.go index 2e31f740ae4..1ad0c762ae0 100644 --- a/msp/msp.go +++ b/msp/msp.go @@ -195,4 +195,18 @@ const ( FABRIC ProviderType = iota // MSP is of FABRIC type IDEMIX // MSP is of IDEMIX type OTHER // MSP is of OTHER TYPE + + // NOTE: as new types are added to this set, + // the mspTypes array below must be extended ) + +var mspTypeStrings []string = []string{"bccsp", "idemix"} + +// ProviderTypeToString returns a string that represents the ProviderType integer +func ProviderTypeToString(id ProviderType) string { + if int(id) < 0 || int(id) > len(mspTypeStrings) { + return "" + } + + return mspTypeStrings[id] +} diff --git a/msp/msp_test.go b/msp/msp_test.go index 6431fc1f6ca..6ebb4f26b71 100644 --- a/msp/msp_test.go +++ b/msp/msp_test.go @@ -202,7 +202,7 @@ func TestGetSigningIdentityFromVerifyingMSP(t *testing.T) { os.Exit(-1) } - conf, err = GetVerifyingMspConfig(mspDir, "DEFAULT") + conf, err = GetVerifyingMspConfig(mspDir, "DEFAULT", ProviderTypeToString(FABRIC)) if err != nil { fmt.Printf("Setup should have succeeded, got err %s instead", err) os.Exit(-1)