Skip to content

Commit

Permalink
Configtx tool to use Verifying MSP
Browse files Browse the repository at this point in the history
LocalMSP expects to use a private key, BCCSP was complaining that it
cannot find the key

Change-Id: I6e99afb9f480f4a9fa963daa0cdbb11f2a60228f
Signed-off-by: Volodymyr Paprotski <vpaprots@ca.ibm.com>
  • Loading branch information
Volodymyr Paprotski committed Feb 24, 2017
1 parent 709d87b commit 3bcd969
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions common/configtx/tool/configtxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"io/ioutil"

"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/common/configtx"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
Expand All @@ -43,6 +44,7 @@ func main() {
logging.SetLevel(logging.INFO, "")

logger.Info("Loading configuration")
factory.InitFactories(nil)
config := genesisconfig.Load(profile)
pgen := provisional.New(config)

Expand Down
4 changes: 2 additions & 2 deletions common/configtx/tool/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func New(conf *genesisconfig.Profile) Generator {
}

for _, org := range conf.Orderer.Organizations {
mspConfig, err := msp.GetLocalMspConfig(org.MSPDir, org.BCCSP, org.ID)
mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.BCCSP, org.ID)
if err != nil {
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func New(conf *genesisconfig.Profile) Generator {
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.AdminsPolicyKey),
}
for _, org := range conf.Application.Organizations {
mspConfig, err := msp.GetLocalMspConfig(org.MSPDir, org.BCCSP, org.ID)
mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.BCCSP, org.ID)
if err != nil {
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
}
Expand Down
38 changes: 26 additions & 12 deletions msp/configbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,41 @@ func SetupBCCSPKeystoreConfig(bccspConfig *factory.FactoryOpts, keystoreDir stri
}

func GetLocalMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string) (*msp.MSPConfig, error) {
cacertDir := filepath.Join(dir, cacerts)
signcertDir := filepath.Join(dir, signcerts)
admincertDir := filepath.Join(dir, admincerts)
keystoreDir := filepath.Join(dir, keystore)
intermediatecertsDir := filepath.Join(dir, intermediatecerts)

SetupBCCSPKeystoreConfig(bccspConfig, keystoreDir)

err := factory.InitFactories(bccspConfig)
if err != nil {
return nil, fmt.Errorf("Could not initialize BCCSP Factories [%s]", err)
}

signcert, err := getPemMaterialFromDir(signcertDir)
if err != nil || len(signcert) == 0 {
return nil, fmt.Errorf("Could not load a valid signer certificate from directory %s, err %s", signcertDir, err)
}

/* FIXME: for now we're making the following assumptions
1) there is exactly one signing cert
2) BCCSP's KeyStore has the the private key that matches SKI of
signing cert
*/

sigid := &msp.SigningIdentityInfo{PublicSigner: signcert[0], PrivateSigner: nil}

return getMspConfig(dir, bccspConfig, ID, sigid)
}

func GetVerifyingMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string) (*msp.MSPConfig, error) {
return getMspConfig(dir, bccspConfig, ID, nil)
}

func getMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string, sigid *msp.SigningIdentityInfo) (*msp.MSPConfig, error) {
cacertDir := filepath.Join(dir, cacerts)
signcertDir := filepath.Join(dir, signcerts)
admincertDir := filepath.Join(dir, admincerts)
intermediatecertsDir := filepath.Join(dir, intermediatecerts)

cacerts, err := getPemMaterialFromDir(cacertDir)
if err != nil || len(cacerts) == 0 {
return nil, fmt.Errorf("Could not load a valid ca certificate from directory %s, err %s", cacertDir, err)
Expand All @@ -139,14 +161,6 @@ func GetLocalMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string)
intermediatecert, _ := getPemMaterialFromDir(intermediatecertsDir)
// intermediate certs are not mandatory

/* FIXME: for now we're making the following assumptions
1) there is exactly one signing cert
2) BCCSP's KeyStore has the the private key that matches SKI of
signing cert
*/

sigid := &msp.SigningIdentityInfo{PublicSigner: signcert[0], PrivateSigner: nil}

fmspconf := &msp.FabricMSPConfig{
Admins: admincert,
RootCerts: cacerts,
Expand Down

0 comments on commit 3bcd969

Please sign in to comment.